Search in sources :

Example 61 with ViewConfiguration

use of android.view.ViewConfiguration in project SunDay by iQuick.

the class SwipeListView method init.

/**
     * Init ListView
     *
     * @param attrs AttributeSet
     */
private void init(AttributeSet attrs) {
    int swipeMode = SWIPE_MODE_BOTH;
    boolean swipeOpenOnLongPress = true;
    boolean swipeCloseAllItemsWhenMoveList = true;
    long swipeAnimationTime = 0;
    float swipeOffsetLeft = 0;
    float swipeOffsetRight = 0;
    int swipeDrawableChecked = 0;
    int swipeDrawableUnchecked = 0;
    int swipeActionLeft = SWIPE_ACTION_REVEAL;
    int swipeActionRight = SWIPE_ACTION_REVEAL;
    if (attrs != null) {
        TypedArray styled = getContext().obtainStyledAttributes(attrs, R.styleable.SwipeListView);
        swipeMode = styled.getInt(R.styleable.SwipeListView_swipeMode, SWIPE_MODE_BOTH);
        swipeActionLeft = styled.getInt(R.styleable.SwipeListView_swipeActionLeft, SWIPE_ACTION_REVEAL);
        swipeActionRight = styled.getInt(R.styleable.SwipeListView_swipeActionRight, SWIPE_ACTION_REVEAL);
        swipeOffsetLeft = styled.getDimension(R.styleable.SwipeListView_swipeOffsetLeft, 0);
        swipeOffsetRight = styled.getDimension(R.styleable.SwipeListView_swipeOffsetRight, 0);
        swipeOpenOnLongPress = styled.getBoolean(R.styleable.SwipeListView_swipeOpenOnLongPress, true);
        swipeAnimationTime = styled.getInteger(R.styleable.SwipeListView_swipeAnimationTime, 0);
        swipeCloseAllItemsWhenMoveList = styled.getBoolean(R.styleable.SwipeListView_swipeCloseAllItemsWhenMoveList, true);
        swipeDrawableChecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableChecked, 0);
        swipeDrawableUnchecked = styled.getResourceId(R.styleable.SwipeListView_swipeDrawableUnchecked, 0);
        swipeFrontView = styled.getResourceId(R.styleable.SwipeListView_swipeFrontView, 0);
        swipeBackView = styled.getResourceId(R.styleable.SwipeListView_swipeBackView, 0);
    }
    if (swipeFrontView == 0 || swipeBackView == 0) {
        swipeFrontView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_FRONT_VIEW, "id", getContext().getPackageName());
        swipeBackView = getContext().getResources().getIdentifier(SWIPE_DEFAULT_BACK_VIEW, "id", getContext().getPackageName());
        if (swipeFrontView == 0 || swipeBackView == 0) {
            throw new RuntimeException(String.format("You forgot the attributes swipeFrontView or swipeBackView. You can add this attributes or use '%s' and '%s' identifiers", SWIPE_DEFAULT_FRONT_VIEW, SWIPE_DEFAULT_BACK_VIEW));
        }
    }
    final ViewConfiguration configuration = ViewConfiguration.get(getContext());
    touchSlop = ViewConfigurationCompat.getScaledPagingTouchSlop(configuration);
    touchListener = new SwipeListViewTouchListener(this, swipeFrontView, swipeBackView);
    if (swipeAnimationTime > 0) {
        touchListener.setAnimationTime(swipeAnimationTime);
    }
    touchListener.setRightOffset(swipeOffsetRight);
    touchListener.setLeftOffset(swipeOffsetLeft);
    touchListener.setSwipeActionLeft(swipeActionLeft);
    touchListener.setSwipeActionRight(swipeActionRight);
    touchListener.setSwipeMode(swipeMode);
    touchListener.setSwipeClosesAllItemsWhenListMoves(swipeCloseAllItemsWhenMoveList);
    touchListener.setSwipeOpenOnLongPress(swipeOpenOnLongPress);
    touchListener.setSwipeDrawableChecked(swipeDrawableChecked);
    touchListener.setSwipeDrawableUnchecked(swipeDrawableUnchecked);
    setOnTouchListener(touchListener);
    setOnScrollListener(touchListener.makeScrollListener());
}
Also used : ViewConfiguration(android.view.ViewConfiguration) TypedArray(android.content.res.TypedArray)

Example 62 with ViewConfiguration

use of android.view.ViewConfiguration in project FreeFlow by Comcast.

the class FreeFlowContainer method init.

@Override
protected void init(Context context) {
    viewpool = new ViewPool();
    frames = new LinkedHashMap<Object, FreeFlowItem>();
    ViewConfiguration configuration = ViewConfiguration.get(context);
    maxFlingVelocity = configuration.getScaledMaximumFlingVelocity();
    minFlingVelocity = configuration.getScaledMinimumFlingVelocity();
    overflingDistance = configuration.getScaledOverflingDistance();
    /*overscrollDistance = configuration.getScaledOverscrollDistance();*/
    touchSlop = configuration.getScaledTouchSlop();
    scroller = new OverScroller(context);
    setEdgeEffectsEnabled(true);
}
Also used : ViewConfiguration(android.view.ViewConfiguration) OverScroller(android.widget.OverScroller)

Example 63 with ViewConfiguration

use of android.view.ViewConfiguration in project android_packages_apps_Launcher2 by CyanogenMod.

the class DeleteDropTarget method onFlingToDelete.

public void onFlingToDelete(final DragObject d, int x, int y, PointF vel) {
    final boolean isAllApps = d.dragSource instanceof AppsCustomizePagedView;
    // Don't highlight the icon as it's animating
    d.dragView.setColor(0);
    d.dragView.updateInitialScaleToCurrentScale();
    // Don't highlight the target if we are flinging from AllApps
    if (isAllApps) {
        resetHoverColor();
    }
    if (mFlingDeleteMode == MODE_FLING_DELETE_TO_TRASH) {
        // Defer animating out the drop target if we are animating to it
        mSearchDropTargetBar.deferOnDragEnd();
        mSearchDropTargetBar.finishAnimations();
    }
    final ViewConfiguration config = ViewConfiguration.get(mLauncher);
    final DragLayer dragLayer = mLauncher.getDragLayer();
    final int duration = FLING_DELETE_ANIMATION_DURATION;
    final long startTime = AnimationUtils.currentAnimationTimeMillis();
    // NOTE: Because it takes time for the first frame of animation to actually be
    // called and we expect the animation to be a continuation of the fling, we have
    // to account for the time that has elapsed since the fling finished.  And since
    // we don't have a startDelay, we will always get call to update when we call
    // start() (which we want to ignore).
    final TimeInterpolator tInterpolator = new TimeInterpolator() {

        private int mCount = -1;

        private float mOffset = 0f;

        @Override
        public float getInterpolation(float t) {
            if (mCount < 0) {
                mCount++;
            } else if (mCount == 0) {
                mOffset = Math.min(0.5f, (float) (AnimationUtils.currentAnimationTimeMillis() - startTime) / duration);
                mCount++;
            }
            return Math.min(1f, mOffset + t);
        }
    };
    AnimatorUpdateListener updateCb = null;
    if (mFlingDeleteMode == MODE_FLING_DELETE_TO_TRASH) {
        updateCb = createFlingToTrashAnimatorListener(dragLayer, d, vel, config);
    } else if (mFlingDeleteMode == MODE_FLING_DELETE_ALONG_VECTOR) {
        updateCb = createFlingAlongVectorAnimatorListener(dragLayer, d, vel, startTime, duration, config);
    }
    Runnable onAnimationEndRunnable = new Runnable() {

        @Override
        public void run() {
            mSearchDropTargetBar.onDragEnd();
            // itself, otherwise, complete the drop to initiate the deletion process
            if (!isAllApps) {
                mLauncher.exitSpringLoadedDragMode();
                completeDrop(d);
            }
            mLauncher.getDragController().onDeferredEndFling(d);
        }
    };
    dragLayer.animateView(d.dragView, updateCb, duration, tInterpolator, onAnimationEndRunnable, DragLayer.ANIMATION_END_DISAPPEAR, null);
}
Also used : ViewConfiguration(android.view.ViewConfiguration) AnimatorUpdateListener(android.animation.ValueAnimator.AnimatorUpdateListener) TimeInterpolator(android.animation.TimeInterpolator)

Example 64 with ViewConfiguration

use of android.view.ViewConfiguration in project android_packages_apps_Launcher2 by CyanogenMod.

the class DragController method isFlingingToDelete.

/**
     * Determines whether the user flung the current item to delete it.
     *
     * @return the vector at which the item was flung, or null if no fling was detected.
     */
private PointF isFlingingToDelete(DragSource source) {
    if (mFlingToDeleteDropTarget == null)
        return null;
    if (!source.supportsFlingToDelete())
        return null;
    ViewConfiguration config = ViewConfiguration.get(mLauncher);
    mVelocityTracker.computeCurrentVelocity(1000, config.getScaledMaximumFlingVelocity());
    if (mVelocityTracker.getYVelocity() < mFlingToDeleteThresholdVelocity) {
        // Do a quick dot product test to ensure that we are flinging upwards
        PointF vel = new PointF(mVelocityTracker.getXVelocity(), mVelocityTracker.getYVelocity());
        PointF upVec = new PointF(0f, -1f);
        float theta = (float) Math.acos(((vel.x * upVec.x) + (vel.y * upVec.y)) / (vel.length() * upVec.length()));
        if (theta <= Math.toRadians(MAX_FLING_DEGREES)) {
            return vel;
        }
    }
    return null;
}
Also used : ViewConfiguration(android.view.ViewConfiguration) PointF(android.graphics.PointF)

Example 65 with ViewConfiguration

use of android.view.ViewConfiguration in project Wallpaper-Manager by Bencodes.

the class PhotoView method init.

private void init(Context context) {
    mScaleDetector = VersionedGestureDetector.newInstance(context, this);
    mGestureDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener());
    mGestureDetector.setOnDoubleTapListener(this);
    final ViewConfiguration configuration = ViewConfiguration.get(context);
    mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
}
Also used : ViewConfiguration(android.view.ViewConfiguration) GestureDetector(android.view.GestureDetector)

Aggregations

ViewConfiguration (android.view.ViewConfiguration)186 Scroller (android.widget.Scroller)41 Context (android.content.Context)28 TypedArray (android.content.res.TypedArray)23 EdgeEffectCompat (android.support.v4.widget.EdgeEffectCompat)16 Point (android.graphics.Point)12 View (android.view.View)12 OverScroller (android.widget.OverScroller)10 Field (java.lang.reflect.Field)9 Resources (android.content.res.Resources)8 Paint (android.graphics.Paint)7 RectF (android.graphics.RectF)7 DisplayMetrics (android.util.DisplayMetrics)7 Drawable (android.graphics.drawable.Drawable)6 GestureDetector (android.view.GestureDetector)6 PointF (android.graphics.PointF)5 ImageView (android.widget.ImageView)5 FlingAnimationUtils (com.android.systemui.statusbar.FlingAnimationUtils)5 SlidingTabLayout (com.google.samples.apps.iosched.ui.widget.SlidingTabLayout)4 TimeInterpolator (android.animation.TimeInterpolator)3