Java Code Examples for androidx.core.view.ViewCompat#setAccessibilityDelegate()

The following examples show how to use androidx.core.view.ViewCompat#setAccessibilityDelegate() . 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 check out the related API usage on the sidebar.
Example 1
Source File: SimpleMonthView.java    From DateTimePicker with Apache License 2.0 6 votes vote down vote up
private void attrHandler(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    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);

    mLocale = res.getConfiguration().locale;
    mCalendar = Calendar.getInstance(mLocale);

    mDayFormatter = NumberFormat.getIntegerInstance(mLocale);

    updateMonthYearLabel();
    updateDayOfWeekLabels();

    initPaints(res);
}
 
Example 2
Source File: MaterialCalendarGridView.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
public MaterialCalendarGridView(Context context, AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);
  if (MaterialDatePicker.isFullscreen(getContext())) {
    setNextFocusLeftId(R.id.cancel_button);
    setNextFocusRightId(R.id.confirm_button);
  }
  ViewCompat.setAccessibilityDelegate(
      this,
      new AccessibilityDelegateCompat() {
        @Override
        public void onInitializeAccessibilityNodeInfo(
            View view, @NonNull AccessibilityNodeInfoCompat accessibilityNodeInfoCompat) {
          super.onInitializeAccessibilityNodeInfo(view, accessibilityNodeInfoCompat);
          // Stop announcing of row/col information in favor of internationalized day information.
          accessibilityNodeInfoCompat.setCollectionInfo(null);
        }
      });
}
 
Example 3
Source File: MaterialDatePicker.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private void initHeaderToggle(Context context) {
  headerToggleButton.setTag(TOGGLE_BUTTON_TAG);
  headerToggleButton.setImageDrawable(createHeaderToggleDrawable(context));
  headerToggleButton.setChecked(inputMode != INPUT_MODE_CALENDAR);

  // By default, CheckableImageButton adds a delegate that reads checked state.
  // This information is not useful; we remove the delegate and use custom content descriptions.
  ViewCompat.setAccessibilityDelegate(headerToggleButton, null);
  updateToggleContentDescription(headerToggleButton);
  headerToggleButton.setOnClickListener(
      new OnClickListener() {
        @Override
        public void onClick(View v) {
          // Update confirm button in case in progress selection has been reset
          confirmButton.setEnabled(dateSelector.isSelectionComplete());

          headerToggleButton.toggle();
          updateToggleContentDescription(headerToggleButton);
          startPickerFragment();
        }
      });
}
 
Example 4
Source File: MonthView.java    From cathode with Apache License 2.0 5 votes vote down vote up
public MonthView(Context context, AttributeSet attr) {
  super(context, attr);
  Resources res = context.getResources();

  mDayLabelCalendar = Calendar.getInstance();
  mCalendar = Calendar.getInstance();

  mDayOfWeekTypeface = res.getString(R.string.day_of_week_label_typeface);
  mMonthTitleTypeface = res.getString(R.string.sans_serif);

  mDayTextColor = res.getColor(R.color.date_picker_day);
  mTodayNumberColor = res.getColor(R.color.blue);
  mDisabledDayTextColor = res.getColor(R.color.date_picker_text_disabled);
  mMonthTitleColor = res.getColor(android.R.color.white);
  mMonthTitleBGColor = res.getColor(R.color.circle_background);
  mMonthDayLabelColor = res.getColor(R.color.date_picker_weekday);

  mStringBuilder = new StringBuilder(50);
  mFormatter = new Formatter(mStringBuilder, Locale.getDefault());

  MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.day_number_size);
  MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.month_label_size);
  MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.month_day_label_text_size);
  MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.month_list_item_header_height);
  DAY_SELECTED_CIRCLE_SIZE = res.getDimensionPixelSize(R.dimen.day_number_select_circle_radius);

  mRowHeight = (res.getDimensionPixelOffset(R.dimen.date_picker_view_animator_height)
      - getMonthHeaderSize()) / MAX_NUM_ROWS;

  // Set up accessibility components.
  mTouchHelper = getMonthViewTouchHelper();
  ViewCompat.setAccessibilityDelegate(this, mTouchHelper);
  ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
  mLockAccessibilityDelegate = true;

  // Sets up any standard paints that will be used
  initView();
}
 
Example 5
Source File: MountState.java    From litho with Apache License 2.0 5 votes vote down vote up
private static void unsetAccessibilityDelegate(View view) {
  if (!(view instanceof ComponentHost) && view.getTag(R.id.component_node_info) == null) {
    return;
  }
  view.setTag(R.id.component_node_info, null);
  if (!(view instanceof ComponentHost)) {
    ViewCompat.setAccessibilityDelegate(view, null);
  }
}
 
Example 6
Source File: ComponentHost.java    From litho with Apache License 2.0 5 votes vote down vote up
protected void refreshAccessibilityDelegatesIfNeeded(boolean isAccessibilityEnabled) {
  if (isAccessibilityEnabled == mIsComponentAccessibilityDelegateSet) {
    return;
  }

  if (isAccessibilityEnabled && mComponentAccessibilityDelegate == null) {
    mComponentAccessibilityDelegate =
        new ComponentAccessibilityDelegate(
            this, this.isFocusable(), ViewCompat.getImportantForAccessibility(this));
  }

  ViewCompat.setAccessibilityDelegate(
      this, isAccessibilityEnabled ? mComponentAccessibilityDelegate : null);
  mIsComponentAccessibilityDelegateSet = isAccessibilityEnabled;

  if (!isAccessibilityEnabled) {
    return;
  }

  for (int i = 0, size = getChildCount(); i < size; i++) {
    final View child = getChildAt(i);
    if (child instanceof ComponentHost) {
      ((ComponentHost) child).refreshAccessibilityDelegatesIfNeeded(true);
    } else {
      final NodeInfo nodeInfo = (NodeInfo) child.getTag(R.id.component_node_info);
      if (nodeInfo != null) {
        ViewCompat.setAccessibilityDelegate(
            child,
            new ComponentAccessibilityDelegate(
                child,
                nodeInfo,
                child.isFocusable(),
                ViewCompat.getImportantForAccessibility(child)));
      }
    }
  }
}
 
Example 7
Source File: VerticalViewPager.java    From DKVideoPlayer with Apache License 2.0 5 votes vote down vote up
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 = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mTopEdge = new EdgeEffectCompat(context);
    mBottomEdge = 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);
    }
}
 
Example 8
Source File: KeyboardAccessibilityDelegate.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 5 votes vote down vote up
public KeyboardAccessibilityDelegate(final KV keyboardView, final KeyDetector keyDetector) {
    super();
    mKeyboardView = keyboardView;
    mKeyDetector = keyDetector;

    // Ensure that the view has an accessibility delegate.
    ViewCompat.setAccessibilityDelegate(keyboardView, this);
}
 
Example 9
Source File: Chip.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
private void updateAccessibilityDelegate() {
  if (hasCloseIcon() && isCloseIconVisible() && onCloseIconClickListener != null) {
    ViewCompat.setAccessibilityDelegate(this, touchHelper);
  } else {
    // Avoid setting custom ExploreByTouchHelper if the trailing icon is only decorative.
    ViewCompat.setAccessibilityDelegate(this, null);
  }
}
 
Example 10
Source File: NavigationMenuItemView.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
public NavigationMenuItemView(
    @NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
  super(context, attrs, defStyleAttr);
  setOrientation(HORIZONTAL);
  LayoutInflater.from(context).inflate(R.layout.design_navigation_menu_item, this, true);
  setIconSize(context.getResources().getDimensionPixelSize(R.dimen.design_navigation_icon_size));
  textView = findViewById(R.id.design_menu_item_text);
  textView.setDuplicateParentStateEnabled(true);
  ViewCompat.setAccessibilityDelegate(textView, accessibilityDelegate);
}
 
Example 11
Source File: BaseSlider.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
public BaseSlider(
    @NonNull Context context, @Nullable final AttributeSet attrs, final int defStyleAttr) {
  super(wrap(context, attrs, defStyleAttr, DEF_STYLE_RES), attrs, defStyleAttr);
  // Ensure we are using the correctly themed context rather than the context that was passed in.
  context = getContext();

  inactiveTrackPaint = new Paint();
  inactiveTrackPaint.setStyle(Style.STROKE);
  inactiveTrackPaint.setStrokeCap(Cap.ROUND);

  activeTrackPaint = new Paint();
  activeTrackPaint.setStyle(Style.STROKE);
  activeTrackPaint.setStrokeCap(Cap.ROUND);

  thumbPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  thumbPaint.setStyle(Style.FILL);
  thumbPaint.setXfermode(new PorterDuffXfermode(Mode.CLEAR));

  haloPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
  haloPaint.setStyle(Style.FILL);

  inactiveTicksPaint = new Paint();
  inactiveTicksPaint.setStyle(Style.STROKE);
  inactiveTicksPaint.setStrokeCap(Cap.ROUND);

  activeTicksPaint = new Paint();
  activeTicksPaint.setStyle(Style.STROKE);
  activeTicksPaint.setStrokeCap(Cap.ROUND);

  loadResources(context.getResources());

  // Because there's currently no way to copy the TooltipDrawable we use this to make more if more
  // thumbs are added.
  labelMaker =
      new TooltipDrawableFactory() {
        @Override
        public TooltipDrawable createTooltipDrawable() {
          final TypedArray a =
              ThemeEnforcement.obtainStyledAttributes(
                  getContext(), attrs, R.styleable.Slider, defStyleAttr, DEF_STYLE_RES);
          TooltipDrawable d = parseLabelDrawable(getContext(), a);
          a.recycle();
          return d;
        }
      };

  processAttributes(context, attrs, defStyleAttr);

  setFocusable(true);
  setClickable(true);

  // Set up the thumb drawable to always show the compat shadow.
  thumbDrawable.setShadowCompatibilityMode(MaterialShapeDrawable.SHADOW_COMPAT_MODE_ALWAYS);

  scaledTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();

  accessibilityHelper = new AccessibilityHelper(this);
  ViewCompat.setAccessibilityDelegate(this, accessibilityHelper);

  accessibilityManager =
      (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
}
 
Example 12
Source File: MonthView.java    From MaterialDateRangePicker with Apache License 2.0 4 votes vote down vote up
public MonthView(Context context, AttributeSet attr, DatePickerController controller) {
    super(context, attr);
    mController = controller;
    Resources res = context.getResources();

    mDayLabelCalendar = Calendar.getInstance();
    mCalendar = Calendar.getInstance();

    mDayOfWeekTypeface = res.getString(R.string.range_day_of_week_label_typeface);
    mMonthTitleTypeface = res.getString(R.string.range_sans_serif);

    boolean darkTheme = mController != null && mController.isThemeDark();
    if(darkTheme) {
        mDayTextColor = res.getColor(R.color.range_date_picker_text_normal_dark_theme);
        mMonthDayTextColor = res.getColor(R.color.range_date_picker_month_day_dark_theme);
        mDisabledDayTextColor = res.getColor(R.color.range_date_picker_text_disabled_dark_theme);
        mHighlightedDayTextColor = res.getColor(R.color.range_date_picker_text_highlighted_dark_theme);
    }
    else {
        mDayTextColor = res.getColor(R.color.range_date_picker_text_normal);
        mMonthDayTextColor = res.getColor(R.color.range_date_picker_month_day);
        mDisabledDayTextColor = res.getColor(R.color.range_date_picker_text_disabled);
        mHighlightedDayTextColor = res.getColor(R.color.range_date_picker_text_highlighted);
    }
    mSelectedDayTextColor = res.getColor(R.color.range_white);
    mTodayNumberColor = res.getColor(R.color.range_accent_color);
    mMonthTitleColor = res.getColor(R.color.range_white);

    mStringBuilder = new StringBuilder(50);
    mFormatter = new Formatter(mStringBuilder, Locale.getDefault());

    MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.range_day_number_size);
    MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.range_month_label_size);
    MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.range_month_day_label_text_size);
    MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.range_month_list_item_header_height);
    DAY_SELECTED_CIRCLE_SIZE = res
            .getDimensionPixelSize(R.dimen.range_day_number_select_circle_radius);

    mRowHeight = (res.getDimensionPixelOffset(R.dimen.range_date_picker_view_animator_height)
            - getMonthHeaderSize()) / MAX_NUM_ROWS;

    // Set up accessibility components.
    mTouchHelper = getMonthViewTouchHelper();
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    mLockAccessibilityDelegate = true;

    // Sets up any standard paints that will be used
    initView();
}
 
Example 13
Source File: MonthView.java    From MaterialDateTimePicker with Apache License 2.0 4 votes vote down vote up
public MonthView(Context context, AttributeSet attr, DatePickerController controller) {
    super(context, attr);
    mController = controller;
    Resources res = context.getResources();

    mDayLabelCalendar = Calendar.getInstance(mController.getTimeZone(), mController.getLocale());
    mCalendar = Calendar.getInstance(mController.getTimeZone(), mController.getLocale());

    mDayOfWeekTypeface = res.getString(R.string.mdtp_day_of_week_label_typeface);
    mMonthTitleTypeface = res.getString(R.string.mdtp_sans_serif);

    boolean darkTheme = mController != null && mController.isThemeDark();
    if (darkTheme) {
        mDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_normal_dark_theme);
        mMonthDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_month_day_dark_theme);
        mDisabledDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_disabled_dark_theme);
        mHighlightedDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_highlighted_dark_theme);
    } else {
        mDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_normal);
        mMonthDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_month_day);
        mDisabledDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_disabled);
        mHighlightedDayTextColor = ContextCompat.getColor(context, R.color.mdtp_date_picker_text_highlighted);
    }
    mSelectedDayTextColor = ContextCompat.getColor(context, R.color.mdtp_white);
    mTodayNumberColor = mController.getAccentColor();
    mMonthTitleColor = ContextCompat.getColor(context, R.color.mdtp_white);

    mStringBuilder = new StringBuilder(50);

    MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_day_number_size);
    MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_month_label_size);
    MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_month_day_label_text_size);
    MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.mdtp_month_list_item_header_height);
    MONTH_HEADER_SIZE_V2 = res.getDimensionPixelOffset(R.dimen.mdtp_month_list_item_header_height_v2);
    DAY_SELECTED_CIRCLE_SIZE = mController.getVersion() == DatePickerDialog.Version.VERSION_1
            ? res.getDimensionPixelSize(R.dimen.mdtp_day_number_select_circle_radius)
            : res.getDimensionPixelSize(R.dimen.mdtp_day_number_select_circle_radius_v2);
    DAY_HIGHLIGHT_CIRCLE_SIZE = res
            .getDimensionPixelSize(R.dimen.mdtp_day_highlight_circle_radius);
    DAY_HIGHLIGHT_CIRCLE_MARGIN = res
            .getDimensionPixelSize(R.dimen.mdtp_day_highlight_circle_margin);

    if (mController.getVersion() == DatePickerDialog.Version.VERSION_1) {
        mRowHeight = (res.getDimensionPixelOffset(R.dimen.mdtp_date_picker_view_animator_height)
                - getMonthHeaderSize()) / MAX_NUM_ROWS;
    } else {
        mRowHeight = (res.getDimensionPixelOffset(R.dimen.mdtp_date_picker_view_animator_height_v2)
                - getMonthHeaderSize() - MONTH_DAY_LABEL_TEXT_SIZE * 2) / MAX_NUM_ROWS;
    }

    mEdgePadding = mController.getVersion() == DatePickerDialog.Version.VERSION_1
            ? 0
            : context.getResources().getDimensionPixelSize(R.dimen.mdtp_date_picker_view_animator_padding_v2);

    // Set up accessibility components.
    mTouchHelper = getMonthViewTouchHelper();
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    mLockAccessibilityDelegate = true;

    // Sets up any standard paints that will be used
    initView();
}
 
Example 14
Source File: MaterialButtonToggleGroup.java    From material-components-android with Apache License 2.0 4 votes vote down vote up
/**
 * This override prohibits Views other than {@link MaterialButton} to be added. It also makes
 * updates to the add button shape and margins.
 */
@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
  if (!(child instanceof MaterialButton)) {
    Log.e(LOG_TAG, "Child views must be of type MaterialButton.");
    return;
  }

  super.addView(child, index, params);
  MaterialButton buttonChild = (MaterialButton) child;
  setGeneratedIdIfNeeded(buttonChild);
  // Sets sensible default values and an internal checked change listener for this child
  setupButtonChild(buttonChild);

  // Reorders children if a checked child was added to this layout
  if (buttonChild.isChecked()) {
    updateCheckedStates(buttonChild.getId(), true);
    setCheckedId(buttonChild.getId());
  }

  // Saves original corner data
  ShapeAppearanceModel shapeAppearanceModel = buttonChild.getShapeAppearanceModel();
  originalCornerData.add(
      new CornerData(
          shapeAppearanceModel.getTopLeftCornerSize(),
          shapeAppearanceModel.getBottomLeftCornerSize(),
          shapeAppearanceModel.getTopRightCornerSize(),
          shapeAppearanceModel.getBottomRightCornerSize()));

  ViewCompat.setAccessibilityDelegate(
      buttonChild,
      new AccessibilityDelegateCompat() {
        @Override
        public void onInitializeAccessibilityNodeInfo(
            View host, @NonNull AccessibilityNodeInfoCompat info) {
          super.onInitializeAccessibilityNodeInfo(host, info);
          info.setCollectionItemInfo(
              CollectionItemInfoCompat.obtain(
                  /* rowIndex= */ 0,
                  /* rowSpan= */ 1,
                  /* columnIndex= */ getIndexWithinVisibleButtons(host),
                  /* columnSpan= */ 1,
                  /* heading= */ false,
                  /* selected= */ ((MaterialButton) host).isChecked()));
        }
      });
}
 
Example 15
Source File: SliderPager.java    From Android-Image-Slider with Apache License 2.0 4 votes vote down vote up
void initSliderPager() {
    setWillNotDraw(false);
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    final Context context = getContext();
    mScroller = new OwnScroller(context, DEFAULT_SCROLL_DURATION, 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 EdgeEffect(context);
    mRightEdge = new EdgeEffect(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 androidx.core.view.OnApplyWindowInsetsListener() {
                private final Rect mTempRect = new Rect();

                @Override
                public WindowInsetsCompat onApplyWindowInsets(final View v,
                                                              final WindowInsetsCompat originalInsets) {
                    // First let the SliderPager itself try and consume them...
                    final WindowInsetsCompat applied =
                            ViewCompat.onApplyWindowInsets(v, originalInsets);
                    if (applied.isConsumed()) {
                        // If the SliderPager consumed all insets, return now
                        return applied;
                    }

                    // Now we'll manually dispatch the insets to our children. Since SliderPager
                    // 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);
                }
            });
}
 
Example 16
Source File: NestedScrollView.java    From AndroidAnimationExercise with Apache License 2.0 4 votes vote down vote up
public NestedScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    initScrollView();

    final TypedArray a = context.obtainStyledAttributes(
            attrs, SCROLLVIEW_STYLEABLE, defStyleAttr, 0);

    setFillViewport(a.getBoolean(0, false));

    a.recycle();

    mParentHelper = new NestedScrollingParentHelper(this);
    mChildHelper = new NestedScrollingChildHelper(this);

    // ...because why else would you be using this widget?
    setNestedScrollingEnabled(true);

    ViewCompat.setAccessibilityDelegate(this, ACCESSIBILITY_DELEGATE);
}
 
Example 17
Source File: CustomViewPager.java    From AsteroidOSSync with GNU General Public License v3.0 4 votes vote down vote up
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 androidx.core.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);
                }
            });
}
 
Example 18
Source File: RadialTimePickerView.java    From DateTimePicker with Apache License 2.0 4 votes vote down vote up
public RadialTimePickerView(
        Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)  {
    super(context, attrs);

    applyAttributes(attrs, defStyleAttr, defStyleRes);

    // Pull disabled alpha from theme.
    final TypedValue outValue = new TypedValue();
    context.getTheme().resolveAttribute(android.R.attr.disabledAlpha, outValue, true);
    mDisabledAlpha = outValue.getFloat();

    mTypeface = Typeface.create("sans-serif", Typeface.NORMAL);

    mPaint[HOURS] = new Paint();
    mPaint[HOURS].setAntiAlias(true);
    mPaint[HOURS].setTextAlign(Paint.Align.CENTER);

    mPaint[MINUTES] = new Paint();
    mPaint[MINUTES].setAntiAlias(true);
    mPaint[MINUTES].setTextAlign(Paint.Align.CENTER);

    mPaintCenter.setAntiAlias(true);

    mPaintSelector[SELECTOR_CIRCLE] = new Paint();
    mPaintSelector[SELECTOR_CIRCLE].setAntiAlias(true);

    mPaintSelector[SELECTOR_DOT] = new Paint();
    mPaintSelector[SELECTOR_DOT].setAntiAlias(true);

    mPaintSelector[SELECTOR_LINE] = new Paint();
    mPaintSelector[SELECTOR_LINE].setAntiAlias(true);
    mPaintSelector[SELECTOR_LINE].setStrokeWidth(2);

    mPaintBackground.setAntiAlias(true);

    final Resources res = getResources();
    mSelectorRadius = res.getDimensionPixelSize(R.dimen.timepicker_selector_radius);
    mSelectorStroke = res.getDimensionPixelSize(R.dimen.timepicker_selector_stroke);
    mSelectorDotRadius = res.getDimensionPixelSize(R.dimen.timepicker_selector_dot_radius);
    mCenterDotRadius = res.getDimensionPixelSize(R.dimen.timepicker_center_dot_radius);

    mTextSize[HOURS] = res.getDimensionPixelSize(R.dimen.timepicker_text_size_normal);
    mTextSize[MINUTES] = res.getDimensionPixelSize(R.dimen.timepicker_text_size_normal);
    mTextSize[HOURS_INNER] = res.getDimensionPixelSize(R.dimen.timepicker_text_size_inner);

    mTextInset[HOURS] = res.getDimensionPixelSize(R.dimen.timepicker_text_inset_normal);
    mTextInset[MINUTES] = res.getDimensionPixelSize(R.dimen.timepicker_text_inset_normal);
    mTextInset[HOURS_INNER] = res.getDimensionPixelSize(R.dimen.timepicker_text_inset_inner);

    mShowHours = true;
    mHoursToMinutes = HOURS;
    mIs24HourMode = false;
    mAmOrPm = AM;

    // Set up accessibility components.
    mTouchHelper = new RadialPickerTouchHelper();
    ViewCompat.setAccessibilityDelegate(this, mTouchHelper);
    //setAccessibilityDelegate(mTouchHelper);

    if(ViewCompat.getImportantForAccessibility(this) == ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_AUTO){
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    }
    /*if (getImportantForAccessibility() == IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
    }*/

    initHoursAndMinutesText();
    initData();

    // Initial values
    final Calendar calendar = Calendar.getInstance(Locale.getDefault());
    final int currentHour = calendar.get(Calendar.HOUR_OF_DAY);
    final int currentMinute = calendar.get(Calendar.MINUTE);

    setCurrentHourInternal(currentHour, false, false);
    setCurrentMinuteInternal(currentMinute, false);

    setHapticFeedbackEnabled(true);
}
 
Example 19
Source File: MonthView.java    From PersianDateRangePicker with Apache License 2.0 4 votes vote down vote up
public MonthView(Context context, AttributeSet attr, DatePickerController controller) {
  super(context, attr);
  mController = controller;
  Resources res = context.getResources();

  mDayLabelCalendar = new PersianDate();
  mPersianDate = new PersianDate();

  mDayOfWeekTypeface = res.getString(R.string.mdtp_day_of_week_label_typeface);
  mMonthTitleTypeface = res.getString(R.string.mdtp_sans_serif);

  boolean darkTheme = mController != null && mController.isThemeDark();
  if (darkTheme) {
    mDayTextColor = res.getColor(R.color.mdtp_date_picker_text_normal_dark_theme);
    mMonthDayTextColor = res.getColor(R.color.mdtp_date_picker_month_day_dark_theme);
    mDisabledDayTextColor = res.getColor(R.color.mdtp_date_picker_text_disabled_dark_theme);
    mHighlightedDayTextColor = res.getColor(R.color.mdtp_date_picker_text_highlighted_dark_theme);
  } else {
    mDayTextColor = res.getColor(R.color.mdtp_date_picker_text_normal);
    mMonthDayTextColor = res.getColor(R.color.mdtp_date_picker_month_day);
    mDisabledDayTextColor = res.getColor(R.color.mdtp_date_picker_text_disabled);
    mHighlightedDayTextColor = res.getColor(R.color.mdtp_date_picker_text_highlighted);
  }
  mSelectedDayTextColor = res.getColor(R.color.mdtp_white);
  mTodayNumberColor = res.getColor(R.color.mdtp_accent_color);
  mMonthTitleColor = res.getColor(R.color.mdtp_white);

  mStringBuilder = new StringBuilder(50);

  MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_day_number_size);
  MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_month_label_size);
  MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.mdtp_month_day_label_text_size);
  MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.mdtp_month_list_item_header_height);
  DAY_SELECTED_CIRCLE_SIZE = res
    .getDimensionPixelSize(R.dimen.mdtp_day_number_select_circle_radius);

  mRowHeight = (res.getDimensionPixelOffset(R.dimen.mdtp_date_picker_view_animator_height)
    - getMonthHeaderSize()) / MAX_NUM_ROWS;

  // Set up accessibility components.
  mTouchHelper = getMonthViewTouchHelper();
  ViewCompat.setAccessibilityDelegate(this, mTouchHelper);
  ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
  mLockAccessibilityDelegate = true;

  // Sets up any standard paints that will be used
  initView();
}
 
Example 20
Source File: TextInputLayout.java    From material-components-android with Apache License 2.0 3 votes vote down vote up
/**
 * Sets an {@link TextInputLayout.AccessibilityDelegate} providing an accessibility implementation
 * for the {@link EditText} used by this layout.
 *
 * <p>Note: This method should be used in place of providing an {@link AccessibilityDelegate}
 * directly on the {@link EditText}.
 */
public void setTextInputAccessibilityDelegate(
    @Nullable TextInputLayout.AccessibilityDelegate delegate) {
  if (editText != null) {
    ViewCompat.setAccessibilityDelegate(editText, delegate);
  }
}