diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index fc06b7ce..85b2488a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -29,11 +29,19 @@ + android:label="@string/about" + android:parentActivityName=".activities.MainActivity"/> + android:label="@string/third_party_licences" + android:parentActivityName=".activities.AboutActivity"/> + + - diff --git a/app/src/main/java/com/simplemobiletools/calculator/Config.java b/app/src/main/java/com/simplemobiletools/calculator/Config.java index ea3cb3fc..077ae556 100644 --- a/app/src/main/java/com/simplemobiletools/calculator/Config.java +++ b/app/src/main/java/com/simplemobiletools/calculator/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/calculator/Constants.java b/app/src/main/java/com/simplemobiletools/calculator/Constants.java index ca067eb4..3bf3a20d 100644 --- a/app/src/main/java/com/simplemobiletools/calculator/Constants.java +++ b/app/src/main/java/com/simplemobiletools/calculator/Constants.java @@ -25,11 +25,10 @@ public class Constants { public static final String EIGHT = "eight"; public static final String NINE = "nine"; - public static final String PREFS = "prefs"; - public static final String WIDGET_BG_COLOR = "widget_bg_color"; - public static final String WIDGET_TEXT_COLOR = "widget_text_color"; - // shared preferences public static final String PREFS_KEY = "Calculator"; 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/calculator/MyWidgetProvider.java b/app/src/main/java/com/simplemobiletools/calculator/MyWidgetProvider.java index 049b220a..dc6217bc 100644 --- a/app/src/main/java/com/simplemobiletools/calculator/MyWidgetProvider.java +++ b/app/src/main/java/com/simplemobiletools/calculator/MyWidgetProvider.java @@ -102,7 +102,7 @@ public class MyWidgetProvider extends AppWidgetProvider implements Calculator { } private SharedPreferences initPrefs(Context context) { - return context.getSharedPreferences(Constants.PREFS, Context.MODE_PRIVATE); + return context.getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE); } private void updateTextColors(int color) { diff --git a/app/src/main/java/com/simplemobiletools/calculator/activities/AboutActivity.java b/app/src/main/java/com/simplemobiletools/calculator/activities/AboutActivity.java index 6bdddef6..1b5cec62 100644 --- a/app/src/main/java/com/simplemobiletools/calculator/activities/AboutActivity.java +++ b/app/src/main/java/com/simplemobiletools/calculator/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/calculator/activities/LicenseActivity.java b/app/src/main/java/com/simplemobiletools/calculator/activities/LicenseActivity.java index 5618b4ca..f0efcc0f 100644 --- a/app/src/main/java/com/simplemobiletools/calculator/activities/LicenseActivity.java +++ b/app/src/main/java/com/simplemobiletools/calculator/activities/LicenseActivity.java @@ -3,14 +3,13 @@ package com.simplemobiletools.calculator.activities; import android.content.Intent; import android.net.Uri; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; import com.simplemobiletools.calculator.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/calculator/activities/MainActivity.java b/app/src/main/java/com/simplemobiletools/calculator/activities/MainActivity.java index f051bbaa..f5bad03d 100644 --- a/app/src/main/java/com/simplemobiletools/calculator/activities/MainActivity.java +++ b/app/src/main/java/com/simplemobiletools/calculator/activities/MainActivity.java @@ -3,9 +3,7 @@ package com.simplemobiletools.calculator.activities; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Intent; -import android.content.res.Resources; import android.os.Bundle; -import android.support.v7.app.AppCompatActivity; import android.view.Menu; import android.view.MenuItem; import android.view.View; @@ -25,7 +23,7 @@ import butterknife.OnClick; import butterknife.OnLongClick; import me.grantland.widget.AutofitHelper; -public class MainActivity extends AppCompatActivity implements Calculator { +public class MainActivity extends SimpleActivity implements Calculator { @BindView(R.id.result) TextView mResult; @BindView(R.id.formula) TextView mFormula; @@ -38,7 +36,6 @@ public class MainActivity extends AppCompatActivity implements Calculator { ButterKnife.bind(this); mCalc = new CalculatorImpl(this); - setupResultView(); AutofitHelper.create(mResult); AutofitHelper.create(mFormula); } @@ -58,24 +55,17 @@ public class MainActivity extends AppCompatActivity implements Calculator { @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); } } - private void setupResultView() { - final Resources res = getResources(); - mResult.setBackgroundColor(res.getColor(android.R.color.white)); - mResult.setTextColor(res.getColor(R.color.text_grey)); - - mFormula.setBackgroundColor(res.getColor(android.R.color.white)); - mFormula.setTextColor(res.getColor(R.color.text_grey)); - } - @OnClick(R.id.btn_plus) public void plusClicked() { mCalc.handleOperation(Constants.PLUS); diff --git a/app/src/main/java/com/simplemobiletools/calculator/activities/SettingsActivity.java b/app/src/main/java/com/simplemobiletools/calculator/activities/SettingsActivity.java new file mode 100644 index 00000000..7f1a9765 --- /dev/null +++ b/app/src/main/java/com/simplemobiletools/calculator/activities/SettingsActivity.java @@ -0,0 +1,43 @@ +package com.simplemobiletools.calculator.activities; + +import android.os.Bundle; +import android.support.v4.app.TaskStackBuilder; +import android.support.v7.widget.SwitchCompat; + +import com.simplemobiletools.calculator.Config; +import com.simplemobiletools.calculator.R; + +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.OnClick; + +public class SettingsActivity extends SimpleActivity { + @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()); + restartActivity(); + } + + private void restartActivity() { + TaskStackBuilder.create(getApplicationContext()).addNextIntentWithParentStack(getIntent()).startActivities(); + } +} diff --git a/app/src/main/java/com/simplemobiletools/calculator/activities/SimpleActivity.java b/app/src/main/java/com/simplemobiletools/calculator/activities/SimpleActivity.java new file mode 100644 index 00000000..ae2c79ea --- /dev/null +++ b/app/src/main/java/com/simplemobiletools/calculator/activities/SimpleActivity.java @@ -0,0 +1,31 @@ +package com.simplemobiletools.calculator.activities; + +import android.os.Bundle; +import android.support.annotation.Nullable; +import android.support.v7.app.AppCompatActivity; +import android.view.MenuItem; + +import com.simplemobiletools.calculator.Config; +import com.simplemobiletools.calculator.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/java/com/simplemobiletools/calculator/activities/WidgetConfigureActivity.java b/app/src/main/java/com/simplemobiletools/calculator/activities/WidgetConfigureActivity.java index d745fb64..33711354 100644 --- a/app/src/main/java/com/simplemobiletools/calculator/activities/WidgetConfigureActivity.java +++ b/app/src/main/java/com/simplemobiletools/calculator/activities/WidgetConfigureActivity.java @@ -56,7 +56,7 @@ public class WidgetConfigureActivity extends AppCompatActivity { } private void initVariables() { - final SharedPreferences prefs = getSharedPreferences(Constants.PREFS, Context.MODE_PRIVATE); + final SharedPreferences prefs = getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE); mBgColor = prefs.getInt(Constants.WIDGET_BG_COLOR, 1); if (mBgColor == 1) { mBgColor = Color.BLACK; @@ -95,7 +95,7 @@ public class WidgetConfigureActivity extends AppCompatActivity { } private void storeWidgetBackground() { - final SharedPreferences prefs = getSharedPreferences(Constants.PREFS, Context.MODE_PRIVATE); + final SharedPreferences prefs = getSharedPreferences(Constants.PREFS_KEY, Context.MODE_PRIVATE); prefs.edit().putInt(Constants.WIDGET_BG_COLOR, mBgColor).apply(); prefs.edit().putInt(Constants.WIDGET_TEXT_COLOR, mTextColor).apply(); } diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 91270e8f..87cfe0b8 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -5,9 +5,7 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="@color/buttons_background" android:orientation="vertical" - android:theme="@style/MainTheme" tools:context=".activities.MainActivity"> + + + + + + + + + + + + + diff --git a/app/src/main/res/menu/menu.xml b/app/src/main/res/menu/menu.xml index 0cce6d24..815619cd 100644 --- a/app/src/main/res/menu/menu.xml +++ b/app/src/main/res/menu/menu.xml @@ -1,6 +1,10 @@ + Seguici: v %1$s\nCopyright © Simple Mobile Tools %2$d + + Impostazioni + Tema scuro + Questa app usa le seguenti librerie di terze parti per semplificarmi la vita. Grazie. Licenze di terze parti diff --git a/app/src/main/res/values-ja/strings.xml b/app/src/main/res/values-ja/strings.xml index 8cd6f157..0c60ffe4 100644 --- a/app/src/main/res/values-ja/strings.xml +++ b/app/src/main/res/values-ja/strings.xml @@ -11,6 +11,10 @@ フォローしてください: v %1$s\nCopyright © Simple Mobile Tools %2$d + + 設定 + ダークテーマ + このアプリは、私の人生を容易にするために、次のサードパーティのライブラリーを使用しています。 ありがとうございます。 サードパーティー ライセンス diff --git a/app/src/main/res/values-sv/strings.xml b/app/src/main/res/values-sv/strings.xml index 72d240b9..35ae1123 100644 --- a/app/src/main/res/values-sv/strings.xml +++ b/app/src/main/res/values-sv/strings.xml @@ -12,6 +12,10 @@ v %1$s v %1$s\nCopyright © Simple Mobile Tools %2$d + + Inställningar + Mörkt tema + Denna app använder följande tredjepartsbibliotek för att göra mitt liv enklare. Tack. Tredjepartslicenser diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 1dc60b30..b5ecad0d 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -3,7 +3,6 @@ #fff68630 #ffe27725 @color/colorPrimary - #fff3f3f3 #77000000 #11000000 diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index 8669c440..8790d4ab 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -3,6 +3,7 @@ 64dp 8dp 40dp + 8dp 250dp 250dp diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index c628b975..bf0db01f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -12,6 +12,10 @@ Follow us: v %1$s\nCopyright © Simple Mobile Tools %2$d + + Settings + Dark theme + This app uses the following third party libraries to make my life easier. Thank you. Third party licences diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 294b63b7..8c0b0ca2 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 + +