Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#ESOB004_DarkUI #58

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,45 @@
/**
* Checks in theme xmls and manifest if the application override a "light" theme:
* <ul>
* <li>Check styles that inherit Theme.Holo.Light or Theme.AppCompat.Light themes (or other themes that begin by
* Theme.Holo.Light or Theme.AppCompat.Light)</li>
* <li>Check themes set in manifest that begin by "@android:style/Theme.Holo.Light" or "@style/Theme.AppCompat.Light"
* </li>
* <li>Check styles that inherit Theme.Holo.Light,
* Theme.AppCompat.Light,
* Theme.Material.Light,
* Theme.Material3.Light or
* Theme.MaterialComponents.Light
* (or other themes that begin by Theme.Holo.Light,
* Theme.AppCompat.Light,
* Theme.Material.Light,
* Theme.Material3.Light or
* Theme.MaterialComponents.Light )</li>
*
* <li>Check themes set in manifest that begin by "@android:style/Theme.Holo.Light",
* "@style/Theme.AppCompat.Light",
* "@android:style/Theme.Material.Light",
* "@style/Theme.Material3.Light" or
* "@style/Theme.MaterialComponents.Light"</li>
* </ul>
*/
@Rule(key = "ESOB004", name = "ecoCodeDarkUITheme")
public class DarkUIThemeXmlRule extends XPathSimpleCheck {

private static final String STYLE_HOLO_LIGHT = "/resources/style[starts-with(@parent, \"@android:style/Theme.Holo.Light\")]/@parent";
private static final String STYLE_APPCOMPAT_LIGHT = "/resources/style[starts-with(@parent, \"Theme.AppCompat.Light\")]/@parent";
private static final String STYLE_MATERIAL_LIGHT = "/resources/style[starts-with(@parent, \"@android:style/Theme.Material.Light\")]/@parent";
private static final String STYLE_MATERIAL3_LIGHT = "/resources/style[starts-with(@parent, \"Theme.Material3.Light\")]/@parent";
private static final String STYLE_MATERIALCOMPONENTS_LIGHT = "/resources/style[starts-with(@parent, \"Theme.MaterialComponents.Light\")]/@parent";

private static final String MANIFEST_HOLO_LIGHT = "/manifest/application[starts-with(@theme, \"@android:style/Theme.Holo.Light\")]/@theme";
private static final String MANIFEST_APPCOMPAT_LIGHT = "/manifest/application[starts-with(@theme, \"@style/Theme.AppCompat.Light\")]/@theme";

private static final String MANIFEST_MATERIAL_LIGHT = "/manifest/application[starts-with(@theme, \"@android:style/Theme.Material.Light\")]/@theme";
private static final String MANIFEST_MATERIAL3_LIGHT = "/manifest/application[starts-with(@theme, \"@style/Theme.Material3.Light\")]/@theme";
private static final String MANIFEST_MATERIALCOMPONENTS_LIGHT = "/manifest/application[starts-with(@theme, \"@style/Theme.MaterialComponents.Light\")]/@theme";
@Override
protected String getMessage() {
return "Using a light theme may have a significant impact on energy consumption on (AM)OLED screens.";
}

@Override
protected String getXPathExpressionString() {
return STYLE_HOLO_LIGHT + "|" + STYLE_APPCOMPAT_LIGHT + "|" + MANIFEST_HOLO_LIGHT + "|" + MANIFEST_APPCOMPAT_LIGHT;
return STYLE_HOLO_LIGHT + "|" + STYLE_APPCOMPAT_LIGHT + "|" + STYLE_MATERIAL_LIGHT + "|" + STYLE_MATERIAL3_LIGHT + "|" + STYLE_MATERIALCOMPONENTS_LIGHT + "|" + MANIFEST_HOLO_LIGHT + "|" + MANIFEST_APPCOMPAT_LIGHT + "|" + MANIFEST_MATERIAL_LIGHT + "|" + MANIFEST_MATERIAL3_LIGHT + "|" + MANIFEST_MATERIALCOMPONENTS_LIGHT;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,13 @@

<application android:theme="@style/Theme.AppCompat.Light.DarkActionBar"> <!-- Noncompliant {{Using a light theme may have a significant impact on energy consumption on (AM)OLED screens.}} -->
</application>

<application android:theme="@android:style/Theme.Material.Light"> <!-- Noncompliant {{Using a light theme may have a significant impact on energy consumption on (AM)OLED screens.}} -->
</application>

<application android:theme="@style/Theme.Material3.Light"> <!-- Noncompliant {{Using a light theme may have a significant impact on energy consumption on (AM)OLED screens.}} -->
</application>

<application android:theme="@style/Theme.MaterialComponents.Light"> <!-- Noncompliant {{Using a light theme may have a significant impact on energy consumption on (AM)OLED screens.}} -->
</application>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,21 @@
<!-- Customize your theme here. -->
</style>

<style name="Theme.EcoCodeDark" parent="@android:style/Theme.Holo">
<style name="Theme.EcoCode" parent="@android:style/Theme.Holo">
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
<item name="colorOnPrimary">@color/white</item>
<!-- Secondary brand color. -->
<item name="colorSecondary">@color/teal_200</item>
<item name="colorSecondaryVariant">@color/teal_700</item>
<item name="colorOnSecondary">@color/black</item>
<!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. -->
</style>

<style name="Theme.EcoCodeDark" parent="@android:style/Theme.Material.Light"> <!-- Noncompliant {{Using a light theme may have a significant impact on energy consumption on (AM)OLED screens.}} -->
<!-- Primary brand color. -->
<item name="colorPrimary">@color/purple_500</item>
<item name="colorPrimaryVariant">@color/purple_700</item>
Expand Down Expand Up @@ -56,4 +70,15 @@
<!-- Primary brand color. -->
<item name="colorPrimary">@color/black</item>
</style>

<style name="Theme.MaterialComponents.Light" parent="Theme.MaterialComponents.Light"> <!-- Noncompliant {{Using a light theme may have a significant impact on energy consumption on (AM)OLED screens.}} -->
<!-- Primary brand color. -->
<item name="colorPrimary">@color/white</item>
</style>

<style name="Theme.Material3.Light" parent="Theme.Material3.Light"> <!-- Noncompliant {{Using a light theme may have a significant impact on energy consumption on (AM)OLED screens.}} -->
<!-- Primary brand color. -->
<item name="colorPrimary">@color/white</item>
</style>

</resources>