Search in sources :

Example 6 with ImageViewDrawableOverlay

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

the class MemePanel method beginEditText.

/**
	 * Begin edit text.
	 * 
	 * @param view
	 *           the view
	 */
private void beginEditText(final DrawableHighlightView view) {
    mLogger.info("beginEditText", view);
    EditText editText = null;
    if (view == topHv) {
        editText = editTopText;
    } else if (view == bottomHv) {
        editText = editBottomText;
    }
    if (editText != null) {
        mEditTextWatcher.view = null;
        editText.removeTextChangedListener(mEditTextWatcher);
        final EditableDrawable editable = (EditableDrawable) view.getContent();
        final String oldText = (String) editable.getText();
        editText.setText(oldText);
        editText.setSelection(editText.length());
        editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
        editText.requestFocusFromTouch();
        Handler handler = new Handler();
        ResultReceiver receiver = new ResultReceiver(handler);
        if (!mInputManager.showSoftInput(editText, 0, receiver)) {
            // TODO: verify
            mInputManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
        }
        mEditTextWatcher.view = view;
        editText.setOnEditorActionListener(this);
        editText.addTextChangedListener(mEditTextWatcher);
        ((ImageViewDrawableOverlay) mImageView).setSelectedHighlightView(view);
        ((EditableDrawable) view.getContent()).setText(((EditableDrawable) view.getContent()).getText());
        view.forceUpdate();
    }
}
Also used : EditText(android.widget.EditText) ImageViewDrawableOverlay(com.aviary.android.feather.widget.ImageViewDrawableOverlay) EditableDrawable(com.aviary.android.feather.library.graphics.drawable.EditableDrawable) Handler(android.os.Handler) ResultReceiver(android.os.ResultReceiver)

Example 7 with ImageViewDrawableOverlay

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

the class StickersPanel method addSticker.

/**
	 * Adds the sticker.
	 * 
	 * @param drawable
	 *           - the drawable
	 * @param rotateAndResize
	 *           - allow rotate and resize
	 */
private void addSticker(FeatherDrawable drawable, boolean rotateAndResize, RectF positionRect) {
    mLogger.info("addSticker: " + drawable + ", rotate: " + rotateAndResize + ", position: " + positionRect);
    setIsChanged(true);
    DrawableHighlightView hv = new DrawableHighlightView(mImageView, drawable);
    hv.setOnDeleteClickListener(new OnDeleteClickListener() {

        @Override
        public void onDeleteClick() {
            onClearCurrent(true);
        }
    });
    Matrix mImageMatrix = mImageView.getImageViewMatrix();
    int cropWidth, cropHeight;
    int x, y;
    final int width = mImageView.getWidth();
    final int height = mImageView.getHeight();
    // width/height of the sticker
    if (positionRect != null) {
        cropWidth = (int) positionRect.width();
        cropHeight = (int) positionRect.height();
    } else {
        cropWidth = drawable.getIntrinsicWidth();
        cropHeight = drawable.getIntrinsicHeight();
    }
    final int cropSize = Math.max(cropWidth, cropHeight);
    final int screenSize = Math.min(mImageView.getWidth(), mImageView.getHeight());
    if (cropSize > screenSize) {
        float ratio;
        float widthRatio = (float) mImageView.getWidth() / cropWidth;
        float heightRatio = (float) mImageView.getHeight() / cropHeight;
        if (widthRatio < heightRatio) {
            ratio = widthRatio;
        } else {
            ratio = heightRatio;
        }
        cropWidth = (int) ((float) cropWidth * (ratio / 2));
        cropHeight = (int) ((float) cropHeight * (ratio / 2));
        if (positionRect == null) {
            int w = mImageView.getWidth();
            int h = mImageView.getHeight();
            positionRect = new RectF(w / 2 - cropWidth / 2, h / 2 - cropHeight / 2, w / 2 + cropWidth / 2, h / 2 + cropHeight / 2);
        }
        positionRect.inset((positionRect.width() - cropWidth) / 2, (positionRect.height() - cropHeight) / 2);
    }
    if (positionRect != null) {
        x = (int) positionRect.left;
        y = (int) positionRect.top;
    } else {
        x = (width - cropWidth) / 2;
        y = (height - cropHeight) / 2;
    }
    Matrix matrix = new Matrix(mImageMatrix);
    matrix.invert(matrix);
    float[] pts = new float[] { x, y, x + cropWidth, y + cropHeight };
    MatrixUtils.mapPoints(matrix, pts);
    RectF cropRect = new RectF(pts[0], pts[1], pts[2], pts[3]);
    Rect imageRect = new Rect(0, 0, width, height);
    hv.setRotateAndScale(rotateAndResize);
    hv.setup(mImageMatrix, imageRect, cropRect, false);
    hv.drawOutlineFill(true);
    hv.drawOutlineStroke(true);
    hv.setPadding(mStickerHvPadding);
    hv.setOutlineStrokeColor(mStickerHvStrokeColorStateList);
    hv.setOutlineFillColor(mStickerHvFillColorStateList);
    hv.setOutlineEllipse(mStickerHvEllipse);
    hv.setMinSize(mStickerHvMinSize);
    Paint stroke = hv.getOutlineStrokePaint();
    stroke.setStrokeWidth(mStickerHvStrokeWidth);
    hv.getOutlineFillPaint().setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.SRC_ATOP));
    ((ImageViewDrawableOverlay) mImageView).addHighlightView(hv);
    ((ImageViewDrawableOverlay) mImageView).setSelectedHighlightView(hv);
}
Also used : RectF(android.graphics.RectF) ImageViewDrawableOverlay(com.aviary.android.feather.widget.ImageViewDrawableOverlay) OnDeleteClickListener(com.aviary.android.feather.widget.DrawableHighlightView.OnDeleteClickListener) Rect(android.graphics.Rect) Matrix(android.graphics.Matrix) PorterDuffXfermode(android.graphics.PorterDuffXfermode) Paint(android.graphics.Paint) DrawableHighlightView(com.aviary.android.feather.widget.DrawableHighlightView) Paint(android.graphics.Paint) Point(android.graphics.Point)

Example 8 with ImageViewDrawableOverlay

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

the class StickersPanel method onCreate.

@SuppressWarnings("deprecation")
@Override
public void onCreate(Bitmap bitmap) {
    super.onCreate(bitmap);
    mStatus = new SimpleStatusMachine();
    // determine if the external packs are enabled
    mExternalPacksEnabled = Constants.getExternalStickersEnabled();
    // init layout components
    mListPacks = (HorizontalVariableListView) getOptionView().findViewById(R.id.list_packs);
    mListStickers = (HorizontalVariableListView) getOptionView().findViewById(R.id.list_stickers);
    mViewFlipper = (ViewFlipper) getOptionView().findViewById(R.id.flipper);
    mImageView = (ImageViewDrawableOverlay) getContentView().findViewById(R.id.overlay);
    // init services
    mPluginService = getContext().getService(PluginService.class);
    mConfigService = getContext().getService(ConfigService.class);
    mPreferenceService = getContext().getService(PreferenceService.class);
    mCacheService = getContext().getService(ImageCacheService.class);
    // TODO: only for testing
    // mCacheService.deleteCache();
    // setup the main horizontal listview
    mListPacks.setGravity(Gravity.BOTTOM);
    mListPacks.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
    mListPacks.setEdgeGravityY(Gravity.BOTTOM);
    // setup the stickers listview
    mListStickers.setGravity(Gravity.BOTTOM);
    mListStickers.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
    mListStickers.setEdgeGravityY(Gravity.BOTTOM);
    // setup the main imageview
    ((ImageViewDrawableOverlay) mImageView).setForceSingleSelection(false);
    ((ImageViewDrawableOverlay) mImageView).setDropTargetListener(this);
    ((ImageViewDrawableOverlay) mImageView).setScaleWithContent(true);
    // create the default action list
    mActionList = MoaActionFactory.actionList();
    // load the configuration for the sticker drawable
    mStickerHvEllipse = mConfigService.getInteger(R.integer.feather_sticker_highlight_ellipse);
    mStickerHvStrokeWidth = mConfigService.getInteger(R.integer.feather_sticker_highlight_stroke_width);
    mStickerHvStrokeColorStateList = mConfigService.getColorStateList(R.color.feather_sticker_color_stroke_selector);
    mStickerHvFillColorStateList = mConfigService.getColorStateList(R.color.feather_sticker_color_fill_selector);
    mStickerHvMinSize = mConfigService.getInteger(R.integer.feather_sticker_highlight_minsize);
    mStickerHvPadding = mConfigService.getInteger(R.integer.feather_sticker_highlight_padding);
    mFeaturedCount = mConfigService.getInteger(R.integer.feather_featured_count);
    mFeaturedDefaultTitle = mConfigService.getString(R.string.feather_featured);
    // update the background drawable
    View content = getOptionView().findViewById(R.id.background);
    content.setBackgroundDrawable(RepeatableHorizontalDrawable.createFromView(content));
    mImageManager = new AsyncImageManager();
    // create the preview for the main imageview
    createAndConfigurePreview();
    if (android.os.Build.VERSION.SDK_INT > 8) {
        DragControllerService dragger = getContext().getService(DragControllerService.class);
        dragger.addDropTarget((DropTarget) mImageView);
        dragger.setMoveTarget(mImageView);
        dragger.setDragListener(this);
        // TODO: remember to activate this!
        // dragger.activate();
        setDragController(dragger);
    }
}
Also used : ImageViewDrawableOverlay(com.aviary.android.feather.widget.ImageViewDrawableOverlay) DragControllerService(com.aviary.android.feather.library.services.DragControllerService) ConfigService(com.aviary.android.feather.library.services.ConfigService) PreferenceService(com.aviary.android.feather.library.services.PreferenceService) PluginService(com.aviary.android.feather.library.services.PluginService) ImageCacheService(com.aviary.android.feather.library.services.ImageCacheService) AsyncImageManager(com.aviary.android.feather.async_tasks.AsyncImageManager) ImageView(android.widget.ImageView) DragView(com.aviary.android.feather.library.services.drag.DragView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) DrawableHighlightView(com.aviary.android.feather.widget.DrawableHighlightView) HorizontalVariableListView(com.aviary.android.feather.widget.HorizontalVariableListView)

Example 9 with ImageViewDrawableOverlay

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

the class StickersPanel method onClearCurrent.

/**
	 * Remove the current sticker.
	 * 
	 * @param removed
	 *           - true if the current sticker is being removed, otherwise it was flattened
	 */
private void onClearCurrent(boolean removed) {
    mLogger.info("onClearCurrent. removed=" + removed);
    if (stickersOnScreen()) {
        final ImageViewDrawableOverlay image = (ImageViewDrawableOverlay) mImageView;
        final DrawableHighlightView hv = image.getHighlightViewAt(0);
        onClearCurrent(hv, removed);
    }
}
Also used : ImageViewDrawableOverlay(com.aviary.android.feather.widget.ImageViewDrawableOverlay) DrawableHighlightView(com.aviary.android.feather.widget.DrawableHighlightView)

Example 10 with ImageViewDrawableOverlay

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

the class MemePanel method addEditable.

/**
	 * Adds the editable.
	 * 
	 * @param hv
	 *           the hv
	 * @param imageMatrix
	 *           the image matrix
	 * @param cropRect
	 *           the crop rect
	 */
private void addEditable(DrawableHighlightView hv, Matrix imageMatrix, RectF cropRect) {
    final ImageViewDrawableOverlay image = (ImageViewDrawableOverlay) mImageView;
    hv.setRotateAndScale(true);
    hv.showAnchors(false);
    hv.drawOutlineFill(false);
    hv.drawOutlineStroke(false);
    hv.setup(imageMatrix, null, cropRect, false);
    hv.getOutlineFillPaint().setXfermode(new PorterDuffXfermode(android.graphics.PorterDuff.Mode.SRC_ATOP));
    hv.setMinSize(10);
    hv.setOutlineFillColor(new ColorStateList(new int[][] { { android.R.attr.state_active } }, new int[] { 0 }));
    hv.setOutlineStrokeColor(new ColorStateList(new int[][] { { android.R.attr.state_active } }, new int[] { 0 }));
    image.addHighlightView(hv);
}
Also used : ImageViewDrawableOverlay(com.aviary.android.feather.widget.ImageViewDrawableOverlay) PorterDuffXfermode(android.graphics.PorterDuffXfermode) ColorStateList(android.content.res.ColorStateList)

Aggregations

ImageViewDrawableOverlay (com.aviary.android.feather.widget.ImageViewDrawableOverlay)10 DrawableHighlightView (com.aviary.android.feather.widget.DrawableHighlightView)7 Matrix (android.graphics.Matrix)3 Paint (android.graphics.Paint)3 Rect (android.graphics.Rect)3 RectF (android.graphics.RectF)3 EditableDrawable (com.aviary.android.feather.library.graphics.drawable.EditableDrawable)3 Point (android.graphics.Point)2 PorterDuffXfermode (android.graphics.PorterDuffXfermode)2 StickerDrawable (com.aviary.android.feather.library.graphics.drawable.StickerDrawable)2 ColorStateList (android.content.res.ColorStateList)1 Handler (android.os.Handler)1 ResultReceiver (android.os.ResultReceiver)1 View (android.view.View)1 AdapterView (android.widget.AdapterView)1 EditText (android.widget.EditText)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 AsyncImageManager (com.aviary.android.feather.async_tasks.AsyncImageManager)1 FeatherDrawable (com.aviary.android.feather.library.graphics.drawable.FeatherDrawable)1