Example usage for android.view ViewConfiguration getScaledPagingTouchSlop

List of usage examples for android.view ViewConfiguration getScaledPagingTouchSlop

Introduction

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

Prototype

public int getScaledPagingTouchSlop() 

Source Link

Usage

From source file:com.ichi2.anki.AnkiDroidApp.java

/**
 * On application creation./*w  w w .j a  v  a  2s  .com*/
 */
@Override
public void onCreate() {
    super.onCreate();
    // Get preferences
    SharedPreferences preferences = getSharedPrefs(this);

    // Initialize crash reporting module
    ACRA.init(this);

    // Setup logging and crash reporting
    if (BuildConfig.DEBUG) {
        // Enable verbose error logging and do method tracing to put the Class name as log tag
        Timber.plant(new Timber.DebugTree());
        // Disable crash reporting
        setAcraReportingMode(FEEDBACK_REPORT_NEVER);
        preferences.edit().putString("reportErrorMode", FEEDBACK_REPORT_NEVER).commit();
        // Use a wider logcat filter incase crash reporting manually re-enabled
        String[] logcatArgs = { "-t", "300", "-v", "long", "ACRA:S" };
        ACRA.getConfig().setLogcatArguments(logcatArgs);
    } else {
        // Disable verbose error logging and use fixed log tag "AnkiDroid"
        Timber.plant(new ProductionCrashReportingTree());
        // Enable or disable crash reporting based on user setting
        setAcraReportingMode(preferences.getString("reportErrorMode", FEEDBACK_REPORT_ASK));
    }
    Timber.tag(TAG);

    sInstance = this;
    setLanguage(preferences.getString(Preferences.LANGUAGE, ""));

    // Configure WebView to allow file scheme pages to access cookies.
    CompatHelper.getCompat().enableCookiesForFileSchemePages();

    // Prepare Cookies to be synchronized between RAM and permanent storage.
    CompatHelper.getCompat().prepareWebViewCookies(this.getApplicationContext());

    // Set good default values for swipe detection
    final ViewConfiguration vc = ViewConfiguration.get(this);
    DEFAULT_SWIPE_MIN_DISTANCE = vc.getScaledPagingTouchSlop();
    DEFAULT_SWIPE_THRESHOLD_VELOCITY = vc.getScaledMinimumFlingVelocity();

    // Create the AnkiDroid directory if missing. Send exception report if inaccessible.
    if (CollectionHelper.hasStorageAccessPermission(this)) {
        try {
            String dir = CollectionHelper.getCurrentAnkiDroidDirectory(this);
            CollectionHelper.initializeAnkiDroidDirectory(dir);
        } catch (StorageAccessException e) {
            Timber.e(e, "Could not initialize AnkiDroid directory");
            String defaultDir = CollectionHelper.getDefaultAnkiDroidDirectory();
            if (isSdCardMounted() && CollectionHelper.getCurrentAnkiDroidDirectory(this).equals(defaultDir)) {
                // Don't send report if the user is using a custom directory as SD cards trip up here a lot
                sendExceptionReport(e, "AnkiDroidApp.onCreate");
            }
        }
    }
}

From source file:com.android.messaging.ui.conversationlist.ConversationListSwipeHelper.java

public ConversationListSwipeHelper(final RecyclerView recyclerView) {
    mRecyclerView = recyclerView;/*from   ww w  . j ava2 s.  co  m*/

    final Context context = mRecyclerView.getContext();
    final Resources res = context.getResources();
    mDefaultRestoreAnimationDuration = res.getInteger(R.integer.swipe_duration_ms);
    mDefaultDismissAnimationDuration = res.getInteger(R.integer.swipe_duration_ms);
    mMaxTranslationAnimationDuration = res.getInteger(R.integer.swipe_duration_ms);

    final ViewConfiguration viewConfiguration = ViewConfiguration.get(context);
    mTouchSlop = viewConfiguration.getScaledPagingTouchSlop();
    mMaximumFlingVelocity = Math.min(viewConfiguration.getScaledMaximumFlingVelocity(),
            res.getInteger(R.integer.swipe_max_fling_velocity_px_per_s));
    mMinimumFlingVelocity = viewConfiguration.getScaledMinimumFlingVelocity();
}

From source file:com.zac4j.widget.CircleIndicator.java

public CircleIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;/*from   www. ja  v a2  s.  c  o  m*/

    //Load defaults from resources
    final Resources res = getResources();
    final int defaultPageColor = ContextCompat.getColor(context, R.color.default_circle_indicator_page_color);
    final int defaultFillColor = ContextCompat.getColor(context, R.color.default_circle_indicator_fill_color);
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    final int defaultStrokeColor = ContextCompat.getColor(context,
            R.color.default_circle_indicator_stroke_color);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CirclePagerIndicator, defStyle, 0);

    mCentered = a.getBoolean(R.styleable.CirclePagerIndicator_centered, defaultCentered);
    mOrientation = a.getInt(R.styleable.CirclePagerIndicator_android_orientation, defaultOrientation);
    mPaintPageFill.setStyle(Style.FILL);
    mPaintPageFill.setColor(a.getColor(R.styleable.CirclePagerIndicator_pageColor, defaultPageColor));
    mPaintStroke.setStyle(Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CirclePagerIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke
            .setStrokeWidth(a.getDimension(R.styleable.CirclePagerIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill.setStyle(Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CirclePagerIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(R.styleable.CirclePagerIndicator_radius, defaultRadius);
    mSnap = a.getBoolean(R.styleable.CirclePagerIndicator_snap, defaultSnap);

    Drawable background = a.getDrawable(R.styleable.CirclePagerIndicator_android_background);
    if (background != null) {
        setBackground(background);
    }

    a.recycle();

    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = configuration.getScaledPagingTouchSlop();
}

From source file:com.farukcankaya.rtlviewpagerindicator.CircleIndicator.java

public CircleIndicator(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    if (isInEditMode())
        return;//w  w w  .  j  av  a2s.  com

    //Load defaults from resources
    final Resources res = getResources();
    final int defaultPageColor = ContextCompat.getColor(context, R.color.default_circle_indicator_page_color);
    final int defaultFillColor = ContextCompat.getColor(context, R.color.default_circle_indicator_fill_color);
    final int defaultOrientation = res.getInteger(R.integer.default_circle_indicator_orientation);
    final int defaultStrokeColor = ContextCompat.getColor(context,
            R.color.default_circle_indicator_stroke_color);
    final float defaultStrokeWidth = res.getDimension(R.dimen.default_circle_indicator_stroke_width);
    final float defaultRadius = res.getDimension(R.dimen.default_circle_indicator_radius);
    final boolean defaultCentered = res.getBoolean(R.bool.default_circle_indicator_centered);
    final boolean defaultSnap = res.getBoolean(R.bool.default_circle_indicator_snap);

    //Retrieve styles attributes
    TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.CircleIndicator, defStyle, 0);

    mCentered = a.getBoolean(R.styleable.CircleIndicator_centered, defaultCentered);
    mOrientation = a.getInt(R.styleable.CircleIndicator_android_orientation, defaultOrientation);
    mPaintPageFill.setStyle(Paint.Style.FILL);
    mPaintPageFill.setColor(a.getColor(R.styleable.CircleIndicator_pageColor, defaultPageColor));
    mPaintStroke.setStyle(Paint.Style.STROKE);
    mPaintStroke.setColor(a.getColor(R.styleable.CircleIndicator_strokeColor, defaultStrokeColor));
    mPaintStroke.setStrokeWidth(a.getDimension(R.styleable.CircleIndicator_strokeWidth, defaultStrokeWidth));
    mPaintFill.setStyle(Paint.Style.FILL);
    mPaintFill.setColor(a.getColor(R.styleable.CircleIndicator_fillColor, defaultFillColor));
    mRadius = a.getDimension(R.styleable.CircleIndicator_radius, defaultRadius);
    mSnap = a.getBoolean(R.styleable.CircleIndicator_snap, defaultSnap);

    Drawable background = a.getDrawable(R.styleable.CircleIndicator_android_background);
    if (background != null) {
        if (Build.VERSION.SDK_INT >= 16) {
            setBackground(background);
        } else {
            setBackgroundDrawable(background);
        }
    }
    a.recycle();
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mTouchSlop = configuration.getScaledPagingTouchSlop();
}

From source file:com.android.launcher2.PagedView.java

/**
 * Initializes various states for this workspace.
 */// w  w  w .j  a va  2  s .c om
protected void init() {
    mDirtyPageContent = new ArrayList<Boolean>();
    mDirtyPageContent.ensureCapacity(32);
    mScroller = new Scroller(getContext(), new ScrollInterpolator());
    mCurrentPage = 0;
    mCenterPagesVertically = true;

    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    mTouchSlop = configuration.getScaledTouchSlop();
    mPagingTouchSlop = configuration.getScaledPagingTouchSlop();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mDensity = getResources().getDisplayMetrics().density;

    mFlingThresholdVelocity = (int) (FLING_THRESHOLD_VELOCITY * mDensity);
    mMinFlingVelocity = (int) (MIN_FLING_VELOCITY * mDensity);
    mMinSnapVelocity = (int) (MIN_SNAP_VELOCITY * mDensity);
    setOnHierarchyChangeListener(this);
}

From source file:de.tum.in.tumcampus.auxiliary.calendar.DayView.java

public DayView(Context context, CalendarController controller, ViewSwitcher viewSwitcher,
        EventLoader eventLoader, int numDays) {
    super(context);
    mContext = context;//from  w  ww  .  ja v a  2 s .c o  m

    mResources = context.getResources();
    mNumDays = numDays;

    DATE_HEADER_FONT_SIZE = (int) mResources.getDimension(R.dimen.date_header_text_size);
    DAY_HEADER_FONT_SIZE = (int) mResources.getDimension(R.dimen.day_label_text_size);
    DAY_HEADER_HEIGHT = (int) mResources.getDimension(R.dimen.day_header_height);
    DAY_HEADER_BOTTOM_MARGIN = (int) mResources.getDimension(R.dimen.day_header_bottom_margin);
    HOURS_TEXT_SIZE = (int) mResources.getDimension(R.dimen.hours_text_size);
    AMPM_TEXT_SIZE = (int) mResources.getDimension(R.dimen.ampm_text_size);
    MIN_HOURS_WIDTH = (int) mResources.getDimension(R.dimen.min_hours_width);
    HOURS_LEFT_MARGIN = (int) mResources.getDimension(R.dimen.hours_left_margin);
    HOURS_RIGHT_MARGIN = (int) mResources.getDimension(R.dimen.hours_right_margin);
    int eventTextSizeId;
    if (mNumDays == 1) {
        eventTextSizeId = R.dimen.day_view_event_text_size;
    } else {
        eventTextSizeId = R.dimen.week_view_event_text_size;
    }
    EVENT_TEXT_FONT_SIZE = (int) mResources.getDimension(eventTextSizeId);
    MIN_EVENT_HEIGHT = mResources.getDimension(R.dimen.event_min_height);
    EVENT_TEXT_TOP_MARGIN = (int) mResources.getDimension(R.dimen.event_text_vertical_margin);
    EVENT_TEXT_BOTTOM_MARGIN = EVENT_TEXT_TOP_MARGIN;

    EVENT_TEXT_LEFT_MARGIN = (int) mResources.getDimension(R.dimen.event_text_horizontal_margin);
    EVENT_TEXT_RIGHT_MARGIN = EVENT_TEXT_LEFT_MARGIN;

    if (mScale == 0) {

        mScale = mResources.getDisplayMetrics().density;
        if (mScale != 1) {

            GRID_LINE_LEFT_MARGIN *= mScale;
            HOURS_TOP_MARGIN *= mScale;
            MIN_CELL_WIDTH_FOR_TEXT *= mScale;

            CURRENT_TIME_LINE_SIDE_BUFFER *= mScale;
            CURRENT_TIME_LINE_TOP_OFFSET *= mScale;

            MIN_Y_SPAN *= mScale;
            MAX_CELL_HEIGHT *= mScale;
            DEFAULT_CELL_HEIGHT *= mScale;
            DAY_HEADER_RIGHT_MARGIN *= mScale;
            DAY_HEADER_ONE_DAY_LEFT_MARGIN *= mScale;
            DAY_HEADER_ONE_DAY_RIGHT_MARGIN *= mScale;
            DAY_HEADER_ONE_DAY_BOTTOM_MARGIN *= mScale;
            EVENT_RECT_TOP_MARGIN *= mScale;
            EVENT_RECT_BOTTOM_MARGIN *= mScale;
            EVENT_RECT_LEFT_MARGIN *= mScale;
            EVENT_RECT_RIGHT_MARGIN *= mScale;
            EVENT_RECT_STROKE_WIDTH *= mScale;
        }
    }
    HOURS_MARGIN = HOURS_LEFT_MARGIN + HOURS_RIGHT_MARGIN;

    mCurrentTimeLine = mResources.getDrawable(R.drawable.timeline_indicator_holo_light);
    mCurrentTimeAnimateLine = mResources.getDrawable(R.drawable.timeline_indicator_activated_holo_light);
    mTodayHeaderDrawable = mResources.getDrawable(R.drawable.today_blue_week_holo_light);
    mAcceptedOrTentativeEventBoxDrawable = mResources.getDrawable(R.drawable.panel_month_event_holo_light);

    mEventLoader = eventLoader;
    mEventGeometry = new EventGeometry();
    mEventGeometry.setMinEventHeight(MIN_EVENT_HEIGHT);
    mEventGeometry.setHourGap(HOUR_GAP);
    mEventGeometry.setCellMargin(DAY_GAP);
    mController = controller;
    mViewSwitcher = viewSwitcher;
    mGestureDetector = new GestureDetector(context, new CalendarGestureListener());
    mScaleGestureDetector = new ScaleGestureDetector(getContext(), this);
    if (mCellHeight == 0) {
        mCellHeight = DEFAULT_CELL_HEIGHT;
    }
    mScroller = new OverScroller(context);
    mHScrollInterpolator = new ScrollInterpolator();
    mEdgeEffectTop = new EdgeEffectCompat(context);
    mEdgeEffectBottom = new EdgeEffectCompat(context);
    ViewConfiguration vc = ViewConfiguration.get(context);
    mScaledPagingTouchSlop = vc.getScaledPagingTouchSlop();
    mOnDownDelay = ViewConfiguration.getTapTimeout();
    OVERFLING_DISTANCE = vc.getScaledOverflingDistance();

    init(context);
}

From source file:cc.flydev.launcher.Page.java

/**
 * Initializes various states for this workspace.
 *///  w w w  .j a  va  2 s .  co m
protected void init() {
    mDirtyPageContent = new ArrayList<Boolean>();
    mDirtyPageContent.ensureCapacity(32);
    mScroller = new Scroller(getContext(), new ScrollInterpolator());
    mCurrentPage = 0;
    mCenterPagesVertically = true;

    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    mTouchSlop = configuration.getScaledPagingTouchSlop();
    mPagingTouchSlop = configuration.getScaledPagingTouchSlop();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mDensity = getResources().getDisplayMetrics().density;

    // Scale the fling-to-delete threshold by the density
    mFlingToDeleteThresholdVelocity = (int) (mFlingToDeleteThresholdVelocity * mDensity);

    mFlingThresholdVelocity = (int) (FLING_THRESHOLD_VELOCITY * mDensity);
    mMinFlingVelocity = (int) (MIN_FLING_VELOCITY * mDensity);
    mMinSnapVelocity = (int) (MIN_SNAP_VELOCITY * mDensity);
    setOnHierarchyChangeListener(this);
}

From source file:us.shandian.launcher.Page.java

/**
 * Initializes various states for this workspace.
 *///from   w w  w  .  j  a va2 s  .  co m
protected void init() {
    mDirtyPageContent = new ArrayList<Boolean>();
    mDirtyPageContent.ensureCapacity(32);
    mScroller = new Scroller(getContext(), new ScrollInterpolator());
    mCurrentPage = 0;
    mCenterPagesVertically = true;

    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    mTouchSlop = configuration.getScaledPagingTouchSlop();
    mPagingTouchSlop = configuration.getScaledPagingTouchSlop();
    mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
    mDensity = getResources().getDisplayMetrics().density;

    // Scale the fling-to-delete threshold by the density
    mFlingToDeleteThresholdVelocity = (int) (mFlingToDeleteThresholdVelocity * mDensity);

    mFlingThresholdVelocity = (int) (FLING_THRESHOLD_VELOCITY * mDensity);
    mMinFlingVelocity = (int) (MIN_FLING_VELOCITY * mDensity);
    mMinSnapVelocity = (int) (MIN_SNAP_VELOCITY * mDensity);
    setOnHierarchyChangeListener(this);

}

From source file:com.android.internal.widget.ViewPager.java

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

    setWillNotDraw(false);// ww w.j  av  a2 s  .  c  o m
    setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
    setFocusable(true);

    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 EdgeEffect(context);
    mRightEdge = new EdgeEffect(context);

    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
    mCloseEnough = (int) (CLOSE_ENOUGH * density);
    mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density);

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

From source file:com.example.sky.test.view.ViewPager.java

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

    mFlingDistance = (int) (MIN_DISTANCE_FOR_FLING * density);
    mCloseEnough = (int) (CLOSE_ENOUGH * density);
    mDefaultGutterSize = (int) (DEFAULT_GUTTER_SIZE * density);

    ViewCompat.setAccessibilityDelegate(this, new ViewPager.MyAccessibilityDelegate());

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

    ViewCompat.setOnApplyWindowInsetsListener(this, new android.support.v4.view.OnApplyWindowInsetsListener() {
        private final Rect mTempRect = new Rect();

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

            // Now we'll manually dispatch the insets to our children. Since ViewPager
            // children are always full-height, we do not want to use the standard
            // ViewGroup dispatchApplyWindowInsets since if child 0 consumes them,
            // the rest of the children will not receive any insets. To workaround this
            // we manually dispatch the applied insets, not allowing children to
            // consume them from each other. We do however keep track of any insets
            // which are consumed, returning the union of our children's consumption
            final Rect res = mTempRect;
            res.left = applied.getSystemWindowInsetLeft();
            res.top = applied.getSystemWindowInsetTop();
            res.right = applied.getSystemWindowInsetRight();
            res.bottom = applied.getSystemWindowInsetBottom();

            for (int i = 0, count = getChildCount(); i < count; i++) {
                final WindowInsetsCompat childInsets = ViewCompat.dispatchApplyWindowInsets(getChildAt(i),
                        applied);
                // Now keep track of any consumed by tracking each dimension's min
                // value
                res.left = Math.min(childInsets.getSystemWindowInsetLeft(), res.left);
                res.top = Math.min(childInsets.getSystemWindowInsetTop(), res.top);
                res.right = Math.min(childInsets.getSystemWindowInsetRight(), res.right);
                res.bottom = Math.min(childInsets.getSystemWindowInsetBottom(), res.bottom);
            }

            // Now return a new WindowInsets, using the consumed window insets
            return applied.replaceSystemWindowInsets(res.left, res.top, res.right, res.bottom);
        }
    });
}