add Dark theme
This commit is contained in:
parent
27cd476566
commit
16185a2e05
17 changed files with 170 additions and 11 deletions
|
@ -23,11 +23,18 @@
|
|||
|
||||
<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:label="@string/settings"
|
||||
android:parentActivityName=".activities.MainActivity"/>
|
||||
|
||||
<provider
|
||||
android:name="android.support.v4.content.FileProvider"
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,4 +4,5 @@ public class Constants {
|
|||
// shared preferences
|
||||
public static final String PREFS_KEY = "Draw";
|
||||
public static final String IS_FIRST_RUN = "is_first_run";
|
||||
public static final String IS_DARK_THEME = "is_dark_theme";
|
||||
}
|
||||
|
|
|
@ -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.draw.activities;
|
|||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
|
||||
import com.simplemobiletools.draw.R;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
|
||||
public class LicenseActivity extends AppCompatActivity {
|
||||
public class LicenseActivity extends SimpleActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
|
|
|
@ -13,7 +13,6 @@ import android.support.v4.app.ActivityCompat;
|
|||
import android.support.v4.content.ContextCompat;
|
||||
import android.support.v4.content.FileProvider;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.util.Log;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
|
@ -36,7 +35,7 @@ import butterknife.ButterKnife;
|
|||
import butterknife.OnClick;
|
||||
import yuku.ambilwarna.AmbilWarnaDialog;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements MyCanvas.PathsChangedListener {
|
||||
public class MainActivity extends SimpleActivity implements MyCanvas.PathsChangedListener {
|
||||
private static final String TAG = MainActivity.class.getSimpleName();
|
||||
private static final String FOLDER_NAME = "images";
|
||||
private static final String FILE_NAME = "simple-draw.png";
|
||||
|
@ -82,9 +81,11 @@ public class MainActivity extends AppCompatActivity implements MyCanvas.PathsCha
|
|||
case R.id.menu_share:
|
||||
shareImage();
|
||||
return true;
|
||||
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);
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
package com.simplemobiletools.draw.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.v4.app.TaskStackBuilder;
|
||||
import android.support.v7.widget.SwitchCompat;
|
||||
|
||||
import com.simplemobiletools.draw.Config;
|
||||
import com.simplemobiletools.draw.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.draw.activities;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import com.simplemobiletools.draw.Config;
|
||||
import com.simplemobiletools.draw.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);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -7,7 +7,8 @@
|
|||
<com.simplemobiletools.draw.MyCanvas
|
||||
android:id="@+id/my_canvas"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"/>
|
||||
android:layout_height="match_parent"
|
||||
android:background="@android:color/white"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/color_picker"
|
||||
|
|
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>
|
|
@ -11,6 +11,10 @@
|
|||
android:icon="@mipmap/share"
|
||||
android:title="@string/share"
|
||||
app:showAsAction="ifRoom"/>
|
||||
<item
|
||||
android:id="@+id/settings"
|
||||
android:title="@string/settings"
|
||||
app:showAsAction="never"/>
|
||||
<item
|
||||
android:id="@+id/about"
|
||||
android:title="@string/about"
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
<string name="enter_file_name">Inserisci un nome per il file</string>
|
||||
<string name="no_permissions">Impossibile salvare il file senza l\'accesso all\'archiviazione esterna</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Impostazioni</string>
|
||||
<string name="dark_theme">Tema scuro</string>
|
||||
|
||||
<!-- About -->
|
||||
<string name="about">Informazioni</string>
|
||||
<string name="website">Altre semplici app e codici sorgenti in:\nhttp://simplemobiletools.com</string>
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
<string name="enter_file_name">ファイル名を入力してください</string>
|
||||
<string name="no_permissions">外部ストレージにアクセスできないためファイルを保存できませんでした</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">設定</string>
|
||||
<string name="dark_theme">ダークテーマ</string>
|
||||
|
||||
<!-- About -->
|
||||
<string name="about">アプリについて</string>
|
||||
<string name="website">もっとシンプルなアプリとソースコードは:\nhttp://simplemobiletools.com</string>
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
<string name="enter_file_name">Ange ett filnamn</string>
|
||||
<string name="no_permissions">Kunde inte spara filen utan tillgång till extern lagringsutrymme</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Inställningar</string>
|
||||
<string name="dark_theme">Mörkt tema</string>
|
||||
|
||||
<!-- About -->
|
||||
<string name="about">Om</string>
|
||||
<string name="website">Fler enkla appar och källkod här:\nhttp://simplemobiletools.com</string>
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
<dimen name="icon_padding">8dp</dimen>
|
||||
<dimen name="social_padding">8dp</dimen>
|
||||
<dimen name="social_logo">40dp</dimen>
|
||||
<dimen name="settings_padding">8dp</dimen>
|
||||
|
||||
<dimen name="normal_text_size">14sp</dimen>
|
||||
</resources>
|
||||
|
|
|
@ -10,6 +10,10 @@
|
|||
<string name="enter_file_name">Please enter a file name</string>
|
||||
<string name="no_permissions">Could not save the file without accessing the external storage</string>
|
||||
|
||||
<!-- Settings -->
|
||||
<string name="settings">Settings</string>
|
||||
<string name="dark_theme">Dark theme</string>
|
||||
|
||||
<!-- About -->
|
||||
<string name="about">About</string>
|
||||
<string name="website">More simple apps and source code at:\nhttp://simplemobiletools.com</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="AppTheme.ActionBarStyle" parent="@style/Base.Widget.AppCompat.ActionBar">
|
||||
<item name="background">@color/colorPrimary</item>
|
||||
<item name="titleTextStyle">@style/AppTheme.ActionBar.TitleTextStyle</item>
|
||||
|
|
Loading…
Reference in a new issue