add a dark theme
This commit is contained in:
parent
c785b96ac8
commit
30e284415d
20 changed files with 174 additions and 34 deletions
|
@ -29,11 +29,19 @@
|
|||
|
||||
<activity
|
||||
android:name=".activities.AboutActivity"
|
||||
android:label="@string/about"/>
|
||||
android:label="@string/about"
|
||||
android:parentActivityName=".activities.MainActivity"/>
|
||||
|
||||
<activity
|
||||
android:name=".activities.LicenseActivity"
|
||||
android:label="@string/third_party_licences"/>
|
||||
android:label="@string/third_party_licences"
|
||||
android:parentActivityName=".activities.AboutActivity"/>
|
||||
|
||||
<activity
|
||||
android:name=".activities.SettingsActivity"
|
||||
android:allowTaskReparenting="true"
|
||||
android:label="@string/settings"
|
||||
android:parentActivityName=".activities.MainActivity"/>
|
||||
|
||||
<receiver
|
||||
android:name=".MyWidgetProvider"
|
||||
|
@ -46,6 +54,5 @@
|
|||
android:name="android.appwidget.provider"
|
||||
android:resource="@xml/widget_info"/>
|
||||
</receiver>
|
||||
|
||||
</application>
|
||||
</manifest>
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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";
|
||||
}
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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">
|
||||
|
||||
<TextView
|
||||
|
@ -20,7 +18,6 @@
|
|||
android:maxLines="1"
|
||||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/activity_margin"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="@dimen/formula_text_size"/>
|
||||
|
||||
<TextView
|
||||
|
@ -34,7 +31,6 @@
|
|||
android:paddingLeft="@dimen/activity_margin"
|
||||
android:paddingRight="@dimen/activity_margin"
|
||||
android:text="0"
|
||||
android:textColor="@android:color/white"
|
||||
android:textSize="@dimen/display_text_size"/>
|
||||
|
||||
<LinearLayout
|
||||
|
|
40
app/src/main/res/layout/activity_settings.xml
Normal file
40
app/src/main/res/layout/activity_settings.xml
Normal file
|
@ -0,0 +1,40 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<ScrollView
|
||||
android:id="@+id/settings_scrollview"
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/settings_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/settings_dark_theme_holder"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/settings_padding"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:padding="@dimen/activity_margin">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/settings_dark_theme_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:paddingLeft="@dimen/settings_padding"
|
||||
android:text="@string/dark_theme"/>
|
||||
|
||||
<android.support.v7.widget.SwitchCompat
|
||||
android:id="@+id/settings_dark_theme"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentRight="true"
|
||||
android:background="@null"
|
||||
android:clickable="false"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
|
@ -1,6 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/settings"
|
||||
android:title="@string/settings"
|
||||
app:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/about"
|
||||
android:title="@string/about"
|
||||
|
|
|
@ -11,6 +11,10 @@
|
|||
<string name="follow_us">Seguici:</string>
|
||||
<string name="copyright">v %1$s\nCopyright © Simple Mobile Tools %2$d</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Impostazioni</string>
|
||||
<string name="dark_theme">Tema scuro</string>
|
||||
|
||||
<!--License-->
|
||||
<string name="notice">Questa app usa le seguenti librerie di terze parti per semplificarmi la vita. Grazie.</string>
|
||||
<string name="third_party_licences">Licenze di terze parti</string>
|
||||
|
|
|
@ -11,6 +11,10 @@
|
|||
<string name="follow_us">フォローしてください:</string>
|
||||
<string name="copyright">v %1$s\nCopyright © Simple Mobile Tools %2$d</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">設定</string>
|
||||
<string name="dark_theme">ダークテーマ</string>
|
||||
|
||||
<!--License-->
|
||||
<string name="notice">このアプリは、私の人生を容易にするために、次のサードパーティのライブラリーを使用しています。 ありがとうございます。</string>
|
||||
<string name="third_party_licences">サードパーティー ライセンス</string>
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
<string name="version">v %1$s</string>
|
||||
<string name="copyright">v %1$s\nCopyright © Simple Mobile Tools %2$d</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Inställningar</string>
|
||||
<string name="dark_theme">Mörkt tema</string>
|
||||
|
||||
<!--License-->
|
||||
<string name="notice">Denna app använder följande tredjepartsbibliotek för att göra mitt liv enklare. Tack.</string>
|
||||
<string name="third_party_licences">Tredjepartslicenser</string>
|
||||
|
|
|
@ -3,7 +3,6 @@
|
|||
<color name="colorPrimary">#fff68630</color>
|
||||
<color name="colorPrimaryDark">#ffe27725</color>
|
||||
<color name="colorAccent">@color/colorPrimary</color>
|
||||
<color name="buttons_background">#fff3f3f3</color>
|
||||
<color name="text_grey">#77000000</color>
|
||||
<color name="dark_grey_pressed_mask">#11000000</color>
|
||||
</resources>
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
<dimen name="result_padding">64dp</dimen>
|
||||
<dimen name="social_padding">8dp</dimen>
|
||||
<dimen name="social_logo">40dp</dimen>
|
||||
<dimen name="settings_padding">8dp</dimen>
|
||||
|
||||
<dimen name="min_widget_width">250dp</dimen>
|
||||
<dimen name="min_widget_height">250dp</dimen>
|
||||
|
|
|
@ -12,6 +12,10 @@
|
|||
<string name="follow_us">Follow us:</string>
|
||||
<string name="copyright">v %1$s\nCopyright © Simple Mobile Tools %2$d</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Settings</string>
|
||||
<string name="dark_theme">Dark theme</string>
|
||||
|
||||
<!--License-->
|
||||
<string name="notice">This app uses the following third party libraries to make my life easier. Thank you.</string>
|
||||
<string name="third_party_licences">Third party licences</string>
|
||||
|
|
|
@ -8,6 +8,14 @@
|
|||
<item name="android:textSize">@dimen/normal_text_size</item>
|
||||
</style>
|
||||
|
||||
<style name="AppTheme.Dark" parent="Theme.AppCompat">
|
||||
<item name="colorPrimary">@color/colorPrimary</item>
|
||||
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
|
||||
<item name="colorAccent">@color/colorAccent</item>
|
||||
<item name="actionBarStyle">@style/AppTheme.ActionBarStyle</item>
|
||||
<item name="android:textSize">@dimen/normal_text_size</item>
|
||||
</style>
|
||||
|
||||
<style name="MainTheme" parent="@style/AppTheme">
|
||||
<item name="android:textColor">@android:color/white</item>
|
||||
</style>
|
||||
|
|
Loading…
Reference in a new issue