diff options
Diffstat (limited to 'OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui')
28 files changed, 298 insertions, 121 deletions
diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java index 65baf0593..5ca7c6bc7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/CertifyKeyFragment.java @@ -53,6 +53,7 @@ import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.ui.adapter.MultiUserIdsAdapter; import org.sufficientlysecure.keychain.ui.base.CachingCryptoOperationFragment; import org.sufficientlysecure.keychain.ui.util.Notify; +import org.sufficientlysecure.keychain.ui.util.FormattingUtils; import org.sufficientlysecure.keychain.ui.widget.CertifyKeySpinner; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Preferences; @@ -154,7 +155,7 @@ public class CertifyKeyFragment // make certify image gray, like action icons ImageView vActionCertifyImage = (ImageView) view.findViewById(R.id.certify_key_action_certify_image); - vActionCertifyImage.setColorFilter(getResources().getColor(R.color.tertiary_text_light), + vActionCertifyImage.setColorFilter(FormattingUtils.getColorFromAttr(getActivity(), R.attr.colorTertiaryText), PorterDuff.Mode.SRC_IN); View vCertifyButton = view.findViewById(R.id.certify_key_certify_button); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java index 4c1dbd1ee..b22053df1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/DeleteKeyDialogActivity.java @@ -49,6 +49,7 @@ import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder; import org.sufficientlysecure.keychain.ui.util.Notify; +import org.sufficientlysecure.keychain.ui.util.ThemeChanger; import org.sufficientlysecure.keychain.util.Log; import java.util.Date; @@ -254,8 +255,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity { final long[] masterKeyIds = getArguments().getLongArray(ARG_DELETE_MASTER_KEY_IDS); final boolean hasSecret = getArguments().getBoolean(ARG_HAS_SECRET); - ContextThemeWrapper theme = new ContextThemeWrapper(activity, - R.style.Theme_AppCompat_Light_Dialog); + ContextThemeWrapper theme = ThemeChanger.getDialogThemeWrapper(activity); CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(theme); @@ -351,10 +351,7 @@ public class DeleteKeyDialogActivity extends FragmentActivity { final String CHOICE_REVOKE = getString(R.string.del_rev_dialog_choice_rev_upload); final String CHOICE_DELETE = getString(R.string.del_rev_dialog_choice_delete); - // if the dialog is displayed from the application class, design is missing - // hack to get holo design (which is not automatically applied due to activity's Theme.NoDisplay - ContextThemeWrapper theme = new ContextThemeWrapper(activity, - R.style.Theme_AppCompat_Light_Dialog); + ContextThemeWrapper theme = ThemeChanger.getDialogThemeWrapper(activity); CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(theme); builder.setTitle(getString(R.string.del_rev_dialog_title, diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/HelpMarkdownFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/HelpMarkdownFragment.java index 97d39feb1..24da13983 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/HelpMarkdownFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/HelpMarkdownFragment.java @@ -78,6 +78,7 @@ public class HelpMarkdownFragment extends Fragment { Log.e(Constants.TAG, "IOException", e); } + text.setBackgroundColor(getResources().getColor(android.R.color.white)); // no flickering when clicking textview for Android < 4 text.setTextColor(getResources().getColor(android.R.color.black)); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java index 95e047b0f..0488d8235 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -68,6 +68,7 @@ import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.ui.adapter.KeyAdapter; import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; +import org.sufficientlysecure.keychain.ui.util.FormattingUtils; import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify.Style; import org.sufficientlysecure.keychain.util.FabContainer; @@ -675,8 +676,11 @@ public class KeyListFragment extends LoaderFragment private HashMap<Integer, Boolean> mSelection = new HashMap<>(); + private Context mContext; + public KeyListAdapter(Context context, Cursor c, int flags) { super(context, c, flags); + mContext = context; } @Override @@ -705,9 +709,11 @@ public class KeyListFragment extends LoaderFragment // let the adapter handle setting up the row views View v = super.getView(position, convertView, parent); + int colorEmphasis = FormattingUtils.getColorFromAttr(mContext, R.attr.colorEmphasis); + if (mSelection.get(position) != null) { // selected position color - v.setBackgroundColor(parent.getResources().getColor(R.color.emphasis)); + v.setBackgroundColor(colorEmphasis); } else { // default color v.setBackgroundColor(Color.TRANSPARENT); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java index 3c8fbf8c9..1cd1a3099 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/LogDisplayFragment.java @@ -43,6 +43,7 @@ import org.sufficientlysecure.keychain.operations.results.OperationResult; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogEntryParcel; import org.sufficientlysecure.keychain.operations.results.OperationResult.LogLevel; import org.sufficientlysecure.keychain.operations.results.OperationResult.SubLogEntryParcel; +import org.sufficientlysecure.keychain.ui.util.FormattingUtils; import org.sufficientlysecure.keychain.util.FileHelper; import org.sufficientlysecure.keychain.util.Log; @@ -57,10 +58,12 @@ public class LogDisplayFragment extends ListFragment implements OnItemClickListe OperationResult mResult; public static final String EXTRA_RESULT = "log"; + protected int mTextColor; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + mTextColor = FormattingUtils.getColorFromAttr(getActivity(), R.attr.colorText); setHasOptionsMenu(true); } @@ -357,13 +360,13 @@ public class LogDisplayFragment extends ListFragment implements OnItemClickListe ih.mSecondText.setText(getResources().getString(subEntry.mType.getMsgId(), subEntry.mParameters)); } - ih.mSecondText.setTextColor(subEntry.mType.mLevel == LogLevel.DEBUG ? Color.GRAY : Color.BLACK); + ih.mSecondText.setTextColor(subEntry.mType.mLevel == LogLevel.DEBUG ? Color.GRAY : mTextColor); switch (subEntry.mType.mLevel) { case DEBUG: ih.mSecondImg.setBackgroundColor(Color.GRAY); break; - case INFO: ih.mSecondImg.setBackgroundColor(Color.BLACK); break; + case INFO: ih.mSecondImg.setBackgroundColor(mTextColor); break; case WARN: ih.mSecondImg.setBackgroundColor(getResources().getColor(R.color.android_orange_light)); break; case ERROR: ih.mSecondImg.setBackgroundColor(getResources().getColor(R.color.android_red_light)); break; - case START: ih.mSecondImg.setBackgroundColor(Color.BLACK); break; + case START: ih.mSecondImg.setBackgroundColor(mTextColor); break; case OK: ih.mSecondImg.setBackgroundColor(getResources().getColor(R.color.android_green_light)); break; case CANCELLED: ih.mSecondImg.setBackgroundColor(getResources().getColor(R.color.android_red_light)); break; } @@ -388,13 +391,13 @@ public class LogDisplayFragment extends ListFragment implements OnItemClickListe entry.mParameters)); } convertView.setPadding((entry.mIndent) * dipFactor, 0, 0, 0); - ih.mText.setTextColor(entry.mType.mLevel == LogLevel.DEBUG ? Color.GRAY : Color.BLACK); + ih.mText.setTextColor(entry.mType.mLevel == LogLevel.DEBUG ? Color.GRAY : mTextColor); switch (entry.mType.mLevel) { case DEBUG: ih.mImg.setBackgroundColor(Color.GRAY); break; - case INFO: ih.mImg.setBackgroundColor(Color.BLACK); break; + case INFO: ih.mImg.setBackgroundColor(mTextColor); break; case WARN: ih.mImg.setBackgroundColor(getResources().getColor(R.color.android_orange_light)); break; case ERROR: ih.mImg.setBackgroundColor(getResources().getColor(R.color.android_red_light)); break; - case START: ih.mImg.setBackgroundColor(Color.BLACK); break; + case START: ih.mImg.setBackgroundColor(mTextColor); break; case OK: ih.mImg.setBackgroundColor(getResources().getColor(R.color.android_green_light)); break; case CANCELLED: ih.mImg.setBackgroundColor(getResources().getColor(R.color.android_red_light)); break; } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java index d00c8f367..6f5d98afd 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/MainActivity.java @@ -33,6 +33,7 @@ import com.mikepenz.community_material_typeface_library.CommunityMaterial; import com.mikepenz.google_material_typeface_library.GoogleMaterial; import com.mikepenz.iconics.typeface.FontAwesome; import com.mikepenz.materialdrawer.Drawer; +import com.mikepenz.materialdrawer.DrawerBuilder; import com.mikepenz.materialdrawer.model.PrimaryDrawerItem; import com.mikepenz.materialdrawer.model.interfaces.IDrawerItem; @@ -56,7 +57,7 @@ public class MainActivity extends BaseNfcActivity implements FabContainer, OnBac public static final String EXTRA_SKIP_FIRST_TIME = "skip_first_time"; public static final String EXTRA_INIT_FRAG = "init_frag"; - public Drawer.Result mDrawerResult; + public Drawer mDrawer; private Toolbar mToolbar; @Override @@ -68,7 +69,7 @@ public class MainActivity extends BaseNfcActivity implements FabContainer, OnBac mToolbar.setTitle(R.string.app_name); setSupportActionBar(mToolbar); - mDrawerResult = new Drawer() + mDrawer = new DrawerBuilder() .withActivity(this) .withHeader(R.layout.main_drawer_header) .withToolbar(mToolbar) @@ -89,7 +90,7 @@ public class MainActivity extends BaseNfcActivity implements FabContainer, OnBac ) .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() { @Override - public void onItemClick(AdapterView<?> parent, View view, int position, long id, IDrawerItem drawerItem) { + public boolean onItemClick(AdapterView<?> parent, View view, int position, long id, IDrawerItem drawerItem) { if (drawerItem != null) { Intent intent = null; switch(drawerItem.getIdentifier()) { @@ -116,6 +117,8 @@ public class MainActivity extends BaseNfcActivity implements FabContainer, OnBac MainActivity.this.startActivity(intent); } } + + return false; } }) .withSelectedItem(-1) @@ -179,28 +182,28 @@ public class MainActivity extends BaseNfcActivity implements FabContainer, OnBac private void onKeysSelected() { mToolbar.setTitle(R.string.app_name); - mDrawerResult.setSelectionByIdentifier(ID_KEYS, false); + mDrawer.setSelectionByIdentifier(ID_KEYS, false); Fragment frag = new KeyListFragment(); setFragment(frag, false); } private void onEnDecryptSelected() { mToolbar.setTitle(R.string.nav_encrypt_decrypt); - mDrawerResult.setSelectionByIdentifier(ID_ENCRYPT_DECRYPT, false); + mDrawer.setSelectionByIdentifier(ID_ENCRYPT_DECRYPT, false); Fragment frag = new EncryptDecryptOverviewFragment(); setFragment(frag, true); } private void onAppsSelected() { mToolbar.setTitle(R.string.nav_apps); - mDrawerResult.setSelectionByIdentifier(ID_APPS, false); + mDrawer.setSelectionByIdentifier(ID_APPS, false); Fragment frag = new AppsListFragment(); setFragment(frag, true); } private void onBackupSelected() { mToolbar.setTitle(R.string.nav_backup); - mDrawerResult.setSelectionByIdentifier(ID_APPS, false); + mDrawer.setSelectionByIdentifier(ID_APPS, false); Fragment frag = new BackupFragment(); setFragment(frag, true); } @@ -208,15 +211,15 @@ public class MainActivity extends BaseNfcActivity implements FabContainer, OnBac @Override protected void onSaveInstanceState(Bundle outState) { // add the values which need to be saved from the drawer to the bundle - outState = mDrawerResult.saveInstanceState(outState); + outState = mDrawer.saveInstanceState(outState); super.onSaveInstanceState(outState); } @Override public void onBackPressed() { // close the drawer first and if the drawer is closed do regular backstack handling - if (mDrawerResult != null && mDrawerResult.isDrawerOpen()) { - mDrawerResult.closeDrawer(); + if (mDrawer != null && mDrawer.isDrawerOpen()) { + mDrawer.closeDrawer(); } else { super.onBackPressed(); } @@ -255,16 +258,16 @@ public class MainActivity extends BaseNfcActivity implements FabContainer, OnBac // make sure the selected icon is the one shown at this point if (frag instanceof KeyListFragment) { mToolbar.setTitle(R.string.app_name); - mDrawerResult.setSelection(mDrawerResult.getPositionFromIdentifier(ID_KEYS), false); + mDrawer.setSelection(mDrawer.getPositionFromIdentifier(ID_KEYS), false); } else if (frag instanceof EncryptDecryptOverviewFragment) { mToolbar.setTitle(R.string.nav_encrypt_decrypt); - mDrawerResult.setSelection(mDrawerResult.getPositionFromIdentifier(ID_ENCRYPT_DECRYPT), false); + mDrawer.setSelection(mDrawer.getPositionFromIdentifier(ID_ENCRYPT_DECRYPT), false); } else if (frag instanceof AppsListFragment) { mToolbar.setTitle(R.string.nav_apps); - mDrawerResult.setSelection(mDrawerResult.getPositionFromIdentifier(ID_APPS), false); + mDrawer.setSelection(mDrawer.getPositionFromIdentifier(ID_APPS), false); } else if (frag instanceof BackupFragment) { mToolbar.setTitle(R.string.nav_backup); - mDrawerResult.setSelection(mDrawerResult.getPositionFromIdentifier(ID_BACKUP), false); + mDrawer.setSelection(mDrawer.getPositionFromIdentifier(ID_BACKUP), false); } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java index 8b482584d..d7224bd04 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/PassphraseDialogActivity.java @@ -59,6 +59,7 @@ import org.sufficientlysecure.keychain.service.PassphraseCacheService; import org.sufficientlysecure.keychain.service.input.CryptoInputParcel; import org.sufficientlysecure.keychain.service.input.RequiredInputParcel; import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder; +import org.sufficientlysecure.keychain.ui.util.ThemeChanger; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Passphrase; import org.sufficientlysecure.keychain.util.Preferences; @@ -196,10 +197,7 @@ public class PassphraseDialogActivity extends FragmentActivity { public Dialog onCreateDialog(Bundle savedInstanceState) { final Activity activity = getActivity(); - // if the dialog is displayed from the application class, design is missing - // hack to get holo design (which is not automatically applied due to activity's Theme.NoDisplay - ContextThemeWrapper theme = new ContextThemeWrapper(activity, - R.style.Theme_AppCompat_Light_Dialog); + ContextThemeWrapper theme = ThemeChanger.getDialogThemeWrapper(activity); mSubKeyId = getArguments().getLong(EXTRA_SUBKEY_ID); mServiceIntent = getArguments().getParcelable(EXTRA_SERVICE_INTENT); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/RetryUploadDialogActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/RetryUploadDialogActivity.java index 85f2096db..2a00e8b70 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/RetryUploadDialogActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/RetryUploadDialogActivity.java @@ -29,6 +29,7 @@ import android.support.v4.app.FragmentActivity; import android.view.ContextThemeWrapper; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.ui.util.ThemeChanger; import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder; public class RetryUploadDialogActivity extends FragmentActivity { @@ -54,8 +55,7 @@ public class RetryUploadDialogActivity extends FragmentActivity { @Override public Dialog onCreateDialog(Bundle savedInstanceState) { - ContextThemeWrapper theme = new ContextThemeWrapper(getActivity(), - R.style.Theme_AppCompat_Light_Dialog); + ContextThemeWrapper theme = ThemeChanger.getDialogThemeWrapper(getActivity()); CustomAlertDialogBuilder dialogBuilder = new CustomAlertDialogBuilder(theme); dialogBuilder.setTitle(R.string.retry_up_dialog_title); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java index d15cea5a4..534dbfd05 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SafeSlingerActivity.java @@ -37,6 +37,7 @@ import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.service.ImportKeyringParcel; import org.sufficientlysecure.keychain.ui.base.BaseActivity; import org.sufficientlysecure.keychain.ui.base.CryptoOperationHelper; +import org.sufficientlysecure.keychain.ui.util.FormattingUtils; import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.ParcelableFileCache; @@ -81,7 +82,7 @@ public class SafeSlingerActivity extends BaseActivity }); ImageView buttonIcon = (ImageView) findViewById(R.id.safe_slinger_button_image); - buttonIcon.setColorFilter(getResources().getColor(R.color.tertiary_text_light), + buttonIcon.setColorFilter(FormattingUtils.getColorFromAttr(this, R.attr.colorTertiaryText), PorterDuff.Mode.SRC_IN); View button = findViewById(R.id.safe_slinger_button); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java index bcf42ba74..2fe868b8b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/SettingsActivity.java @@ -41,6 +41,7 @@ import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.compatibility.AppCompatPreferenceActivity; import org.sufficientlysecure.keychain.ui.util.Notify; +import org.sufficientlysecure.keychain.ui.util.ThemeChanger; import org.sufficientlysecure.keychain.ui.widget.IntegerListPreference; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.Preferences; @@ -53,15 +54,20 @@ 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; private PreferenceScreen mKeyServerPreference = null; private static Preferences sPreferences; + private ThemeChanger mThemeChanger; @Override protected void onCreate(Bundle savedInstanceState) { sPreferences = Preferences.getPreferences(this); + + mThemeChanger = new ThemeChanger(this); + mThemeChanger.changeTheme(); super.onCreate(savedInstanceState); setupToolbar(); @@ -106,6 +112,21 @@ 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)); + } + } + + @Override + protected void onResume() { + super.onResume(); + + if (mThemeChanger.changeTheme()) { + Intent intent = getIntent(); + finish(); + startActivity(intent); } } @@ -425,14 +446,30 @@ public class SettingsActivity extends AppCompatPreferenceActivity { mUseTor.setEnabled(true); } } + } + + /** + * 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)); + } } - @TargetApi(Build.VERSION_CODES.KITKAT) 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 +498,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); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java index 938dbc9f2..1d0e085da 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyActivity.java @@ -691,6 +691,25 @@ public class ViewKeyActivity extends BaseNfcActivity implements int mPreviousColor = 0; + /** + * Calculate a reasonable color for the status bar based on the given toolbar color. + * Style guides want the toolbar color to be a "700" on the Android scale and the status + * bar should be the same color at "500", this is roughly 17 / 20th of the value in each + * channel. + * http://www.google.com/design/spec/style/color.html#color-color-palette + */ + static public int getStatusBarBackgroundColor(int color) { + int r = (color >> 16) & 0xff; + int g = (color >> 8) & 0xff; + int b = color & 0xff; + + r = r * 17 / 20; + g = g * 17 / 20; + b = b * 17 / 20; + + return (0xff << 24) | (r << 16) | (g << 8) | b; + } + @Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { /* TODO better error handling? May cause problems when a key is deleted, @@ -760,7 +779,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements mStatusImage.setVisibility(View.VISIBLE); KeyFormattingUtils.setStatusImage(this, mStatusImage, mStatusText, State.REVOKED, R.color.icons, true); - color = getResources().getColor(R.color.android_red_light); + color = getResources().getColor(R.color.key_flag_red); mActionEncryptFile.setVisibility(View.GONE); mActionEncryptText.setVisibility(View.GONE); @@ -776,7 +795,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements mStatusImage.setVisibility(View.VISIBLE); KeyFormattingUtils.setStatusImage(this, mStatusImage, mStatusText, State.EXPIRED, R.color.icons, true); - color = getResources().getColor(R.color.android_red_light); + color = getResources().getColor(R.color.key_flag_red); mActionEncryptFile.setVisibility(View.GONE); mActionEncryptText.setVisibility(View.GONE); @@ -786,7 +805,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements } else if (mIsSecret) { mStatusText.setText(R.string.view_key_my_key); mStatusImage.setVisibility(View.GONE); - color = getResources().getColor(R.color.primary); + color = getResources().getColor(R.color.key_flag_green); // reload qr code only if the fingerprint changed if (!mFingerprint.equals(mQrCodeLoaded)) { loadQrCode(mFingerprint); @@ -837,7 +856,7 @@ public class ViewKeyActivity extends BaseNfcActivity implements mStatusImage.setVisibility(View.VISIBLE); KeyFormattingUtils.setStatusImage(this, mStatusImage, mStatusText, State.VERIFIED, R.color.icons, true); - color = getResources().getColor(R.color.primary); + color = getResources().getColor(R.color.key_flag_green); photoTask.execute(mMasterKeyId); mFab.setVisibility(View.GONE); @@ -846,20 +865,21 @@ public class ViewKeyActivity extends BaseNfcActivity implements mStatusImage.setVisibility(View.VISIBLE); KeyFormattingUtils.setStatusImage(this, mStatusImage, mStatusText, State.UNVERIFIED, R.color.icons, true); - color = getResources().getColor(R.color.android_orange_light); + color = getResources().getColor(R.color.key_flag_orange); mFab.setVisibility(View.VISIBLE); } } if (mPreviousColor == 0 || mPreviousColor == color) { - mStatusBar.setBackgroundColor(color); + mStatusBar.setBackgroundColor(getStatusBarBackgroundColor(color)); mBigToolbar.setBackgroundColor(color); mPreviousColor = color; } else { ObjectAnimator colorFade1 = ObjectAnimator.ofObject(mStatusBar, "backgroundColor", - new ArgbEvaluator(), mPreviousColor, color); + new ArgbEvaluator(), mPreviousColor, + getStatusBarBackgroundColor(color)); ObjectAnimator colorFade2 = ObjectAnimator.ofObject(mBigToolbar, "backgroundColor", new ArgbEvaluator(), mPreviousColor, color); @@ -943,4 +963,4 @@ public class ViewKeyActivity extends BaseNfcActivity implements public boolean onCryptoSetProgress(String msg, int progress, int max) { return true; } -}
\ No newline at end of file +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java index 6669f2654..673092e61 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvActivity.java @@ -211,18 +211,18 @@ public class ViewKeyAdvActivity extends BaseActivity implements // Note: order is important int color; if (isRevoked || isExpired) { - color = getResources().getColor(R.color.android_red_light); + color = getResources().getColor(R.color.key_flag_red); } else if (isSecret) { - color = getResources().getColor(R.color.primary); + color = getResources().getColor(R.color.android_green_light); } else { if (isVerified) { - color = getResources().getColor(R.color.primary); + color = getResources().getColor(R.color.android_green_light); } else { - color = getResources().getColor(R.color.android_orange_light); + color = getResources().getColor(R.color.key_flag_orange); } } mToolbar.setBackgroundColor(color); - mStatusBar.setBackgroundColor(color); + mStatusBar.setBackgroundColor(ViewKeyActivity.getStatusBarBackgroundColor(color)); mSlidingTabLayout.setBackgroundColor(color); break; diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java index 65f70ec14..4a46896bc 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/ViewKeyAdvShareFragment.java @@ -58,6 +58,7 @@ import org.sufficientlysecure.keychain.provider.KeychainContract; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.provider.ProviderHelper; import org.sufficientlysecure.keychain.provider.TemporaryStorageProvider; +import org.sufficientlysecure.keychain.ui.util.FormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.Notify; import org.sufficientlysecure.keychain.ui.util.Notify.Style; @@ -111,7 +112,7 @@ public class ViewKeyAdvShareFragment extends LoaderFragment implements View vKeyClipboardButton = view.findViewById(R.id.view_key_action_key_clipboard); ImageButton vKeySafeSlingerButton = (ImageButton) view.findViewById(R.id.view_key_action_key_safeslinger); View vKeyUploadButton = view.findViewById(R.id.view_key_action_upload); - vKeySafeSlingerButton.setColorFilter(getResources().getColor(R.color.tertiary_text_light), + vKeySafeSlingerButton.setColorFilter(FormattingUtils.getColorFromAttr(getActivity(), R.attr.colorTertiaryText), PorterDuff.Mode.SRC_IN); vFingerprintShareButton.setOnClickListener(new View.OnClickListener() { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java index 93c6593ab..0be7e8f76 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/ImportKeysAdapter.java @@ -177,9 +177,9 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> { } if (entry.isRevoked()) { - KeyFormattingUtils.setStatusImage(getContext(), holder.status, null, State.REVOKED, R.color.bg_gray); + KeyFormattingUtils.setStatusImage(getContext(), holder.status, null, State.REVOKED, R.color.key_flag_gray); } else if (entry.isExpired()) { - KeyFormattingUtils.setStatusImage(getContext(), holder.status, null, State.EXPIRED, R.color.bg_gray); + KeyFormattingUtils.setStatusImage(getContext(), holder.status, null, State.EXPIRED, R.color.key_flag_gray); } if (entry.isRevoked() || entry.isExpired()) { @@ -188,9 +188,9 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> { // no more space for algorithm display holder.algorithm.setVisibility(View.GONE); - holder.mainUserId.setTextColor(getContext().getResources().getColor(R.color.bg_gray)); - holder.mainUserIdRest.setTextColor(getContext().getResources().getColor(R.color.bg_gray)); - holder.keyId.setTextColor(getContext().getResources().getColor(R.color.bg_gray)); + holder.mainUserId.setTextColor(getContext().getResources().getColor(R.color.key_flag_gray)); + holder.mainUserIdRest.setTextColor(getContext().getResources().getColor(R.color.key_flag_gray)); + holder.keyId.setTextColor(getContext().getResources().getColor(R.color.key_flag_gray)); } else { holder.status.setVisibility(View.GONE); holder.algorithm.setVisibility(View.VISIBLE); @@ -198,11 +198,11 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> { if (entry.isSecretKey()) { holder.mainUserId.setTextColor(Color.RED); } else { - holder.mainUserId.setTextColor(Color.BLACK); + holder.mainUserId.setTextColor(FormattingUtils.getColorFromAttr(mActivity, R.attr.colorText)); } - holder.mainUserIdRest.setTextColor(Color.BLACK); - holder.keyId.setTextColor(Color.BLACK); + holder.mainUserIdRest.setTextColor(FormattingUtils.getColorFromAttr(mActivity, R.attr.colorText)); + holder.keyId.setTextColor(FormattingUtils.getColorFromAttr(mActivity, R.attr.colorText)); } if (entry.getUserIds().size() == 1) { @@ -242,9 +242,9 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> { uidView.setPadding(0, 0, FormattingUtils.dpToPx(getContext(), 8), 0); if (entry.isRevoked() || entry.isExpired()) { - uidView.setTextColor(getContext().getResources().getColor(R.color.bg_gray)); + uidView.setTextColor(getContext().getResources().getColor(R.color.key_flag_gray)); } else { - uidView.setTextColor(getContext().getResources().getColor(R.color.black)); + uidView.setTextColor(FormattingUtils.getColorFromAttr(getContext(), R.attr.colorText)); } holder.userIdsList.addView(uidView); @@ -258,9 +258,9 @@ public class ImportKeysAdapter extends ArrayAdapter<ImportKeysListEntry> { emailView.setText(highlighter.highlight(email)); if (entry.isRevoked() || entry.isExpired()) { - emailView.setTextColor(getContext().getResources().getColor(R.color.bg_gray)); + emailView.setTextColor(getContext().getResources().getColor(R.color.key_flag_gray)); } else { - emailView.setTextColor(getContext().getResources().getColor(R.color.black)); + emailView.setTextColor(FormattingUtils.getColorFromAttr(getContext(), R.attr.colorText)); } holder.userIdsList.addView(emailView); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/KeyAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/KeyAdapter.java index fbab1959a..aba1eb0d8 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/KeyAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/KeyAdapter.java @@ -42,6 +42,7 @@ import org.sufficientlysecure.keychain.pgp.CanonicalizedPublicKeyRing; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.provider.KeychainContract.KeyRings; import org.sufficientlysecure.keychain.ui.util.Highlighter; +import org.sufficientlysecure.keychain.ui.util.FormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils; import org.sufficientlysecure.keychain.ui.util.KeyFormattingUtils.State; @@ -49,6 +50,7 @@ public class KeyAdapter extends CursorAdapter { protected String mQuery; protected LayoutInflater mInflater; + protected Context mContext; // These are the rows that we will retrieve. public static final String[] PROJECTION = new String[]{ @@ -77,6 +79,7 @@ public class KeyAdapter extends CursorAdapter { public KeyAdapter(Context context, Cursor c, int flags) { super(context, c, flags); + mContext = context; mInflater = LayoutInflater.from(context); } @@ -138,26 +141,26 @@ public class KeyAdapter extends CursorAdapter { // Note: order is important! if (item.mIsRevoked) { KeyFormattingUtils - .setStatusImage(context, mStatus, null, State.REVOKED, R.color.bg_gray); + .setStatusImage(context, mStatus, null, State.REVOKED, R.color.key_flag_gray); mStatus.setVisibility(View.VISIBLE); mSlinger.setVisibility(View.GONE); - textColor = R.color.bg_gray; + textColor = context.getResources().getColor(R.color.key_flag_gray); } else if (item.mIsExpired) { - KeyFormattingUtils.setStatusImage(context, mStatus, null, State.EXPIRED, R.color.bg_gray); + KeyFormattingUtils.setStatusImage(context, mStatus, null, State.EXPIRED, R.color.key_flag_gray); mStatus.setVisibility(View.VISIBLE); mSlinger.setVisibility(View.GONE); - textColor = R.color.bg_gray; + textColor = context.getResources().getColor(R.color.key_flag_gray); } else if (item.mIsSecret) { mStatus.setVisibility(View.GONE); if (mSlingerButton.hasOnClickListeners()) { mSlingerButton.setColorFilter( - context.getResources().getColor(R.color.tertiary_text_light), + FormattingUtils.getColorFromAttr(context, R.attr.colorTertiaryText), PorterDuff.Mode.SRC_IN); mSlinger.setVisibility(View.VISIBLE); } else { mSlinger.setVisibility(View.GONE); } - textColor = R.color.black; + textColor = FormattingUtils.getColorFromAttr(context, R.attr.colorText); } else { // this is a public key - show if it's verified if (item.mIsVerified) { @@ -168,15 +171,15 @@ public class KeyAdapter extends CursorAdapter { mStatus.setVisibility(View.VISIBLE); } mSlinger.setVisibility(View.GONE); - textColor = R.color.black; + textColor = FormattingUtils.getColorFromAttr(context, R.attr.colorText); } if (!enabled) { - textColor = R.color.bg_gray; + textColor = context.getResources().getColor(R.color.key_flag_gray); } - mMainUserId.setTextColor(context.getResources().getColor(textColor)); - mMainUserIdRest.setTextColor(context.getResources().getColor(textColor)); + mMainUserId.setTextColor(textColor); + mMainUserIdRest.setTextColor(textColor); if (item.mHasDuplicate) { String dateTime = DateUtils.formatDateTime(context, @@ -187,7 +190,7 @@ public class KeyAdapter extends CursorAdapter { mCreationDate.setText(context.getString(R.string.label_key_created, dateTime)); - mCreationDate.setTextColor(context.getResources().getColor(textColor)); + mCreationDate.setTextColor(textColor); mCreationDate.setVisibility(View.VISIBLE); } else { mCreationDate.setVisibility(View.GONE); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SelectKeyCursorAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SelectKeyCursorAdapter.java index a6cb52977..4ea651bb5 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SelectKeyCursorAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SelectKeyCursorAdapter.java @@ -149,11 +149,11 @@ abstract public class SelectKeyCursorAdapter extends CursorAdapter { boolean enabled; if (cursor.getInt(mIndexIsRevoked) != 0) { h.statusIcon.setVisibility(View.VISIBLE); - KeyFormattingUtils.setStatusImage(mContext, h.statusIcon, null, State.REVOKED, R.color.bg_gray); + KeyFormattingUtils.setStatusImage(mContext, h.statusIcon, null, State.REVOKED, R.color.key_flag_gray); enabled = false; } else if (cursor.getInt(mIndexIsExpiry) != 0) { h.statusIcon.setVisibility(View.VISIBLE); - KeyFormattingUtils.setStatusImage(mContext, h.statusIcon, null, State.EXPIRED, R.color.bg_gray); + KeyFormattingUtils.setStatusImage(mContext, h.statusIcon, null, State.EXPIRED, R.color.key_flag_gray); enabled = false; } else { h.statusIcon.setVisibility(View.GONE); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SubkeysAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SubkeysAdapter.java index 87539ea05..24f5f04a1 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SubkeysAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/SubkeysAdapter.java @@ -284,27 +284,27 @@ public class SubkeysAdapter extends CursorAdapter { vStatus.setVisibility(View.VISIBLE); vCertifyIcon.setColorFilter( - mContext.getResources().getColor(R.color.bg_gray), + mContext.getResources().getColor(R.color.key_flag_gray), PorterDuff.Mode.SRC_IN); vSignIcon.setColorFilter( - mContext.getResources().getColor(R.color.bg_gray), + mContext.getResources().getColor(R.color.key_flag_gray), PorterDuff.Mode.SRC_IN); vEncryptIcon.setColorFilter( - mContext.getResources().getColor(R.color.bg_gray), + mContext.getResources().getColor(R.color.key_flag_gray), PorterDuff.Mode.SRC_IN); vAuthenticateIcon.setColorFilter( - mContext.getResources().getColor(R.color.bg_gray), + mContext.getResources().getColor(R.color.key_flag_gray), PorterDuff.Mode.SRC_IN); if (isRevoked) { vStatus.setImageResource(R.drawable.status_signature_revoked_cutout_24dp); vStatus.setColorFilter( - mContext.getResources().getColor(R.color.bg_gray), + mContext.getResources().getColor(R.color.key_flag_gray), PorterDuff.Mode.SRC_IN); } else if (isExpired) { vStatus.setImageResource(R.drawable.status_signature_expired_cutout_24dp); vStatus.setColorFilter( - mContext.getResources().getColor(R.color.bg_gray), + mContext.getResources().getColor(R.color.key_flag_gray), PorterDuff.Mode.SRC_IN); } } else { diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java index d1103ac1f..e2c6b0928 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/adapter/UserIdsAdapter.java @@ -128,7 +128,7 @@ public class UserIdsAdapter extends UserAttributesAdapter { if (isRevoked) { // set revocation icon (can this even be primary?) - KeyFormattingUtils.setStatusImage(mContext, vVerified, null, State.REVOKED, R.color.bg_gray); + KeyFormattingUtils.setStatusImage(mContext, vVerified, null, State.REVOKED, R.color.key_flag_gray); // disable revoked user ids vName.setEnabled(false); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseActivity.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseActivity.java index 9529d8689..66b784f9b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseActivity.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/base/BaseActivity.java @@ -18,6 +18,7 @@ package org.sufficientlysecure.keychain.ui.base; import android.app.Activity; +import android.content.Intent; import android.os.Bundle; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; @@ -29,6 +30,7 @@ import android.view.ViewGroup; import android.widget.TextView; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.ui.util.ThemeChanger; /** * Setups Toolbar @@ -36,14 +38,28 @@ import org.sufficientlysecure.keychain.R; public abstract class BaseActivity extends AppCompatActivity { protected Toolbar mToolbar; protected View mStatusBar; + protected ThemeChanger mThemeChanger; @Override protected void onCreate(Bundle savedInstanceState) { + mThemeChanger = new ThemeChanger(this); + mThemeChanger.changeTheme(); super.onCreate(savedInstanceState); initLayout(); initToolbar(); } + @Override + protected void onResume() { + super.onResume(); + + if (mThemeChanger.changeTheme()) { + Intent intent = getIntent(); + finish(); + startActivity(intent); + } + } + protected void initLayout() { } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/CustomAlertDialogBuilder.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/CustomAlertDialogBuilder.java index 8a5cc0656..840b95a3c 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/CustomAlertDialogBuilder.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/CustomAlertDialogBuilder.java @@ -28,5 +28,4 @@ public class CustomAlertDialogBuilder extends AlertDialog.Builder { public CustomAlertDialogBuilder(Context context) { super(context); } - } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java index f88cf603a..d1d22b6d7 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/OrbotStartDialogFragment.java @@ -30,6 +30,7 @@ import android.view.ContextThemeWrapper; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.ui.util.ThemeChanger; import org.sufficientlysecure.keychain.util.Log; import org.sufficientlysecure.keychain.util.orbot.OrbotHelper; @@ -67,11 +68,7 @@ public class OrbotStartDialogFragment extends DialogFragment { int middleButton = getArguments().getInt(ARG_MIDDLE_BUTTON); final Activity activity = getActivity(); - // if the dialog is displayed from the application class, design is missing. - // hack to get holo design (which is not automatically applied due to activity's - // Theme.NoDisplay) - ContextThemeWrapper theme = new ContextThemeWrapper(activity, - R.style.Theme_AppCompat_Light_Dialog); + ContextThemeWrapper theme = ThemeChanger.getDialogThemeWrapper(activity); CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(theme); builder.setTitle(title).setMessage(message); @@ -126,4 +123,4 @@ public class OrbotStartDialogFragment extends DialogFragment { return builder.show(); } -}
\ No newline at end of file +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ProgressDialogFragment.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ProgressDialogFragment.java index 52a90b323..764291dd0 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ProgressDialogFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/dialog/ProgressDialogFragment.java @@ -35,6 +35,7 @@ import android.widget.Button; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.service.KeychainService; +import org.sufficientlysecure.keychain.ui.util.ThemeChanger; /** * meant to be used @@ -98,10 +99,7 @@ public class ProgressDialogFragment extends DialogFragment { public Dialog onCreateDialog(Bundle savedInstanceState) { final Activity activity = getActivity(); - // if the progress dialog is displayed from the application class, design is missing - // hack to get holo design (which is not automatically applied due to activity's Theme.NoDisplay - ContextThemeWrapper context = new ContextThemeWrapper(activity, - R.style.Theme_AppCompat_Light); + ContextThemeWrapper context = ThemeChanger.getDialogThemeWrapper(activity); ProgressDialog dialog = new ProgressDialog(context); dialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/FormattingUtils.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/FormattingUtils.java index eb5c3df45..902a7ec56 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/FormattingUtils.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/FormattingUtils.java @@ -18,9 +18,11 @@ package org.sufficientlysecure.keychain.ui.util; import android.content.Context; +import android.content.res.Resources.Theme; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.style.StrikethroughSpan; +import android.util.TypedValue; public class FormattingUtils { @@ -32,4 +34,10 @@ public class FormattingUtils { return (int) ((px / context.getResources().getDisplayMetrics().density) + 0.5f); } + public static int getColorFromAttr(Context context, int attr) { + TypedValue typedValue = new TypedValue(); + Theme theme = context.getTheme(); + theme.resolveAttribute(attr, typedValue, true); + return typedValue.data; + } } diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Highlighter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Highlighter.java index 69338aa3e..ac34d5526 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Highlighter.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Highlighter.java @@ -22,6 +22,7 @@ import android.text.Spannable; import android.text.style.ForegroundColorSpan; import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.ui.util.FormattingUtils; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -44,9 +45,12 @@ public class Highlighter { Pattern pattern = Pattern.compile("(?i)(" + mQuery.trim().replaceAll("\\s+", "|") + ")"); Matcher matcher = pattern.matcher(text); + + int colorEmphasis = FormattingUtils.getColorFromAttr(mContext, R.attr.colorEmphasis); + while (matcher.find()) { highlight.setSpan( - new ForegroundColorSpan(mContext.getResources().getColor(R.color.emphasis)), + new ForegroundColorSpan(colorEmphasis), matcher.start(), matcher.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/InstallDialogFragmentHelper.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/InstallDialogFragmentHelper.java index 5ddb013db..b2213ed10 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/InstallDialogFragmentHelper.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/InstallDialogFragmentHelper.java @@ -31,6 +31,7 @@ import android.view.ContextThemeWrapper; import org.sufficientlysecure.keychain.Constants; import org.sufficientlysecure.keychain.R; import org.sufficientlysecure.keychain.ui.dialog.CustomAlertDialogBuilder; +import org.sufficientlysecure.keychain.ui.util.ThemeChanger; import org.sufficientlysecure.keychain.util.Log; public class InstallDialogFragmentHelper { @@ -65,11 +66,7 @@ public class InstallDialogFragmentHelper { final String installPath = args.getString(ARG_INSTALL_PATH); final boolean useMiddleButton = args.getBoolean(ARG_USE_MIDDLE_BUTTON); - // if the dialog is displayed from the application class, design is missing. - // hack to get holo design (which is not automatically applied due to activity's - // Theme.NoDisplay) - ContextThemeWrapper theme = new ContextThemeWrapper(activity, - R.style.Theme_AppCompat_Light_Dialog); + ContextThemeWrapper theme = ThemeChanger.getDialogThemeWrapper(activity); CustomAlertDialogBuilder builder = new CustomAlertDialogBuilder(theme); builder.setTitle(title).setMessage(message); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java index a3cd63d13..224e0085b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/KeyFormattingUtils.java @@ -40,6 +40,7 @@ import org.sufficientlysecure.keychain.operations.results.DecryptVerifyResult; import org.sufficientlysecure.keychain.pgp.KeyRing; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Algorithm; import org.sufficientlysecure.keychain.service.SaveKeyringParcel.Curve; +import org.sufficientlysecure.keychain.ui.util.FormattingUtils; import org.sufficientlysecure.keychain.util.Log; import java.nio.ByteBuffer; @@ -449,11 +450,11 @@ public class KeyFormattingUtils { if (signatureResult != null && signatureResult.isSignatureOnly()) { encIcon = R.drawable.status_lock_open_24dp; encText = R.string.decrypt_result_not_encrypted; - encColor = R.color.android_red_light; + encColor = R.color.key_flag_red; } else { encIcon = R.drawable.status_lock_closed_24dp; encText = R.string.decrypt_result_encrypted; - encColor = R.color.android_green_light; + encColor = R.color.key_flag_green; } int encColorRes = context.getResources().getColor(encColor); @@ -470,7 +471,7 @@ public class KeyFormattingUtils { sigText = R.string.decrypt_result_no_signature; sigIcon = R.drawable.status_signature_invalid_cutout_24dp; - sigColor = R.color.bg_gray; + sigColor = R.color.key_flag_gray; // won't be used, but makes compiler happy sigActionText = 0; @@ -481,7 +482,7 @@ public class KeyFormattingUtils { case OpenPgpSignatureResult.SIGNATURE_SUCCESS_CERTIFIED: { sigText = R.string.decrypt_result_signature_certified; sigIcon = R.drawable.status_signature_verified_cutout_24dp; - sigColor = R.color.android_green_light; + sigColor = R.color.key_flag_green; sigActionText = R.string.decrypt_result_action_show; sigActionIcon = R.drawable.ic_vpn_key_grey_24dp; @@ -491,7 +492,7 @@ public class KeyFormattingUtils { case OpenPgpSignatureResult.SIGNATURE_SUCCESS_UNCERTIFIED: { sigText = R.string.decrypt_result_signature_uncertified; sigIcon = R.drawable.status_signature_unverified_cutout_24dp; - sigColor = R.color.android_orange_light; + sigColor = R.color.key_flag_orange; sigActionText = R.string.decrypt_result_action_show; sigActionIcon = R.drawable.ic_vpn_key_grey_24dp; @@ -501,7 +502,7 @@ public class KeyFormattingUtils { case OpenPgpSignatureResult.SIGNATURE_KEY_REVOKED: { sigText = R.string.decrypt_result_signature_revoked_key; sigIcon = R.drawable.status_signature_revoked_cutout_24dp; - sigColor = R.color.android_red_light; + sigColor = R.color.key_flag_red; sigActionText = R.string.decrypt_result_action_show; sigActionIcon = R.drawable.ic_vpn_key_grey_24dp; @@ -511,7 +512,7 @@ public class KeyFormattingUtils { case OpenPgpSignatureResult.SIGNATURE_KEY_EXPIRED: { sigText = R.string.decrypt_result_signature_expired_key; sigIcon = R.drawable.status_signature_expired_cutout_24dp; - sigColor = R.color.android_red_light; + sigColor = R.color.key_flag_red; sigActionText = R.string.decrypt_result_action_show; sigActionIcon = R.drawable.ic_vpn_key_grey_24dp; @@ -521,7 +522,7 @@ public class KeyFormattingUtils { case OpenPgpSignatureResult.SIGNATURE_KEY_MISSING: { sigText = R.string.decrypt_result_signature_missing_key; sigIcon = R.drawable.status_signature_unknown_cutout_24dp; - sigColor = R.color.android_red_light; + sigColor = R.color.key_flag_red; sigActionText = R.string.decrypt_result_action_Lookup; sigActionIcon = R.drawable.ic_file_download_grey_24dp; @@ -532,7 +533,7 @@ public class KeyFormattingUtils { case OpenPgpSignatureResult.SIGNATURE_ERROR: { sigText = R.string.decrypt_result_invalid_signature; sigIcon = R.drawable.status_signature_invalid_cutout_24dp; - sigColor = R.color.android_red_light; + sigColor = R.color.key_flag_red; sigActionText = R.string.decrypt_result_action_show; sigActionIcon = R.drawable.ic_vpn_key_grey_24dp; @@ -595,7 +596,7 @@ public class KeyFormattingUtils { context.getResources().getDrawable(R.drawable.status_signature_verified_cutout_24dp)); } if (color == KeyFormattingUtils.DEFAULT_COLOR) { - color = R.color.android_green_light; + color = R.color.key_flag_green; } statusIcon.setColorFilter(context.getResources().getColor(color), PorterDuff.Mode.SRC_IN); @@ -608,7 +609,7 @@ public class KeyFormattingUtils { statusIcon.setImageDrawable( context.getResources().getDrawable(R.drawable.status_lock_closed_24dp)); if (color == KeyFormattingUtils.DEFAULT_COLOR) { - color = R.color.android_green_light; + color = R.color.key_flag_green; } statusIcon.setColorFilter(context.getResources().getColor(color), PorterDuff.Mode.SRC_IN); @@ -627,7 +628,7 @@ public class KeyFormattingUtils { context.getResources().getDrawable(R.drawable.status_signature_unverified_cutout_24dp)); } if (color == KeyFormattingUtils.DEFAULT_COLOR) { - color = R.color.android_orange_light; + color = R.color.key_flag_orange; } statusIcon.setColorFilter(context.getResources().getColor(color), PorterDuff.Mode.SRC_IN); @@ -640,7 +641,7 @@ public class KeyFormattingUtils { statusIcon.setImageDrawable( context.getResources().getDrawable(R.drawable.status_signature_unknown_cutout_24dp)); if (color == KeyFormattingUtils.DEFAULT_COLOR) { - color = R.color.android_red_light; + color = R.color.key_flag_red; } statusIcon.setColorFilter(context.getResources().getColor(color), PorterDuff.Mode.SRC_IN); @@ -659,7 +660,7 @@ public class KeyFormattingUtils { context.getResources().getDrawable(R.drawable.status_signature_revoked_cutout_24dp)); } if (color == KeyFormattingUtils.DEFAULT_COLOR) { - color = R.color.android_red_light; + color = R.color.key_flag_red; } statusIcon.setColorFilter(context.getResources().getColor(color), PorterDuff.Mode.SRC_IN); @@ -677,7 +678,7 @@ public class KeyFormattingUtils { context.getResources().getDrawable(R.drawable.status_signature_expired_cutout_24dp)); } if (color == KeyFormattingUtils.DEFAULT_COLOR) { - color = R.color.android_red_light; + color = R.color.key_flag_red; } statusIcon.setColorFilter(context.getResources().getColor(color), PorterDuff.Mode.SRC_IN); @@ -690,7 +691,7 @@ public class KeyFormattingUtils { statusIcon.setImageDrawable( context.getResources().getDrawable(R.drawable.status_lock_open_24dp)); if (color == KeyFormattingUtils.DEFAULT_COLOR) { - color = R.color.android_red_light; + color = R.color.key_flag_red; } statusIcon.setColorFilter(context.getResources().getColor(color), PorterDuff.Mode.SRC_IN); @@ -703,7 +704,7 @@ public class KeyFormattingUtils { statusIcon.setImageDrawable( context.getResources().getDrawable(R.drawable.status_signature_unknown_cutout_24dp)); if (color == KeyFormattingUtils.DEFAULT_COLOR) { - color = R.color.android_red_light; + color = R.color.key_flag_red; } statusIcon.setColorFilter(context.getResources().getColor(color), PorterDuff.Mode.SRC_IN); @@ -716,7 +717,7 @@ public class KeyFormattingUtils { statusIcon.setImageDrawable( context.getResources().getDrawable(R.drawable.status_signature_invalid_cutout_24dp)); if (color == KeyFormattingUtils.DEFAULT_COLOR) { - color = R.color.android_red_light; + color = R.color.key_flag_red; } statusIcon.setColorFilter(context.getResources().getColor(color), PorterDuff.Mode.SRC_IN); @@ -730,7 +731,7 @@ public class KeyFormattingUtils { statusIcon.setImageDrawable( context.getResources().getDrawable(R.drawable.status_signature_invalid_cutout_24dp)); if (color == KeyFormattingUtils.DEFAULT_COLOR) { - color = R.color.bg_gray; + color = R.color.key_flag_gray; } statusIcon.setColorFilter(context.getResources().getColor(color), PorterDuff.Mode.SRC_IN); diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/ThemeChanger.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/ThemeChanger.java new file mode 100644 index 000000000..f53e43528 --- /dev/null +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/ThemeChanger.java @@ -0,0 +1,73 @@ +/* + * Copyright (C) 2015 Thialfihar <thi@thialfihar.org> + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +package org.sufficientlysecure.keychain.ui.util; + +import android.content.Context; +import android.view.ContextThemeWrapper; + +import org.sufficientlysecure.keychain.Constants; +import org.sufficientlysecure.keychain.R; +import org.sufficientlysecure.keychain.util.Preferences; + +public class ThemeChanger { + private Context mContext; + private Preferences mPreferences; + private String mCurrentTheme = null; + + static public ContextThemeWrapper getDialogThemeWrapper(Context context) { + Preferences preferences = Preferences.getPreferences(context); + + // if the dialog is displayed from the application class, design is missing. + // hack to get holo design (which is not automatically applied due to activity's + // Theme.NoDisplay) + if (Constants.Pref.Theme.DARK.equals(preferences.getTheme())) { + return new ContextThemeWrapper(context, R.style.Theme_AppCompat_Dialog); + } else { + return new ContextThemeWrapper(context, R.style.Theme_AppCompat_Light_Dialog); + } + } + + public ThemeChanger(Context context) { + mContext = context; + mPreferences = Preferences.getPreferences(mContext); + } + + /** + * Apply the theme set in preferences if it isn't equal to mCurrentTheme + * anymore or mCurrentTheme hasn't been set yet. + * If a new theme is applied in this method, then return true, so + * the caller can re-create the activity, if need be. + */ + public boolean changeTheme() { + String newTheme = mPreferences.getTheme(); + if (mCurrentTheme != null && mCurrentTheme.equals(newTheme)) { + return false; + } + + int themeId = R.style.LightTheme; + if (Constants.Pref.Theme.DARK.equals(newTheme)) { + themeId = R.style.DarkTheme; + } + + ContextThemeWrapper w = new ContextThemeWrapper(mContext, themeId); + mContext.getTheme().setTo(w.getTheme()); + mCurrentTheme = newTheme; + + return true; + } +} diff --git a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PasswordStrengthView.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PasswordStrengthView.java index 30bdfb92a..a7ead8039 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PasswordStrengthView.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/widget/PasswordStrengthView.java @@ -99,9 +99,9 @@ public class PasswordStrengthView extends View { public PasswordStrengthView(Context context, AttributeSet attrs) { super(context, attrs); - int COLOR_FAIL = getResources().getColor(R.color.android_red_light); - int COLOR_WEAK = getResources().getColor(R.color.android_orange_light); - int COLOR_STRONG = getResources().getColor(R.color.android_green_light); + int COLOR_FAIL = getResources().getColor(R.color.password_strength_low); + int COLOR_WEAK = getResources().getColor(R.color.password_strength_medium); + int COLOR_STRONG = getResources().getColor(R.color.password_strength_high); TypedArray style = context.getTheme().obtainStyledAttributes( attrs, |