1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-23 18:02:15 -05:00

Add setting to toggle colored background of fallback contact pictures

This commit is contained in:
cketti 2013-08-16 18:42:13 +02:00
parent 3064d8ab31
commit 20fcd6f63d
11 changed files with 82 additions and 4 deletions

View File

@ -51,6 +51,7 @@
<attr name="composerBackgroundColor" format="color"/> <attr name="composerBackgroundColor" format="color"/>
<attr name="compatDividerVertical" format="reference"/> <attr name="compatDividerVertical" format="reference"/>
<attr name="compatSelectableItemBackground" format="reference"/> <attr name="compatSelectableItemBackground" format="reference"/>
<attr name="contactPictureFallbackDefaultBackgroundColor" format="reference|color"/>
</declare-styleable> </declare-styleable>
</resources> </resources>

View File

@ -1147,4 +1147,6 @@ Please submit bug reports, contribute new features and ask questions at
<string name="preposition_for_date">on <xliff:g id="date">%s</xliff:g></string> <string name="preposition_for_date">on <xliff:g id="date">%s</xliff:g></string>
<string name="mark_all_as_read">Mark all as read</string> <string name="mark_all_as_read">Mark all as read</string>
<string name="global_settings_colorize_missing_contact_pictures">Colorize missing contact pictures</string>
</resources> </resources>

View File

@ -51,6 +51,7 @@
<item name="messageComposeAddContactImage">@drawable/ic_button_add_contact_light</item> <item name="messageComposeAddContactImage">@drawable/ic_button_add_contact_light</item>
<item name="compatDividerVertical">?attr/messageListDividerColor</item> <item name="compatDividerVertical">?attr/messageListDividerColor</item>
<item name="compatSelectableItemBackground">@android:color/transparent</item> <item name="compatSelectableItemBackground">@android:color/transparent</item>
<item name="contactPictureFallbackDefaultBackgroundColor">#ffababab</item>
</style> </style>
<style name="Theme.K9.Dark.Base" parent="Theme.Sherlock"> <style name="Theme.K9.Dark.Base" parent="Theme.Sherlock">
@ -101,6 +102,7 @@
<item name="messageComposeAddContactImage">@drawable/ic_button_add_contact_dark</item> <item name="messageComposeAddContactImage">@drawable/ic_button_add_contact_dark</item>
<item name="compatDividerVertical">?attr/messageListDividerColor</item> <item name="compatDividerVertical">?attr/messageListDividerColor</item>
<item name="compatSelectableItemBackground">@android:color/transparent</item> <item name="compatSelectableItemBackground">@android:color/transparent</item>
<item name="contactPictureFallbackDefaultBackgroundColor">#ff606060</item>
</style> </style>
<style name="Theme.K9.Light" parent="Theme.K9.Light.Base"> <style name="Theme.K9.Light" parent="Theme.K9.Light.Base">

View File

@ -178,6 +178,12 @@
android:summary="@string/global_settings_show_contact_picture_summary" android:summary="@string/global_settings_show_contact_picture_summary"
/> />
<CheckBoxPreference
android:persistent="false"
android:key="messagelist_colorize_missing_contact_pictures"
android:title="@string/global_settings_colorize_missing_contact_pictures"
/>
<CheckBoxPreference <CheckBoxPreference
android:persistent="false" android:persistent="false"
android:key="messagelist_background_as_unread_indicator" android:key="messagelist_background_as_unread_indicator"

View File

@ -260,6 +260,7 @@ public class K9 extends Application {
private static boolean sUseBackgroundAsUnreadIndicator = true; private static boolean sUseBackgroundAsUnreadIndicator = true;
private static boolean sThreadedViewEnabled = true; private static boolean sThreadedViewEnabled = true;
private static SplitViewMode sSplitViewMode = SplitViewMode.NEVER; private static SplitViewMode sSplitViewMode = SplitViewMode.NEVER;
private static boolean sColorizeMissingContactPictures = true;
/** /**
* @see #areDatabasesUpToDate() * @see #areDatabasesUpToDate()
@ -537,6 +538,7 @@ public class K9 extends Application {
editor.putBoolean("useBackgroundAsUnreadIndicator", sUseBackgroundAsUnreadIndicator); editor.putBoolean("useBackgroundAsUnreadIndicator", sUseBackgroundAsUnreadIndicator);
editor.putBoolean("threadedView", sThreadedViewEnabled); editor.putBoolean("threadedView", sThreadedViewEnabled);
editor.putString("splitViewMode", sSplitViewMode.name()); editor.putString("splitViewMode", sSplitViewMode.name());
editor.putBoolean("colorizeMissingContactPictures", sColorizeMissingContactPictures);
fontSizes.save(editor); fontSizes.save(editor);
} }
@ -757,6 +759,8 @@ public class K9 extends Application {
setBackgroundOps(BACKGROUND_OPS.WHEN_CHECKED); setBackgroundOps(BACKGROUND_OPS.WHEN_CHECKED);
} }
sColorizeMissingContactPictures = sprefs.getBoolean("colorizeMissingContactPictures", true);
K9.setK9Language(sprefs.getString("language", "")); K9.setK9Language(sprefs.getString("language", ""));
int themeValue = sprefs.getInt("theme", Theme.LIGHT.ordinal()); int themeValue = sprefs.getInt("theme", Theme.LIGHT.ordinal());
@ -1302,6 +1306,15 @@ public class K9 extends Application {
sShowContactPicture = show; sShowContactPicture = show;
} }
public static boolean isColorizeMissingContactPictures() {
return sColorizeMissingContactPictures;
}
public static void setColorizeMissingContactPictures(boolean enabled) {
sColorizeMissingContactPictures = enabled;
}
/** /**
* Check if we already know whether all databases are using the current database schema. * Check if we already know whether all databases are using the current database schema.
* *

View File

@ -38,6 +38,8 @@ public class ContactPictureLoader {
private Contacts mContactsHelper; private Contacts mContactsHelper;
private int mPictureSizeInPx; private int mPictureSizeInPx;
private int mDefaultBackgroundColor;
/** /**
* LRU cache of contact pictures. * LRU cache of contact pictures.
*/ */
@ -59,7 +61,16 @@ public class ContactPictureLoader {
0xffCC0000 0xffCC0000
}; };
public ContactPictureLoader(Context context, int defaultPictureResource) { /**
* Constructor.
*
* @param context
* A {@link Context} instance.
* @param defaultBackgroundColor
* The ARGB value to be used as background color for the fallback picture. {@code 0} to
* use a dynamically calculated background color.
*/
public ContactPictureLoader(Context context, int defaultBackgroundColor) {
Context appContext = context.getApplicationContext(); Context appContext = context.getApplicationContext();
mContentResolver = appContext.getContentResolver(); mContentResolver = appContext.getContentResolver();
mResources = appContext.getResources(); mResources = appContext.getResources();
@ -68,6 +79,8 @@ public class ContactPictureLoader {
float scale = mResources.getDisplayMetrics().density; float scale = mResources.getDisplayMetrics().density;
mPictureSizeInPx = (int) (PICTURE_SIZE * scale); mPictureSizeInPx = (int) (PICTURE_SIZE * scale);
mDefaultBackgroundColor = defaultBackgroundColor;
ActivityManager activityManager = ActivityManager activityManager =
(ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE); (ActivityManager) appContext.getSystemService(Context.ACTIVITY_SERVICE);
int memClass = activityManager.getMemoryClass(); int memClass = activityManager.getMemoryClass();
@ -130,6 +143,10 @@ public class ContactPictureLoader {
} }
private int calcUnknownContactColor(Address address) { private int calcUnknownContactColor(Address address) {
if (mDefaultBackgroundColor != 0) {
return mDefaultBackgroundColor;
}
int val = address.getAddress().toLowerCase().hashCode(); int val = address.getAddress().toLowerCase().hashCode();
int rgb = CONTACT_DUMMY_COLORS_ARGB[Math.abs(val) % CONTACT_DUMMY_COLORS_ARGB.length]; int rgb = CONTACT_DUMMY_COLORS_ARGB[Math.abs(val) % CONTACT_DUMMY_COLORS_ARGB.length];
return rgb; return rgb;

View File

@ -72,6 +72,8 @@ public class Prefs extends K9PreferenceActivity {
private static final String PREFERENCE_MESSAGELIST_SHOW_CONTACT_NAME = "messagelist_show_contact_name"; private static final String PREFERENCE_MESSAGELIST_SHOW_CONTACT_NAME = "messagelist_show_contact_name";
private static final String PREFERENCE_MESSAGELIST_CONTACT_NAME_COLOR = "messagelist_contact_name_color"; private static final String PREFERENCE_MESSAGELIST_CONTACT_NAME_COLOR = "messagelist_contact_name_color";
private static final String PREFERENCE_MESSAGELIST_SHOW_CONTACT_PICTURE = "messagelist_show_contact_picture"; private static final String PREFERENCE_MESSAGELIST_SHOW_CONTACT_PICTURE = "messagelist_show_contact_picture";
private static final String PREFERENCE_MESSAGELIST_COLORIZE_MISSING_CONTACT_PICTURES =
"messagelist_colorize_missing_contact_pictures";
private static final String PREFERENCE_MESSAGEVIEW_FIXEDWIDTH = "messageview_fixedwidth_font"; private static final String PREFERENCE_MESSAGEVIEW_FIXEDWIDTH = "messageview_fixedwidth_font";
private static final String PREFERENCE_MESSAGEVIEW_RETURN_TO_LIST = "messageview_return_to_list"; private static final String PREFERENCE_MESSAGEVIEW_RETURN_TO_LIST = "messageview_return_to_list";
@ -118,6 +120,7 @@ public class Prefs extends K9PreferenceActivity {
private CheckBoxPreference mShowContactName; private CheckBoxPreference mShowContactName;
private CheckBoxPreference mChangeContactNameColor; private CheckBoxPreference mChangeContactNameColor;
private CheckBoxPreference mShowContactPicture; private CheckBoxPreference mShowContactPicture;
private CheckBoxPreference mColorizeMissingContactPictures;
private CheckBoxPreference mFixedWidth; private CheckBoxPreference mFixedWidth;
private CheckBoxPreference mReturnToList; private CheckBoxPreference mReturnToList;
private CheckBoxPreference mShowNext; private CheckBoxPreference mShowNext;
@ -247,6 +250,10 @@ public class Prefs extends K9PreferenceActivity {
mShowContactPicture = (CheckBoxPreference)findPreference(PREFERENCE_MESSAGELIST_SHOW_CONTACT_PICTURE); mShowContactPicture = (CheckBoxPreference)findPreference(PREFERENCE_MESSAGELIST_SHOW_CONTACT_PICTURE);
mShowContactPicture.setChecked(K9.showContactPicture()); mShowContactPicture.setChecked(K9.showContactPicture());
mColorizeMissingContactPictures = (CheckBoxPreference)findPreference(
PREFERENCE_MESSAGELIST_COLORIZE_MISSING_CONTACT_PICTURES);
mColorizeMissingContactPictures.setChecked(K9.isColorizeMissingContactPictures());
mBackgroundAsUnreadIndicator = (CheckBoxPreference)findPreference(PREFERENCE_BACKGROUND_AS_UNREAD_INDICATOR); mBackgroundAsUnreadIndicator = (CheckBoxPreference)findPreference(PREFERENCE_BACKGROUND_AS_UNREAD_INDICATOR);
mBackgroundAsUnreadIndicator.setChecked(K9.useBackgroundAsUnreadIndicator()); mBackgroundAsUnreadIndicator.setChecked(K9.useBackgroundAsUnreadIndicator());
@ -456,6 +463,7 @@ public class Prefs extends K9PreferenceActivity {
K9.setMessageListSenderAboveSubject(mSenderAboveSubject.isChecked()); K9.setMessageListSenderAboveSubject(mSenderAboveSubject.isChecked());
K9.setShowContactName(mShowContactName.isChecked()); K9.setShowContactName(mShowContactName.isChecked());
K9.setShowContactPicture(mShowContactPicture.isChecked()); K9.setShowContactPicture(mShowContactPicture.isChecked());
K9.setColorizeMissingContactPictures(mColorizeMissingContactPictures.isChecked());
K9.setUseBackgroundAsUnreadIndicator(mBackgroundAsUnreadIndicator.isChecked()); K9.setUseBackgroundAsUnreadIndicator(mBackgroundAsUnreadIndicator.isChecked());
K9.setThreadedViewEnabled(mThreadedView.isChecked()); K9.setThreadedViewEnabled(mThreadedView.isChecked());
K9.setChangeContactNameColor(mChangeContactNameColor.isChecked()); K9.setChangeContactNameColor(mChangeContactNameColor.isChecked());

View File

@ -78,6 +78,7 @@ import com.fsck.k9.activity.misc.ContactPictureLoader;
import com.fsck.k9.cache.EmailProviderCache; import com.fsck.k9.cache.EmailProviderCache;
import com.fsck.k9.controller.MessagingController; import com.fsck.k9.controller.MessagingController;
import com.fsck.k9.fragment.ConfirmationDialogFragment.ConfirmationDialogFragmentListener; import com.fsck.k9.fragment.ConfirmationDialogFragment.ConfirmationDialogFragmentListener;
import com.fsck.k9.helper.ContactPicture;
import com.fsck.k9.helper.MergeCursorWithUniqueId; import com.fsck.k9.helper.MergeCursorWithUniqueId;
import com.fsck.k9.helper.MessageHelper; import com.fsck.k9.helper.MessageHelper;
import com.fsck.k9.helper.StringUtils; import com.fsck.k9.helper.StringUtils;
@ -788,8 +789,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
mCheckboxes = K9.messageListCheckboxes(); mCheckboxes = K9.messageListCheckboxes();
if (K9.showContactPicture()) { if (K9.showContactPicture()) {
mContactsPictureLoader = new ContactPictureLoader(getActivity(), mContactsPictureLoader = ContactPicture.getContactPictureLoader(getActivity());
R.drawable.ic_contact_picture);
} }
restoreInstanceState(savedInstanceState); restoreInstanceState(savedInstanceState);

View File

@ -0,0 +1,25 @@
package com.fsck.k9.helper;
import android.content.Context;
import android.util.TypedValue;
import com.fsck.k9.K9;
import com.fsck.k9.R;
import com.fsck.k9.activity.misc.ContactPictureLoader;
public class ContactPicture {
public static ContactPictureLoader getContactPictureLoader(Context context) {
final int defaultBgColor;
if (!K9.isColorizeMissingContactPictures()) {
TypedValue outValue = new TypedValue();
context.getTheme().resolveAttribute(R.attr.contactPictureFallbackDefaultBackgroundColor,
outValue, true);
defaultBgColor = outValue.data;
} else {
defaultBgColor = 0;
}
return new ContactPictureLoader(context, defaultBgColor);
}
}

View File

@ -225,6 +225,9 @@ public class GlobalSettings {
s.put("autofitWidth", Settings.versions( s.put("autofitWidth", Settings.versions(
new V(28, new BooleanSetting(true)) new V(28, new BooleanSetting(true))
)); ));
s.put("colorizeMissingContactPictures", Settings.versions(
new V(29, new BooleanSetting(true))
));
SETTINGS = Collections.unmodifiableMap(s); SETTINGS = Collections.unmodifiableMap(s);

View File

@ -24,6 +24,7 @@ import com.fsck.k9.FontSizes;
import com.fsck.k9.K9; import com.fsck.k9.K9;
import com.fsck.k9.R; import com.fsck.k9.R;
import com.fsck.k9.activity.misc.ContactPictureLoader; import com.fsck.k9.activity.misc.ContactPictureLoader;
import com.fsck.k9.helper.ContactPicture;
import com.fsck.k9.helper.Contacts; import com.fsck.k9.helper.Contacts;
import com.fsck.k9.Account; import com.fsck.k9.Account;
import com.fsck.k9.helper.MessageHelper; import com.fsck.k9.helper.MessageHelper;
@ -253,7 +254,7 @@ public class MessageHeader extends ScrollView implements OnClickListener {
if (K9.showContactPicture()) { if (K9.showContactPicture()) {
mContactBadge.setVisibility(View.VISIBLE); mContactBadge.setVisibility(View.VISIBLE);
mContactsPictureLoader = new ContactPictureLoader(mContext, R.drawable.ic_contact_picture); mContactsPictureLoader = ContactPicture.getContactPictureLoader(mContext);
} else { } else {
mContactBadge.setVisibility(View.GONE); mContactBadge.setVisibility(View.GONE);
} }