summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorJohn Reck <jreck@google.com>2018-09-27 23:04:02 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2018-09-27 23:04:02 +0000
commit702196562e8d30b6dcdb5f01260ef607801cf9d6 (patch)
tree9cb47e2ae9ab3c23f51d2508665bbab767f1a293 /core/java
parent23ca916dca3e1633d59e90f3afeef629edebd3f9 (diff)
parentbb3a35831794477d980791b131c33dc7faa46f59 (diff)
Merge "Wire-up default force-dark based off of isLightTheme"
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/view/ThreadedRenderer.java20
-rw-r--r--core/java/android/view/View.java4
-rw-r--r--core/java/android/view/ViewRootImpl.java25
3 files changed, 49 insertions, 0 deletions
diff --git a/core/java/android/view/ThreadedRenderer.java b/core/java/android/view/ThreadedRenderer.java
index 0986b89849cf..42690cef9da3 100644
--- a/core/java/android/view/ThreadedRenderer.java
+++ b/core/java/android/view/ThreadedRenderer.java
@@ -974,6 +974,25 @@ public final class ThreadedRenderer {
}
}
+ /** The root of everything */
+ public @NonNull RenderNode getRootNode() {
+ return mRootNode;
+ }
+
+ private boolean mForceDark = false;
+
+ /**
+ * Whether or not the force-dark feature should be used for this renderer.
+ */
+ public boolean setForceDark(boolean enable) {
+ if (mForceDark != enable) {
+ mForceDark = enable;
+ nSetForceDark(mNativeProxy, enable);
+ return true;
+ }
+ return false;
+ }
+
/**
* Basic synchronous renderer. Currently only used to render the Magnifier, so use with care.
* TODO: deduplicate against ThreadedRenderer.
@@ -1253,4 +1272,5 @@ public final class ThreadedRenderer {
private static native void nSetIsolatedProcess(boolean enabled);
private static native void nSetContextPriority(int priority);
private static native void nAllocateBuffers(long nativeProxy, Surface window);
+ private static native void nSetForceDark(long nativeProxy, boolean enabled);
}
diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java
index 1eb35c546c99..78e6dd8fb139 100644
--- a/core/java/android/view/View.java
+++ b/core/java/android/view/View.java
@@ -15255,6 +15255,10 @@ public class View implements Drawable.Callback, KeyEvent.Callback,
* a value of 'true' will not override any 'false' value in its parent chain nor will
* it prevent any 'false' in any of its children.
*
+ * The default behavior of force dark is also influenced by the Theme's
+ * {@link android.R.styleable#Theme_isLightTheme isLightTheme} attribute.
+ * If a theme is isLightTheme="false", then force dark is globally disabled for that theme.
+ *
* @param allow Whether or not to allow force dark.
*
* @hide
diff --git a/core/java/android/view/ViewRootImpl.java b/core/java/android/view/ViewRootImpl.java
index 5bc44ce2bd49..bef8e8fedfdf 100644
--- a/core/java/android/view/ViewRootImpl.java
+++ b/core/java/android/view/ViewRootImpl.java
@@ -43,6 +43,7 @@ import android.content.pm.PackageManager;
import android.content.res.CompatibilityInfo;
import android.content.res.Configuration;
import android.content.res.Resources;
+import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
@@ -1077,6 +1078,7 @@ public final class ViewRootImpl implements ViewParent,
mAttachInfo.mThreadedRenderer = ThreadedRenderer.create(mContext, translucent,
attrs.getTitle().toString());
mAttachInfo.mThreadedRenderer.setWideGamut(wideGamut);
+ updateForceDarkMode();
if (mAttachInfo.mThreadedRenderer != null) {
mAttachInfo.mHardwareAccelerated =
mAttachInfo.mHardwareAccelerationRequested = true;
@@ -1085,6 +1087,27 @@ public final class ViewRootImpl implements ViewParent,
}
}
+ private int getNightMode() {
+ return mContext.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
+ }
+
+ private void updateForceDarkMode() {
+ if (mAttachInfo.mThreadedRenderer == null) return;
+
+ boolean nightMode = getNightMode() == Configuration.UI_MODE_NIGHT_YES;
+ TypedArray a = mContext.obtainStyledAttributes(R.styleable.Theme);
+ boolean isLightTheme = a.getBoolean(R.styleable.Theme_isLightTheme, false);
+ a.recycle();
+
+ boolean changed = mAttachInfo.mThreadedRenderer.setForceDark(nightMode);
+ changed |= mAttachInfo.mThreadedRenderer.getRootNode().setAllowForceDark(isLightTheme);
+
+ if (changed) {
+ // TODO: Don't require regenerating all display lists to apply this setting
+ invalidateWorld(mView);
+ }
+ }
+
@UnsupportedAppUsage
public View getView() {
return mView;
@@ -4077,6 +4100,8 @@ public final class ViewRootImpl implements ViewParent,
mForceNextWindowRelayout = true;
requestLayout();
}
+
+ updateForceDarkMode();
}
/**