List of usage examples for android.support.v4.view ViewCompat setAccessibilityDelegate
public static void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate)
From source file:com.av.remusic.widget.RoundViewPager.java
void initViewPager() { setWillNotDraw(false);// www . j av a2 s .co m setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); setFocusable(true); final Context context = getContext(); mScroller = new Scroller(context, sInterpolator); final ViewConfiguration configuration = ViewConfiguration.get(context); final float density = context.getResources().getDisplayMetrics().density; mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); mLeftEdge = new EdgeEffectCompat(context); mRightEdge = new EdgeEffectCompat(context); mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density); mCloseEnough = (int) (CLOSE_ENOUGH * density); mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density); ViewCompat.setAccessibilityDelegate(this, new MyAccessibilityDelegate()); if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); } ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() { private final Rect mTempRect = new Rect(); @Override public WindowInsetsCompat onApplyWindowInsets(final View v, final WindowInsetsCompat originalInsets) { // First let the ViewPager itself try and consume them... final WindowInsetsCompat applied = ViewCompat.onApplyWindowInsets(v, originalInsets); if (applied.isConsumed()) { // If the ViewPager consumed all insets, return now return applied; } // Now we'll manually dispatch the insets to our children. Since ViewPager // children are always full-height, we do not want to use the standard // ViewGroup dispatchApplyWindowInsets since if child 0 consumes them, // the rest of the children will not receive any insets. To workaround this // we manually dispatch the applied insets, not allowing children to // consume them from each other. We do however keep track of any insets // which are consumed, returning the union of our children's consumption final Rect res = mTempRect; res.left = applied.getSystemWindowInsetLeft(); res.top = applied.getSystemWindowInsetTop(); res.right = applied.getSystemWindowInsetRight(); res.bottom = applied.getSystemWindowInsetBottom(); for (int i = 0, count = getChildCount(); i < count; i++) { final WindowInsetsCompat childInsets = ViewCompat.dispatchApplyWindowInsets(getChildAt(i), applied); // Now keep track of any consumed by tracking each dimension's min // value res.left = Math.min(childInsets.getSystemWindowInsetLeft(), res.left); res.top = Math.min(childInsets.getSystemWindowInsetTop(), res.top); res.right = Math.min(childInsets.getSystemWindowInsetRight(), res.right); res.bottom = Math.min(childInsets.getSystemWindowInsetBottom(), res.bottom); } // Now return a new WindowInsets, using the consumed window insets return applied.replaceSystemWindowInsets(res.left, res.top, res.right, res.bottom); } }); isRotating = false; }
From source file:com.example.myronlg.cardviewpagerdemo.MultiCardViewPager.java
void initViewPager() { getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() { @TargetApi(Build.VERSION_CODES.JELLY_BEAN) @Override//from w w w .j a v a2 s . c o m public void onGlobalLayout() { itemScrollOffset = (int) (getClientWidth() * mAdapter.getPageWidth(0)); // int maxScrollX = (int) (2*getClientWidth()*mAdapter.getPageWidth(0) + (mAdapter.getCount() - 2) * getClientWidth() * mAdapter.getPageWidth(1) - getWidth() + getClientWidth()*0.5F); maxScrollX = (int) (getClientWidth() * (2 * mAdapter.getPageWidth(0) + (mAdapter.getCount() - 2) * mAdapter.getPageWidth(1) - 1 + 0.0F)); minScrollX = (int) (-getClientWidth() * 0.0F); // itemScrollOffset = 0; getViewTreeObserver().removeOnGlobalLayoutListener(this); } }); setWillNotDraw(false); setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); setFocusable(true); final Context context = getContext(); mScroller = new Scroller(context, sInterpolator); myScroller = new Scroller(context, new AccelerateInterpolator()); final ViewConfiguration configuration = ViewConfiguration.get(context); final float density = context.getResources().getDisplayMetrics().density; mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration); mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); mLeftEdge = new EdgeEffectCompat(context); mRightEdge = new EdgeEffectCompat(context); mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density); mCloseEnough = (int) (CLOSE_ENOUGH * density); mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density); ViewCompat.setAccessibilityDelegate(this, new MyAccessibilityDelegate()); if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); } }
From source file:com.zyk.drawerlayout.widget.DrawerLayout.java
public DrawerLayout(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS); density = getResources().getDisplayMetrics().density; mMinDrawerMarginWidth = (int) (MIN_DRAWER_MARGIN * density + 0.5f); //FIXME ????// w ww .j a va 2 s. c om mMinDrawerMarginHeight = mMinDrawerMarginWidth; final float minVel = MIN_FLING_VELOCITY * density; mLeftCallback = new ViewDragCallback(Gravity.LEFT); mRightCallback = new ViewDragCallback(Gravity.RIGHT); mTopCallback = new ViewDragCallback(Gravity.TOP); mBottomCallback = new ViewDragCallback(Gravity.BOTTOM); mLeftDragger = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mLeftCallback); mLeftDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_LEFT); mLeftDragger.setMinVelocity(minVel); mLeftCallback.setDragger(mLeftDragger); mRightDragger = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mRightCallback); mRightDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_RIGHT); mRightDragger.setMinVelocity(minVel); mRightCallback.setDragger(mRightDragger); mTopDragger = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mTopCallback); mTopDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_TOP); mTopDragger.setMinVelocity(minVel); mTopCallback.setDragger(mTopDragger); mBottomDragger = ViewDragHelper.create(this, TOUCH_SLOP_SENSITIVITY, mBottomCallback); mBottomDragger.setEdgeTrackingEnabled(ViewDragHelper.EDGE_BOTTOM); mBottomDragger.setMinVelocity(minVel); mBottomCallback.setDragger(mBottomDragger); // 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); if (ViewCompat.getFitsSystemWindows(this)) { IMPL.configureApplyInsets(this); mStatusBarBackground = IMPL.getDefaultStatusBarBackground(context); } mDrawerElevation = DRAWER_ELEVATION * density; mNonDrawerViews = new ArrayList<View>(); }
From source file:com.example.sky.test.view.ViewPager.java
void initViewPager() { setWillNotDraw(false);/*from w ww .j a v a2 s. co m*/ setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); setFocusable(true); final Context context = getContext(); mScroller = new Scroller(context, sInterpolator); final ViewConfiguration configuration = ViewConfiguration.get(context); final float density = context.getResources().getDisplayMetrics().density; mTouchSlop = configuration.getScaledPagingTouchSlop(); mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); mLeftEdge = new EdgeEffectCompat(context); mRightEdge = new EdgeEffectCompat(context); mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density); mCloseEnough = (int) (CLOSE_ENOUGH * density); mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density); ViewCompat.setAccessibilityDelegate(this, new ViewPager.MyAccessibilityDelegate()); if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); } ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() { private final Rect mTempRect = new Rect(); @Override public WindowInsetsCompat onApplyWindowInsets(final View v, final WindowInsetsCompat originalInsets) { // First let the ViewPager itself try and consume them... final WindowInsetsCompat applied = ViewCompat.onApplyWindowInsets(v, originalInsets); if (applied.isConsumed()) { // If the ViewPager consumed all insets, return now return applied; } // Now we'll manually dispatch the insets to our children. Since ViewPager // children are always full-height, we do not want to use the standard // ViewGroup dispatchApplyWindowInsets since if child 0 consumes them, // the rest of the children will not receive any insets. To workaround this // we manually dispatch the applied insets, not allowing children to // consume them from each other. We do however keep track of any insets // which are consumed, returning the union of our children's consumption final Rect res = mTempRect; res.left = applied.getSystemWindowInsetLeft(); res.top = applied.getSystemWindowInsetTop(); res.right = applied.getSystemWindowInsetRight(); res.bottom = applied.getSystemWindowInsetBottom(); for (int i = 0, count = getChildCount(); i < count; i++) { final WindowInsetsCompat childInsets = ViewCompat.dispatchApplyWindowInsets(getChildAt(i), applied); // Now keep track of any consumed by tracking each dimension's min // value res.left = Math.min(childInsets.getSystemWindowInsetLeft(), res.left); res.top = Math.min(childInsets.getSystemWindowInsetTop(), res.top); res.right = Math.min(childInsets.getSystemWindowInsetRight(), res.right); res.bottom = Math.min(childInsets.getSystemWindowInsetBottom(), res.bottom); } // Now return a new WindowInsets, using the consumed window insets return applied.replaceSystemWindowInsets(res.left, res.top, res.right, res.bottom); } }); }
From source file:example.luojing.androidsourceanalysis.ViewPager.java
/** * ??/* ww w. ja v a2 s. c om*/ */ void initViewPager() { setWillNotDraw(false); setDescendantFocusability(FOCUS_AFTER_DESCENDANTS); setFocusable(true); final Context context = getContext(); mScroller = new Scroller(context, sInterpolator); final ViewConfiguration configuration = ViewConfiguration.get(context); final float density = context.getResources().getDisplayMetrics().density; mTouchSlop = configuration.getScaledPagingTouchSlop(); mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density); mMaximumVelocity = configuration.getScaledMaximumFlingVelocity(); mLeftEdge = new EdgeEffectCompat(context); mRightEdge = new EdgeEffectCompat(context); mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density); mCloseEnough = (int) (CLOSE_ENOUGH * density); mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density); ViewCompat.setAccessibilityDelegate(this, new MyAccessibilityDelegate()); if (ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO) { ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); } ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() { private final Rect mTempRect = new Rect(); @Override public WindowInsetsCompat onApplyWindowInsets(final View v, final WindowInsetsCompat originalInsets) { // First let the ViewPager itself try and consume them... final WindowInsetsCompat applied = ViewCompat.onApplyWindowInsets(v, originalInsets); if (applied.isConsumed()) { // If the ViewPager consumed all insets, return now return applied; } // Now we'll manually dispatch the insets to our children. Since ViewPager // children are always full-height, we do not want to use the standard // ViewGroup dispatchApplyWindowInsets since if child 0 consumes them, // the rest of the children will not receive any insets. To workaround this // we manually dispatch the applied insets, not allowing children to // consume them from each other. We do however keep track of any insets // which are consumed, returning the union of our children's consumption final Rect res = mTempRect; res.left = applied.getSystemWindowInsetLeft(); res.top = applied.getSystemWindowInsetTop(); res.right = applied.getSystemWindowInsetRight(); res.bottom = applied.getSystemWindowInsetBottom(); for (int i = 0, count = getChildCount(); i < count; i++) { final WindowInsetsCompat childInsets = ViewCompat.dispatchApplyWindowInsets(getChildAt(i), applied); // Now keep track of any consumed by tracking each dimension's min // value res.left = Math.min(childInsets.getSystemWindowInsetLeft(), res.left); res.top = Math.min(childInsets.getSystemWindowInsetTop(), res.top); res.right = Math.min(childInsets.getSystemWindowInsetRight(), res.right); res.bottom = Math.min(childInsets.getSystemWindowInsetBottom(), res.bottom); } // Now return a new WindowInsets, using the consumed window insets return applied.replaceSystemWindowInsets(res.left, res.top, res.right, res.bottom); } }); }
From source file:android.support.v7.widget.RecyclerViewEx.java
/** * Sets the accessibility delegate compatibility implementation used by RecyclerViewEx. * @param accessibilityDelegate The accessibility delegate to be used by RecyclerViewEx. *///from w w w . ja v a 2 s. c o m public void setAccessibilityDelegateCompat(RecyclerViewAccessibilityDelegateEx accessibilityDelegate) { mAccessibilityDelegate = accessibilityDelegate; ViewCompat.setAccessibilityDelegate(this, mAccessibilityDelegate); }
From source file:com.facebook.litho.ComponentHost.java
protected void refreshAccessibilityDelegatesIfNeeded(boolean isAccessibilityEnabled) { if (isAccessibilityEnabled == mIsComponentAccessibilityDelegateSet) { return;//from www . j av a 2 s .c om } ViewCompat.setAccessibilityDelegate(this, isAccessibilityEnabled ? mComponentAccessibilityDelegate : null); mIsComponentAccessibilityDelegateSet = isAccessibilityEnabled; for (int i = 0, size = getChildCount(); i < size; i++) { final View child = getChildAt(i); if (child instanceof ComponentHost) { ((ComponentHost) child).refreshAccessibilityDelegatesIfNeeded(isAccessibilityEnabled); } else { final NodeInfo nodeInfo = (NodeInfo) child.getTag(R.id.component_node_info); if (nodeInfo != null) { ViewCompat.setAccessibilityDelegate(child, isAccessibilityEnabled ? new ComponentAccessibilityDelegate(child, nodeInfo) : null); } } } }
From source file:cn.ismartv.recyclerview.widget.RecyclerView.java
/** * Sets the accessibility delegate compatibility implementation used by RecyclerView. * @param accessibilityDelegate The accessibility delegate to be used by RecyclerView. *///from ww w . j a v a2 s. c o m public void setAccessibilityDelegateCompat(RecyclerViewAccessibilityDelegate accessibilityDelegate) { mAccessibilityDelegate = accessibilityDelegate; ViewCompat.setAccessibilityDelegate(this, mAccessibilityDelegate); }
From source file:com.redinput.datetimepickercompat.time.RadialPickerLayout.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// w w w . j av a2 s . com public void onInitializeAccessibilityNodeInfo(View host, AccessibilityNodeInfoCompat info) { super.onInitializeAccessibilityNodeInfo(host, info); // 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. info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD); info.addAction(AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD); } @Override public boolean dispatchPopulateAccessibilityEvent(View host, AccessibilityEvent event) { if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { // Clear the event's current text so that only the current time will be spoken. event.getText().clear(); Time time = new Time(); time.hour = getHours(); time.minute = getMinutes(); long millis = time.normalize(true); int flags = DateUtils.FORMAT_SHOW_TIME; if (mIs24HourMode) { flags |= DateUtils.FORMAT_24HOUR; } String timeString = DateUtils.formatDateTime(getContext(), millis, flags); event.getText().add(timeString); return true; } return super.dispatchPopulateAccessibilityEvent(host, event); } @Override public boolean performAccessibilityAction(View host, int action, Bundle args) { if (super.performAccessibilityAction(host, action, args)) { return true; } int changeMultiplier = 0; if (action == AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD) { changeMultiplier = 1; } else if (action == AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD) { changeMultiplier = -1; } if (changeMultiplier != 0) { int value = getCurrentlyShowingValue(); int stepSize = 0; int currentItemShowing = getCurrentItemShowing(); if (currentItemShowing == HOUR_INDEX) { stepSize = HOUR_VALUE_TO_DEGREES_STEP_SIZE; value %= 12; } else if (currentItemShowing == MINUTE_INDEX) { stepSize = MINUTE_VALUE_TO_DEGREES_STEP_SIZE; } int degrees = value * stepSize; degrees = snapOnly30s(degrees, changeMultiplier); value = degrees / stepSize; int maxValue = 0; int minValue = 0; if (currentItemShowing == HOUR_INDEX) { if (mIs24HourMode) { maxValue = 23; } else { maxValue = 12; minValue = 1; } } else { maxValue = 55; } if (value > maxValue) { // If we scrolled forward past the highest number, wrap around to the // lowest. value = minValue; } else if (value < minValue) { // If we scrolled backward past the lowest number, wrap around to the // highest. value = maxValue; } setItem(currentItemShowing, value); mListener.onValueSelected(currentItemShowing, value, false); return true; } return false; } }); }
From source file:android.support.v71.widget.RecyclerView.java
/** * Sets the accessibility delegate compatibility implementation used by RecyclerView. * * @param accessibilityDelegate The accessibility delegate to be used by RecyclerView. *//*w w w . ja v a 2 s. c o m*/ public void setAccessibilityDelegateCompat( android.support.v71.widget.RecyclerViewAccessibilityDelegate accessibilityDelegate) { mAccessibilityDelegate = accessibilityDelegate; ViewCompat.setAccessibilityDelegate(this, mAccessibilityDelegate); }