Merge "Inject and use WindowContext in RotationTouchHelper" into main
This commit is contained in:
committed by
Android (Google) Code Review
commit
bbd09df63a
@@ -21,6 +21,7 @@ import android.hardware.display.DisplayManager
|
||||
import android.os.Handler
|
||||
import android.util.Log
|
||||
import android.view.Display.DEFAULT_DISPLAY
|
||||
import android.view.WindowManager.LayoutParams.TYPE_APPLICATION
|
||||
import com.android.app.displaylib.DisplayLibBackground
|
||||
import com.android.app.displaylib.DisplayLibComponent
|
||||
import com.android.app.displaylib.DisplayRepository
|
||||
@@ -94,20 +95,48 @@ object PerDisplayRepositoriesModule {
|
||||
@Provides
|
||||
fun provideRotationTouchHandlerRepo(
|
||||
repositoryFactory: PerDisplayInstanceRepositoryImpl.Factory<RotationTouchHelper>,
|
||||
@WindowContext windowContextRepository: PerDisplayRepository<Context>,
|
||||
instanceFactory: RotationTouchHelper.Factory,
|
||||
displayRepository: DisplayRepository,
|
||||
): PerDisplayRepository<RotationTouchHelper> {
|
||||
return if (enableOverviewOnConnectedDisplays()) {
|
||||
repositoryFactory.create(
|
||||
"RotationTouchHelperRepo",
|
||||
{ displayId ->
|
||||
displayRepository.getDisplay(displayId)?.let { instanceFactory.create(it) }
|
||||
windowContextRepository[displayId]?.let { instanceFactory.create(it) }
|
||||
},
|
||||
)
|
||||
} else {
|
||||
SingleInstanceRepositoryImpl(
|
||||
"RotationTouchHelperRepo",
|
||||
instanceFactory.create(displayRepository.getDisplay(DEFAULT_DISPLAY)),
|
||||
instanceFactory.create(windowContextRepository[DEFAULT_DISPLAY]),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Provides
|
||||
@WindowContext
|
||||
fun provideWindowContext(
|
||||
repositoryFactory: PerDisplayInstanceRepositoryImpl.Factory<Context>,
|
||||
@ApplicationContext context: Context,
|
||||
displayRepository: DisplayRepository,
|
||||
): PerDisplayRepository<Context> {
|
||||
return if (enableOverviewOnConnectedDisplays()) {
|
||||
repositoryFactory.create(
|
||||
"WindowContextRepo",
|
||||
{ displayId ->
|
||||
displayRepository.getDisplay(displayId)?.let {
|
||||
context.createWindowContext(it, TYPE_APPLICATION, /* options= */ null)
|
||||
}
|
||||
},
|
||||
)
|
||||
} else {
|
||||
SingleInstanceRepositoryImpl(
|
||||
"WindowContextRepo",
|
||||
context.createWindowContext(
|
||||
displayRepository.getDisplay(DEFAULT_DISPLAY)!!,
|
||||
TYPE_APPLICATION,
|
||||
/* options = */ null,
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -29,12 +29,11 @@ import static com.android.launcher3.util.NavigationMode.THREE_BUTTONS;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.view.Display;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.OrientationEventListener;
|
||||
|
||||
import com.android.app.displaylib.PerDisplayRepository;
|
||||
import com.android.launcher3.dagger.ApplicationContext;
|
||||
import com.android.launcher3.dagger.WindowContext;
|
||||
import com.android.launcher3.testing.shared.TestProtocol;
|
||||
import com.android.launcher3.util.DaggerSingletonObject;
|
||||
import com.android.launcher3.util.DaggerSingletonTracker;
|
||||
@@ -49,12 +48,12 @@ import com.android.systemui.shared.system.QuickStepContract;
|
||||
import com.android.systemui.shared.system.TaskStackChangeListener;
|
||||
import com.android.systemui.shared.system.TaskStackChangeListeners;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
import dagger.assisted.Assisted;
|
||||
import dagger.assisted.AssistedFactory;
|
||||
import dagger.assisted.AssistedInject;
|
||||
|
||||
import java.io.PrintWriter;
|
||||
|
||||
/**
|
||||
* Helper class for transforming touch events
|
||||
*/
|
||||
@@ -134,31 +133,28 @@ public class RotationTouchHelper implements DisplayInfoChangeListener {
|
||||
*/
|
||||
private boolean mInOverview;
|
||||
private boolean mTaskListFrozen;
|
||||
private final Context mApplicationContext;
|
||||
private final Context mDisplayContext;
|
||||
private final Context mWindowContext;
|
||||
|
||||
@AssistedInject
|
||||
RotationTouchHelper(@ApplicationContext Context context,
|
||||
RotationTouchHelper(@Assisted Context windowContext,
|
||||
DisplayController displayController,
|
||||
SystemUiProxy systemUiProxy,
|
||||
DaggerSingletonTracker lifeCycle,
|
||||
@Assisted Display display) {
|
||||
mApplicationContext = context;
|
||||
DaggerSingletonTracker lifeCycle) {
|
||||
mWindowContext = windowContext;
|
||||
mDisplayController = displayController;
|
||||
mSystemUiProxy = systemUiProxy;
|
||||
mDisplayContext = mApplicationContext.createDisplayContext(display);
|
||||
mDisplayId = display.getDisplayId();
|
||||
mDisplayId = windowContext.getDisplayId();
|
||||
|
||||
Resources resources = mApplicationContext.getResources();
|
||||
Resources resources = mWindowContext.getResources();
|
||||
mOrientationTouchTransformer = new OrientationTouchTransformer(resources, mMode,
|
||||
() -> QuickStepContract.getWindowCornerRadius(mDisplayContext));
|
||||
() -> QuickStepContract.getWindowCornerRadius(mWindowContext));
|
||||
|
||||
// Register for navigation mode and rotation changes
|
||||
mDisplayController.addChangeListenerForDisplay(this, mDisplayId);
|
||||
DisplayController.Info info = mDisplayController.getInfoForDisplay(mDisplayId);
|
||||
onDisplayInfoChanged(context, info, CHANGE_ALL);
|
||||
onDisplayInfoChanged(windowContext, info, CHANGE_ALL);
|
||||
|
||||
mOrientationListener = new OrientationEventListener(mApplicationContext) {
|
||||
mOrientationListener = new OrientationEventListener(mWindowContext) {
|
||||
@Override
|
||||
public void onOrientationChanged(int degrees) {
|
||||
int newRotation = RecentsOrientedState.getRotationForUserDegreesRotated(degrees,
|
||||
@@ -266,7 +262,7 @@ public class RotationTouchHelper implements DisplayInfoChangeListener {
|
||||
NavigationMode newMode = info.getNavigationMode();
|
||||
mOrientationTouchTransformer.setNavigationMode(newMode,
|
||||
mDisplayController.getInfoForDisplay(mDisplayId),
|
||||
mApplicationContext.getResources());
|
||||
mWindowContext.getResources());
|
||||
|
||||
TaskStackChangeListeners.getInstance()
|
||||
.unregisterTaskStackListener(mFrozenTaskListener);
|
||||
@@ -288,7 +284,7 @@ public class RotationTouchHelper implements DisplayInfoChangeListener {
|
||||
void setGesturalHeight(int newGesturalHeight) {
|
||||
mOrientationTouchTransformer.setGesturalHeight(
|
||||
newGesturalHeight, mDisplayController.getInfoForDisplay(mDisplayId),
|
||||
mApplicationContext.getResources());
|
||||
mWindowContext.getResources());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -399,6 +395,6 @@ public class RotationTouchHelper implements DisplayInfoChangeListener {
|
||||
@AssistedFactory
|
||||
public interface Factory {
|
||||
/** Creates a new instance of [RotationTouchHelper] for a given [display]. */
|
||||
RotationTouchHelper create(Display display);
|
||||
RotationTouchHelper create(@WindowContext Context context);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
/*
|
||||
* Copyright (C) 2025 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.launcher3.dagger;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
|
||||
import javax.inject.Qualifier;
|
||||
|
||||
/**
|
||||
* Qualifier for Launcher application context.
|
||||
*/
|
||||
@Documented
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Qualifier
|
||||
public @interface WindowContext {
|
||||
}
|
||||
Reference in New Issue
Block a user