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:io.doist.datetimepicker.time.RadialTimePickerView.java

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

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

    // process style attributes
    final Resources res = getResources();
    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.TimePicker, defStyleAttr, 0);

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

    // Initialize all alpha values to opaque.
    for (int i = 0; i < mAlpha.length; i++) {
        mAlpha[i] = new IntHolder(ALPHA_OPAQUE);
    }/*from   w  w  w .  j a  v a 2  s . com*/
    for (int i = 0; i < mAlphaSelector.length; i++) {
        for (int j = 0; j < mAlphaSelector[i].length; j++) {
            mAlphaSelector[i][j] = new IntHolder(ALPHA_OPAQUE);
        }
    }

    final int numbersTextColor = a.getColor(R.styleable.TimePicker_numbersTextColor,
            res.getColor(R.color.timepicker_default_text_color_material));

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

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

    mPaintCenter.setColor(numbersTextColor);
    mPaintCenter.setAntiAlias(true);
    mPaintCenter.setTextAlign(Paint.Align.CENTER);

    mPaintSelector[HOURS][SELECTOR_CIRCLE] = new Paint();
    mPaintSelector[HOURS][SELECTOR_CIRCLE].setAntiAlias(true);
    mColorSelector[HOURS][SELECTOR_CIRCLE] = a.getColor(R.styleable.TimePicker_numbersSelectorColor,
            R.color.timepicker_default_selector_color_material);

    mPaintSelector[HOURS][SELECTOR_DOT] = new Paint();
    mPaintSelector[HOURS][SELECTOR_DOT].setAntiAlias(true);
    mColorSelector[HOURS][SELECTOR_DOT] = a.getColor(R.styleable.TimePicker_numbersSelectorColor,
            R.color.timepicker_default_selector_color_material);

    mPaintSelector[HOURS][SELECTOR_LINE] = new Paint();
    mPaintSelector[HOURS][SELECTOR_LINE].setAntiAlias(true);
    mPaintSelector[HOURS][SELECTOR_LINE].setStrokeWidth(2);
    mColorSelector[HOURS][SELECTOR_LINE] = a.getColor(R.styleable.TimePicker_numbersSelectorColor,
            R.color.timepicker_default_selector_color_material);

    mPaintSelector[MINUTES][SELECTOR_CIRCLE] = new Paint();
    mPaintSelector[MINUTES][SELECTOR_CIRCLE].setAntiAlias(true);
    mColorSelector[MINUTES][SELECTOR_CIRCLE] = a.getColor(R.styleable.TimePicker_numbersSelectorColor,
            R.color.timepicker_default_selector_color_material);

    mPaintSelector[MINUTES][SELECTOR_DOT] = new Paint();
    mPaintSelector[MINUTES][SELECTOR_DOT].setAntiAlias(true);
    mColorSelector[MINUTES][SELECTOR_DOT] = a.getColor(R.styleable.TimePicker_numbersSelectorColor,
            R.color.timepicker_default_selector_color_material);

    mPaintSelector[MINUTES][SELECTOR_LINE] = new Paint();
    mPaintSelector[MINUTES][SELECTOR_LINE].setAntiAlias(true);
    mPaintSelector[MINUTES][SELECTOR_LINE].setStrokeWidth(2);
    mColorSelector[MINUTES][SELECTOR_LINE] = a.getColor(R.styleable.TimePicker_numbersSelectorColor,
            R.color.timepicker_default_selector_color_material);

    mPaintBackground.setColor(a.getColor(R.styleable.TimePicker_numbersBackgroundColor,
            res.getColor(R.color.timepicker_default_numbers_background_color_material)));
    mPaintBackground.setAntiAlias(true);

    if (DEBUG) {
        mPaintDebug.setColor(DEBUG_COLOR);
        mPaintDebug.setAntiAlias(true);
        mPaintDebug.setStrokeWidth(DEBUG_STROKE_WIDTH);
        mPaintDebug.setStyle(Paint.Style.STROKE);
        mPaintDebug.setTextAlign(Paint.Align.CENTER);
    }

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

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

    if (getImportantForAccessibility() == IMPORTANT_FOR_ACCESSIBILITY_AUTO) {
        setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_YES);
    }

    initHoursAndMinutesText();
    initData();

    mTransitionMidRadiusMultiplier = Float
            .parseFloat(res.getString(R.string.timepicker_transition_mid_radius_multiplier));
    mTransitionEndRadiusMultiplier = Float
            .parseFloat(res.getString(R.string.timepicker_transition_end_radius_multiplier));

    mTextGridHeights[HOURS] = new float[7];
    mTextGridHeights[MINUTES] = new float[7];

    mSelectionRadiusMultiplier = Float
            .parseFloat(res.getString(R.string.timepicker_selection_radius_multiplier));

    a.recycle();

    setOnTouchListener(this);
    setClickable(true);

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

From source file:com.android.launcher3.ViewPager.java

void initViewPager() {
    setWillNotDraw(false);//from www. ja  va 2 s .c om
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    final Context context = getContext();
    mScroller = new FixedSpeedScroller(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);
    }
}

From source file:com.example.leelay.galleyviewpager.GalleyViewPager.java

void initViewPager() {
    setWillNotDraw(false);//from w  w  w.  j  a  v a  2 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);
        }
    });
}

From source file:comm.custom.CustomViewPager.java

void initViewPager() {
    setWillNotDraw(false);// w w  w.  j a  v a 2 s  .c om
    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);
    //                    }
    //                });
}

From source file:com.appeaser.sublimepickerlibrary.timepicker.RadialTimePickerView.java

private void init(AttributeSet attrs, int defStyleAttr, int defStyleRes) {
    Context context = getContext();

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

    // process style attributes
    final Resources res = getResources();
    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.RadialTimePickerView, defStyleAttr,
            defStyleRes);/*from w  w  w  .j a  v  a2 s  .  c  o m*/

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

    // Initialize all alpha values to opaque.
    for (int i = 0; i < mAlpha.length; i++) {
        mAlpha[i] = new IntHolder(ALPHA_OPAQUE);
    }

    mTextColor[HOURS] = a.getColorStateList(R.styleable.RadialTimePickerView_spNumbersTextColor);
    mTextColor[HOURS_INNER] = a.getColorStateList(R.styleable.RadialTimePickerView_spNumbersInnerTextColor);
    mTextColor[MINUTES] = mTextColor[HOURS];

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

    final ColorStateList selectorColors = a
            .getColorStateList(R.styleable.RadialTimePickerView_spNumbersSelectorColor);

    int selectorActivatedColor = Color.BLACK;
    if (selectorColors != null) {
        selectorActivatedColor = selectorColors
                .getColorForState(SUtils.resolveStateSet(SUtils.STATE_ENABLED | SUtils.STATE_ACTIVATED), 0);
    }

    mPaintCenter.setColor(selectorActivatedColor);
    mPaintCenter.setAntiAlias(true);

    final int[] activatedStateSet = SUtils.resolveStateSet(SUtils.STATE_ENABLED | SUtils.STATE_ACTIVATED);

    mSelectorColor = selectorActivatedColor;
    mSelectorDotColor = mTextColor[HOURS].getColorForState(activatedStateSet, 0);

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

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

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

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

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

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

    mPaintBackground.setColor(a.getColor(R.styleable.RadialTimePickerView_spNumbersBackgroundColor,
            ContextCompat.getColor(context, R.color.timepicker_default_numbers_background_color_material)));
    mPaintBackground.setAntiAlias(true);

    mSelectorRadius = res.getDimensionPixelSize(R.dimen.sp_timepicker_selector_radius);
    mSelectorStroke = res.getDimensionPixelSize(R.dimen.sp_timepicker_selector_stroke);
    mSelectorDotRadius = res.getDimensionPixelSize(R.dimen.sp_timepicker_selector_dot_radius);
    mCenterDotRadius = res.getDimensionPixelSize(R.dimen.sp_timepicker_center_dot_radius);

    mTextSize[HOURS] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_size_normal);
    mTextSize[MINUTES] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_size_normal);
    mTextSize[HOURS_INNER] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_size_inner);

    mTextInset[HOURS] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_inset_normal);
    mTextInset[MINUTES] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_inset_normal);
    mTextInset[HOURS_INNER] = res.getDimensionPixelSize(R.dimen.sp_timepicker_text_inset_inner);

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

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

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

    initHoursAndMinutesText();
    initData();

    a.recycle();

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

From source file:cn.androidy.materialdesignsample.ryanharterviewpager.ViewPager.java

void initViewPager() {
    setWillNotDraw(false);/*  w  w w  .j ava 2s . 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);
    }
}

From source file:com.tjych.swip.vertical.DirectionalViewPager.java

void initViewPager() {
    setWillNotDraw(false);/*from   ww w.  j a va2s.  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();
    mStartEdge = new EdgeEffectCompat(context);
    mEndEdge = 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:dev.dworks.libs.widget.ViewPager.java

void initViewPager() {
    setWillNotDraw(false);/*from w w w . ja 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 = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    mMinimumVelocity = (int) (MIN_FLING_VELOCITY * density);
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mLeftEdge = new EdgeEffectCompat(context);
    mRightEdge = new EdgeEffectCompat(context);
    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);
    }
}

From source file:com.tr4android.support.extension.picker.time.RadialTimePickerView.java

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

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

    // process style attributes
    final Resources res = getResources();
    final TypedArray a = getContext().obtainStyledAttributes(attrs, R.styleable.TimePickerDialog, defStyleAttr,
            defStyleRes);//from w w  w  . j a v  a2s. c o  m

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

    // Initialize all alpha values to opaque.
    for (int i = 0; i < mAlpha.length; i++) {
        mAlpha[i] = new IntHolder(ALPHA_OPAQUE);
    }

    mTextColor[HOURS] = a.getColorStateList(R.styleable.TimePickerDialog_numbersTextColor);
    if (mTextColor[HOURS] == null) {
        mTextColor[HOURS] = PickerThemeUtils.getTextColorPrimaryActivatedStateList(context);
    }
    mTextColor[HOURS_INNER] = a.getColorStateList(R.styleable.TimePickerDialog_numbersInnerTextColor);
    if (mTextColor[HOURS_INNER] == null) {
        mTextColor[HOURS_INNER] = PickerThemeUtils.getTextColorSecondaryActivatedStateList(context);
    }
    mTextColor[MINUTES] = mTextColor[HOURS];

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

    final int[] selectedStateSet = new int[] { android.R.attr.state_enabled, android.R.attr.state_selected };

    // Set up number selected color, if available.
    final ColorStateList numbersSelectorColor;
    if (a.hasValue(R.styleable.TimePickerDialog_numbersSelectorColor)) {
        numbersSelectorColor = a.getColorStateList(R.styleable.TimePickerDialog_numbersSelectorColor);
    } else {
        final TypedArray ta = context.obtainStyledAttributes(new int[] { R.attr.colorControlActivated });
        numbersSelectorColor = ta.getColorStateList(0);
        ta.recycle();
    }
    final int selectorActivatedColor = numbersSelectorColor.getColorForState(selectedStateSet, 0);

    mPaintCenter.setColor(selectorActivatedColor);
    mPaintCenter.setAntiAlias(true);

    mSelectorColor = selectorActivatedColor;
    mSelectorDotColor = mTextColor[HOURS].getColorForState(selectedStateSet, 0);

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

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

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

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

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

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

    mPaintBackground.setColor(a.getColor(R.styleable.TimePickerDialog_numbersBackgroundColor,
            ContextCompat.getColor(context, android.R.color.transparent)));
    mPaintBackground.setAntiAlias(true);

    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;
    mIs24HourMode = false;
    mAmOrPm = AM;

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

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

    initHoursAndMinutesText();
    initData();

    a.recycle();

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

From source file:com.suning.boxcontroller.control.ExViewPager.java

void initViewPager() {
    setWillNotDraw(false);/*from   ww  w . jav  a 2  s . c o  m*/
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);
    final Context context = getContext();
    mScroller = new PageScroller(context, null);
    mScroller.setSrollFinishListener(new OnScrollFinishListener() {

        @Override
        public void OnScrollFinish() {
            // to-do Auto-generated method stub
            Log.d(TAG, "setSrollFinishListener is OnScrollFinish");
            if (null != mPageScrollListener) {
                mPageScrollListener.onPageScrollEnd(getCurrentItem());
            }
        }
    });
    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);
    }
}