Revert "Wrap resources with VectorEnabledTintResources"
This reverts commit 3ea8ff0e5b7e467fc6fd77b92e07c16692a2f5c9.
Reason for revert: Seems to cause LayoutInflater.from(context) to use the wrong Resources object (e.g. can't load vectors)
Change-Id: Iaaa30dc7b72af3bf14ada8255674d1ddca0d2d2b
diff --git a/appcompat/appcompat-resources/api/restricted_current.txt b/appcompat/appcompat-resources/api/restricted_current.txt
index 9ea3d58..84adee2 100644
--- a/appcompat/appcompat-resources/api/restricted_current.txt
+++ b/appcompat/appcompat-resources/api/restricted_current.txt
@@ -87,15 +87,10 @@
@RestrictTo(androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP_PREFIX) public class VectorEnabledTintResources extends android.content.res.Resources {
ctor public VectorEnabledTintResources(android.content.Context, android.content.res.Resources);
- method public int getColor(int) throws android.content.res.Resources.NotFoundException;
- method public android.content.res.ColorStateList! getColorStateList(int) throws android.content.res.Resources.NotFoundException;
method public android.graphics.drawable.Drawable! getDrawable(int) throws android.content.res.Resources.NotFoundException;
- method @RequiresApi(15) public android.graphics.drawable.Drawable! getDrawableForDensity(int, int) throws android.content.res.Resources.NotFoundException;
- method public android.graphics.Movie! getMovie(int) throws android.content.res.Resources.NotFoundException;
method public static boolean isCompatVectorFromResourcesEnabled();
method public static void setCompatVectorFromResourcesEnabled(boolean);
method public static boolean shouldBeUsed();
- method public void updateConfiguration(android.content.res.Configuration!, android.util.DisplayMetrics!);
field public static final int MAX_SDK_WHERE_REQUIRED = 20; // 0x14
}
diff --git a/appcompat/appcompat-resources/src/androidTest/java/androidx/appcompat/widget/TestResources.java b/appcompat/appcompat-resources/src/androidTest/java/androidx/appcompat/widget/TestResources.java
deleted file mode 100644
index a50588f..0000000
--- a/appcompat/appcompat-resources/src/androidTest/java/androidx/appcompat/widget/TestResources.java
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Copyright 2021 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.widget;
-
-import android.content.res.Resources;
-import android.graphics.drawable.Drawable;
-
-/**
- * Observable Resources class.
- */
-@SuppressWarnings("deprecation")
-class TestResources extends Resources {
- private boolean mGetDrawableCalled;
-
- TestResources(Resources res) {
- super(res.getAssets(), res.getDisplayMetrics(), res.getConfiguration());
- }
-
- @Override
- public Drawable getDrawable(int id) throws NotFoundException {
- mGetDrawableCalled = true;
- return super.getDrawable(id);
- }
-
- public void resetGetDrawableCalled() {
- mGetDrawableCalled = false;
- }
-
- public boolean wasGetDrawableCalled() {
- return mGetDrawableCalled;
- }
-}
diff --git a/appcompat/appcompat-resources/src/androidTest/java/androidx/appcompat/widget/TintResourcesTest.java b/appcompat/appcompat-resources/src/androidTest/java/androidx/appcompat/widget/TintResourcesTest.java
index 4aec28c..313399e 100644
--- a/appcompat/appcompat-resources/src/androidTest/java/androidx/appcompat/widget/TintResourcesTest.java
+++ b/appcompat/appcompat-resources/src/androidTest/java/androidx/appcompat/widget/TintResourcesTest.java
@@ -21,6 +21,7 @@
import android.app.Activity;
import android.content.res.Resources;
+import android.graphics.drawable.Drawable;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
@@ -37,16 +38,11 @@
public final androidx.test.rule.ActivityTestRule<Activity> mActivityTestRule =
new androidx.test.rule.ActivityTestRule<>(Activity.class);
- /**
- * Ensures that TintResources delegates calls to the wrapped Resources object.
- */
@Test
public void testTintResourcesDelegateBackToOriginalResources() {
final TestResources testResources =
new TestResources(mActivityTestRule.getActivity().getResources());
-
// First make sure that the flag is false
- testResources.resetGetDrawableCalled();
assertFalse(testResources.wasGetDrawableCalled());
// Now wrap in a TintResources instance and get a Drawable
@@ -57,4 +53,26 @@
// ...and assert that the flag was flipped
assertTrue(testResources.wasGetDrawableCalled());
}
+
+ /**
+ * Special Resources class which returns a known Drawable instance from a special ID
+ */
+ private static class TestResources extends Resources {
+ private boolean mGetDrawableCalled;
+
+ private TestResources(Resources res) {
+ super(res.getAssets(), res.getDisplayMetrics(), res.getConfiguration());
+ }
+
+ @Override
+ public Drawable getDrawable(int id) throws NotFoundException {
+ mGetDrawableCalled = true;
+ return super.getDrawable(id);
+ }
+
+ public boolean wasGetDrawableCalled() {
+ return mGetDrawableCalled;
+ }
+ }
+
}
diff --git a/appcompat/appcompat-resources/src/androidTest/java/androidx/appcompat/widget/VectorEnabledTintResourcesTest.java b/appcompat/appcompat-resources/src/androidTest/java/androidx/appcompat/widget/VectorEnabledTintResourcesTest.java
deleted file mode 100644
index cb02629..0000000
--- a/appcompat/appcompat-resources/src/androidTest/java/androidx/appcompat/widget/VectorEnabledTintResourcesTest.java
+++ /dev/null
@@ -1,60 +0,0 @@
-/*
- * Copyright 2019 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.widget;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import android.app.Activity;
-import android.content.res.Resources;
-
-import androidx.test.ext.junit.runners.AndroidJUnit4;
-import androidx.test.filters.SmallTest;
-
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-@SuppressWarnings("deprecation")
-@SmallTest
-@RunWith(AndroidJUnit4.class)
-public class VectorEnabledTintResourcesTest {
- @Rule
- public final androidx.test.rule.ActivityTestRule<Activity> mActivityTestRule =
- new androidx.test.rule.ActivityTestRule<>(Activity.class);
-
- /**
- * Ensures that TintResources delegates calls to the wrapped Resources object.
- */
- @Test
- public void testVectorEnabledTintResourcesDelegateBackToOriginalResources() {
- final TestResources testResources =
- new TestResources(mActivityTestRule.getActivity().getResources());
-
- // First make sure that the flag is false
- testResources.resetGetDrawableCalled();
- assertFalse(testResources.wasGetDrawableCalled());
-
- // Now wrap in a TintResources instance and get a Drawable
- final Resources tintResources =
- new VectorEnabledTintResources(mActivityTestRule.getActivity(), testResources);
- tintResources.getDrawable(android.R.drawable.ic_delete);
-
- // ...and assert that the flag was flipped
- assertTrue(testResources.wasGetDrawableCalled());
- }
-}
diff --git a/appcompat/appcompat-resources/src/main/java/androidx/appcompat/widget/VectorEnabledTintResources.java b/appcompat/appcompat-resources/src/main/java/androidx/appcompat/widget/VectorEnabledTintResources.java
index 6003628..b375ac4 100644
--- a/appcompat/appcompat-resources/src/main/java/androidx/appcompat/widget/VectorEnabledTintResources.java
+++ b/appcompat/appcompat-resources/src/main/java/androidx/appcompat/widget/VectorEnabledTintResources.java
@@ -35,7 +35,7 @@
* @hide
*/
@RestrictTo(LIBRARY_GROUP_PREFIX)
-public class VectorEnabledTintResources extends ResourcesWrapper {
+public class VectorEnabledTintResources extends Resources {
private static boolean sCompatVectorFromResourcesEnabled = false;
public static boolean shouldBeUsed() {
@@ -53,7 +53,7 @@
@SuppressWarnings("deprecation")
public VectorEnabledTintResources(@NonNull final Context context,
@NonNull final Resources res) {
- super(res);
+ super(res.getAssets(), res.getDisplayMetrics(), res.getConfiguration());
mContextRef = new WeakReference<>(context);
}