@Override protected void onActivityResult(int requestCode, int resultCode, Intent data) { switch (requestCode) { case MenuHelper.RESULT_COMMON_MENU_CROP: if (resultCode == RESULT_OK) { // The CropImage activity passes back the Uri of the // cropped image as the Action rather than the Data. mSavedUri = Uri.parse(data.getAction()); // if onStart() runs before, then set the returned // image as currentImage. if (mAllImages != null) { IImage image = mAllImages.getImageForUri(mSavedUri); // image could be null if SD card is removed. if (image == null) { finish(); } else { mCurrentPosition = mAllImages.getImageIndex(image); setImage(mCurrentPosition, false); } } } break; } }
private boolean init(Uri uri) { if (uri == null) return false; mAllImages = (mParam == null) ? buildImageListFromUri(uri) : ImageManager.makeImageList(getContentResolver(), mParam); IImage image = mAllImages.getImageForUri(uri); if (image == null) return false; mCurrentPosition = mAllImages.getImageIndex(image); mLastSlideShowImage = mCurrentPosition; return true; }
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); mContentResolver = getContentResolver(); setContentView(getContentViewId()); mImageView = getCropImageView(); // Work-around for devices incapable of using hardware-accelerated clipPath. // (android.view.GLES20Canvas.clipPath) // // See also: // - https://code.google.com/p/android/issues/detail?id=20474 // - https://github.com/lvillani/android-cropimage/issues/20 // if (Build.VERSION.SDK_INT > 10 && Build.VERSION.SDK_INT < 16) { // >= Gingerbread && < Jelly Bean mImageView.setLayerType(View.LAYER_TYPE_SOFTWARE, null); } Intent intent = getIntent(); Bundle extras = intent.getExtras(); if (extras != null) { if (extras.getBoolean("circleCrop", false)) { mCircleCrop = true; mAspectX = 1; mAspectY = 1; mOutputFormat = Bitmap.CompressFormat.PNG; } mSaveUri = (Uri) extras.getParcelable(MediaStore.EXTRA_OUTPUT); if (mSaveUri != null) { String outputFormatString = extras.getString("outputFormat"); if (outputFormatString != null) { mOutputFormat = Bitmap.CompressFormat.valueOf(outputFormatString); } mOutputQuality = extras.getInt("outputQuality", 100); } else { mSetWallpaper = extras.getBoolean("setWallpaper"); } mBitmap = (Bitmap) extras.getParcelable("data"); mAspectX = extras.getInt("aspectX"); mAspectY = extras.getInt("aspectY"); mOutputX = extras.getInt("outputX"); mOutputY = extras.getInt("outputY"); mOutlineColor = extras.getInt("outlineColor", HighlightView.DEFAULT_OUTLINE_COLOR); mOutlineCircleColor = extras.getInt("outlineCircleColor", HighlightView.DEFAULT_OUTLINE_CIRCLE_COLOR); mScale = extras.getBoolean("scale", true); mScaleUp = extras.getBoolean("scaleUpIfNeeded", true); mDoFaceDetection = extras.containsKey("noFaceDetection") ? !extras.getBoolean("noFaceDetection") : true; } if (mBitmap == null) { Uri target = intent.getData(); mAllImages = ImageManager.makeImageList(mContentResolver, target, ImageManager.SORT_ASCENDING); mImage = mAllImages.getImageForUri(target); if (mImage != null) { // Don't read in really large bitmaps. Use the (big) thumbnail // instead. // TODO when saving the resulting bitmap use the // decode/crop/encode api so we don't lose any resolution. mBitmap = mImage.thumbBitmap(IImage.ROTATE_AS_NEEDED); } } if (mBitmap == null) { finish(); return; } // Make UI fullscreen. getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); Button discardButton = getDiscardButton(); if (discardButton != null) { discardButton.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { setResult(RESULT_CANCELED); finish(); } }); } Button saveButton = getSaveButton(); if (saveButton != null) { saveButton.setOnClickListener( new View.OnClickListener() { public void onClick(View v) { onSaveClicked(); } }); } startFaceDetection(); }