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

Commit ec8d47c2 authored by Amit Kumar's avatar Amit Kumar
Browse files

Following fixes and improvements:

1. Widget becomes resizable.
2. Improved behaviour of home screen (i.e. Doesn't change previous screen when coming back from any app)
3. Fixes #109
parent 7705271f
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -44,6 +44,7 @@
            android:name=".features.launcher.LauncherActivity"
            android:clearTaskOnLaunch="true"
            android:launchMode="singleTask"
            android:resumeWhilePausing="true"
            android:screenOrientation="nosensor"
            android:stateNotNeeded="true"
            android:theme="@style/HomeScreenTheme"
+1 −3
Original line number Diff line number Diff line
@@ -19,8 +19,6 @@ public class BlissLauncher extends Application {
    private static WidgetHost sAppWidgetHost;
    private static AppWidgetManager sAppWidgetManager;

    private static int sLongPressTimeout = 300;

    private static final String TAG = "BlissLauncher";

    @Override
@@ -92,6 +90,6 @@ public class BlissLauncher extends Application {
    }

    public static long getLongPressTimeout() {
        return sLongPressTimeout;
        return 500;
    }
}
+3 −98
Original line number Diff line number Diff line
@@ -5,11 +5,9 @@ import android.appwidget.AppWidgetProviderInfo;
import android.content.Context;
import android.graphics.Rect;
import android.support.annotation.NonNull;
import android.view.Gravity;
import android.widget.FrameLayout;
import android.widget.ImageView;

import foundation.e.blisslauncher.BlissLauncher;
import foundation.e.blisslauncher.R;

public class AppWidgetResizeFrame extends FrameLayout {
@@ -58,6 +56,8 @@ public class AppWidgetResizeFrame extends FrameLayout {

    private Context mContext;

    private static final String TAG = "AppWidgetResizeFrame";


    public AppWidgetResizeFrame(@NonNull Context context, RoundedWidgetView widgetView) {
        super(context);
@@ -72,101 +72,6 @@ public class AppWidgetResizeFrame extends FrameLayout {

        setBackgroundResource(R.drawable.widget_resize_frame);
        setPadding(0, 0, 0, 0);

        LayoutParams lp;
        mTopHandle = new ImageView(context);
        mTopHandle.setImageResource(R.drawable.widget_resize_handle_top);
        lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
                Gravity.CENTER_HORIZONTAL | Gravity.TOP);
        addView(mTopHandle, lp);

        mBottomHandle = new ImageView(context);
        mBottomHandle.setImageResource(R.drawable.widget_resize_handle_bottom);
        lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT,
                Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM);
        addView(mBottomHandle, lp);

        Rect p = AppWidgetHostView.getDefaultPaddingForWidget(context,
                widgetView.getAppWidgetInfo().provider, null);
        mWidgetPaddingTop = p.top;
        mWidgetPaddingBottom = p.bottom;

        if (mResizeMode == AppWidgetProviderInfo.RESIZE_HORIZONTAL) {
            mTopHandle.setVisibility(GONE);
            mBottomHandle.setVisibility(GONE);
        }

        final float density = context.getResources().getDisplayMetrics().density;
        mBackgroundPadding = (int) Math.ceil(density * BACKGROUND_PADDING);
        mTouchTargetWidth = 2 * mBackgroundPadding;
    }

    public boolean beginResizeIfPointInRegion(int x, int y) {
        boolean horizontalActive = (mResizeMode & AppWidgetProviderInfo.RESIZE_HORIZONTAL) != 0;
        boolean verticalActive = (mResizeMode & AppWidgetProviderInfo.RESIZE_VERTICAL) != 0;

        mTopBorderActive = (y < mTouchTargetWidth + mTopTouchRegionAdjustment) && verticalActive;
        mBottomBorderActive = (y > getHeight() - mTouchTargetWidth + mBottomTouchRegionAdjustment)
                && verticalActive;

        boolean anyBordersActive = mTopBorderActive || mBottomBorderActive;

        mBaselineWidth = getMeasuredWidth();
        mBaselineHeight = getMeasuredHeight();
        mBaselineX = getLeft();
        mBaselineY = getTop();

        if (anyBordersActive) {
            mTopHandle.setAlpha(mTopBorderActive ? 1.0f : DIMMED_HANDLE_ALPHA);
            mBottomHandle.setAlpha(mBottomBorderActive ? 1.0f : DIMMED_HANDLE_ALPHA);
        }
        return anyBordersActive;
    }

    /**
     * Here we bound the deltas such that the frame cannot be stretched beyond the extents
     * of the CellLayout, and such that the frame's borders can't cross.
     */
    public void updateDeltas(int deltaX, int deltaY) {
        if (mTopBorderActive) {
            mDeltaY = Math.max(-mBaselineY, deltaY);
            mDeltaY = Math.min(mBaselineHeight - 2 * mTouchTargetWidth, mDeltaY);
        } else if (mBottomBorderActive) {
            mDeltaY = Math.min(BlissLauncher.getApplication(
                    mContext).getDeviceProfile().availableHeightPx - (mBaselineY + mBaselineHeight),
                    deltaY);
            mDeltaY = Math.max(-mBaselineHeight + 2 * mTouchTargetWidth, mDeltaY);
        }
    }

    public void visualizeResizeForDelta(int deltaX, int deltaY) {
        visualizeResizeForDelta(deltaX, deltaY, false);
    }

    /**
     * Based on the deltas, we resize the frame, and, if needed, we resize the widget.
     */
    private void visualizeResizeForDelta(int deltaX, int deltaY, boolean onDismiss) {
        updateDeltas(deltaX, deltaY);
       /* DragLayer.LayoutParams lp = (DragLayer.LayoutParams) getLayoutParams();

        if (mTopBorderActive) {
            lp.y = mBaselineY + mDeltaY;
            lp.height = mBaselineHeight - mDeltaY;
        } else if (mBottomBorderActive) {
            lp.height = mBaselineHeight + mDeltaY;
        }

        resizeWidgetIfNeeded(onDismiss);*/
        requestLayout();
    }

    /**
     * This is the final step of the resize. Here we save the new widget size and position
     * to LauncherModel and animate the resize frame.
     */
    public void commitResize() {
        //resizeWidgetIfNeeded(true);
        requestLayout();
        //setLayoutParams(mRoundedWidgetView.getLayoutParams());
    }
}
+73 −1
Original line number Diff line number Diff line
@@ -4,8 +4,14 @@ import android.appwidget.AppWidgetHostView;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Path;
import android.graphics.Rect;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.ImageView;

import foundation.e.blisslauncher.R;
import foundation.e.blisslauncher.features.widgets.CheckLongPressHelper;
@@ -15,10 +21,18 @@ public class RoundedWidgetView extends AppWidgetHostView {
    private final Path stencilPath = new Path();
    private float cornerRadius;
    private CheckLongPressHelper mLongPressHelper;
    private Context mContext;
    private static final String TAG = "RoundedWidgetView";
    private ImageView resizeBorder;

    private OnTouchListener _onTouchListener;
    private OnLongClickListener _longClick;
    private long _down;
    private boolean mChildrenFocused;

    public RoundedWidgetView(Context context) {
        super(context);
        this.mContext = context;
        this.cornerRadius = context.getResources().getDimensionPixelSize(R.dimen.corner_radius);
        mLongPressHelper = new CheckLongPressHelper(this);
    }
@@ -44,6 +58,11 @@ public class RoundedWidgetView extends AppWidgetHostView {

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        Log.d(TAG, "onInterceptTouchEvent() called with: ev = [" + ev.getAction() + "]");

        if (ev.getAction() == MotionEvent.ACTION_DOWN) {
            mLongPressHelper.cancelLongPress();
        }

        // Consume any touch events for ourselves after longpress is triggered
        if (mLongPressHelper.hasPerformedLongPress()) {
@@ -60,6 +79,9 @@ public class RoundedWidgetView extends AppWidgetHostView {
            }

            case MotionEvent.ACTION_UP:
                mLongPressHelper.cancelLongPress();
                break;

            case MotionEvent.ACTION_CANCEL:
                mLongPressHelper.cancelLongPress();
                break;
@@ -67,6 +89,7 @@ public class RoundedWidgetView extends AppWidgetHostView {

        // Otherwise continue letting touch events fall through to children
        return false;

    }

    @Override
@@ -78,6 +101,55 @@ public class RoundedWidgetView extends AppWidgetHostView {

    @Override
    public int getDescendantFocusability() {
        return ViewGroup.FOCUS_BLOCK_DESCENDANTS;
        return mChildrenFocused ? ViewGroup.FOCUS_BEFORE_DESCENDANTS
                : ViewGroup.FOCUS_BLOCK_DESCENDANTS;
    }

    @Override
    protected void onFocusChanged(boolean gainFocus, int direction,
            @Nullable Rect previouslyFocusedRect) {
        if (gainFocus) {
            mChildrenFocused = false;
            dispatchChildFocus(false);
        }
        super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
    }

    @Override
    public void requestChildFocus(View child, View focused) {
        super.requestChildFocus(child, focused);
        dispatchChildFocus(mChildrenFocused && focused != null);
        if (focused != null) {
            focused.setFocusableInTouchMode(false);
        }
    }

    @Override
    public boolean dispatchUnhandledMove(View focused, int direction) {
        return mChildrenFocused;
    }

    private void dispatchChildFocus(boolean childIsFocused) {
        // The host view's background changes when selected, to indicate the focus is inside.
        setSelected(childIsFocused);
    }

    public void addBorder() {
        if (resizeBorder != null) {
            removeBorder();
        }
        resizeBorder = new ImageView(mContext);
        resizeBorder.setImageResource(R.drawable.widget_resize_frame);
        FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        resizeBorder.setLayoutParams(layoutParams);
        addView(resizeBorder);
    }

    public void removeBorder() {
        if (resizeBorder != null) {
            removeView(resizeBorder);
            resizeBorder = null;
        }
    }
}
+16 −0
Original line number Diff line number Diff line
@@ -8,8 +8,10 @@ import java.util.List;
import foundation.e.blisslauncher.core.customviews.BlissFrameLayout;
import foundation.e.blisslauncher.core.database.model.FolderItem;
import foundation.e.blisslauncher.core.database.model.LauncherItem;
import foundation.e.blisslauncher.core.database.model.WidgetItem;
import foundation.e.blisslauncher.core.executors.AppExecutors;
import foundation.e.blisslauncher.core.utils.Constants;
import io.reactivex.Single;

public class DatabaseManager {

@@ -107,4 +109,18 @@ public class DatabaseManager {
        LauncherDB.getDatabase(mContext).launcherDao().updateComponent(old_component_name,
                new_component_name);
    }

    public Single<Integer> getHeightOfWidget(int id){
        return Single.defer(() -> Single.just(LauncherDB.getDatabase(mContext).widgetDao().getHeight(id)));
    }

    public void saveWidget(int id, int height){
        WidgetItem widgetItem = new WidgetItem(id, height);
        mAppExecutors.diskIO().execute(
                () -> LauncherDB.getDatabase(mContext).widgetDao().insert(widgetItem));
    }

    public void removeWidget(int id){
        mAppExecutors.diskIO().execute(() -> LauncherDB.getDatabase(mContext).widgetDao().delete(id));
    }
}
Loading