Revert "Night mode stability improvements"
This reverts commit b30d214598794bc450c81050b4a41634d5216a11.
Reason for revert: http://b/117163227
Change-Id: I022ed07edeaba6b56c95f9ade64e8e0a83d7fc9b
diff --git a/appcompat/api/current.txt b/appcompat/api/current.txt
index cfba121..c7c17f4 100644
--- a/appcompat/api/current.txt
+++ b/appcompat/api/current.txt
@@ -259,7 +259,6 @@
method public abstract androidx.appcompat.app.ActionBarDrawerToggle.Delegate getDrawerToggleDelegate();
method public abstract android.view.MenuInflater getMenuInflater();
method public abstract androidx.appcompat.app.ActionBar getSupportActionBar();
- method public abstract android.content.Context getThemedContext();
method public abstract boolean hasWindowFeature(int);
method public abstract void installViewFactory();
method public abstract void invalidateOptionsMenu();
@@ -271,7 +270,6 @@
method public abstract void onPostCreate(android.os.Bundle);
method public abstract void onPostResume();
method public abstract void onSaveInstanceState(android.os.Bundle);
- method public abstract void onSetTheme(int);
method public abstract void onStart();
method public abstract void onStop();
method public abstract boolean requestWindowFeature(int);
diff --git a/appcompat/src/androidTest/AndroidManifest.xml b/appcompat/src/androidTest/AndroidManifest.xml
index a425c02..443fa24 100644
--- a/appcompat/src/androidTest/AndroidManifest.xml
+++ b/appcompat/src/androidTest/AndroidManifest.xml
@@ -144,11 +144,6 @@
android:theme="@style/Theme.AppCompat.DayNight"/>
<activity
- android:name="androidx.appcompat.app.NightModeConfigChangesActivity"
- android:theme="@style/Theme.AppCompat.DayNight"
- android:configChanges="uiMode"/>
-
- <activity
android:name="androidx.appcompat.app.AppCompatVectorDrawableIntegrationActivity"/>
<activity
diff --git a/appcompat/src/androidTest/java/androidx/appcompat/app/NightModeActivity.java b/appcompat/src/androidTest/java/androidx/appcompat/app/NightModeActivity.java
index a4145df..9871cb8 100644
--- a/appcompat/src/androidTest/java/androidx/appcompat/app/NightModeActivity.java
+++ b/appcompat/src/androidTest/java/androidx/appcompat/app/NightModeActivity.java
@@ -16,10 +16,6 @@
package androidx.appcompat.app;
-import android.content.res.Configuration;
-import android.view.View;
-import android.widget.Button;
-
import androidx.appcompat.test.R;
import androidx.appcompat.testutils.BaseTestActivity;
@@ -33,14 +29,6 @@
*/
static NightModeActivity TOP_ACTIVITY = null;
- Configuration lastChangeConfiguration = null;
-
- @Override
- public void onConfigurationChanged(Configuration newConfig) {
- super.onConfigurationChanged(newConfig);
- lastChangeConfiguration = newConfig;
- }
-
@Override
protected int getContentViewLayoutResId() {
return R.layout.activity_night_mode;
@@ -59,11 +47,4 @@
TOP_ACTIVITY = null;
}
}
-
- /**
- * This is referenced from an android:onClick in the layout
- */
- public void onButtonClicked(View view) {
- ((Button) view).setText(R.string.clicked);
- }
}
diff --git a/appcompat/src/androidTest/java/androidx/appcompat/app/NightModeConfigChangesActivity.java b/appcompat/src/androidTest/java/androidx/appcompat/app/NightModeConfigChangesActivity.java
deleted file mode 100644
index eb17cdd..0000000
--- a/appcompat/src/androidTest/java/androidx/appcompat/app/NightModeConfigChangesActivity.java
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * Copyright 2018 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 androidx.appcompat.app;
-
-public class NightModeConfigChangesActivity extends NightModeActivity {}
diff --git a/appcompat/src/androidTest/java/androidx/appcompat/app/NightModeConfigChangesTestCase.java b/appcompat/src/androidTest/java/androidx/appcompat/app/NightModeConfigChangesTestCase.java
deleted file mode 100644
index 549c5cd..0000000
--- a/appcompat/src/androidTest/java/androidx/appcompat/app/NightModeConfigChangesTestCase.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * Copyright 2018 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 androidx.appcompat.app;
-
-import static androidx.appcompat.testutils.NightModeUtils.assertConfigurationNightModeEquals;
-import static androidx.appcompat.testutils.NightModeUtils.setLocalNightModeAndWait;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import android.content.res.Configuration;
-
-import androidx.test.filters.LargeTest;
-import androidx.test.rule.ActivityTestRule;
-import androidx.test.runner.AndroidJUnit4;
-
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@LargeTest
-@RunWith(AndroidJUnit4.class)
-public class NightModeConfigChangesTestCase {
- @Rule
- public final ActivityTestRule<NightModeConfigChangesActivity> mActivityTestRule;
-
- public NightModeConfigChangesTestCase() {
- mActivityTestRule = new ActivityTestRule<>(NightModeConfigChangesActivity.class);
- }
-
- @Before
- public void setup() {
- // By default we'll set the night mode to NO, which allows us to make better
- // assumptions in the test below
- AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
- }
-
- @Test
- public void testOnConfigurationChangedCalled() throws Throwable {
- final NightModeConfigChangesActivity activity = mActivityTestRule.getActivity();
-
- // Assert that the Activity does not have a config currently
- assertNull(activity.lastChangeConfiguration);
-
- // Set local night mode to YES
- setLocalNightModeAndWait(mActivityTestRule, AppCompatDelegate.MODE_NIGHT_YES);
-
- // Assert that the Activity received a new config
- assertNotNull(activity.lastChangeConfiguration);
- assertConfigurationNightModeEquals(Configuration.UI_MODE_NIGHT_YES,
- activity.lastChangeConfiguration);
-
- // Set local night mode back to NO
- setLocalNightModeAndWait(mActivityTestRule, AppCompatDelegate.MODE_NIGHT_NO);
-
- // Assert that the Activity received a new config
- assertNotNull(activity.lastChangeConfiguration);
- assertConfigurationNightModeEquals(Configuration.UI_MODE_NIGHT_NO,
- activity.lastChangeConfiguration);
- }
-}
diff --git a/appcompat/src/androidTest/java/androidx/appcompat/app/NightModeTestCase.java b/appcompat/src/androidTest/java/androidx/appcompat/app/NightModeTestCase.java
index 09037c9..b46481f6 100644
--- a/appcompat/src/androidTest/java/androidx/appcompat/app/NightModeTestCase.java
+++ b/appcompat/src/androidTest/java/androidx/appcompat/app/NightModeTestCase.java
@@ -17,21 +17,15 @@
package androidx.appcompat.app;
import static androidx.appcompat.app.NightModeActivity.TOP_ACTIVITY;
-import static androidx.appcompat.testutils.NightModeUtils.assertConfigurationNightModeEquals;
-import static androidx.appcompat.testutils.NightModeUtils.setLocalNightModeAndWait;
import static androidx.appcompat.testutils.TestUtilsMatchers.isBackground;
import static androidx.test.espresso.Espresso.onView;
-import static androidx.test.espresso.action.ViewActions.click;
import static androidx.test.espresso.assertion.ViewAssertions.matches;
import static androidx.test.espresso.matcher.ViewMatchers.withId;
import static androidx.test.espresso.matcher.ViewMatchers.withText;
-import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import android.app.Instrumentation;
-import android.content.res.Configuration;
-import android.webkit.WebView;
import androidx.appcompat.test.R;
import androidx.core.content.ContextCompat;
@@ -181,62 +175,6 @@
onView(withId(R.id.text_night_mode)).check(matches(withText(STRING_NIGHT)));
}
- @Test
- public void testOnConfigurationChangedNotCalled() throws Throwable {
- final NightModeActivity activity = mActivityTestRule.getActivity();
-
- // Assert that the Activity does not have a config currently
- assertNull(activity.lastChangeConfiguration);
-
- // Set local night mode to YES
- setLocalNightModeAndWait(mActivityTestRule, AppCompatDelegate.MODE_NIGHT_YES);
-
- // Assert that the Activity still does not have a config currently
- assertNull(activity.lastChangeConfiguration);
-
- // Set local night mode back to NO
- setLocalNightModeAndWait(mActivityTestRule, AppCompatDelegate.MODE_NIGHT_NO);
-
- // Assert that the Activity still does not have a config currently
- assertNull(activity.lastChangeConfiguration);
- }
-
- @Test
- public void testWebViewMaintainsConfiguration() throws Throwable {
- // Set night mode and wait for the new Activity
- final NightModeActivity activity = setLocalNightModeAndWaitForRecreate(
- mActivityTestRule.getActivity(), AppCompatDelegate.MODE_NIGHT_YES);
-
- // Assert that the themed context has the correct config
- assertConfigurationNightModeEquals(Configuration.UI_MODE_NIGHT_YES,
- activity.getThemedContext().getResources().getConfiguration());
-
- // Now load a WebView into the Activity
- mActivityTestRule.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- final WebView webView = new WebView(activity);
- }
- });
-
- // Now assert that the themed context has the correct config
- assertConfigurationNightModeEquals(Configuration.UI_MODE_NIGHT_YES,
- activity.getThemedContext().getResources().getConfiguration());
- }
-
- @Test
- public void testXmlOnClickWithNightMode() throws Throwable {
- // Set night mode and wait for the new Activity
- setLocalNightModeAndWaitForRecreate(mActivityTestRule.getActivity(),
- AppCompatDelegate.MODE_NIGHT_YES);
-
- // Click the button and assert that the text changes. The text change logic is in
- // an method in the Activity referenced from the XML layout
- onView(withId(R.id.button))
- .perform(click())
- .check(matches(withText(R.string.clicked)));
- }
-
private static class FakeTwilightManager extends TwilightManager {
private boolean mIsNight;
@@ -256,8 +194,7 @@
private NightModeActivity setLocalNightModeAndWaitForRecreate(
final NightModeActivity activity,
- @AppCompatDelegate.NightMode final int nightMode
- ) throws Throwable {
+ @AppCompatDelegate.NightMode final int nightMode) throws Throwable {
final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
mActivityTestRule.runOnUiThread(new Runnable() {
@Override
diff --git a/appcompat/src/androidTest/java/androidx/appcompat/testutils/NightModeUtils.java b/appcompat/src/androidTest/java/androidx/appcompat/testutils/NightModeUtils.java
deleted file mode 100644
index 8880e99..0000000
--- a/appcompat/src/androidTest/java/androidx/appcompat/testutils/NightModeUtils.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright 2018 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 androidx.appcompat.testutils;
-
-import static org.junit.Assert.assertEquals;
-
-import android.app.Instrumentation;
-import android.content.res.Configuration;
-
-import androidx.appcompat.app.AppCompatActivity;
-import androidx.appcompat.app.AppCompatDelegate;
-import androidx.test.InstrumentationRegistry;
-import androidx.test.rule.ActivityTestRule;
-
-public class NightModeUtils {
- public static void assertConfigurationNightModeEquals(int expectedNightMode,
- Configuration configuration) {
- assertEquals(expectedNightMode, configuration.uiMode & Configuration.UI_MODE_NIGHT_MASK);
- }
-
- public static void setLocalNightModeAndWait(
- final ActivityTestRule<? extends AppCompatActivity> activityRule,
- @AppCompatDelegate.NightMode final int nightMode
- ) throws Throwable {
- final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
- activityRule.runOnUiThread(new Runnable() {
- @Override
- public void run() {
- activityRule.getActivity().getDelegate().setLocalNightMode(nightMode);
- }
- });
- instrumentation.waitForIdleSync();
- }
-}
diff --git a/appcompat/src/androidTest/res/layout/activity_night_mode.xml b/appcompat/src/androidTest/res/layout/activity_night_mode.xml
index 4e624f6..5cd8563 100644
--- a/appcompat/src/androidTest/res/layout/activity_night_mode.xml
+++ b/appcompat/src/androidTest/res/layout/activity_night_mode.xml
@@ -31,11 +31,4 @@
android:layout_height="100dp"
android:background="@drawable/test_night_color_conversion_background" />
- <Button
- android:id="@+id/button"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:>
- android:text="@string/night_mode" />
-
</LinearLayout>
\ No newline at end of file
diff --git a/appcompat/src/androidTest/res/values/strings.xml b/appcompat/src/androidTest/res/values/strings.xml
index 997dd0d..964c32b 100644
--- a/appcompat/src/androidTest/res/values/strings.xml
+++ b/appcompat/src/androidTest/res/values/strings.xml
@@ -104,6 +104,4 @@
<string name="font_serif">serif</string>
<string name="toolbar_collapse">Toolbar collapse</string>
-
- <string name="clicked">Clicked</string>
</resources>
diff --git a/appcompat/src/main/java/androidx/appcompat/app/AppCompatActivity.java b/appcompat/src/main/java/androidx/appcompat/app/AppCompatActivity.java
index 0c9633f..1acc767 100644
--- a/appcompat/src/main/java/androidx/appcompat/app/AppCompatActivity.java
+++ b/appcompat/src/main/java/androidx/appcompat/app/AppCompatActivity.java
@@ -16,7 +16,6 @@
package androidx.appcompat.app;
-import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.content.res.Resources;
@@ -64,35 +63,33 @@
TaskStackBuilder.SupportParentable, ActionBarDrawerToggle.DelegateProvider {
private AppCompatDelegate mDelegate;
+ private int mThemeId = 0;
private Resources mResources;
- /**
- * {@inheritDoc}
- *
- * When inflating any resources, make sure to use this Activity's themed context from {@link #getThemedContext()}.
- * The returned context is setup with the correct theme, and is especially important when using this library's
- * DayNight functionality.
- * <p>
- * This context is automatically used when you call {@link #setContentView(int)}, {@link #setContentView(View)},
- * {@link #setContentView(View, ViewGroup.LayoutParams)}, and is automatically used by
- * {@link androidx.fragment.app.Fragment}'s layout inflater.
- * <p>
- * Please note: make sure that you call {@code super.onCreate()} before using this Activity's {@link Resources}
- * or its {@link Configuration}.
- */
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
final AppCompatDelegate delegate = getDelegate();
delegate.installViewFactory();
delegate.onCreate(savedInstanceState);
- delegate.applyDayNight();
+ if (delegate.applyDayNight() && mThemeId != 0) {
+ // If DayNight has been applied, we need to re-apply the theme for
+ // the changes to take effect. On API 23+, we should bypass
+ // setTheme(), which will no-op if the theme ID is identical to the
+ // current theme ID.
+ if (Build.VERSION.SDK_INT >= 23) {
+ onApplyThemeResource(getTheme(), mThemeId, false);
+ } else {
+ setTheme(mThemeId);
+ }
+ }
super.onCreate(savedInstanceState);
}
@Override
- public void setTheme(@StyleRes final int resId) {
- super.setTheme(resId);
- getDelegate().onSetTheme(resId);
+ public void setTheme(@StyleRes final int resid) {
+ super.setTheme(resid);
+ // Keep hold of the theme id so that we can re-set it later if needed
+ mThemeId = resid;
}
@Override
@@ -101,12 +98,6 @@
getDelegate().onPostCreate(savedInstanceState);
}
- @NonNull
- @Override
- public Context getThemedContext() {
- return getDelegate().getThemedContext();
- }
-
/**
* Support library version of {@link android.app.Activity#getActionBar}.
*
diff --git a/appcompat/src/main/java/androidx/appcompat/app/AppCompatDelegate.java b/appcompat/src/main/java/androidx/appcompat/app/AppCompatDelegate.java
index 7bb6a0c..268d23e 100644
--- a/appcompat/src/main/java/androidx/appcompat/app/AppCompatDelegate.java
+++ b/appcompat/src/main/java/androidx/appcompat/app/AppCompatDelegate.java
@@ -36,7 +36,6 @@
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;
-import androidx.annotation.StyleRes;
import androidx.appcompat.view.ActionMode;
import androidx.appcompat.widget.Toolbar;
import androidx.appcompat.widget.VectorEnabledTintResources;
@@ -488,18 +487,6 @@
}
/**
- * Returns the context which should be used to inflate any view hierarchies.
- */
- @NonNull
- public abstract Context getThemedContext();
-
- /**
- * This should be called from {@link Activity#setTheme(int)} to notify AppCompat of what
- * the current theme resource id is.
- */
- public abstract void onSetTheme(@StyleRes int themeResId);
-
- /**
* Sets whether vector drawables on older platforms (< API 21) can be used within
* {@link android.graphics.drawable.DrawableContainer} resources.
*
diff --git a/appcompat/src/main/java/androidx/appcompat/app/AppCompatDelegateImpl.java b/appcompat/src/main/java/androidx/appcompat/app/AppCompatDelegateImpl.java
index 9ed190e..b628904 100644
--- a/appcompat/src/main/java/androidx/appcompat/app/AppCompatDelegateImpl.java
+++ b/appcompat/src/main/java/androidx/appcompat/app/AppCompatDelegateImpl.java
@@ -44,6 +44,7 @@
import android.text.TextUtils;
import android.util.AndroidRuntimeException;
import android.util.AttributeSet;
+import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.Gravity;
@@ -163,9 +164,6 @@
final Window.Callback mAppCompatWindowCallback;
final AppCompatCallback mAppCompatCallback;
- Context mThemedContext;
- int mThemeResId;
-
ActionBar mActionBar;
MenuInflater mMenuInflater;
@@ -217,8 +215,6 @@
@NightMode
private int mLocalNightMode = MODE_NIGHT_UNSPECIFIED;
private boolean mApplyDayNightCalled;
- private boolean mActivityHandlesUiMode;
- private boolean mActivityHandlesUiModeChecked;
private AutoNightModeManager mAutoNightModeManager;
@@ -258,18 +254,18 @@
mAppCompatWindowCallback = new AppCompatWindowCallback(mOriginalWindowCallback);
// Now install the new callback
mWindow.setCallback(mAppCompatWindowCallback);
- }
- @Override
- public void onCreate(Bundle savedInstanceState) {
final TintTypedArray a = TintTypedArray.obtainStyledAttributes(
- getThemedContext(), null, sWindowBackgroundStyleable);
+ context, null, sWindowBackgroundStyleable);
final Drawable winBg = a.getDrawableIfKnown(0);
if (winBg != null) {
mWindow.setBackgroundDrawable(winBg);
}
a.recycle();
+ }
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
if (mOriginalWindowCallback instanceof Activity) {
String parentActivityName = null;
try {
@@ -374,12 +370,6 @@
invalidateOptionsMenu();
}
- @NonNull
- @Override
- public Context getThemedContext() {
- return mThemedContext != null ? mThemedContext : mContext;
- }
-
final Context getActionBarThemedContext() {
Context context = null;
@@ -390,7 +380,7 @@
}
if (context == null) {
- context = getThemedContext();
+ context = mContext;
}
return context;
}
@@ -400,7 +390,8 @@
// Make sure that action views can get an appropriate theme.
if (mMenuInflater == null) {
initWindowDecorActionBar();
- mMenuInflater = new SupportMenuInflater(getActionBarThemedContext());
+ mMenuInflater = new SupportMenuInflater(
+ mActionBar != null ? mActionBar.getThemedContext() : mContext);
}
return mMenuInflater;
}
@@ -427,11 +418,7 @@
}
// Make sure that the DrawableManager knows about the new config
- final AppCompatDrawableManager acdm = AppCompatDrawableManager.get();
- acdm.onConfigurationChanged(mContext);
- if (mThemedContext != null) {
- acdm.onConfigurationChanged(mThemedContext);
- }
+ AppCompatDrawableManager.get().onConfigurationChanged(mContext);
// Re-apply Day/Night to the new configuration
applyDayNight();
@@ -468,7 +455,7 @@
@Override
public void setContentView(View v) {
ensureSubDecor();
- ViewGroup contentParent = mSubDecor.findViewById(android.R.id.content);
+ ViewGroup contentParent = (ViewGroup) mSubDecor.findViewById(android.R.id.content);
contentParent.removeAllViews();
contentParent.addView(v);
mOriginalWindowCallback.onContentChanged();
@@ -477,21 +464,16 @@
@Override
public void setContentView(int resId) {
ensureSubDecor();
- ViewGroup contentParent = mSubDecor.findViewById(android.R.id.content);
+ ViewGroup contentParent = (ViewGroup) mSubDecor.findViewById(android.R.id.content);
contentParent.removeAllViews();
- if (mThemedContext != null) {
- LayoutInflater.from(mContext).cloneInContext(mThemedContext)
- .inflate(resId, contentParent);
- } else {
- LayoutInflater.from(mContext).inflate(resId, contentParent);
- }
+ LayoutInflater.from(mContext).inflate(resId, contentParent);
mOriginalWindowCallback.onContentChanged();
}
@Override
public void setContentView(View v, ViewGroup.LayoutParams lp) {
ensureSubDecor();
- ViewGroup contentParent = mSubDecor.findViewById(android.R.id.content);
+ ViewGroup contentParent = (ViewGroup) mSubDecor.findViewById(android.R.id.content);
contentParent.removeAllViews();
contentParent.addView(v, lp);
mOriginalWindowCallback.onContentChanged();
@@ -500,7 +482,7 @@
@Override
public void addContentView(View v, ViewGroup.LayoutParams lp) {
ensureSubDecor();
- ViewGroup contentParent = mSubDecor.findViewById(android.R.id.content);
+ ViewGroup contentParent = (ViewGroup) mSubDecor.findViewById(android.R.id.content);
contentParent.addView(v, lp);
mOriginalWindowCallback.onContentChanged();
}
@@ -566,8 +548,7 @@
}
private ViewGroup createSubDecor() {
- final Context themedContext = getThemedContext();
- TypedArray a = themedContext.obtainStyledAttributes(R.styleable.AppCompatTheme);
+ TypedArray a = mContext.obtainStyledAttributes(R.styleable.AppCompatTheme);
if (!a.hasValue(R.styleable.AppCompatTheme_windowActionBar)) {
a.recycle();
@@ -593,7 +574,7 @@
// Now let's make sure that the Window has installed its decor by retrieving it
mWindow.getDecorView();
- final LayoutInflater inflater = LayoutInflater.from(mContext).cloneInContext(themedContext);
+ final LayoutInflater inflater = LayoutInflater.from(mContext);
ViewGroup subDecor = null;
@@ -612,23 +593,24 @@
* ContextThemeWrapper pointing to actionBarTheme.
*/
TypedValue outValue = new TypedValue();
- themedContext.getTheme().resolveAttribute(R.attr.actionBarTheme, outValue, true);
+ mContext.getTheme().resolveAttribute(R.attr.actionBarTheme, outValue, true);
- Context abThemedContext;
+ Context themedContext;
if (outValue.resourceId != 0) {
- abThemedContext = new ContextThemeWrapper(themedContext, outValue.resourceId);
+ themedContext = new ContextThemeWrapper(mContext, outValue.resourceId);
} else {
- abThemedContext = themedContext;
+ themedContext = mContext;
}
// Now inflate the view using the themed context and set it as the content view
- subDecor = (ViewGroup) LayoutInflater.from(abThemedContext)
+ subDecor = (ViewGroup) LayoutInflater.from(themedContext)
.inflate(R.layout.abc_screen_toolbar, null);
- mDecorContentParent = subDecor.findViewById(R.id.decor_content_parent);
+ mDecorContentParent = (DecorContentParent) subDecor
+ .findViewById(R.id.decor_content_parent);
mDecorContentParent.setWindowCallback(getWindowCallback());
- /*
+ /**
* Propagate features to DecorContentParent
*/
if (mOverlayActionBar) {
@@ -746,7 +728,7 @@
void onSubDecorInstalled(ViewGroup subDecor) {}
private void applyFixedSizeWindow() {
- ContentFrameLayout cfl = mSubDecor.findViewById(android.R.id.content);
+ ContentFrameLayout cfl = (ContentFrameLayout) mSubDecor.findViewById(android.R.id.content);
// This is a bit weird. In the framework, the window sizing attributes control
// the decor view's size, meaning that any padding is inset for the min/max widths below.
@@ -757,7 +739,7 @@
windowDecor.getPaddingTop(), windowDecor.getPaddingRight(),
windowDecor.getPaddingBottom());
- TypedArray a = getThemedContext().obtainStyledAttributes(R.styleable.AppCompatTheme);
+ TypedArray a = mContext.obtainStyledAttributes(R.styleable.AppCompatTheme);
a.getValue(R.styleable.AppCompatTheme_windowMinWidthMajor, cfl.getMinWidthMajor());
a.getValue(R.styleable.AppCompatTheme_windowMinWidthMinor, cfl.getMinWidthMinor());
@@ -970,8 +952,6 @@
}
}
- final Context themedContext = getThemedContext();
-
if (mode != null) {
mActionMode = mode;
} else {
@@ -979,20 +959,19 @@
if (mIsFloating) {
// Use the action bar theme.
final TypedValue outValue = new TypedValue();
- final Resources.Theme baseTheme = themedContext.getTheme();
+ final Resources.Theme baseTheme = mContext.getTheme();
baseTheme.resolveAttribute(R.attr.actionBarTheme, outValue, true);
final Context actionBarContext;
if (outValue.resourceId != 0) {
- final Resources.Theme actionBarTheme =
- themedContext.getResources().newTheme();
+ final Resources.Theme actionBarTheme = mContext.getResources().newTheme();
actionBarTheme.setTo(baseTheme);
actionBarTheme.applyStyle(outValue.resourceId, true);
- actionBarContext = new ContextThemeWrapper(themedContext, 0);
+ actionBarContext = new ContextThemeWrapper(mContext, 0);
actionBarContext.getTheme().setTo(actionBarTheme);
} else {
- actionBarContext = themedContext;
+ actionBarContext = mContext;
}
mActionModeView = new ActionBarContextView(actionBarContext);
@@ -1040,7 +1019,8 @@
}
};
} else {
- ViewStubCompat stub = mSubDecor.findViewById(R.id.action_mode_bar_stub);
+ ViewStubCompat stub = (ViewStubCompat) mSubDecor
+ .findViewById(R.id.action_mode_bar_stub);
if (stub != null) {
// Set the layout inflater so that it is inflated with the action bar's context
stub.setLayoutInflater(LayoutInflater.from(getActionBarThemedContext()));
@@ -1252,7 +1232,7 @@
public View createView(View parent, final String name, @NonNull Context context,
@NonNull AttributeSet attrs) {
if (mAppCompatViewInflater == null) {
- TypedArray a = getThemedContext().obtainStyledAttributes(R.styleable.AppCompatTheme);
+ TypedArray a = mContext.obtainStyledAttributes(R.styleable.AppCompatTheme);
String viewInflaterClassName =
a.getString(R.styleable.AppCompatTheme_viewInflaterClass);
if ((viewInflaterClassName == null)
@@ -1272,9 +1252,6 @@
mAppCompatViewInflater = new AppCompatViewInflater();
}
}
- // Give the inflater the host context in case the view hierarchy context is not the
- // same as the Activity's (happens with night mode)
- mAppCompatViewInflater.setHostContext(mContext);
}
boolean inheritContext = false;
@@ -1320,7 +1297,7 @@
@Override
public void installViewFactory() {
- LayoutInflater layoutInflater = LayoutInflater.from(getThemedContext());
+ LayoutInflater layoutInflater = LayoutInflater.from(mContext);
if (layoutInflater.getFactory() == null) {
LayoutInflaterCompat.setFactory2(layoutInflater, this);
} else {
@@ -1356,7 +1333,7 @@
// Don't open an options panel on xlarge devices.
// (The app should be using an action bar for menu items.)
if (st.featureId == FEATURE_OPTIONS_PANEL) {
- Configuration config = getThemedContext().getResources().getConfiguration();
+ Configuration config = mContext.getResources().getConfiguration();
boolean isXLarge = (config.screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK)
== Configuration.SCREENLAYOUT_SIZE_XLARGE;
if (isXLarge) {
@@ -1371,8 +1348,7 @@
return;
}
- final WindowManager wm = (WindowManager) getThemedContext()
- .getSystemService(Context.WINDOW_SERVICE);
+ final WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
if (wm == null) {
return;
}
@@ -1453,7 +1429,7 @@
private void reopenMenu(MenuBuilder menu, boolean toggleMenuMode) {
if (mDecorContentParent != null && mDecorContentParent.canShowOverflowMenu()
- && (!ViewConfiguration.get(getThemedContext()).hasPermanentMenuKey()
+ && (!ViewConfiguration.get(mContext).hasPermanentMenuKey()
|| mDecorContentParent.isOverflowMenuShowPending())) {
final Window.Callback cb = getWindowCallback();
@@ -1496,7 +1472,7 @@
}
private boolean initializePanelMenu(final PanelFeatureState st) {
- Context context = getThemedContext();
+ Context context = mContext;
// If we have an action bar, initialize the menu with the right theme.
if ((st.featureId == FEATURE_OPTIONS_PANEL || st.featureId == FEATURE_SUPPORT_ACTION_BAR) &&
@@ -1688,8 +1664,7 @@
return;
}
- final WindowManager wm = (WindowManager) getThemedContext()
- .getSystemService(Context.WINDOW_SERVICE);
+ final WindowManager wm = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
if (wm != null && st.isOpen && st.decorView != null) {
wm.removeView(st.decorView);
@@ -1730,12 +1705,11 @@
return false;
}
- final Context context = getThemedContext();
boolean handled = false;
final PanelFeatureState st = getPanelState(featureId, true);
if (featureId == FEATURE_OPTIONS_PANEL && mDecorContentParent != null &&
mDecorContentParent.canShowOverflowMenu() &&
- !ViewConfiguration.get(context).hasPermanentMenuKey()) {
+ !ViewConfiguration.get(mContext).hasPermanentMenuKey()) {
if (!mDecorContentParent.isOverflowMenuShowing()) {
if (!mIsDestroyed && preparePanel(st, event)) {
handled = mDecorContentParent.showOverflowMenu();
@@ -1768,7 +1742,7 @@
}
if (handled) {
- AudioManager audioManager = (AudioManager) context.getSystemService(
+ AudioManager audioManager = (AudioManager) mContext.getSystemService(
Context.AUDIO_SERVICE);
if (audioManager != null) {
audioManager.playSoundEffect(AudioManager.FX_KEY_CLICK);
@@ -1928,9 +1902,8 @@
mlp.topMargin = insetTop;
if (mStatusGuard == null) {
- final Context context = getThemedContext();
- mStatusGuard = new View(context);
- mStatusGuard.setBackgroundColor(context.getResources()
+ mStatusGuard = new View(mContext);
+ mStatusGuard.setBackgroundColor(mContext.getResources()
.getColor(R.color.abc_input_method_navigation_guard));
mSubDecor.addView(mStatusGuard, -1,
new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
@@ -2041,18 +2014,6 @@
}
mApplyDayNightCalled = true;
-
- if (applied) {
- // If DayNight has been applied, we need to re-apply the theme for
- // the changes to take effect. On API 23+, we need to force
- // setTheme() since it will no-op if the theme ID is identical to the
- // current theme ID. Instead, we set the theme twice.
- if (Build.VERSION.SDK_INT >= 23) {
- mContext.setTheme(0);
- }
- mContext.setTheme(mThemeResId);
- }
-
return applied;
}
@@ -2110,15 +2071,6 @@
* chosen {@code UI_MODE_NIGHT} value.
*/
private boolean updateForNightMode(@ApplyableNightMode final int mode) {
- // We still need to update the host context configuration for windowBackground, etc
- boolean applied = updateContextConfigForNightMode(mode);
- if (Build.VERSION.SDK_INT >= 17) {
- applied = updateThemedContextForNightMode(mode) || applied;
- }
- return applied;
- }
-
- private boolean updateContextConfigForNightMode(@ApplyableNightMode final int mode) {
final Resources res = mContext.getResources();
final Configuration conf = res.getConfiguration();
final int currentNightMode = conf.uiMode & Configuration.UI_MODE_NIGHT_MASK;
@@ -2128,35 +2080,29 @@
: Configuration.UI_MODE_NIGHT_NO;
if (currentNightMode != newNightMode) {
- final boolean manifestHandlingUiMode = isActivityManifestHandlingUiMode();
- final boolean shouldRecreateOnNightModeChange =
- mApplyDayNightCalled && mContext instanceof Activity && !manifestHandlingUiMode;
-
- if (shouldRecreateOnNightModeChange) {
+ if (shouldRecreateOnNightModeChange()) {
if (DEBUG) {
Log.d(TAG, "applyNightMode() | Night mode changed, recreating Activity");
}
// If we've already been created, we need to recreate the Activity for the
// mode to be applied
- ((Activity) mContext).recreate();
+ final Activity activity = (Activity) mContext;
+ activity.recreate();
} else {
if (DEBUG) {
Log.d(TAG, "applyNightMode() | Night mode changed, updating configuration");
}
final Configuration config = new Configuration(conf);
+ final DisplayMetrics metrics = res.getDisplayMetrics();
+
// Update the UI Mode to reflect the new night mode
config.uiMode = newNightMode | (config.uiMode & ~Configuration.UI_MODE_NIGHT_MASK);
- res.updateConfiguration(config, res.getDisplayMetrics());
+ res.updateConfiguration(config, metrics);
// We may need to flush the Resources' drawable cache due to framework bugs.
- if (Build.VERSION.SDK_INT < 26) {
+ if (!(Build.VERSION.SDK_INT >= 26)) {
ResourcesFlusher.flush(res);
}
-
- // If the Activity is set to handle uiMode config changes, pass along the new config
- if (manifestHandlingUiMode) {
- ((Activity) mContext).onConfigurationChanged(config);
- }
}
return true;
} else {
@@ -2167,64 +2113,9 @@
return false;
}
- @RequiresApi(17)
- private boolean updateThemedContextForNightMode(@ApplyableNightMode final int mode) {
- int currentNightMode = Configuration.UI_MODE_NIGHT_UNDEFINED;
- if (mThemedContext != null) {
- final Resources res = mThemedContext.getResources();
- final Configuration conf = res.getConfiguration();
- currentNightMode = conf.uiMode & Configuration.UI_MODE_NIGHT_MASK;
- }
-
- final int newNightMode = (mode == MODE_NIGHT_YES)
- ? Configuration.UI_MODE_NIGHT_YES
- : Configuration.UI_MODE_NIGHT_NO;
-
- if (currentNightMode != newNightMode) {
- final boolean manifestHandlingUiMode = isActivityManifestHandlingUiMode();
- final boolean shouldRecreateOnNightModeChange =
- mApplyDayNightCalled && mContext instanceof Activity && !manifestHandlingUiMode;
-
- if (shouldRecreateOnNightModeChange) {
- if (DEBUG) {
- Log.d(TAG, "applyNightMode() | Night mode changed, recreating Activity");
- }
- // If we've already been created, we need to recreate the Activity for the
- // mode to be applied
- ((Activity) mContext).recreate();
- } else {
- if (DEBUG) {
- Log.d(TAG, "applyNightMode() | Night mode changed, updating configuration");
- }
- final Configuration config = new Configuration(
- mContext.getResources().getConfiguration());
- // Update the UI Mode to reflect the new night mode
- config.uiMode = newNightMode | (config.uiMode & ~Configuration.UI_MODE_NIGHT_MASK);
-
- mThemedContext = mContext.createConfigurationContext(config);
- mThemedContext.setTheme(mThemeResId);
- }
- return true;
- } else {
- if (DEBUG) {
- Log.d(TAG, "applyNightMode() | Skipping. Night mode has not changed: " + mode);
- }
- }
- return false;
- }
-
- @Override
- public void onSetTheme(int themeResId) {
- mThemeResId = themeResId;
- if (mThemedContext != null) {
- mThemedContext.setTheme(themeResId);
- }
- }
-
private void ensureAutoNightModeManager() {
if (mAutoNightModeManager == null) {
- final TwilightManager twilightManager = TwilightManager.getInstance(getThemedContext());
- mAutoNightModeManager = new AutoNightModeManager(twilightManager);
+ mAutoNightModeManager = new AutoNightModeManager(TwilightManager.getInstance(mContext));
}
}
@@ -2234,23 +2125,25 @@
return mAutoNightModeManager;
}
- private boolean isActivityManifestHandlingUiMode() {
- if (!mActivityHandlesUiModeChecked && mContext instanceof Activity) {
+ private boolean shouldRecreateOnNightModeChange() {
+ if (mApplyDayNightCalled && mContext instanceof Activity) {
+ // If we've already applyDayNight() (via setTheme), we need to check if the
+ // Activity has configChanges set to handle uiMode changes
final PackageManager pm = mContext.getPackageManager();
try {
final ActivityInfo info = pm.getActivityInfo(
new ComponentName(mContext, mContext.getClass()), 0);
- mActivityHandlesUiMode = (info.configChanges & ActivityInfo.CONFIG_UI_MODE) != 0;
+ // We should return true (to recreate) if configChanges does not want to
+ // handle uiMode
+ return (info.configChanges & ActivityInfo.CONFIG_UI_MODE) == 0;
} catch (PackageManager.NameNotFoundException e) {
// This shouldn't happen but let's not crash because of it, we'll just log and
- // return false (since most apps won't be handling it)
+ // return true (since most apps will do that anyway)
Log.d(TAG, "Exception while getting ActivityInfo", e);
- mActivityHandlesUiMode = false;
+ return true;
}
}
- // Flip the checked flag so we don't check again
- mActivityHandlesUiModeChecked = true;
- return mActivityHandlesUiMode;
+ return false;
}
/**
@@ -2725,7 +2618,7 @@
android.view.ActionMode.Callback callback) {
// Wrap the callback as a v7 ActionMode.Callback
final SupportActionModeWrapper.CallbackWrapper callbackWrapper =
- new SupportActionModeWrapper.CallbackWrapper(getThemedContext(), callback);
+ new SupportActionModeWrapper.CallbackWrapper(mContext, callback);
// Try and start a support action mode using the wrapped callback
final androidx.appcompat.view.ActionMode supportActionMode =
@@ -2842,7 +2735,7 @@
@Override
public Drawable getThemeUpIndicator() {
final TintTypedArray a = TintTypedArray.obtainStyledAttributes(
- getActionBarThemedContext(), null, new int[]{R.attr.homeAsUpIndicator});
+ getActionBarThemedContext(), null, new int[]{ R.attr.homeAsUpIndicator });
final Drawable result = a.getDrawable(0);
a.recycle();
return result;
diff --git a/appcompat/src/main/java/androidx/appcompat/app/AppCompatDialog.java b/appcompat/src/main/java/androidx/appcompat/app/AppCompatDialog.java
index 0c0605f..5c93431 100644
--- a/appcompat/src/main/java/androidx/appcompat/app/AppCompatDialog.java
+++ b/appcompat/src/main/java/androidx/appcompat/app/AppCompatDialog.java
@@ -53,18 +53,13 @@
this(context, 0);
}
- public AppCompatDialog(Context context, int themeResId) {
- this(context, getThemeResId(context, themeResId), false);
- }
-
- private AppCompatDialog(Context context, int themeResId, boolean unusedParam) {
- super(context, themeResId);
+ public AppCompatDialog(Context context, int theme) {
+ super(context, getThemeResId(context, theme));
// This is a bit weird, but Dialog's are typically created and setup before being shown,
// which means that we can't rely on onCreate() being called before a content view is set.
// To workaround this, we call onCreate(null) in the ctor, and then again as usual in
// onCreate().
- getDelegate().onSetTheme(themeResId);
getDelegate().onCreate(null);
// Apply AppCompat's DayNight resources if needed
diff --git a/appcompat/src/main/java/androidx/appcompat/app/AppCompatViewInflater.java b/appcompat/src/main/java/androidx/appcompat/app/AppCompatViewInflater.java
index 9c186dd..03d8035 100644
--- a/appcompat/src/main/java/androidx/appcompat/app/AppCompatViewInflater.java
+++ b/appcompat/src/main/java/androidx/appcompat/app/AppCompatViewInflater.java
@@ -16,7 +16,6 @@
package androidx.appcompat.app;
-import android.app.Activity;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.res.TypedArray;
@@ -78,12 +77,6 @@
private final Object[] mConstructorArgs = new Object[2];
- private Context mHostContext;
-
- void setHostContext(@Nullable Context context) {
- mHostContext = context;
- }
-
final View createView(View parent, final String name, @NonNull Context context,
@NonNull AttributeSet attrs, boolean inheritContext,
boolean readAndroidTheme, boolean readAppTheme, boolean wrapContext) {
@@ -307,19 +300,20 @@
private void checkOnClickListener(View view, AttributeSet attrs) {
final Context context = view.getContext();
- // Skip our compat functionality if: the Context is an Activity, or
- // the view doesn't have an OnClickListener (we can only rely on this on API 15+ so
- // always use our compat code on older devices)
- if (!(context instanceof Activity)
- && (Build.VERSION.SDK_INT < 15 || ViewCompat.hasOnClickListeners(view))) {
- final TypedArray a = context.obtainStyledAttributes(attrs, sOnClickAttrs);
- final String handlerName = a.getString(0);
- if (handlerName != null) {
- view.setOnClickListener(
- new DeclaredOnClickListener(view, mHostContext, handlerName));
- }
- a.recycle();
+ if (!(context instanceof ContextWrapper) ||
+ (Build.VERSION.SDK_INT >= 15 && !ViewCompat.hasOnClickListeners(view))) {
+ // Skip our compat functionality if: the Context isn't a ContextWrapper, or
+ // the view doesn't have an OnClickListener (we can only rely on this on API 15+ so
+ // always use our compat code on older devices)
+ return;
}
+
+ final TypedArray a = context.obtainStyledAttributes(attrs, sOnClickAttrs);
+ final String handlerName = a.getString(0);
+ if (handlerName != null) {
+ view.setOnClickListener(new DeclaredOnClickListener(view, handlerName));
+ }
+ a.recycle();
}
private View createViewByPrefix(Context context, String name, String prefix)
@@ -381,16 +375,13 @@
*/
private static class DeclaredOnClickListener implements View.OnClickListener {
private final View mHostView;
- private final Context mHostContext;
private final String mMethodName;
private Method mResolvedMethod;
private Context mResolvedContext;
- DeclaredOnClickListener(@NonNull View hostView, @NonNull Context hostContext,
- @NonNull String methodName) {
+ public DeclaredOnClickListener(@NonNull View hostView, @NonNull String methodName) {
mHostView = hostView;
- mHostContext = hostContext;
mMethodName = methodName;
}
@@ -412,31 +403,11 @@
}
@NonNull
- private void resolveMethod(@Nullable Context viewContext, @NonNull String name) {
- // Try and resolve the method using the view's context
- resolveMethodForContext(viewContext, name);
-
- if (mResolvedMethod == null && mHostContext != viewContext) {
- // If the view context does not contain a method with the name, lets try the
- // host context
- resolveMethodForContext(mHostContext, name);
- }
-
- if (mResolvedMethod == null) {
- final int id = mHostView.getId();
- final String idText = id == View.NO_ID ? "" : " with id '"
- + mHostView.getContext().getResources().getResourceEntryName(id) + "'";
- throw new IllegalStateException("Could not find method " + mMethodName
- + "(View) in a parent or ancestor Context for android:onClick "
- + "attribute defined on view " + mHostView.getClass() + idText);
- }
- }
-
- private void resolveMethodForContext(@Nullable Context context, @NonNull String name) {
+ private void resolveMethod(@Nullable Context context, @NonNull String name) {
while (context != null) {
try {
if (!context.isRestricted()) {
- final Method method = context.getClass().getMethod(name, View.class);
+ final Method method = context.getClass().getMethod(mMethodName, View.class);
if (method != null) {
mResolvedMethod = method;
mResolvedContext = context;
@@ -454,6 +425,13 @@
context = null;
}
}
+
+ final int id = mHostView.getId();
+ final String idText = id == View.NO_ID ? "" : " with id '"
+ + mHostView.getContext().getResources().getResourceEntryName(id) + "'";
+ throw new IllegalStateException("Could not find method " + mMethodName
+ + "(View) in a parent or ancestor Context for android:onClick "
+ + "attribute defined on view " + mHostView.getClass() + idText);
}
}
}
diff --git a/fragment/api/current.txt b/fragment/api/current.txt
index a2da2f6..736dccf 100644
--- a/fragment/api/current.txt
+++ b/fragment/api/current.txt
@@ -155,7 +155,6 @@
method public java.lang.Object getLastCustomNonConfigurationInstance();
method public androidx.fragment.app.FragmentManager getSupportFragmentManager();
method public deprecated androidx.loader.app.LoaderManager getSupportLoaderManager();
- method public android.content.Context getThemedContext();
method public androidx.lifecycle.ViewModelStore getViewModelStore();
method public void onAttachFragment(androidx.fragment.app.Fragment);
method public void onMultiWindowModeChanged(boolean);
diff --git a/fragment/src/androidTest/java/androidx/fragment/app/FragmentTest.java b/fragment/src/androidTest/java/androidx/fragment/app/FragmentTest.java
index 08b6da7..2e9c9bc 100644
--- a/fragment/src/androidTest/java/androidx/fragment/app/FragmentTest.java
+++ b/fragment/src/androidTest/java/androidx/fragment/app/FragmentTest.java
@@ -17,12 +17,10 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
import android.app.Instrumentation;
import android.os.Bundle;
-import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -55,7 +53,7 @@
public class FragmentTest {
@Rule
public ActivityTestRule<FragmentTestActivity> mActivityRule =
- new ActivityTestRule<>(FragmentTestActivity.class);
+ new ActivityTestRule<FragmentTestActivity>(FragmentTestActivity.class);
private FragmentTestActivity mActivity;
private Instrumentation mInstrumentation;
@@ -186,40 +184,6 @@
}
@SmallTest
- @UiThreadTest
- @Test
- public void testInflatedViewContext() {
- final FragmentA fragment = new FragmentA();
-
- mActivity.getSupportFragmentManager()
- .beginTransaction()
- .add(R.id.content, fragment)
- .commitNow();
-
- // Assert that the view has the Activity's context
- assertSame(mActivity, fragment.getView().getContext());
- }
-
- @SmallTest
- @UiThreadTest
- @Test
- public void testInflatedViewContext_withThemedContext() {
- // Set the FragmentActivity to use a 'themed context'
- ContextThemeWrapper themedContext = new ContextThemeWrapper(mActivity,
- android.R.style.Theme_Black);
- mActivity.setTestThemedContext(themedContext);
-
- final FragmentA fragment = new FragmentA();
- mActivity.getSupportFragmentManager()
- .beginTransaction()
- .replace(R.id.content, fragment)
- .commitNow();
-
- // Assert that the view uses the themed context
- assertSame(themedContext, fragment.getView().getContext());
- }
-
- @SmallTest
@Test
public void requireMethodsThrowsWhenNotAttached() {
Fragment fragment = new Fragment();
diff --git a/fragment/src/androidTest/java/androidx/fragment/app/test/FragmentTestActivity.java b/fragment/src/androidTest/java/androidx/fragment/app/test/FragmentTestActivity.java
index 8bdb54d..a4c8e68 100644
--- a/fragment/src/androidTest/java/androidx/fragment/app/test/FragmentTestActivity.java
+++ b/fragment/src/androidTest/java/androidx/fragment/app/test/FragmentTestActivity.java
@@ -30,7 +30,6 @@
import android.view.View;
import android.view.ViewGroup;
-import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
@@ -43,7 +42,6 @@
* A simple activity used for Fragment Transitions and lifecycle event ordering
*/
public class FragmentTestActivity extends FragmentActivity {
- private Context mTestThemedContext;
public final CountDownLatch CountDownLatch(1);
@Override
@@ -65,19 +63,6 @@
onDestroyLatch.countDown();
}
- @NonNull
- @Override
- public Context getThemedContext() {
- if (mTestThemedContext != null) {
- return mTestThemedContext;
- }
- return super.getThemedContext();
- }
-
- public void setTestThemedContext(Context testThemedContext) {
- mTestThemedContext = testThemedContext;
- }
-
public static class TestFragment extends Fragment {
public static final int ENTER = 0;
public static final int RETURN = 1;
diff --git a/fragment/src/main/java/androidx/fragment/app/FragmentActivity.java b/fragment/src/main/java/androidx/fragment/app/FragmentActivity.java
index 8fd6bbf..dc8769a 100644
--- a/fragment/src/main/java/androidx/fragment/app/FragmentActivity.java
+++ b/fragment/src/main/java/androidx/fragment/app/FragmentActivity.java
@@ -298,14 +298,6 @@
}
/**
- * Returns the context to be used for inflating any fragment view hierarchies.
- */
- @NonNull
- public Context getThemedContext() {
- return this;
- }
-
- /**
* Perform initialization of all fragments.
*/
@SuppressWarnings("deprecation")
@@ -960,7 +952,7 @@
@Override
@NonNull
public LayoutInflater onGetLayoutInflater() {
- return FragmentActivity.this.getLayoutInflater().cloneInContext(getThemedContext());
+ return FragmentActivity.this.getLayoutInflater().cloneInContext(FragmentActivity.this);
}
@Override
diff --git a/samples/Support7Demos/src/main/AndroidManifest.xml b/samples/Support7Demos/src/main/AndroidManifest.xml
index 075a9e9..dbb3225 100644
--- a/samples/Support7Demos/src/main/AndroidManifest.xml
+++ b/samples/Support7Demos/src/main/AndroidManifest.xml
@@ -354,16 +354,6 @@
</intent-filter>
</activity>
- <activity android:name=".app.AppCompatNightModeActivityConfigChanges"
- android:label="@string/mode_night_activity_config_changes_title"
- android:theme="@style/Theme.AppCompat.DayNight"
- android:configChanges="uiMode">
- <intent-filter>
- <action android:name="android.intent.action.MAIN"/>
- <category android:name="com.example.android.supportv7.SAMPLE_CODE"/>
- </intent-filter>
- </activity>
-
<activity android:name=".app.AppCompatNightModeDialog"
android:label="@string/mode_night_dialog_title"
android:theme="@style/Theme.AppCompat">
diff --git a/samples/Support7Demos/src/main/java/com/example/android/supportv7/app/AppCompatNightModeActivity.java b/samples/Support7Demos/src/main/java/com/example/android/supportv7/app/AppCompatNightModeActivity.java
index ba25c0f..87707bd 100644
--- a/samples/Support7Demos/src/main/java/com/example/android/supportv7/app/AppCompatNightModeActivity.java
+++ b/samples/Support7Demos/src/main/java/com/example/android/supportv7/app/AppCompatNightModeActivity.java
@@ -18,10 +18,7 @@
import android.os.Bundle;
-import android.view.LayoutInflater;
import android.view.View;
-import android.view.ViewGroup;
-import android.webkit.WebView;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
@@ -37,35 +34,18 @@
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.appcompat_night_mode_activity);
- refreshIndicator();
+ setContentView(R.layout.appcompat_night_mode);
}
public void setModeNightNo(View view) {
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_NO);
- refreshIndicator();
}
public void setModeNightYes(View view) {
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_YES);
- refreshIndicator();
}
public void setModeNightAuto(View view) {
getDelegate().setLocalNightMode(AppCompatDelegate.MODE_NIGHT_AUTO);
- refreshIndicator();
- }
-
- public void loadWebView(View view) {
- // Create a WebView, which will reset the Activity resources
- WebView webView = new WebView(this);
- refreshIndicator();
- }
-
- private void refreshIndicator() {
- final ViewGroup indicatorParent = findViewById(R.id.night_mode_indicator_parent);
- indicatorParent.removeAllViews();
- LayoutInflater.from(getThemedContext())
- .inflate(R.layout.appcompat_night_mode_indicator, indicatorParent);
}
}
\ No newline at end of file
diff --git a/samples/Support7Demos/src/main/java/com/example/android/supportv7/app/AppCompatNightModeActivityConfigChanges.java b/samples/Support7Demos/src/main/java/com/example/android/supportv7/app/AppCompatNightModeActivityConfigChanges.java
deleted file mode 100644
index 6ab97fc..0000000
--- a/samples/Support7Demos/src/main/java/com/example/android/supportv7/app/AppCompatNightModeActivityConfigChanges.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright 2018 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.example.android.supportv7.app;
-
-
-/**
- * This demonstrates idiomatic usage of AppCompatActivity with Theme.AppCompat.DayNight.
- * The difference to AppCompatNightModeActivity is that this Activity is set to handle uiMode
- * config changes in the manifest.
- */
-public class AppCompatNightModeActivityConfigChanges extends AppCompatNightModeActivity {
-}
diff --git a/samples/Support7Demos/src/main/java/com/example/android/supportv7/app/AppCompatNightModeAlertDialog.java b/samples/Support7Demos/src/main/java/com/example/android/supportv7/app/AppCompatNightModeAlertDialog.java
index 72f68be..efbd1ea 100644
--- a/samples/Support7Demos/src/main/java/com/example/android/supportv7/app/AppCompatNightModeAlertDialog.java
+++ b/samples/Support7Demos/src/main/java/com/example/android/supportv7/app/AppCompatNightModeAlertDialog.java
@@ -33,7 +33,7 @@
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.appcompat_night_mode_dialog);
+ setContentView(R.layout.appcompat_night_mode);
}
public void setModeNightNo(View view) {
diff --git a/samples/Support7Demos/src/main/java/com/example/android/supportv7/app/AppCompatNightModeDialog.java b/samples/Support7Demos/src/main/java/com/example/android/supportv7/app/AppCompatNightModeDialog.java
index 62f3427..8d1fe32 100644
--- a/samples/Support7Demos/src/main/java/com/example/android/supportv7/app/AppCompatNightModeDialog.java
+++ b/samples/Support7Demos/src/main/java/com/example/android/supportv7/app/AppCompatNightModeDialog.java
@@ -33,7 +33,7 @@
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- setContentView(R.layout.appcompat_night_mode_dialog);
+ setContentView(R.layout.appcompat_night_mode);
}
public void setModeNightNo(View view) {
diff --git a/samples/Support7Demos/src/main/res/layout/appcompat_night_mode_activity.xml b/samples/Support7Demos/src/main/res/layout/appcompat_night_mode.xml
similarity index 72%
rename from samples/Support7Demos/src/main/res/layout/appcompat_night_mode_activity.xml
rename to samples/Support7Demos/src/main/res/layout/appcompat_night_mode.xml
index 53a0cd8..6039f60 100644
--- a/samples/Support7Demos/src/main/res/layout/appcompat_night_mode_activity.xml
+++ b/samples/Support7Demos/src/main/res/layout/appcompat_night_mode.xml
@@ -40,24 +40,21 @@
android:text="@string/mode_night_auto"
android:>
- <Button android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/mode_night_load_webview"
- android:>
+ <View
+ android:layout_width="match_parent"
+ android:layout_height="100dp" />
+
+ <TextView
+ android:id="@+id/text_night_mode"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/night_mode" />
<View
- android:layout_width="match_parent"
- android:layout_height="100dp"/>
-
- <FrameLayout
- android:id="@+id/night_mode_indicator_parent"
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
-
- <include layout="@layout/appcompat_night_mode_indicator"/>
- <include layout="@layout/appcompat_night_mode_indicator"/>
-
- </FrameLayout>
+ android:id="@+id/view_background"
+ android:layout_width="100dp"
+ android:layout_height="100dp"
+ android:background="@drawable/test_night_color_conversion_background" />
</LinearLayout>
diff --git a/samples/Support7Demos/src/main/res/layout/appcompat_night_mode_dialog.xml b/samples/Support7Demos/src/main/res/layout/appcompat_night_mode_dialog.xml
deleted file mode 100644
index 185e345..0000000
--- a/samples/Support7Demos/src/main/res/layout/appcompat_night_mode_dialog.xml
+++ /dev/null
@@ -1,45 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- ~ Copyright 2018 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.
- -->
-
-<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent">
-
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="vertical"
- android:padding="16dp">
-
- <Button android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/mode_night_no"
- android:>
-
- <Button android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/mode_night_yes"
- android:>
-
- <Button android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:text="@string/mode_night_auto"
- android:>
-
- </LinearLayout>
-
-</ScrollView>
\ No newline at end of file
diff --git a/samples/Support7Demos/src/main/res/layout/appcompat_night_mode_indicator.xml b/samples/Support7Demos/src/main/res/layout/appcompat_night_mode_indicator.xml
deleted file mode 100644
index 05c0d4c0..0000000
--- a/samples/Support7Demos/src/main/res/layout/appcompat_night_mode_indicator.xml
+++ /dev/null
@@ -1,37 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- ~ Copyright 2018 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.
- -->
-
-<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:background="?android:attr/colorBackground"
- android:padding="16dp"
- android:orientation="vertical">
-
- <TextView
- android:id="@+id/text_night_mode"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="@string/night_mode"/>
-
- <View
- android:id="@+id/view_background"
- android:layout_width="100dp"
- android:layout_height="100dp"
- android:background="@drawable/test_night_color_conversion_background"/>
-
-</LinearLayout>
\ No newline at end of file
diff --git a/samples/Support7Demos/src/main/res/values-notnight/strings.xml b/samples/Support7Demos/src/main/res/values-notnight/strings.xml
deleted file mode 100644
index 44e4b63..0000000
--- a/samples/Support7Demos/src/main/res/values-notnight/strings.xml
+++ /dev/null
@@ -1,20 +0,0 @@
-<?xml version="1.0" encoding="utf-8"?>
-<!--
- ~ Copyright 2018 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.
- -->
-
-<resources>
- <string name="night_mode">NOT NIGHT</string>
-</resources>
diff --git a/samples/Support7Demos/src/main/res/values/strings.xml b/samples/Support7Demos/src/main/res/values/strings.xml
index ac3c2c5..d11e06b 100644
--- a/samples/Support7Demos/src/main/res/values/strings.xml
+++ b/samples/Support7Demos/src/main/res/values/strings.xml
@@ -217,9 +217,7 @@
<string name="mode_night_yes">MODE_NIGHT_YES</string>
<string name="mode_night_no">MODE_NIGHT_NO</string>
<string name="mode_night_auto">MODE_NIGHT_AUTO</string>
- <string name="mode_night_load_webview">Load WebView</string>
<string name="mode_night_activity_title">AppCompat/DayNight/Activity Usage</string>
- <string name="mode_night_activity_config_changes_title">AppCompat/DayNight/Activity Usage (handling configChanges)</string>
<string name="mode_night_dialog_title">AppCompat/DayNight/Dialog Usage</string>
<string name="mode_night_alertdialog_title">AppCompat/DayNight/AlertDialog Usage</string>
@@ -253,7 +251,7 @@
<string name="simple_selection_demo_activity">RecyclerView Selection: Gesture Only</string>
<string name="fancy_selection_demo_activity">RecyclerView Selection: Gesture and Pointer</string>
- <string name="night_mode">DEFAULT</string>
+ <string name="night_mode">DAY</string>
<string name="text_plain_enabled">Plain enabled</string>
<string name="text_plain_disabled">Plain disabled</string>