真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

AsyncTask的使用(二)圖片下載,進(jìn)度條-創(chuàng)新互聯(lián)

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import android.os.AsyncTask;
import android.os.Bundle;
import android.app.Activity;
import android.app.ProgressDialog;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends Activity {
    private ProgressDialog dialog;
    private Button button;
    private ImageView p_w_picpathView;
    private String p_w_picpath_path = "http://i1.juyouqu.com/uploads/content//2014/04/1396611698344.jpg!w598";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        dialog = new ProgressDialog(this);
        dialog.setTitle("提示");
        dialog.setMessage("正在下載.......");
        dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
//      dialog.show();
        button = (Button)findViewById(R.id.button1);
        p_w_picpathView = (ImageView)findViewById(R.id.p_w_picpathView1);
        button.setOnClickListener(new View.OnClickListener() {
          
            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                new MyTask().execute(p_w_picpath_path);
            }
        });
    }
    public class MyTask extends AsyncTask
    {
        @Override
        protected void onPreExecute() {
            // TODO Auto-generated method stub
            super.onPreExecute();
            dialog.show();
        }
        @Override
        protected Bitmap doInBackground(String... params) {
            // TODO Auto-generated method stub
            Bitmap bitmap = null;
            ByteArrayOutputStream output = new ByteArrayOutputStream();
            InputStream input = null;
              
            try {
                HttpClient httpClient = new DefaultHttpClient();
                HttpGet httpGet = new HttpGet(params[0]);
                HttpResponse httpResponse = httpClient.execute(httpGet);
                if (httpResponse.getStatusLine().getStatusCode() == 200) {
                      
                    input = httpResponse.getEntity().getContent();
                    long file_length = httpResponse.getEntity().getContentLength();
                    int len = 0;
                    byte[] data = new byte[1024];
                    int total_length = 0;
                    int value = 0;
                   while((len = input.read(data)) != -1)
                    {
                        total_length += len;
                        value = (int)((total_length / (float)file_length) * 100);
                        publishProgress(value);
                        output.write(data, 0, len);
                    }
                    byte[] result = output.toByteArray();
                    bitmap = BitmapFactory.decodeByteArray(result, 0, result.length);
                      
                }
                  
            } catch (Exception e) {
                // TODO: handle exception
            }finally
            {
                if(input != null)
                    try {
                        input.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                if(output != null)
                    try {
                        output.close();
                    } catch (IOException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
            }
            return bitmap;
        }
        @Override
        protected void onPostExecute(Bitmap result) {
            // TODO Auto-generated method stub
            super.onPostExecute(result);
          
            dialog.dismiss();
            p_w_picpathView.setImageBitmap(result);
        }
        @Override
        protected void onProgressUpdate(Integer... values) {
            // TODO Auto-generated method stub
            super.onProgressUpdate(values);
            dialog.setProgress(values[0]);
        }
    }
}

南芬ssl適用于網(wǎng)站、小程序/APP、API接口等需要進(jìn)行數(shù)據(jù)傳輸應(yīng)用場景,ssl證書未來市場廣闊!成為成都創(chuàng)新互聯(lián)的ssl證書銷售渠道,可以享受市場價(jià)格4-6折優(yōu)惠!如果有意向歡迎電話聯(lián)系或者加微信:028-86922220(備注:SSL證書合作)期待與您的合作!

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)scvps.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時(shí)售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機(jī)、免備案服務(wù)器”等云主機(jī)租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價(jià)比高”等特點(diǎn)與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。


當(dāng)前名稱:AsyncTask的使用(二)圖片下載,進(jìn)度條-創(chuàng)新互聯(lián)
標(biāo)題URL:http://weahome.cn/article/cchipg.html

其他資訊

在線咨詢

微信咨詢

電話咨詢

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部