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 @@