Example usage for android.support.v4.view ViewCompat setAccessibilityDelegate

List of usage examples for android.support.v4.view ViewCompat setAccessibilityDelegate

Introduction

In this page you can find the example usage for android.support.v4.view ViewCompat setAccessibilityDelegate.

Prototype

public static void setAccessibilityDelegate(View v, AccessibilityDelegateCompat delegate) 

Source Link

Document

Sets a delegate for implementing accessibility support via compositon as opposed to inheritance.

Usage

From source file:com.ylw.split.splitview.view.SplitView.java

public SplitView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    final float density = context.getResources().getDisplayMetrics().density;
    mOverhangSize = (int) (DEFAULT_OVERHANG_SIZE * density + 0.5f);

    final ViewConfiguration viewConfig = ViewConfiguration.get(context);

    setWillNotDraw(false);//from w w w  . ja  v a 2s  .  c  om

    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegate());
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);

    mDragHelper = ViewDragHelper.create(this, 0.5f, new DragHelperCallback());
    mDragHelper.setMinVelocity(MIN_FLING_VELOCITY * density);
}

From source file:io.doist.datetimepicker.date.SimpleMonthView.java

public SimpleMonthView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    final Resources res = context.getResources();
    mDayOfWeekTypeface = res.getString(R.string.day_of_week_label_typeface);
    mMonthTitleTypeface = res.getString(R.string.sans_serif);

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

    mMiniDayNumberTextSize = res.getDimensionPixelSize(R.dimen.datepicker_day_number_size);
    mMonthLabelTextSize = res.getDimensionPixelSize(R.dimen.datepicker_month_label_size);
    mMonthDayLabelTextSize = res.getDimensionPixelSize(R.dimen.datepicker_month_day_label_text_size);
    mMonthHeaderSize = res.getDimensionPixelOffset(R.dimen.datepicker_month_list_item_header_height);
    mDaySelectedCircleSize = res.getDimensionPixelSize(R.dimen.datepicker_day_number_select_circle_radius);

    mRowHeight = (res.getDimensionPixelOffset(R.dimen.datepicker_view_animator_height) - mMonthHeaderSize)
            / MAX_NUM_ROWS;/*  w w  w  .j a v a2s .c  om*/

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

    // Sets up any standard paints that will be used
    initView();
}

From source file:com.android.widget.SlidingPaneLayout.java

public SlidingPaneLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    mOverhangSize = -1;/*from   www.  j ava 2s. c  o  m*/

    if (attrs != null) {
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingPaneLayout);

        if (ta != null) {
            mOverhangSize = ta.getDimensionPixelSize(R.styleable.SlidingPaneLayout_overhangSize, -1);
            ta.recycle();
        }
    }

    final float density = context.getResources().getDisplayMetrics().density;
    if (mOverhangSize == -1) {
        mOverhangSize = (int) (DEFAULT_OVERHANG_SIZE * density + 0.5f);
    }

    setWillNotDraw(false);

    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegate());
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);

    mDragHelper = ViewDragHelper.create(this, 1.0f, new DragHelperCallback());
    mDragHelper.setMinVelocity(MIN_FLING_VELOCITY * density);
}

From source file:com.ymsfd.practices.ui.widget.SlidingLayout.java

public SlidingLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    final float density = context.getResources().getDisplayMetrics().density;
    mOverhangSize = (int) (DEFAULT_OVERHANG_SIZE * density + 0.5f);

    final ViewConfiguration viewConfig = ViewConfiguration.get(context);

    setWillNotDraw(false);//from w w w. j  a v  a2 s . c o m

    ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegate());
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);

    mDragHelper = ViewDragHelper.create(this, 0.5f, new DragHelperCallback());
    mDragHelper.setMinVelocity(MIN_FLING_VELOCITY * density);
}

From source file:com.hxqc.mall.core.views.CustomScrollView.java

public CustomScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    initScrollView();/*from  w w w  .  ja  va  2  s .c o  m*/

    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);
}

From source file:demo.design.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);

    ThemeUtils.checkAppCompatTheme(context);

    setOrientation(VERTICAL);/*from   www.j a  v  a2 s.  c o m*/
    setWillNotDraw(false);
    setAddStatesFromChildren(true);

    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);
    mHintEnabled = a.getBoolean(R.styleable.TextInputLayout_hintEnabled, true);
    setHint(a.getText(R.styleable.TextInputLayout_android_hint));
    mHintAnimationEnabled = a.getBoolean(R.styleable.TextInputLayout_hintAnimationEnabled, true);

    if (a.hasValue(R.styleable.TextInputLayout_android_textColorHint)) {
        mDefaultTextColor = mFocusedTextColor = a
                .getColorStateList(R.styleable.TextInputLayout_android_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);

    final boolean counterEnabled = a.getBoolean(R.styleable.TextInputLayout_counterEnabled, false);
    setCounterMaxLength(a.getInt(R.styleable.TextInputLayout_counterMaxLength, INVALID_MAX_LENGTH));
    mCounterTextAppearance = a.getResourceId(R.styleable.TextInputLayout_counterTextAppearance, 0);
    mCounterOverflowTextAppearance = a.getResourceId(R.styleable.TextInputLayout_counterOverflowTextAppearance,
            0);
    a.recycle();

    setErrorEnabled(errorEnabled);
    setCounterEnabled(counterEnabled);

    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.appeaser.sublimepickerlibrary.timepicker.SublimeTimePicker.java

private void initializeLayout() {
    mContext = getContext();/* w  w w  .j a v  a2  s .  c  o  m*/
    setCurrentLocale(Locale.getDefault());

    // process style attributes
    final TypedArray a = mContext.obtainStyledAttributes(R.styleable.SublimeTimePicker);
    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);

    DateFormatSymbols dfs = DateFormatSymbols.getInstance(mCurrentLocale);
    String[] amPmStrings = dfs.getAmPmStrings();/*{"AM", "PM"}*/

    if (amPmStrings.length == 2 && !TextUtils.isEmpty(amPmStrings[0]) && !TextUtils.isEmpty(amPmStrings[1])) {
        mAmText = amPmStrings[0].length() > 2 ? amPmStrings[0].substring(0, 2) : amPmStrings[0];
        mPmText = amPmStrings[1].length() > 2 ? amPmStrings[1].substring(0, 2) : amPmStrings[1];
    } else {
        // Defaults
        mAmText = "AM";
        mPmText = "PM";
    }

    final int layoutResourceId = R.layout.time_picker_layout;
    final View mainView = inflater.inflate(layoutResourceId, this);

    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(mContext, 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(mContext, 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);

    ColorStateList headerTextColor = a.getColorStateList(R.styleable.SublimeTimePicker_spHeaderTextColor);

    if (headerTextColor != null) {
        mHourView.setTextColor(headerTextColor);
        mSeparatorView.setTextColor(headerTextColor);
        mMinuteView.setTextColor(headerTextColor);
        mAmLabel.setTextColor(headerTextColor);
        mPmLabel.setTextColor(headerTextColor);
    }

    // Set up header background, if available.
    if (SUtils.isApi_22_OrHigher()) {
        if (a.hasValueOrEmpty(R.styleable.SublimeTimePicker_spHeaderBackground)) {
            SUtils.setViewBackground(mHeaderView,
                    a.getDrawable(R.styleable.SublimeTimePicker_spHeaderBackground));
        }
    } else {
        if (a.hasValue(R.styleable.SublimeTimePicker_spHeaderBackground)) {
            SUtils.setViewBackground(mHeaderView,
                    a.getDrawable(R.styleable.SublimeTimePicker_spHeaderBackground));
        }
    }

    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);
}

From source file:com.appeaser.sublimepickerlibrary.datepicker.SimpleMonthView.java

private void init() {
    mContext = getContext();/*from w  ww.  j a  v a  2s.c  o m*/

    mTouchSlopSquared = ViewConfiguration.get(mContext).getScaledTouchSlop()
            * ViewConfiguration.get(mContext).getScaledTouchSlop();

    final Resources res = mContext.getResources();
    mDesiredMonthHeight = res.getDimensionPixelSize(R.dimen.sp_date_picker_month_height);
    mDesiredDayOfWeekHeight = res.getDimensionPixelSize(R.dimen.sp_date_picker_day_of_week_height);
    mDesiredDayHeight = res.getDimensionPixelSize(R.dimen.sp_date_picker_day_height);
    mDesiredCellWidth = res.getDimensionPixelSize(R.dimen.sp_date_picker_day_width);
    mDesiredDaySelectorRadius = res.getDimensionPixelSize(R.dimen.sp_date_picker_day_selector_radius);
    mPaddingRangeIndicator = res.getDimensionPixelSize(R.dimen.sp_month_view_range_padding);

    // 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;

    String titleFormat;

    if (SUtils.isApi_18_OrHigher()) {
        titleFormat = DateFormat.getBestDateTimePattern(locale, DEFAULT_TITLE_FORMAT);
    } else {
        titleFormat = DateTimePatternHelper.getBestDateTimePattern(locale, DateTimePatternHelper.PATTERN_MMMMy);
    }

    mTitleFormatter = new SimpleDateFormat(titleFormat, locale);
    mDayOfWeekFormatter = new SimpleDateFormat(DAY_OF_WEEK_FORMAT, locale);
    mDayFormatter = NumberFormat.getIntegerInstance(locale);

    initPaints(res);
}

From source file:com.bitflake.counter.HorizontalPicker.java

public HorizontalPicker(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    // create the selector wheel paint
    TextPaint paint = new TextPaint();
    paint.setAntiAlias(true);/* w ww  .  java2s .c  om*/
    textPaint = paint;

    TypedArray a = context.getTheme().obtainStyledAttributes(attrs, R.styleable.HorizontalPicker, defStyle, 0);

    CharSequence[] values;
    int ellipsize = 3; // END default value
    int sideItems = this.sideItems;

    try {
        textColor = a.getColorStateList(R.styleable.HorizontalPicker_android_textColor);
        if (textColor == null) {
            textColor = ColorStateList.valueOf(0xFF000000);
        }

        values = a.getTextArray(R.styleable.HorizontalPicker_values);
        ellipsize = a.getInt(R.styleable.HorizontalPicker_android_ellipsize, ellipsize);
        marqueeRepeatLimit = a.getInt(R.styleable.HorizontalPicker_android_marqueeRepeatLimit,
                marqueeRepeatLimit);
        dividerSize = a.getDimension(R.styleable.HorizontalPicker_dividerSize, dividerSize);
        sideItems = a.getInt(R.styleable.HorizontalPicker_sideItems, sideItems);

        float textSize = a.getDimension(R.styleable.HorizontalPicker_android_textSize, -1);
        if (textSize > -1) {
            setTextSize(textSize);
        }
    } finally {
        a.recycle();
    }

    switch (ellipsize) {
    case 1:
        setEllipsize(TextUtils.TruncateAt.START);
        break;
    case 2:
        setEllipsize(TextUtils.TruncateAt.MIDDLE);
        break;
    case 3:
        setEllipsize(TextUtils.TruncateAt.END);
        break;
    case 4:
        setEllipsize(TextUtils.TruncateAt.MARQUEE);
        break;
    }

    Paint.FontMetricsInt fontMetricsInt = textPaint.getFontMetricsInt();
    boringMetrics = new BoringLayout.Metrics();
    boringMetrics.ascent = fontMetricsInt.ascent;
    boringMetrics.bottom = fontMetricsInt.bottom;
    boringMetrics.descent = fontMetricsInt.descent;
    boringMetrics.leading = fontMetricsInt.leading;
    boringMetrics.top = fontMetricsInt.top;
    boringMetrics.width = itemWidth;

    setWillNotDraw(false);

    flingScrollerX = new OverScroller(context);
    adjustScrollerX = new OverScroller(context, new DecelerateInterpolator(2.5f));

    // initialize constants
    ViewConfiguration configuration = ViewConfiguration.get(context);
    touchSlop = configuration.getScaledTouchSlop();
    mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
    maximumFlingVelocity = configuration.getScaledMaximumFlingVelocity()
            / SELECTOR_MAX_FLING_VELOCITY_ADJUSTMENT;
    overscrollDistance = configuration.getScaledOverscrollDistance();

    previousScrollerX = Integer.MIN_VALUE;

    setValues(values);
    setSideItems(sideItems);

    touchHelper = new PickerTouchHelper(this);
    ViewCompat.setAccessibilityDelegate(this, touchHelper);

}

From source file:org.holoeverywhere.widget.datetimepicker.date.SimpleMonthView.java

public SimpleMonthView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    Resources res = context.getResources();

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

    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.DateTimePicker, defStyle,
            R.style.Holo_DateTimePicker);
    mDayTextColor = a.getColor(R.styleable.DateTimePicker_dateDayTextColor, 0);
    mTodayNumberColor = a.getColor(R.styleable.DateTimePicker_dateTodayColor, 0);
    mMonthTitleColor = a.getColor(R.styleable.DateTimePicker_dateMonthTitleColor, 0);
    mSelectedCircleColor = a.getColor(R.styleable.DateTimePicker_dateCircleColor, 0);
    a.recycle();/*from www .j a va  2s  .  c o  m*/

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

    MINI_DAY_NUMBER_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.date_day_number_size);
    MONTH_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.date_month_label_size);
    MONTH_DAY_LABEL_TEXT_SIZE = res.getDimensionPixelSize(R.dimen.date_month_day_label_text_size);
    MONTH_HEADER_SIZE = res.getDimensionPixelOffset(R.dimen.date_month_list_item_header_height);
    DAY_SELECTED_CIRCLE_SIZE = res.getDimensionPixelSize(R.dimen.date_day_number_select_circle_radius);

    mRowHeight = (res.getDimensionPixelOffset(R.dimen.date_time_picker_size) - MONTH_HEADER_SIZE)
            / MAX_NUM_ROWS;

    // Set up accessibility components.
    mNodeProvider = new MonthViewNodeProvider(context, this);
    ViewCompat.setAccessibilityDelegate(this, mNodeProvider.getAccessibilityDelegate());
    ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    mLockAccessibilityDelegate = true;

    // Sets up any standard paints that will be used
    initView();
}