Example usage for android.graphics.drawable BitmapDrawable setTileModeY

List of usage examples for android.graphics.drawable BitmapDrawable setTileModeY

Introduction

In this page you can find the example usage for android.graphics.drawable BitmapDrawable setTileModeY.

Prototype

public final void setTileModeY(Shader.TileMode mode) 

Source Link

Document

Sets the repeat behavior of this drawable on the Y axis.

Usage

From source file:org.deviceconnect.android.deviceplugin.host.activity.CanvasProfileActivity.java

/**
 * ????./*from  www.  ja va 2s .c o  m*/
 * @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;
    }
}

From source file:org.appcelerator.titanium.util.TiUIHelper.java

public static Drawable buildImageDrawable(final Context context, final Object object, final boolean tileImage,
        final KrollProxy proxy) {

    if (object instanceof TiBlob) {

        switch (((TiBlob) object).getType()) {
        case TiBlob.TYPE_DRAWABLE:
            return buildImageDrawable(context, ((TiBlob) object).getDrawable(), tileImage, proxy);
        case TiBlob.TYPE_FILE:
        case TiBlob.TYPE_IMAGE:
            final String cacheKey = ((TiBlob) object).getCacheKey();
            Bitmap b = TiApplication.getImageMemoryCache().get(cacheKey);
            if (b == null) {
                b = ((TiBlob) object).getImage();
            }//from  w  w  w .j  a  v  a  2  s  .co m
            return buildImageDrawable(context, b, tileImage, proxy);
        default:
            return null;
        }
    } else if (object instanceof String) {
        String url = (String) object;
        if (url != null) {
            url = resolveImageUrl(url, proxy);
        }
        Drawable imageDrawable = null;
        if (url != null) {
            Cache cache = TiApplication.getImageMemoryCache();
            Bitmap bitmap = cache.get(url);
            if (bitmap == null) {
                imageDrawable = TiFileHelper.loadDrawable(url);
                if (imageDrawable instanceof BitmapDrawable) {
                    bitmap = ((BitmapDrawable) imageDrawable).getBitmap();
                    cache.set(url, ((BitmapDrawable) imageDrawable).getBitmap());
                }
            } else {
                imageDrawable = new BitmapDrawable(proxy.getActivity().getResources(), bitmap);
            }

            if (tileImage) {
                if (imageDrawable instanceof BitmapDrawable) {
                    BitmapDrawable tiledBackground = (BitmapDrawable) imageDrawable;
                    tiledBackground.setTileModeX(Shader.TileMode.REPEAT);
                    tiledBackground.setTileModeY(Shader.TileMode.REPEAT);
                }
            }
        }
        return imageDrawable;
    } else if (object instanceof Drawable) {
        Drawable imageDrawable = (Drawable) object;
        if (tileImage && imageDrawable instanceof BitmapDrawable) {
            BitmapDrawable tiledBackground = (BitmapDrawable) imageDrawable;
            tiledBackground.setTileModeX(Shader.TileMode.REPEAT);
            tiledBackground.setTileModeY(Shader.TileMode.REPEAT);
        }
        return imageDrawable;
    } else if (object instanceof Bitmap) {
        BitmapDrawable imageDrawable = new BitmapDrawable(context.getResources(), (Bitmap) object);
        if (tileImage) {
            if (imageDrawable instanceof BitmapDrawable) {
                BitmapDrawable tiledBackground = (BitmapDrawable) imageDrawable;
                tiledBackground.setTileModeX(Shader.TileMode.REPEAT);
                tiledBackground.setTileModeY(Shader.TileMode.REPEAT);
                imageDrawable = tiledBackground;
            }
        }
        return imageDrawable;
    }
    return null;
}