add a Dark theme

+ adding the Settings itself (splitting it into multiple commits would make no sense)
This commit is contained in:
tibbi 2016-07-20 20:46:51 +02:00
parent 952a820aa8
commit 32aa2fbc39
20 changed files with 194 additions and 23 deletions

View file

@ -49,10 +49,12 @@
</activity> </activity>
<activity <activity
android:name=".activities.MediaActivity"/> android:name=".activities.MediaActivity"
android:parentActivityName=".activities.MainActivity"/>
<activity <activity
android:name=".activities.ViewPagerActivity" android:name=".activities.ViewPagerActivity"
android:parentActivityName=".activities.MediaActivity"
android:theme="@style/FullScreenTheme"> android:theme="@style/FullScreenTheme">
<intent-filter> <intent-filter>
@ -68,11 +70,19 @@
<activity <activity
android:name=".activities.AboutActivity" android:name=".activities.AboutActivity"
android:label="@string/about"/> android:label="@string/about"
android:parentActivityName=".activities.MainActivity"/>
<activity <activity
android:name=".activities.LicenseActivity" 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"/>
<activity <activity
android:name=".activities.PhotoVideoActivity"/> android:name=".activities.PhotoVideoActivity"/>

View file

@ -21,4 +21,12 @@ public class Config {
public void setIsFirstRun(boolean firstRun) { public void setIsFirstRun(boolean firstRun) {
mPrefs.edit().putBoolean(Constants.IS_FIRST_RUN, firstRun).apply(); 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();
}
} }

View file

@ -10,4 +10,5 @@ public class Constants {
// shared preferences // shared preferences
public static final String PREFS_KEY = "Gallery"; public static final String PREFS_KEY = "Gallery";
public static final String IS_FIRST_RUN = "is_first_run"; public static final String IS_FIRST_RUN = "is_first_run";
public static final String IS_DARK_THEME = "is_dark_theme";
} }

View file

@ -5,7 +5,6 @@ import android.content.Intent;
import android.content.res.Resources; import android.content.res.Resources;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Html; import android.text.Html;
import android.text.method.LinkMovementMethod; import android.text.method.LinkMovementMethod;
import android.view.View; import android.view.View;
@ -21,7 +20,7 @@ import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick; import butterknife.OnClick;
public class AboutActivity extends AppCompatActivity { public class AboutActivity extends SimpleActivity {
@BindView(R.id.about_copyright) TextView mCopyright; @BindView(R.id.about_copyright) TextView mCopyright;
@BindView(R.id.about_email) TextView mEmailTV; @BindView(R.id.about_email) TextView mEmailTV;
@BindView(R.id.about_rate_us) View mRateUs; @BindView(R.id.about_rate_us) View mRateUs;

View file

@ -3,14 +3,13 @@ package com.simplemobiletools.gallery.activities;
import android.content.Intent; import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import com.simplemobiletools.gallery.R; import com.simplemobiletools.gallery.R;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick; import butterknife.OnClick;
public class LicenseActivity extends AppCompatActivity { public class LicenseActivity extends SimpleActivity {
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {

View file

@ -15,7 +15,6 @@ import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.util.SparseBooleanArray; import android.util.SparseBooleanArray;
import android.view.ActionMode; import android.view.ActionMode;
import android.view.Menu; import android.view.Menu;
@ -45,7 +44,7 @@ import java.util.Map;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
public class MainActivity extends AppCompatActivity public class MainActivity extends SimpleActivity
implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener { implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener {
@BindView(R.id.directories_grid) GridView mGridView; @BindView(R.id.directories_grid) GridView mGridView;
@ -97,16 +96,15 @@ public class MainActivity extends AppCompatActivity
@Override @Override
public boolean onOptionsItemSelected(MenuItem item) { public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) { switch (item.getItemId()) {
case R.id.camera: { case R.id.camera:
final Intent intent = new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA); startActivity(new Intent(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA));
startActivity(intent);
return true; return true;
} case R.id.settings:
case R.id.about: { startActivity(new Intent(getApplicationContext(), SettingsActivity.class));
final Intent intent = new Intent(getApplicationContext(), AboutActivity.class); return true;
startActivity(intent); case R.id.about:
startActivity(new Intent(getApplicationContext(), AboutActivity.class));
return true; return true;
}
default: default:
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }

View file

@ -13,7 +13,6 @@ import android.os.Parcelable;
import android.provider.MediaStore; import android.provider.MediaStore;
import android.support.design.widget.CoordinatorLayout; import android.support.design.widget.CoordinatorLayout;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.util.Log; import android.util.Log;
import android.util.SparseBooleanArray; import android.util.SparseBooleanArray;
import android.view.ActionMode; import android.view.ActionMode;
@ -44,7 +43,7 @@ import java.util.regex.Pattern;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
public class MediaActivity extends AppCompatActivity public class MediaActivity extends SimpleActivity
implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener { implements AdapterView.OnItemClickListener, GridView.MultiChoiceModeListener, GridView.OnTouchListener {
private static final String TAG = MediaActivity.class.getSimpleName(); private static final String TAG = MediaActivity.class.getSimpleName();
@BindView(R.id.media_grid) GridView mGridView; @BindView(R.id.media_grid) GridView mGridView;

View file

@ -4,7 +4,6 @@ import android.content.Intent;
import android.net.Uri; import android.net.Uri;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -16,7 +15,7 @@ import com.simplemobiletools.gallery.fragments.VideoFragment;
import com.simplemobiletools.gallery.fragments.ViewPagerFragment; import com.simplemobiletools.gallery.fragments.ViewPagerFragment;
import com.simplemobiletools.gallery.models.Medium; import com.simplemobiletools.gallery.models.Medium;
public class PhotoVideoActivity extends AppCompatActivity implements ViewPagerFragment.FragmentClickListener { public class PhotoVideoActivity extends SimpleActivity implements ViewPagerFragment.FragmentClickListener {
private static ActionBar mActionbar; private static ActionBar mActionbar;
private static Uri mUri; private static Uri mUri;

View file

@ -0,0 +1,43 @@
package com.simplemobiletools.gallery.activities;
import android.os.Bundle;
import android.support.v4.app.TaskStackBuilder;
import android.support.v7.widget.SwitchCompat;
import com.simplemobiletools.gallery.Config;
import com.simplemobiletools.gallery.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();
}
}

View file

@ -0,0 +1,35 @@
package com.simplemobiletools.gallery.activities;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import com.simplemobiletools.gallery.Config;
import com.simplemobiletools.gallery.R;
public class SimpleActivity extends AppCompatActivity {
protected Config mConfig;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
mConfig = Config.newInstance(getApplicationContext());
int theme = mConfig.getIsDarkTheme() ? R.style.AppTheme_Dark : R.style.AppTheme;
if (this instanceof ViewPagerActivity || this instanceof PhotoActivity || this instanceof VideoActivity) {
theme = mConfig.getIsDarkTheme() ? R.style.FullScreenTheme_Dark : R.style.FullScreenTheme;
}
setTheme(theme);
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);
}
}
}

View file

@ -11,7 +11,6 @@ import android.provider.MediaStore;
import android.support.v4.view.ViewPager; import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBar; import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog; import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.MotionEvent; import android.view.MotionEvent;
@ -38,7 +37,7 @@ import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick; import butterknife.OnClick;
public class ViewPagerActivity extends AppCompatActivity public class ViewPagerActivity extends SimpleActivity
implements ViewPager.OnPageChangeListener, View.OnSystemUiVisibilityChangeListener, ViewPager.OnTouchListener, implements ViewPager.OnPageChangeListener, View.OnSystemUiVisibilityChangeListener, ViewPager.OnTouchListener,
ViewPagerFragment.FragmentClickListener { ViewPagerFragment.FragmentClickListener {
@BindView(R.id.undo_delete) View mUndoBtn; @BindView(R.id.undo_delete) View mUndoBtn;

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

View file

@ -6,6 +6,10 @@
android:icon="@mipmap/camera" android:icon="@mipmap/camera"
android:title="@string/open_camera" android:title="@string/open_camera"
app:showAsAction="ifRoom"/> app:showAsAction="ifRoom"/>
<item
android:id="@+id/settings"
android:title="@string/settings"
app:showAsAction="never"/>
<item <item
android:id="@+id/about" android:id="@+id/about"
android:title="@string/about" android:title="@string/about"

View file

@ -40,6 +40,10 @@
<string name="follow_us">Seguici:</string> <string name="follow_us">Seguici:</string>
<string name="copyright">v %1$s\nCopyright © Simple Mobile Tools %2$d</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--> <!--License-->
<string name="notice">Questa app usa le seguenti librerie di terze parti per semplificarmi la vita. Grazie.</string> <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> <string name="third_party_licences">Licenze di terze parti</string>

View file

@ -40,6 +40,10 @@
<string name="follow_us">フォローしてください:</string> <string name="follow_us">フォローしてください:</string>
<string name="copyright">v %1$s\nCopyright © Simple Mobile Tools %2$d</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--> <!--License-->
<string name="notice">このアプリは、私の人生を容易にするために、次のサードパーティのライブラリーを使用しています。 ありがとうございます。</string> <string name="notice">このアプリは、私の人生を容易にするために、次のサードパーティのライブラリーを使用しています。 ありがとうございます。</string>
<string name="third_party_licences">サードパーティー ライセンス</string> <string name="third_party_licences">サードパーティー ライセンス</string>

View file

@ -40,6 +40,10 @@
<string name="follow_us">Följ oss:</string> <string name="follow_us">Följ oss:</string>
<string name="copyright">v %1$s\nCopyright © Simple Mobile Tools %2$d</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--> <!--License-->
<string name="notice">Denna app använder följande tredjepartsbibliotek för att göra mitt liv enklare. Tack.</string> <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> <string name="third_party_licences">Tredjepartslicenser</string>

View file

@ -4,4 +4,8 @@
<item name="android:windowTranslucentNavigation">true</item> <item name="android:windowTranslucentNavigation">true</item>
</style> </style>
<style name="FullScreenTheme.Dark" parent="FullScreenTheme.Base.Dark">
<item name="android:windowTranslucentNavigation">true</item>
</style>
</resources> </resources>

View file

@ -10,6 +10,7 @@
<dimen name="social_logo">40dp</dimen> <dimen name="social_logo">40dp</dimen>
<dimen name="tmb_shadow_height">50dp</dimen> <dimen name="tmb_shadow_height">50dp</dimen>
<dimen name="undo_size">56dp</dimen> <dimen name="undo_size">56dp</dimen>
<dimen name="settings_padding">8dp</dimen>
<dimen name="normal_text_size">14sp</dimen> <dimen name="normal_text_size">14sp</dimen>
</resources> </resources>

View file

@ -41,6 +41,10 @@
<string name="follow_us">Follow us:</string> <string name="follow_us">Follow us:</string>
<string name="copyright">v %1$s\nCopyright © Simple Mobile Tools %2$d</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--> <!--License-->
<string name="notice">This app uses the following third party libraries to make my life easier. Thank you.</string> <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> <string name="third_party_licences">Third party licences</string>

View file

@ -14,8 +14,24 @@
<item name="android:actionBarStyle">@style/MyFullScreenActionBar</item> <item name="android:actionBarStyle">@style/MyFullScreenActionBar</item>
</style> </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="FullScreenTheme.Base.Dark" parent="AppTheme.Dark">
<item name="android:windowContentOverlay">@null</item>
<item name="actionBarStyle">@style/MyFullScreenActionBar</item>
<item name="android:actionBarStyle">@style/MyFullScreenActionBar</item>
</style>
<style name="FullScreenTheme" parent="FullScreenTheme.Base"/> <style name="FullScreenTheme" parent="FullScreenTheme.Base"/>
<style name="FullScreenTheme.Dark" parent="FullScreenTheme.Base.Dark"/>
<style name="MyFullScreenActionBar" parent="Widget.AppCompat.Light.ActionBar"> <style name="MyFullScreenActionBar" parent="Widget.AppCompat.Light.ActionBar">
<item name="background">@color/actionbar_grey</item> <item name="background">@color/actionbar_grey</item>
<item name="android:background">@color/actionbar_grey</item> <item name="android:background">@color/actionbar_grey</item>