Back to project page CommonLibs.
The source code is released under:
Apache License
If you think the Android project CommonLibs listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.alex.common.activities; /*from www . ja v a2 s.c o m*/ import com.alex.common.R; import com.alex.common.utils.ImageUtils; import com.alex.common.utils.ToastUtils; import com.alex.common.utils.FileUtils.PathType; import com.alex.common.views.ZoomImageView; import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.assist.FailReason; import com.nostra13.universalimageloader.core.assist.ImageScaleType; import com.nostra13.universalimageloader.core.display.FadeInBitmapDisplayer; import com.nostra13.universalimageloader.core.listener.ImageLoadingListener; import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.os.Bundle; import android.text.TextUtils; import android.view.Menu; import android.view.MenuItem; import android.view.View; import android.view.MenuItem.OnMenuItemClickListener; import android.widget.ProgressBar; /** * ???????Activity????????????????????????????????????? * @author caisenchuan */ public class ImageLoadActivity extends BaseActivity{ /*-------------------------- * ??? *-------------------------*/ public static final String TAG = ImageLoadActivity.class.getSimpleName(); //Intent extra /**????????*/ public static final String INTENT_IMG_URL = "img_url"; /*-------------------------- * ????? *-------------------------*/ /*-------------------------- * ???????? *-------------------------*/ //???? /**??????*/ private String mUrl = ""; /**????*/ private Bitmap mImageBuffer = null; //?????? private ZoomImageView mImage = null; private ProgressBar mProgress = null; /*-------------------------- * public?? *-------------------------*/ /** * ?????Activity????? */ public static void loadImage(Context context, String url) { Intent it = new Intent(context, ImageLoadActivity.class); it.putExtra(INTENT_IMG_URL, url); context.startActivity(it); } /*-------------------------- * protected??packet?? *-------------------------*/ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_load_image); mImage = (ZoomImageView)findViewById(R.id.image_load); mProgress = (ProgressBar)findViewById(R.id.prog_load_image); handleIntent(); startLoad(); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. super.onCreateOptionsMenu(menu); //????????? MenuItem add = menu.add(0, 0, 0, R.string.image_load_save); //?????? add.setOnMenuItemClickListener(new OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { saveImage(); return false; } }); return true; } /*-------------------------- * private?? *-------------------------*/ /** * ????Intent */ private void handleIntent() { Intent it = getIntent(); String url = it.getStringExtra(INTENT_IMG_URL); if(!TextUtils.isEmpty(url)) { mUrl = url; } } /** * ?????? */ private void startLoad() { DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder() .cacheOnDisc(true) .cacheInMemory(true) .displayer(new FadeInBitmapDisplayer(50)) .bitmapConfig(Bitmap.Config.RGB_565) .imageScaleType(ImageScaleType.EXACTLY) .build(); ImageLoadingListener listener = new ImageLoadingListener() { @Override public void onLoadingStarted(String imageUri, View view) { mProgress.setVisibility(View.VISIBLE); mImageBuffer = null; } @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { mProgress.setVisibility(View.GONE); ToastUtils.showLongToast(ImageLoadActivity.this, "Load faild!", false); mImageBuffer = null; } @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { mProgress.setVisibility(View.GONE); mImageBuffer = loadedImage; } @Override public void onLoadingCancelled(String imageUri, View view) { mProgress.setVisibility(View.GONE); mImageBuffer = null; } }; ImageLoader.getInstance().displayImage(mUrl, mImage, defaultOptions, listener); } /** * ??????SD??? */ private void saveImage() { if(mImageBuffer == null) { showToastOnUIThread(R.string.image_load_hint_loading); } else { Bitmap bitmap = mImageBuffer; String path = ImageUtils.savePicToSD(PathType.DOWNLOAD, bitmap); showToastOnUIThread(String.format("%s%s", getString(R.string.image_load_hint_save_to), path)); } } }