コード例 #1
0
 public void setCropVisible(boolean mDefault) {
   if (mDefault) {
     mCropView.setVisibility(View.VISIBLE);
   } else {
     mCropView.setVisibility(View.GONE);
   }
 }
コード例 #2
0
 public void setCropViewVisible(boolean visible) {
   if (visible) {
     mCropView.setVisibility(View.VISIBLE);
   } else {
     mCropView.setVisibility(View.GONE);
   }
 }
コード例 #3
0
 protected void cropImageAndSetWallpaper(
     Resources res, int resId, final boolean finishActivityWhenDone) {
   // crop this image and scale it down to the default wallpaper size for
   // this device
   int rotation = getRotationFromExif(res, resId);
   Point inSize = mCropView.getSourceDimensions();
   Point outSize = getDefaultWallpaperSize(getResources(), getWindowManager());
   RectF crop = getMaxCropRect(inSize.x, inSize.y, outSize.x, outSize.y, false);
   Runnable onEndCrop =
       new Runnable() {
         public void run() {
           // Passing 0, 0 will cause launcher to revert to using the
           // default wallpaper size
           updateWallpaperDimensions(0, 0);
           if (finishActivityWhenDone) {
             setResult(Activity.RESULT_OK);
             finish();
           }
         }
       };
   BitmapCropTask cropTask =
       new BitmapCropTask(
           this, res, resId, crop, rotation, outSize.x, outSize.y, true, false, onEndCrop);
   cropTask.execute();
 }
コード例 #4
0
 @Override
 protected void onDestroy() {
   if (mCropView != null) {
     mCropView.destroy();
   }
   super.onDestroy();
 }
コード例 #5
0
  public void init(Context context) {
    LayoutInflater inflater =
        (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View view = inflater.inflate(R.layout.view_crop, this, true);

    mImageView = (ImageView) view.findViewById(R.id.imageView);
    mCropView = (CropView) view.findViewById(R.id.cropView);
    mCropView.setImageView(mImageView);
    setDefault(true);
  }
コード例 #6
0
  @Override
  public void prepare() {
    // Cropped results wouldn't be previewed for changed crop bounds.
    final CropFilter filter = new CropFilter();
    disableFilterOutput();

    CropView cropView = toolKit.addCropView();
    cropView.setOnCropChangeListener(
        new CropView.OnCropChangeListener() {

          @Override
          public void onCropChanged(RectF cropBounds, boolean fromUser) {
            if (fromUser) {
              filter.setCropBounds(cropBounds);
              notifyChanged(filter);
            }
          }
        });

    RectF bounds = new RectF(DEFAULT_CROP, DEFAULT_CROP, 1 - DEFAULT_CROP, 1 - DEFAULT_CROP);
    cropView.setCropBounds(bounds);
    filter.setCropBounds(bounds);
    notifyChanged(filter);
  }
コード例 #7
0
  protected void cropImageAndSetWallpaper(
      Uri uri,
      OnBitmapCroppedHandler onBitmapCroppedHandler,
      final boolean finishActivityWhenDone) {
    boolean centerCrop = getResources().getBoolean(R.bool.center_crop);
    // Get the crop
    boolean ltr = mCropView.getLayoutDirection() == View.LAYOUT_DIRECTION_LTR;

    Display d = getWindowManager().getDefaultDisplay();

    Point displaySize = new Point();
    d.getSize(displaySize);
    boolean isPortrait = displaySize.x < displaySize.y;

    Point defaultWallpaperSize = getDefaultWallpaperSize(getResources(), getWindowManager());
    // Get the crop
    RectF cropRect = mCropView.getCrop();

    Point inSize = mCropView.getSourceDimensions();

    int cropRotation = mCropView.getImageRotation();
    float cropScale = mCropView.getWidth() / (float) cropRect.width();

    Matrix rotateMatrix = new Matrix();
    rotateMatrix.setRotate(cropRotation);
    float[] rotatedInSize = new float[] {inSize.x, inSize.y};
    rotateMatrix.mapPoints(rotatedInSize);
    rotatedInSize[0] = Math.abs(rotatedInSize[0]);
    rotatedInSize[1] = Math.abs(rotatedInSize[1]);

    // due to rounding errors in the cropview renderer the edges can be slightly offset
    // therefore we ensure that the boundaries are sanely defined
    cropRect.left = Math.max(0, cropRect.left);
    cropRect.right = Math.min(rotatedInSize[0], cropRect.right);
    cropRect.top = Math.max(0, cropRect.top);
    cropRect.bottom = Math.min(rotatedInSize[1], cropRect.bottom);

    // ADJUST CROP WIDTH
    // Extend the crop all the way to the right, for parallax
    // (or all the way to the left, in RTL)
    float extraSpace;
    if (centerCrop) {
      extraSpace = 2f * Math.min(rotatedInSize[0] - cropRect.right, cropRect.left);
    } else {
      extraSpace = ltr ? rotatedInSize[0] - cropRect.right : cropRect.left;
    }
    // Cap the amount of extra width
    float maxExtraSpace = defaultWallpaperSize.x / cropScale - cropRect.width();
    extraSpace = Math.min(extraSpace, maxExtraSpace);

    if (centerCrop) {
      cropRect.left -= extraSpace / 2f;
      cropRect.right += extraSpace / 2f;
    } else {
      if (ltr) {
        cropRect.right += extraSpace;
      } else {
        cropRect.left -= extraSpace;
      }
    }

    // ADJUST CROP HEIGHT
    if (isPortrait) {
      cropRect.bottom = cropRect.top + defaultWallpaperSize.y / cropScale;
    } else { // LANDSCAPE
      float extraPortraitHeight = defaultWallpaperSize.y / cropScale - cropRect.height();
      float expandHeight =
          Math.min(
              Math.min(rotatedInSize[1] - cropRect.bottom, cropRect.top), extraPortraitHeight / 2);
      cropRect.top -= expandHeight;
      cropRect.bottom += expandHeight;
    }
    final int outWidth = (int) Math.round(cropRect.width() * cropScale);
    final int outHeight = (int) Math.round(cropRect.height() * cropScale);

    Runnable onEndCrop =
        new Runnable() {
          public void run() {
            updateWallpaperDimensions(outWidth, outHeight);
            if (finishActivityWhenDone) {
              setResult(Activity.RESULT_OK);
              finish();
            }
          }
        };
    BitmapCropTask cropTask =
        new BitmapCropTask(
            this, uri, cropRect, cropRotation, outWidth, outHeight, true, false, onEndCrop);
    if (onBitmapCroppedHandler != null) {
      cropTask.setOnBitmapCropped(onBitmapCroppedHandler);
    }
    cropTask.execute();
  }
コード例 #8
0
 public List<Poynt> getCropCorners() {
   return mCropView.getCorners();
 }
コード例 #9
0
 public void setDefault(boolean mDefault) {
   mCropView.setDefault(mDefault);
   mCropView.invalidate();
 }
コード例 #10
0
 public void setCorners(List<Poynt> corners) {
   mCropView.setCorners(corners);
   mCropView.invalidate();
 }
コード例 #11
0
 public void setImageBitmap(Bitmap b) {
   mImageView.setImageBitmap(b);
   mCropView.setBitmap(b);
   setCropViewVisible(true);
 }