add a Dark theme

This commit is contained in:
tibbi 2016-07-24 13:33:00 +02:00
parent fce2433a00
commit 743d4d2cb9
16 changed files with 106 additions and 13 deletions

View File

@ -19,14 +19,17 @@
<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 <activity
android:name=".activities.SettingsActivity" android:name=".activities.SettingsActivity"
android:label="@string/settings"/> android:label="@string/settings"
android:parentActivityName=".activities.MainActivity"/>
</application> </application>
</manifest> </manifest>

View File

@ -22,6 +22,14 @@ public class Config {
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();
}
public boolean getShowHidden() { public boolean getShowHidden() {
return mPrefs.getBoolean(Constants.SHOW_HIDDEN, false); return mPrefs.getBoolean(Constants.SHOW_HIDDEN, false);
} }

View File

@ -6,5 +6,6 @@ public class Constants {
// shared preferences // shared preferences
public static final String PREFS_KEY = "File Manager"; public static final String PREFS_KEY = "File Manager";
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";
public static final String SHOW_HIDDEN = "show_hidden"; public static final String SHOW_HIDDEN = "show_hidden";
} }

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.filemanager.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.filemanager.R; import com.simplemobiletools.filemanager.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

@ -6,7 +6,6 @@ import android.content.pm.PackageManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.Environment; import android.os.Environment;
import android.support.v4.app.ActivityCompat; import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
@ -21,7 +20,7 @@ import com.simplemobiletools.filemanager.models.FileDirItem;
import butterknife.BindView; import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
public class MainActivity extends AppCompatActivity implements ItemsFragment.ItemInteractionListener, Breadcrumbs.BreadcrumbsListener { public class MainActivity extends SimpleActivity implements ItemsFragment.ItemInteractionListener, Breadcrumbs.BreadcrumbsListener {
@BindView(R.id.breadcrumbs) Breadcrumbs mBreadcrumbs; @BindView(R.id.breadcrumbs) Breadcrumbs mBreadcrumbs;
private static final int STORAGE_PERMISSION = 1; private static final int STORAGE_PERMISSION = 1;

View File

@ -1,7 +1,7 @@
package com.simplemobiletools.filemanager.activities; package com.simplemobiletools.filemanager.activities;
import android.os.Bundle; import android.os.Bundle;
import android.support.v7.app.AppCompatActivity; import android.support.v4.app.TaskStackBuilder;
import android.support.v7.widget.SwitchCompat; import android.support.v7.widget.SwitchCompat;
import com.simplemobiletools.filemanager.Config; import com.simplemobiletools.filemanager.Config;
@ -11,7 +11,8 @@ import butterknife.BindView;
import butterknife.ButterKnife; import butterknife.ButterKnife;
import butterknife.OnClick; import butterknife.OnClick;
public class SettingsActivity extends AppCompatActivity { public class SettingsActivity extends SimpleActivity {
@BindView(R.id.settings_dark_theme) SwitchCompat mDarkThemeSwitch;
@BindView(R.id.settings_show_hidden) SwitchCompat mShowHiddenSwitch; @BindView(R.id.settings_show_hidden) SwitchCompat mShowHiddenSwitch;
private static Config mConfig; private static Config mConfig;
@ -23,16 +24,32 @@ public class SettingsActivity extends AppCompatActivity {
mConfig = Config.newInstance(getApplicationContext()); mConfig = Config.newInstance(getApplicationContext());
ButterKnife.bind(this); ButterKnife.bind(this);
setupDarkTheme();
setupShowHidden(); setupShowHidden();
} }
private void setupDarkTheme() {
mDarkThemeSwitch.setChecked(mConfig.getIsDarkTheme());
}
private void setupShowHidden() { private void setupShowHidden() {
mShowHiddenSwitch.setChecked(mConfig.getShowHidden()); mShowHiddenSwitch.setChecked(mConfig.getShowHidden());
} }
@OnClick(R.id.settings_dark_theme_holder)
public void handleDarkTheme() {
mDarkThemeSwitch.setChecked(!mDarkThemeSwitch.isChecked());
mConfig.setIsDarkTheme(mDarkThemeSwitch.isChecked());
restartActivity();
}
@OnClick(R.id.settings_show_hidden_holder) @OnClick(R.id.settings_show_hidden_holder)
public void handleShowHidden() { public void handleShowHidden() {
mShowHiddenSwitch.setChecked(!mShowHiddenSwitch.isChecked()); mShowHiddenSwitch.setChecked(!mShowHiddenSwitch.isChecked());
mConfig.setShowHidden(mShowHiddenSwitch.isChecked()); mConfig.setShowHidden(mShowHiddenSwitch.isChecked());
} }
private void restartActivity() {
TaskStackBuilder.create(getApplicationContext()).addNextIntentWithParentStack(getIntent()).startActivities();
}
} }

View File

@ -0,0 +1,31 @@
package com.simplemobiletools.filemanager.activities;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.MenuItem;
import com.simplemobiletools.filemanager.Config;
import com.simplemobiletools.filemanager.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);
}
}
}

View File

@ -11,6 +11,32 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:orientation="vertical"> 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>
<RelativeLayout <RelativeLayout
android:id="@+id/settings_show_hidden_holder" android:id="@+id/settings_show_hidden_holder"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -39,7 +39,6 @@
android:layout_toRightOf="@+id/item_icon" android:layout_toRightOf="@+id/item_icon"
android:paddingLeft="@dimen/small_margin" android:paddingLeft="@dimen/small_margin"
android:text="1 KB" android:text="1 KB"
android:textColor="@color/details_grey"
android:textSize="@dimen/details_text_size"/> android:textSize="@dimen/details_text_size"/>
</RelativeLayout> </RelativeLayout>

View File

@ -47,5 +47,6 @@
<!-- Settings --> <!-- Settings -->
<string name="settings">Impostazioni</string> <string name="settings">Impostazioni</string>
<string name="dark_theme">Tema scuro</string>
<string name="show_hidden">Mostra file e cartelle nascosti</string> <string name="show_hidden">Mostra file e cartelle nascosti</string>
</resources> </resources>

View File

@ -52,5 +52,6 @@
<!-- Settings --> <!-- Settings -->
<string name="settings">設定</string> <string name="settings">設定</string>
<string name="dark_theme">ダークテーマ</string>
<string name="show_hidden">非表示のファイルとディレクトリーを表示する</string> <string name="show_hidden">非表示のファイルとディレクトリーを表示する</string>
</resources> </resources>

View File

@ -50,5 +50,6 @@
<!-- Settings --> <!-- Settings -->
<string name="settings">Settings</string> <string name="settings">Settings</string>
<string name="dark_theme">Mörkt tema</string>
<string name="show_hidden">Visa dolda filer</string> <string name="show_hidden">Visa dolda filer</string>
</resources> </resources>

View File

@ -7,5 +7,4 @@
<color name="lightGrey">#33000000</color> <color name="lightGrey">#33000000</color>
<color name="pressed_item_foreground">#08000000</color> <color name="pressed_item_foreground">#08000000</color>
<color name="activated_item_foreground">#11000000</color> <color name="activated_item_foreground">#11000000</color>
<color name="details_grey">#33000000</color>
</resources> </resources>

View File

@ -55,5 +55,6 @@
<!-- Settings --> <!-- Settings -->
<string name="settings">Settings</string> <string name="settings">Settings</string>
<string name="dark_theme">Dark theme</string>
<string name="show_hidden">Show hidden files and directories</string> <string name="show_hidden">Show hidden files and directories</string>
</resources> </resources>

View File

@ -8,6 +8,14 @@
<item name="android:textSize">@dimen/normal_text_size</item> <item name="android:textSize">@dimen/normal_text_size</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="AppTheme.ActionBarStyle" parent="@style/Base.Widget.AppCompat.ActionBar"> <style name="AppTheme.ActionBarStyle" parent="@style/Base.Widget.AppCompat.ActionBar">
<item name="background">@color/colorPrimary</item> <item name="background">@color/colorPrimary</item>
<item name="titleTextStyle">@style/AppTheme.ActionBar.TitleTextStyle</item> <item name="titleTextStyle">@style/AppTheme.ActionBar.TitleTextStyle</item>