1
0
mirror of https://github.com/oliexdev/openScale.git synced 2025-08-23 16:53:04 +02:00

added an option to select a light or a dark app theme.

This commit is contained in:
OliE
2018-01-28 15:27:20 +01:00
parent 26549c9746
commit 2dc40e4bc4
27 changed files with 270 additions and 73 deletions

View File

@@ -14,7 +14,7 @@
android:allowBackup="true"
android:icon="@drawable/ic_launcher_openscale"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
android:theme="@style/AppTheme_Light" >
<activity
android:name=".gui.MainActivity"
android:label="@string/app_name" >

View File

@@ -73,6 +73,12 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
String app_theme = PreferenceManager.getDefaultSharedPreferences(this).getString("app_theme", "Light");
if (app_theme.equals("Dark")) {
setTheme(R.style.AppTheme_Dark);
}
super.onCreate(savedInstanceState);
CaocConfig.Builder.create()
@@ -245,7 +251,9 @@ public class MainActivity extends AppCompatActivity {
fragmentClass = StatisticsFragment.class;
break;
case R.id.nav_settings:
startActivityForResult(new Intent(this, SettingsActivity.class), 1);
Intent settingsIntent = new Intent(this, SettingsActivity.class);
settingsIntent.putExtra("tintColor", navDrawer.getItemTextColor().getDefaultColor());
startActivityForResult(settingsIntent, 1);
return;
default:
fragmentClass = OverviewFragment.class;

View File

@@ -15,7 +15,11 @@
*/
package com.health.openscale.gui.activities;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import com.health.openscale.R;
@@ -25,12 +29,28 @@ import java.util.List;
public class SettingsActivity extends PreferenceActivity {
private static List<String> fragments = new ArrayList<String>();
@Override
public void onCreate(Bundle savedInstanceState) {
String app_theme = PreferenceManager.getDefaultSharedPreferences(this).getString("app_theme", "Light");
if (app_theme.equals("Dark")) {
setTheme(R.style.AppTheme_Dark);
}
super.onCreate(savedInstanceState);
}
@Override
public void onBuildHeaders(List<Header> target) {
loadHeadersFromResource(R.xml.header_preferences, target);
int tintColor = getIntent().getIntExtra("tintColor", 0);
fragments.clear();
for (Header header : target) {
Drawable icon = getResources().getDrawable(header.iconRes);
icon.setColorFilter(tintColor, PorterDuff.Mode.SRC_IN);
fragments.add(header.fragment);
}
}

View File

@@ -83,6 +83,8 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
private FloatingActionButton enableMonth;
private SharedPreferences prefs;
private int textColor;
private OpenScale openScale;
private Calendar calYears;
@@ -124,6 +126,9 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
chartBottom.setOnValueTouchListener(new chartBottomValueTouchListener());
chartTop.setOnValueTouchListener(new chartTopValueTouchListener());
// HACK: get default text color from hidden text view to set the correct axis colors
textColor = ((TextView)graphView.findViewById(R.id.colorHack)).getCurrentTextColor();
txtYear = (TextView) graphView.findViewById(R.id.txtYear);
txtYear.setText(Integer.toString(calYears.get(Calendar.YEAR)));
@@ -421,13 +426,13 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
LineChartData lineData = new LineChartData(lines);
lineData.setAxisXBottom(new Axis(axisValues).
setHasLines(true).
setTextColor(Color.BLACK)
setTextColor(textColor)
);
lineData.setAxisYLeft(new Axis().
setHasLines(true).
setMaxLabelChars(5).
setTextColor(Color.BLACK)
setTextColor(textColor)
);
chartBottom.setLineChartData(lineData);
@@ -507,7 +512,7 @@ public class GraphFragment extends Fragment implements FragmentUpdateListener {
ColumnChartData columnData = new ColumnChartData(columns);
columnData.setAxisXBottom(new Axis(axisValues).setHasLines(true).setTextColor(Color.BLACK));
columnData.setAxisXBottom(new Axis(axisValues).setHasLines(true).setTextColor(textColor));
chartTop.setColumnChartData(columnData);
chartTop.setValueSelectionEnabled(true);

View File

@@ -359,13 +359,13 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
LineChartData lineData = new LineChartData(lines);
lineData.setAxisXBottom(new Axis(axisValues).
setHasLines(true).
setTextColor(Color.BLACK)
setTextColor(txtTitleLastMeasurement.getCurrentTextColor())
);
lineData.setAxisYLeft(new Axis().
setHasLines(true).
setMaxLabelChars(5).
setTextColor(Color.BLACK)
setTextColor(txtTitleLastMeasurement.getCurrentTextColor())
);
lineChartLast.setLineChartData(lineData);
@@ -405,7 +405,8 @@ public class OverviewFragment extends Fragment implements FragmentUpdateListener
pieChartData.setHasCenterCircle(true);
pieChartData.setCenterText1(String.format("%.2f %s", lastScaleMeasurement.getConvertedWeight(unit), unit.toString()));
pieChartData.setCenterText2(DateFormat.getDateInstance(DateFormat.MEDIUM).format(lastScaleMeasurement.getDateTime()));
pieChartData.setCenterText1Color(txtTitleLastMeasurement.getCurrentTextColor());
pieChartData.setCenterText2Color(txtTitleLastMeasurement.getCurrentTextColor());
if ((getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_XLARGE ||
(getResources().getConfiguration().screenLayout & Configuration.SCREENLAYOUT_SIZE_MASK) == Configuration.SCREENLAYOUT_SIZE_LARGE) {

View File

@@ -0,0 +1,128 @@
/* Copyright (C) 2014 olie.xdev <olie.xdev@googlemail.com>
*
* This program 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.
*
* This program 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 com.health.openscale.gui.preferences;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.EditTextPreference;
import android.preference.ListPreference;
import android.preference.MultiSelectListPreference;
import android.preference.Preference;
import android.preference.PreferenceFragment;
import android.preference.PreferenceGroup;
import android.widget.Toast;
import com.health.openscale.R;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;
public class GeneralPreferences extends PreferenceFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
private static final String PREFERENCE_KEY_APP_THEME = "app_theme";
private ListPreference appThemeList;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.general_preferences);
appThemeList = (ListPreference)findPreference(PREFERENCE_KEY_APP_THEME);
appThemeList.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object o) {
Toast.makeText(getActivity().getApplicationContext(), getResources().getString(R.string.info_app_restart_required), Toast.LENGTH_LONG).show();
return true;
}
});
initSummary(getPreferenceScreen());
}
private void initSummary(Preference p) {
if (p instanceof PreferenceGroup) {
PreferenceGroup pGrp = (PreferenceGroup) p;
for (int i = 0; i < pGrp.getPreferenceCount(); i++) {
initSummary(pGrp.getPreference(i));
}
} else {
updatePrefSummary(p);
}
}
private void updatePrefSummary(Preference p)
{
if (p instanceof ListPreference)
{
ListPreference listPref = (ListPreference) p;
p.setSummary(listPref.getEntry());
}
if (p instanceof EditTextPreference)
{
EditTextPreference editTextPref = (EditTextPreference) p;
if (p.getTitle().toString().contains("assword"))
{
p.setSummary("******");
}
else
{
p.setSummary(editTextPref.getText());
}
}
if (p instanceof MultiSelectListPreference)
{
MultiSelectListPreference editMultiListPref = (MultiSelectListPreference) p;
CharSequence[] entries = editMultiListPref.getEntries();
CharSequence[] entryValues = editMultiListPref.getEntryValues();
List<String> currentEntries = new ArrayList<>();
Set<String> currentEntryValues = editMultiListPref.getValues();
for (int i = 0; i < entries.length; i++)
{
if (currentEntryValues.contains(entryValues[i].toString())) currentEntries.add(entries[i].toString());
}
p.setSummary(currentEntries.toString());
}
}
@Override
public void onResume()
{
super.onResume();
getPreferenceManager().getSharedPreferences().registerOnSharedPreferenceChangeListener(this);
}
@Override
public void onPause()
{
getPreferenceManager().getSharedPreferences().unregisterOnSharedPreferenceChangeListener(this);
super.onPause();
}
@Override
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
updatePrefSummary(findPreference(key));
}
}

View File

@@ -102,14 +102,13 @@ public abstract class MeasurementView extends TableLayout {
iconView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
iconView.setPadding(20,0,20,0);
iconView.setColorFilter(nameView.getCurrentTextColor());
nameView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
nameView.setTextColor(Color.BLACK);
nameView.setLines(2);
nameView.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 0.55f));
valueView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 15);
valueView.setTextColor(Color.BLACK);
valueView.setGravity(Gravity.RIGHT | Gravity.CENTER);
valueView.setPadding(0,0,20,0);
valueView.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.WRAP_CONTENT, 0.29f));
@@ -122,6 +121,7 @@ public abstract class MeasurementView extends TableLayout {
editModeView.setImageDrawable(ContextCompat.getDrawable(context, R.drawable.ic_editable));
editModeView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
editModeView.setVisibility(View.GONE);
editModeView.setColorFilter(nameView.getCurrentTextColor());
indicatorView.setLayoutParams(new TableRow.LayoutParams(0, LayoutParams.MATCH_PARENT, 0.01f));
indicatorView.setBackgroundColor(Color.GRAY);
@@ -185,8 +185,14 @@ public abstract class MeasurementView extends TableLayout {
valueView.setGravity(Gravity.RIGHT | Gravity.CENTER);
if (!isEditable()) {
editModeView.setImageDrawable(ContextCompat.getDrawable(getContext(),
R.drawable.ic_noteeditable));
// if measurement is not editable, darken the icon color
float[] hsv = new float[3];
int color = nameView.getCurrentTextColor();
Color.colorToHSV(color, hsv);
hsv[2] *= 0.4f; // value component
color = Color.HSVToColor(hsv);
editModeView.setColorFilter(color);
}
showEvaluatorRow(false);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 672 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 792 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.0 KiB

View File

@@ -142,7 +142,7 @@
android:gravity="center"
android:text="year"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#FFFFFF"
android:textColor="@android:color/white"
android:textStyle="bold" />
<Button
@@ -155,6 +155,12 @@
android:text=">"
android:textColor="@android:color/white" />
<TextView
android:id="@+id/colorHack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone" />
</LinearLayout>
<lecho.lib.hellocharts.view.ColumnChartView

View File

@@ -1,4 +1,5 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
@@ -44,7 +45,8 @@
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_gravity="center"
android:src="@drawable/ic_target" />
android:src="@drawable/ic_target"
android:tint="?attr/editTextColor" />
<TextView
android:id="@+id/txtLabelGoalWeight"
@@ -87,7 +89,8 @@
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_gravity="center"
android:src="@drawable/ic_difference" />
android:src="@drawable/ic_difference"
android:tint="?attr/editTextColor" />
<TextView
android:id="@+id/txtLabelGoalDiff"
@@ -130,7 +133,8 @@
android:layout_width="match_parent"
android:layout_height="20dp"
android:layout_gravity="center"
android:src="@drawable/ic_daysleft" />
android:src="@drawable/ic_daysleft"
android:tint="?attr/editTextColor" />
<TextView
android:id="@+id/txtLabelDayLeft"

View File

@@ -132,7 +132,6 @@
<string name="label_category_display">Mostreu</string>
<string name="label_category_body_metrics_estimation">Estimació de mètriques corporals</string>
<string name="label_category_measurement_database">Base de dades de mesures</string>
<string name="label_category_misc">Varis</string>
<string name="label_maintainer">Responsable</string>
<string name="label_website">Pàgina Web</string>

View File

@@ -144,7 +144,6 @@
<string name="label_category_body_metrics_estimation">Körpermetriken abschätzen</string>
<string name="label_category_display">Anzeige</string>
<string name="label_category_measurement_database">Messwertedatenbank</string>
<string name="label_category_misc">Verschiedenes</string>
<string name="label_estimate_fat">Körperfettschätzung</string>
<string name="label_estimate_fat_formula">Körperfettformel</string>
<string name="label_estimate_water">Körperwasserschätzung</string>
@@ -180,4 +179,7 @@
<string name="customactivityoncrash_error_activity_error_details_copy">Kopieren in die Zwischenablage</string>
<string name="customactivityoncrash_error_activity_error_details_copied">in Zwischenablage kopiert</string>
<string name="customactivityoncrash_error_activity_error_details_clipboard_label">Fehlerinformationen</string>
<string name="title_general">Allgmein</string>
<string name="label_theme">Theme</string>
<string name="info_app_restart_required">Um die Änderungen zu übernehmen, ist ein App Neustart erforderlich</string>
</resources>

View File

@@ -132,7 +132,6 @@
<string name="label_category_display">Mostrar</string>
<string name="label_category_body_metrics_estimation">Estimación de métricas corporales</string>
<string name="label_category_measurement_database">Base de datos de mediciones</string>
<string name="label_category_misc">Varios</string>
<string name="label_maintainer">Responsable</string>
<string name="label_website">Página Web</string>

View File

@@ -134,7 +134,6 @@
<string name="label_category_display">Scherm</string>
<string name="label_category_body_metrics_estimation"> Schatting lichaamssamenstelling</string>
<string name="label_category_measurement_database">Metingen database</string>
<string name="label_category_misc"> Diversen</string>
<string name="label_maintainer">Beheerder</string>
<string name="label_website">Website</string>

View File

@@ -41,7 +41,6 @@
<string name="label_reminder_weekdays">Veckodagar</string>
<string name="label_website">Hemsida</string>
<string name="label_license">License</string>
<string name="label_category_misc">Diverse</string>
<string name="error_exporting">Fel vid export</string>
<string name="label_gender">Kön</string>
<string name="label_male">Man</string>

View File

@@ -130,7 +130,6 @@
<string name="label_category_display">Display</string>
<string name="label_category_body_metrics_estimation">Vücüt ölçütleri tahmini</string>
<string name="label_category_measurement_database">Ölçüm veritabaný</string>
<string name="label_category_misc">Miscellaneous</string>
<string name="label_maintainer">Maintainer</string>
<string name="label_website">Websitesi</string>

View File

@@ -10,6 +10,7 @@
<string name="title_data">Data</string>
<string name="title_measurements">Measurements</string>
<string name="title_about">About</string>
<string name="title_general">General</string>
<string name="action_settings">Settings</string>
<string name="action_bluetooth_status">Bluetooth Status</string>
@@ -140,7 +141,6 @@
<string name="label_category_display">Display</string>
<string name="label_category_body_metrics_estimation">Body metrics estimation</string>
<string name="label_category_measurement_database">Measurement database</string>
<string name="label_category_misc">Miscellaneous</string>
<string name="label_maintainer">Maintainer</string>
<string name="label_website">Website</string>
@@ -151,6 +151,9 @@
<string name="label_estimate_fat_formula">Body fat formula</string>
<string name="label_automatic">auto</string>
<string name="label_theme">Theme</string>
<string name="info_app_restart_required">To apply changes an app restart is required</string>
<string name="label_reminder">Reminder</string>
<string name="label_reminder_weekdays">Weekdays</string>
<string name="label_reminder_time">Time</string>

View File

@@ -1,9 +1,12 @@
<resources>
<!-- Application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.DayNight.NoActionBar">
<style name="AppTheme_Light" parent="Theme.Design.Light.NoActionBar">
<!-- All customizations that are NOT specific to a particular API-level can go here. -->
<item name="colorPrimary">#000000</item>
<item name="colorPrimaryDark">#000000</item>
<item name="colorAccent">@android:color/holo_blue_light</item>
</style>
<style name="AppTheme_Dark" parent="Theme.Design.NoActionBar">
</style>
</resources>

View File

@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
<string-array name="themes_entries">
<item>Light</item>
<item>Dark</item>
</string-array>
<string-array name="themes_values">
<item>Light</item>
<item>Dark</item>
</string-array>
</resources>

View File

@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<ListPreference android:title="@string/label_theme" android:entries="@array/themes_entries" android:entryValues="@array/themes_values" android:key="app_theme" android:defaultValue="Light"/>
<CheckBoxPreference android:title="@string/label_delete_confirmation" android:summaryOn="@string/info_is_enable" android:summaryOff="@string/info_is_not_enable" android:key="deleteConfirmationEnable" android:defaultValue="true" />
</PreferenceScreen>

View File

@@ -1,14 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceCategory android:title="@string/label_category_display">
<CheckBoxPreference android:title="@string/label_average_data" android:summaryOn="@string/info_is_enable" android:summaryOff="@string/info_is_not_enable" android:key="averageData" android:defaultValue="true" />
<CheckBoxPreference android:title="@string/label_enable_labels" android:summaryOn="@string/info_is_visible" android:summaryOff="@string/info_is_not_visible" android:key="labelsEnable" android:defaultValue="true"/>
<CheckBoxPreference android:title="@string/label_enable_points" android:summaryOn="@string/info_is_visible" android:summaryOff="@string/info_is_not_visible" android:key="pointsEnable" android:defaultValue="true"/>
<CheckBoxPreference android:title="@string/label_goal_line" android:summaryOn="@string/info_is_visible" android:summaryOff="@string/info_is_not_visible" android:key="goalLine" android:defaultValue="true" />
<CheckBoxPreference android:title="@string/label_regression_line" android:summaryOn="@string/info_is_visible" android:summaryOff="@string/info_is_not_visible" android:key="regressionLine" android:defaultValue="false" />
<EditTextPreference android:title="@string/label_regression_line_degree" android:key="regressionLineOrder" android:defaultValue="1" />
</PreferenceCategory>
<PreferenceCategory android:title="@string/label_category_misc">
<CheckBoxPreference android:title="@string/label_delete_confirmation" android:summaryOn="@string/info_is_enable" android:summaryOff="@string/info_is_not_enable" android:key="deleteConfirmationEnable" android:defaultValue="true" />
<CheckBoxPreference android:title="@string/label_average_data" android:summaryOn="@string/info_is_enable" android:summaryOff="@string/info_is_not_enable" android:key="averageData" android:defaultValue="true" />
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -1,5 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<preference-headers xmlns:android="http://schemas.android.com/apk/res/android">
<header
android:fragment="com.health.openscale.gui.preferences.GeneralPreferences"
android:title="@string/title_general"
android:icon="@drawable/ic_preferences_settings" />
<header
android:fragment="com.health.openscale.gui.preferences.UsersPreferences"
android:title="@string/title_users"