Example usage for android.widget TextView setCompoundDrawables

List of usage examples for android.widget TextView setCompoundDrawables

Introduction

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

Prototype

public void setCompoundDrawables(@Nullable Drawable left, @Nullable Drawable top, @Nullable Drawable right,
        @Nullable Drawable bottom) 

Source Link

Document

Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text.

Usage

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));
    }/*from w  w  w .  java2 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;
}