Example usage for android.widget TextView setContentDescription

List of usage examples for android.widget TextView setContentDescription

Introduction

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

Prototype

@RemotableViewMethod
public void setContentDescription(CharSequence contentDescription) 

Source Link

Document

Sets the View 's content description.

Usage

From source file:org.totschnig.myexpenses.activity.AccountEdit.java

@SuppressLint("InlinedApi")
@Override//ww w  . j  a v a2 s  . c  om
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.one_account);
    setupToolbar();

    mLabelText = (EditText) findViewById(R.id.Label);
    mDescriptionText = (EditText) findViewById(R.id.Description);

    Bundle extras = getIntent().getExtras();
    long rowId = extras != null ? extras.getLong(DatabaseConstants.KEY_ROWID) : 0;
    requireAccount();
    if (mAccount == null) {
        Toast.makeText(this, "Error instantiating account " + rowId, Toast.LENGTH_SHORT).show();
        finish();
        return;
    }
    if (rowId != 0) {
        mNewInstance = false;
        setTitle(R.string.menu_edit_account);
        mLabelText.setText(mAccount.label);
        mDescriptionText.setText(mAccount.description);
    } else {
        setTitle(R.string.menu_create_account);
        mAccount = new Account();
        String currency = extras != null ? extras.getString(DatabaseConstants.KEY_CURRENCY) : null;
        if (currency != null)
            try {
                mAccount.setCurrency(currency);
            } catch (IllegalArgumentException e) {
                //if not supported ignore
            }
    }
    configTypeButton();
    mAmountText.setFractionDigits(Money.getFractionDigits(mAccount.currency));

    mCurrencySpinner = new SpinnerHelper(findViewById(R.id.Currency));
    currencyAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item, android.R.id.text1,
            CurrencyEnum.sortedValues());
    currencyAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
    mCurrencySpinner.setAdapter(currencyAdapter);

    mAccountTypeSpinner = new SpinnerHelper(findViewById(R.id.AccountType));
    ArrayAdapter<AccountType> typAdapter = new ArrayAdapter<>(this, android.R.layout.simple_spinner_item,
            android.R.id.text1, AccountType.values());
    typAdapter.setDropDownViewResource(R.layout.support_simple_spinner_dropdown_item);
    mAccountTypeSpinner.setAdapter(typAdapter);

    mColorSpinner = new SpinnerHelper(findViewById(R.id.Color));
    mColors = new ArrayList<>();
    Resources r = getResources();
    mColors.add(r.getColor(R.color.material_red));
    mColors.add(r.getColor(R.color.material_pink));
    mColors.add(r.getColor(R.color.material_purple));
    mColors.add(r.getColor(R.color.material_deep_purple));
    mColors.add(r.getColor(R.color.material_indigo));
    mColors.add(r.getColor(R.color.material_blue));
    mColors.add(r.getColor(R.color.material_light_blue));
    mColors.add(r.getColor(R.color.material_cyan));
    mColors.add(r.getColor(R.color.material_teal));
    mColors.add(r.getColor(R.color.material_green));
    mColors.add(r.getColor(R.color.material_light_green));
    mColors.add(r.getColor(R.color.material_lime));
    mColors.add(r.getColor(R.color.material_yellow));
    mColors.add(r.getColor(R.color.material_amber));
    mColors.add(r.getColor(R.color.material_orange));
    mColors.add(r.getColor(R.color.material_deep_orange));
    mColors.add(r.getColor(R.color.material_brown));
    mColors.add(r.getColor(R.color.material_grey));
    mColors.add(r.getColor(R.color.material_blue_grey));

    if (mColors.indexOf(mAccount.color) == -1)
        mColors.add(mAccount.color);

    mColAdapter = new ArrayAdapter<Integer>(this, android.R.layout.simple_spinner_item, mColors) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            TextView tv = (TextView) super.getView(position, convertView, parent);
            if (mColors.get(position) != 0)
                setColor(tv, mColors.get(position));
            else
                setColor(tv, mAccount.color);
            return tv;
        }

        @Override
        public View getDropDownView(int position, View convertView, ViewGroup parent) {
            TextView tv = (TextView) super.getDropDownView(position, convertView, parent);
            if (mColors.get(position) != 0)
                setColor(tv, mColors.get(position));
            return tv;
        }

        public void setColor(TextView tv, int color) {
            tv.setBackgroundColor(color);
            tv.setText("");
            tv.setContentDescription(getString(R.string.color));
        }
    };
    mColAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    mColorSpinner.setAdapter(mColAdapter);
    linkInputsWithLabels();
    populateFields();
}

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.
 *//*from   www  .  j  a va 2  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.google.android.apps.forscience.whistlepunk.review.RunReviewFragment.java

private void hookUpExperimentDetailsArea(ExperimentRun run, View rootView) {
    setArchivedUi(rootView, run.isArchived());

    final TextView runTitle = (TextView) rootView.findViewById(R.id.run_title_text);
    runTitle.setText(run.getRunTitle(rootView.getContext()));

    final TextView runDetailsText = (TextView) rootView.findViewById(R.id.run_details_text);
    runDetailsText.setText(run.getDisplayTime(runDetailsText.getContext()));

    final TextView durationText = (TextView) rootView.findViewById(R.id.run_review_duration);
    ElapsedTimeFormatter formatter = ElapsedTimeFormatter.getInstance(durationText.getContext());
    durationText.setText(formatter.format(run.elapsedSeconds()));
    durationText.setContentDescription(formatter.formatForAccessibility(run.elapsedSeconds()));
}

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  www .  ja va 2s.  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:org.chromium.chrome.browser.ntp.NewTabPageView.java

/**
 * Sets up the hint text and event handlers for the search box text view.
 *///  w ww  . j  a  va 2s  . co m
private void initializeSearchBoxTextView() {
    final TextView searchBoxTextView = (TextView) mSearchBoxView.findViewById(R.id.search_box_text);
    String hintText = getResources().getString(R.string.search_or_type_url);

    if (!DeviceFormFactor.isTablet(getContext()) || mManager.isFakeOmniboxTextEnabledTablet()) {
        searchBoxTextView.setHint(hintText);
    } else {
        searchBoxTextView.setContentDescription(hintText);
    }
    searchBoxTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            mManager.focusSearchBox(false, null);
        }
    });
    searchBoxTextView.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            if (s.length() == 0)
                return;
            mManager.focusSearchBox(false, s.toString());
            searchBoxTextView.setText("");
        }
    });
}

From source file:org.nypl.simplified.app.MainSettingsAccountActivity.java

@Override
public void onAccountIsLoggedIn(final AccountCredentials creds) {
    LOG.debug("account is logged in: {}", creds);

    final SimplifiedCatalogAppServicesType app = Simplified.getCatalogAppServices();
    final BooksType books = app.getBooks();

    final Resources rr = NullCheck.notNull(this.getResources());
    final TableLayout in_table_with_code = NullCheck.notNull(this.table_with_code);
    final TableLayout in_table_signup = NullCheck.notNull(this.table_signup);
    final TextView in_account_name_text = NullCheck.notNull(this.account_name_text);
    final TextView in_account_subtitle_text = NullCheck.notNull(this.account_subtitle_text);
    final ImageView in_account_icon = NullCheck.notNull(this.account_icon);
    final TextView in_barcode_text = NullCheck.notNull(this.barcode_text);
    final TextView in_pin_text = NullCheck.notNull(this.pin_text);
    final ImageView in_barcode_image = NullCheck.notNull(this.barcode_image);
    final TextView in_barcode_image_toggle = NullCheck.notNull(this.barcode_image_toggle);
    final Button in_login = NullCheck.notNull(this.login);

    UIThread.runOnUIThread(() -> {/*w  ww.ja  v a 2 s. co  m*/
        in_table_with_code.setVisibility(View.VISIBLE);
        in_table_signup.setVisibility(View.GONE);
        in_account_name_text.setText(this.account.getName());
        in_account_subtitle_text.setText(this.account.getSubtitle());

        try {
            in_account_icon.setImageBitmap(this.account.getLogoBitmap());
        } catch (IllegalArgumentException e) {
            in_account_icon.setImageResource(R.drawable.librarylogomagic);
        }

        in_barcode_text.setText(creds.getBarcode().toString());
        in_barcode_text.setContentDescription(creds.getBarcode().toString().replaceAll(".(?=.)", "$0,"));
        in_pin_text.setText(creds.getPin().toString());
        in_pin_text.setContentDescription(creds.getPin().toString().replaceAll(".(?=.)", "$0,"));

        if (account.supportsBarcodeDisplay()) {
            Bitmap barcodeBitmap = generateBarcodeImage(creds.getBarcode().toString());
            if (barcodeBitmap != null) {
                in_barcode_image.setImageBitmap(barcodeBitmap);

                in_barcode_image_toggle.setVisibility(View.VISIBLE);
                in_barcode_image_toggle.setOnClickListener(v -> {
                    if (in_barcode_image_toggle.getText() == getText(R.string.settings_toggle_barcode_show)) {
                        in_barcode_image.setVisibility(View.VISIBLE);
                        in_barcode_image_toggle.setText(R.string.settings_toggle_barcode_hide);
                    } else {
                        in_barcode_image.setVisibility(View.GONE);
                        in_barcode_image_toggle.setText(R.string.settings_toggle_barcode_show);
                    }
                });
            }
        }

        in_login.setText(rr.getString(R.string.settings_log_out));
        in_login.setOnClickListener(v -> {
            final LogoutDialog d = LogoutDialog.newDialog();
            d.setOnConfirmListener(() -> books.accountLogout(creds, this, this, this));
            final FragmentManager fm = this.getFragmentManager();
            d.show(fm, "logout-confirm");
        });
    });
}

From source file:com.android.contacts.list.ContactListItemView.java

private void updateHeaderText(TextView headerTextView, String title) {
    setMarqueeText(headerTextView, title);
    headerTextView.setAllCaps(true);/*from   w w  w .  ja  v a 2 s  .c om*/
    if (ContactsSectionIndexer.BLANK_HEADER_STRING.equals(title)) {
        headerTextView.setContentDescription(getContext().getString(R.string.description_no_name_header));
    } else {
        headerTextView.setContentDescription(title);
    }
    headerTextView.setVisibility(View.VISIBLE);
}

From source file:dk.bearware.gui.MainActivity.java

private void adjustVoxState(boolean voiceActivationEnabled, int level) {
    ImageButton voxSwitch = (ImageButton) findViewById(R.id.voxSwitch);
    TextView mikeLevel = (TextView) findViewById(R.id.mikelevel_text);

    if (voiceActivationEnabled) {
        mikeLevel.setText(level + "%");
        mikeLevel.setContentDescription(getString(R.string.vox_level_description, mikeLevel.getText()));
        voxSwitch.setImageResource(R.drawable.microphone);
        voxSwitch.setContentDescription(getString(R.string.voice_activation_off));
        findViewById(R.id.mikeDec).setContentDescription(getString(R.string.decvoxlevel));
        findViewById(R.id.mikeInc).setContentDescription(getString(R.string.incvoxlevel));
    } else {/*  w  ww.  j  a va2s.  c  om*/
        mikeLevel.setText(Utils.refVolumeToPercent(level) + "%");
        mikeLevel.setContentDescription(getString(R.string.mic_gain_description, mikeLevel.getText()));
        voxSwitch.setImageResource(R.drawable.mike_green);
        voxSwitch.setContentDescription(getString(R.string.voice_activation_on));
        findViewById(R.id.mikeDec).setContentDescription(getString(R.string.decgain));
        findViewById(R.id.mikeInc).setContentDescription(getString(R.string.incgain));
    }
}

From source file:dk.bearware.gui.MainActivity.java

@Override
protected void onStart() {
    super.onStart();

    if (ttsWrapper == null)
        ttsWrapper = TTSWrapper.getInstance(this);
    if (mConnection == null)
        mConnection = new TeamTalkConnection(this);

    if (!mConnection.isBound()) {
        // Bind to LocalService
        Intent intent = new Intent(getApplicationContext(), TeamTalkService.class);
        Log.d(TAG, "Binding TeamTalk service");
        if (!bindService(intent, mConnection, Context.BIND_AUTO_CREATE))
            Log.e(TAG, "Failed to bind to TeamTalk service");
    } else {//from w  w w  .  j a v a2 s .c o m
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

        int mastervol = prefs.getInt(Preferences.PREF_SOUNDSYSTEM_MASTERVOLUME,
                SoundLevel.SOUND_VOLUME_DEFAULT);
        int gain = prefs.getInt(Preferences.PREF_SOUNDSYSTEM_MICROPHONEGAIN, SoundLevel.SOUND_GAIN_DEFAULT);
        int voxlevel = prefs.getInt(Preferences.PREF_SOUNDSYSTEM_VOICEACTIVATION_LEVEL, 5);
        boolean voxState = ttservice.isVoiceActivationEnabled();
        boolean txState = ttservice.isVoiceTransmitting();

        // only set volume and gain if tt-instance hasn't already been configured
        if (ttclient.getSoundOutputVolume() != mastervol)
            ttclient.setSoundOutputVolume(mastervol);
        if (ttclient.getSoundInputGainLevel() != gain)
            ttclient.setSoundInputGainLevel(gain);
        if (ttclient.getVoiceActivationLevel() != voxlevel)
            ttclient.setVoiceActivationLevel(voxlevel);

        adjustMuteButton((ImageButton) findViewById(R.id.speakerBtn));
        adjustVoxState(voxState, voxState ? voxlevel : gain);
        adjustTxState(txState);

        TextView volLevel = (TextView) findViewById(R.id.vollevel_text);
        volLevel.setText(Utils.refVolumeToPercent(mastervol) + "%");
        volLevel.setContentDescription(getString(R.string.speaker_volume_description, volLevel.getText()));
    }
}

From source file:dk.bearware.gui.MainActivity.java

@Override
public void onServiceConnected(TeamTalkService service) {
    ttservice = service;/*from w w  w .  j ava 2 s.  c  o  m*/
    ttclient = ttservice.getTTInstance();

    //ttclient.DBG_SetSoundInputTone(StreamType.STREAMTYPE_VOICE, 440);

    int mychannel = ttclient.getMyChannelID();
    if (mychannel > 0) {
        setCurrentChannel(ttservice.getChannels().get(mychannel));
    }

    this.mychannel = ttservice.getChannels().get(mychannel);

    mSectionsPagerAdapter.onPageSelected(mViewPager.getCurrentItem());

    channelsAdapter.notifyDataSetChanged();

    textmsgAdapter.setTextMessages(ttservice.getChatLogTextMsgs());
    textmsgAdapter.setMyUserID(ttclient.getMyUserID());
    textmsgAdapter.notifyDataSetChanged();

    mediaAdapter.setTeamTalkService(service);
    mediaAdapter.notifyDataSetChanged();

    filesAdapter.setTeamTalkService(service);
    filesAdapter.update(mychannel);

    int flags = ttclient.getFlags();
    if (((flags & ClientFlag.CLIENT_SNDOUTPUT_READY) == 0) && !ttclient.initSoundOutputDevice(0))
        Toast.makeText(this, R.string.err_init_sound_output, Toast.LENGTH_LONG).show();

    if (!restarting) {
        ttservice.setMute(false);
        ttservice.enableVoiceTransmission(false);
        ttservice.enableVoiceActivation(false);
        if (Permissions.setupPermission(getBaseContext(), this,
                Permissions.MY_PERMISSIONS_REQUEST_READ_PHONE_STATE))
            ttservice.enablePhoneCallReaction();
    }

    ttservice.registerConnectionListener(this);
    ttservice.registerCommandListener(this);
    ttservice.registerUserListener(this);
    ttservice.registerClientListener(this);
    ttservice.setOnVoiceTransmissionToggleListener(this);
    audioManager.registerMediaButtonEventReceiver(mediaButtonEventReceiver);

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getBaseContext());

    if (Permissions.setupPermission(getBaseContext(), this, Permissions.MY_PERMISSIONS_REQUEST_WAKE_LOCK))
        wakeLock.acquire();

    int mastervol = prefs.getInt(Preferences.PREF_SOUNDSYSTEM_MASTERVOLUME, SoundLevel.SOUND_VOLUME_DEFAULT);
    int gain = prefs.getInt(Preferences.PREF_SOUNDSYSTEM_MICROPHONEGAIN, SoundLevel.SOUND_GAIN_DEFAULT);
    int voxlevel = prefs.getInt(Preferences.PREF_SOUNDSYSTEM_VOICEACTIVATION_LEVEL, 5);
    boolean voxState = ttservice.isVoiceActivationEnabled();
    boolean txState = ttservice.isVoiceTransmitting();

    // only set volume and gain if tt-instance hasn't already been configured
    if (ttclient.getSoundOutputVolume() != mastervol)
        ttclient.setSoundOutputVolume(mastervol);
    if (ttclient.getSoundInputGainLevel() != gain)
        ttclient.setSoundInputGainLevel(gain);
    if (ttclient.getVoiceActivationLevel() != voxlevel)
        ttclient.setVoiceActivationLevel(voxlevel);

    adjustMuteButton((ImageButton) findViewById(R.id.speakerBtn));
    adjustVoxState(voxState, voxState ? voxlevel : gain);
    adjustTxState(txState);

    TextView volLevel = (TextView) findViewById(R.id.vollevel_text);
    volLevel.setText(Utils.refVolumeToPercent(mastervol) + "%");
    volLevel.setContentDescription(getString(R.string.speaker_volume_description, volLevel.getText()));
}