Android——Tomcat版本更新下載+頭像照片上傳到Tomcat

[java] view plain copy
  1. package com.example.schoolappzyf;  
  2.   
  3. import android.app.Notification;  
  4. import android.app.NotificationManager;  
  5. import android.app.PendingIntent;  
  6. import android.content.Intent;  
  7. import android.content.pm.PackageManager;  
  8. import android.net.Uri;  
  9. import android.os.AsyncTask;  
  10. import android.os.Bundle;  
  11. import android.support.v7.app.AppCompatActivity;  
  12. import android.support.v7.app.NotificationCompat;  
  13. import android.util.Log;  
  14. import android.view.View;  
  15. import android.widget.Button;  
  16. import android.widget.TextView;  
  17. import android.widget.Toast;  
  18.   
  19. import com.example.schoolappzyf.util.File5Uitlity;  
  20. import com.example.schoolappzyf.util.HttpUtil;  
  21. import com.example.schoolappzyf.util.UrlUtil;  
  22.   
  23. import org.json.JSONException;  
  24. import org.json.JSONObject;  
  25.   
  26. import java.io.BufferedOutputStream;  
  27. import java.io.File;  
  28. import java.io.FileOutputStream;  
  29. import java.io.IOException;  
  30. import java.io.InputStream;  
  31. import java.net.HttpURLConnection;  
  32. import java.net.MalformedURLException;  
  33. import java.net.URL;  
  34.   
  35. public class DownloadActivity extends AppCompatActivity {  
  36.     private TextView tv1, tv2,gx;  
  37.     private int i,vid;  
  38.     private Button denglu, tuichu;  
  39.     private NotificationManager nm;  
  40.     private NotificationCompat.Builder builder;  
  41.     private Notification nf;  
  42.   
  43.     @Override  
  44.     protected void onCreate(Bundle savedInstanceState) {  
  45.         super.onCreate(savedInstanceState);  
  46.         setContentView(R.layout.activity_download);  
  47.         denglu = (Button) findViewById(R.id.denglu);  
  48.         tuichu = (Button) findViewById(R.id.tuichu);  
  49.         tv1 = (TextView) findViewById(R.id.tv1);  
  50.         tv2 = (TextView) findViewById(R.id.tv2);  
  51.         gx = (TextView) findViewById(R.id.gx);  
  52.         String ur2 = UrlUtil.schoolUrl + "apk";  
  53.         new Getapk().execute(ur2);  
  54.   
  55.         try {  
  56.             //獲取當前版本  
  57.             vid = getPackageManager().getPackageInfo(this.getPackageName(), 0)  
  58.                     .versionCode;  
  59.             Log.d("????1?", vid + "");  
  60.             tv1.setText(vid + "");  
  61.   
  62.   
  63.         } catch (PackageManager.NameNotFoundException e) {  
  64.             e.printStackTrace();  
  65.         }  
  66.   
  67.   
  68.         tuichu.setOnClickListener(new View.OnClickListener() {  
  69.             @Override  
  70.             public void onClick(View view) {  
  71.                 finish();  
  72.             }  
  73.         });  
  74.   
  75.         denglu.setOnClickListener(new View.OnClickListener() {  
  76.             @Override  
  77.             public void onClick(View view) {  
  78.                 if (vid<i) {  
  79.                     String url = UrlUtil.schoolUrl + "apk/cc.apk";  
  80.                     new DownLoasAPK().execute(url);  
  81.                 }else {  
  82.                     Toast.makeText(getBaseContext(), "不需要更新", Toast.LENGTH_SHORT).show();  
  83.                 }  
  84.             }  
  85.         });  
  86.         //構建通知欄  
  87.         nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);  
  88.         builder =  
  89.                 new NotificationCompat.Builder(getBaseContext());  
  90.         builder.setContentTitle("下載");  
  91.         builder.setContentText("校園通正在下載");  
  92.         builder.setSmallIcon(R.mipmap.ic_launcher);  
  93.   
  94.     }  
  95.   
  96.     public class DownLoasAPK extends AsyncTask<String, Integer, String> {  
  97.         int i = 0;  
  98.   
  99.         @Override  
  100.         protected void onPreExecute() {  
  101.             super.onPreExecute();  
  102.             nf = builder.build();  
  103.             nm.notify(0, nf);  
  104.         }  
  105.   
  106.         @Override  
  107.         protected void onPostExecute(String s) {  
  108.             super.onPostExecute(s);  
  109.         }  
  110.   
  111.         //子線程  
  112.         @Override  
  113.         protected String doInBackground(String... strings) {  
  114.             HttpURLConnection connection = null;  
  115.             InputStream is = null;  
  116.             BufferedOutputStream bos = null;  
  117.             try {  
  118.                 URL url = new URL(strings[0]);  
  119.                 connection = (HttpURLConnection) url.openConnection();  
  120.                 connection.setConnectTimeout(5 * 1000);  
  121.                 connection.setReadTimeout(5 * 1000);  
  122.                 if (connection.getResponseCode() == 200) {  
  123.                     is = connection.getInputStream();  
  124. //                    File5Uitlity.getInstance(DownloadActivity.this,  
  125. //                            getPackageName());  
  126. //                    File root = Environment.getExternalStorageDirectory();  
  127. //                    File apk = new File(root+"/"+getPackageName(),"testtt.apk");  
  128. //                    Log.d("?????66",root+"");  
  129.   
  130. //  
  131.                     String root = File5Uitlity.getInstance(DownloadActivity.this, getPackageName())  
  132.                             .ROOT_CACHE;  
  133.   
  134.                     Log.d("?????++", root);  
  135.                     File apk = new File(root, "testtt.apk");  
  136.                     Log.d("?????++", apk + "");  
  137.   
  138.                     bos = new BufferedOutputStream(  
  139.                             new FileOutputStream(apk));  
  140.                     int next = 0;  
  141.                     int length = connection.getContentLength();  
  142.                     double currentprogress = 0;  
  143.                     byte[] b = new byte[1024 * 1024 * 10];  
  144.                     while ((next = is.read(b)) > 0) {  
  145.   
  146.                         currentprogress += next;  
  147.                         bos.write(b, 0, next);  
  148.                         Log.d("?????", currentprogress + "");  
  149.                         int progress = (int) (currentprogress / length * 100);  
  150.                         publishProgress(progress);  
  151.   
  152.                     }  
  153.   
  154.                 }  
  155.   
  156.   
  157.             } catch (MalformedURLException e) {  
  158.                 e.printStackTrace();  
  159.             } catch (IOException e) {  
  160.                 e.printStackTrace();  
  161.             } finally {  
  162.   
  163.                 try {  
  164.                     if (bos != null) {  
  165.   
  166.                         bos.flush();  
  167.                         bos.close();  
  168.                     }  
  169.   
  170.                 } catch (IOException e) {  
  171.                     e.printStackTrace();  
  172.                 }  
  173.             }  
  174.   
  175.   
  176.             return null;  
  177.         }  
  178.   
  179.         @Override  
  180.         protected void onProgressUpdate(Integer... values) {  
  181.             super.onProgressUpdate(values);  
  182.             ;  
  183.             if (i == values[0]) {  
  184.                 return;  
  185.             }  
  186.             i = values[0];  
  187.             builder.setProgress(100, values[0], false);  
  188.             Log.d("====values=""" + values[0]);  
  189.             nf = builder.build();  
  190.             nm.notify(0, nf);  
  191.             if (values[0] == 100) {  
  192.                 Intent it = new Intent(Intent.ACTION_VIEW);  
  193.                 it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
  194.   
  195.                 it.setDataAndType(Uri.parse("file:///sdcard/"  
  196.                                 + "imagCache" + "/testtt.apk"),  
  197.                         "application/vnd.android.package-archive");  
  198.                 PendingIntent pi = PendingIntent  
  199.                         .getActivity(DownloadActivity.this,  
  200.                                 0,  
  201.                                 it,  
  202.                                 PendingIntent.FLAG_UPDATE_CURRENT);  
  203.                 builder.setContentIntent(pi)  
  204.                         .setAutoCancel(true)  
  205.                         .setContentText("點擊安裝")  
  206.                         .setContentTitle("下載完成");  
  207.                 nf = builder.build();  
  208.                 nm.notify(0, nf);  
  209.             }  
  210.   
  211.         }  
  212.   
  213.   
  214.     }  
  215.   
  216.     public class Getapk extends AsyncTask<String, Void, String> {  
  217.   
  218.   
  219.         @Override  
  220.         protected String doInBackground(String... strings) {  
  221.             // url= UrlUtil.schoolUrl+strings[0];  
  222.   
  223.             return HttpUtil.HttpGet(strings[0]);  
  224.         }  
  225.   
  226.         @Override  
  227.         protected void onPostExecute(String s) {  
  228.             super.onPostExecute(s);  
  229.             if (s == null) {  
  230.                 Toast.makeText(getBaseContext(), "沒有數據網路不好", Toast.LENGTH_SHORT).show();  
  231.   
  232.             } else {  
  233.                 try {  
  234.                     JSONObject obj = new JSONObject(s);  
  235.                     tv2.setText(obj.getString("vid"));  
  236.                     i= Integer.parseInt(obj.getString("vid"));  
  237.                     if (vid<i){  
  238.                         gx.setText("新版本可點擊更新");  
  239.                     }  
  240.                 } catch (JSONException e) {  
  241.                     e.printStackTrace();  
  242.                 }  
  243.   
  244.   
  245.             }  
  246.   
  247.   
  248.         }  
  249.     }  
  250.   
  251.   
  252. }  

[html] view plain copy
  1. <?xml version="1.0" encoding="utf-8"?>  
  2. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  3.     xmlns:tools="http://schemas.android.com/tools"  
  4.     android:layout_width="match_parent"  
  5.     android:layout_height="match_parent"  
  6.   
  7.     tools:context="com.example.schoolappzyf.DownloadActivity">  
  8.     <LinearLayout  
  9.         android:layout_width="match_parent"  
  10.         android:layout_height="match_parent"  
  11.         android:orientation="vertical">  
  12.         <TextView  
  13.             android:layout_width="match_parent"  
  14.             android:layout_height="70dp"  
  15.             />  
  16.         <TextView  
  17.             android:layout_width="match_parent"  
  18.             android:layout_height="80dp"  
  19.             android:id="@+id/gx"  
  20.             android:text="最新版本不需更新"  
  21.             android:gravity="center"  
  22.             android:textSize="25sp"  
  23.   
  24.   
  25.             />  
  26.         <TextView  
  27.             android:layout_width="match_parent"  
  28.             android:layout_height="30dp"  
  29.             android:textSize="25sp"  
  30.             android:text="當前版本"  
  31.             />  
  32.         <TextView  
  33.             android:layout_width="match_parent"  
  34.             android:layout_height="30dp"  
  35.             android:textSize="25sp"  
  36.             android:text="無"  
  37.             android:id="@+id/tv1"  
  38.             android:layout_marginLeft="260dp"  
  39.             />  
  40.   
  41.         <TextView  
  42.             android:layout_width="match_parent"  
  43.             android:layout_height="30dp"  
  44.             android:textSize="25sp"  
  45.             android:text="現在版本"  
  46.   
  47.             />  
  48.         <TextView  
  49.             android:layout_width="match_parent"  
  50.             android:layout_height="30dp"  
  51.             android:textSize="25sp"  
  52.             android:text="無"  
  53.             android:id="@+id/tv2"  
  54.             android:layout_marginLeft="260dp"  
  55.             />  
  56.         <Button  
  57.             android:layout_width="match_parent"  
  58.             android:layout_height="80dp"  
  59.             android:id="@+id/denglu"  
  60.             android:text="更新下載"  
  61.             android:textSize="25sp"/>  
  62.         <Button  
  63.             android:layout_width="match_parent"  
  64.             android:layout_height="80dp"  
  65.             android:id="@+id/tuichu"  
  66.             android:text="稍後更新並退出"  
  67.             android:textSize="25sp"/>  
  68.     </LinearLayout>  
  69.   
  70. </RelativeLayout>  

保存文件位置工具

[java] view plain copy
  1. package com.example.schoolappzyf.util;  
  2.   
  3. import android.content.Context;  
  4. import android.os.Environment;  
  5. import android.util.Log;  
  6.   
  7. import java.io.BufferedReader;  
  8. import java.io.File;  
  9. import java.io.FileInputStream;  
  10. import java.io.FileNotFoundException;  
  11. import java.io.FileOutputStream;  
  12. import java.io.IOException;  
  13. import java.io.InputStreamReader;  
  14.   
  15.   
  16. public class File5Uitlity {  
  17.     public static String ROOT_CACHE;  
  18.     public static File5Uitlity instance = null;  
  19.     private File5Uitlity() {  
  20.     }  
  21.     //創建文件夾  
  22.     public static File5Uitlity getInstance(Context context, String root_dir) {  
  23.         if (instance == null) {  
  24.             if (Environment.getExternalStorageState().equals(  
  25.                     Environment.MEDIA_MOUNTED)) {  
  26.                 ROOT_CACHE = (Environment.getExternalStorageDirectory() + "/"  
  27.                         + root_dir + "/");  
  28.             } else {  
  29.                 ROOT_CACHE = (context.getFilesDir().getAbsolutePath() + "/"+root_dir+"/");  
  30.             }  
  31.             File dir = new File(ROOT_CACHE);  
  32.             if (!dir.exists()) {  
  33.                 dir.mkdirs();  
  34.             }  
  35.             instance = new File5Uitlity();  
  36.         }else{  
  37.             File dir = new File(ROOT_CACHE+"/"+root_dir);  
  38.             if (!dir.exists()) {  
  39.                 dir.mkdirs();  
  40.             }  
  41.         }  
  42.         return instance;  
  43.     }  
  44.     public File makeDir(String dir) {  
  45.         File fileDir = new File(ROOT_CACHE + dir);  
  46.         if (fileDir.exists()) {  
  47.             return fileDir;  
  48.         } else {  
  49.             fileDir.mkdirs();  
  50.             return fileDir;  
  51.         }  
  52.     }  
  53.     //判斷文件是否存在SD卡  
  54.     public static boolean fileExists(String fileName){  
  55.         String state = Environment.getExternalStorageState();  
  56.         if(!state.equals(Environment.MEDIA_MOUNTED)){  
  57.             return false;  
  58.         }else{  
  59.   
  60.             File file = new File(ROOT_CACHE,fileName);  
  61.             return  file.exists();  
  62.         }  
  63.     }  
  64.     //保存文件到SD卡  
  65.     public static String saveFileToSdcard(String fileName,String content){  
  66.         String state = Environment.getExternalStorageState();  
  67.         if(!state.equals(Environment.MEDIA_MOUNTED)){  
  68.             Log.d("=====","文件保存失敗11");  
  69.   
  70.             return "SD卡未就緒";  
  71.         }  
  72.         FileOutputStream fos = null;  
  73.         try {  
  74.             fos = new FileOutputStream(ROOT_CACHE+"/"+fileName);  
  75.             fos.write(content.getBytes());  
  76.             return "ok";  
  77.         } catch (FileNotFoundException e) {  
  78.             e.printStackTrace();  
  79.         } catch (IOException e) {  
  80.             e.printStackTrace();  
  81.         } finally {  
  82.             if(fos!=null){  
  83.                 try {  
  84.                     fos.close();  
  85.                 } catch (IOException e) {  
  86.                     e.printStackTrace();  
  87.                 }  
  88.             }  
  89.         }  
  90.         return "";  
  91.     }  
  92.     //讀取SD卡文件  
  93.     public static String readFileFromSdcard(String fileName){  
  94.         String statue = Environment.getExternalStorageState();  
  95.         if(!statue.equals(Environment.MEDIA_MOUNTED)){  
  96.             return "";  
  97.         }else{  
  98.             BufferedReader reader =null;  
  99.             FileInputStream fis = null;  
  100.             StringBuilder sbd = new StringBuilder();  
  101.             try {  
  102.                 fis = new FileInputStream(ROOT_CACHE+"/"+fileName);  
  103.                 reader = new BufferedReader(new InputStreamReader(fis));  
  104.                 String row = "";  
  105.                 while ((row=reader.readLine())!=null){  
  106.                     sbd.append(row);  
  107.                 }  
  108.             } catch (FileNotFoundException e) {  
  109.                 e.printStackTrace();  
  110.             } catch (IOException e) {  
  111.                 e.printStackTrace();  
  112.             } finally {  
  113.                 if(reader!=null){  
  114.                     try {  
  115.                         reader.close();  
  116.                     } catch (IOException e) {  
  117.                         e.printStackTrace();  
  118.                     }  
  119.                 }  
  120.             }  
  121.             return sbd.toString();  
  122.         }  
  123.     }  
  124.   
  125.   
  126.   
  127. }  

[java] view plain copy
  1. package com.example.schoolappzyf.util;  
  2.   
  3. import android.content.Context;  
  4. import android.os.Environment;  
  5.   
  6. import java.io.BufferedReader;  
  7. import java.io.File;  
  8. import java.io.FileInputStream;  
  9. import java.io.FileNotFoundException;  
  10. import java.io.FileOutputStream;  
  11. import java.io.IOException;  
  12. import java.io.InputStreamReader;  
  13.   
  14. //      String httpUrl="http://apis.baidu.com/showapi_open_bus/channel_news/search_news";  
  15. //      String httpArg="channelId=5572a109b3cdc86cf39001db&channelName=%E5%9B%BD%E5%86%85%E6%9C%80%E6%96%B0&title=%E4%B8%8A%E5%B8%82&page=1&needContent=0&needHtml=0";  
  16.   
  17. public class FileUitlity6 {  
  18.     public static String ROOT_CACHE;  
  19.     public static FileUitlity6 instance = null;  
  20.     private FileUitlity6() {  
  21.     }  
  22.     //創建文件夾  
  23.     public static FileUitlity6 getInstance(Context context,String root_dir) {  
  24.         if (instance == null) {  
  25.             if (Environment.getExternalStorageState().equals(  
  26.                     Environment.MEDIA_MOUNTED)) {  
  27.                 ROOT_CACHE = (Environment.getExternalStorageDirectory() + "/"  
  28.                         + root_dir + "/");  
  29.             } else {  
  30.   
  31.             }  
  32.             File dir = new File(ROOT_CACHE);  
  33.             if (!dir.exists()) {  
  34.                 dir.mkdirs();  
  35.             }  
  36.             instance = new FileUitlity6();}  
  37. //      else{  
  38. //          ROOT_CACHE = (context.getFilesDir().getAbsolutePath() + "/"+root_dir+"/");  
  39. //          File dir=new File(ROOT_CACHE);  
  40. //          if (!dir.exists()){  
  41. //              dir.mkdirs();  
  42. //          }  
  43. //      }  
  44.         return instance;  
  45.     }  
  46.     //  
  47.     public File makeDir(String dir) {  
  48.         File fileDir = new File(ROOT_CACHE + dir);  
  49.         if (fileDir.exists()) {  
  50.             return fileDir;  
  51.         } else {  
  52.             fileDir.mkdirs();  
  53.             return fileDir;  
  54.         }  
  55.     }  
  56.   
  57.     //判斷文件是否存在SD卡  
  58.     public static boolean fileExists(String fileName){  
  59.         String state=Environment.getExternalStorageState();  
  60.         if (!state.equals(Environment.MEDIA_MOUNTED)){  
  61.             return false;  
  62.         }else {  
  63.             File root=Environment.getExternalStorageDirectory();  
  64.             File file=new File(root,fileName);  
  65.             return file.exists();  
  66.         }  
  67.     }  
  68.   
  69.     //保存文件  
  70.     public static String saveFileToSdcard(String fileName, String content){  
  71.         String state = Environment.getExternalStorageState();  
  72.         if(!state.equals(Environment.MEDIA_MOUNTED)){  
  73.             return "SD卡未就緒";  
  74.         }  
  75.         File root = Environment.getExternalStorageDirectory();  
  76.         FileOutputStream fos = null;  
  77.         try {  
  78.             fos = new FileOutputStream(root+"/"+fileName);  
  79.             fos.write(content.getBytes());  
  80.             return "ok";  
  81.         } catch (FileNotFoundException e) {  
  82.             e.printStackTrace();  
  83.         } catch (IOException e) {  
  84.             e.printStackTrace();  
  85.         } finally {  
  86.             if(fos!=null){  
  87.                 try {  
  88.                     fos.close();  
  89.                 } catch (IOException e) {  
  90.                     e.printStackTrace();  
  91.                 }  
  92.             }  
  93.         }  
  94.         return "";  
  95.     }  
  96. //讀取文件  
  97.     public static String readFileFromSdcard(String fileName){  
  98.         String statue=Environment.getExternalStorageState();  
  99.         if (!statue.equals(Environment.MEDIA_MOUNTED)){  
  100.             return "";  
  101.         }else {  
  102.             File root=Environment.getExternalStorageDirectory();  
  103.             BufferedReader reader=null;  
  104.             FileInputStream fis=null;  
  105.             StringBuilder sbd=new StringBuilder();  
  106.             try {  
  107.                 fis=new FileInputStream(root+"/"+fileName);  
  108.                 reader=new BufferedReader(new InputStreamReader(fis));  
  109.                 String row="";  
  110.                 while ((row=reader.readLine())!=null){  
  111.                     sbd.append(row);  
  112.                 }  
  113.             } catch (FileNotFoundException e) {  
  114.                 e.printStackTrace();  
  115.             } catch (IOException e) {  
  116.                 e.printStackTrace();  
  117.             }finally {  
  118.                 if (reader!=null){  
  119.                     try {  
  120.                         reader.close();  
  121.                     } catch (IOException e) {  
  122.                         e.printStackTrace();  
  123.                     }  
  124.                 }  
  125.             }  
  126.             return sbd.toString();  
  127.         }  
  128.   
  129.     }  
  130.       
  131. }  
???????????????????????
[java] view plain copy
  1. package com.example.administrator.jreduch07;  
  2.   
  3. import android.app.Notification;  
  4. import android.app.NotificationManager;  
  5. import android.app.PendingIntent;  
  6. import android.content.Intent;  
  7. import android.content.pm.PackageManager;  
  8. import android.net.Uri;  
  9. import android.os.AsyncTask;  
  10. import android.os.Bundle;  
  11. import android.os.Environment;  
  12. import android.support.v7.app.AppCompatActivity;  
  13. import android.support.v7.app.NotificationCompat;  
  14. import android.view.View;  
  15. import android.widget.Button;  
  16. import android.widget.TextView;  
  17.   
  18. import com.example.administrator.jreduch07.util.FileUitlity;  
  19.   
  20. import java.io.BufferedOutputStream;  
  21. import java.io.File;  
  22. import java.io.FileOutputStream;  
  23. import java.io.IOException;  
  24. import java.io.InputStream;  
  25. import java.net.HttpURLConnection;  
  26. import java.net.MalformedURLException;  
  27. import java.net.URL;  
  28.   
  29. public class DownloadActivity extends AppCompatActivity {  
  30.     private Button button ;  
  31.     private TextView show;  
  32.     private NotificationManager nm;  
  33.     private NotificationCompat.Builder builder;  
  34.     private Notification nf;  
  35.     @Override  
  36.     protected void onCreate(Bundle savedInstanceState) {  
  37.         super.onCreate(savedInstanceState);  
  38.         setContentView(R.layout.activity_download);  
  39.         button = (Button) findViewById(R.id.download);  
  40.         show = (TextView) findViewById(R.id.show);  
  41.         try {//獲得當前apk版本號  
  42.             int vid = getPackageManager().getPackageInfo(getPackageName(),0).versionCode;  
  43.             show.setText("當前版本號:"+vid);  
  44.         } catch (PackageManager.NameNotFoundException e) {  
  45.             e.printStackTrace();  
  46.         }  
  47.         button.setOnClickListener(new View.OnClickListener() {  
  48.             @Override  
  49.             public void onClick(View view) {  
  50.                 String url = "http://192.168.1.33:8080/SchoolLife/apk/cc.apk";  
  51.                 new DownLoadApk().execute(url);  
  52.             }  
  53.         });  
  54.         //構建通知欄  
  55.         nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);  
  56.         builder =  
  57.                 new NotificationCompat.Builder(getBaseContext());  
  58.         builder.setContentTitle("下載");  
  59.         builder.setContentText("校園通正在下載");  
  60.         builder.setSmallIcon(R.mipmap.ic_launcher);  
  61.     }  
  62.     public class DownLoadApk extends AsyncTask<String,Integer,String>{  
  63.         @Override  
  64.         protected void onPreExecute() {  
  65.             super.onPreExecute();  
  66.             nf = builder.build();  
  67.             nm.notify(0,nf);  
  68.         }  
  69.         @Override  
  70.         protected String doInBackground(String... strings) {  
  71.             HttpURLConnection connection = null;  
  72.             InputStream is = null;  
  73.             BufferedOutputStream bos = null;  
  74.             try {  
  75.                 URL url = new URL(strings[0]);  
  76.                 connection = (HttpURLConnection) url.openConnection();  
  77.                 connection.setConnectTimeout(5*1000);  
  78.                 connection.setReadTimeout(5*1000);  
  79.                 if(connection.getResponseCode()==200){  
  80.                     is = connection.getInputStream();  
  81.                     FileUitlity.getInstance(DownloadActivity.this,  
  82.                             getPackageName());  
  83.                     File root = Environment.getExternalStorageDirectory();  
  84.                     File apk = new File(root+"/"+getPackageName(),"test.apk");  
  85.                     bos = new BufferedOutputStream(  
  86.                                     new FileOutputStream(apk));  
  87.                     int next = 0;  
  88.                     byte[] b = new byte[1024*1024*10];  
  89.                     int length = connection.getContentLength();  
  90.                     double currentProgress = 0;  
  91.                     while((next=is.read(b))>0){  
  92.                         currentProgress += next ;  
  93.                         int progress = (int)(currentProgress/length *100);  
  94.                         publishProgress(progress);  
  95.                         bos.write(b,0,next);  
  96.                     }  
  97.                 }  
  98.             } catch (MalformedURLException e) {  
  99.                 e.printStackTrace();  
  100.             } catch (IOException e) {  
  101.                 e.printStackTrace();  
  102.             } finally {  
  103.                 try {  
  104.                     if(bos!=null){  
  105.                         bos.flush();  
  106.                         bos.close();  
  107.                     }  
  108.                 } catch (IOException e) {  
  109.                     e.printStackTrace();  
  110.                 }  
  111.             }  
  112.             return null;  
  113.         }  
  114.         @Override  
  115.         protected void onPostExecute(String s) {  
  116.             super.onPostExecute(s);  
  117.         }  
  118.         @Override  
  119.         protected void onProgressUpdate(Integer... values) {  
  120.             super.onProgressUpdate(values);  
  121.             builder.setProgress(100,values[0],false);  
  122.             nf = builder.build();  
  123.             nm.notify(0,nf);  
  124.             if(values[0]==100){  
  125.                 Intent it = new Intent(Intent.ACTION_VIEW);  
  126.                 it.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
  127.                 it.setDataAndType(Uri.parse("file:///sdcard/"  
  128.                         +getPackageName()+"/test.apk"),  
  129.                         "application/vnd.android.package-archive");  
  130.                 PendingIntent pi  = PendingIntent  
  131.                         .getActivity(DownloadActivity.this,  
  132.                                 0,  
  133.                                 it,  
  134.                                 PendingIntent.FLAG_UPDATE_CURRENT);  
  135.                 builder.setContentIntent(pi)  
  136.                         .setAutoCancel(true)  
  137.                         .setContentText("點擊安裝")  
  138.                         .setContentTitle("下載完成");  
  139.                 nf = builder.build();  
  140.                 nm.notify(0,nf);  
  141.             }  
  142.         }  
  143.     }  
  144. }  

頭像上傳

[java] view plain copy
  1. package com.example.schoolappzyf;  
  2.   
  3. import android.app.Activity;  
  4. import android.content.DialogInterface;  
  5. import android.content.Intent;  
  6. import android.content.SharedPreferences;  
  7. import android.database.Cursor;  
  8. import android.graphics.Bitmap;  
  9. import android.graphics.drawable.ColorDrawable;  
  10. import android.net.Uri;  
  11. import android.os.Bundle;  
  12. import android.provider.MediaStore;  
  13. import android.support.v7.app.AlertDialog;  
  14. import android.support.v7.app.AppCompatActivity;  
  15. import android.util.Base64;  
  16. import android.view.Gravity;  
  17. import android.view.View;  
  18. import android.view.WindowManager;  
  19. import android.widget.Button;  
  20. import android.widget.LinearLayout;  
  21. import android.widget.PopupWindow;  
  22. import android.widget.Switch;  
  23. import android.widget.TextView;  
  24.   
  25. import com.android.volley.RequestQueue;  
  26. import com.android.volley.Response;  
  27. import com.android.volley.VolleyError;  
  28. import com.android.volley.toolbox.Volley;  
  29. import com.bumptech.glide.Glide;  
  30. import com.example.schoolappzyf.dao.UserdlDao;  
  31. import com.example.schoolappzyf.entity.User;  
  32. import com.example.schoolappzyf.util.FileUitlity1;  
  33. import com.example.schoolappzyf.util.RoundImageView;  
  34. import com.example.schoolappzyf.util.StringPostRequest;  
  35. import com.example.schoolappzyf.util.UrlUtil;  
  36.   
  37. import java.io.ByteArrayOutputStream;  
  38. import java.io.File;  
  39. import java.io.IOException;  
  40.   
  41. public class SZActivity  extends AppCompatActivity implements View.OnClickListener {  
  42.     private PopupWindow pw;  
  43.     private View popView;  
  44.     private TextView name,tv1,show,tv3;  
  45.     private Button bc,exit;  
  46.     private Switch sszd,ssjz;  
  47.     private RoundImageView riv;  
  48.     private RequestQueue requestQueue;  
  49.   
  50. private  UserdlDao userdlDao;  
  51.     private User user;  
  52.   
  53.     private SharedPreferences sp;  
  54.   
  55.     @Override  
  56.     protected void onCreate(Bundle savedInstanceState) {  
  57.         super.onCreate(savedInstanceState);  
  58.         setContentView(R.layout.activity_sz);  
  59.         requestQueue = Volley.newRequestQueue(this);  
  60.         getSupportActionBar().hide();  
  61.         //加載PopWindow中的佈局  
  62.         popView = getLayoutInflater().inflate(R.layout.pop_layout, null);  
  63.         //從主佈局中取得控件  
  64.   
  65.         //從PopWindow佈局中取得控件  
  66.         Button xc = (Button)popView.findViewById(R.id.xc);  
  67.         Button xj = (Button)popView.findViewById(R.id.xj);  
  68.         Button bt = (Button)popView.findViewById(R.id.bt);  
  69.         name=(TextView)findViewById(R.id.name);  
  70.         show=(TextView)findViewById(R.id.show);  
  71.         tv3=(TextView)findViewById(R.id.tv3);  
  72.   
  73.   
  74.         ssjz=(Switch)findViewById(R.id.ssjz);  
  75.         sszd=(Switch)findViewById(R.id.sszd);  
  76.         bc=(Button)findViewById(R.id.bc);  
  77.        exit=(Button)findViewById(R.id.exit);  
  78.   
  79.         tv3.setOnClickListener(new View.OnClickListener() {  
  80.             @Override  
  81.             public void onClick(View view) {  
  82.                 Intent intent=new Intent(getBaseContext(),DownloadActivity.class);  
  83.                 startActivity(intent);  
  84.             }  
  85.         });  
  86.   
  87.   
  88. bc.setOnClickListener(new View.OnClickListener() {  
  89.     @Override  
  90.     public void onClick(View view) {  
  91.         SharedPreferences.Editor editor=sp.edit();  
  92.         editor.putBoolean("jzmm",ssjz.isChecked());  
  93.         editor.putBoolean("zddl",sszd.isChecked());  
  94.         editor.commit();  
  95.     }  
  96. });  
  97. exit.setOnClickListener(new View.OnClickListener() {  
  98.     @Override  
  99.     public void onClick(View view) {  
  100.         userdlDao.delectAll();  
  101.         Intent intent=new Intent(getBaseContext(),SchoolAppActivity.class);  
  102.         startActivity(intent);  
  103.     }  
  104. });  
  105.   
  106.   
  107.   
  108.   
  109.   
  110.   
  111.         riv = (RoundImageView) findViewById(R.id.riv);  
  112.         tv1=(TextView)findViewById(R.id.tv1);  
  113.         tv1.setOnClickListener(new View.OnClickListener() {  
  114.             @Override  
  115.             public void onClick(View view) {  
  116.                 Intent intent=new Intent(getBaseContext(),XGMMActivity.class);  
  117.                 startActivity(intent);  
  118.             }  
  119.         });  
  120.   
  121.   
  122.         userdlDao=new UserdlDao(getBaseContext());  
  123.        user=userdlDao.searchMewsTop().get(0);  
  124.         name.setText(userdlDao.searchMewsTop().get(0).getStuName());  
  125.         show.setText("學號:"+user.getUno()+"\n"+"用戶名:"+userdlDao.searchMewsTop().get(0).getStuName()+"\n"+  
  126.                 "班級:"+userdlDao.searchMewsTop().get(0).getClassName()+"\n"+"系別:"+user.getMajorName()+"\n"+"職位:"+user.getRole()+"\n"  
  127.         );  
  128.         Glide.with(SZActivity.this).load(userdlDao.searchMewsTop().get(0).getImg())  
  129.                 .error(R.mipmap.ic_launcher).into(riv);  
  130.   
  131.   
  132.   
  133.   
  134.   
  135.   
  136.         //註冊   本類監聽  
  137.         riv.setOnClickListener(this);  
  138.         xc.setOnClickListener(this);  
  139.         xj.setOnClickListener(this);  
  140.         bt.setOnClickListener(this);  
  141.         //顯示Intent,明確指定要跳轉的組件  
  142. //        Intent intent=new Intent(IntentActivity.this,SecondActivity.class);  
  143. //        startActivity(intent);  
  144.   
  145.         //---------------------------------------  
  146.   
  147.   
  148.     }  
  149.     @Override  
  150.     public void onClick(View v) {  
  151.         int id = v.getId();  
  152.         switch (id) {  
  153.   
  154.             case R.id.riv://點擊頭像打開PopWindow  
  155.                 pw=getPopWindow(popView);  
  156.                 break;  
  157.             case R.id.xc:  
  158.                 phonePhoto();  
  159.                 break;  
  160.             case R.id.xj:  
  161.                 takephoto();  
  162.                 break;  
  163.             case R.id.bt:  
  164.                 pw.dismiss();  
  165.                 break;  
  166.         }  
  167.     }  
  168.   
  169.   
  170.   
  171.     /* 
  172.     * 調用圖庫 
  173.     * */  
  174.     public void phonePhoto(){  
  175.         Intent intent=new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);  
  176.         startActivityForResult(intent,2);  
  177.   
  178.     }  
  179.   
  180.     /* 
  181.     * 調用相機 
  182.     * */  
  183.     private String capturePath="";  
  184.     public void takephoto(){  
  185.         Intent camera=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  
  186.         File parent= FileUitlity1.getInstance(getApplicationContext())  
  187.                 .makeDir("head_imag");  
  188.         capturePath=parent.getPath()+File.separatorChar+System.currentTimeMillis()+".jpg";  
  189.         camera.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(capturePath)));  
  190.         camera.putExtra(MediaStore.EXTRA_VIDEO_QUALITY,1);  
  191.         startActivityForResult(camera, 1);  
  192.     }  
  193.   
  194.     @Override  
  195.     protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
  196.         super.onActivityResult(requestCode, resultCode, data);  
  197.   
  198.         if (resultCode!= Activity.RESULT_OK){  
  199.   
  200.             return;  
  201.         }  
  202.         //相機返回結果,調用系統裁剪啊  
  203.         if (requestCode==1){  
  204.             startPicZoom(Uri.fromFile(new File(capturePath)));  
  205.   
  206.         }  
  207.         //相冊返回結果調用系統裁剪  
  208.         else if (requestCode==2){  
  209.             Cursor cursor=getContentResolver()  
  210.                     .query(data.getData(),new String[]{MediaStore.Images.Media.DATA}  
  211.                             ,null,null,null);  
  212.             cursor.moveToFirst();  
  213.             String  capturePath=cursor.getString(  
  214.                     cursor.getColumnIndex(  
  215.                             MediaStore.Images.Media.DATA));  
  216.             cursor.close();  
  217.             startPicZoom(Uri.fromFile(new File(capturePath)));  
  218.         }  
  219.         else if (requestCode==3){  
  220.             Bundle bundle= data.getExtras();  
  221.             if (bundle!=null){  
  222.                 final Bitmap bitmap=bundle.getParcelable("data");  
  223.                 riv.setImageBitmap(bitmap);  
  224.                 pw.dismiss();  
  225.                 AlertDialog.Builder  alter =  
  226.                         new AlertDialog.Builder(this)  
  227.                                 .setPositiveButton("上傳"new DialogInterface.OnClickListener() {  
  228.                                     @Override  
  229.                                     public void onClick(DialogInterface dialog, int which) {  
  230.                                         uploadImg(bitmap);  
  231.                                     }  
  232.                                 }).setNegativeButton("取消"new DialogInterface.OnClickListener() {  
  233.                             @Override  
  234.                             public void onClick(DialogInterface dialog, int which) {  
  235.   
  236.                             }  
  237.                         });  
  238.                 AlertDialog dialog = alter.create();  
  239.                 dialog.show();  
  240.             }  
  241.         }  
  242.     }  
  243.     public void uploadImg(Bitmap bitmap){  
  244.         String url = UrlUtil.LOGIN_URL;  
  245.         StringPostRequest request = new StringPostRequest(url, new Response.Listener<String>() {  
  246.             @Override  
  247.             public void onResponse(String s) {  
  248.                 user.setImg(s);  
  249.                 userdlDao.update(user);  
  250.             }  
  251.         }, new Response.ErrorListener() {  
  252.             @Override  
  253.             public void onErrorResponse(VolleyError volleyError) {  
  254.   
  255.             }  
  256.         });  
  257.         request.putParams("userName",user.getUno());  
  258.         request.putParams("pwd",user.getPwd());  
  259.         request.putParams("headImage","1");  
  260.         request.putParams("uhead", convertBitmap(bitmap));  
  261.         requestQueue.add(request);  
  262.     }  
  263.   
  264.     /** 
  265.      * 將Bitmap轉換爲Base64編碼的字符串 
  266.      * @param b 
  267.      * @return 
  268.      */  
  269.     public String convertBitmap(Bitmap b){  
  270.         ByteArrayOutputStream out = new ByteArrayOutputStream();  
  271.         b.compress(Bitmap.CompressFormat.JPEG, 100, out);  
  272.         try {  
  273.             out.flush();  
  274.             out.close();  
  275.         } catch (IOException e) {  
  276.             e.printStackTrace();  
  277.         }  
  278.         byte[] buffer = out.toByteArray();  
  279.         byte[] encode = Base64.encode(buffer, Base64.DEFAULT);  
  280.         return new String(encode);  
  281.     }  
  282.   
  283.   
  284.     /* 
  285.     調用系統裁剪功能 
  286.  
  287.      */  
  288.     public  void  startPicZoom(Uri  uri){  
  289.         Intent intent=new Intent("com.android.camera.action.CROP");  
  290.         intent.setDataAndType(uri,"image/*");  
  291.         intent.putExtra("crop","true");//允許裁剪  
  292.         intent.putExtra("aspectX",1);//設置裁剪比例  
  293.         intent.putExtra("aspectY",1);  
  294.         //設置圖片寬度高度  
  295.         intent.putExtra("outputX",150);  
  296.         intent.putExtra("outputY",150);  
  297.         intent.putExtra("return-data",true);  
  298.         startActivityForResult(intent,3);  
  299.   
  300.     }  
  301.   
  302.   
  303.   
  304.     //設置屏幕背景透明度方法  
  305.     public void backgroundAlpha(float bgAlpha){  
  306.         WindowManager.LayoutParams ll=getWindow().getAttributes();  
  307.         ll.alpha=bgAlpha;  
  308.         getWindow().setAttributes(ll);  
  309.     }  
  310.     //構建一個PopWindow  
  311.     public PopupWindow getPopWindow(View view){  
  312.         PopupWindow popupWindow=new PopupWindow(view,  
  313.                 LinearLayout.LayoutParams.MATCH_PARENT,  
  314.                 LinearLayout.LayoutParams.WRAP_CONTENT,true);  
  315.         // popupWindow.setFocusable(true);  
  316.         //點擊pop外面是否消失  
  317.         popupWindow.setOutsideTouchable(true);  
  318.   
  319.         popupWindow.setAnimationStyle(R.style.popStyle);  
  320.         //設置背景透明度  
  321.         backgroundAlpha(0.3f);  
  322.         //————————  
  323.         //設置View隱藏  
  324.         riv.setVisibility(View.GONE);  
  325.         popupWindow.setBackgroundDrawable(new ColorDrawable());  
  326.         popupWindow.showAtLocation(riv, Gravity.BOTTOM, 00);  
  327.         popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {  
  328.             @Override  
  329.             public void onDismiss() {  
  330.                 //設置背景透明度  
  331.                 backgroundAlpha(1f);  
  332.                 //設置View可見  
  333.                 riv.setVisibility(View.VISIBLE);  
  334.             }  
  335.         });  
  336.         return popupWindow;  
  337.     }  
  338.     @Override  
  339.     protected void onStart() {  
  340.         super.onStart();  
  341.         sp=getSharedPreferences("userInfo",MODE_PRIVATE);  
  342.   
  343.         Boolean jzmm=sp.getBoolean("jzmm",false);  
  344.         Boolean zddl=sp.getBoolean("zddl",false);  
  345.         ssjz.setChecked(jzmm);  
  346.         sszd.setChecked(zddl);  
  347.     }  
  348. }  

頭像

[java] view plain copy
  1. package com.example.zyfnewsctzf;  
  2.   
  3.   
  4. import android.app.Activity;  
  5. import android.content.Intent;  
  6. import android.database.Cursor;  
  7. import android.graphics.Bitmap;  
  8. import android.graphics.drawable.ColorDrawable;  
  9. import android.net.Uri;  
  10. import android.os.Bundle;  
  11. import android.provider.MediaStore;  
  12. import android.support.v7.app.AppCompatActivity;  
  13. import android.view.Gravity;  
  14. import android.view.View;  
  15. import android.view.WindowManager;  
  16. import android.widget.Button;  
  17. import android.widget.LinearLayout;  
  18. import android.widget.PopupWindow;  
  19.   
  20. import com.example.zyfnewsctzf.util.FileUitlity1;  
  21. import com.example.zyfnewsctzf.util.RoundImageView;  
  22.   
  23. import java.io.File;  
  24.   
  25. public class MyIntentActivity  extends AppCompatActivity implements View.OnClickListener {  
  26.     private PopupWindow pw;  
  27.     private View popView;  
  28.     private RoundImageView riv;  
  29.     @Override  
  30.     protected void onCreate(Bundle savedInstanceState) {  
  31.         super.onCreate(savedInstanceState);  
  32.         setContentView(R.layout.activity_intent);  
  33.       getSupportActionBar().hide();  
  34.         //加載PopWindow中的佈局  
  35.         popView = getLayoutInflater().inflate(R.layout.pop_layout, null);  
  36.         //從主佈局中取得控件  
  37.   
  38.         //從PopWindow佈局中取得控件  
  39.         Button xc = (Button)popView.findViewById(R.id.xc);  
  40.         Button xj = (Button)popView.findViewById(R.id.xj);  
  41.         Button bt = (Button)popView.findViewById(R.id.bt);  
  42.   
  43.         riv = (RoundImageView) findViewById(R.id.riv);  
  44.         //註冊   本類監聽  
  45.   
  46.         riv.setOnClickListener(this);  
  47.         xc.setOnClickListener(this);  
  48.         xj.setOnClickListener(this);  
  49.         bt.setOnClickListener(this);  
  50.         //顯示Intent,明確指定要跳轉的組件  
  51. //        Intent intent=new Intent(IntentActivity.this,SecondActivity.class);  
  52. //        startActivity(intent);  
  53.   
  54.         //---------------------------------------  
  55.   
  56.   
  57.     }  
  58.     @Override  
  59.     public void onClick(View v) {  
  60.         int id = v.getId();  
  61.         switch (id) {  
  62.   
  63.             case R.id.riv://點擊頭像打開PopWindow  
  64.                 pw=getPopWindow(popView);  
  65.                 break;  
  66.             case R.id.xc:  
  67.                 phonePhoto();  
  68.                 break;  
  69.             case R.id.xj:  
  70.                 takephoto();  
  71.                 break;  
  72.             case R.id.bt:  
  73.                 pw.dismiss();  
  74.                 break;  
  75.         }  
  76.     }  
  77.   
  78.   
  79.   
  80.     /* 
  81.     * 調用圖庫 
  82.     * */  
  83.     public void phonePhoto(){  
  84.         Intent intent=new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);  
  85.         startActivityForResult(intent,2);  
  86.   
  87.     }  
  88.   
  89.     /* 
  90.     * 調用相機 
  91.     * */  
  92.     private String capturePath="";  
  93.     public void takephoto(){  
  94.         Intent camera=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);  
  95.         File parent= FileUitlity1.getInstance(getApplicationContext())  
  96.                 .makeDir("head_imag");  
  97.         capturePath=parent.getPath()+File.separatorChar+System.currentTimeMillis()+".jpg";  
  98.         camera.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(capturePath)));  
  99.         camera.putExtra(MediaStore.EXTRA_VIDEO_QUALITY,1);  
  100.         startActivityForResult(camera, 1);  
  101.     }  
  102.   
  103.     @Override  
  104.     protected void onActivityResult(int requestCode, int resultCode, Intent data) {  
  105.         super.onActivityResult(requestCode, resultCode, data);  
  106.   
  107.         if (resultCode!= Activity.RESULT_OK){  
  108.   
  109.             return;  
  110.         }  
  111.         //相機返回結果,調用系統裁剪啊  
  112.         if (requestCode==1){  
  113.             startPicZoom(Uri.fromFile(new File(capturePath)));  
  114.   
  115.         }  
  116.         //相冊返回結果調用系統裁剪  
  117.         else if (requestCode==2){  
  118.             Cursor cursor=getContentResolver()  
  119.                     .query(data.getData(),new String[]{MediaStore.Images.Media.DATA}  
  120.                             ,null,null,null);  
  121.             cursor.moveToFirst();  
  122.             String  capturePath=cursor.getString(  
  123.                     cursor.getColumnIndex(  
  124.                             MediaStore.Images.Media.DATA));  
  125.             cursor.close();  
  126.             startPicZoom(Uri.fromFile(new File(capturePath)));  
  127.         }  
  128.         else if (requestCode==3){  
  129.             Bundle bundle= data.getExtras();  
  130.             if (bundle!=null){  
  131.                 Bitmap bitmap=bundle.getParcelable("data");  
  132.                 riv.setImageBitmap(bitmap);  
  133.   
  134.             }  
  135.         }  
  136.     }  
  137.   
  138.     /* 
  139.     調用系統裁剪功能 
  140.  
  141.      */  
  142.     public  void  startPicZoom(Uri  uri){  
  143.         Intent intent=new Intent("com.android.camera.action.CROP");  
  144.         intent.setDataAndType(uri,"image/*");  
  145.         intent.putExtra("crop","true");//允許裁剪  
  146.         intent.putExtra("aspectX",1);//設置裁剪比例  
  147.         intent.putExtra("aspectY",1);  
  148.         //設置圖片寬度高度  
  149.         intent.putExtra("outputX",150);  
  150.         intent.putExtra("outputY",150);  
  151.         intent.putExtra("return-data",true);  
  152.         startActivityForResult(intent,3);  
  153.   
  154.     }  
  155.   
  156.   
  157.   
  158.     //設置屏幕背景透明度方法  
  159.     public void backgroundAlpha(float bgAlpha){  
  160.         WindowManager.LayoutParams ll=getWindow().getAttributes();  
  161.         ll.alpha=bgAlpha;  
  162.         getWindow().setAttributes(ll);  
  163.     }  
  164.     //構建一個PopWindow  
  165.     public PopupWindow getPopWindow(View view){  
  166.         PopupWindow popupWindow=new PopupWindow(view,  
  167.                 LinearLayout.LayoutParams.MATCH_PARENT,  
  168.                 LinearLayout.LayoutParams.WRAP_CONTENT,true);  
  169.         // popupWindow.setFocusable(true);  
  170.         //點擊pop外面是否消失  
  171.         popupWindow.setOutsideTouchable(true);  
  172.   
  173.         popupWindow.setAnimationStyle(R.style.popStyle);  
  174.         //設置背景透明度  
  175.         backgroundAlpha(0.3f);  
  176.         //————————  
  177.         //設置View隱藏  
  178.         riv.setVisibility(View.GONE);  
  179.         popupWindow.setBackgroundDrawable(new ColorDrawable());  
  180.         popupWindow.showAtLocation(riv, Gravity.BOTTOM, 00);  
  181.         popupWindow.setOnDismissListener(new PopupWindow.OnDismissListener() {  
  182.             @Override  
  183.             public void onDismiss() {  
  184.                 //設置背景透明度  
  185.                 backgroundAlpha(1f);  
  186.                 //設置View可見  
  187.                 riv.setVisibility(View.VISIBLE);  
  188.             }  
  189.         });  
  190.         return popupWindow;  
  191.     }  
  192.   
  193. }  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章