该App已经上传到百度应用市场:http://shouji.baidu.com/soft/item?docid=8928185&from=as&f=search_app_it%E8%B5%84%E8%AE%AF%40list_1_image%402%40header_all_input
有兴趣的可以下载看看。接下来我会公布源代码,不过该App并没有使用代码混淆,所以可以通过反编译清楚的看到源码。
以下是布局文件
<?xml version="1.0" encoding="utf-8"?> <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:gesture-image="http://schemas.polites.com/android" android:layout_width="fill_parent" android:layout_height="fill_parent" > <com.polites.android.GestureImageView android:id="@+id/image" android:layout_width="fill_parent" android:layout_height="fill_parent" gesture-image:max-scale="10.0" gesture-image:min-scale="0.75" /> <ProgressBar android:id="@+id/loading" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center" android:visibility="visible" /> <FrameLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_gravity="bottom" android:background="@color/transparentblack" > <ImageView android:id="@+id/back" android:onClick="back" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/back_btn" /> <ImageView android:id="@+id/download" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="right|center_vertical" android:layout_marginRight="16dp" android:clickable="true" android:focusable="true" android:onClick="downloadImg" android:src="@drawable/download_btn" /> </FrameLayout>
显示源码:
public class ImageShowActivity extends BaseActivityImpl { private String url; private ProgressBar loading; private GestureImageView gestureImageView; private Bitmap bitmap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_image_page); //拿到图片的URL url = getIntent().getExtras().getString("url"); loading = (ProgressBar) findViewById(R.id.loading); gestureImageView = (GestureImageView) findViewById(R.id.image); new DownLoadImgTask().execute(); } /** * 点击返回按钮 * * @param view */ public void back(View view) { finish(); } /** * 下载图片 * * @param view */ public void downloadImg(View view) { gestureImageView.setDrawingCacheEnabled(true); if (FileUtil.writeSDcard(url, gestureImageView.getDrawingCache())) { Toast.makeText(getApplicationContext(), "保存成功", Toast.LENGTH_SHORT).show(); } else { Toast.makeText(getApplicationContext(), "保存失败", Toast.LENGTH_SHORT).show(); } gestureImageView.setDrawingCacheEnabled(false); //禁用DrawingCahce否则会影响性能 } class DownLoadImgTask extends AsyncTask<Void, Void, Void> { @Override protected Void doInBackground(Void... params) { bitmap = HttpUtil.HttpGetImg(url, getApplicationContext()); return null; } @Override protected void onPostExecute(Void result) { gestureImageView.setImageBitmap(bitmap); loading.setVisibility(View.GONE); super.onPostExecute(result); } }