Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0aa58a94 authored by Amit Kumar's avatar Amit Kumar
Browse files

Add swipe to search and change folder animation

parent 49dc8fd0
Loading
Loading
Loading
Loading
+10 −1
Original line number Original line Diff line number Diff line
@@ -7,7 +7,7 @@ android {
        minSdkVersion rootProject.ext.minSdkVersion
        minSdkVersion rootProject.ext.minSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        targetSdkVersion rootProject.ext.targetSdkVersion
        versionCode 1
        versionCode 1
        versionName "1.0"
        versionName "1.0.0-alpha"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"


        renderscriptTargetApi 18
        renderscriptTargetApi 18
@@ -22,6 +22,15 @@ android {
            applicationIdSuffix '.debug'
            applicationIdSuffix '.debug'
            signingConfig signingConfigs.debug
            signingConfig signingConfigs.debug
        }
        }

        applicationVariants.all { variant ->
            if (variant.buildType.name == "debug") {
                variant.outputs.all { output ->
                    outputFileName = "BlissLauncher-${variant.getFlavorName()}-${variant.versionName}.apk"
                }
            }

        }
    }
    }


    signingConfigs {
    signingConfigs {
+38 −8
Original line number Original line Diff line number Diff line
@@ -7,6 +7,7 @@ import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.Rect;
import android.os.Parcel;
import android.os.Parcel;
import android.os.Parcelable;
import android.os.Parcelable;
import android.support.v4.view.GestureDetectorCompat;
import android.util.AttributeSet;
import android.util.AttributeSet;
import android.util.Log;
import android.util.Log;
import android.view.MotionEvent;
import android.view.MotionEvent;
@@ -22,6 +23,9 @@ import java.util.HashSet;
import java.util.Set;
import java.util.Set;


import foundation.e.blisslauncher.R;
import foundation.e.blisslauncher.R;
import foundation.e.blisslauncher.features.launcher.DetectSwipeGestureListener;
import foundation.e.blisslauncher.features.launcher.LauncherActivity;
import foundation.e.blisslauncher.features.launcher.OnSwipeDownListener;


public class HorizontalPager extends ViewGroup {
public class HorizontalPager extends ViewGroup {
    private static final String TAG = "HorizontalPager";
    private static final String TAG = "HorizontalPager";
@@ -47,7 +51,8 @@ public class HorizontalPager extends ViewGroup {
    private float mLastMotionY;
    private float mLastMotionY;


    private final static int TOUCH_STATE_REST = 0;
    private final static int TOUCH_STATE_REST = 0;
    private final static int TOUCH_STATE_SCROLLING = 1;
    private final static int TOUCH_STATE_HORIZONTAL_SCROLLING = 1;
    private final static int TOUCH_STATE_VERTICAL_SCROLLING = 2;


    private int mTouchState = TOUCH_STATE_REST;
    private int mTouchState = TOUCH_STATE_REST;


@@ -56,6 +61,7 @@ public class HorizontalPager extends ViewGroup {


    private Set<OnScrollListener> mListeners = new HashSet<>();
    private Set<OnScrollListener> mListeners = new HashSet<>();
    private boolean mIsUiCreated;
    private boolean mIsUiCreated;
    private GestureDetectorCompat gestureDetectorCompat;


    public HorizontalPager(Context context, AttributeSet attrs) {
    public HorizontalPager(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
        this(context, attrs, 0);
@@ -80,6 +86,16 @@ public class HorizontalPager extends ViewGroup {
        final ViewConfiguration configuration = ViewConfiguration.get(getContext());
        final ViewConfiguration configuration = ViewConfiguration.get(getContext());
        mTouchSlop = configuration.getScaledTouchSlop();
        mTouchSlop = configuration.getScaledTouchSlop();
        mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
        mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();

        // Create a common gesture listener object.
        DetectSwipeGestureListener gestureListener = new DetectSwipeGestureListener();

        // Set activity in the listener.
        if (getContext() instanceof LauncherActivity) {
            gestureListener.setListener((OnSwipeDownListener) getContext());
        }

        gestureDetectorCompat = new GestureDetectorCompat(getContext(), gestureListener);
    }
    }


    public void setDock(DockGridLayout dock) {
    public void setDock(DockGridLayout dock) {
@@ -279,7 +295,8 @@ public class HorizontalPager extends ViewGroup {
                 * otherwise don't.  mScroller.isFinished should be false when
                 * otherwise don't.  mScroller.isFinished should be false when
                 * being flinged.
                 * being flinged.
                 */
                 */
                mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST : TOUCH_STATE_SCROLLING;
                mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST
                        : TOUCH_STATE_HORIZONTAL_SCROLLING;
                break;
                break;


            case MotionEvent.ACTION_CANCEL:
            case MotionEvent.ACTION_CANCEL:
@@ -308,9 +325,12 @@ public class HorizontalPager extends ViewGroup {


        if (xMoved || yMoved) {
        if (xMoved || yMoved) {


            if (xMoved) {
            if (yMoved && (y - mLastMotionY) > 0 && yDiff > xDiff && currentPage != 0) {
                mTouchState = TOUCH_STATE_VERTICAL_SCROLLING;
                ((OnSwipeDownListener) getContext()).onSwipeStart();
            } else if (xMoved && yDiff < xDiff) {
                // Scroll if the user moved far enough along the X axis
                // Scroll if the user moved far enough along the X axis
                mTouchState = TOUCH_STATE_SCROLLING;
                mTouchState = TOUCH_STATE_HORIZONTAL_SCROLLING;
                enableChildrenCache();
                enableChildrenCache();
            }
            }
            // Either way, cancel any pending longpress
            // Either way, cancel any pending longpress
@@ -338,6 +358,11 @@ public class HorizontalPager extends ViewGroup {
    @SuppressLint("ClickableViewAccessibility")
    @SuppressLint("ClickableViewAccessibility")
    @Override
    @Override
    public boolean onTouchEvent(MotionEvent ev) {
    public boolean onTouchEvent(MotionEvent ev) {
        /*if (gestureDetectorCompat.onTouchEvent(ev)) {
            return true;
        } else {

        }*/
        if (mVelocityTracker == null) {
        if (mVelocityTracker == null) {
            mVelocityTracker = VelocityTracker.obtain();
            mVelocityTracker = VelocityTracker.obtain();
        }
        }
@@ -346,7 +371,6 @@ public class HorizontalPager extends ViewGroup {
        final int action = ev.getAction();
        final int action = ev.getAction();
        final float x = ev.getX();
        final float x = ev.getX();
        final float y = ev.getY();
        final float y = ev.getY();
        Log.i(TAG, "motion x: " + x);
        if (mIsUiCreated) {
        if (mIsUiCreated) {
            switch (action) {
            switch (action) {
                case MotionEvent.ACTION_DOWN:
                case MotionEvent.ACTION_DOWN:
@@ -360,11 +384,15 @@ public class HorizontalPager extends ViewGroup {


                    // Remember where the motion event started
                    // Remember where the motion event started
                    mLastMotionX = x;
                    mLastMotionX = x;
                    mLastMotionY = y;
                    break;
                    break;
                case MotionEvent.ACTION_MOVE:
                case MotionEvent.ACTION_MOVE:
                    if (mTouchState == TOUCH_STATE_REST) {
                    if (mTouchState == TOUCH_STATE_REST) {
                        checkStartScroll(x, y);
                        checkStartScroll(x, y);
                    } else if (mTouchState == TOUCH_STATE_SCROLLING) {
                    } else if (mTouchState == TOUCH_STATE_VERTICAL_SCROLLING) {
                        int diffY = (int) (y - mLastMotionY);
                        ((OnSwipeDownListener) getContext()).onSwipe(diffY);
                    } else if (mTouchState == TOUCH_STATE_HORIZONTAL_SCROLLING) {
                        // Scroll to follow the motion event
                        // Scroll to follow the motion event
                        int deltaX = (int) (mLastMotionX - x);
                        int deltaX = (int) (mLastMotionX - x);
                        mLastMotionX = x;
                        mLastMotionX = x;
@@ -384,7 +412,10 @@ public class HorizontalPager extends ViewGroup {
                    }
                    }
                    break;
                    break;
                case MotionEvent.ACTION_UP:
                case MotionEvent.ACTION_UP:
                    if (mTouchState == TOUCH_STATE_SCROLLING) {
                    if (mTouchState == TOUCH_STATE_VERTICAL_SCROLLING) {
                        ((OnSwipeDownListener) getContext()).onSwipeFinish();
                    }
                    if (mTouchState == TOUCH_STATE_HORIZONTAL_SCROLLING) {
                        final VelocityTracker velocityTracker = mVelocityTracker;
                        final VelocityTracker velocityTracker = mVelocityTracker;
                        velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
                        velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
                        int velocityX = (int) velocityTracker.getXVelocity();
                        int velocityX = (int) velocityTracker.getXVelocity();
@@ -409,7 +440,6 @@ public class HorizontalPager extends ViewGroup {
                    break;
                    break;
                case MotionEvent.ACTION_CANCEL:
                case MotionEvent.ACTION_CANCEL:
                    mTouchState = TOUCH_STATE_REST;
                    mTouchState = TOUCH_STATE_REST;

            }
            }
        }
        }


+63 −0
Original line number Original line Diff line number Diff line
package foundation.e.blisslauncher.features.launcher;

import android.view.GestureDetector;
import android.view.MotionEvent;

public class DetectSwipeGestureListener extends GestureDetector.SimpleOnGestureListener {

    // Minimal x and y axis swipe distance.
    private static int MIN_SWIPE_DISTANCE_X = 100;
    private static int MIN_SWIPE_DISTANCE_Y = 100;

    // Maximal x and y axis swipe distance.
    private static int MAX_SWIPE_DISTANCE_X = 1000;
    private static int MAX_SWIPE_DISTANCE_Y = 1000;

    // Source activity that display message in text view.
    private OnSwipeDownListener mOnSwipeDownListener = null;

    public void setListener(OnSwipeDownListener listener) {
        mOnSwipeDownListener = listener;
    }

    @Override
    public boolean onDown(MotionEvent e) {
        return true;
    }

    /* This method is invoked when a swipe gesture happened. */
    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {

        // Get swipe delta value in x axis.
        float deltaX = e1.getX() - e2.getX();

        // Get swipe delta value in y axis.
        float deltaY = e1.getY() - e2.getY();

        // Get absolute value.
        float deltaXAbs = Math.abs(deltaX);
        float deltaYAbs = Math.abs(deltaY);

        if ((deltaYAbs >= MIN_SWIPE_DISTANCE_Y) && (deltaYAbs <= MAX_SWIPE_DISTANCE_Y)) {
            if (deltaY < 0) {
                this.mOnSwipeDownListener.onSwipeFinish();
                return true;
            }
        }
        return false;
    }

    // Invoked when single tap screen.
    @Override
    public boolean onSingleTapConfirmed(MotionEvent e) {
        return false;
    }

    // Invoked when double tap screen.
    @Override
    public boolean onDoubleTap(MotionEvent e) {
        return false;
    }

}
+418 −139

File changed.

Preview size limit exceeded, changes collapsed.

+8 −0
Original line number Original line Diff line number Diff line
package foundation.e.blisslauncher.features.launcher;

public interface OnSwipeDownListener {

    void onSwipeStart();
    void onSwipe(int position);
    void onSwipeFinish();
}
Loading