你的位置:首页 > 操作系统

[操作系统]开源的Android开发框架


图片异步加载。可以备注图片是否缓存、缓存状态。

1、缓存-SD卡,路径可设置

2、图片压缩

3、可加载本地和网络图片

4、url为本地视频文件可以显示缩略图

5、中文url图片地址FileNotFoundException解决

 

 1 EditText input = (EditText) findViewById(R.id.input); 2 ImageView img = (ImageView) findViewById(R.id.img); 3 RadioButton radio1 = (RadioButton) findViewById(R.id.radio1); 4 RadioButton radio2 = (RadioButton) findViewById(R.id.radio2); 5 RadioButton radio3 = (RadioButton) findViewById(R.id.radio3); 6 String url = input.getText().toString(); 7 ImageTask task = new ImageTask(img,"/mnt/sdcard/",new ImageTaskListener() { 8    9   @Override10   public void onTaskOver(ImageView img) {11     // TODO Auto-generated method stub12     Log.e("loadImg", "图片下载完成");13   }14   15   @Override16   public void onDownloading(int max, int progress) {17     Log.e("loadImg", "图片下载进度:" + progress + "/" + max);18   }19 });20 ImageTaskOpion option = task.getImageTaskOpion();21 option.setAutoVisibility(radio1.isChecked());22 option.setOverlap(radio2.isChecked());23 option.setAutoCompress(radio3.isChecked());24 task.setOption(option);25 task.execute(url);

以上是框架里面的代码。

 

下面看看如何在自己的代码里面进行调用。

 1 public class ImageTaskActivity extends Activity implements OnClickListener { 2  3    4    5   @Override 6   protected void onCreate(Bundle savedInstanceState) { 7     super.onCreate(savedInstanceState); 8     setContentView(R.layout.activity_image_task); 9   }10 11   @Override12   public void onClick(View v) {13     switch(v.getId()){14     case R.id.btnExecute:15       loadImg();16       break;17     }18 19   }20   21   private void loadImg(){22     EditText input = (EditText) findViewById(R.id.input);23     ImageView img = (ImageView) findViewById(R.id.img);24     RadioButton radio1 = (RadioButton) findViewById(R.id.radio1);25     RadioButton radio2 = (RadioButton) findViewById(R.id.radio2);26     RadioButton radio3 = (RadioButton) findViewById(R.id.radio3);27     String url = input.getText().toString();28     ImageTask task = new ImageTask(img,"/mnt/sdcard/",new ImageTaskListener() {29       30       @Override31       public void onTaskOver(ImageView img) {32         // TODO Auto-generated method stub33         Log.e("loadImg", "图片下载完成");34       }35       36       @Override37       public void onDownloading(int max, int progress) {38         Log.e("loadImg", "图片下载进度:" + progress + "/" + max);39       }40     });41     ImageTaskOpion option = task.getImageTaskOpion();42     option.setAutoVisibility(radio1.isChecked());43     option.setOverlap(radio2.isChecked());44     option.setAutoCompress(radio3.isChecked());45     task.setOption(option);46     task.execute(url);47     48   }49 50 }

 

DEMO文件的运行效果: