Java Code Examples for android.widget.TextView#setContentDescription()

The following examples show how to use android.widget.TextView#setContentDescription() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * Control from / to prefix for not valid waypoint entries.
 */
void updateViewHolderAccordingToPosition(final int position, final WaypointsListViewHolder holder) {
    final WaypointEntry waypointEntry = mWaypointEntryList.get(position);
    final TextView entryView = holder.getEntryView();
    String formatString = null;
    if (position == 0) {
        formatString = entryView.getContext().getString(R.string.msdkui_rp_from);
    } else if (position == mWaypointEntryList.size() - 1) {
        formatString = entryView.getContext().getString(R.string.msdkui_rp_to);
    }

    if (waypointEntry == null || waypointEntry.isValid()) {
        if (formatString == null) {
            entryView.setContentDescription(entryView.getText());
        } else {
            entryView.setContentDescription(String.format(formatString, entryView.getText()));
        }
        return;
    }
    final String waypointEntryName = waypointEntry.getLabel(entryView.getContext(), "");
    if (formatString == null) {
        entryView.setText(waypointEntryName);
    } else {
        entryView.setText(String.format(formatString, waypointEntryName));
    }
}
 
Example 2
private int layoutPunctuationsAndReturnStartIndexOfMoreSuggestions(
        final PunctuationSuggestions punctuationSuggestions, final ViewGroup stripView) {
    final int countInStrip = Math.min(punctuationSuggestions.size(), PUNCTUATIONS_IN_STRIP);
    for (int positionInStrip = 0; positionInStrip < countInStrip; positionInStrip++) {
        if (positionInStrip != 0) {
            // Add divider if this isn't the left most suggestion in suggestions strip.
            addDivider(stripView, mDividerViews.get(positionInStrip));
        }

        final TextView wordView = mWordViews.get(positionInStrip);
        final String punctuation = punctuationSuggestions.getLabel(positionInStrip);
        // {@link TextView#getTag()} is used to get the index in suggestedWords at
        // {@link SuggestionStripView#onClick(View)}.
        wordView.setTag(positionInStrip);
        wordView.setText(punctuation);
        wordView.setContentDescription(punctuation);
        wordView.setTextScaleX(1.0f);
        wordView.setCompoundDrawables(null, null, null, null);
        wordView.setTextColor(mColorAutoCorrect);
        stripView.addView(wordView);
        setLayoutWeight(wordView, 1.0f, mSuggestionsStripHeight);
    }
    mMoreSuggestionsAvailable = (punctuationSuggestions.size() > countInStrip);
    return countInStrip;
}
 
Example 3
private boolean setView(int id, String packageName) {
    TextView donate = (TextView) findViewById(id);
    PackageManager pm = getPackageManager();
    try {
        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;
    }
}
 
Example 4
/** Expands the views for individual list entries, and sets content descriptions for use by the
 *  TaskBackAccessibilityService.
 */
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if(convertView == null) {
        LayoutInflater inflater = LayoutInflater.from(mContext);
        convertView = inflater.inflate(R.layout.tasklist_row, parent, false);
    }

    CheckBox checkbox = (CheckBox) convertView.findViewById(R.id.tasklist_finished);
    checkbox.setChecked(mCheckboxes[position]);

    TextView label = (TextView)(convertView.findViewById(R.id.tasklist_label));
    label.setText(mLabels[position]);

    String contentDescription = new StringBuilder()
            .append(mContext.getString(R.string.task_name))
            .append(' ')
            .append(mLabels[position]).toString();
    label.setContentDescription(contentDescription);

    convertView.setTag(position);

    return convertView;
}
 
Example 5
/**
 * 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.
 */
private TextView layoutWord(final Context context, 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)
                ? context.getResources().getString(R.string.spoken_empty_suggestion)
                : word.toString());
    final CharSequence text = getEllipsizedTextWithSettingScaleX(
            word, width, wordView.getPaint());
    final float scaleX = wordView.getTextScaleX();
    wordView.setText(text); // TextView.setText() resets text scale x to 1.0.
    wordView.setTextScaleX(scaleX);
    // 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.Companion.getInstance().isTouchExplorationEnabled());
    return wordView;
}
 
Example 6
/**
 * 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.
 */
private TextView layoutWord(final Context context, 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)
                ? context.getResources().getString(R.string.spoken_empty_suggestion)
                : word.toString());
    final CharSequence text = getEllipsizedTextWithSettingScaleX(
            word, width, wordView.getPaint());
    final float scaleX = wordView.getTextScaleX();
    wordView.setText(text); // TextView.setText() resets text scale x to 1.0.
    wordView.setTextScaleX(scaleX);
    // 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;
}
 
Example 7
Source Project: science-journal   File: StatsList.java    License: Apache License 2.0 5 votes vote down vote up
public void updateStats(List<StreamStat> stats) {
  this.stats.clear();
  this.stats.addAll(stats);

  for (int i = 0; i < stats.size(); i++) {
    StreamStat stat = stats.get(i);
    TextView next = null;
    switch (stat.getType()) {
      case StreamStat.TYPE_MIN:
        next = minTextView;
        break;
      case StreamStat.TYPE_MAX:
        next = maxTextView;
        break;
      case StreamStat.TYPE_AVERAGE:
        next = avgTextView;
        break;
    }
    if (next == null) {
      continue;
    }
    String text = stat.getDisplayValue();
    next.setText(text);
    next.setContentDescription(
        getResources().getString(stat.getDisplayTypeStringId()) + ": " + text);
  }
}
 
Example 8
private void hookUpExperimentDetailsArea(Trial trial, View rootView) {
  setArchivedUi(rootView, trial.isArchived());

  final RelativeTimeTextView runDetailsText =
      (RelativeTimeTextView) rootView.findViewById(R.id.run_details_text);
  runDetailsText.setTime(trial.getFirstTimestamp());

  final TextView durationText = (TextView) rootView.findViewById(R.id.run_review_duration);
  ElapsedTimeFormatter formatter = ElapsedTimeFormatter.getInstance(durationText.getContext());
  durationText.setText(formatter.format(trial.elapsedSeconds()));
  durationText.setContentDescription(formatter.formatForAccessibility(trial.elapsedSeconds()));
}
 
Example 9
private static void updateCounterContentDescription(
    @NonNull Context context,
    @NonNull TextView counterView,
    int length,
    int counterMaxLength,
    boolean counterOverflowed) {
  counterView.setContentDescription(
      context.getString(
          counterOverflowed
              ? R.string.character_counter_overflowed_content_description
              : R.string.character_counter_content_description,
          length,
          counterMaxLength));
}
 
Example 10
@Override
public void onBindViewHolder(PreferenceViewHolder view) {
    super.onBindViewHolder(view);
    if (!TextUtils.isEmpty(mContentDescription)) {
        final TextView titleView = (TextView) view.findViewById(android.R.id.title);
        titleView.setContentDescription(mContentDescription);
    }
    ViewGroup.LayoutParams layoutParams = view.findViewById(R.id.icon_frame).getLayoutParams();
    if (layoutParams instanceof LinearLayout.LayoutParams) {
        if (((LinearLayout.LayoutParams) layoutParams).leftMargin < 0) {
            ((LinearLayout.LayoutParams) layoutParams).leftMargin = 0;
        }
    }
    dimIcon(shouldDimIcon());
}
 
Example 11
Source Project: Trebuchet   File: Hotseat.java    License: GNU General Public License v3.0 5 votes vote down vote up
void resetLayout() {
    mContent.removeAllViewsInLayout();

    // Add the Apps button
    Context context = getContext();

    LayoutInflater inflater = LayoutInflater.from(context);
    TextView allAppsButton = (TextView)
            inflater.inflate(R.layout.all_apps_button, mContent, false);
    Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon);

    mLauncher.resizeIconDrawable(d);
    allAppsButton.setCompoundDrawables(null, d, null, null);

    allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
    allAppsButton.setOnKeyListener(new HotseatIconKeyEventListener());
    if (mLauncher != null) {
        mLauncher.setAllAppsButton(allAppsButton);
        allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener());
        allAppsButton.setOnClickListener(mLauncher);
        allAppsButton.setOnLongClickListener(mLauncher);
        allAppsButton.setOnFocusChangeListener(mLauncher.mFocusHandler);
    }

    // Note: We do this to ensure that the hotseat is always laid out in the orientation of
    // the hotseat in order regardless of which orientation they were added
    int x = getCellXFromOrder(mAllAppsButtonRank);
    int y = getCellYFromOrder(mAllAppsButtonRank);
    CellLayout.LayoutParams lp = new CellLayout.LayoutParams(x,y,1,1);
    lp.canReorder = false;
    mContent.addViewToCellLayout(allAppsButton, -1, allAppsButton.getId(), lp, true);
}
 
Example 12
public void setContentDescription( String value )
{
    this.contentDescription = value;
    TextView snackText = (TextView) snackbar.getView().findViewById(android.support.design.R.id.snackbar_text);
    if (snackText != null)
    {
        snackText.setContentDescription(contentDescription);
    }
}
 
Example 13
private View setUpViewHierarchy() {
  Context targetContext = getApplicationContext();
  TextView v1 = new TextView(targetContext);
  v1.setText(text1);
  TextView v2 = new TextView(targetContext);
  v2.setText(text2);
  v2.setContentDescription("content description");
  ViewGroup parent = new RelativeLayout(targetContext);
  View grany = new ScrollView(targetContext);
  ((ViewGroup) grany).addView(parent);
  parent.addView(v1);
  parent.addView(v2);

  return grany;
}
 
Example 14
Source Project: LB-Launcher   File: Hotseat.java    License: Apache License 2.0 5 votes vote down vote up
void resetLayout() {
    mContent.removeAllViewsInLayout();

    if (!LauncherAppState.isDisableAllApps()) {
        // Add the Apps button
        Context context = getContext();

        LayoutInflater inflater = LayoutInflater.from(context);
        TextView allAppsButton = (TextView)
                inflater.inflate(R.layout.all_apps_button, mContent, false);
        Drawable d = context.getResources().getDrawable(R.drawable.all_apps_button_icon);

        Utilities.resizeIconDrawable(d);
        allAppsButton.setCompoundDrawables(null, d, null, null);

        allAppsButton.setContentDescription(context.getString(R.string.all_apps_button_label));
        allAppsButton.setOnKeyListener(new HotseatIconKeyEventListener());
        if (mLauncher != null) {
            allAppsButton.setOnTouchListener(mLauncher.getHapticFeedbackTouchListener());
            mLauncher.setAllAppsButton(allAppsButton);
            allAppsButton.setOnClickListener(mLauncher);
            allAppsButton.setOnFocusChangeListener(mLauncher.mFocusHandler);
        }

        // Note: We do this to ensure that the hotseat is always laid out in the orientation of
        // the hotseat in order regardless of which orientation they were added
        int x = getCellXFromOrder(mAllAppsButtonRank);
        int y = getCellYFromOrder(mAllAppsButtonRank);
        CellLayout.LayoutParams lp = new CellLayout.LayoutParams(x,y,1,1);
        lp.canReorder = false;
        mContent.addViewToCellLayout(allAppsButton, -1, allAppsButton.getId(), lp, true);
    }
}
 
Example 15
Source Project: a   File: TabLayout.java    License: GNU General Public License v3.0 4 votes vote down vote up
private void updateTextAndIcon(@Nullable final TextView textView,
                               @Nullable final ImageView iconView) {
    final Drawable icon = mTab != null ? mTab.getIcon() : null;
    final CharSequence text = mTab != null ? mTab.getText() : null;
    final CharSequence contentDesc = mTab != null ? mTab.getContentDescription() : null;

    if (iconView != null) {
        if (icon != null) {
            iconView.setImageDrawable(icon);
            iconView.setVisibility(VISIBLE);
            setVisibility(VISIBLE);
        } else {
            iconView.setVisibility(GONE);
            iconView.setImageDrawable(null);
        }
        iconView.setContentDescription(contentDesc);
    }

    final boolean hasText = !TextUtils.isEmpty(text);
    if (textView != null) {
        if (hasText) {
            textView.setText(text);
            textView.setVisibility(VISIBLE);
            setVisibility(VISIBLE);
        } else {
            textView.setVisibility(GONE);
            textView.setText(null);
        }
        textView.setContentDescription(contentDesc);
    }

    if (iconView != null) {
        MarginLayoutParams lp = ((MarginLayoutParams) iconView.getLayoutParams());
        int bottomMargin = 0;
        if (hasText && iconView.getVisibility() == VISIBLE) {
            // If we're showing both text and icon, add some margin bottom to the icon
            bottomMargin = dpToPx(DEFAULT_GAP_TEXT_ICON);
        }
        if (bottomMargin != lp.bottomMargin) {
            lp.bottomMargin = bottomMargin;
            iconView.requestLayout();
        }
    }
    TooltipCompat.setTooltipText(this, hasText ? null : contentDesc);
}
 
Example 16
public SuggestionStripView(final Context context, final AttributeSet attrs,
        final int defStyle) {
    super(context, attrs, defStyle);

    final LayoutInflater inflater = LayoutInflater.from(context);
    inflater.inflate(R.layout.suggestions_strip, this);

    mSuggestionsStrip = findViewById(R.id.suggestions_strip);
    mVoiceKey = findViewById(R.id.suggestions_strip_voice_key);
    mImportantNoticeStrip = findViewById(R.id.important_notice_strip);
    mStripVisibilityGroup = new StripVisibilityGroup(this, mSuggestionsStrip,
            mImportantNoticeStrip);

    for (int pos = 0; pos < SuggestedWords.MAX_SUGGESTIONS; pos++) {
        final TextView word = new TextView(context, null, R.attr.suggestionWordStyle);
        word.setContentDescription(getResources().getString(R.string.spoken_empty_suggestion));
        word.setOnClickListener(this);
        word.setOnLongClickListener(this);
        mWordViews.add(word);
        final View divider = inflater.inflate(R.layout.suggestion_divider, null);
        mDividerViews.add(divider);
        final TextView info = new TextView(context, null, R.attr.suggestionWordStyle);
        info.setTextColor(Color.WHITE);
        info.setTextSize(TypedValue.COMPLEX_UNIT_DIP, DEBUG_INFO_TEXT_SIZE_IN_DIP);
        mDebugInfoViews.add(info);
    }

    mLayoutHelper = new SuggestionStripLayoutHelper(
            context, attrs, defStyle, mWordViews, mDividerViews, mDebugInfoViews);

    mMoreSuggestionsContainer = inflater.inflate(R.layout.more_suggestions, null);
    mMoreSuggestionsView = mMoreSuggestionsContainer
            .findViewById(R.id.more_suggestions_view);
    mMoreSuggestionsBuilder = new MoreSuggestions.Builder(context, mMoreSuggestionsView);

    final Resources res = context.getResources();
    mMoreSuggestionsModalTolerance = res.getDimensionPixelOffset(
            R.dimen.config_more_suggestions_modal_tolerance);
    mMoreSuggestionsSlidingDetector = new GestureDetector(
            context, mMoreSuggestionsSlidingListener);

    final TypedArray keyboardAttr = context.obtainStyledAttributes(attrs,
            R.styleable.Keyboard, defStyle, R.style.SuggestionStripView);
    final Drawable iconVoice = keyboardAttr.getDrawable(R.styleable.Keyboard_iconShortcutKey);
    keyboardAttr.recycle();
    mVoiceKey.setImageDrawable(iconVoice);
    mVoiceKey.setOnClickListener(this);
}
 
Example 17
public SuggestionStripView(final Context context, final AttributeSet attrs,
        final int defStyle) {
    super(context, attrs, defStyle);

    final LayoutInflater inflater = LayoutInflater.from(context);
    inflater.inflate(R.layout.suggestions_strip, this);

    mSuggestionsStrip = (ViewGroup)findViewById(R.id.suggestions_strip);
    mVoiceKey = (ImageButton)findViewById(R.id.suggestions_strip_voice_key);
    mImportantNoticeStrip = findViewById(R.id.important_notice_strip);
    mStripVisibilityGroup = new StripVisibilityGroup(this, mSuggestionsStrip,
            mImportantNoticeStrip);

    for (int pos = 0; pos < SuggestedWords.MAX_SUGGESTIONS; pos++) {
        final TextView word = new TextView(context, null, R.attr.suggestionWordStyle);
        word.setContentDescription(getResources().getString(R.string.spoken_empty_suggestion));
        word.setOnClickListener(this);
        word.setOnLongClickListener(this);
        mWordViews.add(word);
        final View divider = inflater.inflate(R.layout.suggestion_divider, null);
        mDividerViews.add(divider);
        final TextView info = new TextView(context, null, R.attr.suggestionWordStyle);
        info.setTextColor(Color.WHITE);
        info.setTextSize(TypedValue.COMPLEX_UNIT_DIP, DEBUG_INFO_TEXT_SIZE_IN_DIP);
        mDebugInfoViews.add(info);
    }

    mLayoutHelper = new SuggestionStripLayoutHelper(
            context, attrs, defStyle, mWordViews, mDividerViews, mDebugInfoViews);

    mMoreSuggestionsContainer = inflater.inflate(R.layout.more_suggestions, null);
    mMoreSuggestionsView = (MoreSuggestionsView)mMoreSuggestionsContainer
            .findViewById(R.id.more_suggestions_view);
    mMoreSuggestionsBuilder = new MoreSuggestions.Builder(context, mMoreSuggestionsView);

    final Resources res = context.getResources();
    mMoreSuggestionsModalTolerance = res.getDimensionPixelOffset(
            R.dimen.config_more_suggestions_modal_tolerance);
    mMoreSuggestionsSlidingDetector = new GestureDetector(
            context, mMoreSuggestionsSlidingListener);

    final TypedArray keyboardAttr = context.obtainStyledAttributes(attrs,
            R.styleable.Keyboard, defStyle, R.style.SuggestionStripView);
    final Drawable iconVoice = keyboardAttr.getDrawable(R.styleable.Keyboard_iconShortcutKey);
    keyboardAttr.recycle();
    mVoiceKey.setImageDrawable(iconVoice);
    mVoiceKey.setOnClickListener(this);
}
 
Example 18
public SuggestionStripView(final Context context, final AttributeSet attrs,
        final int defStyle) {
    super(context, attrs, defStyle);

    final LayoutInflater inflater = LayoutInflater.from(context);
    inflater.inflate(R.layout.suggestions_strip, this);

    mSuggestionsStrip = (ViewGroup)findViewById(R.id.suggestions_strip);
    mVoiceKey = (ImageButton)findViewById(R.id.suggestions_strip_voice_key);
    mImportantNoticeStrip = findViewById(R.id.important_notice_strip);
    mStripVisibilityGroup = new StripVisibilityGroup(this, mSuggestionsStrip,
            mImportantNoticeStrip);

    for (int pos = 0; pos < SuggestedWords.MAX_SUGGESTIONS; pos++) {
        final TextView word = new TextView(context, null, R.attr.suggestionWordStyle);
        word.setContentDescription(getResources().getString(R.string.spoken_empty_suggestion));
        word.setOnClickListener(this);
        word.setOnLongClickListener(this);
        mWordViews.add(word);
        final View divider = inflater.inflate(R.layout.suggestion_divider, null);
        mDividerViews.add(divider);
        final TextView info = new TextView(context, null, R.attr.suggestionWordStyle);
        info.setTextColor(Color.WHITE);
        info.setTextSize(TypedValue.COMPLEX_UNIT_DIP, DEBUG_INFO_TEXT_SIZE_IN_DIP);
        mDebugInfoViews.add(info);
    }

    mLayoutHelper = new SuggestionStripLayoutHelper(
            context, attrs, defStyle, mWordViews, mDividerViews, mDebugInfoViews);

    mMoreSuggestionsContainer = inflater.inflate(R.layout.more_suggestions, null);
    mMoreSuggestionsView = (MoreSuggestionsView)mMoreSuggestionsContainer
            .findViewById(R.id.more_suggestions_view);
    mMoreSuggestionsBuilder = new MoreSuggestions.Builder(context, mMoreSuggestionsView);

    final Resources res = context.getResources();
    mMoreSuggestionsModalTolerance = res.getDimensionPixelOffset(
            R.dimen.config_more_suggestions_modal_tolerance);
    mMoreSuggestionsSlidingDetector = new GestureDetector(
            context, mMoreSuggestionsSlidingListener);

    final TypedArray keyboardAttr = context.obtainStyledAttributes(attrs,
            R.styleable.Keyboard, defStyle, R.style.SuggestionStripView);
    final Drawable iconVoice = keyboardAttr.getDrawable(R.styleable.Keyboard_iconShortcutKey);
    keyboardAttr.recycle();
    mVoiceKey.setImageDrawable(iconVoice);
    mVoiceKey.setOnClickListener(this);
}
 
Example 19
Source Project: microbit   File: ProjectActivity.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Updates UI of current connection status and device name.
 */
private void setConnectedDeviceText() {

    TextView connectedIndicatorText = (TextView) findViewById(R.id.connectedIndicatorText);
    connectedIndicatorText.setText(connectedIndicatorText.getText());
    connectedIndicatorText.setTypeface(MBApp.getApp().getRobotoTypeface());
    TextView deviceName = (TextView) findViewById(R.id.deviceName);
    deviceName.setContentDescription(deviceName.getText());
    deviceName.setTypeface(MBApp.getApp().getRobotoTypeface());
    deviceName.setOnClickListener(this);
    ImageView connectedIndicatorIcon = (ImageView) findViewById(R.id.connectedIndicatorIcon);

    //Override the connection Icon in case of active flashing
    if(mActivityState == FlashActivityState.FLASH_STATE_FIND_DEVICE
            || mActivityState == FlashActivityState.FLASH_STATE_VERIFY_DEVICE
            || mActivityState == FlashActivityState.FLASH_STATE_WAIT_DEVICE_REBOOT
            || mActivityState == FlashActivityState.FLASH_STATE_INIT_DEVICE
            || mActivityState == FlashActivityState.FLASH_STATE_PROGRESS
            ) {
        connectedIndicatorIcon.setImageResource(R.drawable.device_status_connected);
        connectedIndicatorText.setText(getString(R.string.connected_to));

        return;
    }
    ConnectedDevice device = BluetoothUtils.getPairedMicrobit(this);
    if(!device.mStatus) {
        connectedIndicatorIcon.setImageResource(R.drawable.device_status_disconnected);
        connectedIndicatorText.setText(getString(R.string.not_connected));
        if(device.mName != null) {
            deviceName.setText(device.mName);
        } else {
            deviceName.setText("");
        }
    } else {
        connectedIndicatorIcon.setImageResource(R.drawable.device_status_connected);
        connectedIndicatorText.setText(getString(R.string.connected_to));
        if(device.mName != null) {
            deviceName.setText(device.mName);
        } else {
            deviceName.setText("");
        }
    }
}
 
Example 20
Source Project: microbit   File: PairingActivity.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Displays needed screen according to a pairing state and
 * allows to navigate through the connection screens.
 *
 * @param gotoState New pairing state.
 */
private void displayScreen(PAIRING_STATE gotoState) {
    //Reset all screens first
    pairTipView.setVisibility(View.GONE);
    newDeviceView.setVisibility(View.GONE);
    pairSearchView.setVisibility(View.GONE);
    connectDeviceView.setVisibility(View.GONE);

    logi("********** Connect: state from " + pairingState + " to " + gotoState);
    pairingState = gotoState;

    boolean mDeviceListAvailable = ((gotoState == PAIRING_STATE.PAIRING_STATE_CONNECT_BUTTON) ||
            (gotoState == PAIRING_STATE.PAIRING_STATE_ERROR));

    if(mDeviceListAvailable) {
        updatePairedDeviceCard();
        connectDeviceView.setVisibility(View.VISIBLE);
    }

    switch(gotoState) {
        case PAIRING_STATE_CONNECT_BUTTON:
            break;

        case PAIRING_STATE_ERROR:
            Arrays.fill(DEVICE_CODE_ARRAY, 0);
            findViewById(R.id.enter_pattern_step_2_gridview).setEnabled(true);
            newDeviceName = "";
            newDeviceCode = "";
            break;

        case PAIRING_STATE_STEP_1:
            pairTipView.setVisibility(View.VISIBLE);
            findViewById(R.id.ok_tip_step_1_btn).setOnClickListener(this);
            break;

        case PAIRING_STATE_STEP_2:
            newDeviceView.setVisibility(View.VISIBLE);
            findViewById(R.id.cancel_enter_pattern_step_2_btn).setVisibility(View.VISIBLE);
            findViewById(R.id.enter_pattern_step_2_title).setVisibility(View.VISIBLE);
            findViewById(R.id.oh_pretty_emoji).setVisibility(View.VISIBLE);

            displayLedGrid();
            break;

        case PAIRING_STATE_SEARCHING:
            if(pairSearchView != null) {
                pairSearchView.setVisibility(View.VISIBLE);
                TextView tvTitle = (TextView) findViewById(R.id.search_microbit_step_3_title);
                TextView tvSearchingStep = (TextView) findViewById(R.id.searching_microbit_step);
                tvSearchingStep.setContentDescription(tvSearchingStep.getText());
                TextView tvSearchingInstructions = (TextView) findViewById(R.id.searching_microbit_step_instructions);
                if(tvTitle != null) {
                    tvTitle.setText(R.string.searchingTitle);
                    findViewById(R.id.searching_progress_spinner).setVisibility(View.VISIBLE);
                    ((GifImageView) findViewById(R.id.searching_microbit_found_giffview))
                            .setImageResource(R.drawable.pairing_pin_screen_two);
                    if(currentOrientation == Configuration.ORIENTATION_LANDSCAPE) {
                        tvSearchingStep.setText(R.string.searching_tip_step_text_one_line);
                    } else {
                        tvSearchingStep.setText(R.string.searching_tip_step_text);
                    }
                    tvSearchingInstructions.setText(R.string.searching_tip_text_instructions);
                }
                justPaired = true;
            } else {
                justPaired = false;
            }
            break;
    }
}