Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7f651ceb authored by Bill Lin's avatar Bill Lin
Browse files

Fix java.lang.NoSuchFieldError on R$styleable

Some unused styleable was removed by proguard that TestCase can't refer
at runtime.
Refactor and move styleable from docsui to TestCase res if necessary
(Prevent unused resources removed by proguard)

Note: GridItem default color is transparent(res/color/item_doc_grid_tint.xml)
Remove useless GridItem testCase due to the color is not relatie to theme

Fixes: 131835503
Fixes: 131735635

Test: atest DocumentsUIGoogleTests

Change-Id: I20b0d823c0d166466f18023928021ced58e32c21
parent e66ca09d
Loading
Loading
Loading
Loading
+0 −36
Original line number Diff line number Diff line
@@ -15,22 +15,6 @@
-->
<resources>

    <declare-styleable name="ActionBarView">
        <attr name="android:colorBackground" />
        <attr name="android:colorPrimary" />
        <attr name="android:colorControlNormal" />
        <attr name="android:textColorPrimary" />
    </declare-styleable>

    <declare-styleable name="DrawerMenuTitle">
        <attr name="android:textColor" />
        <attr name="android:textSize" />
    </declare-styleable>

    <declare-styleable name="CardView">
        <attr name="android:colorBackgroundFloating" format="color" />
    </declare-styleable>

    <declare-styleable name="DropBadgeView">
        <attr name="state_reject_drop" format="boolean"/>
        <attr name="state_copy" format="boolean"/>
@@ -47,24 +31,4 @@
        <attr name="state_highlighted" format="boolean"/>
    </declare-styleable>

    <declare-styleable name="SnackbarView">
        <attr name="android:textColor" />
    </declare-styleable>

    <declare-styleable name="SystemWindow">
        <attr name="android:statusBarColor" />
        <attr name="android:navigationBarColor" />
        <attr name="android:windowBackground" />
        <attr name="android:windowLightStatusBar" />
        <attr name="android:windowLightNavigationBar" />
    </declare-styleable>

    <declare-styleable name="SwipeRefresh">
        <attr name="android:colorPrimary" />
    </declare-styleable>

    <declare-styleable name="MaterialButtons">
        <attr name="materialButtonStyle" format="reference" />
        <attr name="materialButtonOutlinedStyle" format="reference"/>
    </declare-styleable>
</resources>
+4 −3
Original line number Diff line number Diff line
@@ -42,9 +42,10 @@ public class DocumentsSwipeRefreshLayout extends SwipeRefreshLayout {
    public DocumentsSwipeRefreshLayout(Context context, AttributeSet attrs) {
        super(context, attrs);

        TypedArray a = context.obtainStyledAttributes(R.styleable.SwipeRefresh);
        @ColorRes int colorId = a.getResourceId(R.styleable.SwipeRefresh_android_colorPrimary,
                -1);
        final int[] styledAttrs = {android.R.attr.colorPrimary};

        TypedArray a = context.obtainStyledAttributes(styledAttrs);
        @ColorRes int colorId = a.getResourceId(0, -1);
        if (colorId == -1) {
            Log.w(TAG, "Retrive colorPrimary colorId from theme fail, assign R.color.primary");
            colorId = R.color.primary;
+34 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 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
  -->
<resources>

    <declare-styleable name="ThemeColor">
        <attr name="android:colorBackground" />
        <attr name="android:colorPrimary" />
        <attr name="android:colorControlNormal" />
        <attr name="android:textColorPrimary" />
    </declare-styleable>

    <declare-styleable name="SystemWindow">
        <attr name="android:statusBarColor" />
        <attr name="android:navigationBarColor" />
        <attr name="android:windowBackground" />
        <attr name="android:windowLightStatusBar" />
        <attr name="android:windowLightNavigationBar" />
    </declare-styleable>

</resources>
 No newline at end of file
+10 −13
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@ import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.documentsui.R;
import com.android.documentsui.tests.R;

import org.junit.Before;
import org.junit.Test;
@@ -47,14 +47,9 @@ public class DarkThemeUiTest extends ThemeUiTestBase {

    @Test
    public void themeNightModeEnable_actionBarColorShouldBeDark() {
        assertTheme(R.styleable.ActionBarView, R.styleable.ActionBarView_android_colorBackground,
                mTheme.getResources().getColor(R.color.app_background_color, mTheme));
    }

    @Test
    public void themeNightModeEnable_gridItemTintColorShouldBeThemeable() {
        assertTheme(R.styleable.GridItem, R.styleable.GridItem_gridItemTint,
                mTheme.getResources().getColor(R.color.item_doc_grid_tint, mTheme));
        assertTheme(R.styleable.ThemeColor, R.styleable.ThemeColor_android_colorBackground,
                mTheme.getResources().getColor(com.android.documentsui.R.color.app_background_color,
                        mTheme));
    }

    @Test
@@ -78,18 +73,20 @@ public class DarkThemeUiTest extends ThemeUiTestBase {
    @Test
    public void themeNightModeEnable_windowBackgroundColorShouldBeDark() {
        assertTheme(R.styleable.SystemWindow, R.styleable.SystemWindow_android_windowBackground,
                mTheme.getResources().getColor(R.color.app_background_color, mTheme));
                mTheme.getResources().getColor(com.android.documentsui.R.color.app_background_color,
                        mTheme));
    }

    @Test
    public void themeNightModeEnable_statusBarColorShouldBeDark() {
        assertTheme(R.styleable.SystemWindow, R.styleable.SystemWindow_android_statusBarColor,
                mTheme.getResources().getColor(R.color.app_background_color, mTheme));
                mTheme.getResources().getColor(com.android.documentsui.R.color.app_background_color,
                        mTheme));
    }

    @Test
    public void appCompatThemeNightModeEnable_colorPrimaryShouldBeThemeable() {
        assertTheme(R.styleable.AppCompatTheme, R.styleable.AppCompatTheme_colorPrimary,
                mTheme.getResources().getColor(R.color.primary, mTheme));
        assertTheme(R.styleable.ThemeColor, R.styleable.ThemeColor_android_colorPrimary,
                mTheme.getResources().getColor(com.android.documentsui.R.color.primary, mTheme));
    }
}
 No newline at end of file
+4 −10
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ import android.graphics.Color;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.documentsui.R;
import com.android.documentsui.tests.R;

import org.junit.Before;
import org.junit.Test;
@@ -44,16 +44,10 @@ public class ThemeUiTest extends ThemeUiTestBase {

    @Test
    public void themeNightModeDisable_actionBarColorShouldBeLight() {
        assertTheme(R.styleable.ActionBarView, R.styleable.ActionBarView_android_colorBackground,
        assertTheme(R.styleable.ThemeColor, R.styleable.ThemeColor_android_colorBackground,
                Color.WHITE);
    }

    @Test
    public void themeNightModeDisable_gridItemTintColorShouldBeThemeable() {
        assertTheme(R.styleable.GridItem, R.styleable.GridItem_gridItemTint,
                mTheme.getResources().getColor(R.color.item_doc_grid_tint, mTheme));
    }

    @Test
    public void themeNightModeDisable_windowLightNavigationBarShouldBeTrue() {
        assertTheme(R.styleable.SystemWindow,
@@ -86,7 +80,7 @@ public class ThemeUiTest extends ThemeUiTestBase {

    @Test
    public void appCompatThemeNightModeDisable_colorPrimaryShouldBeThemeable() {
        assertTheme(R.styleable.AppCompatTheme, R.styleable.AppCompatTheme_colorPrimary,
                mTheme.getResources().getColor(R.color.primary, mTheme));
        assertTheme(R.styleable.ThemeColor, R.styleable.ThemeColor_android_colorPrimary,
                mTheme.getResources().getColor(com.android.documentsui.R.color.primary, mTheme));
    }
}