Example usage for android.widget TextView getCompoundDrawables

List of usage examples for android.widget TextView getCompoundDrawables

Introduction

In this page you can find the example usage for android.widget TextView getCompoundDrawables.

Prototype

@NonNull
public Drawable[] getCompoundDrawables() 

Source Link

Document

Returns drawables for the left, top, right, and bottom borders.

Usage

From source file:com.github.topbottomsnackbar.TBSnackbar.java

public TBSnackbar setIconRight(@DrawableRes int drawableRes, float sizeDp) {
    final TextView tv = mView.getMessageView();
    Drawable drawable = ContextCompat.getDrawable(mContext, drawableRes);
    if (drawable != null) {
        drawable = fitDrawable(drawable, (int) convertDpToPixel(sizeDp, mContext));
    } else {/*  w w  w  .j av  a2 s.  com*/
        throw new IllegalArgumentException("resource_id is not a valid drawable!");
    }
    final Drawable[] compoundDrawables = tv.getCompoundDrawables();
    tv.setCompoundDrawables(compoundDrawables[0], compoundDrawables[1], drawable, compoundDrawables[3]);
    return this;
}

From source file:com.custom.music.MusicBrowserActivity.java

/**
 * update play back tab info/*  w  w w  .  j  a va2  s  . c o m*/
 */
private void updatePlaybackTab() {
    final int drawalbeTopPostion = 1;
    final int opaqueFull = 255; // 100%
    final int opaqueHalf = 128; // 50%
    TabWidget tabWidgetTemp = mTabHost.getTabWidget();
    TextView tabView = (TextView) tabWidgetTemp.getChildTabViewAt(PLAYBACK_INDEX);
    boolean enable = true;
    long id = -1;
    Drawable[] drawables;
    Drawable drawableTop = null;
    int drawableTopAlpha = opaqueFull;

    if (tabView == null) {
        return;
    }
    try {
        if (mService != null) {
            id = mService.getAudioId();
        }
    } catch (RemoteException ex) {
        Log.e(TAG, "updatePlaybackTab getAudioId remote excption:" + ex, Log.APP);
    }
    if (id == -1) {
        enable = false;
        drawableTopAlpha = opaqueHalf;
    }
    tabView.setEnabled(enable);
    drawables = tabView.getCompoundDrawables();
    drawableTop = drawables[drawalbeTopPostion];
    if (drawableTop != null) {
        drawableTop.setAlpha(drawableTopAlpha);
    }
    Log.i(TAG, "updatePlaybackTab:" + enable, Log.APP);
}

From source file:com.android.music.MusicBrowserActivity.java

/**
 * update play back tab info/* www. ja va  2 s  . c  om*/
 */
private void updatePlaybackTab() {
    final int drawalbeTopPostion = 1;
    final int opaqueFull = 255; // 100%
    final int opaqueHalf = 128; // 50%
    TabWidget tabWidgetTemp = mTabHost.getTabWidget();
    TextView tabView = (TextView) tabWidgetTemp.getChildTabViewAt(PLAYBACK_INDEX);
    boolean enable = true;
    long id = -1;
    Drawable[] drawables;
    Drawable drawableTop = null;
    int drawableTopAlpha = opaqueFull;

    if (tabView == null) {
        return;
    }
    try {
        if (mService != null) {
            id = mService.getAudioId();
        }
    } catch (RemoteException ex) {
        MusicLogUtils.e(TAG, "updatePlaybackTab getAudioId remote excption:" + ex);
    }
    if (id == -1) {
        enable = false;
        drawableTopAlpha = opaqueHalf;
    }
    tabView.setEnabled(enable);
    drawables = tabView.getCompoundDrawables();
    drawableTop = drawables[drawalbeTopPostion];
    if (drawableTop != null) {
        drawableTop.setAlpha(drawableTopAlpha);
    }
    MusicLogUtils.d(TAG, "updatePlaybackTab:" + enable);
}

From source file:org.telegram.ui.ProfileActivity.java

private static int getSideDrawablesSize(TextView textView) {
    Drawable[] drawable = textView.getCompoundDrawables();
    int size = 0;
    if (drawable[0] != null) {
        size += drawable[0].getIntrinsicWidth() + textView.getCompoundDrawablePadding();
    }//from  w  w  w .  j a va  2 s . co  m
    if (drawable[2] != null) {
        size += drawable[2].getIntrinsicWidth() + textView.getCompoundDrawablePadding();
    }
    return size;
}

From source file:com.klinker.android.launcher.launcher3.Workspace.java

/**
 * Returns the drawable for the given text view.
 *//*from w  w  w.j  a  v  a  2 s.c o m*/
public static Drawable getTextViewIcon(TextView tv) {
    final Drawable[] drawables = tv.getCompoundDrawables();
    for (int i = 0; i < drawables.length; i++) {
        if (drawables[i] != null) {
            return drawables[i];
        }
    }
    return null;
}

From source file:com.zyk.launcher.Workspace.java

public void onExternalDragStartedWithItem(View v) {
    // Compose a drag bitmap with the view scaled to the icon size
    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    int iconSize = grid.iconSizePx;
    int bmpWidth = v.getMeasuredWidth();
    int bmpHeight = v.getMeasuredHeight();

    // If this is a text view, use its drawable instead
    if (v instanceof TextView) {
        TextView tv = (TextView) v;
        Drawable d = tv.getCompoundDrawables()[1];
        Rect bounds = Utils.getDrawableBounds(d);
        bmpWidth = bounds.width();/* w ww .  j  a va  2s .  com*/
        bmpHeight = bounds.height();
    }

    // Compose the bitmap to create the icon from
    Bitmap b = Bitmap.createBitmap(bmpWidth, bmpHeight, Bitmap.Config.ARGB_8888);
    mCanvas.setBitmap(b);
    Utils.drawDragView(v, mCanvas, 0);
    mCanvas.setBitmap(null);

    // The outline is used to visualize where the item will land if dropped
    mDragOutline = createDragOutline(b, DRAG_BITMAP_PADDING, iconSize, iconSize, true);
}

From source file:org.telegram.ui.ChatActivity.java

private void setTypingAnimation(boolean start) {
    TextView subtitle = (TextView) parentActivity.findViewById(R.id.action_bar_subtitle);
    if (subtitle == null) {
        final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_subtitle", "id",
                "android");
        subtitle = (TextView) parentActivity.findViewById(subtitleId);
    }//from w  ww. j  a v a 2 s . co  m
    if (subtitle != null) {
        if (start) {
            try {
                if (currentChat != null) {
                    subtitle.setCompoundDrawablesWithIntrinsicBounds(R.drawable.typing_dots_chat, 0, 0, 0);
                } else {
                    subtitle.setCompoundDrawablesWithIntrinsicBounds(R.drawable.typing_dots, 0, 0, 0);
                }
                subtitle.setCompoundDrawablePadding(Utilities.dp(4));
                AnimationDrawable mAnim = (AnimationDrawable) subtitle.getCompoundDrawables()[0];
                mAnim.setAlpha(200);
                mAnim.start();
            } catch (Exception e) {
                FileLog.e("tmessages", e);
            }
        } else {
            subtitle.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
        }
    }
}

From source file:com.android.launcher3.Workspace.java

public void onExternalDragStartedWithItem(View v) {
    // Compose a drag bitmap with the view scaled to the icon size
    LauncherAppState app = LauncherAppState.getInstance();
    DeviceProfile grid = app.getDynamicGrid().getDeviceProfile();
    int iconSize = grid.iconSizePx;
    int bmpWidth = v.getMeasuredWidth();
    int bmpHeight = v.getMeasuredHeight();

    // If this is a text view, use its drawable instead
    if (v instanceof TextView) {
        TextView tv = (TextView) v;
        Drawable d = tv.getCompoundDrawables()[1];
        Rect bounds = getDrawableBounds(d);
        bmpWidth = bounds.width();/* w w w  .j  a  v  a  2s  .  c  o m*/
        bmpHeight = bounds.height();
    }

    // Compose the bitmap to create the icon from
    Bitmap b = Bitmap.createBitmap(bmpWidth, bmpHeight, Bitmap.Config.ARGB_8888);
    mCanvas.setBitmap(b);
    drawDragView(v, mCanvas, 0);
    mCanvas.setBitmap(null);

    // The outline is used to visualize where the item will land if dropped
    mDragOutline = createDragOutline(b, DRAG_BITMAP_PADDING, iconSize, iconSize, true);
}