mirror of
https://github.com/oxen-io/session-android.git
synced 2025-02-19 20:08:27 +00:00
Refactor colorization to support dark theme.
// FREEBIE
This commit is contained in:
parent
eacfca37f2
commit
ce2f66ad17
@ -1,5 +1,6 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<attr name="theme_type" format="string"/>
|
||||
<attr name="conversation_list_item_background_selected" format="reference"/>
|
||||
<attr name="conversation_list_item_background_read" format="reference"/>
|
||||
<attr name="conversation_list_item_background_unread" format="reference"/>
|
||||
|
@ -3,6 +3,7 @@
|
||||
<resources xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<style name="TextSecure.LightNoActionBar" parent="@style/Theme.AppCompat.Light.NoActionBar">
|
||||
<item name="theme_type">light</item>
|
||||
<item name="actionBarStyle">@style/TextSecure.LightActionBar</item>
|
||||
<item name="actionBarTabBarStyle">@style/TextSecure.LightActionBar.TabBar</item>
|
||||
<item name="colorPrimary">@color/textsecure_primary</item>
|
||||
@ -12,6 +13,7 @@
|
||||
</style>
|
||||
|
||||
<style name="TextSecure.DarkNoActionBar" parent="@style/Theme.AppCompat.NoActionBar">
|
||||
<item name="theme_type">dark</item>
|
||||
<item name="actionBarStyle">@style/TextSecure.DarkActionBar</item>
|
||||
<item name="actionBarTabBarStyle">@style/TextSecure.DarkActionBar.TabBar</item>
|
||||
<item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat.Dark</item>
|
||||
@ -58,6 +60,7 @@
|
||||
</style>
|
||||
|
||||
<style name="TextSecure.LightTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
|
||||
<item name="theme_type">light</item>
|
||||
<item name="actionBarStyle">@style/TextSecure.LightActionBar</item>
|
||||
<item name="actionBarTabBarStyle">@style/TextSecure.LightActionBar.TabBar</item>
|
||||
<item name="colorPrimary">@color/textsecure_primary</item>
|
||||
@ -171,6 +174,7 @@
|
||||
</style>
|
||||
|
||||
<style name="TextSecure.DarkTheme" parent="@style/Theme.AppCompat">
|
||||
<item name="theme_type">dark</item>
|
||||
<item name="actionBarStyle">@style/TextSecure.DarkActionBar</item>
|
||||
<item name="actionBarTabBarStyle">@style/TextSecure.DarkActionBar.TabBar</item>
|
||||
<item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat.Dark</item>
|
||||
|
@ -54,6 +54,8 @@ import com.afollestad.materialdialogs.AlertDialogWrapper;
|
||||
import com.google.protobuf.ByteString;
|
||||
|
||||
import org.thoughtcrime.securesms.TransportOptions.OnTransportChangedListener;
|
||||
import org.thoughtcrime.securesms.color.MaterialColor;
|
||||
import org.thoughtcrime.securesms.color.ThemeType;
|
||||
import org.thoughtcrime.securesms.components.AnimatingToggle;
|
||||
import org.thoughtcrime.securesms.components.ComposeText;
|
||||
import org.thoughtcrime.securesms.components.SendButton;
|
||||
@ -61,7 +63,6 @@ import org.thoughtcrime.securesms.components.emoji.EmojiDrawer;
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiToggle;
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor;
|
||||
import org.thoughtcrime.securesms.contacts.ContactAccessor.ContactData;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactColors;
|
||||
import org.thoughtcrime.securesms.crypto.MasterCipher;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.crypto.SecurityEvent;
|
||||
@ -225,7 +226,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
initializeIme();
|
||||
|
||||
titleView.setTitle(recipients);
|
||||
setActionBarColor(recipients.getColor());
|
||||
setActionBarColor(recipients.getColor(this));
|
||||
setBlockedUserState(recipients);
|
||||
calculateCharactersRemaining();
|
||||
|
||||
@ -809,7 +810,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
public void run() {
|
||||
titleView.setTitle(recipients);
|
||||
setBlockedUserState(recipients);
|
||||
setActionBarColor(recipients.getColor());
|
||||
setActionBarColor(recipients.getColor(ConversationActivity.this));
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -1000,15 +1001,13 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
return future;
|
||||
}
|
||||
|
||||
private void setActionBarColor(Optional<Integer> color) {
|
||||
int colorPrimary = getResources().getColor(R.color.textsecure_primary);
|
||||
int colorPrimaryDark = getResources().getColor(R.color.textsecure_primary_dark);
|
||||
private void setActionBarColor(MaterialColor color) {
|
||||
ThemeType themeType = ThemeType.getCurrent(this);
|
||||
|
||||
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color.or(colorPrimary)));
|
||||
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color.toActionBarColor(themeType)));
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
if (color.isPresent()) getWindow().setStatusBarColor(ContactColors.getStatusTinted(color.get()).or(colorPrimaryDark));
|
||||
else getWindow().setStatusBarColor(colorPrimaryDark);
|
||||
getWindow().setStatusBarColor(color.toStatusBarColor(themeType));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.content.res.TypedArray;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
@ -39,6 +40,7 @@ import android.widget.Toast;
|
||||
import com.afollestad.materialdialogs.AlertDialogWrapper;
|
||||
|
||||
import org.thoughtcrime.securesms.ConversationFragment.SelectionClickListener;
|
||||
import org.thoughtcrime.securesms.color.ThemeType;
|
||||
import org.thoughtcrime.securesms.components.AvatarImageView;
|
||||
import org.thoughtcrime.securesms.components.ThumbnailView;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
@ -192,14 +194,14 @@ public class ConversationItem extends LinearLayout {
|
||||
private void setBubbleState(MessageRecord messageRecord) {
|
||||
int[] attributes = new int[]{R.attr.conversation_item_bubble_background};
|
||||
TypedArray colors = context.obtainStyledAttributes(attributes);
|
||||
int defaultColor = colors.getColor(0, 0xFFFFFF);
|
||||
int defaultColor = colors.getColor(0, Color.WHITE);
|
||||
|
||||
if (messageRecord.isOutgoing()) {
|
||||
bodyBubble.getBackground().setColorFilter(defaultColor, PorterDuff.Mode.MULTIPLY);
|
||||
} else {
|
||||
bodyBubble.getBackground().setColorFilter(messageRecord.getIndividualRecipient()
|
||||
.getColor()
|
||||
.or(defaultColor),
|
||||
.toConversationColor(ThemeType.getCurrent(context)),
|
||||
PorterDuff.Mode.MULTIPLY);
|
||||
}
|
||||
|
||||
|
@ -19,14 +19,17 @@ import android.support.v4.app.Fragment;
|
||||
import android.support.v4.preference.PreferenceFragment;
|
||||
import android.support.v7.widget.Toolbar;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.afollestad.materialdialogs.AlertDialogWrapper;
|
||||
|
||||
import org.thoughtcrime.securesms.color.MaterialColor;
|
||||
import org.thoughtcrime.securesms.color.MaterialColors;
|
||||
import org.thoughtcrime.securesms.color.ThemeType;
|
||||
import org.thoughtcrime.securesms.components.AvatarImageView;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactColors;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
import org.thoughtcrime.securesms.database.RecipientPreferenceDatabase.VibrateState;
|
||||
@ -36,7 +39,6 @@ import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.util.DynamicLanguage;
|
||||
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
|
||||
public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActivity implements Recipients.RecipientsModifiedListener
|
||||
{
|
||||
@ -117,17 +119,14 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
|
||||
}
|
||||
|
||||
private void setHeader(Recipients recipients) {
|
||||
Optional<Integer> color = recipients.getColor();
|
||||
ThemeType themeType = ThemeType.getCurrent(this);
|
||||
|
||||
this.avatar.setAvatar(recipients, true);
|
||||
this.title.setText(recipients.toShortString());
|
||||
this.toolbar.setBackgroundColor(color.or(getResources().getColor(R.color.textsecure_primary)));
|
||||
this.toolbar.setBackgroundColor(recipients.getColor(this).toActionBarColor(themeType));
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
int primaryDark = getResources().getColor(R.color.textsecure_primary_dark);
|
||||
|
||||
if (color.isPresent()) getWindow().setStatusBarColor(ContactColors.getStatusTinted(color.get()).or(primaryDark));
|
||||
else getWindow().setStatusBarColor(primaryDark);
|
||||
getWindow().setStatusBarColor(recipients.getColor(this).toStatusBarColor(themeType));
|
||||
}
|
||||
|
||||
if (recipients.isBlocked()) this.blockedIndicator.setVisibility(View.VISIBLE);
|
||||
@ -194,6 +193,7 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
|
||||
ListPreference vibratePreference = (ListPreference) this.findPreference(PREFERENCE_VIBRATE);
|
||||
ColorPreference colorPreference = (ColorPreference) this.findPreference(PREFERENCE_COLOR);
|
||||
Preference blockPreference = this.findPreference(PREFERENCE_BLOCK);
|
||||
ThemeType themeType = ThemeType.getCurrent(getActivity());
|
||||
|
||||
mutePreference.setChecked(recipients.isMuted());
|
||||
|
||||
@ -218,13 +218,9 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
|
||||
vibratePreference.setValueIndex(2);
|
||||
}
|
||||
|
||||
if (recipients.getColor().isPresent()) {
|
||||
colorPreference.setEnabled(true);
|
||||
colorPreference.setValue(recipients.getColor().get());
|
||||
} else {
|
||||
colorPreference.setEnabled(false);
|
||||
colorPreference.setValue(getResources().getColor(R.color.textsecure_primary));
|
||||
}
|
||||
colorPreference.setEnabled(recipients.isSingleRecipient() && !recipients.isGroupRecipient());
|
||||
colorPreference.setChoices(MaterialColors.CONVERSATION_PALETTE.asConversationColorArray(themeType));
|
||||
colorPreference.setValue(recipients.getColor(getActivity()).toActionBarColor(ThemeType.getCurrent(getActivity())));
|
||||
|
||||
if (!recipients.isSingleRecipient() || recipients.isGroupRecipient()) {
|
||||
blockPreference.setEnabled(false);
|
||||
@ -298,16 +294,20 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
|
||||
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
final int value = (Integer)newValue;
|
||||
final int value = (Integer) newValue;
|
||||
final MaterialColor selectedColor = MaterialColors.CONVERSATION_PALETTE.getByColor(value);
|
||||
final MaterialColor currentColor = recipients.getColor(getActivity());
|
||||
|
||||
if (preference.isEnabled() && value != recipients.getColor().get()) {
|
||||
recipients.setColor(Optional.of(value));
|
||||
if (selectedColor == null) return false;
|
||||
|
||||
if (preference.isEnabled() && !currentColor.equals(selectedColor)) {
|
||||
recipients.setColor(selectedColor);
|
||||
|
||||
new AsyncTask<Void, Void, Void>() {
|
||||
@Override
|
||||
protected Void doInBackground(Void... params) {
|
||||
DatabaseFactory.getRecipientPreferenceDatabase(getActivity())
|
||||
.setColor(recipients, value);
|
||||
.setColor(recipients, selectedColor);
|
||||
return null;
|
||||
}
|
||||
}.execute();
|
||||
|
@ -0,0 +1,28 @@
|
||||
package org.thoughtcrime.securesms.color;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
class BlueGreyMaterialColor extends MaterialColor {
|
||||
|
||||
static final String SERIALIZED_NAME = "blue_grey";
|
||||
|
||||
BlueGreyMaterialColor() {
|
||||
super(new HashMap<String, Integer>() {{
|
||||
put("50", 0xFFECEFF1);
|
||||
put("100", 0xFFCFD8DC);
|
||||
put("200", 0xFFB0BEC5);
|
||||
put("300", 0xFF90A4AE);
|
||||
put("400", 0xFF78909C);
|
||||
put("500", 0xFF607D8B);
|
||||
put("600", 0xFF546E7A);
|
||||
put("700", 0xFF455A64);
|
||||
put("800", 0xFF37474F);
|
||||
put("900", 0xFF263238);
|
||||
}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() {
|
||||
return SERIALIZED_NAME;
|
||||
}
|
||||
}
|
32
src/org/thoughtcrime/securesms/color/BlueMaterialColor.java
Normal file
32
src/org/thoughtcrime/securesms/color/BlueMaterialColor.java
Normal file
@ -0,0 +1,32 @@
|
||||
package org.thoughtcrime.securesms.color;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
class BlueMaterialColor extends MaterialColor {
|
||||
|
||||
static final String SERIALIZED_NAME = "blue";
|
||||
|
||||
BlueMaterialColor() {
|
||||
super(new HashMap<String, Integer>() {{
|
||||
put("50", 0xFFE3F2FD);
|
||||
put("100", 0xFFBBDEFB);
|
||||
put("200", 0xFF90CAF9);
|
||||
put("300", 0xFF64B5F6);
|
||||
put("400", 0xFF42A5F5);
|
||||
put("500", 0xFF2196F3);
|
||||
put("600", 0xFF1E88E5);
|
||||
put("700", 0xFF1976D2);
|
||||
put("800", 0xFF1565C0);
|
||||
put("900", 0xFF0D47A1);
|
||||
put("A100", 0xFF82B1FF);
|
||||
put("A200", 0xFF448AFF);
|
||||
put("A400", 0xFF2979FF);
|
||||
put("A700", 0xFF2962FF);
|
||||
}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() {
|
||||
return SERIALIZED_NAME;
|
||||
}
|
||||
}
|
28
src/org/thoughtcrime/securesms/color/BrownMaterialColor.java
Normal file
28
src/org/thoughtcrime/securesms/color/BrownMaterialColor.java
Normal file
@ -0,0 +1,28 @@
|
||||
package org.thoughtcrime.securesms.color;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
class BrownMaterialColor extends MaterialColor {
|
||||
|
||||
static final String SERIALIZED_NAME = "brown";
|
||||
|
||||
BrownMaterialColor() {
|
||||
super(new HashMap<String, Integer>() {{
|
||||
put("50", 0xFFEFEBE9);
|
||||
put("100", 0xFFD7CCC8);
|
||||
put("200", 0xFFBCAAA4);
|
||||
put("300", 0xFFA1887F);
|
||||
put("400", 0xFF8D6E63);
|
||||
put("500", 0xFF795548);
|
||||
put("600", 0xFF6D4C41);
|
||||
put("700", 0xFF5D4037);
|
||||
put("800", 0xFF4E342E);
|
||||
put("900", 0xFF3E2723);
|
||||
}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() {
|
||||
return SERIALIZED_NAME;
|
||||
}
|
||||
}
|
32
src/org/thoughtcrime/securesms/color/CyanMaterialColor.java
Normal file
32
src/org/thoughtcrime/securesms/color/CyanMaterialColor.java
Normal file
@ -0,0 +1,32 @@
|
||||
package org.thoughtcrime.securesms.color;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
class CyanMaterialColor extends MaterialColor {
|
||||
|
||||
static final String SERIALIZED_NAME = "cyan";
|
||||
|
||||
CyanMaterialColor() {
|
||||
super(new HashMap<String, Integer>() {{
|
||||
put("50", 0xFFE0F7FA);
|
||||
put("100", 0xFFB2EBF2);
|
||||
put("200", 0xFF80DEEA);
|
||||
put("300", 0xFF4DD0E1);
|
||||
put("400", 0xFF26C6DA);
|
||||
put("500", 0xFF00BCD4);
|
||||
put("600", 0xFF00ACC1);
|
||||
put("700", 0xFF0097A7);
|
||||
put("800", 0xFF00838F);
|
||||
put("900", 0xFF006064);
|
||||
put("A100", 0xFF84FFFF);
|
||||
put("A200", 0xFF18FFFF);
|
||||
put("A400", 0xFF00E5FF);
|
||||
put("A700", 0xFF00B8D4);
|
||||
}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() {
|
||||
return SERIALIZED_NAME;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package org.thoughtcrime.securesms.color;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
class DeepOrangeMaterialColor extends MaterialColor {
|
||||
|
||||
static final String SERIALIZED_NAME = "deep_orange";
|
||||
|
||||
DeepOrangeMaterialColor() {
|
||||
super(new HashMap<String, Integer>() {{
|
||||
put("50", 0xFFFBE9E7);
|
||||
put("100", 0xFFFFCCBC);
|
||||
put("200", 0xFFFFAB91);
|
||||
put("300", 0xFFFF8A65);
|
||||
put("400", 0xFFFF7043);
|
||||
put("500", 0xFFFF5722);
|
||||
put("600", 0xFFF4511E);
|
||||
put("700", 0xFFE64A19);
|
||||
put("800", 0xFFD84315);
|
||||
put("900", 0xFFBF360C);
|
||||
put("A100", 0xFFFF9E80);
|
||||
put("A200", 0xFFFF6E40);
|
||||
put("A400", 0xFFFF3D00);
|
||||
put("A700", 0xFFDD2C00);
|
||||
}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() {
|
||||
return SERIALIZED_NAME;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package org.thoughtcrime.securesms.color;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
class DeepPurpleMaterialColor extends MaterialColor {
|
||||
|
||||
static final String SERIALIZED_NAME = "deep_purple";
|
||||
|
||||
DeepPurpleMaterialColor() {
|
||||
super(new HashMap<String, Integer>() {{
|
||||
put("50",0xFFEDE7F6);
|
||||
put("100", 0xFFD1C4E9);
|
||||
put("200", 0xFFB39DDB);
|
||||
put("300", 0xFF9575CD);
|
||||
put("400", 0xFF7E57C2);
|
||||
put("500", 0xFF673AB7);
|
||||
put("600", 0xFF5E35B1);
|
||||
put("700", 0xFF512DA8);
|
||||
put("800", 0xFF4527A0);
|
||||
put("900", 0xFF311B92);
|
||||
put("A100", 0xFFB388FF);
|
||||
put("A200", 0xFF7C4DFF);
|
||||
put("A400", 0xFF651FFF);
|
||||
put("A700", 0xFF6200EA);
|
||||
}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() {
|
||||
return SERIALIZED_NAME;
|
||||
}
|
||||
}
|
32
src/org/thoughtcrime/securesms/color/GreenMaterialColor.java
Normal file
32
src/org/thoughtcrime/securesms/color/GreenMaterialColor.java
Normal file
@ -0,0 +1,32 @@
|
||||
package org.thoughtcrime.securesms.color;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
class GreenMaterialColor extends MaterialColor {
|
||||
|
||||
static final String SERIALIZED_NAME = "green";
|
||||
|
||||
GreenMaterialColor() {
|
||||
super(new HashMap<String, Integer>() {{
|
||||
put("50", 0xFFE8F5E9);
|
||||
put("100", 0xFFC8E6C9);
|
||||
put("200", 0xFFA5D6A7);
|
||||
put("300", 0xFF81C784);
|
||||
put("400", 0xFF66BB6A);
|
||||
put("500", 0xFF4CAF50);
|
||||
put("600", 0xFF43A047);
|
||||
put("700", 0xFF388E3C);
|
||||
put("800", 0xFF2E7D32);
|
||||
put("900", 0xFF1B5E20);
|
||||
put("A100", 0xFFB9F6CA);
|
||||
put("A200", 0xFF69F0AE);
|
||||
put("A400", 0xFF00E676);
|
||||
put("A700", 0xFF00C853);
|
||||
}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() {
|
||||
return SERIALIZED_NAME;
|
||||
}
|
||||
}
|
27
src/org/thoughtcrime/securesms/color/GreyMaterialColor.java
Normal file
27
src/org/thoughtcrime/securesms/color/GreyMaterialColor.java
Normal file
@ -0,0 +1,27 @@
|
||||
package org.thoughtcrime.securesms.color;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class GreyMaterialColor extends MaterialColor {
|
||||
|
||||
static final String SERIALIZED_NAME = "grey";
|
||||
|
||||
GreyMaterialColor() {
|
||||
super(new HashMap<String, Integer>(){{
|
||||
put("50", 0xFFFAFAFA);
|
||||
put("100", 0xFFF5F5F5);
|
||||
put("200", 0xFFEEEEEE);
|
||||
put("300", 0xFFE0E0E0);
|
||||
put("400", 0xFFBDBDBD);
|
||||
put("500", 0xFF9E9E9E);
|
||||
put("600", 0xFF757575);
|
||||
put("700", 0xFF616161);
|
||||
put("800", 0xFF424242);
|
||||
put("900", 0xFF212121);
|
||||
}});
|
||||
}
|
||||
@Override
|
||||
public String serialize() {
|
||||
return SERIALIZED_NAME;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package org.thoughtcrime.securesms.color;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
class IndigoMaterialColor extends MaterialColor {
|
||||
|
||||
static final String SERIALIZED_NAME = "indigo";
|
||||
|
||||
IndigoMaterialColor() {
|
||||
super(new HashMap<String, Integer>(){{
|
||||
put("50", 0xFFE8EAF6);
|
||||
put("100", 0xFFC5CAE9);
|
||||
put("200", 0xFF9FA8DA);
|
||||
put("300", 0xFF7986CB);
|
||||
put("400", 0xFF5C6BC0);
|
||||
put("500", 0xFF3F51B5);
|
||||
put("600", 0xFF3949AB);
|
||||
put("700", 0xFF303F9F);
|
||||
put("800", 0xFF283593);
|
||||
put("900", 0xFF1A237E);
|
||||
put("A100", 0xFF8C9EFF);
|
||||
put("A200", 0xFF536DFE);
|
||||
put("A400", 0xFF3D5AFE);
|
||||
put("A700", 0xFF304FFE);
|
||||
}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() {
|
||||
return SERIALIZED_NAME;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package org.thoughtcrime.securesms.color;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
class LightBlueMaterialColor extends MaterialColor {
|
||||
|
||||
static final String SERIALIZED_NAME = "light_blue";
|
||||
|
||||
LightBlueMaterialColor() {
|
||||
super(new HashMap<String, Integer>() {{
|
||||
put("50", 0xFFE1F5FE);
|
||||
put("100", 0xFFB3E5FC);
|
||||
put("200", 0xFF81D4FA);
|
||||
put("300", 0xFF4FC3F7);
|
||||
put("400", 0xFF29B6F6);
|
||||
put("500", 0xFF03A9F4);
|
||||
put("600", 0xFF039BE5);
|
||||
put("700", 0xFF0288D1);
|
||||
put("800", 0xFF0277BD);
|
||||
put("900", 0xFF01579B);
|
||||
put("A100", 0xFF80D8FF);
|
||||
put("A200", 0xFF40C4FF);
|
||||
put("A400", 0xFF00B0FF);
|
||||
put("A700", 0xFF0091EA);
|
||||
}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() {
|
||||
return SERIALIZED_NAME;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package org.thoughtcrime.securesms.color;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
class LightGreenMaterialColor extends MaterialColor {
|
||||
|
||||
static final String SERIALIZED_NAME = "light_green";
|
||||
|
||||
LightGreenMaterialColor() {
|
||||
super(new HashMap<String, Integer>() {{
|
||||
put("50", 0xFFF1F8E9);
|
||||
put("100", 0xFFDCEDC8);
|
||||
put("200", 0xFFC5E1A5);
|
||||
put("300", 0xFFAED581);
|
||||
put("400", 0xFF9CCC65);
|
||||
put("500", 0xFF8BC34A);
|
||||
put("600", 0xFF7CB342);
|
||||
put("700", 0xFF689F38);
|
||||
put("800", 0xFF558B2F);
|
||||
put("900", 0xFF33691E);
|
||||
put("A100", 0xFFCCFF90);
|
||||
put("A200", 0xFFB2FF59);
|
||||
put("A400", 0xFF76FF03);
|
||||
put("A700", 0xFF64DD17);
|
||||
}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() {
|
||||
return SERIALIZED_NAME;
|
||||
}
|
||||
}
|
73
src/org/thoughtcrime/securesms/color/MaterialColor.java
Normal file
73
src/org/thoughtcrime/securesms/color/MaterialColor.java
Normal file
@ -0,0 +1,73 @@
|
||||
package org.thoughtcrime.securesms.color;
|
||||
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public abstract class MaterialColor {
|
||||
|
||||
private final Map<String, Integer> colorWeightMap;
|
||||
|
||||
protected MaterialColor(Map<String, Integer> colorWeightMap) {
|
||||
this.colorWeightMap = colorWeightMap;
|
||||
}
|
||||
|
||||
public int toConversationColor(ThemeType themeType) {
|
||||
if (themeType == ThemeType.DARK) return colorWeightMap.get("900");
|
||||
else return colorWeightMap.get("500");
|
||||
}
|
||||
|
||||
public int toActionBarColor(ThemeType themeType) {
|
||||
return toConversationColor(themeType);
|
||||
}
|
||||
|
||||
public int toStatusBarColor(ThemeType themeType) {
|
||||
return colorWeightMap.get("700");
|
||||
}
|
||||
|
||||
public boolean represents(int colorValue) {
|
||||
return colorWeightMap.values().contains(colorValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object other) {
|
||||
if (other == null || !(other instanceof MaterialColor)) return false;
|
||||
return serialize().equals(((MaterialColor)other).serialize());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Util.hashCode(serialize());
|
||||
}
|
||||
|
||||
public abstract String serialize();
|
||||
|
||||
public static MaterialColor fromSerialized(String serialized) throws UnknownColorException {
|
||||
switch (serialized) {
|
||||
case RedMaterialColor.SERIALIZED_NAME: return new RedMaterialColor();
|
||||
case PinkMaterialColor.SERIALIZED_NAME: return new PinkMaterialColor();
|
||||
case PurpleMaterialColor.SERIALIZED_NAME: return new PurpleMaterialColor();
|
||||
case DeepPurpleMaterialColor.SERIALIZED_NAME: return new DeepPurpleMaterialColor();
|
||||
case IndigoMaterialColor.SERIALIZED_NAME: return new IndigoMaterialColor();
|
||||
case BlueMaterialColor.SERIALIZED_NAME: return new BlueMaterialColor();
|
||||
case LightBlueMaterialColor.SERIALIZED_NAME: return new LightBlueMaterialColor();
|
||||
case CyanMaterialColor.SERIALIZED_NAME: return new CyanMaterialColor();
|
||||
case TealMaterialColor.SERIALIZED_NAME: return new TealMaterialColor();
|
||||
case GreenMaterialColor.SERIALIZED_NAME: return new GreenMaterialColor();
|
||||
case LightGreenMaterialColor.SERIALIZED_NAME: return new LightGreenMaterialColor();
|
||||
case OrangeMaterialColor.SERIALIZED_NAME: return new OrangeMaterialColor();
|
||||
case DeepOrangeMaterialColor.SERIALIZED_NAME: return new DeepOrangeMaterialColor();
|
||||
case BrownMaterialColor.SERIALIZED_NAME: return new BrownMaterialColor();
|
||||
case GreyMaterialColor.SERIALIZED_NAME: return new GreyMaterialColor();
|
||||
case BlueGreyMaterialColor.SERIALIZED_NAME: return new BlueGreyMaterialColor();
|
||||
|
||||
default: throw new UnknownColorException("Unknown color: " + serialized);
|
||||
}
|
||||
}
|
||||
|
||||
public static class UnknownColorException extends Exception {
|
||||
public UnknownColorException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
}
|
76
src/org/thoughtcrime/securesms/color/MaterialColors.java
Normal file
76
src/org/thoughtcrime/securesms/color/MaterialColors.java
Normal file
@ -0,0 +1,76 @@
|
||||
package org.thoughtcrime.securesms.color;
|
||||
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class MaterialColors {
|
||||
|
||||
public static final MaterialColor GREY = new GreyMaterialColor();
|
||||
|
||||
public static final MaterialColorList CONVERSATION_PALETTE = new MaterialColorList(new ArrayList<>(Arrays.asList(
|
||||
new RedMaterialColor(),
|
||||
new PinkMaterialColor(),
|
||||
new PurpleMaterialColor(),
|
||||
new DeepPurpleMaterialColor(),
|
||||
new IndigoMaterialColor(),
|
||||
new BlueMaterialColor(),
|
||||
new LightBlueMaterialColor(),
|
||||
new CyanMaterialColor(),
|
||||
new TealMaterialColor(),
|
||||
new GreenMaterialColor(),
|
||||
new LightGreenMaterialColor(),
|
||||
// Lime
|
||||
// Yellow
|
||||
// Amber
|
||||
new OrangeMaterialColor(),
|
||||
new DeepOrangeMaterialColor(),
|
||||
new BrownMaterialColor(),
|
||||
// Grey
|
||||
new BlueGreyMaterialColor()
|
||||
)));
|
||||
|
||||
public static class MaterialColorList {
|
||||
|
||||
private final List<MaterialColor> colors;
|
||||
|
||||
private MaterialColorList(List<MaterialColor> colors) {
|
||||
this.colors = colors;
|
||||
}
|
||||
|
||||
public MaterialColor get(int index) {
|
||||
return colors.get(index);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return colors.size();
|
||||
}
|
||||
|
||||
public @Nullable MaterialColor getByColor(int colorValue) {
|
||||
for (MaterialColor color : colors) {
|
||||
if (color.represents(colorValue)) {
|
||||
return color;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public int[] asConversationColorArray(ThemeType themeType) {
|
||||
int[] results = new int[colors.size()];
|
||||
int index = 0;
|
||||
|
||||
for (MaterialColor color : colors) {
|
||||
results[index++] = color.toConversationColor(themeType);
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -0,0 +1,32 @@
|
||||
package org.thoughtcrime.securesms.color;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
class OrangeMaterialColor extends MaterialColor {
|
||||
|
||||
static final String SERIALIZED_NAME = "orange";
|
||||
|
||||
OrangeMaterialColor() {
|
||||
super(new HashMap<String, Integer>() {{
|
||||
put("50", 0xFFFFF3E0);
|
||||
put("100", 0xFFFFE0B2);
|
||||
put("200", 0xFFFFCC80);
|
||||
put("300", 0xFFFFB74D);
|
||||
put("400", 0xFFFFA726);
|
||||
put("500", 0xFFFF9800);
|
||||
put("600", 0xFFFB8C00);
|
||||
put("700", 0xFFF57C00);
|
||||
put("800", 0xFFEF6C00);
|
||||
put("900", 0xFFE65100);
|
||||
put("A100", 0xFFFFD180);
|
||||
put("A200", 0xFFFFAB40);
|
||||
put("A400", 0xFFFF9100);
|
||||
put("A700", 0xFFFF6D00);
|
||||
}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() {
|
||||
return SERIALIZED_NAME;
|
||||
}
|
||||
}
|
32
src/org/thoughtcrime/securesms/color/PinkMaterialColor.java
Normal file
32
src/org/thoughtcrime/securesms/color/PinkMaterialColor.java
Normal file
@ -0,0 +1,32 @@
|
||||
package org.thoughtcrime.securesms.color;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class PinkMaterialColor extends MaterialColor {
|
||||
|
||||
static final String SERIALIZED_NAME = "pink";
|
||||
|
||||
PinkMaterialColor() {
|
||||
super(new HashMap<String, Integer>() {{
|
||||
put("50", 0xFFFCE4EC);
|
||||
put("100", 0xFFF8BBD0);
|
||||
put("200", 0xFFF48FB1);
|
||||
put("300", 0xFFF06292);
|
||||
put("400", 0xFFEC407A);
|
||||
put("500", 0xFFE91E63);
|
||||
put("600", 0xFFD81B60);
|
||||
put("700", 0xFFC2185B);
|
||||
put("800", 0xFFAD1457);
|
||||
put("900", 0xFF880E4F);
|
||||
put("A100", 0xFFFF80AB);
|
||||
put("A200", 0xFFFF4081);
|
||||
put("A400", 0xFFF50057);
|
||||
put("A700", 0xFFC51162);
|
||||
}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() {
|
||||
return SERIALIZED_NAME;
|
||||
}
|
||||
}
|
@ -0,0 +1,32 @@
|
||||
package org.thoughtcrime.securesms.color;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
class PurpleMaterialColor extends MaterialColor {
|
||||
|
||||
static final String SERIALIZED_NAME = "purple";
|
||||
|
||||
PurpleMaterialColor() {
|
||||
super(new HashMap<String, Integer>() {{
|
||||
put("50", 0xFFF3E5F5);
|
||||
put("100", 0xFFE1BEE7);
|
||||
put("200", 0xFFCE93D8);
|
||||
put("300", 0xFFBA68C8);
|
||||
put("400", 0xFFAB47BC);
|
||||
put("500", 0xFF9C27B0);
|
||||
put("600", 0xFF8E24AA);
|
||||
put("700", 0xFF7B1FA2);
|
||||
put("800", 0xFF6A1B9A);
|
||||
put("900", 0xFF4A148C);
|
||||
put("A100", 0xFFEA80FC);
|
||||
put("A200", 0xFFE040FB);
|
||||
put("A400", 0xFFD500F9);
|
||||
put("A700", 0xFFAA00FF);
|
||||
}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() {
|
||||
return SERIALIZED_NAME;
|
||||
}
|
||||
}
|
32
src/org/thoughtcrime/securesms/color/RedMaterialColor.java
Normal file
32
src/org/thoughtcrime/securesms/color/RedMaterialColor.java
Normal file
@ -0,0 +1,32 @@
|
||||
package org.thoughtcrime.securesms.color;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class RedMaterialColor extends MaterialColor {
|
||||
|
||||
static final String SERIALIZED_NAME = "red";
|
||||
|
||||
RedMaterialColor() {
|
||||
super(new HashMap<String, Integer>() {{
|
||||
put("50", 0xFFFFEBEE);
|
||||
put("100", 0xFFFFCDD2);
|
||||
put("200", 0xFFEF9A9A);
|
||||
put("300", 0xFFE57373);
|
||||
put("400", 0xFFEF5350);
|
||||
put("500", 0xFFF44336);
|
||||
put("600", 0xFFE53935);
|
||||
put("700", 0xFFD32F2F);
|
||||
put("800", 0xFFC62828);
|
||||
put("900", 0xFFB71C1C);
|
||||
put("A100", 0xFFFF8A80);
|
||||
put("A200", 0xFFFF5252);
|
||||
put("A400", 0xFFFF1744);
|
||||
put("A700", 0xFFD50000);
|
||||
}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() {
|
||||
return SERIALIZED_NAME;
|
||||
}
|
||||
}
|
32
src/org/thoughtcrime/securesms/color/TealMaterialColor.java
Normal file
32
src/org/thoughtcrime/securesms/color/TealMaterialColor.java
Normal file
@ -0,0 +1,32 @@
|
||||
package org.thoughtcrime.securesms.color;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
class TealMaterialColor extends MaterialColor {
|
||||
|
||||
static final String SERIALIZED_NAME = "teal";
|
||||
|
||||
TealMaterialColor() {
|
||||
super(new HashMap<String, Integer>() {{
|
||||
put("50", 0xFFE0F2F1);
|
||||
put("100", 0xFFB2DFDB);
|
||||
put("200", 0xFF80CBC4);
|
||||
put("300", 0xFF4DB6AC);
|
||||
put("400", 0xFF26A69A);
|
||||
put("500", 0xFF009688);
|
||||
put("600", 0xFF00897B);
|
||||
put("700", 0xFF00796B);
|
||||
put("800", 0xFF00695C);
|
||||
put("900", 0xFF004D40);
|
||||
put("A100", 0xFFA7FFEB);
|
||||
put("A200", 0xFF64FFDA);
|
||||
put("A400", 0xFF1DE9B6);
|
||||
put("A700", 0xFF00BFA5);
|
||||
}});
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() {
|
||||
return SERIALIZED_NAME;
|
||||
}
|
||||
}
|
32
src/org/thoughtcrime/securesms/color/ThemeType.java
Normal file
32
src/org/thoughtcrime/securesms/color/ThemeType.java
Normal file
@ -0,0 +1,32 @@
|
||||
package org.thoughtcrime.securesms.color;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.TypedValue;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
|
||||
public enum ThemeType {
|
||||
LIGHT("light"), DARK("dark");
|
||||
|
||||
private static final String TAG = ThemeType.class.getSimpleName();
|
||||
|
||||
private final String type;
|
||||
|
||||
private ThemeType(String type) {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public static ThemeType getCurrent(Context context) {
|
||||
TypedValue outValue = new TypedValue();
|
||||
context.getTheme().resolveAttribute(R.attr.theme_type, outValue, true);
|
||||
|
||||
if ("dark".equals(outValue.coerceToString())) return ThemeType.DARK;
|
||||
else return ThemeType.LIGHT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type;
|
||||
}
|
||||
|
||||
}
|
@ -10,6 +10,8 @@ import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.color.MaterialColor;
|
||||
import org.thoughtcrime.securesms.color.ThemeType;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactColors;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactPhotoFactory;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
@ -37,12 +39,14 @@ public class AvatarImageView extends ImageView {
|
||||
}
|
||||
|
||||
public void setAvatar(@Nullable Recipients recipients, boolean quickContactEnabled) {
|
||||
ThemeType themeType = ThemeType.getCurrent(getContext());
|
||||
|
||||
if (recipients != null) {
|
||||
int backgroundColor = recipients.getColor().or(ContactColors.UNKNOWN_COLOR);
|
||||
setImageDrawable(recipients.getContactPhoto().asDrawable(getContext(), backgroundColor, inverted));
|
||||
MaterialColor backgroundColor = recipients.getColor(getContext());
|
||||
setImageDrawable(recipients.getContactPhoto().asDrawable(getContext(), backgroundColor.toConversationColor(themeType), inverted));
|
||||
setAvatarClickHandler(recipients, quickContactEnabled);
|
||||
} else {
|
||||
setImageDrawable(ContactPhotoFactory.getDefaultContactPhoto(null).asDrawable(getContext(), ContactColors.UNKNOWN_COLOR, inverted));
|
||||
setImageDrawable(ContactPhotoFactory.getDefaultContactPhoto(null).asDrawable(getContext(), ContactColors.UNKNOWN_COLOR.toConversationColor(themeType), inverted));
|
||||
setOnClickListener(null);
|
||||
}
|
||||
}
|
||||
|
@ -1,164 +1,61 @@
|
||||
package org.thoughtcrime.securesms.contacts.avatars;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.SparseIntArray;
|
||||
|
||||
import com.amulyakhare.textdrawable.util.ColorGenerator;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.color.MaterialColor;
|
||||
import org.thoughtcrime.securesms.color.MaterialColors;
|
||||
import org.thoughtcrime.securesms.color.ThemeType;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
public class ContactColors {
|
||||
|
||||
public static final int UNKNOWN_COLOR = 0xff9E9E9E;
|
||||
|
||||
private static final int RED_300 = 0xffE57373;
|
||||
private static final int RED_500 = 0xffF44336;
|
||||
private static final int RED_700 = 0xFFD32F2F;
|
||||
private static final int PINK_300 = 0xffF06292;
|
||||
private static final int PINK_500 = 0xffE91E63;
|
||||
private static final int PINK_700 = 0xFFC2185B;
|
||||
private static final int PURPLE_300 = 0xffBA68C8;
|
||||
private static final int PURPLE_500 = 0Xff9C27B0;
|
||||
private static final int PURPLE_700 = 0xFF7B1FA2;
|
||||
private static final int DEEP_PURPLE_300 = 0xff9575CD;
|
||||
private static final int DEEP_PURPLE_500 = 0xff673AB7;
|
||||
private static final int DEEP_PURPLE_700 = 0xFF512DA8;
|
||||
private static final int INDIGO_300 = 0xff7986CB;
|
||||
private static final int INDIGO_500 = 0xff3F51B5;
|
||||
private static final int INDIGO_700 = 0xff303F9F;
|
||||
private static final int BLUE_300 = 0xff64B5F6;
|
||||
private static final int BLUE_500 = 0xff2196F3;
|
||||
private static final int BLUE_700 = 0xFF1976D2;
|
||||
private static final int LIGHT_BLUE_300 = 0xff4FC3F7;
|
||||
private static final int LIGHT_BLUE_500 = 0xff03A9F4;
|
||||
private static final int LIGHT_BLUE_700 = 0xFF0288D1;
|
||||
private static final int CYAN_300 = 0xff4DD0E1;
|
||||
private static final int CYAN_500 = 0xff00BCD4;
|
||||
private static final int CYAN_700 = 0xFF0097A7;
|
||||
private static final int TEAL_300 = 0xFF4DB6AC;
|
||||
private static final int TEAL_500 = 0xff009688;
|
||||
private static final int TEAL_700 = 0xFF00796B;
|
||||
private static final int GREEN_300 = 0xFF81C784;
|
||||
private static final int GREEN_500 = 0xff4CAF50;
|
||||
private static final int GREEN_700 = 0xFF388E3C;
|
||||
private static final int LIGHT_GREEN_300 = 0xFFAED581;
|
||||
private static final int LIGHT_GREEN_500 = 0xff8BC34A;
|
||||
private static final int LIGHT_GREEN_700 = 0xFF689F38;
|
||||
private static final int LIME_300 = 0xFFDCE775;
|
||||
private static final int LIME_500 = 0XFFCDDC39;
|
||||
private static final int LIME_700 = 0xFFAFB42B;
|
||||
private static final int YELLOW_300 = 0xFFFFF176;
|
||||
private static final int YELLOW_500 = 0xffFFEB3B;
|
||||
private static final int YELLOW_700 = 0xFFFBC02D;
|
||||
private static final int AMBER_300 = 0xFFFFD54F;
|
||||
private static final int AMBER_500 = 0XFFFFC107;
|
||||
private static final int AMBER_700 = 0xFFFFA000;
|
||||
private static final int ORANGE_300 = 0xFFFFB74D;
|
||||
private static final int ORANGE_500 = 0xffFF9800;
|
||||
private static final int ORANGE_700 = 0xFFF57C00;
|
||||
private static final int DEEP_ORANGE_300 = 0xFFFF8A65;
|
||||
private static final int DEEP_ORANGE_500 = 0xffFF5722;
|
||||
private static final int DEEP_ORANGE_700 = 0xFFE64A19;
|
||||
private static final int BROWN_300 = 0xFFA1887F;
|
||||
private static final int BROWN_500 = 0xff795548;
|
||||
private static final int BROWN_700 = 0xFF5D4037;
|
||||
private static final int BLUE_GREY_300 = 0xFF90A4AE;
|
||||
private static final int BLUE_GREY_500 = 0xff607D8B;
|
||||
private static final int BLUE_GREY_700 = 0xFF455A64;
|
||||
|
||||
private static final List<Integer> MATERIAL_300 = new ArrayList<>(Arrays.asList(
|
||||
RED_300,
|
||||
PINK_300,
|
||||
PURPLE_300,
|
||||
DEEP_PURPLE_300,
|
||||
INDIGO_300,
|
||||
BLUE_300,
|
||||
LIGHT_BLUE_300,
|
||||
CYAN_300,
|
||||
TEAL_300,
|
||||
GREEN_300,
|
||||
LIGHT_GREEN_300,
|
||||
LIME_300,
|
||||
AMBER_300,
|
||||
ORANGE_300,
|
||||
DEEP_ORANGE_300,
|
||||
BROWN_300,
|
||||
BLUE_GREY_300)
|
||||
);
|
||||
|
||||
private static final List<Integer> MATERIAL_500 = new ArrayList<>(Arrays.asList(
|
||||
RED_500,
|
||||
PINK_500,
|
||||
PURPLE_500,
|
||||
DEEP_PURPLE_500,
|
||||
INDIGO_500,
|
||||
BLUE_500,
|
||||
LIGHT_BLUE_500,
|
||||
CYAN_500,
|
||||
TEAL_500,
|
||||
GREEN_500,
|
||||
LIGHT_GREEN_500,
|
||||
// LIME_500,
|
||||
AMBER_500,
|
||||
ORANGE_500,
|
||||
DEEP_ORANGE_500,
|
||||
BROWN_500,
|
||||
BLUE_GREY_500)
|
||||
);
|
||||
|
||||
private static final SparseIntArray MATERIAL_500_TO_700 = new SparseIntArray() {{
|
||||
put(RED_500, RED_700);
|
||||
put(PINK_500, PINK_700);
|
||||
put(PURPLE_500, PURPLE_700);
|
||||
put(DEEP_PURPLE_500, DEEP_PURPLE_700);
|
||||
put(INDIGO_500, INDIGO_700);
|
||||
put(BLUE_500, BLUE_700);
|
||||
put(LIGHT_BLUE_500, LIGHT_BLUE_700);
|
||||
put(CYAN_500, CYAN_700);
|
||||
put(TEAL_500, TEAL_700);
|
||||
put(GREEN_500, GREEN_700);
|
||||
put(LIGHT_GREEN_500, LIGHT_GREEN_700);
|
||||
// put(LIME_500, LIME_700);
|
||||
put(AMBER_500, AMBER_700);
|
||||
put(ORANGE_500, ORANGE_700);
|
||||
put(DEEP_ORANGE_500, DEEP_ORANGE_700);
|
||||
put(BROWN_500, BROWN_700);
|
||||
put(BLUE_GREY_500, BLUE_GREY_700);
|
||||
}};
|
||||
|
||||
private static final SparseIntArray MATERIAL_300_TO_700 = new SparseIntArray() {{
|
||||
put(RED_300, RED_700);
|
||||
put(PINK_300, PINK_700);
|
||||
put(PURPLE_300, PURPLE_700);
|
||||
put(DEEP_PURPLE_300, DEEP_PURPLE_700);
|
||||
put(INDIGO_300, INDIGO_700);
|
||||
put(BLUE_300, BLUE_700);
|
||||
put(LIGHT_BLUE_300, LIGHT_BLUE_700);
|
||||
put(CYAN_300, CYAN_700);
|
||||
put(TEAL_300, TEAL_700);
|
||||
put(GREEN_300, GREEN_700);
|
||||
put(LIGHT_GREEN_300, LIGHT_GREEN_700);
|
||||
put(LIME_300, LIME_700);
|
||||
put(AMBER_300, AMBER_700);
|
||||
put(ORANGE_300, ORANGE_700);
|
||||
put(DEEP_ORANGE_300, DEEP_ORANGE_700);
|
||||
put(BROWN_300, BROWN_700);
|
||||
put(BLUE_GREY_300, BLUE_GREY_700);
|
||||
}};
|
||||
|
||||
private static final ColorGenerator MATERIAL_GENERATOR = ColorGenerator.create(MATERIAL_500);
|
||||
|
||||
public static int generateFor(@NonNull String name) {
|
||||
return MATERIAL_GENERATOR.getColor(name);
|
||||
public static final MaterialColor UNKNOWN_COLOR = MaterialColors.GREY;
|
||||
|
||||
public static MaterialColor generateFor(@NonNull String name) {
|
||||
return MaterialColors.CONVERSATION_PALETTE.get(Math.abs(name.hashCode()) % MaterialColors.CONVERSATION_PALETTE.size());
|
||||
}
|
||||
|
||||
public static Optional<Integer> getStatusTinted(int color) {
|
||||
int statusTinted = MATERIAL_500_TO_700.get(color, -1);
|
||||
return statusTinted == -1 ? Optional.<Integer>absent() : Optional.of(statusTinted);
|
||||
public static MaterialColor getGroupColor(Context context) {
|
||||
final int actionBarColor = context.getResources().getColor(R.color.textsecure_primary);
|
||||
final int statusBarColor = context.getResources().getColor(R.color.textsecure_primary_dark);
|
||||
|
||||
return new MaterialColor(new HashMap<String, Integer>()) {
|
||||
@Override
|
||||
public int toConversationColor(ThemeType themeType) {
|
||||
return UNKNOWN_COLOR.toConversationColor(themeType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int toActionBarColor(ThemeType themeType) {
|
||||
return actionBarColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int toStatusBarColor(ThemeType themeType) {
|
||||
return statusBarColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serialize() {
|
||||
return "group_color";
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// public static Optional<Integer> getStatusTinted(int color) {
|
||||
// int statusTinted = MATERIAL_500_TO_700.get(color, -1);
|
||||
// return statusTinted == -1 ? Optional.<Integer>absent() : Optional.of(statusTinted);
|
||||
// }
|
||||
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.color.MaterialColor;
|
||||
import org.thoughtcrime.securesms.recipients.Recipients;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
@ -57,7 +58,7 @@ public class RecipientPreferenceDatabase extends Database {
|
||||
NOTIFICATION + " TEXT DEFAULT NULL, " +
|
||||
VIBRATE + " INTEGER DEFAULT " + VibrateState.DEFAULT.getId() + ", " +
|
||||
MUTE_UNTIL + " INTEGER DEFAULT 0, " +
|
||||
COLOR + " INTEGER DEFAULT -1);";
|
||||
COLOR + " TEXT DEFAULT NULL);";
|
||||
|
||||
public RecipientPreferenceDatabase(Context context, SQLiteOpenHelper databaseHelper) {
|
||||
super(context, databaseHelper);
|
||||
@ -89,16 +90,23 @@ public class RecipientPreferenceDatabase extends Database {
|
||||
String notification = cursor.getString(cursor.getColumnIndexOrThrow(NOTIFICATION));
|
||||
int vibrateState = cursor.getInt(cursor.getColumnIndexOrThrow(VIBRATE));
|
||||
long muteUntil = cursor.getLong(cursor.getColumnIndexOrThrow(MUTE_UNTIL));
|
||||
int color = cursor.getInt(cursor.getColumnIndexOrThrow(COLOR));
|
||||
String serializedColor = cursor.getString(cursor.getColumnIndexOrThrow(COLOR));
|
||||
Uri notificationUri = notification == null ? null : Uri.parse(notification);
|
||||
|
||||
MaterialColor color;
|
||||
|
||||
try {
|
||||
color = serializedColor == null ? null : MaterialColor.fromSerialized(serializedColor);
|
||||
} catch (MaterialColor.UnknownColorException e) {
|
||||
Log.w(TAG, e);
|
||||
color = null;
|
||||
}
|
||||
|
||||
Log.w(TAG, "Muted until: " + muteUntil);
|
||||
|
||||
return Optional.of(new RecipientsPreferences(blocked, muteUntil,
|
||||
VibrateState.fromId(vibrateState),
|
||||
notificationUri,
|
||||
color == -1 ? Optional.<Integer>absent() :
|
||||
Optional.of(color)));
|
||||
notificationUri, color));
|
||||
}
|
||||
|
||||
return Optional.absent();
|
||||
@ -107,9 +115,9 @@ public class RecipientPreferenceDatabase extends Database {
|
||||
}
|
||||
}
|
||||
|
||||
public void setColor(Recipients recipients, int color) {
|
||||
public void setColor(Recipients recipients, MaterialColor color) {
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(COLOR, color);
|
||||
values.put(COLOR, color.serialize());
|
||||
updateOrInsert(recipients, values);
|
||||
}
|
||||
|
||||
@ -158,14 +166,16 @@ public class RecipientPreferenceDatabase extends Database {
|
||||
}
|
||||
|
||||
public static class RecipientsPreferences {
|
||||
private final boolean blocked;
|
||||
private final long muteUntil;
|
||||
private final VibrateState vibrateState;
|
||||
private final Uri notification;
|
||||
private final Optional<Integer> color;
|
||||
private final boolean blocked;
|
||||
private final long muteUntil;
|
||||
private final VibrateState vibrateState;
|
||||
private final Uri notification;
|
||||
private final MaterialColor color;
|
||||
|
||||
public RecipientsPreferences(boolean blocked, long muteUntil, VibrateState vibrateState,
|
||||
Uri notification, Optional<Integer> color)
|
||||
public RecipientsPreferences(boolean blocked, long muteUntil,
|
||||
@NonNull VibrateState vibrateState,
|
||||
@Nullable Uri notification,
|
||||
@Nullable MaterialColor color)
|
||||
{
|
||||
this.blocked = blocked;
|
||||
this.muteUntil = muteUntil;
|
||||
@ -174,7 +184,7 @@ public class RecipientPreferenceDatabase extends Database {
|
||||
this.color = color;
|
||||
}
|
||||
|
||||
public Optional<Integer> getColor() {
|
||||
public @Nullable MaterialColor getColor() {
|
||||
return color;
|
||||
}
|
||||
|
||||
|
@ -46,6 +46,7 @@ import android.util.Log;
|
||||
import org.thoughtcrime.securesms.ConversationActivity;
|
||||
import org.thoughtcrime.securesms.ConversationListActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.color.ThemeType;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactColors;
|
||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
@ -195,8 +196,8 @@ public class MessageNotifier {
|
||||
Recipient recipient = notifications.get(0).getIndividualRecipient();
|
||||
Recipients recipients = notifications.get(0).getRecipients();
|
||||
int largeIconTargetSize = context.getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size);
|
||||
Drawable recipientPhoto = recipient.getContactPhoto().asDrawable(context, recipients == null ? ContactColors.UNKNOWN_COLOR :
|
||||
recipients.getColor().or(ContactColors.UNKNOWN_COLOR));
|
||||
Drawable recipientPhoto = recipient.getContactPhoto().asDrawable(context, recipients == null ? ContactColors.UNKNOWN_COLOR.toConversationColor(ThemeType.LIGHT) :
|
||||
recipients.getColor(context).toConversationColor(ThemeType.LIGHT));
|
||||
|
||||
if (recipientPhoto != null) {
|
||||
Bitmap recipientPhotoBitmap = BitmapUtil.createFromDrawable(recipientPhoto, largeIconTargetSize, largeIconTargetSize);
|
||||
|
@ -74,15 +74,15 @@ public class ColorPreference extends Preference {
|
||||
try {
|
||||
mItemLayoutId = a.getResourceId(R.styleable.ColorPreference_itemLayout, mItemLayoutId);
|
||||
mNumColumns = a.getInteger(R.styleable.ColorPreference_numColumns, mNumColumns);
|
||||
int choicesResId = a.getResourceId(R.styleable.ColorPreference_choices,
|
||||
R.array.default_color_choice_values);
|
||||
if (choicesResId > 0) {
|
||||
String[] choices = a.getResources().getStringArray(choicesResId);
|
||||
mColorChoices = new int[choices.length];
|
||||
for (int i = 0; i < choices.length; i++) {
|
||||
mColorChoices[i] = Color.parseColor(choices[i]);
|
||||
}
|
||||
}
|
||||
// int choicesResId = a.getResourceId(R.styleable.ColorPreference_choices,
|
||||
// R.array.default_color_choice_values);
|
||||
// if (choicesResId > 0) {
|
||||
// String[] choices = a.getResources().getStringArray(choicesResId);
|
||||
// mColorChoices = new int[choices.length];
|
||||
// for (int i = 0; i < choices.length; i++) {
|
||||
// mColorChoices[i] = Color.parseColor(choices[i]);
|
||||
// }
|
||||
// }
|
||||
|
||||
} finally {
|
||||
a.recycle();
|
||||
@ -106,6 +106,10 @@ public class ColorPreference extends Preference {
|
||||
}
|
||||
}
|
||||
|
||||
public void setChoices(int[] values) {
|
||||
mColorChoices = values;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onClick() {
|
||||
super.onClick();
|
||||
|
@ -21,6 +21,7 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.color.MaterialColor;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactColors;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactPhotoFactory;
|
||||
@ -28,7 +29,6 @@ import org.thoughtcrime.securesms.recipients.RecipientProvider.RecipientDetails;
|
||||
import org.thoughtcrime.securesms.util.FutureTaskListener;
|
||||
import org.thoughtcrime.securesms.util.GroupUtil;
|
||||
import org.thoughtcrime.securesms.util.ListenableFutureTask;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
@ -46,16 +46,17 @@ public class Recipient {
|
||||
private String number;
|
||||
private String name;
|
||||
|
||||
private ContactPhoto contactPhoto;
|
||||
private Uri contactUri;
|
||||
private Optional<Integer> color;
|
||||
private ContactPhoto contactPhoto;
|
||||
private Uri contactUri;
|
||||
|
||||
@Nullable private MaterialColor color;
|
||||
|
||||
Recipient(long recipientId, String number, ListenableFutureTask<RecipientDetails> future)
|
||||
{
|
||||
this.recipientId = recipientId;
|
||||
this.number = number;
|
||||
this.contactPhoto = ContactPhotoFactory.getLoadingPhoto();
|
||||
this.color = Optional.absent();
|
||||
this.color = null;
|
||||
|
||||
future.addListener(new FutureTaskListener<RecipientDetails>() {
|
||||
@Override
|
||||
@ -97,13 +98,13 @@ public class Recipient {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
public synchronized @NonNull Optional<Integer> getColor() {
|
||||
if (color.isPresent()) return color;
|
||||
else if (name != null) return Optional.of(ContactColors.generateFor(name));
|
||||
else return Optional.of(ContactColors.UNKNOWN_COLOR);
|
||||
public synchronized @NonNull MaterialColor getColor() {
|
||||
if (color != null) return color;
|
||||
else if (name != null) return ContactColors.generateFor(name);
|
||||
else return ContactColors.UNKNOWN_COLOR;
|
||||
}
|
||||
|
||||
public void setColor(Optional<Integer> color) {
|
||||
public void setColor(@NonNull MaterialColor color) {
|
||||
synchronized (this) {
|
||||
this.color = color;
|
||||
}
|
||||
@ -141,8 +142,7 @@ public class Recipient {
|
||||
|
||||
public static Recipient getUnknownRecipient() {
|
||||
return new Recipient(-1, new RecipientDetails("Unknown", "Unknown", null,
|
||||
ContactPhotoFactory.getDefaultContactPhoto("Unknown"),
|
||||
Optional.<Integer>absent()));
|
||||
ContactPhotoFactory.getDefaultContactPhoto("Unknown"), null));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -25,6 +25,7 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.color.MaterialColor;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactPhotoFactory;
|
||||
import org.thoughtcrime.securesms.database.CanonicalAddressDatabase;
|
||||
@ -122,7 +123,7 @@ public class RecipientProvider {
|
||||
|
||||
private @NonNull RecipientDetails getIndividualRecipientDetails(Context context, long recipientId, String number) {
|
||||
Optional<RecipientsPreferences> preferences = DatabaseFactory.getRecipientPreferenceDatabase(context).getRecipientsPreferences(new long[]{recipientId});
|
||||
Optional<Integer> color = preferences.isPresent() ? preferences.get().getColor() : Optional.<Integer>absent();
|
||||
MaterialColor color = preferences.isPresent() ? preferences.get().getColor() : null;
|
||||
Uri uri = Uri.withAppendedPath(PhoneLookup.CONTENT_FILTER_URI, Uri.encode(number));
|
||||
Cursor cursor = context.getContentResolver().query(uri, CALLER_ID_PROJECTION,
|
||||
null, null, null);
|
||||
@ -152,13 +153,13 @@ public class RecipientProvider {
|
||||
|
||||
if (record != null) {
|
||||
ContactPhoto contactPhoto = ContactPhotoFactory.getGroupContactPhoto(record.getAvatar());
|
||||
return new RecipientDetails(record.getTitle(), groupId, null, contactPhoto, Optional.<Integer>absent());
|
||||
return new RecipientDetails(record.getTitle(), groupId, null, contactPhoto, null);
|
||||
}
|
||||
|
||||
return new RecipientDetails(null, groupId, null, ContactPhotoFactory.getDefaultGroupPhoto(), Optional.<Integer>absent());
|
||||
return new RecipientDetails(null, groupId, null, ContactPhotoFactory.getDefaultGroupPhoto(), null);
|
||||
} catch (IOException e) {
|
||||
Log.w("RecipientProvider", e);
|
||||
return new RecipientDetails(null, groupId, null, ContactPhotoFactory.getDefaultGroupPhoto(), Optional.<Integer>absent());
|
||||
return new RecipientDetails(null, groupId, null, ContactPhotoFactory.getDefaultGroupPhoto(), null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -182,21 +183,21 @@ public class RecipientProvider {
|
||||
}
|
||||
|
||||
public static class RecipientDetails {
|
||||
@Nullable public final String name;
|
||||
@NonNull public final String number;
|
||||
@NonNull public final ContactPhoto avatar;
|
||||
@Nullable public final Uri contactUri;
|
||||
@NonNull public final Optional<Integer> color;
|
||||
@Nullable public final String name;
|
||||
@NonNull public final String number;
|
||||
@NonNull public final ContactPhoto avatar;
|
||||
@Nullable public final Uri contactUri;
|
||||
@Nullable public final MaterialColor color;
|
||||
|
||||
public RecipientDetails(@Nullable String name, @NonNull String number,
|
||||
@Nullable Uri contactUri, @NonNull ContactPhoto avatar,
|
||||
@NonNull Optional<Integer> color)
|
||||
@Nullable MaterialColor color)
|
||||
{
|
||||
this.name = name;
|
||||
this.number = number;
|
||||
this.avatar = avatar;
|
||||
this.contactUri = contactUri;
|
||||
this.color = color;
|
||||
this.name = name;
|
||||
this.number = number;
|
||||
this.avatar = avatar;
|
||||
this.contactUri = contactUri;
|
||||
this.color = color;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,12 +16,15 @@
|
||||
*/
|
||||
package org.thoughtcrime.securesms.recipients;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
import android.util.Patterns;
|
||||
|
||||
import org.thoughtcrime.securesms.color.MaterialColor;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactColors;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactPhoto;
|
||||
import org.thoughtcrime.securesms.contacts.avatars.ContactPhotoFactory;
|
||||
import org.thoughtcrime.securesms.database.RecipientPreferenceDatabase.RecipientsPreferences;
|
||||
@ -32,7 +35,6 @@ import org.thoughtcrime.securesms.util.GroupUtil;
|
||||
import org.thoughtcrime.securesms.util.ListenableFutureTask;
|
||||
import org.thoughtcrime.securesms.util.NumberUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.libaxolotl.util.guava.Optional;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@ -155,13 +157,13 @@ public class Recipients implements Iterable<Recipient>, RecipientModifiedListene
|
||||
else return ContactPhotoFactory.getDefaultGroupPhoto();
|
||||
}
|
||||
|
||||
public synchronized @NonNull Optional<Integer> getColor() {
|
||||
if (!isSingleRecipient() || isGroupRecipient()) return Optional.absent();
|
||||
else if (isEmpty()) return Optional.absent();
|
||||
public synchronized @NonNull MaterialColor getColor(Context context) {
|
||||
if (!isSingleRecipient() || isGroupRecipient()) return ContactColors.getGroupColor(context);
|
||||
else if (isEmpty()) return ContactColors.UNKNOWN_COLOR;
|
||||
else return recipients.get(0).getColor();
|
||||
}
|
||||
|
||||
public synchronized void setColor(Optional<Integer> color) {
|
||||
public synchronized void setColor(@NonNull MaterialColor color) {
|
||||
if (!isSingleRecipient() || isGroupRecipient()) throw new AssertionError("Groups don't have colors!");
|
||||
else if (!isEmpty()) recipients.get(0).setColor(color);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user