List of usage examples for android.widget TextView setContentDescription
@RemotableViewMethod public void setContentDescription(CharSequence contentDescription)
From source file:com.google.samples.apps.iosched.myschedule.MyScheduleActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_schedule); // Pre-process the intent received to open this activity to determine if it was a deep // link to a SessionDetail. Typically you wouldn't use this type of logic, but we need to // because of the path of session details page on the website is only /schedule and session // ids are part of the query parameters (sid). Intent intent = getIntent();// ww w. j av a 2s . c o m if (intent != null && !TextUtils.isEmpty(intent.getDataString())) { // Check format against website format. String intentDataString = intent.getDataString(); try { Uri dataUri = Uri.parse(intentDataString); String sessionId = dataUri.getQueryParameter("sid"); if (!TextUtils.isEmpty(sessionId)) { Uri data = ScheduleContract.Sessions.buildSessionUri(sessionId); Intent sessionDetailIntent = new Intent(MyScheduleActivity.this, SessionDetailActivity.class); sessionDetailIntent.setData(data); startActivity(sessionDetailIntent); finish(); } LOGD(TAG, "SessionId: " + sessionId); } catch (Exception exception) { LOGE(TAG, "Data uri existing but wasn't parsable for a session detail deep link"); } } // ANALYTICS SCREEN: View the My Schedule screen // Contains: Nothing (Page name is a constant) AnalyticsHelper.sendScreenView(SCREEN_LABEL); mViewPager = (ViewPager) findViewById(R.id.view_pager); mScrollViewWide = (ScrollView) findViewById(R.id.main_content_wide); mWideMode = findViewById(R.id.my_schedule_first_day) != null; if (SettingsUtils.isAttendeeAtVenue(this)) { mDayZeroAdapter = new MyScheduleAdapter(this, getLUtils()); prepareDayZeroAdapter(); } for (int i = 0; i < Config.CONFERENCE_DAYS.length; i++) { mScheduleAdapters[i] = new MyScheduleAdapter(this, getLUtils()); } mViewPagerAdapter = new OurViewPagerAdapter(getFragmentManager()); mViewPager.setAdapter(mViewPagerAdapter); if (mWideMode) { mMyScheduleViewWide[0] = (MyScheduleView) findViewById(R.id.my_schedule_first_day); mMyScheduleViewWide[0].setAdapter(mScheduleAdapters[0]); mMyScheduleViewWide[1] = (MyScheduleView) findViewById(R.id.my_schedule_second_day); mMyScheduleViewWide[1].setAdapter(mScheduleAdapters[1]); TextView firstDayHeaderView = (TextView) findViewById(R.id.day_label_first_day); TextView secondDayHeaderView = (TextView) findViewById(R.id.day_label_second_day); if (firstDayHeaderView != null) { firstDayHeaderView.setText(getDayName(0)); } if (secondDayHeaderView != null) { secondDayHeaderView.setText(getDayName(1)); } TextView zerothDayHeaderView = (TextView) findViewById(R.id.day_label_zeroth_day); MyScheduleView dayZeroView = (MyScheduleView) findViewById(R.id.my_schedule_zeroth_day); if (mDayZeroAdapter != null) { dayZeroView.setAdapter(mDayZeroAdapter); dayZeroView.setVisibility(View.VISIBLE); zerothDayHeaderView.setText(getDayName(-1)); zerothDayHeaderView.setVisibility(View.VISIBLE); } else { dayZeroView.setVisibility(View.GONE); zerothDayHeaderView.setVisibility(View.GONE); } } else { // it's PagerAdapter set. mTabLayout = (TabLayout) findViewById(R.id.sliding_tabs); mTabLayout.setTabsFromPagerAdapter(mViewPagerAdapter); mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { mViewPager.setCurrentItem(tab.getPosition(), true); TextView view = (TextView) findViewById(baseTabViewId + tab.getPosition()); view.setContentDescription( getString(R.string.talkback_selected, getString(R.string.a11y_button, tab.getText()))); } @Override public void onTabUnselected(TabLayout.Tab tab) { TextView view = (TextView) findViewById(baseTabViewId + tab.getPosition()); view.setContentDescription(getString(R.string.a11y_button, tab.getText())); } @Override public void onTabReselected(TabLayout.Tab tab) { // Do nothing } }); mViewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.my_schedule_page_margin)); mViewPager.setPageMarginDrawable(R.drawable.page_margin); setTabLayoutContentDescriptions(); } mButterBar = findViewById(R.id.butter_bar); removeLoginFailed(); overridePendingTransition(0, 0); addDataObservers(); }
From source file:com.android.launcher3.allapps.AllAppsGridAdapter.java
@Override public void onBindViewHolder(ViewHolder holder, int position) { switch (holder.getItemViewType()) { case ICON_VIEW_TYPE: { AppInfo info = mApps.getAdapterItems().get(position).appInfo; BubbleTextView icon = (BubbleTextView) holder.mContent; icon.applyFromApplicationInfo(info); icon.setAccessibilityDelegate(LauncherAppState.getInstance().getAccessibilityDelegate()); break;/*from w w w. ja v a2 s .c o m*/ } case PREDICTION_ICON_VIEW_TYPE: { AppInfo info = mApps.getAdapterItems().get(position).appInfo; BubbleTextView icon = (BubbleTextView) holder.mContent; icon.applyFromApplicationInfo(info); icon.setAccessibilityDelegate(LauncherAppState.getInstance().getAccessibilityDelegate()); break; } case EMPTY_SEARCH_VIEW_TYPE: TextView emptyViewText = (TextView) holder.mContent; emptyViewText.setText(mEmptySearchMessage); emptyViewText.setGravity( mApps.hasNoFilteredResults() ? Gravity.CENTER : Gravity.START | Gravity.CENTER_VERTICAL); break; case SEARCH_MARKET_VIEW_TYPE: TextView searchView = (TextView) holder.mContent; if (mMarketSearchIntent != null) { searchView.setVisibility(View.VISIBLE); searchView.setContentDescription(mMarketSearchMessage); searchView.setGravity( mApps.hasNoFilteredResults() ? Gravity.CENTER : Gravity.START | Gravity.CENTER_VERTICAL); searchView.setText(mMarketSearchMessage); } else { searchView.setVisibility(View.GONE); } break; } if (mBindViewCallback != null) { mBindViewCallback.onBindView(holder); } }
From source file:com.razza.apps.iosched.myschedule.MyScheduleActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_my_schedule); // Pre-process the intent received to open this activity to determine if it was a deep // link to a SessionDetail. Typically you wouldn't use this type of logic, but we need to // because of the path of session details page on the website is only /schedule and session // ids are part of the query parameters (sid). Intent intent = getIntent();/*from www . j ava 2 s . c o m*/ if (intent != null && !TextUtils.isEmpty(intent.getDataString())) { // Check format against website format. String intentDataString = intent.getDataString(); try { Uri dataUri = Uri.parse(intentDataString); String sessionId = dataUri.getQueryParameter("sid"); if (!TextUtils.isEmpty(sessionId)) { Uri data = ScheduleContract.Sessions.buildSessionUri(sessionId); Intent sessionDetailIntent = new Intent(MyScheduleActivity.this, SessionDetailActivity.class); sessionDetailIntent.setData(data); startActivity(sessionDetailIntent); finish(); } LogUtils.LOGD(TAG, "SessionId: " + sessionId); } catch (Exception exception) { LogUtils.LOGE(TAG, "Data uri existing but wasn't parsable for a session detail deep link"); } } // ANALYTICS SCREEN: View the My Schedule screen // Contains: Nothing (Page name is a constant) AnalyticsHelper.sendScreenView(SCREEN_LABEL); mViewPager = (ViewPager) findViewById(R.id.view_pager); mScrollViewWide = (ScrollView) findViewById(R.id.main_content_wide); mWideMode = findViewById(R.id.my_schedule_first_day) != null; if (SettingsUtils.isAttendeeAtVenue(this)) { mDayZeroAdapter = new MyScheduleAdapter(this, getLUtils()); prepareDayZeroAdapter(); } for (int i = 0; i < Config.CONFERENCE_DAYS.length; i++) { mScheduleAdapters[i] = new MyScheduleAdapter(this, getLUtils()); } mViewPagerAdapter = new OurViewPagerAdapter(getFragmentManager()); mViewPager.setAdapter(mViewPagerAdapter); if (mWideMode) { mMyScheduleViewWide[0] = (MyScheduleView) findViewById(R.id.my_schedule_first_day); mMyScheduleViewWide[0].setAdapter(mScheduleAdapters[0]); mMyScheduleViewWide[1] = (MyScheduleView) findViewById(R.id.my_schedule_second_day); mMyScheduleViewWide[1].setAdapter(mScheduleAdapters[1]); TextView firstDayHeaderView = (TextView) findViewById(R.id.day_label_first_day); TextView secondDayHeaderView = (TextView) findViewById(R.id.day_label_second_day); if (firstDayHeaderView != null) { firstDayHeaderView.setText(getDayName(0)); } if (secondDayHeaderView != null) { secondDayHeaderView.setText(getDayName(1)); } TextView zerothDayHeaderView = (TextView) findViewById(R.id.day_label_zeroth_day); MyScheduleView dayZeroView = (MyScheduleView) findViewById(R.id.my_schedule_zeroth_day); if (mDayZeroAdapter != null) { dayZeroView.setAdapter(mDayZeroAdapter); dayZeroView.setVisibility(View.VISIBLE); zerothDayHeaderView.setText(getDayName(-1)); zerothDayHeaderView.setVisibility(View.VISIBLE); } else { dayZeroView.setVisibility(View.GONE); zerothDayHeaderView.setVisibility(View.GONE); } } else { // it's PagerAdapter set. mTabLayout = (TabLayout) findViewById(R.id.sliding_tabs); mTabLayout.setTabsFromPagerAdapter(mViewPagerAdapter); mTabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { mViewPager.setCurrentItem(tab.getPosition(), true); TextView view = (TextView) findViewById(baseTabViewId + tab.getPosition()); view.setContentDescription( getString(R.string.talkback_selected, getString(R.string.a11y_button, tab.getText()))); } @Override public void onTabUnselected(TabLayout.Tab tab) { TextView view = (TextView) findViewById(baseTabViewId + tab.getPosition()); view.setContentDescription(getString(R.string.a11y_button, tab.getText())); } @Override public void onTabReselected(TabLayout.Tab tab) { // Do nothing } }); mViewPager.setPageMargin(getResources().getDimensionPixelSize(R.dimen.my_schedule_page_margin)); mViewPager.setPageMarginDrawable(R.drawable.page_margin); setTabLayoutContentDescriptions(); } mButterBar = findViewById(R.id.butter_bar); removeLoginFailed(); overridePendingTransition(0, 0); addDataObservers(); }
From source file:com.google.samples.apps.iosched.myschedule.MyScheduleActivity.java
private void setTabLayoutContentDescriptions() { LayoutInflater inflater = getLayoutInflater(); int gap = mDayZeroAdapter == null ? 0 : 1; for (int i = 0, count = mTabLayout.getTabCount(); i < count; i++) { TabLayout.Tab tab = mTabLayout.getTabAt(i); TextView view = (TextView) inflater.inflate(R.layout.tab_my_schedule, mTabLayout, false); view.setId(baseTabViewId + i);//w w w . j av a 2s . c o m view.setText(tab.getText()); if (i == 0) { view.setContentDescription( getString(R.string.talkback_selected, getString(R.string.a11y_button, tab.getText()))); } else { view.setContentDescription(getString(R.string.a11y_button, tab.getText())); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { view.announceForAccessibility(getString(R.string.my_schedule_tab_desc_a11y, getDayName(i - gap))); } tab.setCustomView(view); } }
From source file:com.orange.essentials.otb.ui.OtbContainerFragment.java
/** * Convenient method used to fill information title, label and accessbility string */// www. j a v a2 s .c o m private void setTitleAndLabel(int viewId, int titleId, int contentId, int titleRes, int contentRes, int accessibilityRes) { TextView dataTitle = null; TextView dataDetail = null; View container = this.getActivity().findViewById(viewId); if (null != container) { dataTitle = (TextView) container.findViewById(titleId); dataDetail = (TextView) container.findViewById(contentId); } if (dataTitle == null) { dataTitle = (TextView) getActivity().findViewById(viewId); } if (null != dataTitle) { dataTitle.setText(titleRes); dataTitle.setContentDescription(getString(accessibilityRes) + " " + getString(titleRes)); } if (null != dataDetail) { dataDetail.setText(contentRes); } }
From source file:com.android.launcher3.Hotseat.java
void resetLayout() { mContent.removeAllViewsInLayout();//from w w w. ja va2 s.c o m if (!FeatureFlags.NO_ALL_APPS_ICON) { // Add the Apps button Context context = getContext(); int allAppsButtonRank = mLauncher.getDeviceProfile().inv.getAllAppsButtonRank(); 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); int scaleDownPx = getResources().getDimensionPixelSize(R.dimen.all_apps_button_scale_down); Rect bounds = d.getBounds(); d.setBounds(bounds.left, bounds.top + scaleDownPx / 2, bounds.right - scaleDownPx, bounds.bottom - scaleDownPx / 2); 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(allAppsButtonRank); int y = getCellYFromOrder(allAppsButtonRank); CellLayout.LayoutParams lp = new CellLayout.LayoutParams(x, y, 1, 1); lp.canReorder = false; mContent.addViewToCellLayout(allAppsButton, -1, allAppsButton.getId(), lp, true); } }
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 {/*from ww w. ja va2s .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:com.lite.android.launcher3.allapps.AllAppsGridAdapter.java
@Override public void onBindViewHolder(ViewHolder holder, int position) { boolean hideIconLabels = SettingsProvider.getBoolean(mLauncher, SettingsProvider.SETTINGS_UI_DRAWER_HIDE_ICON_LABELS, R.bool.preferences_interface_drawer_hide_icon_labels_default); FastScrollFocusApplicator.setFastScrollDimmed(holder.mContent, false, false); FastScrollFocusApplicator.setFastScrollFocused(holder.mContent, false, false); switch (holder.getItemViewType()) { case ICON_VIEW_TYPE: { AppInfo info = mApps.getAdapterItems().get(position).appInfo; BubbleTextView icon = (BubbleTextView) holder.mContent; icon.setTextColor(mAllAppsTextColor); if (hideIconLabels) { icon.setTextVisibility(!hideIconLabels); }/*from w w w.ja v a2 s.com*/ icon.applyFromApplicationInfo(info); FastScrollFocusApplicator.setFastScrollDimmed(icon, shouldDimPosition(position), !mIconsDimmed); FastScrollFocusApplicator.setFastScrollFocused(icon, false, !mIconsDimmed); break; } case PREDICTION_ICON_VIEW_TYPE: { AppInfo info = mApps.getAdapterItems().get(position).appInfo; BubbleTextView icon = (BubbleTextView) holder.mContent; icon.setTextColor(mAllAppsTextColor); if (hideIconLabels) { icon.setTextVisibility(!hideIconLabels); } icon.applyFromApplicationInfo(info); FastScrollFocusApplicator.setFastScrollDimmed(icon, shouldDimPosition(position), !mIconsDimmed); FastScrollFocusApplicator.setFastScrollFocused(icon, false, !mIconsDimmed); mRemoteFolderManager.onBindViewHolder(holder, info); break; } case EMPTY_SEARCH_VIEW_TYPE: TextView emptyViewText = (TextView) holder.mContent; emptyViewText.setText(mEmptySearchMessage); emptyViewText.setGravity( mApps.hasNoFilteredResults() ? Gravity.CENTER : Gravity.START | Gravity.CENTER_VERTICAL); break; case SEARCH_MARKET_VIEW_TYPE: TextView searchView = (TextView) holder.mContent; if (mMarketSearchIntent != null) { searchView.setVisibility(View.VISIBLE); searchView.setContentDescription(mMarketSearchMessage); searchView.setGravity( mApps.hasNoFilteredResults() ? Gravity.CENTER : Gravity.START | Gravity.CENTER_VERTICAL); searchView.setText(mMarketSearchMessage); } else { searchView.setVisibility(View.GONE); } break; case CUSTOM_PREDICTED_APPS_HEADER_VIEW_TYPE: { TextView title = (TextView) holder.mContent.findViewById(R.id.title); title.setTextColor(mAllAppsTextColor); FastScrollFocusApplicator.setFastScrollDimmed(holder.mContent, shouldDimPosition(position), !mIconsDimmed); FastScrollFocusApplicator.setFastScrollFocused(holder.mContent, false, !mIconsDimmed); ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) holder.mContent.getLayoutParams(); mCustomPredictedAppsHeaderHeight = holder.mContent.getHeight() + lp.topMargin + lp.bottomMargin; break; } case CUSTOM_PREDICTED_APPS_FOOTER_VIEW_TYPE: ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) holder.mContent.getLayoutParams(); mCustomPredictedAppsFooterHeight = holder.mContent.getHeight() + lp.topMargin + lp.bottomMargin; } }
From source file:com.google.samples.apps.iosched.session.SessionDetailFragment.java
private void displayTags(SessionDetailModel data) { if (data.getTagMetadata() == null || data.getTagsString() == null) { mTagsContainer.setVisibility(View.GONE); return;/*ww w. j av a2s .co m*/ } if (TextUtils.isEmpty(data.getTagsString())) { mTagsContainer.setVisibility(View.GONE); } else { mTagsContainer.setVisibility(View.VISIBLE); mTags.removeAllViews(); LayoutInflater inflater = LayoutInflater.from(getContext()); String[] tagIds = data.getTagsString().split(","); List<TagMetadata.Tag> tags = new ArrayList<TagMetadata.Tag>(); for (String tagId : tagIds) { if (Config.Tags.SESSIONS.equals(tagId) || Config.Tags.SPECIAL_KEYNOTE.equals(tagId)) { continue; } TagMetadata.Tag tag = data.getTagMetadata().getTag(tagId); if (tag == null) { continue; } tags.add(tag); } if (tags.size() == 0) { mTagsContainer.setVisibility(View.GONE); return; } Collections.sort(tags, TagMetadata.TAG_DISPLAY_ORDER_COMPARATOR); for (final TagMetadata.Tag tag : tags) { TextView chipView = (TextView) inflater.inflate(R.layout.include_session_tag_chip, mTags, false); chipView.setText(tag.getName()); chipView.setContentDescription(getString(R.string.talkback_button, tag.getName())); chipView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent intent = new Intent(getContext(), ExploreSessionsActivity.class) .putExtra(ExploreSessionsActivity.EXTRA_FILTER_TAG, tag.getId()) .addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK); startActivity(intent); } }); mTags.addView(chipView); } } }
From source file:com.android.inputmethod.latin.suggestions.SuggestionStripLayoutHelper.java
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)); }//from w w w . j av a 2 s . c o m 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; }