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

Commit fde5505d authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Handling configuration changes

> Adding a listener for device profile changes
> Updating various controllers instead of recreating them
> Clearing all-apps icon

Bug: 71709920
Change-Id: Ief7db199eb7494ebd8fb433198f333cd2e8e661d
parent c94cfc05
Loading
Loading
Loading
Loading
+11 −2
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.media.midi.MidiManager.OnDeviceOpenedListener;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
@@ -43,6 +44,7 @@ import android.view.ViewGroup;
import android.view.animation.Interpolator;
import android.widget.ImageView;

import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
import com.android.launcher3.InsettableFrameLayout.LayoutParams;
import com.android.launcher3.allapps.AllAppsTransitionController;
import com.android.launcher3.anim.Interpolators;
@@ -61,7 +63,8 @@ import com.android.systemui.shared.system.WindowManagerWrapper;
 */
@TargetApi(Build.VERSION_CODES.O)
@SuppressWarnings("unused")
public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManager {
public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManager
        implements OnDeviceProfileChangeListener {

    private static final String TAG = "LauncherTransition";
    private static final int REFRESH_RATE_MS = 16;
@@ -78,7 +81,7 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag

    private final DragLayer mDragLayer;
    private final Launcher mLauncher;
    private final DeviceProfile mDeviceProfile;
    private DeviceProfile mDeviceProfile;

    private final float mContentTransY;
    private final float mWorkspaceTransY;
@@ -99,9 +102,15 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
        mContentTransY = res.getDimensionPixelSize(R.dimen.content_trans_y);
        mWorkspaceTransY = res.getDimensionPixelSize(R.dimen.workspace_trans_y);

        mLauncher.addOnDeviceProfileChangeListener(this);
        registerRemoteAnimations();
    }

    @Override
    public void onDeviceProfileChanged(DeviceProfile dp) {
        mDeviceProfile = dp;
    }

    private void setCurrentAnimator(Animator animator) {
        if (mCurrentAnimator != null && mCurrentAnimator.isRunning()) {
            mCurrentAnimator.cancel();
+9 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.graphics.Rect;
import android.view.MotionEvent;

import com.android.launcher3.DeviceProfile;
import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
import com.android.launcher3.Launcher;
import com.android.launcher3.anim.SpringAnimationHandler;
import com.android.launcher3.dragndrop.DragLayer;
@@ -36,13 +37,20 @@ import com.android.quickstep.RecentsView;
/**
 * Extension of {@link VerticalSwipeController} to go from NORMAL to OVERVIEW.
 */
public class EdgeSwipeController extends VerticalSwipeController {
public class EdgeSwipeController extends VerticalSwipeController implements
        OnDeviceProfileChangeListener {

    private static final Rect sTempRect = new Rect();

    public EdgeSwipeController(Launcher l) {
        super(l, NORMAL, OVERVIEW, l.getDeviceProfile().isVerticalBarLayout()
                ? HORIZONTAL : VERTICAL);
        l.addOnDeviceProfileChangeListener(this);
    }

    @Override
    public void onDeviceProfileChanged(DeviceProfile dp) {
        mDetector.updateDirection(dp.isVerticalBarLayout() ? HORIZONTAL : VERTICAL);
    }

    @Override
+16 −0
Original line number Diff line number Diff line
@@ -22,11 +22,16 @@ import android.content.ContextWrapper;
import android.content.Intent;
import android.view.View.AccessibilityDelegate;

import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener;
import com.android.launcher3.logging.UserEventDispatcher;
import com.android.launcher3.util.SystemUiController;

import java.util.ArrayList;

public abstract class BaseActivity extends Activity {

    private final ArrayList<OnDeviceProfileChangeListener> mDPChangeListeners = new ArrayList<>();

    protected DeviceProfile mDeviceProfile;
    protected UserEventDispatcher mUserEventDispatcher;
    protected SystemUiController mSystemUiController;
@@ -87,4 +92,15 @@ public abstract class BaseActivity extends Activity {
    public boolean isStarted() {
        return mStarted;
    }

    public void addOnDeviceProfileChangeListener(OnDeviceProfileChangeListener listener) {
        mDPChangeListeners.add(listener);
    }

    protected void dispatchDeviceProfileChanged() {
        int count = mDPChangeListeners.size();
        for (int i = 0; i < count; i++) {
            mDPChangeListeners.get(i).onDeviceProfileChanged(mDeviceProfile);
        }
    }
}
+14 −0
Original line number Diff line number Diff line
@@ -518,4 +518,18 @@ public class DeviceProfile {
        context.orientation = orientation;
        return c.createConfigurationContext(context);
    }

    /**
     * Callback when a component changes the DeviceProfile associated with it, as a result of
     * configuration change
     */
    public interface OnDeviceProfileChangeListener {

        /**
         * Called when the device profile is reassigned. Note that for layout and measurements, it
         * is sufficient to listen for inset changes. Use this callback when you need to perform
         * a one time operation.
         */
        void onDeviceProfileChanged(DeviceProfile dp);
    }
}
+1 −10
Original line number Diff line number Diff line
@@ -413,16 +413,7 @@ public class Launcher extends BaseActivity
        if ((diff & (CONFIG_ORIENTATION | CONFIG_SCREEN_SIZE)) != 0) {
            mUserEventDispatcher = null;
            initDeviceProfile(mDeviceProfile.inv);

            // Re create transition manager as it may rely on the device profile.
            // TODO: Remove any dynamic states from this class.
            mAppTransitionManager = LauncherAppTransitionManager.newInstance(this);

            // TODO: Link these to the callbacks
            mAllAppsController.onDeviceProfileChanged(mDeviceProfile);
            mDragLayer.setup(this, mDragController);

            // TODO: Clear all-apps recycler view pools
            dispatchDeviceProfileChanged();

            getRootView().dispatchInsets();
            getStateManager().reapplyState();
Loading