From 58cb6bb4b70795213f9609682c68d0025e0bab56 Mon Sep 17 00:00:00 2001 From: Thialfihar Date: Thu, 25 Jun 2015 19:24:02 +0200 Subject: Start moving colors into themes Using attrs instead of fixed colors it will be possible to style everything and also dynamically grab the color where needed in code. This is done with colorEmphasis as an initial test. Also remove several unused colors. --- .../keychain/ui/KeyListFragment.java | 12 ++++++++- .../keychain/ui/util/Highlighter.java | 10 ++++++- .../main/res/layout/api_app_settings_activity.xml | 6 ++--- .../src/main/res/layout/drawer_custom_header.xml | 4 +-- .../src/main/res/layout/key_list_fragment.xml | 18 ++++++------- .../src/main/res/layout/view_key_activity.xml | 6 ++--- OpenKeychain/src/main/res/values/attrs.xml | 8 ++++++ OpenKeychain/src/main/res/values/colors.xml | 31 +++------------------- OpenKeychain/src/main/res/values/themes.xml | 24 ++++++++++++----- 9 files changed, 65 insertions(+), 54 deletions(-) create mode 100644 OpenKeychain/src/main/res/values/attrs.xml (limited to 'OpenKeychain/src/main') 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..21af2c83b 100644 --- a/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java +++ b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/KeyListFragment.java @@ -28,6 +28,7 @@ import android.annotation.TargetApi; import android.app.Activity; import android.content.Context; import android.content.Intent; +import android.content.res.Resources.Theme; import android.database.Cursor; import android.graphics.Color; import android.net.Uri; @@ -46,6 +47,7 @@ import android.view.MenuItem; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup; +import android.util.TypedValue; import android.widget.AbsListView.MultiChoiceModeListener; import android.widget.AdapterView; import android.widget.ListView; @@ -675,8 +677,11 @@ public class KeyListFragment extends LoaderFragment private HashMap mSelection = new HashMap<>(); + private Context mContext; + public KeyListAdapter(Context context, Cursor c, int flags) { super(context, c, flags); + mContext = context; } @Override @@ -705,9 +710,14 @@ public class KeyListFragment extends LoaderFragment // let the adapter handle setting up the row views View v = super.getView(position, convertView, parent); + TypedValue typedValue = new TypedValue(); + Theme theme = mContext.getTheme(); + theme.resolveAttribute(R.attr.colorEmphasis, typedValue, true); + int colorEmphasis = typedValue.data; + 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/util/Highlighter.java b/OpenKeychain/src/main/java/org/sufficientlysecure/keychain/ui/util/Highlighter.java index 69338aa3e..22c5315a9 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 @@ -18,8 +18,10 @@ package org.sufficientlysecure.keychain.ui.util; import android.content.Context; +import android.content.res.Resources.Theme; import android.text.Spannable; import android.text.style.ForegroundColorSpan; +import android.util.TypedValue; import org.sufficientlysecure.keychain.R; @@ -44,9 +46,15 @@ public class Highlighter { Pattern pattern = Pattern.compile("(?i)(" + mQuery.trim().replaceAll("\\s+", "|") + ")"); Matcher matcher = pattern.matcher(text); + + TypedValue typedValue = new TypedValue(); + Theme theme = mContext.getTheme(); + theme.resolveAttribute(R.attr.colorEmphasis, typedValue, true); + int colorEmphasis = typedValue.data; + 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/res/layout/api_app_settings_activity.xml b/OpenKeychain/src/main/res/layout/api_app_settings_activity.xml index c3f6e33cb..ea20b77b3 100644 --- a/OpenKeychain/src/main/res/layout/api_app_settings_activity.xml +++ b/OpenKeychain/src/main/res/layout/api_app_settings_activity.xml @@ -117,7 +117,7 @@ android:layout_height="wrap_content" android:elevation="4dp" fab:fab_icon="@drawable/ic_play_arrow_white_24dp" - fab:fab_colorNormal="@color/fab" - fab:fab_colorPressed="@color/fab_pressed" /> + fab:fab_colorNormal="?attr/colorFab" + fab:fab_colorPressed="?attr/colorFabPressed" /> - \ No newline at end of file + diff --git a/OpenKeychain/src/main/res/layout/drawer_custom_header.xml b/OpenKeychain/src/main/res/layout/drawer_custom_header.xml index 86465db98..716ec2cd2 100644 --- a/OpenKeychain/src/main/res/layout/drawer_custom_header.xml +++ b/OpenKeychain/src/main/res/layout/drawer_custom_header.xml @@ -4,7 +4,7 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:gravity="center" - android:background="@color/primary"> + android:background="?attr/colorPrimary"> - \ No newline at end of file + diff --git a/OpenKeychain/src/main/res/layout/key_list_fragment.xml b/OpenKeychain/src/main/res/layout/key_list_fragment.xml index ea3426f90..9c41590db 100644 --- a/OpenKeychain/src/main/res/layout/key_list_fragment.xml +++ b/OpenKeychain/src/main/res/layout/key_list_fragment.xml @@ -45,8 +45,8 @@ android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:layout_alignParentBottom="true" - fab:fab_addButtonColorNormal="@color/primary" - fab:fab_addButtonColorPressed="@color/primary_dark" + fab:fab_addButtonColorNormal="?attr/colorPrimary" + fab:fab_addButtonColorPressed="?attr/colorPrimaryDark" fab:fab_addButtonSize="normal" fab:fab_addButtonPlusIconColor="@color/icons" fab:fab_expandDirection="up" @@ -61,8 +61,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" fab:fab_icon="@drawable/ic_qrcode_white_24dp" - fab:fab_colorNormal="@color/primary" - fab:fab_colorPressed="@color/primary_dark" + fab:fab_colorNormal="?attr/colorPrimary" + fab:fab_colorPressed="?attr/colorPrimaryDark" fab:fab_title="Scan QR Code" fab:fab_size="mini" /> @@ -71,8 +71,8 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" fab:fab_icon="@drawable/ic_cloud_search_24dp" - fab:fab_colorNormal="@color/primary" - fab:fab_colorPressed="@color/primary_dark" + fab:fab_colorNormal="?attr/colorPrimary" + fab:fab_colorPressed="?attr/colorPrimaryDark" fab:fab_title="Search Cloud" fab:fab_size="mini" /> @@ -81,10 +81,10 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" fab:fab_icon="@drawable/ic_folder_white_24dp" - fab:fab_colorNormal="@color/primary" - fab:fab_colorPressed="@color/primary_dark" + fab:fab_colorNormal="?attr/colorPrimary" + fab:fab_colorPressed="?attr/colorPrimaryDark" fab:fab_title="Import from File" fab:fab_size="mini" /> - \ No newline at end of file + diff --git a/OpenKeychain/src/main/res/layout/view_key_activity.xml b/OpenKeychain/src/main/res/layout/view_key_activity.xml index b3f4e721d..648e072ac 100644 --- a/OpenKeychain/src/main/res/layout/view_key_activity.xml +++ b/OpenKeychain/src/main/res/layout/view_key_activity.xml @@ -200,7 +200,7 @@ tools:visibility="visible" android:elevation="4dp" fab:fab_icon="@drawable/ic_qrcode_white_24dp" - fab:fab_colorNormal="@color/fab" - fab:fab_colorPressed="@color/fab_pressed" /> + fab:fab_colorNormal="?attr/colorFab" + fab:fab_colorPressed="?attr/colorFabPressed" /> - \ No newline at end of file + diff --git a/OpenKeychain/src/main/res/values/attrs.xml b/OpenKeychain/src/main/res/values/attrs.xml new file mode 100644 index 000000000..ce110418e --- /dev/null +++ b/OpenKeychain/src/main/res/values/attrs.xml @@ -0,0 +1,8 @@ + + + + + + + + diff --git a/OpenKeychain/src/main/res/values/colors.xml b/OpenKeychain/src/main/res/values/colors.xml index ead006a63..b6b46ec8c 100644 --- a/OpenKeychain/src/main/res/values/colors.xml +++ b/OpenKeychain/src/main/res/values/colors.xml @@ -1,38 +1,15 @@ - - - - - #7bad45 - - #6c983d - - #2196F3 - - - - #000000 - - #C8E6C9 - @color/accent - #1976D2 - #212121 - #727272 #FFFFFF - #B6B6B6 #00FFFFFF #212121 - - @color/accent #cecbce #808080 #ffdd3333 - #33999999 #33CCCCCC @@ -43,10 +20,8 @@ #B2000000 - #e5e5e5 - #808080 + #000000 #fafafa - #f1f1f1 true @@ -14,10 +19,15 @@ @style/MySearchViewStyle -