Add dark theme

Julien LepillerSat Jul 24 02:56:47+0200 2021

5463422

Add dark theme

app/src/main/java/eu/lepiller/nani/MainActivity.java

7676
7777
        Button radical_button = findViewById(R.id.radical_button);
7878
79-
        pagerAdapter = new ResultPagerAdapter(this.getApplicationContext());
79+
        pagerAdapter = new ResultPagerAdapter(this);
8080
        pagerAdapter.setReadingStyle(readingStyle);
8181
        pagerAdapter.notifyDataSetChanged();
8282
        viewPager2.setAdapter(pagerAdapter);

app/src/main/java/eu/lepiller/nani/PitchDiagramView.java

11
package eu.lepiller.nani;
22
33
import android.content.Context;
4+
import android.content.res.Configuration;
45
import android.content.res.TypedArray;
56
import android.graphics.Canvas;
67
import android.graphics.Color;

4546
4647
    private void setDefaults() {
4748
        textColor = getContext().getResources().getColor(android.R.color.tab_indicator_text);
48-
        pitchColor = getContext().getResources().getColor(android.R.color.background_dark);
49+
        int mode = getContext().getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
50+
        if(mode == Configuration.UI_MODE_NIGHT_NO) {
51+
            pitchColor = getContext().getResources().getColor(android.R.color.background_dark);
52+
        } else if(mode == Configuration.UI_MODE_NIGHT_YES) {
53+
            pitchColor = getContext().getResources().getColor(android.R.color.background_light);
54+
        }
4955
        textSize = new TextView(getContext()).getTextSize();
5056
    }
5157

app/src/main/res/drawable-night/ic_pause.xml unknown status 1

1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
    android:width="32dp"
3+
    android:height="32dp"
4+
    android:viewportWidth="32"
5+
    android:viewportHeight="32">
6+
    <path
7+
        android:pathData="M6,2h8v28h-8z"
8+
        android:strokeWidth="0.22660473"
9+
        android:fillColor="#dddddd"/>
10+
    <path
11+
        android:pathData="M18,2h8v28h-8z"
12+
        android:strokeWidth="0.22660473"
13+
        android:fillColor="#dddddd"/>
14+
</vector>

app/src/main/res/drawable-night/ic_pitch_border.xml unknown status 1

1+
<?xml version="1.0" encoding="utf-8"?>
2+
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
3+
    <solid android:color="@android:color/black" />
4+
    <stroke android:width="1dip" android:color="#444"/>
5+
</shape>
5<
06<
\ No newline at end of file

app/src/main/res/layout/activity_help_pitch.xml

124124
                        android:orientation="vertical"
125125
                        android:layout_width="wrap_content"
126126
                        android:layout_height="wrap_content"
127-
                        android:background="@android:color/white">
127+
                        android:background="@color/colorWhite">
128128
129129
                        <eu.lepiller.nani.PitchDiagramView
130130
                            android:layout_width="wrap_content"

180180
                        android:orientation="vertical"
181181
                        android:layout_width="wrap_content"
182182
                        android:layout_height="wrap_content"
183-
                        android:background="@android:color/white">
183+
                        android:background="@color/colorWhite">
184184
185185
                        <eu.lepiller.nani.PitchDiagramView
186186
                            android:layout_width="wrap_content"

258258
                        android:orientation="vertical"
259259
                        android:layout_width="wrap_content"
260260
                        android:layout_height="wrap_content"
261-
                        android:background="@android:color/white">
261+
                        android:background="@color/colorWhite">
262262
263263
                        <eu.lepiller.nani.PitchDiagramView
264264
                            android:layout_width="wrap_content"

359359
                    <LinearLayout
360360
                        android:layout_width="wrap_content"
361361
                        android:layout_height="wrap_content"
362-
                        android:background="@android:color/white"
362+
                        android:background="@color/colorWhite"
363363
                        android:orientation="vertical">
364364
365365
                        <eu.lepiller.nani.PitchDiagramView

app/src/main/res/layout/activity_help_radical.xml

125125
                    tools:ignore="HardcodedText" />
126126
            </TableRow>
127127
            <TableRow
128-
                android:background="@android:color/white"
128+
                android:background="@color/colorWhite"
129129
                android:layout_width="wrap_content"
130130
                android:layout_height="wrap_content">
131131
                <TextView

216216
                    tools:ignore="HardcodedText" />
217217
            </TableRow>
218218
            <TableRow
219-
                android:background="@android:color/white"
219+
                android:background="@color/colorWhite"
220220
                android:layout_width="wrap_content"
221221
                android:layout_height="wrap_content">
222222
                <TextView

314314
                    tools:ignore="HardcodedText" />
315315
            </TableRow>
316316
            <TableRow
317-
                android:background="@android:color/white"
317+
                android:background="@color/colorWhite"
318318
                android:layout_width="wrap_content"
319319
                android:layout_height="wrap_content">
320320
                <TextView

app/src/main/res/layout/activity_help_romaji.xml

4343
            android:layout_height="wrap_content"
4444
            android:layout_marginBottom="16dp">
4545
            <TableRow
46-
                android:background="@android:color/white">
46+
                android:background="@color/colorWhite">
4747
                <LinearLayout
4848
                    android:layout_width="wrap_content"
4949
                    android:layout_height="wrap_content"

383383
                </LinearLayout>
384384
            </TableRow>
385385
            <TableRow
386-
                android:background="@android:color/white">
386+
                android:background="@color/colorWhite">
387387
                <LinearLayout
388388
                    android:layout_width="wrap_content"
389389
                    android:layout_height="wrap_content"

785785
                </LinearLayout>
786786
            </TableRow>
787787
            <TableRow
788-
                android:background="@android:color/white">
788+
                android:background="@color/colorWhite">
789789
                <LinearLayout
790790
                    android:layout_width="wrap_content"
791791
                    android:layout_height="wrap_content"

12641264
                </LinearLayout>
12651265
            </TableRow>
12661266
            <TableRow
1267-
                android:background="@android:color/white">
1267+
                android:background="@color/colorWhite">
12681268
                <LinearLayout
12691269
                    android:layout_width="wrap_content"
12701270
                    android:layout_height="wrap_content"

15761576
                </LinearLayout>
15771577
            </TableRow>
15781578
            <TableRow
1579-
                android:background="@android:color/white">
1579+
                android:background="@color/colorWhite">
15801580
                <LinearLayout
15811581
                    android:layout_width="wrap_content"
15821582
                    android:layout_height="wrap_content"

19571957
                </LinearLayout>
19581958
            </TableRow>
19591959
            <TableRow
1960-
                android:background="@android:color/white">
1960+
                android:background="@color/colorWhite">
19611961
                <LinearLayout
19621962
                    android:layout_width="wrap_content"
19631963
                    android:layout_height="wrap_content"

23312331
                </LinearLayout>
23322332
            </TableRow>
23332333
            <TableRow
2334-
                android:background="@android:color/white">
2334+
                android:background="@color/colorWhite">
23352335
                <LinearLayout
23362336
                    android:layout_width="wrap_content"
23372337
                    android:layout_height="wrap_content"

26482648
                </LinearLayout>
26492649
            </TableRow>
26502650
            <TableRow
2651-
                android:background="@android:color/white">
2651+
                android:background="@color/colorWhite">
26522652
                <LinearLayout
26532653
                    android:layout_width="wrap_content"
26542654
                    android:layout_height="wrap_content"

28062806
                    tools:ignore="HardcodedText" />
28072807
            </TableRow>
28082808
            <TableRow
2809-
                android:background="@android:color/white">
2809+
                android:background="@color/colorWhite">
28102810
                <TextView
28112811
                    android:layout_width="wrap_content"
28122812
                    android:layout_height="wrap_content"

28442844
                    tools:ignore="HardcodedText" />
28452845
            </TableRow>
28462846
            <TableRow
2847-
                android:background="@android:color/white">
2847+
                android:background="@color/colorWhite">
28482848
                <TextView
28492849
                    android:layout_width="wrap_content"
28502850
                    android:layout_height="wrap_content"

28822882
                    tools:ignore="HardcodedText" />
28832883
            </TableRow>
28842884
            <TableRow
2885-
                android:background="@android:color/white">
2885+
                android:background="@color/colorWhite">
28862886
                <TextView
28872887
                    android:layout_width="wrap_content"
28882888
                    android:layout_height="wrap_content"

app/src/main/res/values-night/colors.xml unknown status 1

1+
<?xml version="1.0" encoding="utf-8"?>
2+
<resources>
3+
    <color name="colorPrimary">#008577</color>
4+
    <color name="colorPrimaryDark">#00574B</color>
5+
    <color name="colorAccent">#D81B60</color>
6+
    <color name="colorWhite">#000000</color>
7+
    <color name="colorGrey">#111111</color>
8+
    <color name="colorUpdate">#F4DE96</color>
9+
    <color name="colorDarkerGrey">#1f1f1f</color>
10+
    <color name="colorDarkGrey">#2a2a2a</color>
11+
    <color name="colorTextGrey">#909090</color>
12+
    <color name="colorBlack">#505050</color>
13+
    <color name="colorLang">#925424</color>
14+
</resources>

app/src/main/res/values/colors.xml

33
    <color name="colorPrimary">#008577</color>
44
    <color name="colorPrimaryDark">#00574B</color>
55
    <color name="colorAccent">#D81B60</color>
6+
    <color name="colorWhite">#FFFFFF</color>
67
    <color name="colorGrey">#EEF2EE</color>
78
    <color name="colorUpdate">#F4DE96</color>
89
    <color name="colorDarkerGrey">#e0e3e0</color>

app/src/main/res/values/styles.xml

11
<resources>
22
33
    <!-- Base application theme. -->
4-
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
4+
    <style name="AppTheme" parent="Theme.AppCompat.DayNight">
55
        <!-- Customize your theme here. -->
66
        <item name="colorPrimary">@color/colorPrimary</item>
77
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>