成人国产在线小视频_日韩寡妇人妻调教在线播放_色成人www永久在线观看_2018国产精品久久_亚洲欧美高清在线30p_亚洲少妇综合一区_黄色在线播放国产_亚洲另类技巧小说校园_国产主播xx日韩_a级毛片在线免费

資訊專(zhuān)欄INFORMATION COLUMN

android 一些 utils

lsxiao / 2108人閱讀

一 Paint ,Canvas

public class drawView extends View{
    private Paint paint1;
    public drawView(Context context,AttributeSet set ){
        super(context,set);
    }
         
    public void onDraw(Canvas canvas){
        
        super.onDraw(canvas);
                //new 一個(gè)畫(huà)筆對(duì)象
        paint1= new Paint();
        canvas.drawColor(Color.TRANSPARENT);
        //給畫(huà)筆設(shè)置 屬性
        paint1.setAntiAlias(true);
        paint1.setColor(Color.GRAY);
        paint1.setStyle(Paint.Style.FILL);
        paint1.setStrokeWidth(3);
 
        //畫(huà)一個(gè)圓
        //canvas.drawCircle(arg0, arg1, arg2, arg3);
        canvas.drawCircle(10, 10, 5, paint1);
        }
}

二 AsyncImageTask

    /*
     *  //默認(rèn)開(kāi)啟的線(xiàn)程數(shù)為128條如果超過(guò)128條會(huì)放進(jìn)隊(duì)列進(jìn)行排隊(duì)
        //繼承AsyncTask時(shí)指定三個(gè)參數(shù)第一個(gè)為要傳入的參數(shù)類(lèi)型 第二個(gè)為進(jìn)度的參數(shù)類(lèi)型 第三個(gè)為返回結(jié)果的參數(shù)類(lèi)型
        //當(dāng)調(diào)用execute時(shí)首先執(zhí)行preExecute然后在執(zhí)行去啟用線(xiàn)程池的execute
        //這時(shí)會(huì)啟動(dòng)子線(xiàn)程去執(zhí)行doinbackground--執(zhí)行完后AsyncTask內(nèi)部會(huì)有Handler將結(jié)果返回到UI線(xiàn)程中
        //也就是onPostExecute的這個(gè)方法然后在進(jìn)行UI界面的更新
     */
     private  void asyncImageLoad(ImageView imageView, String path) {
            AsyncImageTask asyncImageTask = new AsyncImageTask(imageView);
            asyncImageTask.execute(path);
            
        }
      private final class AsyncImageTask extends AsyncTask{
        private ImageView imageView;
        public AsyncImageTask(ImageView imageView) {
            this.imageView = imageView;
         
        }
        protected Uri doInBackground(String... params) {//子線(xiàn)程中執(zhí)行的
            try {
                Uri uu = ContactService.getImage(params[0], cache);//將URI路徑拋給主線(xiàn)程
                System.out.println(uu+"   zuuuuuuuu");
                return uu;
            } catch (Exception e) {
                e.printStackTrace();
            }
            return null;
        }
        protected void onPostExecute(Uri result) {//運(yùn)行在主線(xiàn)程,獲取 URI 路徑 ,進(jìn)行圖片更新
            Log.i("Test", result+"");
            if(result!=null && imageView!= null)
                imageView.setImageURI(result);//setImageURI這個(gè)方法會(huì)根據(jù)路徑加載圖片
        }
     } 

三 截取字符串

//截取字符串  從 0 到 第一個(gè) "/" 字符
 String name = result.substring(0,result.indexOf("/"));
//截取字符串  從 第一個(gè) 字符 “/”  到  最后一個(gè) “/” 字符
 String name = result.substring(result.indexOf("/")+1, result.lastIndexOf("/")));

四 MD5廣泛用于加密

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5 {
    public static String getMD5(String content) {
        try {
            MessageDigest digest = MessageDigest.getInstance("MD5");
            digest.update(content.getBytes());
            return getHashString(digest);
            
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return null;
    }
    
    private static String getHashString(MessageDigest digest) {
        StringBuilder builder = new StringBuilder();
        for (byte b : digest.digest()) {
            builder.append(Integer.toHexString((b >> 4) & 0xf));
            builder.append(Integer.toHexString(b & 0xf));
        }
        return builder.toString();
    }
}

五 讀取流中的字節(jié):

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
public class StreamTool {
    /**
     * 讀取流中的數(shù)據(jù)
     * @param inStream
     * @return
     * @throws Exception
     */
    public static byte[] read(InputStream inStream) throws Exception{
        ByteArrayOutputStream outStream = new ByteArrayOutputStream();
        byte[] buffer = new byte[1024];
        int len = 0;
        while( (len = inStream.read(buffer)) != -1){
            outStream.write(buffer, 0, len);
        }
        inStream.close();
        return outStream.toByteArray();
    }
}

六 解析服務(wù)器傳過(guò)來(lái)的 xml 數(shù)據(jù)流

/*
     * 得到解析 xml 后 的 Contact list 集合
     */
    public static List getContacts() throws Exception {
        
        String path = StringTools.getURL_list_xml;
        URL url = new URL(path);
    //URLConnection與HttPURLConnection都是抽象類(lèi),無(wú)法直接實(shí)例化對(duì)象。
    //其對(duì)象主要通過(guò)URL的openconnection方法獲得。
    //利用HttpURLConnection對(duì)象從網(wǎng)絡(luò)中獲取網(wǎng)頁(yè)數(shù)據(jù)
        HttpURLConnection con = (HttpURLConnection) url.openConnection();
        con.setReadTimeout(5000);
        con.setRequestMethod("GET");
        if(con.getResponseCode() == 200){ //http協(xié)議,里面有相應(yīng)狀態(tài)碼的解釋, 
                                     //這里如樓上所說(shuō)是判斷是否正常響應(yīng)請(qǐng)求數(shù)據(jù).
            return parseXML(con.getInputStream()); //FFF
            //return StreamTool.read(con.getInputStream());
        }
        return null;
    }
其中   parseXML(con.getInputStream());

    /*
     * 解析XMl 
     */
     private static List parseXML(InputStream xml) throws Exception {
        List contacts = new ArrayList();
        Contact contact = null;
        XmlPullParser pullParser = Xml.newPullParser();
        pullParser.setInput(xml,"UTF-8");
        int event = pullParser.getEventType();
        while(event != XmlPullParser.END_DOCUMENT){
            switch (event) {
            case XmlPullParser.START_TAG :
                if("contact".equals(pullParser.getName())){
                    contact = new Contact();
                    contact.id = new Integer(pullParser.getAttributeValue(0));
                }else if("name".equals(pullParser.getName())){
                    contact.name = pullParser.nextText();// .nextText 不是  .getText !?。?!
                }else if("image".equals(pullParser.getName())){
                    
                    contact.imageUrl = pullParser.getAttributeValue(0);//FFF
                }
            
                break;
            case XmlPullParser.END_TAG :
                if("contact".equals(pullParser.getName())){
                contacts.add(contact);
                contact = null;
                }
                break;
            }
            event = pullParser.next();
        }
        return contacts;
    } 

七 解析 服務(wù)器傳過(guò)來(lái)的 Json 數(shù)據(jù):

/*
     * 解析 Json 數(shù)據(jù)
     */
    private static List parseJson(InputStream inputStream) throws Exception {
        
        List SecondActivity_Goods_Beans = new ArrayList();
        SecondActivity_Goods_Bean goodBean = null;
        byte[]  data = StreamTool.read(inputStream);
        String json = new String(data);
        JSONArray array = new JSONArray(json);
        for(int i=0;i

八 向服務(wù)器提交數(shù)據(jù):

    private static String sendPostRequest(String path,Map parame, String encoding) 
    throws Exception {
        //StringBuilder 來(lái)組合成這段數(shù)據(jù) 發(fā)給服務(wù)器      telephone_number=telephone_number&password=password 
        StringBuilder data = new StringBuilder();
        if(parame != null && !parame.isEmpty()){
            for(Map.Entry entry:parame.entrySet()){
                data.append(entry.getKey()).append("=");
                data.append(URLEncoder.encode(entry.getValue(), encoding));
                data.append("&");
            }
            data.deleteCharAt(data.length() -1);//最后會(huì)多出 “&”
        }
        byte[] entity = data.toString().getBytes();//默認(rèn)得到UTF-8的字節(jié)碼
        HttpURLConnection conn = (HttpURLConnection) new URL(path).openConnection();
        conn.setConnectTimeout(5000);
        conn.setRequestMethod("POST"); //采用 POST 向服務(wù)器發(fā)送請(qǐng)求
        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");//設(shè)置Post請(qǐng)求的 頭字段
        conn.setRequestProperty("Content-Length", String.valueOf(entity.length));//設(shè)置Post請(qǐng)求的 頭字段
        
        OutputStream outStream = conn.getOutputStream();//得到數(shù)據(jù)輸出流
        outStream.write(entity);//將數(shù)據(jù)寫(xiě)給 http輸出流緩沖區(qū)
        
        if(conn.getResponseCode() == 200){ //的android客戶(hù)端向服務(wù)器請(qǐng)求 請(qǐng)求碼 時(shí) 數(shù)據(jù)輸出流的緩沖區(qū)才把數(shù)據(jù)寫(xiě)給服務(wù)器
            //String s =  conn.getResponseMessage();//這個(gè)方法得到字符串 “OK”
            /*
             * 得到服務(wù)器返回的數(shù)據(jù)?。?!  得到服務(wù)器的返回值就可以判斷數(shù)據(jù)是否上傳成功
             */
            byte[] stringData =  StreamTool.read(conn.getInputStream());
            String stringFlag = new String(stringData,"UTF-8");
            return stringFlag; // 數(shù)據(jù)發(fā)送成功 返回 true
        }
        return "Submit_Fail";
    }

九 SharedPreferences

public class SharedPreferences_Service {
    private Context context;
    private SharedPreferences sp;
    public SharedPreferences_Service(Context applicationCon){
        this.context = applicationCon;
    }
    /**
     * 將 文件存儲(chǔ)在  File Explorer的data/data/相應(yīng)的包名/Rsgistered_form.xml 下導(dǎo)出該文件
     * @param name
     * @param telephone_number
     * @param password
     */
    public void SetParament(String name,String telephone_number,String password){
        sp = context.getSharedPreferences("Rsgistered_form", context.MODE_APPEND);
        Editor et = sp.edit();
        et.putString("name", name);
        et.putString("telephone_number",telephone_number);
        et.putString("password",password);
        et.commit();
    }
    /**
     * 在文件夾  File Explorer的data/data/相應(yīng)的 Rsgistered_form.xml下取數(shù)據(jù)
     * @return
     */
    public Map GetParament(){
        Map parmes = new HashMap();
        sp = context.getSharedPreferences("Rsgistered_form", context.MODE_APPEND);
        parmes.put("name", sp.getString("name", ""));//獲得name字段,參數(shù)為空就返回空
        parmes.put("telephone_number", sp.getString("telephone_number", ""));
        parmes.put("password", sp.getString("password", ""));
        return parmes;
    }
}



    












來(lái)源: 
 
也可以在 drawable 文件夾下 在定義個(gè)  xxx.xml  使用 selector


  
  
定義一個(gè)有四個(gè)角弧度的 長(zhǎng)方形背景


    
    
    
    
    
    
    

十一 anim文件

// anim 文件夾下 的  out.xml 動(dòng)畫(huà)文件


    
    
     
     
          

2016 - 7 - 24 ..........................更新...........................

十二 ,將 Raw 加載數(shù)據(jù)庫(kù) 導(dǎo)入 手機(jī)文件夾下

private SQLiteDatabase openDatabase(String dbfile) {

        try {
            if (!(new File(dbfile).exists())) {
                //判斷數(shù)據(jù)庫(kù)文件是否存在,若不存在則執(zhí)行導(dǎo)入,否則直接打開(kāi)數(shù)據(jù)庫(kù)
                InputStream is = this.context.getResources().openRawResource(R.raw.china_city); //欲導(dǎo)入的數(shù)據(jù)庫(kù)
                FileOutputStream fos = new FileOutputStream(dbfile);
                byte[] buffer = new byte[BUFFER_SIZE];
                int count = 0;
                while ((count = is.read(buffer)) > 0) {
                    fos.write(buffer, 0, count);
                }
                fos.close();
                is.close();
            }
            return SQLiteDatabase.openOrCreateDatabase(dbfile, null);
        } catch (FileNotFoundException e) {
            PLog.e("File not found");
            e.printStackTrace();
        } catch (IOException e) {
            PLog.e("IO exception");
            e.printStackTrace();
        }

        return null;
    }

十三 , 雙擊退出應(yīng)用

 
public class DoubleClickExit {
    /**
     * 雙擊退出檢測(cè), 閾值 2000ms
     */
    public static long lastClick = 0L;
    private static final int THRESHOLD = 2000;// 2000ms
    public static boolean check() {
        long now = System.currentTimeMillis();
        boolean b = now - lastClick < THRESHOLD;
        lastClick = now;
        return b;
    }
}
    @Override
    public void onBackPressed() {
        if (!DoubleClickExit.check()) {
                ToastUtil.showShort(getString(R.string.double_exit));
            } else {
                finish();
            }
    }

2016 - 7 - 27 ..........................更新...........................

十四 EditText 一些設(shè)置:

//設(shè)置點(diǎn)擊后 軟鍵盤(pán)的 顯示類(lèi)型 ,numberDecimal帶小數(shù)點(diǎn)的數(shù)字
android:inputType="numberDecimal"
// 設(shè)置alertDialog中的 editView  自動(dòng)彈出軟鍵盤(pán)
 editView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
            @Override
            public void onFocusChange(View v, boolean hasFocus) {
                if (hasFocus) {
                    // 設(shè)置 彈出軟鍵盤(pán)
                    alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
                }
            }
        });

十五 Calendar

mCalendar= Calendar.getInstance();//獲取當(dāng)前日期
        int_YEAR = mCalendar.get(Calendar.YEAR);
        int_MONTH = mCalendar.get(Calendar.MONTH);
        int_DAT = mCalendar.get(Calendar.DAY_OF_MONTH);
        int_lastday=mCalendar.getActualMaximum(Calendar.DAY_OF_MONTH);
        int_week =  mCalendar.get(Calendar.DAY_OF_WEEK);

十六 DialogFragment ,DialogFragment官方推薦使用的,好處就不多說(shuō)

public class YourDialogFragment extends DialogFragment {
  

    public interface DialogFragmentDataImp{//定義一個(gè)與Activity通信的接口,使用該DialogFragment的Activity須實(shí)現(xiàn)該接口
        void showMessage(String message);
    }

    public static YourDialogFragment newInstance(String message){
        //創(chuàng)建一個(gè)帶有參數(shù)的Fragment實(shí)例
        YourDialogFragment fragment = new YourDialogFragment ();
        Bundle bundle = new Bundle();
        bundle.putString("message", message);
        fragment.setArguments(bundle);//把參數(shù)傳遞給該DialogFragment
        return fragment;
    }
    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        View customView = LayoutInflater.from(getActivity()).inflate(
                R.layout.fragment_edit_bill_dialog, null);
        //ButterKnife.bind(this,customView);
        mContext = getActivity();

        initView();

        return new AlertDialog.Builder(getActivity()).setView(customView)
                .create();
    }

使用(在 activity 或 fragment 調(diào)用):

 YourDialogFragment dialog = new YourDialogFragment();
        dialog.show(getFragmentManager(), "loginDialog");

文章版權(quán)歸作者所有,未經(jīng)允許請(qǐng)勿轉(zhuǎn)載,若此文章存在違規(guī)行為,您可以聯(lián)系管理員刪除。

轉(zhuǎn)載請(qǐng)注明本文地址:http://systransis.cn/yun/64947.html

相關(guān)文章

發(fā)表評(píng)論

0條評(píng)論

最新活動(dòng)
閱讀需要支付1元查看
<