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

Commit 15a78d2a authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Fixing double state changes when using an InternalStateHandler" into ub-launcher3-master

parents 67419a15 d3864fa6
Loading
Loading
Loading
Loading
+4 −24
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@ import android.app.ActivityManager.RunningTaskInfo;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.os.Build;
import android.os.UserHandle;
import android.support.annotation.BinderThread;
import android.support.annotation.UiThread;
import android.util.FloatProperty;
@@ -32,6 +31,7 @@ import android.view.Choreographer.FrameCallback;
import android.view.View;
import android.view.ViewGroup;

import com.android.launcher3.AbstractFloatingView;
import com.android.launcher3.Hotseat;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
@@ -40,11 +40,7 @@ import com.android.launcher3.anim.AnimationSuccessListener;
import com.android.launcher3.anim.Interpolators;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.states.InternalStateHandler;
import com.android.launcher3.uioverrides.OverviewState;
import com.android.systemui.shared.recents.model.RecentsTaskLoadPlan;
import com.android.systemui.shared.recents.model.Task.TaskKey;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.BackgroundExecutor;
import com.android.systemui.shared.system.WindowManagerWrapper;

import java.util.concurrent.ExecutionException;
@@ -119,25 +115,10 @@ public class NavBarSwipeInteractionHandler extends InternalStateHandler implemen
    }

    @Override
    public void onCreate(Launcher launcher) {
        mLauncher = launcher;
        mDragView = new SnapshotDragView(mLauncher, mTaskSnapshot);
        mLauncher.getDragLayer().addView(mDragView);
        mDragView.setPivotX(0);
        mDragView.setPivotY(0);
        mRecentsView = mLauncher.getOverviewPanel();
        mHotseat = mLauncher.getHotseat();
    protected void init(Launcher launcher, boolean alreadyOnHome) {
        AbstractFloatingView.closeAllOpenViews(launcher, alreadyOnHome);
        launcher.getStateManager().goToState(LauncherState.OVERVIEW, alreadyOnHome);

        // Optimization
        mLauncher.getAppsView().setVisibility(View.GONE);

        // Launch overview
        mRecentsView.update(consumeLastLoadPlan());
        mLauncher.getStateManager().goToState(LauncherState.OVERVIEW, false /* animate */);
    }

    @Override
    public void onNewIntent(Launcher launcher, boolean alreadyOnHome) {
        mLauncher = launcher;
        mDragView = new SnapshotDragView(mLauncher, mTaskSnapshot);
        mLauncher.getDragLayer().addView(mDragView);
@@ -151,7 +132,6 @@ public class NavBarSwipeInteractionHandler extends InternalStateHandler implemen

        // Launch overview, animate if already on home
        mRecentsView.update(consumeLastLoadPlan());
        mLauncher.getStateManager().goToState(LauncherState.OVERVIEW, alreadyOnHome);
    }

    /**
+2 −11
Original line number Diff line number Diff line
@@ -17,8 +17,6 @@ package com.android.quickstep;

import static android.view.MotionEvent.INVALID_POINTER_ID;

import static com.android.launcher3.states.InternalStateHandler.EXTRA_STATE_HANDLER;

import android.app.ActivityManager.RunningTaskInfo;
import android.app.ActivityOptions;
import android.app.Service;
@@ -31,7 +29,6 @@ import android.graphics.Bitmap;
import android.graphics.Point;
import android.graphics.PointF;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.os.UserHandle;
@@ -42,7 +39,6 @@ import android.view.VelocityTracker;
import android.view.ViewConfiguration;
import android.view.WindowManager;

import com.android.launcher3.LauncherAppState;
import com.android.launcher3.R;
import com.android.systemui.shared.recents.IOverviewProxy;
import com.android.systemui.shared.recents.ISystemUiProxy;
@@ -212,13 +208,8 @@ public class TouchInteractionService extends Service {
            RecentsTaskLoader loader = TouchInteractionService.getRecentsTaskLoader();
            loadPlan.preloadPlan(loader, mRunningTask.id, UserHandle.myUserId());

            // Pass the
            Bundle extras = new Bundle();
            extras.putBinder(EXTRA_STATE_HANDLER, mInteractionHandler);

            // Start the activity
            Intent homeIntent = new Intent(mHomeIntent);
            homeIntent.putExtras(extras);
            // Start the activity with our custom handler
            Intent homeIntent = mInteractionHandler.addToIntent(new Intent(mHomeIntent));
            startActivity(homeIntent, ActivityOptions.makeCustomAnimation(this, 0, 0).toBundle());
            /*
            ActivityManagerWrapper.getInstance().startRecentsActivity(null, options,
+54 −66
Original line number Diff line number Diff line
@@ -107,7 +107,6 @@ import com.android.launcher3.dragndrop.DragController;
import com.android.launcher3.dragndrop.DragLayer;
import com.android.launcher3.dragndrop.DragOptions;
import com.android.launcher3.dragndrop.DragView;
import com.android.launcher3.dragndrop.PinItemDragListener;
import com.android.launcher3.dynamicui.WallpaperColorInfo;
import com.android.launcher3.folder.Folder;
import com.android.launcher3.folder.FolderIcon;
@@ -359,9 +358,27 @@ public class Launcher extends BaseActivity

        mPopupDataProvider = new PopupDataProvider(this);

        restoreState(savedInstanceState);
        mRotationEnabled = getResources().getBoolean(R.bool.allow_rotation);
        // In case we are on a device with locked rotation, we should look at preferences to check
        // if the user has specifically allowed rotation.
        if (!mRotationEnabled) {
            mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
            mRotationPrefChangeHandler = new RotationPrefChangeHandler();
            mSharedPrefs.registerOnSharedPreferenceChangeListener(mRotationPrefChangeHandler);
        }

        boolean internalStateHandled = InternalStateHandler.handleCreate(this, getIntent());
        if (internalStateHandled) {
            // Temporarily enable the rotation
            mRotationEnabled = true;

        InternalStateHandler.handleCreate(this, getIntent());
            if (savedInstanceState != null) {
                // InternalStateHandler has already set the appropriate state.
                // We dont need to do anything.
                savedInstanceState.remove(RUNTIME_STATE);
            }
        }
        restoreState(savedInstanceState);

        // We only load the page synchronously if the user rotates (or triggers a
        // configuration change) while launcher is in the foreground
@@ -369,10 +386,13 @@ public class Launcher extends BaseActivity
        if (savedInstanceState != null) {
            currentScreen = savedInstanceState.getInt(RUNTIME_STATE_CURRENT_SCREEN, currentScreen);
        }

        if (!mModel.startLoader(currentScreen)) {
            if (!internalStateHandled) {
                // If we are not binding synchronously, show a fade in animation when
                // the first page bind completes.
                mDragLayer.setAlpha(0);
            }
        } else {
            // Pages bound synchronously.
            mWorkspace.setCurrentPage(currentScreen);
@@ -384,20 +404,6 @@ public class Launcher extends BaseActivity
        mDefaultKeySsb = new SpannableStringBuilder();
        Selection.setSelection(mDefaultKeySsb, 0);

        mRotationEnabled = getResources().getBoolean(R.bool.allow_rotation);
        // In case we are on a device with locked rotation, we should look at preferences to check
        // if the user has specifically allowed rotation.
        if (!mRotationEnabled) {
            mRotationEnabled = Utilities.isAllowRotationPrefEnabled(getApplicationContext());
            mRotationPrefChangeHandler = new RotationPrefChangeHandler();
            mSharedPrefs.registerOnSharedPreferenceChangeListener(mRotationPrefChangeHandler);
        }

        if (PinItemDragListener.handleDragRequest(this, getIntent())) {
            // Temporarily enable the rotation
            mRotationEnabled = true;
        }

        // On large interfaces, or on devices that a user has specifically enabled screen rotation,
        // we want the screen to auto-rotate based on the current orientation
        setRequestedOrientation(mRotationEnabled
@@ -1342,14 +1348,13 @@ public class Launcher extends BaseActivity
        boolean shouldMoveToDefaultScreen = alreadyOnHome && isInState(NORMAL)
                && AbstractFloatingView.getTopOpenView(this) == null;
        boolean isActionMain = Intent.ACTION_MAIN.equals(intent.getAction());
        if (isActionMain) {
            if (mWorkspace == null) {
                // Can be cases where mWorkspace is null, this prevents a NPE
                return;
            }
        boolean internalStateHandled = InternalStateHandler
                .handleNewIntent(this, intent, alreadyOnHome);

            // Note: There should be at most one log per method call. This is enforced implicitly
            // by using if-else statements.
        if (isActionMain) {
            if (!internalStateHandled) {
                // Note: There should be at most one log per method call. This is enforced
                // implicitly by using if-else statements.
                UserEventDispatcher ued = getUserEventDispatcher();
                AbstractFloatingView topOpenView = AbstractFloatingView.getTopOpenView(this);
                if (topOpenView != null) {
@@ -1362,45 +1367,28 @@ public class Launcher extends BaseActivity

                // In all these cases, only animate if we're already on home
                AbstractFloatingView.closeAllOpenViews(this, alreadyOnHome);
            mStateManager.goToState(NORMAL, alreadyOnHome /* animated */);

            final View v = getWindow().peekDecorView();
            if (v != null && v.getWindowToken() != null) {
                UiThreadHelper.hideKeyboardAsync(this, v.getWindowToken());
            }
                mStateManager.goToState(NORMAL, alreadyOnHome /* animated */);

                // Reset the apps view
                if (!alreadyOnHome && mAppsView != null) {
                    mAppsView.reset();
                }

            if (mLauncherCallbacks != null) {
                mLauncherCallbacks.onHomeIntent();
                if (shouldMoveToDefaultScreen && !mWorkspace.isTouchActive()) {
                    mWorkspace.post(mWorkspace::moveToDefaultScreen);
                }
            }
        PinItemDragListener.handleDragRequest(this, intent);

        if (mLauncherCallbacks != null) {
            mLauncherCallbacks.onNewIntent(intent);
            final View v = getWindow().peekDecorView();
            if (v != null && v.getWindowToken() != null) {
                UiThreadHelper.hideKeyboardAsync(this, v.getWindowToken());
            }

        // Defer moving to the default screen until after we callback to the LauncherCallbacks
        // as slow logic in the callbacks eat into the time the scroller expects for the snapToPage
        // animation.
        if (isActionMain) {
            if (shouldMoveToDefaultScreen && !mWorkspace.isTouchActive()) {

                mWorkspace.post(new Runnable() {
                    @Override
                    public void run() {
                        if (mWorkspace != null) {
                            mWorkspace.moveToDefaultScreen();
                        }
                    }
                });
            if (mLauncherCallbacks != null) {
                mLauncherCallbacks.onHomeIntent();
            }
        }
        InternalStateHandler.handleNewIntent(this, intent, alreadyOnHome);

        TraceHelper.endSection("NEW_INTENT");
    }
+0 −1
Original line number Diff line number Diff line
@@ -45,7 +45,6 @@ public interface LauncherCallbacks {
    void onPause();
    void onDestroy();
    void onSaveInstanceState(Bundle outState);
    void onNewIntent(Intent intent);
    void onActivityResult(int requestCode, int resultCode, Intent data);
    void onRequestPermissionsResult(int requestCode, String[] permissions,
            int[] grantResults);
+6 −5
Original line number Diff line number Diff line
@@ -147,11 +147,12 @@ public class AddItemActivity extends BaseActivity implements OnLongClickListener
        // Start home and pass the draw request params
        PinItemDragListener listener = new PinItemDragListener(mRequest, bounds,
                img.getBitmap().getWidth(), img.getWidth());
        Intent homeIntent = new Intent(Intent.ACTION_MAIN)

        Intent homeIntent = listener.addToIntent(
                new Intent(Intent.ACTION_MAIN)
                        .addCategory(Intent.CATEGORY_HOME)
                        .setPackage(getPackageName())
                .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                .putExtra(PinItemDragListener.EXTRA_PIN_ITEM_DRAG_LISTENER, listener);
                        .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));

        if (!getResources().getBoolean(R.bool.allow_rotation) &&
                !Utilities.isAllowRotationPrefEnabled(this) &&
Loading