Example usage for android.graphics.drawable BitmapDrawable setTileModeXY

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

Introduction

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

Prototype

public void setTileModeXY(Shader.TileMode xmode, Shader.TileMode ymode) 

Source Link

Document

Sets the repeat behavior of this drawable on both axis.

Usage

From source file:com.mobicage.rogerthat.plugins.messaging.FriendsThreadActivity.java

private void setThreadBackground() {
    Bitmap background = SystemPlugin.getAppAsset(mService, SystemPlugin.ASSET_CHAT_BACKGROUND);
    if (background == null) {
        findViewById(R.id.thread_container).setBackgroundResource(R.color.mc_background_color);
    } else {/*from w  w  w  . j av  a 2s  .com*/
        BitmapDrawable backgroundDrawable = new BitmapDrawable(getResources(), background);
        backgroundDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
        findViewById(R.id.thread_container).setBackground(backgroundDrawable);
    }
}

From source file:com.javielinux.fragments.MyActivityFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = View.inflate(getActivity(), R.layout.my_activity_fragment, null);

    themeManager = new ThemeManager(getActivity());
    themeManager.setTheme();/*from  w w  w  .  j  a va 2  s.  co  m*/

    themeManager.setColors();

    view.findViewById(R.id.layout_foot).setBackgroundColor(themeManager.getColor("color_bottom_bar"));

    BitmapDrawable bmp = (BitmapDrawable) getActivity().getResources()
            .getDrawable(themeManager.getResource("search_tile"));
    if (bmp != null) {
        bmp.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
        view.setBackgroundDrawable(bmp);
    }

    view.findViewById(R.id.my_activity_add_user).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showDialogSocialNetworks();
        }

    });

    view.findViewById(R.id.my_activity_add_search).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            ((TweetTopicsActivity) getActivity()).newSearch();
        }

    });

    view.findViewById(R.id.my_activity_add_trending).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showMenuMoreActions(v);
        }

    });

    view.findViewById(R.id.my_activity_more_options).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showMenuOptions(v);
        }

    });

    listUsers = (ListView) view.findViewById(R.id.my_activity_users);

    listUsers.setAdapter(adapter);

    lblEmpty = (TextView) view.findViewById(R.id.my_activity_empty);

    return view;
}

From source file:com.eleybourn.bookcatalogue.utils.Utils.java

/**
  * Reuse of bitmaps in tiled backgrounds is a known cause of problems:
  *      http://stackoverflow.com/questions/4077487/background-image-not-repeating-in-android-layout
 * So we avoid reusing them./*from   w  w  w  .  j a v  a  2  s .  c om*/
 * 
 * This seems to have become further messed up in 4.1 so now, we just created them manually. No references,
 * but the old cleanup method (see below for cleanupTiledBackground()) no longer works. Since it effectively
 * un-cached the background, we just create it here.
 * 
 * The main problem with this approach is that the style is defined in code rather than XML.
 *
 * @param a         Activity context
 * @param bright   Flag indicating if background should be 'bright'
 * 
 * @return         Background Drawable
 */
public static Drawable makeTiledBackground(boolean bright) {
    // Storage for the layers
    Drawable[] drawables = new Drawable[2];
    // Get the BG image, put in tiled drawable
    Bitmap b = BitmapFactory.decodeResource(BookCatalogueApp.context.getResources(), R.drawable.books_bg);
    BitmapDrawable bmD = new BitmapDrawable(BookCatalogueApp.context.getResources(), b);
    bmD.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
    // Add to layers
    drawables[0] = bmD;

    // Set up the gradient colours based on 'bright' setting
    int[] colours = new int[3];
    if (bright) {
        colours[0] = Color.argb(224, 0, 0, 0);
        colours[1] = Color.argb(208, 0, 0, 0);
        colours[2] = Color.argb(48, 0, 0, 0);
    } else {
        colours[0] = Color.argb(255, 0, 0, 0);
        colours[1] = Color.argb(208, 0, 0, 0);
        colours[2] = Color.argb(160, 0, 0, 0);
    }

    // Create a gradient and add to layers
    GradientDrawable gd = new GradientDrawable(GradientDrawable.Orientation.LEFT_RIGHT, colours);
    drawables[1] = gd;

    // Make the layers and we are done.
    LayerDrawable ll = new LayerDrawable(drawables);
    ll.setDither(true);

    return ll;
}

From source file:org.cryptsecure.Utility.java

/**
 * Sets the background tiled for a view element according to a given
 * resourceID.//from   w  w  w .ja  v a 2 s  .  c o m
 * 
 * @param activity
 *            the activity
 * @param view
 *            the view
 * @param resourceID
 *            the resource id
 */
@SuppressWarnings("deprecation")
public static void setBackground(Context activity, View view, int resourceID) {
    // set dolphin background
    Bitmap bm2 = BitmapFactory.decodeResource(activity.getResources(), resourceID);
    BitmapDrawable background2 = new BitmapDrawable(bm2);
    background2.setTileModeXY(TileMode.REPEAT, TileMode.REPEAT);
    view.setBackgroundDrawable(background2);
}

From source file:com.android.launcher2.AsyncTaskCallback.java

private Bitmap getWidgetPreview(ComponentName provider, int previewImage, int iconId, int cellHSpan,
        int cellVSpan, int maxWidth, int maxHeight) {
    // Load the preview image if possible
    String packageName = provider.getPackageName();
    if (maxWidth < 0)
        maxWidth = Integer.MAX_VALUE;
    if (maxHeight < 0)
        maxHeight = Integer.MAX_VALUE;

    Drawable drawable = null;/*w  w  w .j a va 2  s  .  c o m*/
    if (previewImage != 0) {
        drawable = mPackageManager.getDrawable(packageName, previewImage, null);
        if (drawable == null) {
            Log.w(TAG, "Can't load widget preview drawable 0x" + Integer.toHexString(previewImage)
                    + " for provider: " + provider);
        }
    }

    int bitmapWidth;
    int bitmapHeight;
    Bitmap defaultPreview = null;
    boolean widgetPreviewExists = (drawable != null);
    if (widgetPreviewExists) {
        bitmapWidth = drawable.getIntrinsicWidth();
        bitmapHeight = drawable.getIntrinsicHeight();
    } else {
        // Generate a preview image if we couldn't load one
        if (cellHSpan < 1)
            cellHSpan = 1;
        if (cellVSpan < 1)
            cellVSpan = 1;

        BitmapDrawable previewDrawable = (BitmapDrawable) getResources()
                .getDrawable(R.drawable.widget_preview_tile);
        final int previewDrawableWidth = previewDrawable.getIntrinsicWidth();
        final int previewDrawableHeight = previewDrawable.getIntrinsicHeight();
        bitmapWidth = previewDrawableWidth * cellHSpan; // subtract 2 dips
        bitmapHeight = previewDrawableHeight * cellVSpan;

        defaultPreview = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Config.ARGB_8888);
        final Canvas c = mCachedAppWidgetPreviewCanvas.get();
        c.setBitmap(defaultPreview);
        previewDrawable.setBounds(0, 0, bitmapWidth, bitmapHeight);
        previewDrawable.setTileModeXY(Shader.TileMode.REPEAT, Shader.TileMode.REPEAT);
        previewDrawable.draw(c);
        c.setBitmap(null);

        // Draw the icon in the top left corner
        int minOffset = (int) (mAppIconSize * sWidgetPreviewIconPaddingPercentage);
        int smallestSide = Math.min(bitmapWidth, bitmapHeight);
        float iconScale = Math.min((float) smallestSide / (mAppIconSize + 2 * minOffset), 1f);

        try {
            Drawable icon = null;
            int hoffset = (int) ((previewDrawableWidth - mAppIconSize * iconScale) / 2);
            int yoffset = (int) ((previewDrawableHeight - mAppIconSize * iconScale) / 2);
            if (iconId > 0)
                icon = mIconCache.getFullResIcon(packageName, iconId);
            if (icon != null) {
                renderDrawableToBitmap(icon, defaultPreview, hoffset, yoffset, (int) (mAppIconSize * iconScale),
                        (int) (mAppIconSize * iconScale));
            }
        } catch (Resources.NotFoundException e) {
        }
    }

    // Scale to fit width only - let the widget preview be clipped in the
    // vertical dimension
    float scale = 1f;
    if (bitmapWidth > maxWidth) {
        scale = maxWidth / (float) bitmapWidth;
    }
    if (scale != 1f) {
        bitmapWidth = (int) (scale * bitmapWidth);
        bitmapHeight = (int) (scale * bitmapHeight);
    }

    Bitmap preview = Bitmap.createBitmap(bitmapWidth, bitmapHeight, Config.ARGB_8888);

    // Draw the scaled preview into the final bitmap
    if (widgetPreviewExists) {
        renderDrawableToBitmap(drawable, preview, 0, 0, bitmapWidth, bitmapHeight);
    } else {
        final Canvas c = mCachedAppWidgetPreviewCanvas.get();
        final Rect src = mCachedAppWidgetPreviewSrcRect.get();
        final Rect dest = mCachedAppWidgetPreviewDestRect.get();
        c.setBitmap(preview);
        src.set(0, 0, defaultPreview.getWidth(), defaultPreview.getHeight());
        dest.set(0, 0, preview.getWidth(), preview.getHeight());

        Paint p = mCachedAppWidgetPreviewPaint.get();
        if (p == null) {
            p = new Paint();
            p.setFilterBitmap(true);
            mCachedAppWidgetPreviewPaint.set(p);
        }
        c.drawBitmap(defaultPreview, src, dest, p);
        c.setBitmap(null);
    }
    return preview;
}