List of usage examples for android.support.v4.view ViewCompat setAccessibilityDelegate
public static void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate)
From source file:android.support.design.widget.BottomSheetDialog.java
private View wrapInBottomSheet(int layoutResId, View view, ViewGroup.LayoutParams params) { final CoordinatorLayout coordinator = (CoordinatorLayout) View.inflate(getContext(), R.layout.design_bottom_sheet_dialog, null); if (layoutResId != 0 && view == null) { view = getLayoutInflater().inflate(layoutResId, coordinator, false); }/*from w ww . ja va2 s. c om*/ FrameLayout bottomSheet = (FrameLayout) coordinator.findViewById(R.id.design_bottom_sheet); mBehavior = BottomSheetBehavior.from(bottomSheet); mBehavior.setBottomSheetCallback(mBottomSheetCallback); mBehavior.setHideable(mCancelable); if (params == null) { bottomSheet.addView(view); } else { bottomSheet.addView(view, params); } // We treat the CoordinatorLayout as outside the dialog though it is technically inside coordinator.findViewById(R.id.touch_outside).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { if (mCancelable && isShowing() && shouldWindowCloseOnTouchOutside()) { cancel(); } } }); // Handle accessibility events ViewCompat.setAccessibilityDelegate(bottomSheet, new AccessibilityDelegateCompat() { @Override public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { super.onInitializeAccessibilityNodeInfo(host, info); if (mCancelable) { info.addAction(AccessibilityNodeInfoCompat.ACTION_DISMISS); info.setDismissable(true); } else { info.setDismissable(false); } } @Override public boolean performAccessibilityAction(View host, int action, Bundle args) { if (action == AccessibilityNodeInfoCompat.ACTION_DISMISS && mCancelable) { cancel(); return true; } return super.performAccessibilityAction(host, action, args); } }); return coordinator; }
From source file:org.connectbot.views.CheckableMenuItem.java
public CheckableMenuItem(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); mRootView = inflate(context, R.layout.view_checkablemenuitem, this); mTitle = (TextView) mRootView.findViewById(R.id.title); mSummary = (TextView) mRootView.findViewById(R.id.summary); mSwitch = (SwitchCompat) findViewById(R.id.checkbox_switch); setFocusable(true);//from w ww . j ava2s . c o m mAccessHelper = new ExploreByTouchHelper(this) { private final Rect mTmpRect = new Rect(); @Override protected int getVirtualViewAt(float x, float y) { return HOST_ID; } @Override protected void getVisibleVirtualViews(List<Integer> virtualViewIds) { } @Override protected void onPopulateEventForVirtualView(int virtualViewId, AccessibilityEvent event) { if (virtualViewId != HOST_ID) { // TODO(kroot): remove this when the bug is fixed. event.setContentDescription(PLACEHOLDER_STRING); return; } event.setContentDescription(mTitle.getText() + " " + mSummary.getText()); event.setClassName(ACCESSIBILITY_EVENT_CLASS_NAME); event.setChecked(isChecked()); } @Override protected void onPopulateNodeForVirtualView(int virtualViewId, AccessibilityNodeInfoCompat node) { if (virtualViewId != HOST_ID) { // TODO(kroot): remove this when the bug is fixed. node.setBoundsInParent(mPlaceHolderRect); node.setContentDescription(PLACEHOLDER_STRING); return; } mTmpRect.set(0, 0, CheckableMenuItem.this.getWidth(), CheckableMenuItem.this.getHeight()); node.setBoundsInParent(mTmpRect); node.addAction(AccessibilityNodeInfoCompat.ACTION_CLICK); node.setClassName(ACCESSIBILITY_EVENT_CLASS_NAME); node.setCheckable(true); node.setChecked(isChecked()); node.addChild(mTitle); node.addChild(mSummary); } @Override protected boolean onPerformActionForVirtualView(int virtualViewId, int action, Bundle arguments) { if (virtualViewId != HOST_ID) { return false; } if (action == AccessibilityNodeInfoCompat.ACTION_CLICK) { mSwitch.toggle(); sendAccessibilityEvent(mRootView, AccessibilityEventCompat.CONTENT_CHANGE_TYPE_UNDEFINED); return true; } return false; } }; ViewCompat.setAccessibilityDelegate(mRootView, mAccessHelper); setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mSwitch.toggle(); } }); if (attrs != null) { TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.CheckableMenuItem, 0, 0); @DrawableRes int iconRes = typedArray.getResourceId(R.styleable.CheckableMenuItem_android_icon, 0); @StringRes int titleRes = typedArray.getResourceId(R.styleable.CheckableMenuItem_android_title, 0); @StringRes int summaryRes = typedArray.getResourceId(R.styleable.CheckableMenuItem_summary, 0); typedArray.recycle(); ImageView icon = (ImageView) mRootView.findViewById(R.id.icon); mTitle.setText(titleRes); if (iconRes != 0) { Resources resources = context.getResources(); Resources.Theme theme = context.getTheme(); Drawable iconDrawable = VectorDrawableCompat.create(resources, iconRes, theme); icon.setImageDrawable(iconDrawable); } if (summaryRes != 0) { mSummary.setText(summaryRes); } } }
From source file:com.googlecode.eyesfree.example.bargraph.BarGraphView.java
public BarGraphView(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); // Load styled attributes. final int defStyleRes = (isInEditMode() ? 0 : R.style.BarGraph); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.BarGraph, defStyle, defStyleRes); final int n = a.getIndexCount(); for (int i = 0; i < n; i++) { final int attr = a.getIndex(i); switch (attr) { case R.styleable.BarGraph_barMargin: mBarMargin = a.getDimension(attr, mBarMargin); break; case R.styleable.BarGraph_barMinWidth: mBarMinHeight = a.getDimension(attr, mBarMinHeight); break; case R.styleable.BarGraph_barMinHeight: mBarMinWidth = a.getDimension(attr, mBarMinWidth); break; case R.styleable.BarGraph_title: setTitle(a.getText(attr));//w w w .j ava 2s .com break; case R.styleable.BarGraph_titleSize: mTitleSize = a.getDimension(attr, mTitleSize); break; case R.styleable.BarGraph_values: if (!isInEditMode()) { setData(context.getResources().getIntArray(a.getResourceId(attr, 0))); } break; } } a.recycle(); if (isInEditMode()) { // Special considerations for edit mode. mBarGraphAccessHelper = null; setData(new int[] { 1, 1, 2, 3, 5, 8 }); setSelection(3); } else { // Set up accessibility helper class. mBarGraphAccessHelper = new BarGraphAccessHelper(this); ViewCompat.setAccessibilityDelegate(this, mBarGraphAccessHelper); } }
From source file:im.ene.lab.io_timer.ui.widget.MiniDrawerLayout.java
@TargetApi(Build.VERSION_CODES.LOLLIPOP) public MiniDrawerLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); // as recommended setWillNotDraw(false);/*from w w w.j a v a 2 s. c om*/ // Custom attributes TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.MiniDrawerLayout, defStyleAttr, defStyleRes); mCollapseWidth = a.getDimensionPixelSize(R.styleable.MiniDrawerLayout_collapseWidth, 0); mExpandWidth = a.getDimensionPixelSize(R.styleable.MiniDrawerLayout_expandWidth, 0); a.recycle(); // View dragger final float density = getResources().getDisplayMetrics().density; final float minVel = MIN_FLING_VELOCITY * density; ViewDragCallback mDraggerCallback = new ViewDragCallback(); mDragHelper = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mDraggerCallback); mDragHelper.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT); mDragHelper.setMinVelocity(minVel); mDraggerCallback.setDragger(mDragHelper); // So that we can catch the back button setFocusableInTouchMode(true); ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegate()); ViewGroupCompat.setMotionEventSplittingEnabled(this, false); mNonDrawerViews = new ArrayList<>(); }
From source file:xyz.berial.textinputlayout.TextInputLayout.java
public TextInputLayout(Context context, AttributeSet attrs, int defStyleAttr) { // Can't call through to super(Context, AttributeSet, int) since it doesn't exist on API 10 super(context, attrs); setOrientation(VERTICAL);/* w w w . j av a 2 s. c o m*/ setWillNotDraw(false); setAddStatesFromChildren(true); mResources = getResources(); mCollapsingTextHelper.setTextSizeInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR); mCollapsingTextHelper.setPositionInterpolator(new AccelerateInterpolator()); mCollapsingTextHelper.setCollapsedTextGravity(Gravity.TOP | GravityCompat.START); final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.TextInputLayout, defStyleAttr, R.style.Widget_Design_TextInputLayout); mHint = a.getText(R.styleable.TextInputLayout_hint); mHintAnimationEnabled = a.getBoolean(R.styleable.TextInputLayout_hintAnimationEnabled, true); /*custom*/ final boolean counterEnabled = a.getBoolean(R.styleable.TextInputLayout_counterEnabled, false); mCounterMaxLength = a.getInt(R.styleable.TextInputLayout_counterMaxLength, 0); /*custom*/ if (a.hasValue(R.styleable.TextInputLayout_textColorHint)) { mDefaultTextColor = mFocusedTextColor = a.getColorStateList(R.styleable.TextInputLayout_textColorHint); } final int hintAppearance = a.getResourceId(R.styleable.TextInputLayout_hintTextAppearance, -1); if (hintAppearance != -1) { setHintTextAppearance(a.getResourceId(R.styleable.TextInputLayout_hintTextAppearance, 0)); } mErrorTextAppearance = a.getResourceId(R.styleable.TextInputLayout_errorTextAppearance, 0); final boolean errorEnabled = a.getBoolean(R.styleable.TextInputLayout_errorEnabled, false); a.recycle(); /*custom*/ mBottomBar = new RelativeLayout(context); addView(mBottomBar); setCounterEnabled(counterEnabled); /*custom*/ setErrorEnabled(errorEnabled); if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { // Make sure we're important for accessibility if we haven't been explicitly not ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); } ViewCompat.setAccessibilityDelegate(this, new TextInputAccessibilityDelegate()); }
From source file:com.redinput.datetimepickercompat.date.YearPickerView.java
private void installAccessibilityDelegate() { // The accessibility delegate enables customizing accessibility behavior // via composition as opposed as inheritance. The main benefit is that // one can write a backwards compatible application by setting the delegate // only if the API level is high enough i.e. the delegate is part of the APIs. // The easiest way to achieve that is by using the support library which // takes the burden of checking API version and knowing which API version // introduced the delegate off the developer. ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() { @Override/*from ww w.java 2 s.c om*/ public void onInitializeAccessibilityEvent(View host, AccessibilityEvent event) { super.onInitializeAccessibilityEvent(host, event); // Note that View.onInitializeAccessibilityNodeInfo was introduced in // ICS and we would like to tweak a bit the text that is reported to // accessibility services via the AccessibilityNodeInfo. if (event.getEventType() == AccessibilityEventCompat.TYPE_VIEW_SCROLLED) { event.setFromIndex(0); } } }); }
From source file:io.doist.datetimepicker.time.TimePickerClockDelegate.java
public TimePickerClockDelegate(TimePicker delegator, Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(delegator, context); // process style attributes final TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.TimePicker, defStyleAttr, defStyleRes);//from w w w . java 2s . c o m final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Resources res = mContext.getResources(); mSelectHours = res.getString(R.string.select_hours); mSelectMinutes = res.getString(R.string.select_minutes); String[] amPmStrings = DateTimeUtilsCompat.getBestAmPmStrings(mCurrentLocale); mAmText = amPmStrings[0]; mPmText = amPmStrings[1]; final int layoutResourceId = a.getResourceId(R.styleable.TimePicker_layout, R.layout.time_picker_holo); final View mainView = inflater.inflate(layoutResourceId, delegator); mHeaderView = mainView.findViewById(R.id.time_header); mHeaderView.setBackground(a.getDrawable(R.styleable.TimePicker_headerBackground)); // Set up hour/minute labels. mHourView = (TextView) mHeaderView.findViewById(R.id.hours); mHourView.setOnClickListener(mClickListener); ViewCompat.setAccessibilityDelegate(mHourView, new ClickActionDelegate(context, R.string.select_hours)); mSeparatorView = (TextView) mHeaderView.findViewById(R.id.separator); mMinuteView = (TextView) mHeaderView.findViewById(R.id.minutes); mMinuteView.setOnClickListener(mClickListener); ViewCompat.setAccessibilityDelegate(mMinuteView, new ClickActionDelegate(context, R.string.select_minutes)); final int headerTimeTextAppearance = a.getResourceId(R.styleable.TimePicker_headerTimeTextAppearance, 0); if (headerTimeTextAppearance != 0) { mHourView.setTextAppearance(context, headerTimeTextAppearance); mSeparatorView.setTextAppearance(context, headerTimeTextAppearance); mMinuteView.setTextAppearance(context, headerTimeTextAppearance); } // Now that we have text appearances out of the way, make sure the hour // and minute views are correctly sized. mHourView.setMinWidth(computeStableWidth(mHourView, 24)); mMinuteView.setMinWidth(computeStableWidth(mMinuteView, 60)); // TODO: This can be removed once we support themed color state lists. final int headerSelectedTextColor = a.getColor(R.styleable.TimePicker_headerSelectedTextColor, res.getColor(R.color.timepicker_default_selector_color_material)); mHourView.setTextColor(ViewStateUtils.addStateIfMissing(mHourView.getTextColors(), android.R.attr.state_selected, headerSelectedTextColor)); mMinuteView.setTextColor(ViewStateUtils.addStateIfMissing(mMinuteView.getTextColors(), android.R.attr.state_selected, headerSelectedTextColor)); // Set up AM/PM labels. // Set up AM/PM labels. mAmPmLayout = mHeaderView.findViewById(R.id.ampm_layout); mAmLabel = (CheckedTextView) mAmPmLayout.findViewById(R.id.am_label); mAmLabel.setText(mAmText); mAmLabel.setOnClickListener(mClickListener); mPmLabel = (CheckedTextView) mAmPmLayout.findViewById(R.id.pm_label); mPmLabel.setText(mPmText); mPmLabel.setOnClickListener(mClickListener); final int headerAmPmTextAppearance = a.getResourceId(R.styleable.TimePicker_headerAmPmTextAppearance, 0); if (headerAmPmTextAppearance != 0) { mAmLabel.setTextAppearance(context, headerAmPmTextAppearance); mPmLabel.setTextAppearance(context, headerAmPmTextAppearance); } a.recycle(); // Pull disabled alpha from theme. final TypedValue outValue = new TypedValue(); context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, outValue, true); mDisabledAlpha = outValue.getFloat(); mRadialTimePickerView = (RadialTimePickerView) mainView.findViewById(R.id.radial_picker); setupListeners(); mAllowAutoAdvance = true; // Set up for keyboard mode. mDoublePlaceholderText = res.getString(R.string.time_placeholder); mDeletedKeyFormat = res.getString(R.string.deleted_key); mPlaceholderText = mDoublePlaceholderText.charAt(0); mAmKeyCode = mPmKeyCode = -1; generateLegalTimesTree(); // Initialize with current time final Calendar calendar = Calendar.getInstance(mCurrentLocale); final int currentHour = calendar.get(Calendar.HOUR_OF_DAY); final int currentMinute = calendar.get(Calendar.MINUTE); initialize(currentHour, currentMinute, false /* 12h */, HOUR_INDEX); }
From source file:com.tr4android.support.extension.picker.date.SimpleMonthView.java
public SimpleMonthView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); final Resources res = context.getResources(); mDesiredMonthHeight = res.getDimensionPixelSize(R.dimen.date_picker_month_height); mDesiredDayOfWeekHeight = res.getDimensionPixelSize(R.dimen.date_picker_day_of_week_height); mDesiredDayHeight = res.getDimensionPixelSize(R.dimen.date_picker_day_height); mDesiredCellWidth = res.getDimensionPixelSize(R.dimen.date_picker_day_width); mDesiredDaySelectorRadius = res.getDimensionPixelSize(R.dimen.date_picker_day_selector_radius); // Set up accessibility components. mTouchHelper = new MonthViewTouchHelper(this); ViewCompat.setAccessibilityDelegate(this, mTouchHelper); ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); final Locale locale = res.getConfiguration().locale; final String titleFormat = DateFormatUtils.getBestDateTimePattern(locale, DEFAULT_TITLE_FORMAT); mTitleFormatter = new SimpleDateFormat(titleFormat, locale); mDayOfWeekFormatter = new SimpleDateFormat(DAY_OF_WEEK_FORMAT, locale); mDayFormatter = NumberFormat.getIntegerInstance(locale); initPaints(res);/*from w w w .j a va2 s. c om*/ }
From source file:com.android.datetimepicker.time.RadialPickerLayout.java
private void installAccessibilityDelegate() { ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegateCompat() { /**/*from www . j a va 2 s .c om*/ * Necessary for accessibility, to ensure we support "scrolling" forward and backward * in the circle. */ @Override public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { super.onInitializeAccessibilityNodeInfo(host, info); info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD); info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD); } }); }
From source file:com.tr4android.support.extension.picker.time.AppCompatTimePickerDelegate.java
public AppCompatTimePickerDelegate(AppCompatTimePicker delegator, Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(delegator, context); // process style attributes final TypedArray a = mContext.obtainStyledAttributes(attrs, R.styleable.TimePickerDialog, defStyleAttr, defStyleRes);// w ww .ja v a2 s. c om final LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); final Resources res = mContext.getResources(); mSelectHours = res.getString(R.string.select_hours); mSelectMinutes = res.getString(R.string.select_minutes); String[] amPmStrings = getAmPmStrings(context); mAmText = amPmStrings[0]; mPmText = amPmStrings[1]; final View mainView = inflater.inflate(R.layout.time_picker_material, delegator); mHeaderView = mainView.findViewById(R.id.time_header); // Set up hour/minute labels. mHourView = (TextView) mainView.findViewById(R.id.hours); mHourView.setOnClickListener(mClickListener); ViewCompat.setAccessibilityDelegate(mHourView, new ClickActionDelegate(context, R.string.select_hours)); mSeparatorView = (TextView) mainView.findViewById(R.id.separator); mMinuteView = (TextView) mainView.findViewById(R.id.minutes); mMinuteView.setOnClickListener(mClickListener); ViewCompat.setAccessibilityDelegate(mMinuteView, new ClickActionDelegate(context, R.string.select_minutes)); // Now that we have text appearances out of the way, make sure the hour // and minute views are correctly sized. mHourView.setMinWidth(computeStableWidth(mHourView, 24)); mMinuteView.setMinWidth(computeStableWidth(mMinuteView, 60)); // Set up AM/PM labels. mAmPmLayout = mainView.findViewById(R.id.ampm_layout); mAmLabel = (CheckedTextView) mAmPmLayout.findViewById(R.id.am_label); mAmLabel.setText(obtainVerbatim(amPmStrings[0])); mAmLabel.setOnClickListener(mClickListener); mPmLabel = (CheckedTextView) mAmPmLayout.findViewById(R.id.pm_label); mPmLabel.setText(obtainVerbatim(amPmStrings[1])); mPmLabel.setOnClickListener(mClickListener); // Set up header text color, if available. ColorStateList headerTextColor; if (a.hasValue(R.styleable.TimePickerDialog_headerTextColor)) { headerTextColor = a.getColorStateList(R.styleable.DatePickerDialog_headerTextColor); } else { headerTextColor = PickerThemeUtils.getHeaderTextColorStateList(mContext); } mHourView.setTextColor(headerTextColor); mSeparatorView.setTextColor(headerTextColor); mMinuteView.setTextColor(headerTextColor); mAmLabel.setTextColor(headerTextColor); mPmLabel.setTextColor(headerTextColor); // Set up header background, if available. ViewCompatUtils.setBackground(mHeaderView, PickerThemeUtils.getHeaderBackground(mContext, a.getColor(R.styleable.DatePickerDialog_headerBackground, ThemeUtils.getThemeAttrColor(mContext, R.attr.colorAccent)))); a.recycle(); mRadialTimePickerView = (RadialTimePickerView) mainView.findViewById(R.id.radial_picker); setupListeners(); mAllowAutoAdvance = true; // Set up for keyboard mode. mDoublePlaceholderText = res.getString(R.string.time_placeholder); mDeletedKeyFormat = res.getString(R.string.deleted_key); mPlaceholderText = mDoublePlaceholderText.charAt(0); mAmKeyCode = mPmKeyCode = -1; generateLegalTimesTree(); // Initialize with current time final Calendar calendar = Calendar.getInstance(mCurrentLocale); final int currentHour = calendar.get(Calendar.HOUR_OF_DAY); final int currentMinute = calendar.get(Calendar.MINUTE); initialize(currentHour, currentMinute, false /* 12h */, HOUR_INDEX); }