package com.ch.day13_imageloaderdemo;
import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.assist.FailReason; import com.nostra13.universalimageloader.core.listener.ImageLoadingListener; import com.nostra13.universalimageloader.core.listener.ImageLoadingProgressListener;
import android.os.Bundle; import android.app.Activity; import android.app.ProgressDialog; import android.graphics.Bitmap; import android.util.Log; import android.view.Menu; import android.view.View; import android.widget.ImageView;
public class MainActivity extends Activity { private ImageView img; String url = "http://photocdn.sohu.com/kis/fengmian/1193/1193693/1193693_ver_big.jpg"; String url1 = "http://a0.att.hudong.com/15/08/300218769736132194086202411_950.jpg"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); init(); } public void init(){ img = (ImageView) findViewById(R.id.img); //通过ImageLoader加载网络图片,配置给img // ImageLoader.getInstance().displayImage(url, img); // ImageLoader.getInstance().displayImage(url, img, MyApplication.getOptions()); // ImageLoader.getInstance().displayImage(url, img, MyApplication.getOptions(), new ImageLoadingListener() { // @Override // public void onLoadingStarted(String arg0, View arg1) { // } // @Override // public void onLoadingFailed(String arg0, View arg1, FailReason arg2) { // } // @Override // public void onLoadingComplete(String arg0, View arg1, Bitmap arg2) { // } // @Override // public void onLoadingCancelled(String arg0, View arg1) { // } // }); final ProgressDialog pro = new ProgressDialog(this); pro.setMessage("努力加载中。。。"); pro.setIcon(R.drawable.ic_launcher); pro.show(); ImageLoader.getInstance().displayImage(url1, img, MyApplication.getOptions(), null, new ImageLoadingProgressListener() { @Override public void onProgressUpdate(String arg0, View arg1, int arg2, int arg3) { // TODO Auto-generated method stub Log.i("TAG", arg0+",,"+arg2+","+arg3); float rs = ((float)arg2)/arg3; pro.setMessage("当前加载到:"+rs*100+"%"); if(arg2 == arg3){ pro.cancel(); } } }); }
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.activity_main, menu); return true; }
}
|
|