Java Code Examples for android.graphics.drawable.BitmapDrawable#setTileModeX()

The following examples show how to use android.graphics.drawable.BitmapDrawable#setTileModeX() . 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: CanvasActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * Sets a bitmap to ImageView.
 * @param bitmap bitmap
 * @param mode mode
 * @param x x
 * @param y y
 */
private synchronized void setImageBitmap(final Bitmap bitmap, final int mode, final int x, final int y) {
    switch (mode) {
        default:
        case WearConst.MODE_NORMAL:
            Matrix matrix = new Matrix();
            matrix.postTranslate((float) x, (float) y);
            mImageView.setImageBitmap(bitmap);
            mImageView.setScaleType(ImageView.ScaleType.MATRIX);
            mImageView.setImageMatrix(matrix);
            mImageView.setVisibility(View.VISIBLE);
            BoxInsetLayout.LayoutParams normalLayoutParam = new BoxInsetLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT, Gravity.CENTER, BOX_ALL);
            mFrameLayout.setLayoutParams(normalLayoutParam);
            break;
        case WearConst.MODE_SCALES:
            mImageView.setImageBitmap(bitmap);
            mImageView.setScaleType(ImageView.ScaleType.FIT_START);
            mImageView.setTranslationX(x);
            mImageView.setTranslationY(y);
            mImageView.setVisibility(View.VISIBLE);
            BoxInsetLayout.LayoutParams scaleLayoutParam = new BoxInsetLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT, Gravity.LEFT | Gravity.TOP);
            mFrameLayout.setLayoutParams(scaleLayoutParam);
            break;
        case WearConst.MODE_FILLS:
            BitmapDrawable bd = new BitmapDrawable(getResources(), bitmap);
            bd.setTileModeX(Shader.TileMode.REPEAT);
            bd.setTileModeY(Shader.TileMode.REPEAT);
            mImageView.setImageDrawable(bd);
            mImageView.setScaleType(ImageView.ScaleType.FIT_XY);
            mImageView.setTranslationX(x);
            mImageView.setTranslationY(y);
            mImageView.setVisibility(View.VISIBLE);
            BoxInsetLayout.LayoutParams fillLayoutParam = new BoxInsetLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.MATCH_PARENT, Gravity.LEFT | Gravity.TOP);
            mFrameLayout.setLayoutParams(fillLayoutParam);
            break;
    }
}
 
Example 2
Source File: CanvasProfileActivity.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * 画面を更新します.
 * @param drawObj 更新する画像データ
 */
private void showDrawObject(final CanvasDrawImageObject drawObj) {
    switch (drawObj.getMode()) {
        default:
        case NON_SCALE_MODE:
            Matrix matrix = new Matrix();
            matrix.postTranslate((float) drawObj.getX(), (float) drawObj.getY());
            mCanvasView.setImageBitmap(mBitmap);
            mCanvasView.setScaleType(ScaleType.MATRIX);
            mCanvasView.setImageMatrix(matrix);
            break;
        case SCALE_MODE:
            mCanvasView.setImageBitmap(mBitmap);
            mCanvasView.setScaleType(ScaleType.FIT_CENTER);
            mCanvasView.setTranslationX((int) drawObj.getX());
            mCanvasView.setTranslationY((int) drawObj.getY());
            break;
        case FILL_MODE:
            BitmapDrawable bd = new BitmapDrawable(getResources(), mBitmap);
            bd.setTileModeX(Shader.TileMode.REPEAT);
            bd.setTileModeY(Shader.TileMode.REPEAT);
            mCanvasView.setImageDrawable(bd);
            mCanvasView.setScaleType(ScaleType.FIT_XY);
            mCanvasView.setTranslationX((int) drawObj.getX());
            mCanvasView.setTranslationY((int) drawObj.getY());
            break;
    }
}
 
Example 3
Source File: MainActivity.java    From CircularImageView with Apache License 2.0 5 votes vote down vote up
/**
 * Setup image container
 */
private void setupImageContainer() {
    Resources res = getResources();
    Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.grid);
    int cellH = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 22, res.getDisplayMetrics());
    bitmap = Bitmap.createScaledBitmap(bitmap, cellH, cellH, true);

    BitmapDrawable bitmapDrawable = new BitmapDrawable(res, bitmap);
    bitmapDrawable.setTileModeX(Shader.TileMode.REPEAT);
    bitmapDrawable.setTileModeY(Shader.TileMode.REPEAT);
    mImageContainer.setBackgroundDrawable(bitmapDrawable);
}