android.graphics.NinePatch Java Examples

The following examples show how to use android.graphics.NinePatch. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PigstyMode.java    From CatchPiggy with GNU General Public License v3.0 6 votes vote down vote up
private void init() {
    isFirstInit = true;
    setZOrderOnTop(true);
    mSurfaceHolder = getHolder();
    mSurfaceHolder.setFormat(PixelFormat.TRANSLUCENT);
    mSurfaceHolder.addCallback(this);
    mCaughtPiggies = new ArrayList<>();
    mDraggingProps = new HashSet<>();
    mDraggingPiggies = new HashSet<>();
    mDraggingPropIds = new SparseIntArray();
    mDraggingPiggyIds = new SparseIntArray();
    mCaughtPiggiesPosition = new SparseIntArray();
    mComputePathTasks = new Future[PIGGY_COUNT];
    mPiggiesOccupiedPosition = new WayData[PIGGY_COUNT];
    mCarriageIsOccupied = new boolean[PIGGY_COUNT];
    mItemSize = (int) getContext().getResources().getDimension(R.dimen.xhpx_64);
    mPropSize = (int) getContext().getResources().getDimension(R.dimen.xhpx_108);
    mFrameBackgroundBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_frame);
    mFrameBackground = new NinePatch(mFrameBackgroundBitmap, mFrameBackgroundBitmap.getNinePatchChunk(), null);
    mLevelStringFormat = getContext().getString(R.string.level_format);
    initCar();
    initPaint();
    initPiggies();
}
 
Example #2
Source File: RecyclerViewLinearItemDecoration.java    From RecyclerViewDecoration with Apache License 2.0 6 votes vote down vote up
private void initPaint(Context context) {

        this.mBmp = BitmapFactory.decodeResource(context.getResources(), mDrawableRid);
        if (mBmp != null) {

            if (mBmp.getNinePatchChunk() != null) {
                hasNinePatch = true;
                mNinePatch = new NinePatch(mBmp, mBmp.getNinePatchChunk(), null);
            }

            if (mMode == RVItemDecorationConst.MODE_HORIZONTAL) {
                mCurrentThickness = mThickness == 0 ? mBmp.getHeight() : mThickness;
            }
            if (mMode == RVItemDecorationConst.MODE_VERTICAL) {
                mCurrentThickness = mThickness == 0 ? mBmp.getWidth() : mThickness;
            }
        } else {
            mCurrentThickness = mThickness;
        }

        mPaint = new Paint();
        mPaint.setColor(mColor);
        mPaint.setStyle(Paint.Style.STROKE);
        mPaint.setStrokeWidth(mCurrentThickness);
    }
 
Example #3
Source File: BackGroudSeletor.java    From FloatBall with Apache License 2.0 6 votes vote down vote up
/**
 * 获取asset下面的.9 png
 *
 * @param imagename 图片名
 * @param context   上下文对象
 */
public static NinePatchDrawable get9png(String imagename, Context context) {
    Bitmap toast_bitmap;
    try {
        toast_bitmap = BitmapFactory.decodeStream(context.getAssets().open("image/" + imagename + ".9.png"));
        byte[] temp = toast_bitmap.getNinePatchChunk();
        boolean is_nine = NinePatch.isNinePatchChunk(temp);
        if (is_nine) {
            NinePatchDrawable nine_draw = new NinePatchDrawable(context.getResources(), toast_bitmap, temp, new Rect(), null);
            return nine_draw;
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example #4
Source File: RecordingCanvas.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public final void drawPatch(@NonNull NinePatch patch, @NonNull RectF dst,
        @Nullable Paint paint) {
    Bitmap bitmap = patch.getBitmap();
    throwIfCannotDraw(bitmap);
    final long nativePaint = paint == null ? 0 : paint.getNativeInstance();
    nDrawNinePatch(mNativeCanvasWrapper, bitmap.getNativeInstance(), patch.mNativeChunk,
            dst.left, dst.top, dst.right, dst.bottom, nativePaint,
            mDensity, patch.getDensity());
}
 
Example #5
Source File: NinePatchUtil.java    From pixate-freestyle-android with Apache License 2.0 5 votes vote down vote up
public static NinePatchDrawable createNinePatch(Resources res, Bitmap bitmap, PXOffsets insets,
        String srcName) {

    byte[] chunk = createNinePatchChunk(insets);
    NinePatchDrawable drawable = new NinePatchDrawable(res, new NinePatch(bitmap, chunk,
            srcName));
    return drawable;
}
 
Example #6
Source File: ChatImageView.java    From ChatImageView with MIT License 5 votes vote down vote up
private void init() {
    mMatrix = new Matrix();
    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
    if (mMaskResId <= 0) {
        return;
    }
    mMaskBmp = BitmapFactory.decodeResource(getResources(), mMaskResId);
    byte[] ninePatchChunk = mMaskBmp.getNinePatchChunk();
    if (ninePatchChunk != null && NinePatch.isNinePatchChunk(ninePatchChunk)) {
        mMaskDrawable = new NinePatchDrawable(getResources(), mMaskBmp, ninePatchChunk, new Rect(), null);
    }
    internalSetImage();
}
 
Example #7
Source File: Utils.java    From RangeSeekBar with Apache License 2.0 5 votes vote down vote up
public static void drawBitmap(Canvas canvas, Paint paint, Bitmap bmp, Rect rect) {
    try {
        if (NinePatch.isNinePatchChunk(bmp.getNinePatchChunk())) {
            drawNinePath(canvas, bmp, rect);
            return;
        }
    } catch (Exception e) {
    }
    canvas.drawBitmap(bmp, rect.left, rect.top, paint);
}
 
Example #8
Source File: TaskGuide.java    From letv with Apache License 2.0 5 votes vote down vote up
private Drawable a(String str, Context context) {
    Drawable createFromStream;
    IOException e;
    try {
        InputStream open = context.getApplicationContext().getAssets().open(str);
        if (open == null) {
            return null;
        }
        if (str.endsWith(".9.png")) {
            Bitmap decodeStream = BitmapFactory.decodeStream(open);
            if (decodeStream == null) {
                return null;
            }
            byte[] ninePatchChunk = decodeStream.getNinePatchChunk();
            NinePatch.isNinePatchChunk(ninePatchChunk);
            return new NinePatchDrawable(decodeStream, ninePatchChunk, new Rect(), null);
        }
        createFromStream = Drawable.createFromStream(open, str);
        try {
            open.close();
            return createFromStream;
        } catch (IOException e2) {
            e = e2;
            e.printStackTrace();
            return createFromStream;
        }
    } catch (IOException e3) {
        IOException iOException = e3;
        createFromStream = null;
        e = iOException;
        e.printStackTrace();
        return createFromStream;
    }
}
 
Example #9
Source File: AuthAgent.java    From letv with Apache License 2.0 5 votes vote down vote up
private Drawable a(String str, Context context) {
    Drawable createFromStream;
    IOException e;
    try {
        InputStream open = context.getApplicationContext().getAssets().open(str);
        if (open == null) {
            return null;
        }
        if (str.endsWith(".9.png")) {
            Bitmap decodeStream = BitmapFactory.decodeStream(open);
            if (decodeStream == null) {
                return null;
            }
            byte[] ninePatchChunk = decodeStream.getNinePatchChunk();
            NinePatch.isNinePatchChunk(ninePatchChunk);
            return new NinePatchDrawable(decodeStream, ninePatchChunk, new Rect(), null);
        }
        createFromStream = Drawable.createFromStream(open, str);
        try {
            open.close();
            return createFromStream;
        } catch (IOException e2) {
            e = e2;
            e.printStackTrace();
            return createFromStream;
        }
    } catch (IOException e3) {
        IOException iOException = e3;
        createFromStream = null;
        e = iOException;
        e.printStackTrace();
        return createFromStream;
    }
}
 
Example #10
Source File: RecyclerViewItemDecoration.java    From FriendBook with GNU General Public License v3.0 5 votes vote down vote up
public void setParams(Context context, Param params) {

        this.mMode = params.mode;
        this.mDrawableRid = params.drawableRid;
        this.mColor = params.color;
        this.mThickness = params.thickness;
        this.mDashGap = params.dashGap;
        this.mDashWidth = params.dashWidth;
        this.mPaddingStart = params.paddingStart;
        this.mPaddingEnd = params.paddingEnd;
        this.mFirstLineVisible = params.firstLineVisible;
        this.mLastLineVisible = params.lastLineVisible;
        this.mGridLeftVisible = params.gridLeftVisible;
        this.mGridRightVisible = params.gridRightVisible;
        this.mGridTopVisible = params.gridTopVisible;
        this.mGridBottomVisible = params.gridBottomVisible;
        this.mGridHorizontalSpacing = params.gridHorizontalSpacing;
        this.mGridVerticalSpacing = params.gridVerticalSpacing;

        this.mParent = params.parent;

        if (mParent != null) compatibleWithLayoutManager(mParent);

        this.mBmp = BitmapFactory.decodeResource(context.getResources(), mDrawableRid);
        if (mBmp != null) {

            if (mBmp.getNinePatchChunk() != null) {
                hasNinePatch = true;
                mNinePatch = new NinePatch(mBmp, mBmp.getNinePatchChunk(), null);
            }

            if (mMode == MODE_HORIZONTAL)
                mCurrentThickness = mThickness == 0 ? mBmp.getHeight() : mThickness;
            if (mMode == MODE_VERTICAL)
                mCurrentThickness = mThickness == 0 ? mBmp.getWidth() : mThickness;
        }

        initPaint();

    }
 
Example #11
Source File: RecordingCanvas.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
@Override
public final void drawPatch(@NonNull NinePatch patch, @NonNull Rect dst,
        @Nullable Paint paint) {
    Bitmap bitmap = patch.getBitmap();
    throwIfCannotDraw(bitmap);
    final long nativePaint = paint == null ? 0 : paint.getNativeInstance();
    nDrawNinePatch(mNativeCanvasWrapper, bitmap.getNativeInstance(), patch.mNativeChunk,
            dst.left, dst.top, dst.right, dst.bottom, nativePaint,
            mDensity, patch.getDensity());
}
 
Example #12
Source File: NinePatchData.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Attempts to decode 9-patch data from a {@link Bitmap}.
 * @param bitmap The {@link Bitmap} to check.
 * @return       An instance of {@link NinePatchData} representing the 9-patch information
 *               encoded in {@code bitmap} or {@code null} if the {@link Bitmap} wasn't a
 *               9-patch.
 */
public static NinePatchData create(Bitmap bitmap) {
    if (bitmap == null) return null;

    try {
        byte[] chunk = bitmap.getNinePatchChunk();
        if (chunk == null || !NinePatch.isNinePatchChunk(chunk)) return null;

        ByteBuffer buffer = ByteBuffer.wrap(chunk).order(ByteOrder.nativeOrder());

        // int8_t wasDeserialized
        if (buffer.get() == 0) return null;

        // int8_t numXDivs
        int numDivX = buffer.get();
        if (numDivX == 0 || (numDivX & 0x01) != 0) return null;

        // int8_t numYDivs
        int numDivY = buffer.get();
        if (numDivY == 0 || (numDivY & 0x01) != 0) return null;

        // int8_t numColors
        buffer.get();

        // uint32_t xDivsOffset
        buffer.getInt();

        // uint32_t yDivsOffset
        buffer.getInt();

        Rect padding = new Rect();

        // uint32_t paddingLeft
        padding.left = buffer.getInt();

        // uint32_t paddingRight
        padding.right = buffer.getInt();

        // uint32_t paddingTop
        padding.top = buffer.getInt();

        // uint32_t paddingBottom
        padding.bottom = buffer.getInt();

        // uint32_t colorsOffset
        buffer.getInt();

        // uint32_t uint32_t uint32_t ...
        int[] divX = new int[numDivX];
        for (int i = 0; i < numDivX; i++) divX[i] = buffer.getInt();

        // uint32_t uint32_t uint32_t ...
        int[] divY = new int[numDivY];
        for (int i = 0; i < numDivY; i++) divY[i] = buffer.getInt();

        return new NinePatchData(bitmap.getWidth(), bitmap.getHeight(), padding, divX, divY);
    } catch (BufferUnderflowException ex) {
        return null;
    }
}
 
Example #13
Source File: RVPaint.java    From RecyclerViewDecoration with Apache License 2.0 4 votes vote down vote up
public static void drawNinePatch(Canvas canvas, NinePatch ninePatch, Rect rect) {
    ninePatch.draw(canvas, rect);
}
 
Example #14
Source File: RVPaint.java    From RecyclerViewDecoration with Apache License 2.0 4 votes vote down vote up
public static void drawNinePatch(Canvas canvas, NinePatch ninePatch, int left, int top, int right, int bottom) {
    ninePatch.draw(canvas, new Rect(left, top, right, bottom));
}
 
Example #15
Source File: NinePatchAssert.java    From assertj-android with Apache License 2.0 4 votes vote down vote up
public NinePatchAssert(NinePatch actual) {
  super(actual, NinePatchAssert.class);
}
 
Example #16
Source File: Utils.java    From RangeSeekBar with Apache License 2.0 2 votes vote down vote up
/**
 * draw 9Path
 *
 * @param canvas Canvas
 * @param bmp    9path bitmap
 * @param rect   9path rect
 */
public static void drawNinePath(Canvas canvas, Bitmap bmp, Rect rect) {
    NinePatch.isNinePatchChunk(bmp.getNinePatchChunk());
    NinePatch patch = new NinePatch(bmp, bmp.getNinePatchChunk(), null);
    patch.draw(canvas, rect);
}
 
Example #17
Source File: RxSeekBar.java    From RxTools-master with Apache License 2.0 2 votes vote down vote up
/**
 * 绘制 9Path
 *
 * @param c
 * @param bmp
 * @param rect
 */
public void drawNinePath(Canvas c, Bitmap bmp, Rect rect) {
    NinePatch patch = new NinePatch(bmp, bmp.getNinePatchChunk(), null);
    patch.draw(c, rect);
}
 
Example #18
Source File: Utils.java    From MusicPlayer with GNU General Public License v3.0 2 votes vote down vote up
/**
 * draw 9Path
 *
 * @param canvas Canvas
 * @param bmp 9path bitmap
 * @param rect 9path rect
 */
public static void drawNinePath(Canvas canvas, Bitmap bmp, Rect rect) {
    NinePatch patch = new NinePatch(bmp, bmp.getNinePatchChunk(), null);
    patch.draw(canvas, rect);
}