Search in sources :

Example 1 with ImageViewTouchAndDraw

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

the class DrawingPanel method onGenerateResult.

/*
	 * (non-Javadoc)
	 * 
	 * @see com.aviary.android.feather.effects.AbstractEffectPanel#onGenerateResult()
	 */
@Override
protected void onGenerateResult() {
    Bitmap bitmap = null;
    if (!mBitmap.isMutable()) {
        bitmap = BitmapUtils.copy(mBitmap, mBitmap.getConfig());
    } else {
        bitmap = mBitmap;
    }
    Canvas canvas = new Canvas(bitmap);
    ((ImageViewTouchAndDraw) mImageView).commit(canvas);
    ((ImageViewTouchAndDraw) mImageView).setImageBitmap(bitmap, false);
    onComplete(bitmap, mActionList);
}
Also used : Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) ImageViewTouchAndDraw(com.aviary.android.feather.widget.ImageViewTouchAndDraw)

Example 2 with ImageViewTouchAndDraw

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

the class DrawingPanel method onActivate.

/*
	 * (non-Javadoc)
	 * 
	 * @see com.aviary.android.feather.effects.AbstractEffectPanel#onActivate()
	 */
@Override
public void onActivate() {
    super.onActivate();
    disableHapticIsNecessary(mGalleryColor, mGallerySize);
    initToast();
    mGallerySize.setOnItemsScrollListener(new OnItemsScrollListener() {

        @Override
        public void onScrollFinished(AdapterView<?> parent, View view, int position, long id) {
            mSize = (Integer) mGallerySize.getAdapter().getItem(position);
            final boolean soft = ((GallerySizeAdapter) mGallerySize.getAdapter()).getIsSoft(position);
            if (soft)
                mPaint.setMaskFilter(new BlurMaskFilter(mBlur, Blur.NORMAL));
            else
                mPaint.setMaskFilter(null);
            updatePaint();
            updateSelectedSize(view, position);
            hideToastPreview();
        }

        @Override
        public void onScrollStarted(AdapterView<?> parent, View view, int position, long id) {
            showToastPreview();
            if (getSelectedTool() == DrawinTool.Zoom) {
                setSelectedTool(DrawinTool.Draw);
            }
        }

        @Override
        public void onScroll(AdapterView<?> parent, View view, int position, long id) {
            GallerySizeAdapter adapter = (GallerySizeAdapter) parent.getAdapter();
            int size = (Integer) adapter.getItem(position);
            int blur = adapter.getIsSoft(position) ? mBlur : 0;
            boolean is_eraser = mGalleryColor.getSelectedItemPosition() == 0 || mGalleryColor.getSelectedItemPosition() == mGalleryColor.getAdapter().getCount() - 1;
            if (is_eraser) {
                updateToastPreview(size, Color.WHITE, blur, true);
            } else {
                updateToastPreview(size, mColor, blur, false);
            }
        }
    });
    mGalleryColor.setOnItemsScrollListener(new OnItemsScrollListener() {

        @Override
        public void onScrollFinished(AdapterView<?> parent, View view, int position, long id) {
            mColor = (Integer) parent.getAdapter().getItem(position);
            final boolean is_eraser = position == 0 || (position == parent.getAdapter().getCount() - 1);
            if (is_eraser) {
                mColor = 0;
            }
            mPaint.setColor(mColor);
            if (getSelectedTool() == DrawinTool.Zoom) {
                if (is_eraser)
                    setSelectedTool(DrawinTool.Erase);
                else
                    setSelectedTool(DrawinTool.Draw);
            } else {
                if (is_eraser && getSelectedTool() != DrawinTool.Erase)
                    setSelectedTool(DrawinTool.Erase);
                else if (!is_eraser && getSelectedTool() != DrawinTool.Draw)
                    setSelectedTool(DrawinTool.Draw);
            }
            updatePaint();
            updateSelectedColor(view, position);
            hideToastPreview();
        }

        @Override
        public void onScrollStarted(AdapterView<?> parent, View view, int position, long id) {
            showToastPreview();
            if (getSelectedTool() == DrawinTool.Zoom) {
                setSelectedTool(DrawinTool.Draw);
            }
        }

        @Override
        public void onScroll(AdapterView<?> parent, View view, int position, long id) {
            final boolean is_eraser = position == 0 || (position == parent.getAdapter().getCount() - 1);
            if (is_eraser) {
                updateToastPreview(mSize, Color.WHITE, mBlur, true);
            } else {
                updateToastPreview(mSize, mBrushColors[position], mBlur, false);
            }
        }
    });
    mLensButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            boolean selected = arg0.isSelected();
            arg0.setSelected(!selected);
            if (arg0.isSelected()) {
                setSelectedTool(DrawinTool.Zoom);
            } else {
                if (mGalleryColor.getSelectedItemPosition() == 0) {
                    setSelectedTool(DrawinTool.Erase);
                } else {
                    setSelectedTool(DrawinTool.Draw);
                }
                updatePaint();
            }
        }
    });
    setSelectedTool(DrawinTool.Draw);
    updatePaint();
    updateSelectedSize((View) mGallerySize.getSelectedView(), mGallerySize.getSelectedItemPosition());
    updateSelectedColor((View) mGalleryColor.getSelectedView(), mGalleryColor.getSelectedItemPosition());
    ((ImageViewTouchAndDraw) mImageView).setOnDrawStartListener(this);
    ((ImageViewTouchAndDraw) mImageView).setOnDrawPathListener(this);
    mLensButton.setVisibility(View.VISIBLE);
    getContentView().setVisibility(View.VISIBLE);
    contentReady();
}
Also used : OnClickListener(android.view.View.OnClickListener) ImageViewTouchAndDraw(com.aviary.android.feather.widget.ImageViewTouchAndDraw) BlurMaskFilter(android.graphics.BlurMaskFilter) OnItemsScrollListener(com.aviary.android.feather.widget.Gallery.OnItemsScrollListener) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(com.aviary.android.feather.widget.AdapterView) Paint(android.graphics.Paint)

Example 3 with ImageViewTouchAndDraw

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

the class DrawingPanel method setSelectedTool.

/**
	 * Sets the selected tool.
	 * 
	 * @param which
	 *           the new selected tool
	 */
private void setSelectedTool(DrawinTool which) {
    switch(which) {
        case Draw:
            ((ImageViewTouchAndDraw) mImageView).setDrawMode(TouchMode.DRAW);
            mPaint.setAlpha(255);
            mPaint.setXfermode(null);
            updatePaint();
            break;
        case Erase:
            ((ImageViewTouchAndDraw) mImageView).setDrawMode(TouchMode.DRAW);
            mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR));
            mPaint.setAlpha(0);
            updatePaint();
            break;
        case Zoom:
            ((ImageViewTouchAndDraw) mImageView).setDrawMode(TouchMode.IMAGE);
            break;
    }
    mLensButton.setSelected(which == DrawinTool.Zoom);
    setPanelEnabled(which != DrawinTool.Zoom);
    mSelectedTool = which;
}
Also used : PorterDuffXfermode(android.graphics.PorterDuffXfermode) ImageViewTouchAndDraw(com.aviary.android.feather.widget.ImageViewTouchAndDraw)

Aggregations

ImageViewTouchAndDraw (com.aviary.android.feather.widget.ImageViewTouchAndDraw)3 Bitmap (android.graphics.Bitmap)1 BlurMaskFilter (android.graphics.BlurMaskFilter)1 Canvas (android.graphics.Canvas)1 Paint (android.graphics.Paint)1 PorterDuffXfermode (android.graphics.PorterDuffXfermode)1 View (android.view.View)1 OnClickListener (android.view.View.OnClickListener)1 ImageView (android.widget.ImageView)1 AdapterView (com.aviary.android.feather.widget.AdapterView)1 OnItemsScrollListener (com.aviary.android.feather.widget.Gallery.OnItemsScrollListener)1