Beispiel #1
0
 private void enableZooming() {
   Log.d(TAG, "enable zoom ");
   mZooming = true;
   getActionBar().setSubtitle(R.string.subtitle_activity_zooming);
   getActionBar().setTitle(R.string.title_activity_zooming);
   if (mCropRectangle != null && mCropRectangle.getParent() != null) {
     mCropRectangle.disable();
     if (mCropRectangle.getParent() == null) {
       Log.d(Constants.DEBUG, "crop rectangle parent is null, not removed!");
     } else {
       ((RelativeLayout) mCropRectangle.getParent()).removeView(mCropRectangle);
     }
   }
   mResultImageView.setOnTouchListener(new OnZoomTouchListener());
   invalidateOptionsMenu();
 }
Beispiel #2
0
  private void setUI() {
    getActionBar().setSubtitle(R.string.subtitle_activity_cropping);

    mImageResultContainer = (RelativeLayout) findViewById(R.id.imageResultContainer);
    LayoutInflater inflater = getLayoutInflater();
    inflater.inflate(R.layout.crop_rectangle, mImageResultContainer, true);
    // mImageResultContainer.addView(mCropRectangle);
    mCropRectangle = (CropRectangle) findViewById(R.id.cropRectangle);

    ((RelativeLayout) mCropRectangle.getParent()).removeView(mCropRectangle);
    mImageResultContainer.addView(mCropRectangle);

    // Fetch screen height and width, to use as our max size when loading
    // images as this
    // activity runs full screen
    final DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    final int height = displayMetrics.heightPixels;
    final int width = displayMetrics.widthPixels;

    // For this sample we'll use half of the longest width to resize our
    // images. As the
    // image scaling ensures the image is larger than this, we should be
    // left with a
    // resolution that is appropriate for both portrait and landscape.
    // For
    // best image quality
    // we shouldn't divide by 2, but this will use more memory and
    // require a
    // larger memory
    // cache.
    final int longest = (height > width ? height : width);

    // BitmapFactory.Options options = new BitmapFactory.Options();
    // options.inSampleSize = 2;
    // Bitmap bm = BitmapFactory.decodeFile(mCurrentPhotoPath, options);
    // mResultImageView.setImageBitmap(bm);

    // The ImageFetcher takes care of loading images into our ImageView
    // children asynchronously

    mImageFetcher = new ImageFetcher(this, longest);

    mImageFetcher.loadImage(mCurrentPhotoPath, mResultImageView);
    final Activity activity = this;
    ViewTreeObserver viewTreeObserver = mResultImageView.getViewTreeObserver();
    if (viewTreeObserver.isAlive()) {
      viewTreeObserver.addOnGlobalLayoutListener(
          new OnGlobalLayoutListener() {
            @SuppressWarnings("deprecation")
            @Override
            public void onGlobalLayout() {
              if (mRectLeft != 0) {
                Log.d(Constants.DEBUG, "CROP rect set mrectleft" + mRectLeft);
                mCropRectangle.setCropRectangle(
                    new RectF(mRectLeft, mRectTop, mRectRight, mRectBottom));
              }
              mCropRectangle.setReportView(mResultImageView, activity);
              mResultImageView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
            }
          });
    }
  }