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

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

Initial changes for handling configuration changes dynamically

Bug: 71709920
Change-Id: I88cf2229dea28d01c13a5a76d2290e91b07d095e
parent 260fec1b
Loading
Loading
Loading
Loading
+7 −2
Original line number Diff line number Diff line
@@ -26,12 +26,14 @@ import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
@@ -57,6 +59,8 @@ import com.android.systemui.shared.system.WindowManagerWrapper;
/**
 * Manages the opening and closing app transitions from Launcher.
 */
@TargetApi(Build.VERSION_CODES.O)
@SuppressWarnings("unused")
public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManager {

    private static final String TAG = "LauncherTransition";
@@ -94,6 +98,8 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
        Resources res = mLauncher.getResources();
        mContentTransY = res.getDimensionPixelSize(R.dimen.content_trans_y);
        mWorkspaceTransY = res.getDimensionPixelSize(R.dimen.workspace_trans_y);

        registerRemoteAnimations();
    }

    private void setCurrentAnimator(Animator animator) {
@@ -392,8 +398,7 @@ public class LauncherAppTransitionManagerImpl extends LauncherAppTransitionManag
    /**
     * Registers remote animations used when closing apps to home screen.
     */
    @Override
    public void registerRemoteAnimations() {
    private void registerRemoteAnimations() {
        if (hasControlRemoteAppTransitionPermission()) {
            try {
                RemoteAnimationDefinitionCompat definition = new RemoteAnimationDefinitionCompat();
+1 −0
Original line number Diff line number Diff line
@@ -111,6 +111,7 @@ public class DropTargetBar extends FrameLayout

            lp.topMargin += grid.edgeMarginPx;
            lp.height = grid.dropTargetBarSizePx;
            lp.gravity = Gravity.CENTER_HORIZONTAL | Gravity.TOP;
        }
        setLayoutParams(lp);
        for (ButtonDropTarget button : mDropTargets) {
+0 −2
Original line number Diff line number Diff line
@@ -28,12 +28,10 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewDebug;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.logging.UserEventDispatcher;
import com.android.launcher3.logging.UserEventDispatcher.LogContainerProvider;
import com.android.launcher3.userevent.nano.LauncherLogProto.Action;
import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType;
+0 −4
Original line number Diff line number Diff line
@@ -38,10 +38,6 @@ public class InsettableFrameLayout extends FrameLayout implements Insettable {

    @Override
    public void setInsets(Rect insets) {
        // If the insets haven't changed, this is a no-op. Avoid unnecessary layout caused by
        // modifying child layout params.
        if (insets.equals(mInsets)) return;

        final int n = getChildCount();
        for (int i = 0; i < n; i++) {
            final View child = getChildAt(i);
+49 −20
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.launcher3;

import static android.content.pm.ActivityInfo.CONFIG_ORIENTATION;
import static android.content.pm.ActivityInfo.CONFIG_SCREEN_SIZE;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_NOSENSOR;
import static android.content.pm.ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED;

@@ -53,7 +55,9 @@ import android.content.IntentFilter;
import android.content.IntentSender;
import android.content.SharedPreferences;
import android.content.SharedPreferences.OnSharedPreferenceChangeListener;
import android.content.pm.ActivityInfo;
import android.content.pm.PackageManager;
import android.content.res.Configuration;
import android.database.sqlite.SQLiteDatabase;
import android.graphics.Point;
import android.graphics.PointF;
@@ -215,6 +219,7 @@ public class Launcher extends BaseActivity
    @Thunk static final int NEW_APPS_ANIMATION_DELAY = 500;

    private LauncherAppTransitionManager mAppTransitionManager;
    private Configuration mOldConfig;

    @Thunk Workspace mWorkspace;
    private View mLauncherView;
@@ -237,10 +242,6 @@ public class Launcher extends BaseActivity
    // UI and state for the overview panel
    private ViewGroup mOverviewPanel;

    // We need to store the orientation Launcher was created with, due to a bug (b/64916689)
    // that results in widgets being inflated in the wrong orientation.
    private int mOrientation;

    @Thunk boolean mWorkspaceLoading = true;

    private OnResumeCallback mOnResumeCallback;
@@ -310,17 +311,9 @@ public class Launcher extends BaseActivity
        TraceHelper.partitionSection("Launcher-onCreate", "super call");

        LauncherAppState app = LauncherAppState.getInstance(this);
        mOldConfig = new Configuration(getResources().getConfiguration());
        initDeviceProfile(app.getInvariantDeviceProfile());

        // Load configuration-specific DeviceProfile
        mDeviceProfile = app.getInvariantDeviceProfile().getDeviceProfile(this);
        if (isInMultiWindowModeCompat()) {
            Display display = getWindowManager().getDefaultDisplay();
            Point mwSize = new Point();
            display.getSize(mwSize);
            mDeviceProfile = mDeviceProfile.getMultiWindowProfile(this, mwSize);
        }

        mOrientation = getResources().getConfiguration().orientation;
        mSharedPrefs = Utilities.getPrefs(this);
        mIsSafeModeEnabled = getPackageManager().isSafeMode();
        mModel = app.setLauncher(this);
@@ -393,7 +386,7 @@ public class Launcher extends BaseActivity
                ? SCREEN_ORIENTATION_UNSPECIFIED : SCREEN_ORIENTATION_NOSENSOR);

        setContentView(mLauncherView);
        ((LauncherRootView) mLauncherView).dispatchInsets();
        getRootView().dispatchInsets();

        // Listen for broadcasts
        IntentFilter filter = new IntentFilter();
@@ -405,10 +398,7 @@ public class Launcher extends BaseActivity
        getSystemUiController().updateUiState(SystemUiController.UI_STATE_BASE_WINDOW,
                Themes.getAttrBoolean(this, R.attr.isWorkspaceDarkText));

        mAppTransitionManager = Utilities.getOverrideObject(LauncherAppTransitionManager.class,
                        this, R.string.app_transition_manager_class);

        mAppTransitionManager.registerRemoteAnimations();
        mAppTransitionManager = LauncherAppTransitionManager.newInstance(this);

        if (mLauncherCallbacks != null) {
            mLauncherCallbacks.onCreate(savedInstanceState);
@@ -417,6 +407,45 @@ public class Launcher extends BaseActivity
        TraceHelper.endSection("Launcher-onCreate");
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig) {
        int diff = newConfig.diff(mOldConfig);
        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

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

            // TODO: We can probably avoid rebind when only screen size changed.
            mModel.startLoader(mWorkspace.getNextPage());
        }

        mOldConfig.setTo(newConfig);
        super.onConfigurationChanged(newConfig);
    }

    private void initDeviceProfile(InvariantDeviceProfile idp) {
        // Load configuration-specific DeviceProfile
        mDeviceProfile = idp.getDeviceProfile(this);
        if (isInMultiWindowModeCompat()) {
            Display display = getWindowManager().getDefaultDisplay();
            Point mwSize = new Point();
            display.getSize(mwSize);
            mDeviceProfile = mDeviceProfile.getMultiWindowProfile(this, mwSize);
        }
    }

    @Override
    public void onThemeChanged() {
        recreate();
@@ -1216,7 +1245,7 @@ public class Launcher extends BaseActivity
        return mSharedPrefs;
    }

    public int getOrientation() { return mOrientation; }
    public int getOrientation() { return mOldConfig.orientation; }

    @Override
    protected void onNewIntent(Intent intent) {
Loading