Example usage for android.view ViewConfiguration getScaledMinimumFlingVelocity

List of usage examples for android.view ViewConfiguration getScaledMinimumFlingVelocity

Introduction

In this page you can find the example usage for android.view ViewConfiguration getScaledMinimumFlingVelocity.

Prototype

public int getScaledMinimumFlingVelocity() 

Source Link

Usage

From source file:com.mixiaoxiao.support.widget.SmoothSwitch.java

/**
 * Construct a new Switch with a default style determined by the given theme
 * attribute, overriding specific style attributes as requested.
 * /*from ww w  .  j  av a  2s. c  o  m*/
 * @param context
 *            The Context that will determine this widget's theming.
 * @param attrs
 *            Specification of attributes that should deviate from the
 *            default styling.
 * @param defStyleAttr
 *            An attribute in the current theme that contains a reference to
 *            a style resource that supplies default values for the view.
 *            Can be 0 to not look for defaults.
 */
public SmoothSwitch(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);

    mTextPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);

    final Resources res = getResources();
    final float density = res.getDisplayMetrics().density;
    mTextPaint.density = density;//res.getDisplayMetrics().density;

    final int thumbSize = (int) (Default.DEFAULT_SIZE_DP * density + 0.5f);// truckSize = 15dp 
    final int thumbWidth = thumbSize;//a.getDimensionPixelSize(R.styleable.SwitchCompat_thumbWidth, thumbSize);
    mThumbColorOn = Default.DEFAULT_THUMB_ON_COLOR;//a.getColor(R.styleable.SwitchCompat_colorOn, Default.DEFAULT_THUMB_ON_COLOR);
    mThumbColorOff = Default.DEFAULT_THUMB_OFF_COLOR;//a.getColor(R.styleable.SwitchCompat_colorOff, Default.DEFAULT_THUMB_OFF_COLOR);
    mTrackColorOn = Default.DEFAULT_TRACK_ON_COLOR;//a.getColor(R.styleable.SwitchCompat_trackColorOn, Default.DEFAULT_TRACK_ON_COLOR);
    mTrackColorOff = Default.DEFAULT_TRACK_OFF_COLOR;//a.getColor(R.styleable.SwitchCompat_trackColorOff, Default.DEFAULT_TRACK_OFF_COLOR);

    final float radius = thumbSize * Default.DEFAULT_RADIUS_PERCENT_OF_SIZE;//a.getFloat(R.styleable.SwitchCompat_radiusPercentOfThumbSize,
    //            Default.DEFAULT_RADIUS_PERCENT_OF_SIZE);
    final int thumbPadding = (int) (thumbSize * Default.DEFAULT_THUMB_PADDING_PERCENT_OF_SIZE + 0.5f);//thumbSize * a.getFloat(R.styleable.SwitchCompat_thumbPaddingPercentOfThumbSize,
    //            Default.DEFAULT_THUMB_PADDING_PERCENT_OF_SIZE) + 0.5f);
    final int trackPadding = (int) (thumbSize * Default.DEFAULT_TRACK_PADDING_PERCENT_OF_SIZE + 0.5f);//thumbSize * a.getFloat(R.styleable.SwitchCompat_trackPaddingPercentOfThumbSize,
    //            Default.DEFAULT_TRACK_PADDING_PERCENT_OF_SIZE) + 0.5f);

    final int curThumbColor = isChecked() ? mThumbColorOn : mThumbColorOff;
    final int curTrackColor = isChecked() ? mTrackColorOn : mTrackColorOff;
    mThumbDrawable = makeThumbDrawable(curThumbColor, thumbWidth, thumbSize, radius, thumbPadding);
    mTrackDrawable = makeTrackDrawable(curTrackColor, thumbWidth, thumbSize, radius, trackPadding);
    //      final int onDisableColor = getDisableColor(onColor);
    //      final int offDisableColor = getDisableColor(offColor);
    //      final StateListDrawable thumbDrawable = new StateListDrawable();
    //      thumbDrawable.addState(new int[] { -android.R.attr.state_enabled, android.R.attr.state_checked},
    //            makeThumbDrawable(onDisableColor, thumbSize));// Disabled ON
    //      thumbDrawable.addState(new int[] { -android.R.attr.state_enabled, -android.R.attr.state_checked},
    //            makeThumbDrawable(offDisableColor, thumbSize));// Disabled OFF
    //      thumbDrawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_checked },
    //            makeThumbDrawable(onColor, thumbSize));
    //      thumbDrawable.addState(new int[] {}, makeThumbDrawable(offColor, thumbSize));
    //      mThumbDrawable = thumbDrawable;
    //
    //      final StateListDrawable trackDrawable = new StateListDrawable();
    //      trackDrawable.addState(new int[] { -android.R.attr.state_enabled, android.R.attr.state_checked},
    //            makeTrackDrawable(onDisableColor, thumbSize));// Disabled ON
    //      trackDrawable.addState(new int[] { -android.R.attr.state_enabled, -android.R.attr.state_checked},
    //            makeTrackDrawable(offDisableColor, thumbSize));// Disabled OFF
    //      trackDrawable.addState(new int[] { android.R.attr.state_enabled, android.R.attr.state_checked },
    //            makeTrackDrawable(onColor, thumbSize));
    //      trackDrawable.addState(new int[] {}, makeTrackDrawable(offColor, thumbSize));
    //      mTrackDrawable = trackDrawable;

    //      mTextOn = a.getText(R.styleable.SwitchCompat_android_textOn);
    //      mTextOff = a.getText(R.styleable.SwitchCompat_android_textOff);
    mShowText = false;//a.getBoolean(R.styleable.SwitchCompat_showText, false);
    mThumbTextPadding = 0;//a.getDimensionPixelSize(R.styleable.SwitchCompat_thumbTextPadding, 0);
    //      mSwitchMinWidth = a.getDimensionPixelSize(R.styleable.SwitchCompat_switchMinWidth, 0);
    mSwitchMinWidth = Math.max(mSwitchMinWidth, thumbWidth * 2);
    mSwitchPadding = 0;//a.getDimensionPixelSize(R.styleable.SwitchCompat_switchPadding, 0);
    //      mSplitTrack = a.getBoolean(R.styleable.SwitchCompat_splitTrack, false);

    //      final int appearance = a.getResourceId(R.styleable.SwitchCompat_switchTextAppearance, 0);
    //      if (appearance != 0) {
    //         setSwitchTextAppearance(context, appearance);
    //      }else{
    //         ColorStateList colors = a.getColorStateList(R.styleable.SwitchCompat_switchTextColor);
    //         if (colors != null) {
    //            mTextColors = colors;
    //         } else {
    //            // If no color set in TextAppearance, default to the view's textColor
    //            mTextColors = getTextColors();
    //         }
    //         float ts = a.getDimension(R.styleable.SwitchCompat_switchTextSize, 0);
    //         if (ts != 0) {
    //            if (ts != mTextPaint.getTextSize()) {
    //               mTextPaint.setTextSize(ts);
    //               requestLayout();
    //            }
    //         }
    //      }

    // mTintManager = a.getTintManager();

    //      a.recycle();

    final ViewConfiguration config = ViewConfiguration.get(context);
    mTouchSlop = config.getScaledTouchSlop();
    mMinFlingVelocity = config.getScaledMinimumFlingVelocity();

    // Refresh display with current params
    refreshDrawableState();
    setChecked(isChecked());
}

From source file:com.hb.hkm.slidinglayer.SlidLayer.java

private void init() {

    setWillNotDraw(false);//from w  w w.  j av  a 2  s. co m
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);

    final Context context = getContext();
    mScroller = new Scroller(context, sMenuInterpolator);

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();

    final float density = context.getResources().getDisplayMetrics().density;
    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);

    mRandom = new Random();
}

From source file:com.bullmobi.message.ui.fragments.EasyNotificationFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Resources res = getResources();
    mConfigWidgetPinDuration = res.getInteger(R.integer.config_maxPinTime);
    mConfigWidgetSelectDelay = res.getInteger(R.integer.config_iconSelectDelayMillis);
    ViewConfiguration vc = ViewConfiguration.get(getActivity());
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();

    // Clock widget
    mClockWidget = new ClockWidget(this, this);

    // Media widget
    mMediaController = MediaController2.newInstance(getActivity());
    mMediaWidget = new MediaWidget(this, this);

    // Transitions
    if (Device.hasKitKatApi()) {
        mTransitionJit = new TransitionSet().setOrdering(TransitionSet.ORDERING_TOGETHER)
                .addTransition(new Fade()).addTransition(new ChangeBounds());
        mTransitionSwitchScene = new TransitionSet().setOrdering(TransitionSet.ORDERING_TOGETHER)
                .addTransition(new Fade(Fade.OUT).setDuration(200))
                .addTransition(new Fade(Fade.IN).setStartDelay(80))
                .addTransition(new ChangeBounds().setStartDelay(80));
    }//from  www  .  j a  v  a 2s .  com

    // Timeout
    mTimeout = isNotDemo() ? mActivityAcd.getTimeout() : new Timeout();
}

From source file:com.achep.acdisplay.ui.fragments.AcDisplayFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Resources res = getResources();
    mConfigWidgetPinDuration = res.getInteger(R.integer.config_maxPinTime);
    mConfigWidgetSelectDelay = res.getInteger(R.integer.config_iconSelectDelayMillis);
    ViewConfiguration vc = ViewConfiguration.get(getActivity());
    mMaxFlingVelocity = vc.getScaledMaximumFlingVelocity();
    mMinFlingVelocity = vc.getScaledMinimumFlingVelocity();

    // Clock widget
    mClockWidget = getConfig().isCustomWidgetEnabled() ? new HostWidget(this, this)
            : new ClockWidget(this, this);

    // Media widget
    mMediaController = MediaController2.newInstance(getActivity()).asyncWrap();
    mMediaWidget = new MediaWidget(this, this);

    // Transitions
    if (Device.hasKitKatApi()) {
        mTransitionJit = new TransitionSet().setOrdering(TransitionSet.ORDERING_TOGETHER)
                .addTransition(new Fade()).addTransition(new ChangeBounds());
        mTransitionSwitchScene = new TransitionSet().setOrdering(TransitionSet.ORDERING_TOGETHER)
                .addTransition(new Fade(Fade.OUT).setDuration(200))
                .addTransition(new Fade(Fade.IN).setStartDelay(80))
                .addTransition(new ChangeBounds().setStartDelay(80));
    }// w w  w  .ja  va2  s.  co  m

    // Timeout
    mTimeout = isNotDemo() ? mActivityAcd.getTimeout() : new Timeout();
}

From source file:jackson.com.slidingmenulib.MyViewDragHelper.java

/**
 * Apps should use ViewDragHelper.create() to get a new instance.
 * This will allow VDH to use internal compatibility implementations for different
 * platform versions./* www.  ja  va 2 s . c om*/
 *
 * @param context Context to initialize config-dependent params from
 * @param forParent Parent view to monitor
 */
private MyViewDragHelper(Context context, ViewGroup forParent, ViewDragHelper.Callback cb) {
    if (forParent == null) {
        throw new IllegalArgumentException("Parent view may not be null");
    }
    if (cb == null) {
        throw new IllegalArgumentException("Callback may not be null");
    }

    mParentView = forParent;
    mCallback = cb;

    final ViewConfiguration vc = ViewConfiguration.get(context);
    final float density = context.getResources().getDisplayMetrics().density;
    mEdgeSize = (int) (EDGE_SIZE * density + 0.5f);

    mTouchSlop = vc.getScaledTouchSlop();
    mMaxVelocity = vc.getScaledMaximumFlingVelocity();
    mMinVelocity = vc.getScaledMinimumFlingVelocity();
    mScroller = new OverScroller(context, sInterpolator);
}

From source file:com.wunderlist.slidinglayer.SlidingLayer.java

private void init() {

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        setLayerType(LAYER_TYPE_HARDWARE, null);
    }//from www  . j av  a 2  s.  co  m

    setWillNotDraw(false);
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);

    final Context context = getContext();
    mScroller = new Scroller(context, sMenuInterpolator);

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();

    final float density = context.getResources().getDisplayMetrics().density;
    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);

    mRandom = new Random();
}

From source file:com.chauthai.swipereveallayout.ViewDragHelper.java

/**
 * Apps should use ViewDragHelper.create() to get a new instance.
 * This will allow VDH to use internal compatibility implementations for different
 * platform versions./*from w w w .  j  ava2 s . c o  m*/
 *
 * @param context   Context to initialize config-dependent params from
 * @param forParent Parent view to monitor
 */
private ViewDragHelper(Context context, ViewGroup forParent, Callback cb) {
    if (forParent == null) {
        throw new IllegalArgumentException("Parent view may not be null");
    }
    if (cb == null) {
        throw new IllegalArgumentException("Callback may not be null");
    }
    mParentView = forParent;
    mCallback = cb;
    final ViewConfiguration vc = ViewConfiguration.get(context);
    final float density = context.getResources().getDisplayMetrics().density;
    mEdgeSize = (int) (EDGE_SIZE * density + 0.5f);
    mTouchSlop = vc.getScaledTouchSlop();
    mMaxVelocity = vc.getScaledMaximumFlingVelocity();
    mMinVelocity = vc.getScaledMinimumFlingVelocity();
    mScroller = ScrollerCompat.create(context, sInterpolator);
}

From source file:com.iterlog.swipbackhelper.ViewDragHelper.java

/**
 * Apps should use ViewDragHelper.create() to get a new instance. This will
 * allow VDH to use internal compatibility implementations for different
 * platform versions.//from ww  w  .  ja v a 2s . c o  m
 *
 * @param context   Context to initialize config-dependent params from
 * @param forParent Parent view to monitor
 */
private ViewDragHelper(Context context, ViewGroup forParent, Callback cb) {
    if (forParent == null) {
        throw new IllegalArgumentException("Parent view may not be null");
    }
    if (cb == null) {
        throw new IllegalArgumentException("Callback may not be null");
    }

    mParentView = forParent;
    mCallback = cb;

    final ViewConfiguration vc = ViewConfiguration.get(context);
    final float density = context.getResources().getDisplayMetrics().density;
    mEdgeSize = (int) (EDGE_SIZE * density + 0.5f);

    mTouchSlop = vc.getScaledTouchSlop();
    mMaxVelocity = vc.getScaledMaximumFlingVelocity();
    mMinVelocity = vc.getScaledMinimumFlingVelocity();
    mScroller = ScrollerCompat.create(context, sInterpolator);

}

From source file:com.cyanogenmod.filemanager.ui.widgets.ViewDragHelper.java

/**
 * Apps should use ViewDragHelper.create() to get a new instance.
 * This will allow VDH to use internal compatibility implementations for different
 * platform versions.//from  w w  w. jav  a2s .c o  m
 *
 * @param context Context to initialize config-dependent params from
 * @param forParent Parent view to monitor
 */
private ViewDragHelper(Context context, ViewGroup forParent, Callback cb) {
    if (forParent == null) {
        throw new IllegalArgumentException("Parent view may not be null");
    }
    if (cb == null) {
        throw new IllegalArgumentException("Callback may not be null");
    }

    mParentView = forParent;
    mCallback = cb;

    final ViewConfiguration vc = ViewConfiguration.get(context);
    final float density = context.getResources().getDisplayMetrics().density;
    mEdgeSize = (int) (EDGE_SIZE * density + 0.5f);

    mTouchSlop = vc.getScaledTouchSlop();
    mMaxVelocity = vc.getScaledMaximumFlingVelocity();
    mMinVelocity = vc.getScaledMinimumFlingVelocity();
    mScroller = new Scroller(context, sInterpolator);
}

From source file:com.albedinsky.android.support.ui.widget.ViewDragHelper.java

/**
 * Apps should use ViewDragHelper.create() to get a new instance.
 * This will allow VDH to use internal compatibility implementations for different
 * platform versions.//  ww w . j a v a  2s . c o  m
 *
 * @param context Context to initialize config-dependent params from
 * @param forParent Parent view to monitor
 */
ViewDragHelper(Context context, ViewGroup forParent, Callback cb) {
    if (forParent == null) {
        throw new IllegalArgumentException("Parent view may not be null");
    }
    if (cb == null) {
        throw new IllegalArgumentException("Callback may not be null");
    }

    mParentView = forParent;
    mCallback = cb;

    final ViewConfiguration vc = ViewConfiguration.get(context);
    final float density = context.getResources().getDisplayMetrics().density;
    mEdgeSize = (int) (EDGE_SIZE * density + 0.5f);

    mTouchSlop = vc.getScaledTouchSlop();
    mMaxVelocity = vc.getScaledMaximumFlingVelocity();
    mMinVelocity = vc.getScaledMinimumFlingVelocity();
    //mScroller = ScrollerCompat.create(context, sInterpolator);
    mScroller = new Scroller(context, sInterpolator);
}