summaryrefslogtreecommitdiff
path: root/core/java/android/app/WindowContext.java
diff options
context:
space:
mode:
authorCharles Chen <charlesccchen@google.com>2021-03-05 18:07:46 +0800
committerCharles Chen <charlesccchen@google.com>2021-03-19 21:56:35 +0800
commit0783811428958673b877674d0eff2c3fac11ceb1 (patch)
treeb4b886f1af3fbecbdd7778bdea748f3c625c1c05 /core/java/android/app/WindowContext.java
parenta7ee1a9a4936985dc0e672903b1a3c45e68d1ef8 (diff)
Enable to listen to WindowContext's config changes
This CL overrides registerComponentCallbacks for WindowContext. Users can use below code snippet to listen to Configuration changes. ``` Context windowContext = context.createWindowContext( display, ...); windowContext.registerComponentCallbacks( new ComponentCallbacks() { @Override public void onConfigurationChanged( Configuration newConfig) { // Do Something } }); ``` Bug: 181134729 Test: atest WindowContextTests Test: atest ComponentCallbacksControllerTest Change-Id: Iff46607bae3c942a96b64dcc97708f3a8c33f23a
Diffstat (limited to 'core/java/android/app/WindowContext.java')
-rw-r--r--core/java/android/app/WindowContext.java21
1 files changed, 21 insertions, 0 deletions
diff --git a/core/java/android/app/WindowContext.java b/core/java/android/app/WindowContext.java
index cbe2995f2467..d44918cf0379 100644
--- a/core/java/android/app/WindowContext.java
+++ b/core/java/android/app/WindowContext.java
@@ -20,8 +20,11 @@ import static android.view.WindowManagerImpl.createWindowContextWindowManager;
import android.annotation.NonNull;
import android.annotation.Nullable;
import android.annotation.UiContext;
+import android.content.ComponentCallbacks;
+import android.content.ComponentCallbacksController;
import android.content.Context;
import android.content.ContextWrapper;
+import android.content.res.Configuration;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
@@ -49,6 +52,8 @@ public class WindowContext extends ContextWrapper {
private final IWindowManager mWms;
private final WindowTokenClient mToken;
private boolean mListenerRegistered;
+ private final ComponentCallbacksController mCallbacksController =
+ new ComponentCallbacksController();
/**
* Default constructor. Will generate a {@link WindowTokenClient} and attach this context to
@@ -131,8 +136,24 @@ public class WindowContext extends ContextWrapper {
}
void destroy() {
+ mCallbacksController.clearCallbacks();
final ContextImpl impl = (ContextImpl) getBaseContext();
impl.scheduleFinalCleanup(getClass().getName(), "WindowContext");
Reference.reachabilityFence(this);
}
+
+ @Override
+ public void registerComponentCallbacks(@NonNull ComponentCallbacks callback) {
+ mCallbacksController.registerCallbacks(callback);
+ }
+
+ @Override
+ public void unregisterComponentCallbacks(@NonNull ComponentCallbacks callback) {
+ mCallbacksController.unregisterCallbacks(callback);
+ }
+
+ /** Dispatch {@link Configuration} to each {@link ComponentCallbacks}. */
+ void dispatchConfigurationChanged(@NonNull Configuration newConfig) {
+ mCallbacksController.dispatchConfigurationChanged(newConfig);
+ }
}