Add theme setting
This prepares that different themes can be added. Currently light and dark will just use the default OK theme.
This commit is contained in:
@@ -9,15 +9,15 @@
|
||||
===============
|
||||
- Last APG 1 version was 10900 (1.0.9 beta 00)
|
||||
- Keychain starting with versionCode 20000!
|
||||
|
||||
|
||||
Association of file types to Keychain
|
||||
=====================================
|
||||
General remarks about file ending conventions:
|
||||
- *.gpg,*.pgp for binary files
|
||||
- *.asc for ascii armored files The actual content can be anything.
|
||||
|
||||
|
||||
The file ending only shows if it is binary or ascii encoded.
|
||||
|
||||
|
||||
Remarks about the ugly android:pathPattern:
|
||||
- We are matching all files with a specific file ending.
|
||||
This is done in an ugly way because of Android limitations.
|
||||
@@ -73,7 +73,7 @@
|
||||
android:hardwareAccelerated="true"
|
||||
android:icon="@drawable/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:theme="@style/KeychainTheme">
|
||||
android:theme="@style/LightTheme">
|
||||
<activity
|
||||
android:name=".ui.MainActivity"
|
||||
android:configChanges="orientation|screenSize|keyboardHidden|keyboard"
|
||||
|
||||
@@ -103,6 +103,7 @@ public final class Constants {
|
||||
public static final String PROXY_HOST = "proxyHost";
|
||||
public static final String PROXY_PORT = "proxyPort";
|
||||
public static final String PROXY_TYPE = "proxyType";
|
||||
public static final String THEME = "theme";
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -53,6 +53,7 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
public static final String ACTION_PREFS_CLOUD = "org.sufficientlysecure.keychain.ui.PREFS_CLOUD";
|
||||
public static final String ACTION_PREFS_ADV = "org.sufficientlysecure.keychain.ui.PREFS_ADV";
|
||||
public static final String ACTION_PREFS_PROXY = "org.sufficientlysecure.keychain.ui.PREFS_PROXY";
|
||||
public static final String ACTION_PREFS_GUI = "org.sufficientlysecure.keychain.ui.PREFS_GUI";
|
||||
|
||||
public static final int REQUEST_CODE_KEYSERVER_PREF = 0x00007005;
|
||||
|
||||
@@ -106,6 +107,10 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
initializeUseNumKeypadForYubiKeyPin(
|
||||
(CheckBoxPreference) findPreference(Constants.Pref.USE_NUMKEYPAD_FOR_YUBIKEY_PIN));
|
||||
|
||||
} else if (action != null && action.equals(ACTION_PREFS_GUI)) {
|
||||
addPreferencesFromResource(R.xml.gui_preferences);
|
||||
|
||||
initializeTheme((ListPreference) findPreference(Constants.Pref.THEME));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -425,14 +430,30 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
mUseTor.setEnabled(true);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
||||
/**
|
||||
* This fragment shows gui preferences.
|
||||
*/
|
||||
public static class GuiPrefsFragment extends PreferenceFragment {
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
|
||||
// Load the preferences from an XML resource
|
||||
addPreferencesFromResource(R.xml.gui_preferences);
|
||||
|
||||
initializeTheme((ListPreference) findPreference(Constants.Pref.THEME));
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isValidFragment(String fragmentName) {
|
||||
return AdvancedPrefsFragment.class.getName().equals(fragmentName)
|
||||
|| CloudSearchPrefsFragment.class.getName().equals(fragmentName)
|
||||
|| ProxyPrefsFragment.class.getName().equals(fragmentName)
|
||||
|| GuiPrefsFragment.class.getName().equals(fragmentName)
|
||||
|| super.isValidFragment(fragmentName);
|
||||
}
|
||||
|
||||
@@ -461,6 +482,19 @@ public class SettingsActivity extends AppCompatPreferenceActivity {
|
||||
});
|
||||
}
|
||||
|
||||
private static void initializeTheme(final ListPreference mTheme) {
|
||||
mTheme.setValue(sPreferences.getTheme());
|
||||
mTheme.setSummary(mTheme.getEntry());
|
||||
mTheme.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
mTheme.setValue((String) newValue);
|
||||
mTheme.setSummary(mTheme.getEntry());
|
||||
sPreferences.setTheme((String) newValue);
|
||||
return false;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void initializeSearchKeyserver(final CheckBoxPreference mSearchKeyserver) {
|
||||
Preferences.CloudSearchPrefs prefs = sPreferences.getCloudSearchPrefs();
|
||||
mSearchKeyserver.setChecked(prefs.searchKeyserver);
|
||||
|
||||
@@ -22,6 +22,7 @@ import android.os.Bundle;
|
||||
import android.support.v7.app.ActionBar;
|
||||
import android.support.v7.app.AppCompatActivity;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.view.ContextThemeWrapper;
|
||||
import android.view.Gravity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
@@ -29,6 +30,7 @@ import android.view.ViewGroup;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.sufficientlysecure.keychain.R;
|
||||
import org.sufficientlysecure.keychain.util.Preferences;
|
||||
|
||||
/**
|
||||
* Setups Toolbar
|
||||
@@ -36,9 +38,19 @@ import org.sufficientlysecure.keychain.R;
|
||||
public abstract class BaseActivity extends AppCompatActivity {
|
||||
protected Toolbar mToolbar;
|
||||
protected View mStatusBar;
|
||||
private static Preferences sPreferences;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
sPreferences = Preferences.getPreferences(this);
|
||||
int themeId = R.style.LightTheme;
|
||||
if ("dark".equals(sPreferences.getTheme())) {
|
||||
themeId = R.style.DarkTheme;
|
||||
}
|
||||
|
||||
ContextThemeWrapper w = new ContextThemeWrapper(this, themeId);
|
||||
getTheme().setTo(w.getTheme());
|
||||
|
||||
super.onCreate(savedInstanceState);
|
||||
initLayout();
|
||||
initToolbar();
|
||||
|
||||
@@ -220,6 +220,15 @@ public class Preferences {
|
||||
return mSharedPreferences.getBoolean(Pref.TEXT_USE_COMPRESSION, true);
|
||||
}
|
||||
|
||||
public String getTheme() {
|
||||
return mSharedPreferences.getString(Pref.THEME, "light");
|
||||
}
|
||||
|
||||
public void setTheme(String value) {
|
||||
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
||||
editor.putString(Constants.Pref.THEME, value);
|
||||
editor.commit();
|
||||
}
|
||||
|
||||
public void setUseArmor(boolean useArmor) {
|
||||
SharedPreferences.Editor editor = mSharedPreferences.edit();
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<style name="KeychainTheme" parent="KeychainTheme.Base">
|
||||
<style name="LightTheme" parent="LightBaseTheme">
|
||||
<item name="android:windowTranslucentStatus">true</item>
|
||||
|
||||
<!-- enable window content transitions -->
|
||||
@@ -12,4 +12,17 @@
|
||||
<item name="android:windowSharedElementExitTransition">@android:transition/move</item>
|
||||
|
||||
</style>
|
||||
</resources>
|
||||
|
||||
<style name="DarkTheme" parent="DarkBaseTheme">
|
||||
<item name="android:windowTranslucentStatus">true</item>
|
||||
|
||||
<!-- enable window content transitions -->
|
||||
<item name="android:windowContentTransitions">true</item>
|
||||
<item name="android:windowAllowEnterTransitionOverlap">true</item>
|
||||
<item name="android:windowAllowReturnTransitionOverlap">true</item>
|
||||
<item name="android:windowSharedElementEnterTransition">@android:transition/move</item>
|
||||
<item name="android:windowSharedElementExitTransition">@android:transition/move</item>
|
||||
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
||||
@@ -61,4 +61,12 @@
|
||||
<item>@string/key_size_custom</item>
|
||||
</string-array>
|
||||
|
||||
<string-array name="theme_entries" translatable="false">
|
||||
<item>@string/theme_dark</item>
|
||||
<item>@string/theme_light</item>
|
||||
</string-array>
|
||||
<string-array name="theme_values" translatable="false">
|
||||
<item>"dark"</item>
|
||||
<item>"ligh"</item>
|
||||
</string-array>
|
||||
</resources>
|
||||
|
||||
@@ -50,6 +50,7 @@
|
||||
<string name="section_cloud_search">"Cloud search"</string>
|
||||
<string name="section_passphrase_cache">"Password/PIN Handling"</string>
|
||||
<string name="section_proxy_settings">"Proxy Settings"</string>
|
||||
<string name="section_gui">"Interface"</string>
|
||||
<string name="section_certify">"Confirm"</string>
|
||||
<string name="section_actions">"Actions"</string>
|
||||
<string name="section_share_key">"Key"</string>
|
||||
@@ -167,6 +168,7 @@
|
||||
<string name="label_verify_keyserver">"Verify keyserver"</string>
|
||||
<string name="label_enter_keyserver_url">"Enter keyserver URL"</string>
|
||||
<string name="label_keyserver_dialog_delete">"Delete keyserver"</string>
|
||||
<string name="label_theme">"Theme"</string>
|
||||
|
||||
<string name="pref_keyserver">"OpenPGP keyservers"</string>
|
||||
<string name="pref_keyserver_summary">"Search keys on selected OpenPGP keyservers (HKP protocol)"</string>
|
||||
@@ -245,6 +247,8 @@
|
||||
<string name="filemanager_title_open">"Open…"</string>
|
||||
<string name="error">"Error"</string>
|
||||
<string name="error_message">"Error: %s"</string>
|
||||
<string name="theme_dark">"Dark"</string>
|
||||
<string name="theme_light">"Light"</string>
|
||||
|
||||
<!-- key flags -->
|
||||
<string name="flag_certify">"Certify"</string>
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
|
||||
<style name="KeychainTheme" parent="KeychainTheme.Base" />
|
||||
|
||||
<style name="KeychainTheme.Base" parent="Theme.AppCompat.Light">
|
||||
<style name="LightBaseTheme" parent="Theme.AppCompat.Light">
|
||||
<item name="colorPrimary">@color/primary</item>
|
||||
<item name="colorPrimaryDark">@color/primary_dark</item>
|
||||
<item name="colorAccent">@color/accent</item>
|
||||
@@ -16,6 +14,25 @@
|
||||
<item name="searchViewStyle">@style/MySearchViewStyle</item>
|
||||
</style>
|
||||
|
||||
<style name="DarkBaseTheme" parent="Theme.AppCompat">
|
||||
<item name="colorPrimary">@color/primary</item>
|
||||
<item name="colorPrimaryDark">@color/primary_dark</item>
|
||||
<item name="colorAccent">@color/accent</item>
|
||||
|
||||
<!-- remove actionbar and title, we use toolbar! -->
|
||||
<item name="windowNoTitle">true</item>
|
||||
<item name="windowActionBar">false</item>
|
||||
<!-- multi selection should overlay Toolbar! http://stackoverflow.com/a/26450875 -->
|
||||
<item name="windowActionModeOverlay">true</item>
|
||||
<item name="searchViewStyle">@style/MySearchViewStyle</item>
|
||||
</style>
|
||||
|
||||
<style name="LightTheme" parent="LightBaseTheme">
|
||||
</style>
|
||||
|
||||
<style name="DarkTheme" parent="DarkBaseTheme">
|
||||
</style>
|
||||
|
||||
<!-- http://android-developers.blogspot.de/2014/10/appcompat-v21-material-design-for-pre.html -->
|
||||
<style name="MySearchViewStyle" parent="Widget.AppCompat.SearchView">
|
||||
<!-- Background for the search query section (e.g. EditText) -->
|
||||
@@ -40,4 +57,4 @@
|
||||
<item name="windowActionBar">false</item>
|
||||
<item name="windowNoTitle">true</item>
|
||||
</style>
|
||||
</resources>
|
||||
</resources>
|
||||
|
||||
10
OpenKeychain/src/main/res/xml/gui_preferences.xml
Normal file
10
OpenKeychain/src/main/res/xml/gui_preferences.xml
Normal file
@@ -0,0 +1,10 @@
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<ListPreference
|
||||
android:persistent="false"
|
||||
android:key="theme"
|
||||
android:title="@string/label_theme"
|
||||
android:entries="@array/theme_entries"
|
||||
android:entryValues="@array/theme_values"
|
||||
android:dialogTitle="@string/label_theme" />
|
||||
|
||||
</PreferenceScreen>
|
||||
@@ -1,4 +1,7 @@
|
||||
<preference-headers xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<header
|
||||
android:fragment="org.sufficientlysecure.keychain.ui.SettingsActivity$GuiPrefsFragment"
|
||||
android:title="@string/section_gui" />
|
||||
<header
|
||||
android:fragment="org.sufficientlysecure.keychain.ui.SettingsActivity$CloudSearchPrefsFragment"
|
||||
android:title="@string/section_cloud_search" />
|
||||
|
||||
Reference in New Issue
Block a user