From 743d4d2cb92efa76dc992967197805e3245542f0 Mon Sep 17 00:00:00 2001 From: tibbi Date: Sun, 24 Jul 2016 13:33:00 +0200 Subject: [PATCH] add a Dark theme --- app/src/main/AndroidManifest.xml | 9 ++++-- .../simplemobiletools/filemanager/Config.java | 8 +++++ .../filemanager/Constants.java | 1 + .../filemanager/activities/AboutActivity.java | 3 +- .../activities/LicenseActivity.java | 3 +- .../filemanager/activities/MainActivity.java | 3 +- .../activities/SettingsActivity.java | 21 +++++++++++-- .../activities/SimpleActivity.java | 31 +++++++++++++++++++ app/src/main/res/layout/activity_settings.xml | 26 ++++++++++++++++ app/src/main/res/layout/list_item.xml | 1 - app/src/main/res/values-it/strings.xml | 1 + app/src/main/res/values-ja/strings.xml | 1 + app/src/main/res/values-sv/strings.xml | 1 + app/src/main/res/values/colors.xml | 1 - app/src/main/res/values/strings.xml | 1 + app/src/main/res/values/styles.xml | 8 +++++ 16 files changed, 106 insertions(+), 13 deletions(-) create mode 100644 app/src/main/java/com/simplemobiletools/filemanager/activities/SimpleActivity.java diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 139c2cc6..22ac01c9 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -19,14 +19,17 @@ + android:label="@string/about" + android:parentActivityName=".activities.MainActivity"/> + android:label="@string/third_party_licences" + android:parentActivityName=".activities.AboutActivity"/> + android:label="@string/settings" + android:parentActivityName=".activities.MainActivity"/> diff --git a/app/src/main/java/com/simplemobiletools/filemanager/Config.java b/app/src/main/java/com/simplemobiletools/filemanager/Config.java index 7366c287..2d54aefc 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/Config.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/Config.java @@ -22,6 +22,14 @@ public class Config { 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(); + } + public boolean getShowHidden() { return mPrefs.getBoolean(Constants.SHOW_HIDDEN, false); } diff --git a/app/src/main/java/com/simplemobiletools/filemanager/Constants.java b/app/src/main/java/com/simplemobiletools/filemanager/Constants.java index 258b3835..30f531a7 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/Constants.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/Constants.java @@ -6,5 +6,6 @@ public class Constants { // shared preferences public static final String PREFS_KEY = "File Manager"; public static final String IS_FIRST_RUN = "is_first_run"; + public static final String IS_DARK_THEME = "is_dark_theme"; public static final String SHOW_HIDDEN = "show_hidden"; } diff --git a/app/src/main/java/com/simplemobiletools/filemanager/activities/AboutActivity.java b/app/src/main/java/com/simplemobiletools/filemanager/activities/AboutActivity.java index d9c22c31..27d4974f 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/activities/AboutActivity.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/activities/AboutActivity.java @@ -5,7 +5,6 @@ import android.content.Intent; import android.content.res.Resources; import android.net.Uri; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; import android.text.Html; import android.text.method.LinkMovementMethod; import android.view.View; @@ -21,7 +20,7 @@ import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; -public class AboutActivity extends AppCompatActivity { +public class AboutActivity extends SimpleActivity { @BindView(R.id.about_copyright) TextView mCopyright; @BindView(R.id.about_email) TextView mEmailTV; @BindView(R.id.about_rate_us) View mRateUs; diff --git a/app/src/main/java/com/simplemobiletools/filemanager/activities/LicenseActivity.java b/app/src/main/java/com/simplemobiletools/filemanager/activities/LicenseActivity.java index 440ee8b0..882a9b90 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/activities/LicenseActivity.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/activities/LicenseActivity.java @@ -3,14 +3,13 @@ package com.simplemobiletools.filemanager.activities; import android.content.Intent; import android.net.Uri; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; import com.simplemobiletools.filemanager.R; import butterknife.ButterKnife; import butterknife.OnClick; -public class LicenseActivity extends AppCompatActivity { +public class LicenseActivity extends SimpleActivity { @Override protected void onCreate(Bundle savedInstanceState) { diff --git a/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java index 339e379e..7b51f259 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/activities/MainActivity.java @@ -6,7 +6,6 @@ import android.content.pm.PackageManager; import android.os.Bundle; import android.os.Environment; import android.support.v4.app.ActivityCompat; -import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.MenuItem; @@ -21,7 +20,7 @@ import com.simplemobiletools.filemanager.models.FileDirItem; import butterknife.BindView; import butterknife.ButterKnife; -public class MainActivity extends AppCompatActivity implements ItemsFragment.ItemInteractionListener, Breadcrumbs.BreadcrumbsListener { +public class MainActivity extends SimpleActivity implements ItemsFragment.ItemInteractionListener, Breadcrumbs.BreadcrumbsListener { @BindView(R.id.breadcrumbs) Breadcrumbs mBreadcrumbs; private static final int STORAGE_PERMISSION = 1; diff --git a/app/src/main/java/com/simplemobiletools/filemanager/activities/SettingsActivity.java b/app/src/main/java/com/simplemobiletools/filemanager/activities/SettingsActivity.java index 203a86ce..ece88202 100644 --- a/app/src/main/java/com/simplemobiletools/filemanager/activities/SettingsActivity.java +++ b/app/src/main/java/com/simplemobiletools/filemanager/activities/SettingsActivity.java @@ -1,7 +1,7 @@ package com.simplemobiletools.filemanager.activities; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; +import android.support.v4.app.TaskStackBuilder; import android.support.v7.widget.SwitchCompat; import com.simplemobiletools.filemanager.Config; @@ -11,7 +11,8 @@ import butterknife.BindView; import butterknife.ButterKnife; import butterknife.OnClick; -public class SettingsActivity extends AppCompatActivity { +public class SettingsActivity extends SimpleActivity { + @BindView(R.id.settings_dark_theme) SwitchCompat mDarkThemeSwitch; @BindView(R.id.settings_show_hidden) SwitchCompat mShowHiddenSwitch; private static Config mConfig; @@ -23,16 +24,32 @@ public class SettingsActivity extends AppCompatActivity { mConfig = Config.newInstance(getApplicationContext()); ButterKnife.bind(this); + setupDarkTheme(); setupShowHidden(); } + private void setupDarkTheme() { + mDarkThemeSwitch.setChecked(mConfig.getIsDarkTheme()); + } + private void setupShowHidden() { mShowHiddenSwitch.setChecked(mConfig.getShowHidden()); } + @OnClick(R.id.settings_dark_theme_holder) + public void handleDarkTheme() { + mDarkThemeSwitch.setChecked(!mDarkThemeSwitch.isChecked()); + mConfig.setIsDarkTheme(mDarkThemeSwitch.isChecked()); + restartActivity(); + } + @OnClick(R.id.settings_show_hidden_holder) public void handleShowHidden() { mShowHiddenSwitch.setChecked(!mShowHiddenSwitch.isChecked()); mConfig.setShowHidden(mShowHiddenSwitch.isChecked()); } + + private void restartActivity() { + TaskStackBuilder.create(getApplicationContext()).addNextIntentWithParentStack(getIntent()).startActivities(); + } } diff --git a/app/src/main/java/com/simplemobiletools/filemanager/activities/SimpleActivity.java b/app/src/main/java/com/simplemobiletools/filemanager/activities/SimpleActivity.java new file mode 100644 index 00000000..9df519b1 --- /dev/null +++ b/app/src/main/java/com/simplemobiletools/filemanager/activities/SimpleActivity.java @@ -0,0 +1,31 @@ +package com.simplemobiletools.filemanager.activities; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.view.MenuItem; + +import com.simplemobiletools.filemanager.Config; +import com.simplemobiletools.filemanager.R; + +public class SimpleActivity extends AppCompatActivity { + protected Config mConfig; + + @Override + protected void onCreate(@Nullable Bundle savedInstanceState) { + mConfig = Config.newInstance(getApplicationContext()); + setTheme(mConfig.getIsDarkTheme() ? R.style.AppTheme_Dark : R.style.AppTheme); + super.onCreate(savedInstanceState); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case android.R.id.home: + finish(); + return true; + default: + return super.onOptionsItemSelected(item); + } + } +} diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 51c1dc8e..4b185fc4 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -11,6 +11,32 @@ android:layout_height="wrap_content" android:orientation="vertical"> + + + + + + + + diff --git a/app/src/main/res/values-it/strings.xml b/app/src/main/res/values-it/strings.xml index 8259fa2b..2d835752 100644 --- a/app/src/main/res/values-it/strings.xml +++ b/app/src/main/res/values-it/strings.xml @@ -47,5 +47,6 @@ Impostazioni + Tema scuro Mostra file e cartelle nascosti diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index ea62cf4e..d40794cc 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -52,5 +52,6 @@ 設定 + ダークテーマ 非表示のファイルとディレクトリーを表示する diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 44e36a8e..9b2676be 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -50,5 +50,6 @@ Settings + Mörkt tema Visa dolda filer diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 145a36a3..68099771 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -7,5 +7,4 @@ #33000000 #08000000 #11000000 - #33000000 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index b7d5c512..6a5a97c5 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -55,5 +55,6 @@ Settings + Dark theme Show hidden files and directories diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 35d16734..3d05f332 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -8,6 +8,14 @@ @dimen/normal_text_size + +