Example usage for android.widget TextView setCompoundDrawablePadding

List of usage examples for android.widget TextView setCompoundDrawablePadding

Introduction

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

Prototype

@android.view.RemotableViewMethod
public void setCompoundDrawablePadding(int pad) 

Source Link

Document

Sets the size of the padding between the compound drawables and the text.

Usage

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);
    }//  www.ja  va 2s . c o  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:edu.cmu.cylab.starslinger.view.HomeActivity.java

protected AlertDialog.Builder xshowChangeSenderOptions(final Activity act, Bundle args) {
    final ArrayList<UseContactItem> items = new ArrayList<UseContactItem>();
    boolean isContactInUse = args.getBoolean(extra.CREATED);
    final String pName = args.getString(extra.NAME);
    byte[] pPhoto = args.getByteArray(extra.PHOTO);
    String pLookupKey = args.getString(extra.CONTACT_LOOKUP_KEY);
    if (!TextUtils.isEmpty(pName)) {
        items.add(new UseContactItem(String.format(act.getString(R.string.menu_UseProfilePerson), pName),
                pPhoto, pLookupKey, UCType.PROFILE));
    }/*www  .j av  a2  s.  c  om*/
    int i = 0;
    String cName = args.getString(extra.NAME + i);
    byte[] cPhoto = args.getByteArray(extra.PHOTO + i);
    String cLookupKey = args.getString(extra.CONTACT_LOOKUP_KEY + i);
    while (!TextUtils.isEmpty(cName)) {
        items.add(new UseContactItem(String.format(act.getString(R.string.menu_UseContactPerson), cName),
                cPhoto, cLookupKey, UCType.CONTACT));
        i++;
        cName = args.getString(extra.NAME + i);
        cPhoto = args.getByteArray(extra.PHOTO + i);
        cLookupKey = args.getString(extra.CONTACT_LOOKUP_KEY + i);
    }
    items.add(new UseContactItem(act.getString(R.string.menu_UseNoContact), UCType.NONE));
    items.add(new UseContactItem(act.getString(R.string.menu_UseAnother), UCType.ANOTHER));
    items.add(new UseContactItem(act.getString(R.string.menu_CreateNew), UCType.NEW));
    items.add(new UseContactItem(act.getString(R.string.menu_EditName), UCType.EDIT_NAME));
    if (isContactInUse) {
        items.add(new UseContactItem(act.getString(R.string.menu_EditContact), UCType.EDIT_CONTACT));
    }

    AlertDialog.Builder ad = new AlertDialog.Builder(act);
    ad.setTitle(R.string.title_MyIdentity);
    ad.setOnCancelListener(new DialogInterface.OnCancelListener() {
        @Override
        public void onCancel(DialogInterface dialog) {
            dialog.dismiss();
        }
    });
    ListAdapter adapter = new ArrayAdapter<UseContactItem>(act, android.R.layout.select_dialog_item,
            android.R.id.text1, items) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            View v = super.getView(position, convertView, parent);
            TextView tv = (TextView) v.findViewById(android.R.id.text1);
            UseContactItem item = items.get(position);

            if (item.contact) {
                Drawable d;
                if (item.icon != null) {
                    Bitmap bm = BitmapFactory.decodeByteArray(item.icon, 0, item.icon.length, null);
                    d = new BitmapDrawable(getResources(), bm);
                } else {
                    d = getResources().getDrawable(R.drawable.ic_silhouette);
                }
                int avatar_size_list = (int) getResources().getDimension(R.dimen.avatar_size_list);
                d.setBounds(0, 0, avatar_size_list, avatar_size_list);
                tv.setCompoundDrawables(null, null, d, null);
                tv.setCompoundDrawablePadding((int) getResources().getDimension(R.dimen.size_5dp));
            } else {
                tv.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
            }

            return v;
        }
    };
    ad.setAdapter(adapter, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int item) {
            dialog.dismiss();
            switch (items.get(item).type) {
            case PROFILE:
                // user wants to use found profile as a personal contact
                // save these for lookup and display purposes
                SafeSlingerPrefs.setContactName(pName);
                SafeSlingerPrefs.setContactLookupKey(items.get(item).contactLookupKey);
                refreshView();
                break;
            case CONTACT:
                // user wants to use found contact as a personal contact
                SafeSlingerPrefs.setContactName(getContactName(items.get(item).contactLookupKey));
                SafeSlingerPrefs.setContactLookupKey(items.get(item).contactLookupKey);
                refreshView();
                break;
            case ANOTHER:
                // user wants to choose new contact for themselves
                showPickContact(RESULT_PICK_CONTACT_SENDER);
                break;
            case NONE:
                // user wants to remove link to address book
                SafeSlingerPrefs.setContactLookupKey(null);
                refreshView();
                break;
            case NEW:
                // user wants to create new contact
                showAddContact(SafeSlingerPrefs.getContactName());
                break;
            case EDIT_CONTACT:
                // user wants to edit contact
                showEditContact(RESULT_PICK_CONTACT_SENDER);
                break;
            case EDIT_NAME:
                // user wants to edit name
                showSettings();
                refreshView();
                break;
            }
        }
    });

    return ad;
}