Added switch for Dark Theme
This commit is contained in:
parent
8a18bf8b2e
commit
2220ab9d30
@ -190,7 +190,7 @@ public class Daedalus extends Application {
|
||||
}
|
||||
|
||||
public static boolean isDarkTheme() {
|
||||
return false;
|
||||
return getInstance().prefs.getBoolean("settings_dark_theme", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -56,7 +56,7 @@ public class ConfigActivity extends AppCompatActivity {
|
||||
break;
|
||||
}
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar_config);
|
||||
Toolbar toolbar = findViewById(R.id.toolbar_config);
|
||||
Drawable drawable = ContextCompat.getDrawable(this, R.drawable.ic_clear);
|
||||
Drawable wrappedDrawable = DrawableCompat.wrap(drawable);
|
||||
DrawableCompat.setTint(wrappedDrawable, Color.WHITE);
|
||||
|
@ -58,6 +58,8 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||
public static final int FRAGMENT_DNS_SERVERS = 5;
|
||||
public static final int FRAGMENT_LOG = 6;
|
||||
|
||||
public static final String LAUNCH_NEED_RECREATE = "org.itxtech.daedalus.activity.MainActivity.LAUNCH_NEED_RECREATE";
|
||||
|
||||
private static MainActivity instance = null;
|
||||
|
||||
private ToolbarFragment currentFragment;
|
||||
@ -92,7 +94,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||
((TextView) navigationView.getHeaderView(0).findViewById(R.id.textView_nav_git_commit)).setText(getString(R.string.nav_git_commit) + " " + BuildConfig.GIT_COMMIT);
|
||||
|
||||
updateUserInterface(getIntent());
|
||||
Log.d(TAG, "onCreate");
|
||||
}
|
||||
|
||||
private void switchFragment(Class fragmentClass) {
|
||||
@ -123,8 +124,6 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
Log.d(TAG, "onDestroy");
|
||||
instance = null;
|
||||
currentFragment = null;
|
||||
}
|
||||
@ -208,6 +207,19 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
|
||||
}
|
||||
|
||||
int fragment = intent.getIntExtra(LAUNCH_FRAGMENT, FRAGMENT_NONE);
|
||||
|
||||
if (intent.getBooleanExtra(LAUNCH_NEED_RECREATE, false)) {
|
||||
finish();
|
||||
overridePendingTransition(R.anim.start, R.anim.end);
|
||||
if (fragment != FRAGMENT_NONE) {
|
||||
startActivity(new Intent(this, MainActivity.class)
|
||||
.putExtra(LAUNCH_FRAGMENT, fragment));
|
||||
} else {
|
||||
startActivity(new Intent(this, MainActivity.class));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
switch (fragment) {
|
||||
case FRAGMENT_ABOUT:
|
||||
switchFragment(AboutFragment.class);
|
||||
|
@ -1,5 +1,6 @@
|
||||
package org.itxtech.daedalus.fragment;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.*;
|
||||
@ -7,6 +8,7 @@ import android.support.design.widget.Snackbar;
|
||||
import android.view.View;
|
||||
import org.itxtech.daedalus.Daedalus;
|
||||
import org.itxtech.daedalus.R;
|
||||
import org.itxtech.daedalus.activity.MainActivity;
|
||||
import org.itxtech.daedalus.util.server.DNSServerHelper;
|
||||
|
||||
/**
|
||||
@ -81,6 +83,17 @@ public class GlobalConfigFragment extends PreferenceFragment {
|
||||
}
|
||||
});
|
||||
|
||||
SwitchPreference darkTheme = (SwitchPreference) findPreference("settings_dark_theme");
|
||||
darkTheme.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object o) {
|
||||
getActivity().startActivity(new Intent(Daedalus.getInstance(), MainActivity.class)
|
||||
.putExtra(MainActivity.LAUNCH_FRAGMENT, MainActivity.FRAGMENT_SETTINGS)
|
||||
.putExtra(MainActivity.LAUNCH_NEED_RECREATE, true));
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
|
||||
SwitchPreference advanced = (SwitchPreference) findPreference("settings_advanced_switch");
|
||||
advanced.setEnabled(false);
|
||||
|
7
app/src/main/res/anim/end.xml
Normal file
7
app/src/main/res/anim/end.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<alpha
|
||||
android:duration="300"
|
||||
android:fromAlpha="1.0"
|
||||
android:toAlpha="0.0"/>
|
||||
</set>
|
7
app/src/main/res/anim/start.xml
Normal file
7
app/src/main/res/anim/start.xml
Normal file
@ -0,0 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<set xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<alpha
|
||||
android:duration="300"
|
||||
android:fromAlpha="0.0"
|
||||
android:toAlpha="1.0"/>
|
||||
</set>
|
@ -86,4 +86,5 @@
|
||||
<string name="notice_check_dynamic_rule_reload">请在设置中勾选“允许动态更新规则”</string>
|
||||
<string name="notice_export_complete">导出完成。</string>
|
||||
<string name="notice_importing_rule">正在导入规则,请稍等。</string>
|
||||
<string name="settings_dark_theme">使用暗主题</string>
|
||||
</resources>
|
@ -86,4 +86,5 @@
|
||||
<string name="notice_check_dynamic_rule_reload">請在設定中開啟「允許動態規則重新載入」</string>
|
||||
<string name="notice_export_complete">导出完成。 TODO</string>
|
||||
<string name="notice_importing_rule">正在导入规则,请稍等。 TODO</string>
|
||||
<string name="settings_dark_theme">使用暗主题</string>
|
||||
</resources>
|
||||
|
@ -64,6 +64,7 @@
|
||||
<string name="settings_manual_summary">Visit GitHub wiki page.</string>
|
||||
<string name="settings_allow_dynamic_rule_reload">Allow dynamic rule reload</string>
|
||||
<string name="settings_debug_output">Debug output</string>
|
||||
<string name="settings_dark_theme">Use Dark Theme</string>
|
||||
|
||||
<string name="settings_rule_name">Rule Name</string>
|
||||
<string name="settings_rule_type">Rule Type</string>
|
||||
|
@ -35,6 +35,10 @@
|
||||
android:key="settings_notification"
|
||||
android:title="@string/settings_notification"
|
||||
android:defaultValue="true"/>
|
||||
<SwitchPreference
|
||||
android:key="settings_dark_theme"
|
||||
android:title="@string/settings_dark_theme"
|
||||
android:defaultValue="false"/>
|
||||
<EditTextPreference
|
||||
android:key="settings_log_size"
|
||||
android:selectAllOnFocus="false"
|
||||
|
Loading…
Reference in New Issue
Block a user