Search in sources :

Example 1 with CropImageView

use of com.aviary.android.feather.widget.CropImageView in project mobile-android by photo.

the class CropPanel method onActivate.

/*
	 * (non-Javadoc)
	 * 
	 * @see com.aviary.android.feather.effects.AbstractEffectPanel#onActivate()
	 */
@Override
public void onActivate() {
    super.onActivate();
    int position = mGallery.getSelectedItemPosition();
    final double ratio = calculateAspectRatio(position, false);
    disableHapticIsNecessary(mGallery);
    setIsChanged(true);
    contentReady();
    mGallery.setOnItemsScrollListener(new OnItemsScrollListener() {

        @Override
        public void onScrollFinished(AdapterView<?> parent, View view, int position, long id) {
            if (!isActive())
                return;
            if (position == mSelectedPosition) {
                if (!strict && !nonInvertOptions.contains(position)) {
                    isChecked = !isChecked;
                    CropImageView cview = (CropImageView) mImageView;
                    double currentAspectRatio = cview.getAspectRatio();
                    HighlightView hv = cview.getHighlightView();
                    if (!cview.getAspectRatioIsFixed() && hv != null) {
                        currentAspectRatio = (double) hv.getDrawRect().width() / (double) hv.getDrawRect().height();
                    }
                    double invertedAspectRatio = 1 / currentAspectRatio;
                    cview.setAspectRatio(invertedAspectRatio, cview.getAspectRatioIsFixed());
                    invertRatios(mCropNames, mCropValues);
                    mGallery.invalidateViews();
                }
            } else {
                double ratio = calculateAspectRatio(position, false);
                setCustomRatio(ratio, ratio != 0);
            }
            updateSelection(view, position);
        }

        @Override
        public void onScrollStarted(AdapterView<?> parent, View view, int position, long id) {
        }

        @Override
        public void onScroll(AdapterView<?> parent, View view, int position, long id) {
        }
    });
    getOptionView().getHandler().post(new Runnable() {

        @Override
        public void run() {
            createCropView(ratio, ratio != 0);
            updateSelection((View) mGallery.getSelectedView(), mGallery.getSelectedItemPosition());
        }
    });
}
Also used : HighlightView(com.aviary.android.feather.widget.HighlightView) OnItemsScrollListener(com.aviary.android.feather.widget.Gallery.OnItemsScrollListener) CropImageView(com.aviary.android.feather.widget.CropImageView) View(android.view.View) CropImageView(com.aviary.android.feather.widget.CropImageView) HighlightView(com.aviary.android.feather.widget.HighlightView) TextView(android.widget.TextView) AdapterView(com.aviary.android.feather.widget.AdapterView) Paint(android.graphics.Paint)

Example 2 with CropImageView

use of com.aviary.android.feather.widget.CropImageView in project mobile-android by photo.

the class CropPanel method onCreate.

/*
	 * (non-Javadoc)
	 * 
	 * @see com.aviary.android.feather.effects.AbstractEffectPanel#onCreate(android.graphics.Bitmap)
	 */
@Override
public void onCreate(Bitmap bitmap) {
    super.onCreate(bitmap);
    ConfigService config = getContext().getService(ConfigService.class);
    mFilter = FilterLoaderFactory.get(Filters.CROP);
    mCropNames = config.getStringArray(R.array.feather_crop_names);
    mCropValues = config.getStringArray(R.array.feather_crop_values);
    strict = config.getBoolean(R.integer.feather_crop_invert_policy);
    if (!strict) {
        if (bitmap.getHeight() > bitmap.getWidth()) {
            mIsPortrait = true;
        } else {
            mIsPortrait = false;
        }
        // configure options that will not invert
        populateInvertOptions(nonInvertOptions, mCropValues);
        if (mIsPortrait) {
            invertRatios(mCropNames, mCropValues);
        }
    }
    mSelectedPosition = config.getInteger(R.integer.feather_crop_selected_value);
    mImageView = (CropImageView) getContentView().findViewById(R.id.crop_image_view);
    mImageView.setDoubleTapEnabled(false);
    int minAreaSize = config.getInteger(R.integer.feather_crop_min_size);
    ((CropImageView) mImageView).setMinCropSize(minAreaSize);
    mGallery = (Gallery) getOptionView().findViewById(R.id.gallery);
    mGallery.setCallbackDuringFling(false);
    mGallery.setSpacing(0);
    mGallery.setAdapter(new GalleryAdapter(getContext().getBaseContext(), mCropNames));
    mGallery.setSelection(mSelectedPosition, false, true);
}
Also used : ConfigService(com.aviary.android.feather.library.services.ConfigService) CropImageView(com.aviary.android.feather.widget.CropImageView) Paint(android.graphics.Paint)

Aggregations

Paint (android.graphics.Paint)2 CropImageView (com.aviary.android.feather.widget.CropImageView)2 View (android.view.View)1 TextView (android.widget.TextView)1 ConfigService (com.aviary.android.feather.library.services.ConfigService)1 AdapterView (com.aviary.android.feather.widget.AdapterView)1 OnItemsScrollListener (com.aviary.android.feather.widget.Gallery.OnItemsScrollListener)1 HighlightView (com.aviary.android.feather.widget.HighlightView)1