@Override
        public Object instantiateItem(View arg0, int position) {
          // TODO Auto-generated method stub
          View view = LayoutInflater.from(context).inflate(R.layout.photo, null);
          view.setTag(mlist.get(position));
          ((ViewPager) arg0).addView(view);
          ImageViewTouch imageView = (ImageViewTouch) view.findViewById(R.id.photo);
          imageView.setDisplayType(DisplayType.FIT_IF_BIGGER);
          bitmap = BitmapFactory.decodeFile(mlist.get(position));
          bm = BitmapTools.resizeImage2(bitmap, mwidth - 80, mheight - 120);

          imageView.setImageBitmap(bm);
          imageView.setBackgroundColor(Color.rgb(192, 192, 192));
          return view;
        }
        public void handleMessage(Message msg) {
          switch (msg.what) {
            case 1:
              pb.setVisibility(4);
              isRun = false;
              image.setImageBitmap(bm);

              break;
            case 3:
              progressDialog.dismiss();
              mThread = null;
              Toast.makeText(context, "Convert Success!!", Toast.LENGTH_SHORT).show();
              File file = new File(root_Path2 + MyApplication.folder_path + ".pdf");
              Intent mailIntent = new Intent(Intent.ACTION_SEND);
              mailIntent.putExtra(Intent.EXTRA_SUBJECT, "TinyScan");
              mailIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));
              if (file.getName().endsWith(".gz")) {
                mailIntent.setType("application/x-gzip"); // 如果是gz使用gzip的mime
              } else if (file.getName().endsWith(".txt")) {
                mailIntent.setType("text/plain"); // 纯文本则用text/plain的mime
              } else {
                mailIntent.setType("application/octet-stream"); // 其他的均使用流当做二进制数据来发送
              }
              startActivity(Intent.createChooser(mailIntent, "Export"));
              break;
            default:
              break;
          }
          super.handleMessage(msg);
        }
 @Override
 public void onResume() {
   super.onResume();
   cleanPageBitmap();
   loadPageBitmap();
   imageViewTouch.setImageBitmap(pageBitmap);
 }
 private void stopLoading() {
   getSupportLoaderManager().destroyLoader(0);
   if (!mImageLoaded) {
     mRefreshStopSaveButton.setImageResource(R.drawable.ic_menu_refresh);
     mImageView.setImageBitmap(
         BitmapFactory.decodeResource(getResources(), R.drawable.refresh_image));
     mProgress.setVisibility(View.GONE);
   }
 }
 @Override
 public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   requestWindowFeature(Window.FEATURE_NO_TITLE);
   setContentView(R.layout.page_image_view);
   imageViewTouch = (ImageViewTouch) findViewById(R.id.imageViewer);
   Matrix matrix = new Matrix();
   matrix.postScale(1.0f, 1.0f);
   imageViewTouch.setImageMatrix(matrix);
 }
 @Override
 public void onLoadFinished(
     final Loader<ImageLoader.Result> loader, final ImageLoader.Result data) {
   if (data != null && data.bitmap != null) {
     mImageView.setImageBitmap(data.bitmap);
     mImageFile = data.file;
     mImageLoaded = true;
     mRefreshStopSaveButton.setImageResource(R.drawable.ic_menu_save);
   } else {
     mImageView.setImageBitmap(
         BitmapFactory.decodeResource(getResources(), R.drawable.broken_image));
     mImageFile = null;
     mImageLoaded = false;
     mRefreshStopSaveButton.setImageResource(R.drawable.ic_menu_refresh);
     if (data != null) {
       showErrorMessage(this, null, data.exception, true);
     }
   }
   mProgress.setVisibility(View.GONE);
   mProgress.setProgress(0);
 }
 private void loadImage(final boolean init) {
   getSupportLoaderManager().destroyLoader(0);
   final Uri uri = getIntent().getData();
   if (uri == null) {
     finish();
     return;
   }
   mImageView.setImageBitmap(null);
   final Bundle args = new Bundle();
   args.putParcelable(INTENT_KEY_URI, uri);
   if (init) {
     getSupportLoaderManager().initLoader(0, args, this);
   } else {
     getSupportLoaderManager().restartLoader(0, args, this);
   }
 }
  public void selectRandomImage() {
    Cursor c =
        getContentResolver().query(Images.Media.EXTERNAL_CONTENT_URI, null, null, null, null);
    if (c != null) {
      int count = c.getCount();
      int position = (int) (Math.random() * count);
      if (c.moveToPosition(position)) {
        long id = c.getLong(c.getColumnIndex(Images.Media._ID));

        Uri imageUri = Uri.parse(Images.Media.EXTERNAL_CONTENT_URI + "/" + id);

        // imageUri = Uri.parse( "content://media/external/images/media/7993" ); // test

        Log.d("image", imageUri.toString());

        final int size = -1; // use the original image size
        Bitmap bitmap = DecodeUtils.decode(this, imageUri, size, size);
        if (null != bitmap) {
          // calling this will force the image to fit the ImageView container width/height

          if (null == imageMatrix) {
            imageMatrix = new Matrix();
          } else {
            // get the current image matrix, if we want restore the
            // previous matrix once the bitmap is changed
            // imageMatrix = mImage.getDisplayMatrix();
          }

          mImage.setImageBitmap(
              bitmap,
              imageMatrix.isIdentity() ? null : imageMatrix,
              ImageViewTouchBase.ZOOM_INVALID,
              ImageViewTouchBase.ZOOM_INVALID);

        } else {
          Toast.makeText(this, "Failed to load the image", Toast.LENGTH_LONG).show();
        }
      }
      c.close();
      c = null;
      return;
    }
  }
  @Override
  public void onContentChanged() {
    super.onContentChanged();
    mImage = (ImageViewTouch) findViewById(R.id.image);

    // set the default image display type
    mImage.setDisplayType(DisplayType.FIT_IF_BIGGER);

    mButton1 = (Button) findViewById(R.id.button);
    mButton2 = (Button) findViewById(R.id.button2);

    mButton1.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {
            selectRandomImage();
          }
        });

    mButton2.setOnClickListener(
        new OnClickListener() {

          @Override
          public void onClick(View v) {

            int current = mImage.getDisplayType().ordinal() + 1;
            if (current >= DisplayType.values().length) {
              current = 0;
            }

            mImage.setDisplayType(DisplayType.values()[current]);
          }
        });

    mImage.setSingleTapListener(
        new OnImageViewTouchSingleTapListener() {

          @Override
          public void onSingleTapConfirmed() {
            Log.d(LOG_TAG, "onSingleTapConfirmed");
          }
        });

    mImage.setDoubleTapListener(
        new OnImageViewTouchDoubleTapListener() {

          @Override
          public void onDoubleTap() {
            Log.d(LOG_TAG, "onDoubleTap");
          }
        });

    mImage.setOnDrawableChangedListener(
        new OnDrawableChangeListener() {

          @Override
          public void onDrawableChanged(Drawable drawable) {
            Log.i(LOG_TAG, "onBitmapChanged: " + drawable);
          }
        });
  }