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

Commit 3dce5f3f authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Merging duplicate logic for deferred drop handling in Worksace and Folder

> All the logic is contained in UninstallDropTarget
> Also fixing a bug were mWaitingForResume was not cleared

Bug: 34692289
Change-Id: I617475ce53062902d6817954fb608198e6e03d3c
parent a9e345f8
Loading
Loading
Loading
Loading
+9 −1
Original line number Diff line number Diff line
@@ -42,6 +42,7 @@ import android.widget.TextView;

import com.android.launcher3.IconCache.IconLoadRequest;
import com.android.launcher3.IconCache.ItemInfoUpdateReceiver;
import com.android.launcher3.Launcher.OnResumeCallback;
import com.android.launcher3.badge.BadgeInfo;
import com.android.launcher3.badge.BadgeRenderer;
import com.android.launcher3.folder.FolderIcon;
@@ -59,7 +60,7 @@ import java.text.NumberFormat;
 * because we want to make the bubble taller than the text and TextView's clip is
 * too aggressive.
 */
public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver {
public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, OnResumeCallback {

    private static final int DISPLAY_WORKSPACE = 0;
    private static final int DISPLAY_ALL_APPS = 1;
@@ -330,6 +331,13 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver {
        refreshDrawableState();
    }

    @Override
    public void onLauncherResume() {
        // Reset the pressed state of icon that was locked in the press state while activity
        // was launching
        setStayPressed(false);
    }

    void clearPressedBackground() {
        setPressed(false);
        setStayPressed(false);
+1 −1
Original line number Diff line number Diff line
@@ -215,7 +215,7 @@ public abstract class ButtonDropTarget extends TextView
     * On drop animate the dropView to the icon.
     */
    @Override
    public void onDrop(final DragObject d) {
    public void onDrop(final DragObject d, final DragOptions options) {
        final DragLayer dragLayer = mLauncher.getDragLayer();
        final Rect from = new Rect();
        dragLayer.getViewRectRelativeToSelf(d.dragView, from);
+2 −1
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.launcher3;
import android.graphics.Rect;

import com.android.launcher3.accessibility.DragViewStateAnnouncer;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.dragndrop.DragView;

/**
@@ -106,7 +107,7 @@ public interface DropTarget {
    /**
     * Handle an object being dropped on the DropTarget
     */
    void onDrop(DragObject dragObject);
    void onDrop(DragObject dragObject, DragOptions options);

    void onDragEnter(DragObject dragObject);

+16 −19
Original line number Diff line number Diff line
@@ -49,28 +49,29 @@ public class InfoDropTarget extends UninstallDropTarget {
    }

    @Override
    public void completeDrop(DragObject d) {
        DropTargetResultCallback callback = d.dragSource instanceof DropTargetResultCallback
                ? (DropTargetResultCallback) d.dragSource : null;
        startDetailsActivityForInfo(d.dragInfo, mLauncher, callback);
    protected ComponentName performDropAction(DragObject d) {
        return performDropAction(mLauncher, d.dragInfo, null, null);
    }

    /**
     * @return Whether the activity was started.
     */
    public static boolean startDetailsActivityForInfo(
            ItemInfo info, Launcher launcher, DropTargetResultCallback callback) {
        return startDetailsActivityForInfo(info, launcher, callback, null, null);
            ItemInfo info, Launcher launcher, Rect sourceBounds, Bundle opts) {
        return performDropAction(launcher, info, sourceBounds, opts) != null;
    }

    public static boolean startDetailsActivityForInfo(ItemInfo info, Launcher launcher,
            DropTargetResultCallback callback, Rect sourceBounds, Bundle opts) {
    /**
     * Performs the drop action and returns the target component for the dragObject or null if
     * the action was not performed.
     */
    private static ComponentName performDropAction(Context context, ItemInfo info,
            Rect sourceBounds, Bundle opts) {
        if (info instanceof PromiseAppInfo) {
            PromiseAppInfo promiseAppInfo = (PromiseAppInfo) info;
            launcher.startActivity(promiseAppInfo.getMarketIntent());
            return true;
            context.startActivity(promiseAppInfo.getMarketIntent());
            return null;
        }
        boolean result = false;
        ComponentName componentName = null;
        if (info instanceof AppInfo) {
            componentName = ((AppInfo) info).componentName;
@@ -83,19 +84,15 @@ public class InfoDropTarget extends UninstallDropTarget {
        }
        if (componentName != null) {
            try {
                LauncherAppsCompat.getInstance(launcher)
                LauncherAppsCompat.getInstance(context)
                        .showAppDetailsForProfile(componentName, info.user, sourceBounds, opts);
                result = true;
                return componentName;
            } catch (SecurityException | ActivityNotFoundException e) {
                Toast.makeText(launcher, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
                Toast.makeText(context, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
                Log.e(TAG, "Unable to launch settings", e);
            }
        }

        if (callback != null) {
            sendUninstallResult(launcher, result, componentName, info.user, callback);
        }
        return result;
        return null;
    }

    @Override
+28 −31
Original line number Diff line number Diff line
@@ -263,7 +263,8 @@ public class Launcher extends BaseActivity
    private boolean mOnResumeNeedsLoad;

    private final ArrayList<Runnable> mBindOnResumeCallbacks = new ArrayList<>();
    private final ArrayList<Runnable> mOnResumeCallbacks = new ArrayList<>();
    private OnResumeCallback mOnResumeCallback;

    private ViewOnDrawExecutor mPendingExecutor;

    private LauncherModel mModel;
@@ -288,11 +289,6 @@ public class Launcher extends BaseActivity
    // it from the context.
    private SharedPreferences mSharedPrefs;

    // This is set to the view that launched the activity that navigated the user away from
    // launcher. Since there is no callback for when the activity has finished launching, enable
    // the press state and keep this reference to reset the press state when we return to launcher.
    private BubbleTextView mWaitingForResume;

    // Exiting spring loaded mode happens with a delay. This runnable object triggers the
    // state transition. If another state transition happened during this delay,
    // simply unregister this runnable.
@@ -887,19 +883,8 @@ public class Launcher extends BaseActivity
            }
            mBindOnResumeCallbacks.clear();
        }
        if (mOnResumeCallbacks.size() > 0) {
            for (int i = 0; i < mOnResumeCallbacks.size(); i++) {
                mOnResumeCallbacks.get(i).run();
            }
            mOnResumeCallbacks.clear();
        }

        // Reset the pressed state of icons that were locked in the press state while activities
        // were launching
        if (mWaitingForResume != null) {
            // Resets the previous workspace icon press state
            mWaitingForResume.setStayPressed(false);
        }
        setOnResumeCallback(null);

        updateInteraction(Workspace.State.NORMAL, mWorkspace.getState());

@@ -2127,11 +2112,7 @@ public class Launcher extends BaseActivity
    private void startMarketIntentForPackage(View v, String packageName) {
        ItemInfo item = (ItemInfo) v.getTag();
        Intent intent = PackageManagerHelper.getMarketIntent(packageName);
        boolean success = startActivitySafely(v, intent, item);
        if (success && v instanceof BubbleTextView) {
            mWaitingForResume = (BubbleTextView) v;
            mWaitingForResume.setStayPressed(true);
        }
        startActivitySafely(v, intent, item);
    }

    /**
@@ -2201,13 +2182,8 @@ public class Launcher extends BaseActivity
        if (intent == null) {
            throw new IllegalArgumentException("Input must have a valid intent");
        }
        boolean success = startActivitySafely(v, intent, item);
        startActivitySafely(v, intent, item);
        getUserEventDispatcher().logAppLaunch(v, intent); // TODO for discovered apps b/35802115

        if (success && v instanceof BubbleTextView) {
            mWaitingForResume = (BubbleTextView) v;
            mWaitingForResume.setStayPressed(true);
        }
    }

    /**
@@ -2438,6 +2414,16 @@ public class Launcher extends BaseActivity
                LauncherAppsCompat.getInstance(this).startActivityForProfile(
                        intent.getComponent(), user, intent.getSourceBounds(), optsBundle);
            }

            if (v instanceof BubbleTextView) {
                // This is set to the view that launched the activity that navigated the user away
                // from launcher. Since there is no callback for when the activity has finished
                // launching, enable the press state and keep this reference to reset the press
                // state when we return to launcher.
                BubbleTextView btv = (BubbleTextView) v;
                btv.setStayPressed(true);
                setOnResumeCallback(btv);
            }
            return true;
        } catch (ActivityNotFoundException|SecurityException e) {
            Toast.makeText(this, R.string.activity_not_found, Toast.LENGTH_SHORT).show();
@@ -2831,8 +2817,11 @@ public class Launcher extends BaseActivity
        }
    }

    public void addOnResumeCallback(Runnable run) {
        mOnResumeCallbacks.add(run);
    public void setOnResumeCallback(OnResumeCallback callback) {
        if (mOnResumeCallback != null) {
            mOnResumeCallback.onLauncherResume();
        }
        mOnResumeCallback = callback;
    }

    /**
@@ -3710,4 +3699,12 @@ public class Launcher extends BaseActivity
            }
        }
    }

    /**
     * Callback for listening for onResume
     */
    public interface OnResumeCallback {

        void onLauncherResume();
    }
}
Loading