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.
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>
|
||||
</RelativeLayout>
|
||||
|
||||
@@ -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>
|
||||
</LinearLayout>
|
||||
|
||||
@@ -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>
|
||||
</RelativeLayout>
|
||||
|
||||
@@ -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>
|
||||
</RelativeLayout>
|
||||
|
||||
8
OpenKeychain/src/main/res/values/attrs.xml
Normal file
8
OpenKeychain/src/main/res/values/attrs.xml
Normal file
@@ -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>
|
||||
@@ -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>
|
||||
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user