Example usage for android.widget TextView setCompoundDrawablesWithIntrinsicBounds

List of usage examples for android.widget TextView setCompoundDrawablesWithIntrinsicBounds

Introduction

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

Prototype

@android.view.RemotableViewMethod
public void setCompoundDrawablesWithIntrinsicBounds(@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:me.piebridge.prevent.ui.UserGuideActivity.java

private boolean setView(int id, String packageName) {
    TextView donate = (TextView) findViewById(id);
    PackageManager pm = getPackageManager();
    try {/* w  ww  . j ava2s.c  o  m*/
        ApplicationInfo info = pm.getApplicationInfo(packageName, 0);
        if (!info.enabled) {
            return false;
        }
        CharSequence label = getLabel(pm, info);
        donate.setContentDescription(label);
        donate.setCompoundDrawablesWithIntrinsicBounds(null, cropDrawable(pm.getApplicationIcon(info)), null,
                null);
        donate.setText(label);
        donate.setClickable(true);
        donate.setOnClickListener(this);
        donate.setVisibility(View.VISIBLE);
        return true;
    } catch (PackageManager.NameNotFoundException e) {
        UILog.d("cannot find package " + packageName, e);
        return false;
    }
}

From source file:cs.umass.edu.prepare.view.activities.CalendarActivity.java

/**
 * Populates the details view with adherence data for a particular date.
 * @param dateKey corresponds to the selected date. Note that the date key must have zeroed
 *                out all fields excluding month, year and date.
 * @param insertPoint the parent to which the adherence views are to be added.
 *//*from   w  w w .j  a v  a 2s . com*/
private void insertDetailsForDate(final Calendar dateKey, ViewGroup insertPoint) {
    final Map<Medication, Adherence[]> adherenceMap = adherenceData.get(dateKey);
    for (final Medication medication : medications) {
        View details = View.inflate(this, R.layout.view_adherence_details_full, null);
        LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);

        View[] adherenceViews = new View[2];
        int[] viewIDs = new int[] { R.id.adherence_details1, R.id.adherence_details2 };
        int[] timeTakenIDs = new int[] { R.id.txtTimeTaken1, R.id.txtTimeTaken2 };
        int[] medicationImgIDs = new int[] { R.id.imgMedication1, R.id.imgMedication2 };
        final Adherence[] adherence = adherenceMap.get(medication);
        int dosage = dosageMapping.get(medication);
        Calendar[] schedule = dailySchedule.get(medication);

        for (int i = 0; i < viewIDs.length; i++) {
            final int index = i;
            adherenceViews[index] = details.findViewById(viewIDs[index]);
            // TODO : Swiping on details doesn't work as expected (only works for adherence view):
            //            motionEventListener.setOnSwipeListener(adherenceViews[index], onDetailsSwiped);
            adherenceViews[index].setOnLongClickListener(view -> {
                editAdherence(medication, dateKey, index);
                return false;
            });
            adherenceViews[index].setOnClickListener(view -> {
                if (adherence[index].getAdherenceType() == Adherence.AdherenceType.TAKEN_CLARIFY_TIME) {
                    setTimeTaken(medication, dateKey, index);
                }
            });
            adherenceViews[index]
                    .setBackground(Utils.getDrawableForAdherence(this, adherence[index].getAdherenceType()));
            TextView timeTaken = (TextView) details.findViewById(timeTakenIDs[index]);
            TextView imgMedication = (TextView) details.findViewById(medicationImgIDs[index]);
            BitmapDrawable medicationDrawable = new BitmapDrawable(getResources(), medication.getImage());
            imgMedication.setCompoundDrawablesWithIntrinsicBounds(null, medicationDrawable, null, null);
            imgMedication.setText(String.format(Locale.getDefault(), "%d mg", dosage));
            adherenceViews[index].setVisibility(View.VISIBLE);
            switch (adherence[index].getAdherenceType()) {
            case NONE:
                adherenceViews[index].setVisibility(View.INVISIBLE);
                break;
            case MISSED:
                timeTaken.setText(R.string.adherence_text_missed);
                break;
            case TAKEN_CLARIFY_TIME:
                timeTaken.setText(R.string.adherence_text_unknown);
                break;
            case FUTURE:
                timeTaken.setText(timeFormat.format(schedule[index].getTime()));
                break;
            default: // taken on-time or taken late/early
                Calendar time = adherence[index].getTimeTaken();
                if (time != null)
                    timeTaken.setText(timeFormat.format(time.getTime()));
                break;
            }
        }
        // set margins and add to parent
        layoutParams.setMargins(0, 15, 0, 15);
        insertPoint.addView(details, layoutParams);
    }
}

From source file:com.soomla.example.ExampleSocialActivity.java

/**
 * {@inheritDoc}/*from   w  ww.  j a v  a  2  s .  c o  m*/
 */
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_social);

    //        SoomlaConfig.logDebug = true;

    mProgressDialog = new ProgressDialog(this);

    final Bundle extras = getIntent().getExtras();
    if (extras != null) {
        final String provider = extras.getString("provider");
        mProvider = IProvider.Provider.getEnum(provider);
        mItemId = extras.getString("id");
        mItemAmount = extras.getInt("amount", 1);
        mItemName = extras.getString("name");
        mItemResId = extras.getInt("iconResId", R.drawable.ic_launcher);

        // set the social provider logo if possible
        final int resourceId = getResources().getIdentifier(provider, "drawable", getPackageName());
        Drawable drawableLogo = getResources().getDrawable(resourceId);
        if (drawableLogo != null) {
            final TextView topBarTextView = (TextView) findViewById(R.id.textview);
            if (topBarTextView != null) {
                topBarTextView.setCompoundDrawablesWithIntrinsicBounds(drawableLogo, null, null, null);
            }
        }
    }

    final TextView vItemDisplay = (TextView) findViewById(R.id.vItem);
    if (vItemDisplay != null) {
        vItemDisplay.setText(mItemName);
        vItemDisplay.setCompoundDrawablesWithIntrinsicBounds(null, getResources().getDrawable(mItemResId), null,
                null);
    }

    mProfileBar = (ViewGroup) findViewById(R.id.profile_bar);
    mProfileAvatar = (ImageView) findViewById(R.id.prof_avatar);
    mProfileName = (TextView) findViewById(R.id.prof_name);

    mPnlStatusUpdate = (ViewGroup) findViewById(R.id.pnlStatusUpdate);
    mEdtStatusText = (EditText) findViewById(R.id.edtStatusText);

    mEdtStatusText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_SEND) {
                doUpdateStatus();
                handled = true;
            }

            return handled;
        }
    });

    mBtnUpdateStatus = (Button) findViewById(R.id.btnStatusUpdate);
    mBtnUpdateStatus.setEnabled(false);
    mBtnUpdateStatus.setOnClickListener(new View.OnClickListener() {

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

    mPnlUploadImage = (ViewGroup) findViewById(R.id.pnlUploadImage);
    mImagePreview = (ImageView) findViewById(R.id.imagePreview);
    mEdtImageText = (EditText) findViewById(R.id.edtImageText);

    mEdtImageText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_SEND) {
                doUpdateStatus();
                handled = true;
            }

            return handled;
        }
    });

    mBtnChooseImage = (ImageView) findViewById(R.id.btnChooseImage);
    mBtnChooseImage.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            chooseImageFile();
        }
    });

    mBtnUploadImage = (Button) findViewById(R.id.btnUploadImage);
    mBtnUploadImage.setEnabled(false);
    mBtnUploadImage.setOnClickListener(new View.OnClickListener() {

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

    mPnlStoryUpdate = (ViewGroup) findViewById(R.id.pnlStoryUpdate);
    mEdtStoryText = (EditText) findViewById(R.id.edtStoryText);

    mEdtStoryText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            boolean handled = false;
            if (actionId == EditorInfo.IME_ACTION_SEND) {
                doUpdateStory();
                handled = true;
            }

            return handled;
        }
    });

    mBtnUpdateStory = (Button) findViewById(R.id.btnStoryUpdate);
    mBtnUpdateStory.setEnabled(false);
    mBtnUpdateStory.setOnClickListener(new View.OnClickListener() {

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

    mBtnShare = (Button) findViewById(R.id.btnShare);

    if (!SoomlaProfile.getInstance().isLoggedIn(this, mProvider)) {
        SoomlaProfile.getInstance().login(this, mProvider, gameLoginReward);

        mProgressDialog.setMessage("logging in...");
        mProgressDialog.show();
    } else {
        applyLoggedInUser(mProvider);
    }
}

From source file:com.mk4droid.IMC_Activities.FActivity_TabHost.java

private LinearLayout ActivateColorize(LinearLayout ll, String text, Drawable dr) {

    // text//  w w w .  j  a va 2 s  .  c om
    TextView v = (TextView) ll.findViewWithTag("tv");
    v.setText(text);
    v.setTextSize(10);
    v.setTextColor(Color.BLACK); //v.setTextColor(Color.WHITE);
    v.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);

    //dr.setColorFilter(0xFF888888, android.graphics.PorterDuff.Mode.MULTIPLY);
    dr.setColorFilter(resources.getColor(R.color.orange), android.graphics.PorterDuff.Mode.SRC_ATOP);

    v.setCompoundDrawablesWithIntrinsicBounds(null, dr, null, null);
    v.setPadding(0, 5, 0, 2);

    v.setBackgroundDrawable(resources.getDrawable(R.drawable.gradient_tabs_focused));

    // hbar
    View hbar = ll.findViewWithTag("hbar");
    //hbar.setBackgroundColor(resources.getColor(R.color.orange));
    hbar.setBackgroundDrawable(resources.getDrawable(R.drawable.gradient_orange));

    return ll;
}

From source file:de.kodejak.hashr.fragmentHashFromFile.java

public void OnButtonCompareClick() {
    TextView edOutput = (TextView) getView().findViewById(R.id.edOutput);
    String strOutput = edOutput.getText().toString();
    EditText edCompare = (EditText) getView().findViewById(R.id.edCompare);
    String strCompare = edCompare.getText().toString();
    TextView tvMatch = (TextView) getView().findViewById(R.id.tvCompare);

    if (strOutput.length() < 1 || strCompare.length() < 1) {
        return;//from w w w  . j a v  a2 s.com
    }

    if (strOutput.equals(strCompare)) {
        tvMatch.setText("Match !");
        if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            tvMatch.setBackgroundDrawable(getResources().getDrawable(R.drawable.match_ok_bg));
        } else {
            tvMatch.setBackground(getResources().getDrawable(R.drawable.match_ok_bg));
        }
        tvMatch.setTextColor(Color.WHITE);
        tvMatch.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_check, 0, 0, 0);
    } else {
        tvMatch.setText("No match !");
        if (sdk < android.os.Build.VERSION_CODES.JELLY_BEAN) {
            tvMatch.setBackgroundDrawable(getResources().getDrawable(R.drawable.match_notok_bg));
        } else {
            tvMatch.setBackground(getResources().getDrawable(R.drawable.match_notok_bg));
        }
        tvMatch.setTextColor(Color.WHITE);
        tvMatch.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_cancel, 0, 0, 0);
    }

    tvMatch.setVisibility(View.VISIBLE);
}

From source file:com.android.inputmethod.latin.suggestions.SuggestionStripLayoutHelper.java

/**
 * Format appropriately the suggested word in {@link #mWordViews} specified by
 * <code>positionInStrip</code>. When the suggested word doesn't exist, the corresponding
 * {@link TextView} will be disabled and never respond to user interaction. The suggested word
 * may be shrunk or ellipsized to fit in the specified width.
 *
 * The <code>positionInStrip</code> argument is the index in the suggestion strip. The indices
 * increase towards the right for LTR scripts and the left for RTL scripts, starting with 0.
 * The position of the most important suggestion is in {@link #mCenterPositionInStrip}. This
 * usually doesn't match the index in <code>suggedtedWords</code> -- see
 * {@link #getPositionInSuggestionStrip(int,SuggestedWords)}.
 *
 * @param positionInStrip the position in the suggestion strip.
 * @param width the maximum width for layout in pixels.
 * @return the {@link TextView} containing the suggested word appropriately formatted.
 *//*  w  w w  . java2 s . c o m*/
private TextView layoutWord(final int positionInStrip, final int width) {
    final TextView wordView = mWordViews.get(positionInStrip);
    final CharSequence word = wordView.getText();
    if (positionInStrip == mCenterPositionInStrip && mMoreSuggestionsAvailable) {
        // TODO: This "more suggestions hint" should have a nicely designed icon.
        wordView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, mMoreSuggestionsHint);
        // HACK: Align with other TextViews that have no compound drawables.
        wordView.setCompoundDrawablePadding(-mMoreSuggestionsHint.getIntrinsicHeight());
    } else {
        wordView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
    }
    // {@link StyleSpan} in a content description may cause an issue of TTS/TalkBack.
    // Use a simple {@link String} to avoid the issue.
    wordView.setContentDescription(TextUtils.isEmpty(word) ? null : word.toString());
    final CharSequence text = getEllipsizedText(word, width, wordView.getPaint());
    final float scaleX = getTextScaleX(word, width, wordView.getPaint());
    wordView.setText(text); // TextView.setText() resets text scale x to 1.0.
    wordView.setTextScaleX(Math.max(scaleX, MIN_TEXT_XSCALE));
    // A <code>wordView</code> should be disabled when <code>word</code> is empty in order to
    // make it unclickable.
    // With accessibility touch exploration on, <code>wordView</code> should be enabled even
    // when it is empty to avoid announcing as "disabled".
    wordView.setEnabled(
            !TextUtils.isEmpty(word) || AccessibilityUtils.getInstance().isTouchExplorationEnabled());
    return wordView;
}

From source file:com.nttec.everychan.ui.NewTabFragment.java

private void openChansList() {
    final ArrayAdapter<ChanModule> chansAdapter = new ArrayAdapter<ChanModule>(activity, 0) {
        private LayoutInflater inflater = LayoutInflater.from(activity);
        private int drawablePadding = (int) (resources.getDisplayMetrics().density * 5 + 0.5f);

        {/* w  ww. ja  v a2  s  .  c  o m*/
            for (ChanModule chan : MainApplication.getInstance().chanModulesList)
                add(chan);
        }

        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            ChanModule chan = getItem(position);
            TextView view = (TextView) (convertView == null
                    ? inflater.inflate(android.R.layout.simple_list_item_1, parent, false)
                    : convertView);
            view.setText(chan.getDisplayingName());
            view.setCompoundDrawablesWithIntrinsicBounds(chan.getChanFavicon(), null, null, null);
            view.setCompoundDrawablePadding(drawablePadding);
            return view;
        }
    };

    DialogInterface.OnClickListener onChanSelected = new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            ChanModule chan = chansAdapter.getItem(which);
            UrlPageModel model = new UrlPageModel();
            model.chanName = chan.getChanName();
            model.type = UrlPageModel.TYPE_INDEXPAGE;
            openNewTab(chan.buildUrl(model));
        }
    };

    final AlertDialog chansListDialog = new AlertDialog.Builder(activity)
            .setTitle(R.string.newtab_quickaccess_all_boards).setAdapter(chansAdapter, onChanSelected)
            .setNegativeButton(android.R.string.cancel, null).create();

    chansListDialog.getListView().setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
        @Override
        public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
            MenuItem.OnMenuItemClickListener contextMenuHandler = new MenuItem.OnMenuItemClickListener() {
                @SuppressLint("InlinedApi")
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    final ChanModule chan = chansAdapter
                            .getItem(((AdapterView.AdapterContextMenuInfo) item.getMenuInfo()).position);
                    switch (item.getItemId()) {
                    case R.id.context_menu_favorites_from_fragment:
                        if (MainApplication.getInstance().database.isFavorite(chan.getChanName(), null, null,
                                null)) {
                            MainApplication.getInstance().database.removeFavorite(chan.getChanName(), null,
                                    null, null);
                        } else {
                            try {
                                UrlPageModel indexPage = new UrlPageModel();
                                indexPage.chanName = chan.getChanName();
                                indexPage.type = UrlPageModel.TYPE_INDEXPAGE;
                                MainApplication.getInstance().database.addFavorite(chan.getChanName(), null,
                                        null, null, chan.getChanName(), chan.buildUrl(indexPage));
                            } catch (Exception e) {
                                Logger.e(TAG, e);
                            }
                        }
                        return true;
                    case R.id.context_menu_quickaccess_add:
                        QuickAccess.Entry newEntry = new QuickAccess.Entry();
                        newEntry.chan = chan;
                        list.add(0, newEntry);
                        adapter.notifyDataSetChanged();
                        saveQuickAccessToPreferences();
                        chansListDialog.dismiss();
                        return true;
                    case R.id.context_menu_quickaccess_custom_board:
                        LinearLayout dialogLayout = new LinearLayout(activity);
                        dialogLayout.setOrientation(LinearLayout.VERTICAL);
                        final EditText boardField = new EditText(activity);
                        final EditText descriptionField = new EditText(activity);
                        boardField.setHint(R.string.newtab_quickaccess_addcustom_boardcode);
                        descriptionField.setHint(R.string.newtab_quickaccess_addcustom_boarddesc);
                        LinearLayout.LayoutParams fieldsParams = new LinearLayout.LayoutParams(
                                LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
                        dialogLayout.addView(boardField, fieldsParams);
                        dialogLayout.addView(descriptionField, fieldsParams);
                        DialogInterface.OnClickListener onOkClicked = new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                String boardName = boardField.getText().toString();
                                for (QuickAccess.Entry entry : list)
                                    if (entry.boardName != null && entry.chan != null)
                                        if (entry.chan.getChanName().equals(chan.getChanName())
                                                && entry.boardName.equals(boardName)) {
                                            Toast.makeText(activity,
                                                    R.string.newtab_quickaccess_addcustom_already_exists,
                                                    Toast.LENGTH_LONG).show();
                                            return;
                                        }

                                try {
                                    if (boardName.trim().length() == 0)
                                        throw new Exception();
                                    UrlPageModel boardPageModel = new UrlPageModel();
                                    boardPageModel.type = UrlPageModel.TYPE_BOARDPAGE;
                                    boardPageModel.chanName = chan.getChanName();
                                    boardPageModel.boardName = boardName;
                                    boardPageModel.boardPage = UrlPageModel.DEFAULT_FIRST_PAGE;
                                    chan.buildUrl(boardPageModel); //,  ??  ?    
                                } catch (Exception e) {
                                    Toast.makeText(activity,
                                            R.string.newtab_quickaccess_addcustom_incorrect_code,
                                            Toast.LENGTH_LONG).show();
                                    return;
                                }

                                QuickAccess.Entry newEntry = new QuickAccess.Entry();
                                newEntry.chan = chan;
                                newEntry.boardName = boardName;
                                newEntry.boardDescription = descriptionField.getText().toString();
                                list.add(0, newEntry);
                                adapter.notifyDataSetChanged();
                                saveQuickAccessToPreferences();
                                chansListDialog.dismiss();
                            }
                        };
                        new AlertDialog.Builder(activity)
                                .setTitle(resources.getString(R.string.newtab_quickaccess_addcustom_title,
                                        chan.getChanName()))
                                .setView(dialogLayout).setPositiveButton(android.R.string.ok, onOkClicked)
                                .setNegativeButton(android.R.string.cancel, null).show();
                        return true;
                    }
                    return false;
                }
            };
            String thisChanName = chansAdapter.getItem(((AdapterView.AdapterContextMenuInfo) menuInfo).position)
                    .getChanName();
            boolean canAddToQuickAccess = true;
            for (QuickAccess.Entry entry : list)
                if (entry.boardName == null && entry.chan != null
                        && entry.chan.getChanName().equals(thisChanName)) {
                    canAddToQuickAccess = false;
                    break;
                }
            menu.add(Menu.NONE, R.id.context_menu_favorites_from_fragment, 1,
                    MainApplication.getInstance().database.isFavorite(thisChanName, null, null, null)
                            ? R.string.context_menu_remove_favorites
                            : R.string.context_menu_add_favorites)
                    .setOnMenuItemClickListener(contextMenuHandler);
            menu.add(Menu.NONE, R.id.context_menu_quickaccess_add, 2, R.string.context_menu_quickaccess_add)
                    .setOnMenuItemClickListener(contextMenuHandler).setVisible(canAddToQuickAccess);
            menu.add(Menu.NONE, R.id.context_menu_quickaccess_custom_board, 3,
                    R.string.context_menu_quickaccess_custom_board)
                    .setOnMenuItemClickListener(contextMenuHandler);
            if (isSingleboardChan(
                    chansAdapter.getItem(((AdapterView.AdapterContextMenuInfo) menuInfo).position)))
                menu.findItem(R.id.context_menu_quickaccess_custom_board).setVisible(false);
        }
    });
    chansListDialog.show();
}

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

@Override
public void applySelfActionBar() {
    if (parentActivity == null) {
        return;// w w  w.jav a2s.  com
    }
    ActionBar actionBar = parentActivity.getSupportActionBar();
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setDisplayShowHomeEnabled(false);
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayUseLogoEnabled(false);
    actionBar.setDisplayShowCustomEnabled(false);
    actionBar.setCustomView(null);
    actionBar.setTitle(getStringEntry(R.string.NewGroup));

    TextView title = (TextView) parentActivity.findViewById(R.id.action_bar_title);
    if (title == null) {
        final int subtitleId = parentActivity.getResources().getIdentifier("action_bar_title", "id", "android");
        title = (TextView) parentActivity.findViewById(subtitleId);
    }
    if (title != null) {
        title.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
        title.setCompoundDrawablePadding(0);
    }
}

From source file:com.mobiletin.inputmethod.indic.suggestions.SuggestionStripLayoutHelper.java

/**
 * Format appropriately the suggested word in {@link #mWordViews} specified by
 * <code>positionInStrip</code>. When the suggested word doesn't exist, the corresponding
 * {@link TextView} will be disabled and never respond to user interaction. The suggested word
 * may be shrunk or ellipsized to fit in the specified width.
 *
 * The <code>positionInStrip</code> argument is the index in the suggestion strip. The indices
 * increase towards the right for LTR scripts and the left for RTL scripts, starting with 0.
 * The position of the most important suggestion is in {@link #mCenterPositionInStrip}. This
 * usually doesn't match the index in <code>suggedtedWords</code> -- see
 * {@link #getPositionInSuggestionStrip(int,SuggestedWords)}.
 *
 * @param positionInStrip the position in the suggestion strip.
 * @param width the maximum width for layout in pixels.
 * @return the {@link TextView} containing the suggested word appropriately formatted.
 *//*from w w  w .jav  a  2 s .c o m*/
private TextView layoutWord(final int positionInStrip, final int width) {

    //    final TextView wordView = mWordViews.get(positionInStrip);

    final TextView wordView = mWordViews.get(positionInStrip);

    final CharSequence word = wordView.getText();
    if (positionInStrip == mCenterPositionInStrip && mMoreSuggestionsAvailable) {
        // TODO: This "more suggestions hint" should have a nicely designed icon.
        wordView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, mMoreSuggestionsHint);
        // HACK: Align with other TextViews that have no compound drawables.
        wordView.setCompoundDrawablePadding(-mMoreSuggestionsHint.getIntrinsicHeight());
    } else {
        wordView.setCompoundDrawablesWithIntrinsicBounds(null, null, null, null);
    }
    // {@link StyleSpan} in a content description may cause an issue of TTS/TalkBack.
    // Use a simple {@link String} to avoid the issue.
    wordView.setContentDescription(TextUtils.isEmpty(word) ? null : word.toString());

    final CharSequence text = getEllipsizedText(word, width, wordView.getPaint());
    final float scaleX = getTextScaleX(word, width, wordView.getPaint());
    wordView.setText(text); // TextView.setText() resets text scale x to 1.0.
    wordView.setTextScaleX(Math.max(scaleX, MIN_TEXT_XSCALE));
    // A <code>wordView</code> should be disabled when <code>word</code> is empty in order to
    // make it unclickable.
    // With accessibility touch exploration on, <code>wordView</code> should be enabled even
    // when it is empty to avoid announcing as "disabled".
    wordView.setEnabled(
            !TextUtils.isEmpty(word) || AccessibilityUtils.getInstance().isTouchExplorationEnabled());
    return wordView;
}

From source file:com.cw.litenote.tabs.TabsHost.java

@Override
public void onTabSelected(TabLayout.Tab tab) {
    System.out.println("TabsHost / _onTabSelected: " + tab.getPosition());

    setFocus_tabPos(tab.getPosition());/*w w w  . ja v a  2s  . com*/

    // keep focus view page table Id
    int pageTableId = mTabsPagerAdapter.dbFolder.getPageTableId(getFocus_tabPos(), true);
    Pref.setPref_focusView_page_tableId(MainAct.mAct, pageTableId);

    // current page table Id
    mFocusPageTableId = pageTableId;

    // refresh list view of selected page
    Page_recycler page = mTabsPagerAdapter.fragmentList.get(getFocus_tabPos());
    if ((tab.getPosition() == audioPlayTabPos) && (page != null) && (page.itemAdapter != null)) {
        RecyclerView listView = page.recyclerView;
        if ((audioPlayer_page != null) && !isDoingMarking && (listView != null)
                && (Audio_manager.getPlayerState() != Audio_manager.PLAYER_AT_STOP)) {
            audioPlayer_page.scrollHighlightAudioItemToVisible(listView);
        }
    }

    // add for update page item view
    if ((page != null) && (page.itemAdapter != null)) {
        page.itemAdapter.notifyDataSetChanged();
        System.out.println("TabsHost / _onTabSelected / notifyDataSetChanged ");
    } else
        System.out.println("TabsHost / _onTabSelected / not notifyDataSetChanged ");

    // set tab audio icon when audio playing
    if ((MainAct.mPlaying_folderPos == FolderUi.getFocus_folderPos())
            && (Audio_manager.getPlayerState() != Audio_manager.PLAYER_AT_STOP)
            && (tab.getPosition() == audioPlayTabPos)) {
        if (tab.getCustomView() == null) {
            LinearLayout tabLinearLayout = (LinearLayout) MainAct.mAct.getLayoutInflater()
                    .inflate(R.layout.tab_custom, null);
            TextView title = (TextView) tabLinearLayout.findViewById(R.id.tabTitle);
            title.setText(mTabsPagerAdapter.dbFolder.getPageTitle(tab.getPosition(), true));
            title.setTextColor(MainAct.mAct.getResources().getColor(R.color.colorWhite));
            title.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_audio, 0, 0, 0);
            tab.setCustomView(title);
        }
    } else
        tab.setCustomView(null);

    // call onCreateOptionsMenu
    MainAct.mAct.invalidateOptionsMenu();

    // set text color
    mTabLayout.setTabTextColors(ContextCompat.getColor(MainAct.mAct, R.color.colorGray), //normal
            ContextCompat.getColor(MainAct.mAct, R.color.colorWhite) //selected
    );

    // set long click listener
    setLongClickListener();

    TabsHost.showFooter(MainAct.mAct);

    isDoingMarking = false;
}