diff options
author | Thialfihar <thi@thialfihar.org> | 2015-06-25 19:24:02 +0200 |
---|---|---|
committer | Thialfihar <thi@thialfihar.org> | 2015-07-21 20:49:08 +0200 |
commit | 58cb6bb4b70795213f9609682c68d0025e0bab56 (patch) | |
tree | 882a1ded5495c6c02ae00ee5d07596988176691d | |
parent | 4d412d53dc85d2f1d50f43b92a03c3e374872445 (diff) | |
download | open-keychain-58cb6bb4b70795213f9609682c68d0025e0bab56.tar.gz open-keychain-58cb6bb4b70795213f9609682c68d0025e0bab56.tar.bz2 open-keychain-58cb6bb4b70795213f9609682c68d0025e0bab56.zip |
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.
9 files changed, 65 insertions, 54 deletions
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<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 +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" /> -</RelativeLayout>
\ No newline at end of file +</RelativeLayout> 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"> <TextView android:layout_width="wrap_content" @@ -13,4 +13,4 @@ android:text="@string/app_name" android:textColor="@color/white" android:layout_gravity="center_horizontal" /> -</LinearLayout>
\ No newline at end of file +</LinearLayout> 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" /> </com.getbase.floatingactionbutton.FloatingActionsMenu> -</RelativeLayout>
\ No newline at end of file +</RelativeLayout> 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" /> -</RelativeLayout>
\ No newline at end of file +</RelativeLayout> 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 @@ +<?xml version="1.0" encoding="utf-8"?> +<resources> + <declare-styleable name="CustomTheme"> + <attr name="colorFab" format="color" /> + <attr name="colorFabPressed" format="color" /> + <attr name="colorEmphasis" format="color" /> + </declare-styleable> +</resources> 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 @@ <?xml version="1.0" encoding="utf-8"?> <resources> - <!-- Main theme colors --> - - <!-- green colors from OpenKeychain logo bottom right --> - <!-- your app branding color for the app bar --> - <color name="primary">#7bad45</color> - <!-- darker variant for the status bar and contextual app bars --> - <color name="primary_dark">#6c983d</color> - <!-- theme UI controls like checkboxes and text fields --> - <color name="accent">#2196F3</color> - - <!-- Other colors --> - - <color name="black">#000000</color> - - <color name="primary_light">#C8E6C9</color> - <color name="fab">@color/accent</color> - <color name="fab_pressed">#1976D2</color> - <color name="primary_text">#212121</color> - <color name="secondary_text">#727272</color> <color name="icons">#FFFFFF</color> - <color name="divider">#B6B6B6</color> <color name="transparent">#00FFFFFF</color> <color name="header_text">#212121</color> - <!-- item selection, search highlight --> - <color name="emphasis">@color/accent</color> <color name="bg_gray">#cecbce</color> <color name="tertiary_text_light">#808080</color> <color name="alert">#ffdd3333</color> - <color name="holo_gray_light">#33999999</color> <color name="holo_gray_bright">#33CCCCCC</color> <!-- tabs --> @@ -43,10 +20,8 @@ <!-- floating action buttons --> <color name="black_semi_transparent">#B2000000</color> - <color name="background">#e5e5e5</color> - <color name="half_black">#808080</color> + <color name="black">#000000</color> <color name="white">#fafafa</color> - <color name="white_pressed">#f1f1f1</color> <!-- http://www.google.com/design/spec/style/color.html#color-color-palette @@ -59,8 +34,8 @@ <color name="android_red_dark">#b71c1c</color> <color name="android_orange_light">#ff9800</color> <color name="android_orange_dark">#e65100</color> - <color name="android_green_light">@color/primary</color> - <color name="android_green_dark">@color/primary_dark</color> + <color name="android_green_light">#00ff00</color> + <color name="android_green_dark">#008000</color> <color name="android_purple_light">#673ab7</color> <color name="android_purple_dark">#311b92</color> diff --git a/OpenKeychain/src/main/res/values/themes.xml b/OpenKeychain/src/main/res/values/themes.xml index d15106966..823622269 100644 --- a/OpenKeychain/src/main/res/values/themes.xml +++ b/OpenKeychain/src/main/res/values/themes.xml @@ -2,9 +2,14 @@ <resources> <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> + <item name="colorPrimary">#7bad45</item> + <item name="colorPrimaryDark">#6c983d</item> + <item name="colorAccent">#2196f3</item> + + <item name="colorFab">#2196f3</item> + <item name="colorFabPressed">#1976d2</item> + + <item name="colorEmphasis">#2196f3</item> <!-- remove actionbar and title, we use toolbar! --> <item name="windowNoTitle">true</item> @@ -14,10 +19,15 @@ <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> + <style name="DarkBaseTheme" parent="MaterialDrawerTheme.ActionBar"> + <item name="colorPrimary">#268bd2</item> + <item name="colorPrimaryDark">#166bb2</item> + <item name="colorAccent">#2196f3</item> + + <item name="colorFab">#2196f3</item> + <item name="colorFabPressed">#1976d2</item> + + <item name="colorEmphasis">#2196f3</item> <!-- remove actionbar and title, we use toolbar! --> <item name="windowNoTitle">true</item> |