From 45527473e3360fa71dc5c91fb6f02fb537443b56 Mon Sep 17 00:00:00 2001 From: tibbi Date: Mon, 18 Jul 2016 20:11:58 +0200 Subject: [PATCH] add a Dark Theme toggle --- app/src/main/AndroidManifest.xml | 4 ++ .../simplemobiletools/calendar/Config.java | 8 ++++ .../simplemobiletools/calendar/Constants.java | 12 +++--- .../calendar/activities/MainActivity.java | 6 ++- .../calendar/activities/SettingsActivity.java | 38 ++++++++++++++++++ app/src/main/res/layout/activity_settings.xml | 40 +++++++++++++++++++ app/src/main/res/menu/menu.xml | 4 ++ app/src/main/res/values/strings.xml | 4 ++ 8 files changed, 109 insertions(+), 7 deletions(-) create mode 100644 app/src/main/java/com/simplemobiletools/calendar/activities/SettingsActivity.java create mode 100644 app/src/main/res/layout/activity_settings.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 645bc8b43..aafee2685 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -45,6 +45,10 @@ android:name=".activities.LicenseActivity" android:label="@string/third_party_licences"/> + + diff --git a/app/src/main/java/com/simplemobiletools/calendar/Config.java b/app/src/main/java/com/simplemobiletools/calendar/Config.java index 6b333c0ec..8079ff542 100644 --- a/app/src/main/java/com/simplemobiletools/calendar/Config.java +++ b/app/src/main/java/com/simplemobiletools/calendar/Config.java @@ -21,4 +21,12 @@ public class Config { public void setIsFirstRun(boolean firstRun) { mPrefs.edit().putBoolean(Constants.IS_FIRST_RUN, firstRun).apply(); } + + public boolean getIsDarkTheme() { + return mPrefs.getBoolean(Constants.IS_DARK_THEME, false); + } + + public void setIsDarkTheme(boolean isDarkTheme) { + mPrefs.edit().putBoolean(Constants.IS_DARK_THEME, isDarkTheme).apply(); + } } diff --git a/app/src/main/java/com/simplemobiletools/calendar/Constants.java b/app/src/main/java/com/simplemobiletools/calendar/Constants.java index 35ad4cbdd..16a5c82d8 100644 --- a/app/src/main/java/com/simplemobiletools/calendar/Constants.java +++ b/app/src/main/java/com/simplemobiletools/calendar/Constants.java @@ -4,11 +4,13 @@ public class Constants { public static final float LOW_ALPHA = .2f; public static final float HIGH_ALPHA = .8f; - public static final String PREFS_KEY = "Calendar"; - public static final String IS_FIRST_RUN = "is_first_run"; - public static final String WIDGET_BG_COLOR = "widget_bg_color"; - public static final String WIDGET_TEXT_COLOR = "widget_text_color"; - public static final String DAY_CODE = "day_code"; public static final String EVENT = "event"; + + // Shared Preferences + public static final String PREFS_KEY = "Calendar"; + public static final String IS_FIRST_RUN = "is_first_run"; + public static final String IS_DARK_THEME = "is_dark_theme"; + public static final String WIDGET_BG_COLOR = "widget_bg_color"; + public static final String WIDGET_TEXT_COLOR = "widget_text_color"; } diff --git a/app/src/main/java/com/simplemobiletools/calendar/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/calendar/activities/MainActivity.java index cdeeb9228..68a50ed3f 100644 --- a/app/src/main/java/com/simplemobiletools/calendar/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/calendar/activities/MainActivity.java @@ -103,9 +103,11 @@ public class MainActivity extends AppCompatActivity implements Calendar { @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { + case R.id.settings: + startActivity(new Intent(getApplicationContext(), SettingsActivity.class)); + return true; case R.id.about: - final Intent intent = new Intent(getApplicationContext(), AboutActivity.class); - startActivity(intent); + startActivity(new Intent(getApplicationContext(), AboutActivity.class)); return true; default: return super.onOptionsItemSelected(item); diff --git a/app/src/main/java/com/simplemobiletools/calendar/activities/SettingsActivity.java b/app/src/main/java/com/simplemobiletools/calendar/activities/SettingsActivity.java new file mode 100644 index 000000000..8b69a9cde --- /dev/null +++ b/app/src/main/java/com/simplemobiletools/calendar/activities/SettingsActivity.java @@ -0,0 +1,38 @@ +package com.simplemobiletools.calendar.activities; + +import android.os.Bundle; +import android.support.v7.app.AppCompatActivity; +import android.support.v7.widget.SwitchCompat; + +import com.simplemobiletools.calendar.Config; +import com.simplemobiletools.calendar.R; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; + +public class SettingsActivity extends AppCompatActivity { + @BindView(R.id.settings_dark_theme) SwitchCompat mDarkThemeSwitch; + + private static Config mConfig; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_settings); + mConfig = Config.newInstance(getApplicationContext()); + ButterKnife.bind(this); + + setupDarkTheme(); + } + + private void setupDarkTheme() { + mDarkThemeSwitch.setChecked(mConfig.getIsDarkTheme()); + } + + @OnClick(R.id.settings_dark_theme_holder) + public void handleDarkTheme() { + mDarkThemeSwitch.setChecked(!mDarkThemeSwitch.isChecked()); + mConfig.setIsDarkTheme(mDarkThemeSwitch.isChecked()); + } +} diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml new file mode 100644 index 000000000..9d993a182 --- /dev/null +++ b/app/src/main/res/layout/activity_settings.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + diff --git a/app/src/main/res/menu/menu.xml b/app/src/main/res/menu/menu.xml index 0cce6d24e..815619cdb 100644 --- a/app/src/main/res/menu/menu.xml +++ b/app/src/main/res/menu/menu.xml @@ -1,6 +1,10 @@ + 1 event deleted %1$d events deleted + + + Settings + Dark theme