Search in sources :

Example 11 with NinePatchDrawable

use of android.graphics.drawable.NinePatchDrawable in project android_frameworks_base by ResurrectionRemix.

the class ResourceHelper method getNinePatchDrawable.

private static Drawable getNinePatchDrawable(InputStream inputStream, Density density, boolean isFramework, String cacheKey, BridgeContext context) throws IOException {
    // see if we still have both the chunk and the bitmap in the caches
    NinePatchChunk chunk = Bridge.getCached9Patch(cacheKey, isFramework ? null : context.getProjectKey());
    Bitmap bitmap = Bridge.getCachedBitmap(cacheKey, isFramework ? null : context.getProjectKey());
    // if either chunk or bitmap is null, then we reload the 9-patch file.
    if (chunk == null || bitmap == null) {
        try {
            NinePatch ninePatch = NinePatch.load(inputStream, true, /*is9Patch*/
            false);
            if (ninePatch != null) {
                if (chunk == null) {
                    chunk = ninePatch.getChunk();
                    Bridge.setCached9Patch(cacheKey, chunk, isFramework ? null : context.getProjectKey());
                }
                if (bitmap == null) {
                    bitmap = Bitmap_Delegate.createBitmap(ninePatch.getImage(), false, /*isMutable*/
                    density);
                    Bridge.setCachedBitmap(cacheKey, bitmap, isFramework ? null : context.getProjectKey());
                }
            }
        } catch (MalformedURLException e) {
        // URL is wrong, we'll return null below
        }
    }
    if (chunk != null && bitmap != null) {
        int[] padding = chunk.getPadding();
        Rect paddingRect = new Rect(padding[0], padding[1], padding[2], padding[3]);
        return new NinePatchDrawable(context.getResources(), bitmap, NinePatch_Delegate.serialize(chunk), paddingRect, null);
    }
    return null;
}
Also used : Bitmap(android.graphics.Bitmap) MalformedURLException(java.net.MalformedURLException) Rect(android.graphics.Rect) NinePatch(com.android.ninepatch.NinePatch) NinePatchChunk(com.android.ninepatch.NinePatchChunk) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable)

Example 12 with NinePatchDrawable

use of android.graphics.drawable.NinePatchDrawable in project android_packages_apps_Launcher2 by CyanogenMod.

the class CellLayout method dispatchDraw.

@Override
protected void dispatchDraw(Canvas canvas) {
    super.dispatchDraw(canvas);
    if (mForegroundAlpha > 0) {
        mOverScrollForegroundDrawable.setBounds(mForegroundRect);
        Paint p = ((NinePatchDrawable) mOverScrollForegroundDrawable).getPaint();
        p.setXfermode(sAddBlendMode);
        mOverScrollForegroundDrawable.draw(canvas);
        p.setXfermode(null);
    }
}
Also used : Paint(android.graphics.Paint) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable)

Example 13 with NinePatchDrawable

use of android.graphics.drawable.NinePatchDrawable in project android_packages_inputmethods_LatinIME by CyanogenMod.

the class KeyboardView method onDrawKeyTopVisuals.

// Draw key top visuals.
protected void onDrawKeyTopVisuals(@Nonnull final Key key, @Nonnull final Canvas canvas, @Nonnull final Paint paint, @Nonnull final KeyDrawParams params) {
    final int keyWidth = key.getDrawWidth();
    final int keyHeight = key.getHeight();
    final float centerX = keyWidth * 0.5f;
    final float centerY = keyHeight * 0.5f;
    // Draw key label.
    final Keyboard keyboard = getKeyboard();
    final Drawable icon = (keyboard == null) ? null : key.getIcon(keyboard.mIconsSet, params.mAnimAlpha);
    float labelX = centerX;
    float labelBaseline = centerY;
    final String label = key.getLabel();
    if (label != null) {
        paint.setTypeface(key.selectTypeface(params));
        paint.setTextSize(key.selectTextSize(params));
        final float labelCharHeight = TypefaceUtils.getReferenceCharHeight(paint);
        final float labelCharWidth = TypefaceUtils.getReferenceCharWidth(paint);
        // Vertical label text alignment.
        labelBaseline = centerY + labelCharHeight / 2.0f;
        // Horizontal label text alignment
        if (key.isAlignLabelOffCenter()) {
            // The label is placed off center of the key. Used mainly on "phone number" layout.
            labelX = centerX + params.mLabelOffCenterRatio * labelCharWidth;
            paint.setTextAlign(Align.LEFT);
        } else {
            labelX = centerX;
            paint.setTextAlign(Align.CENTER);
        }
        if (key.needsAutoXScale()) {
            final float ratio = Math.min(1.0f, (keyWidth * MAX_LABEL_RATIO) / TypefaceUtils.getStringWidth(label, paint));
            if (key.needsAutoScale()) {
                final float autoSize = paint.getTextSize() * ratio;
                paint.setTextSize(autoSize);
            } else {
                paint.setTextScaleX(ratio);
            }
        }
        if (key.isEnabled()) {
            paint.setColor(key.selectTextColor(params));
            // Set a drop shadow for the text if the shadow radius is positive value.
            if (mKeyTextShadowRadius > 0.0f) {
                paint.setShadowLayer(mKeyTextShadowRadius, 0.0f, 0.0f, params.mTextShadowColor);
            } else {
                paint.clearShadowLayer();
            }
        } else {
            // Make label invisible
            paint.setColor(Color.TRANSPARENT);
            paint.clearShadowLayer();
        }
        blendAlpha(paint, params.mAnimAlpha);
        canvas.drawText(label, 0, label.length(), labelX, labelBaseline, paint);
        // Turn off drop shadow and reset x-scale.
        paint.clearShadowLayer();
        paint.setTextScaleX(1.0f);
    }
    // Draw hint label.
    final String hintLabel = key.getHintLabel();
    if (hintLabel != null) {
        paint.setTextSize(key.selectHintTextSize(params));
        paint.setColor(key.selectHintTextColor(params));
        // TODO: Should add a way to specify type face for hint letters
        paint.setTypeface(Typeface.DEFAULT_BOLD);
        blendAlpha(paint, params.mAnimAlpha);
        final float labelCharHeight = TypefaceUtils.getReferenceCharHeight(paint);
        final float labelCharWidth = TypefaceUtils.getReferenceCharWidth(paint);
        final float hintX, hintBaseline;
        if (key.hasHintLabel()) {
            // The hint label is placed just right of the key label. Used mainly on
            // "phone number" layout.
            hintX = labelX + params.mHintLabelOffCenterRatio * labelCharWidth;
            if (key.isAlignHintLabelToBottom(mDefaultKeyLabelFlags)) {
                hintBaseline = labelBaseline;
            } else {
                hintBaseline = centerY + labelCharHeight / 2.0f;
            }
            paint.setTextAlign(Align.LEFT);
        } else if (key.hasShiftedLetterHint()) {
            // The hint label is placed at top-right corner of the key. Used mainly on tablet.
            hintX = keyWidth - mKeyShiftedLetterHintPadding - labelCharWidth / 2.0f;
            paint.getFontMetrics(mFontMetrics);
            hintBaseline = -mFontMetrics.top;
            paint.setTextAlign(Align.CENTER);
        } else {
            // key.hasHintLetter()
            // The hint letter is placed at top-right corner of the key. Used mainly on phone.
            final float hintDigitWidth = TypefaceUtils.getReferenceDigitWidth(paint);
            final float hintLabelWidth = TypefaceUtils.getStringWidth(hintLabel, paint);
            hintX = keyWidth - mKeyHintLetterPadding - Math.max(hintDigitWidth, hintLabelWidth) / 2.0f;
            hintBaseline = -paint.ascent();
            paint.setTextAlign(Align.CENTER);
        }
        final float adjustmentY = params.mHintLabelVerticalAdjustment * labelCharHeight;
        canvas.drawText(hintLabel, 0, hintLabel.length(), hintX, hintBaseline + adjustmentY, paint);
    }
    // Draw key icon.
    if (label == null && icon != null) {
        final int iconWidth;
        if (key.getCode() == Constants.CODE_SPACE && icon instanceof NinePatchDrawable) {
            iconWidth = (int) (keyWidth * mSpacebarIconWidthRatio);
        } else {
            iconWidth = Math.min(icon.getIntrinsicWidth(), keyWidth);
        }
        final int iconHeight = icon.getIntrinsicHeight();
        final int iconY;
        if (key.isAlignIconToBottom()) {
            iconY = keyHeight - iconHeight;
        } else {
            // Align vertically center.
            iconY = (keyHeight - iconHeight) / 2;
        }
        // Align horizontally center.
        final int iconX = (keyWidth - iconWidth) / 2;
        drawIcon(canvas, icon, iconX, iconY, iconWidth, iconHeight);
    }
    if (key.hasPopupHint() && key.getMoreKeys() != null) {
        drawKeyPopupHint(key, canvas, paint, params);
    }
}
Also used : NinePatchDrawable(android.graphics.drawable.NinePatchDrawable) Drawable(android.graphics.drawable.Drawable) Paint(android.graphics.Paint) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable)

Example 14 with NinePatchDrawable

use of android.graphics.drawable.NinePatchDrawable in project android_frameworks_base by DirtyUnicorns.

the class ResourceHelper method getNinePatchDrawable.

private static Drawable getNinePatchDrawable(InputStream inputStream, Density density, boolean isFramework, String cacheKey, BridgeContext context) throws IOException {
    // see if we still have both the chunk and the bitmap in the caches
    NinePatchChunk chunk = Bridge.getCached9Patch(cacheKey, isFramework ? null : context.getProjectKey());
    Bitmap bitmap = Bridge.getCachedBitmap(cacheKey, isFramework ? null : context.getProjectKey());
    // if either chunk or bitmap is null, then we reload the 9-patch file.
    if (chunk == null || bitmap == null) {
        try {
            NinePatch ninePatch = NinePatch.load(inputStream, true, /*is9Patch*/
            false);
            if (ninePatch != null) {
                if (chunk == null) {
                    chunk = ninePatch.getChunk();
                    Bridge.setCached9Patch(cacheKey, chunk, isFramework ? null : context.getProjectKey());
                }
                if (bitmap == null) {
                    bitmap = Bitmap_Delegate.createBitmap(ninePatch.getImage(), false, /*isMutable*/
                    density);
                    Bridge.setCachedBitmap(cacheKey, bitmap, isFramework ? null : context.getProjectKey());
                }
            }
        } catch (MalformedURLException e) {
        // URL is wrong, we'll return null below
        }
    }
    if (chunk != null && bitmap != null) {
        int[] padding = chunk.getPadding();
        Rect paddingRect = new Rect(padding[0], padding[1], padding[2], padding[3]);
        return new NinePatchDrawable(context.getResources(), bitmap, NinePatch_Delegate.serialize(chunk), paddingRect, null);
    }
    return null;
}
Also used : Bitmap(android.graphics.Bitmap) MalformedURLException(java.net.MalformedURLException) Rect(android.graphics.Rect) NinePatch(com.android.ninepatch.NinePatch) NinePatchChunk(com.android.ninepatch.NinePatchChunk) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable)

Example 15 with NinePatchDrawable

use of android.graphics.drawable.NinePatchDrawable in project android_frameworks_base by AOSPA.

the class ResourceHelper method getNinePatchDrawable.

private static Drawable getNinePatchDrawable(InputStream inputStream, Density density, boolean isFramework, String cacheKey, BridgeContext context) throws IOException {
    // see if we still have both the chunk and the bitmap in the caches
    NinePatchChunk chunk = Bridge.getCached9Patch(cacheKey, isFramework ? null : context.getProjectKey());
    Bitmap bitmap = Bridge.getCachedBitmap(cacheKey, isFramework ? null : context.getProjectKey());
    // if either chunk or bitmap is null, then we reload the 9-patch file.
    if (chunk == null || bitmap == null) {
        try {
            NinePatch ninePatch = NinePatch.load(inputStream, true, /*is9Patch*/
            false);
            if (ninePatch != null) {
                if (chunk == null) {
                    chunk = ninePatch.getChunk();
                    Bridge.setCached9Patch(cacheKey, chunk, isFramework ? null : context.getProjectKey());
                }
                if (bitmap == null) {
                    bitmap = Bitmap_Delegate.createBitmap(ninePatch.getImage(), false, /*isMutable*/
                    density);
                    Bridge.setCachedBitmap(cacheKey, bitmap, isFramework ? null : context.getProjectKey());
                }
            }
        } catch (MalformedURLException e) {
        // URL is wrong, we'll return null below
        }
    }
    if (chunk != null && bitmap != null) {
        int[] padding = chunk.getPadding();
        Rect paddingRect = new Rect(padding[0], padding[1], padding[2], padding[3]);
        return new NinePatchDrawable(context.getResources(), bitmap, NinePatch_Delegate.serialize(chunk), paddingRect, null);
    }
    return null;
}
Also used : Bitmap(android.graphics.Bitmap) MalformedURLException(java.net.MalformedURLException) Rect(android.graphics.Rect) NinePatch(com.android.ninepatch.NinePatch) NinePatchChunk(com.android.ninepatch.NinePatchChunk) NinePatchDrawable(android.graphics.drawable.NinePatchDrawable)

Aggregations

NinePatchDrawable (android.graphics.drawable.NinePatchDrawable)34 GeneralItemAnimator (com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator)19 ItemShadowDecorator (com.h6ah4i.android.widget.advrecyclerview.decoration.ItemShadowDecorator)19 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)16 SimpleListDividerDecorator (com.h6ah4i.android.widget.advrecyclerview.decoration.SimpleListDividerDecorator)16 RecyclerViewDragDropManager (com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager)10 RecyclerView (android.support.v7.widget.RecyclerView)9 View (android.view.View)9 RecyclerViewSwipeManager (com.h6ah4i.android.widget.advrecyclerview.swipeable.RecyclerViewSwipeManager)9 RecyclerViewTouchActionGuardManager (com.h6ah4i.android.widget.advrecyclerview.touchguard.RecyclerViewTouchActionGuardManager)9 Bitmap (android.graphics.Bitmap)8 DraggableItemAnimator (com.h6ah4i.android.widget.advrecyclerview.animator.DraggableItemAnimator)8 Rect (android.graphics.Rect)7 SwipeDismissItemAnimator (com.h6ah4i.android.widget.advrecyclerview.animator.SwipeDismissItemAnimator)7 NinePatch (com.android.ninepatch.NinePatch)6 NinePatchChunk (com.android.ninepatch.NinePatchChunk)6 MalformedURLException (java.net.MalformedURLException)6 Parcelable (android.os.Parcelable)5 RecyclerViewExpandableItemManager (com.h6ah4i.android.widget.advrecyclerview.expandable.RecyclerViewExpandableItemManager)5 ImageView (android.widget.ImageView)4