mirror of
https://github.com/russok/FitoTrack.git
synced 2025-10-28 00:02:11 -07:00
#48 Dark mode
This commit is contained in:
parent
4a89e95b41
commit
5adc2a0536
@ -32,6 +32,7 @@ import java.util.List;
|
||||
import de.tadris.fitness.data.AppDatabase;
|
||||
import de.tadris.fitness.data.UserPreferences;
|
||||
import de.tadris.fitness.recording.LocationListener;
|
||||
import de.tadris.fitness.util.FitoTrackThemes;
|
||||
import de.tadris.fitness.util.unit.UnitUtils;
|
||||
|
||||
public class Instance {
|
||||
@ -50,12 +51,14 @@ public class Instance {
|
||||
public final AppDatabase db;
|
||||
public final List<LocationListener.LocationChangeListener> locationChangeListeners = new ArrayList<>();
|
||||
public final UserPreferences userPreferences;
|
||||
public final FitoTrackThemes themes;
|
||||
|
||||
public boolean pressureAvailable= false;
|
||||
public float lastPressure= 0;
|
||||
|
||||
private Instance(Context context) {
|
||||
userPreferences= new UserPreferences(context);
|
||||
themes = new FitoTrackThemes(context);
|
||||
db = Room.databaseBuilder(context.getApplicationContext(), AppDatabase.class, DATABASE_NAME)
|
||||
.addMigrations(new Migration(1, 2) {
|
||||
@Override
|
||||
|
||||
@ -23,15 +23,23 @@ import android.Manifest;
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.util.TypedValue;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.core.app.ActivityCompat;
|
||||
|
||||
import de.tadris.fitness.Instance;
|
||||
import de.tadris.fitness.R;
|
||||
|
||||
abstract public class FitoTrackActivity extends Activity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setTheme(Instance.getInstance(this).themes.getDefaultTheme());
|
||||
}
|
||||
|
||||
int getThemePrimaryColor() {
|
||||
final TypedValue value = new TypedValue ();
|
||||
|
||||
@ -23,6 +23,7 @@ import android.app.AlertDialog;
|
||||
import android.media.Ringtone;
|
||||
import android.media.RingtoneManager;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceActivity;
|
||||
@ -31,13 +32,21 @@ import android.preference.RingtonePreference;
|
||||
import android.text.TextUtils;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import de.tadris.fitness.Instance;
|
||||
import de.tadris.fitness.R;
|
||||
import de.tadris.fitness.util.unit.UnitUtils;
|
||||
|
||||
public abstract class FitoTrackSettingsActivity extends PreferenceActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
setTheme(Instance.getInstance(this).themes.getDefaultTheme());
|
||||
super.onCreate(savedInstanceState);
|
||||
}
|
||||
|
||||
protected void showErrorDialog(Exception e, @StringRes int title, @StringRes int message) {
|
||||
new AlertDialog.Builder(this)
|
||||
.setTitle(title)
|
||||
|
||||
@ -32,7 +32,7 @@ public class LauncherActivity extends Activity {
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setTheme(R.style.AppThemeNoActionbar);
|
||||
setTheme(android.R.style.Theme_Material_Light_NoActionBar);
|
||||
setContentView(R.layout.activity_main);
|
||||
}
|
||||
|
||||
|
||||
@ -19,7 +19,6 @@
|
||||
|
||||
package de.tadris.fitness.activity;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
@ -41,7 +40,7 @@ import de.tadris.fitness.data.WorkoutType;
|
||||
import de.tadris.fitness.util.DialogUtils;
|
||||
import de.tadris.fitness.view.WorkoutAdapter;
|
||||
|
||||
public class ListWorkoutsActivity extends Activity implements WorkoutAdapter.WorkoutAdapterListener {
|
||||
public class ListWorkoutsActivity extends FitoTrackActivity implements WorkoutAdapter.WorkoutAdapterListener {
|
||||
|
||||
private RecyclerView listView;
|
||||
private RecyclerView.Adapter adapter;
|
||||
|
||||
@ -90,7 +90,7 @@ public class RecordWorkoutActivity extends FitoTrackActivity implements Location
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setTheme(ACTIVITY.theme);
|
||||
setTheme(Instance.getInstance(this).themes.getWorkoutTypeTheme(ACTIVITY));
|
||||
setContentView(R.layout.activity_record_workout);
|
||||
|
||||
setTitle(R.string.recordWorkout);
|
||||
|
||||
@ -62,6 +62,7 @@ public class SettingsActivity extends FitoTrackSettingsActivity {
|
||||
|
||||
bindPreferenceSummaryToValue(findPreference("unitSystem"));
|
||||
bindPreferenceSummaryToValue(findPreference("mapStyle"));
|
||||
bindPreferenceSummaryToValue(findPreference("themeSetting"));
|
||||
|
||||
findPreference("weight").setOnPreferenceClickListener(preference -> {
|
||||
showWeightPicker();
|
||||
|
||||
@ -75,7 +75,7 @@ public abstract class WorkoutActivity extends InformationActivity {
|
||||
void initBeforeContent() {
|
||||
workout= selectedWorkout;
|
||||
samples= Arrays.asList(Instance.getInstance(this).db.workoutDao().getAllSamplesOfWorkout(workout.id));
|
||||
setTheme(workout.getWorkoutType().theme);
|
||||
setTheme(Instance.getInstance(this).themes.getWorkoutTypeTheme(workout.getWorkoutType()));
|
||||
}
|
||||
|
||||
void initAfterContent() {
|
||||
|
||||
@ -26,25 +26,26 @@ import de.tadris.fitness.R;
|
||||
|
||||
public enum WorkoutType {
|
||||
|
||||
RUNNING("running", R.string.workoutTypeRunning, 7, true, R.style.Running),
|
||||
HIKING("hiking", R.string.workoutTypeHiking, 7, true, R.style.Hiking),
|
||||
CYCLING("cycling", R.string.workoutTypeCycling, 12, true, R.style.Bicycling),
|
||||
OTHER("other", R.string.workoutTypeOther, 7, true, R.style.AppTheme);
|
||||
RUNNING("running", R.string.workoutTypeRunning, 7, true, R.style.Running, R.style.RunningDark),
|
||||
HIKING("hiking", R.string.workoutTypeHiking, 7, true, R.style.Hiking, R.style.HikingDark),
|
||||
CYCLING("cycling", R.string.workoutTypeCycling, 12, true, R.style.Bicycling, R.style.BicyclingDark),
|
||||
OTHER("other", R.string.workoutTypeOther, 7, true, R.style.AppTheme, R.style.AppThemeDark);
|
||||
|
||||
public String id;
|
||||
public @StringRes
|
||||
int title;
|
||||
@StringRes
|
||||
public int title;
|
||||
public int minDistance; // Minimum distance between samples
|
||||
public boolean hasGPS;
|
||||
public @StyleRes
|
||||
int theme;
|
||||
@StyleRes
|
||||
public int lightTheme, darkTheme;
|
||||
|
||||
WorkoutType(String id, int title, int minDistance, boolean hasGPS, int theme) {
|
||||
WorkoutType(String id, int title, int minDistance, boolean hasGPS, int lightTheme, int darkTheme) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.minDistance = minDistance;
|
||||
this.hasGPS = hasGPS;
|
||||
this.theme = theme;
|
||||
this.lightTheme = lightTheme;
|
||||
this.darkTheme = darkTheme;
|
||||
}
|
||||
|
||||
public static WorkoutType getTypeById(String id) {
|
||||
|
||||
@ -55,7 +55,7 @@ public class CalorieCalculator {
|
||||
if (type == WorkoutType.CYCLING) {
|
||||
return Math.max(3, (speedInKmh-10) / 1.5);
|
||||
}
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright (c) 2020 Jannis Scheibe <jannis@tadris.de>
|
||||
*
|
||||
* This file is part of FitoTrack
|
||||
*
|
||||
* FitoTrack is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* FitoTrack is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.tadris.fitness.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Configuration;
|
||||
import android.preference.PreferenceManager;
|
||||
|
||||
import androidx.annotation.StyleRes;
|
||||
|
||||
import de.tadris.fitness.R;
|
||||
import de.tadris.fitness.data.WorkoutType;
|
||||
|
||||
public class FitoTrackThemes {
|
||||
|
||||
private static final int THEME_SETTING_AUTO = 0;
|
||||
private static final int THEME_SETTING_LIGHT = 1;
|
||||
private static final int THEME_SETTING_DARK = 2;
|
||||
|
||||
private Context context;
|
||||
|
||||
public FitoTrackThemes(Context context) {
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
@StyleRes
|
||||
public int getDefaultTheme() {
|
||||
if (shouldUseLightMode()) {
|
||||
return R.style.AppTheme;
|
||||
} else {
|
||||
return R.style.AppThemeDark;
|
||||
}
|
||||
}
|
||||
|
||||
@StyleRes
|
||||
public int getWorkoutTypeTheme(WorkoutType type) {
|
||||
if (shouldUseLightMode()) {
|
||||
return type.lightTheme;
|
||||
} else {
|
||||
return type.darkTheme;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean shouldUseLightMode() {
|
||||
switch (getThemeSetting()) {
|
||||
default:
|
||||
case THEME_SETTING_AUTO:
|
||||
return !isSystemNightModeEnabled();
|
||||
case THEME_SETTING_LIGHT:
|
||||
return true;
|
||||
case THEME_SETTING_DARK:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private int getThemeSetting() {
|
||||
String setting = PreferenceManager.getDefaultSharedPreferences(context).getString("themeSetting", String.valueOf(THEME_SETTING_AUTO));
|
||||
assert setting != null;
|
||||
return Integer.parseInt(setting);
|
||||
}
|
||||
|
||||
private boolean isSystemNightModeEnabled() {
|
||||
int nightModeFlags = context.getResources().getConfiguration().uiMode & Configuration.UI_MODE_NIGHT_MASK;
|
||||
return nightModeFlags == Configuration.UI_MODE_NIGHT_YES;
|
||||
}
|
||||
|
||||
}
|
||||
@ -21,7 +21,7 @@
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:theme="@style/AppThemeNoActionbar"
|
||||
android:theme="@android:style/Theme.Material.Light.NoActionBar"
|
||||
tools:context=".activity.LauncherActivity">
|
||||
|
||||
<ImageView
|
||||
|
||||
@ -38,8 +38,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:textSize="20sp"
|
||||
android:textColor="@color/textLighterBlack" />
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/lineViewRoot"
|
||||
@ -58,10 +57,9 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:textSize="20sp"
|
||||
android:textColor="@color/textLighterBlack"
|
||||
android:layout_centerVertical="true"
|
||||
android:textAlignment="textEnd" />
|
||||
android:textAlignment="textEnd"
|
||||
android:textAppearance="@android:style/TextAppearance.Material.Medium" />
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
|
||||
@ -41,7 +41,7 @@
|
||||
android:fontFamily="sans-serif-black"
|
||||
android:text=""
|
||||
android:textAllCaps="true"
|
||||
android:textColor="@color/textColorLight"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
@ -51,7 +51,7 @@
|
||||
android:fontFamily="sans-serif-black"
|
||||
android:text=""
|
||||
android:textAllCaps="false"
|
||||
android:textColor="@color/textLighterBlack"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold" />
|
||||
</LinearLayout>
|
||||
@ -73,7 +73,7 @@
|
||||
android:fontFamily="sans-serif-black"
|
||||
android:text=""
|
||||
android:textAllCaps="true"
|
||||
android:textColor="@color/textColorLight"
|
||||
android:textColor="?android:textColorSecondary"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<TextView
|
||||
@ -83,7 +83,7 @@
|
||||
android:fontFamily="sans-serif-black"
|
||||
android:text=""
|
||||
android:textAllCaps="false"
|
||||
android:textColor="@color/textLighterBlack"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
|
||||
@ -36,7 +36,7 @@
|
||||
android:layout_weight="1"
|
||||
android:text="Aug 19, 2019 20:15"
|
||||
android:textAllCaps="true"
|
||||
android:textColor="@color/textLighterBlack"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="18sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
@ -80,7 +80,7 @@
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="27min"
|
||||
android:textColor="@color/textLighterBlack"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="30sp" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@ -34,5 +34,6 @@
|
||||
<color name="colorPrimaryDarkHiking">#007267</color>
|
||||
|
||||
<color name="textLighterBlack">#C8000000</color>
|
||||
<color name="textDarkerWhite">#C8FFFFFF</color>
|
||||
<color name="textColorLight">#C8414141</color>
|
||||
</resources>
|
||||
|
||||
@ -172,4 +172,5 @@
|
||||
<string name="savingFailed">Saving failed</string>
|
||||
<string name="info">Info</string>
|
||||
<string name="OpenStreetMapAttribution">© OpenStreetMap contributors</string>
|
||||
<string name="theme">Theme</string>
|
||||
</resources>
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
<!--
|
||||
~ Copyright (c) 2019 Jannis Scheibe <jannis@tadris.de>
|
||||
~ Copyright (c) 2020 Jannis Scheibe <jannis@tadris.de>
|
||||
~
|
||||
~ This file is part of FitoTrack
|
||||
~
|
||||
@ -19,43 +19,65 @@
|
||||
|
||||
<resources>
|
||||
|
||||
<style name="AppThemeNoActionbar" parent="android:Theme.Material.Light.NoActionBar">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="android:colorPrimary">@color/colorPrimary</item>
|
||||
<item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="android:colorAccent">@color/colorAccent</item>
|
||||
|
||||
</style>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="AppTheme" parent="android:Theme.Material.Light.DarkActionBar">
|
||||
<!-- Custom<color name="colorPrimaryBicycling">#523220</color>
|
||||
<color name="colorPrimaryDarkBicycling">#462A1D</color>ize your theme here. -->
|
||||
<item name="android:colorPrimary">@color/colorPrimary</item>
|
||||
<item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="android:colorAccent">@color/colorAccent</item>
|
||||
|
||||
<item name="android:textAppearanceMedium">@style/MediumTextLight</item>
|
||||
</style>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="Running" parent="AppTheme">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="android:colorPrimary">@color/colorPrimaryRunning</item>
|
||||
<item name="android:colorPrimaryDark">@color/colorPrimaryDarkRunning</item>
|
||||
</style>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="Bicycling" parent="AppTheme">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="android:colorPrimary">@color/colorPrimaryBicycling</item>
|
||||
<item name="android:colorPrimaryDark">@color/colorPrimaryDarkBicycling</item>
|
||||
</style>
|
||||
|
||||
<!-- Base application theme. -->
|
||||
<style name="Hiking" parent="AppTheme">
|
||||
<!-- Customize your theme here. -->
|
||||
<item name="android:colorPrimary">@color/colorPrimaryHiking</item>
|
||||
<item name="android:colorPrimaryDark">@color/colorPrimaryDarkHiking</item>
|
||||
</style>
|
||||
|
||||
|
||||
<style name="AppThemeDark" parent="android:Theme.Material">
|
||||
<item name="android:colorPrimary">@color/colorPrimary</item>
|
||||
<item name="android:colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="android:colorAccent">@color/colorAccent</item>
|
||||
<item name="android:windowBackground">@android:color/black</item>
|
||||
|
||||
<item name="android:textAppearanceMedium">@style/MediumTextDark</item>
|
||||
</style>
|
||||
|
||||
<style name="RunningDark" parent="AppThemeDark">
|
||||
<item name="android:colorPrimary">@color/colorPrimaryRunning</item>
|
||||
<item name="android:colorPrimaryDark">@color/colorPrimaryDarkRunning</item>
|
||||
</style>
|
||||
|
||||
<style name="BicyclingDark" parent="AppThemeDark">
|
||||
<item name="android:colorPrimary">@color/colorPrimaryBicycling</item>
|
||||
<item name="android:colorPrimaryDark">@color/colorPrimaryDarkBicycling</item>
|
||||
</style>
|
||||
|
||||
<style name="HikingDark" parent="AppThemeDark">
|
||||
<item name="android:colorPrimary">@color/colorPrimaryHiking</item>
|
||||
<item name="android:colorPrimaryDark">@color/colorPrimaryDarkHiking</item>
|
||||
</style>
|
||||
|
||||
|
||||
<style name="MediumTextLight" parent="android:TextAppearance.Material.Medium">
|
||||
<item name="android:textColor">@color/textLighterBlack</item>
|
||||
<item name="android:textSize">22sp</item>
|
||||
</style>
|
||||
|
||||
<style name="MediumTextDark" parent="android:TextAppearance.Material.Medium.Inverse">
|
||||
<item name="android:textColor">@color/textDarkerWhite</item>
|
||||
<item name="android:textSize">22sp</item>
|
||||
</style>
|
||||
|
||||
|
||||
</resources>
|
||||
|
||||
34
app/src/main/res/values/theme_setting.xml
Normal file
34
app/src/main/res/values/theme_setting.xml
Normal file
@ -0,0 +1,34 @@
|
||||
<?xml version="1.0" encoding="utf-8"?><!--
|
||||
~ Copyright (c) 2020 Jannis Scheibe <jannis@tadris.de>
|
||||
~
|
||||
~ This file is part of FitoTrack
|
||||
~
|
||||
~ FitoTrack is free software: you can redistribute it and/or modify
|
||||
~ it under the terms of the GNU General Public License as published by
|
||||
~ the Free Software Foundation, either version 3 of the License, or
|
||||
~ (at your option) any later version.
|
||||
~
|
||||
~ FitoTrack is distributed in the hope that it will be useful,
|
||||
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
~ GNU General Public License for more details.
|
||||
~
|
||||
~ You should have received a copy of the GNU General Public License
|
||||
~ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
-->
|
||||
|
||||
<resources>
|
||||
|
||||
<string-array name="pref_theme_setting">
|
||||
<item>System</item>
|
||||
<item>Light</item>
|
||||
<item>Dark</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="pref_theme_setting_values">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
</string-array>
|
||||
|
||||
</resources>
|
||||
@ -33,6 +33,13 @@
|
||||
android:summary="@string/pref_weight_summary"
|
||||
android:title="@string/pref_weight" />
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="0"
|
||||
android:entries="@array/pref_theme_setting"
|
||||
android:entryValues="@array/pref_theme_setting_values"
|
||||
android:key="themeSetting"
|
||||
android:title="@string/theme" />
|
||||
|
||||
<ListPreference
|
||||
android:defaultValue="osm.mapnik"
|
||||
android:entries="@array/pref_map_layers"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user