mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-11 16:33:39 +00:00
Use theme-defined weights instead of ThemeType.
// FREEBIE
This commit is contained in:
parent
ce2f66ad17
commit
9bf7562d49
@ -1,6 +1,5 @@
|
||||
<?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"/>
|
||||
@ -23,6 +22,10 @@
|
||||
<attr name="centered_app_title_color" format="reference|color" />
|
||||
<attr name="ic_arrow_forward" format="reference" />
|
||||
|
||||
<attr name="conversation_color_material_weight" format="string"/>
|
||||
<attr name="actionbar_color_material_weight" format="string"/>
|
||||
<attr name="statusbar_color_material_weight" format="string"/>
|
||||
|
||||
<attr name="conversation_background" format="reference|color"/>
|
||||
<attr name="conversation_editor_background" format="reference|color"/>
|
||||
<attr name="conversation_editor_text_color" format="reference|color"/>
|
||||
|
@ -3,7 +3,10 @@
|
||||
<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="conversation_color_material_weight">500</item>
|
||||
<item name="actionbar_color_material_weight">500</item>
|
||||
<item name="statusbar_color_material_weight">700</item>
|
||||
|
||||
<item name="actionBarStyle">@style/TextSecure.LightActionBar</item>
|
||||
<item name="actionBarTabBarStyle">@style/TextSecure.LightActionBar.TabBar</item>
|
||||
<item name="colorPrimary">@color/textsecure_primary</item>
|
||||
@ -13,7 +16,10 @@
|
||||
</style>
|
||||
|
||||
<style name="TextSecure.DarkNoActionBar" parent="@style/Theme.AppCompat.NoActionBar">
|
||||
<item name="theme_type">dark</item>
|
||||
<item name="conversation_color_material_weight">900</item>
|
||||
<item name="actionbar_color_material_weight">900</item>
|
||||
<item name="statusbar_color_material_weight">700</item>
|
||||
|
||||
<item name="actionBarStyle">@style/TextSecure.DarkActionBar</item>
|
||||
<item name="actionBarTabBarStyle">@style/TextSecure.DarkActionBar.TabBar</item>
|
||||
<item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat.Dark</item>
|
||||
@ -60,7 +66,10 @@
|
||||
</style>
|
||||
|
||||
<style name="TextSecure.LightTheme" parent="@style/Theme.AppCompat.Light.DarkActionBar">
|
||||
<item name="theme_type">light</item>
|
||||
<item name="conversation_color_material_weight">500</item>
|
||||
<item name="actionbar_color_material_weight">500</item>
|
||||
<item name="statusbar_color_material_weight">700</item>
|
||||
|
||||
<item name="actionBarStyle">@style/TextSecure.LightActionBar</item>
|
||||
<item name="actionBarTabBarStyle">@style/TextSecure.LightActionBar.TabBar</item>
|
||||
<item name="colorPrimary">@color/textsecure_primary</item>
|
||||
@ -174,7 +183,10 @@
|
||||
</style>
|
||||
|
||||
<style name="TextSecure.DarkTheme" parent="@style/Theme.AppCompat">
|
||||
<item name="theme_type">dark</item>
|
||||
<item name="conversation_color_material_weight">900</item>
|
||||
<item name="actionbar_color_material_weight">900</item>
|
||||
<item name="statusbar_color_material_weight">700</item>
|
||||
|
||||
<item name="actionBarStyle">@style/TextSecure.DarkActionBar</item>
|
||||
<item name="actionBarTabBarStyle">@style/TextSecure.DarkActionBar.TabBar</item>
|
||||
<item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat.Dark</item>
|
||||
|
@ -55,7 +55,6 @@ 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;
|
||||
@ -1002,12 +1001,10 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
}
|
||||
|
||||
private void setActionBarColor(MaterialColor color) {
|
||||
ThemeType themeType = ThemeType.getCurrent(this);
|
||||
|
||||
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color.toActionBarColor(themeType)));
|
||||
getSupportActionBar().setBackgroundDrawable(new ColorDrawable(color.toActionBarColor(this)));
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
getWindow().setStatusBarColor(color.toStatusBarColor(themeType));
|
||||
getWindow().setStatusBarColor(color.toStatusBarColor(this));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -40,7 +40,6 @@ 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;
|
||||
@ -201,7 +200,7 @@ public class ConversationItem extends LinearLayout {
|
||||
} else {
|
||||
bodyBubble.getBackground().setColorFilter(messageRecord.getIndividualRecipient()
|
||||
.getColor()
|
||||
.toConversationColor(ThemeType.getCurrent(context)),
|
||||
.toConversationColor(context),
|
||||
PorterDuff.Mode.MULTIPLY);
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,6 @@ 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;
|
||||
@ -28,7 +27,6 @@ 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.crypto.MasterSecret;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
@ -119,14 +117,12 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
|
||||
}
|
||||
|
||||
private void setHeader(Recipients recipients) {
|
||||
ThemeType themeType = ThemeType.getCurrent(this);
|
||||
|
||||
this.avatar.setAvatar(recipients, true);
|
||||
this.title.setText(recipients.toShortString());
|
||||
this.toolbar.setBackgroundColor(recipients.getColor(this).toActionBarColor(themeType));
|
||||
this.toolbar.setBackgroundColor(recipients.getColor(this).toActionBarColor(this));
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
getWindow().setStatusBarColor(recipients.getColor(this).toStatusBarColor(themeType));
|
||||
getWindow().setStatusBarColor(recipients.getColor(this).toStatusBarColor(this));
|
||||
}
|
||||
|
||||
if (recipients.isBlocked()) this.blockedIndicator.setVisibility(View.VISIBLE);
|
||||
@ -193,7 +189,6 @@ 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());
|
||||
|
||||
@ -219,8 +214,8 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
|
||||
}
|
||||
|
||||
colorPreference.setEnabled(recipients.isSingleRecipient() && !recipients.isGroupRecipient());
|
||||
colorPreference.setChoices(MaterialColors.CONVERSATION_PALETTE.asConversationColorArray(themeType));
|
||||
colorPreference.setValue(recipients.getColor(getActivity()).toActionBarColor(ThemeType.getCurrent(getActivity())));
|
||||
colorPreference.setChoices(MaterialColors.CONVERSATION_PALETTE.asConversationColorArray(getActivity()));
|
||||
colorPreference.setValue(recipients.getColor(getActivity()).toActionBarColor(getActivity()));
|
||||
|
||||
if (!recipients.isSingleRecipient() || recipients.isGroupRecipient()) {
|
||||
blockPreference.setEnabled(false);
|
||||
|
@ -1,5 +1,11 @@
|
||||
package org.thoughtcrime.securesms.color;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
import android.util.TypedValue;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
import java.util.Map;
|
||||
@ -8,21 +14,20 @@ public abstract class MaterialColor {
|
||||
|
||||
private final Map<String, Integer> colorWeightMap;
|
||||
|
||||
protected MaterialColor(Map<String, Integer> colorWeightMap) {
|
||||
protected MaterialColor(@NonNull 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 toConversationColor(@NonNull Context context) {
|
||||
return colorWeightMap.get(getWeight(context, R.attr.conversation_color_material_weight, "500"));
|
||||
}
|
||||
|
||||
public int toActionBarColor(ThemeType themeType) {
|
||||
return toConversationColor(themeType);
|
||||
public int toActionBarColor(@NonNull Context context) {
|
||||
return colorWeightMap.get(getWeight(context, R.attr.actionbar_color_material_weight, "500"));
|
||||
}
|
||||
|
||||
public int toStatusBarColor(ThemeType themeType) {
|
||||
return colorWeightMap.get("700");
|
||||
public int toStatusBarColor(@NonNull Context context) {
|
||||
return colorWeightMap.get(getWeight(context, R.attr.statusbar_color_material_weight, "700"));
|
||||
}
|
||||
|
||||
public boolean represents(int colorValue) {
|
||||
@ -42,6 +47,16 @@ public abstract class MaterialColor {
|
||||
|
||||
public abstract String serialize();
|
||||
|
||||
private String getWeight(Context context, int attribute, String defaultWeight) {
|
||||
TypedValue outValue = new TypedValue();
|
||||
|
||||
if (context.getTheme().resolveAttribute(attribute, outValue, true)) {
|
||||
return outValue.coerceToString().toString();
|
||||
} else {
|
||||
return defaultWeight;
|
||||
}
|
||||
}
|
||||
|
||||
public static MaterialColor fromSerialized(String serialized) throws UnknownColorException {
|
||||
switch (serialized) {
|
||||
case RedMaterialColor.SERIALIZED_NAME: return new RedMaterialColor();
|
||||
|
@ -1,5 +1,7 @@
|
||||
package org.thoughtcrime.securesms.color;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -58,12 +60,12 @@ public class MaterialColors {
|
||||
return null;
|
||||
}
|
||||
|
||||
public int[] asConversationColorArray(ThemeType themeType) {
|
||||
public int[] asConversationColorArray(@NonNull Context context) {
|
||||
int[] results = new int[colors.size()];
|
||||
int index = 0;
|
||||
|
||||
for (MaterialColor color : colors) {
|
||||
results[index++] = color.toConversationColor(themeType);
|
||||
results[index++] = color.toConversationColor(context);
|
||||
}
|
||||
|
||||
return results;
|
||||
|
@ -1,32 +0,0 @@
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
@ -11,7 +11,6 @@ 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;
|
||||
@ -39,14 +38,12 @@ public class AvatarImageView extends ImageView {
|
||||
}
|
||||
|
||||
public void setAvatar(@Nullable Recipients recipients, boolean quickContactEnabled) {
|
||||
ThemeType themeType = ThemeType.getCurrent(getContext());
|
||||
|
||||
if (recipients != null) {
|
||||
MaterialColor backgroundColor = recipients.getColor(getContext());
|
||||
setImageDrawable(recipients.getContactPhoto().asDrawable(getContext(), backgroundColor.toConversationColor(themeType), inverted));
|
||||
setImageDrawable(recipients.getContactPhoto().asDrawable(getContext(), backgroundColor.toConversationColor(getContext()), inverted));
|
||||
setAvatarClickHandler(recipients, quickContactEnabled);
|
||||
} else {
|
||||
setImageDrawable(ContactPhotoFactory.getDefaultContactPhoto(null).asDrawable(getContext(), ContactColors.UNKNOWN_COLOR.toConversationColor(themeType), inverted));
|
||||
setImageDrawable(ContactPhotoFactory.getDefaultContactPhoto(null).asDrawable(getContext(), ContactColors.UNKNOWN_COLOR.toConversationColor(getContext()), inverted));
|
||||
setOnClickListener(null);
|
||||
}
|
||||
}
|
||||
|
@ -2,25 +2,17 @@ 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 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());
|
||||
}
|
||||
@ -31,17 +23,17 @@ public class ContactColors {
|
||||
|
||||
return new MaterialColor(new HashMap<String, Integer>()) {
|
||||
@Override
|
||||
public int toConversationColor(ThemeType themeType) {
|
||||
return UNKNOWN_COLOR.toConversationColor(themeType);
|
||||
public int toConversationColor(@NonNull Context context) {
|
||||
return UNKNOWN_COLOR.toConversationColor(context);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int toActionBarColor(ThemeType themeType) {
|
||||
public int toActionBarColor(@NonNull Context context) {
|
||||
return actionBarColor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int toStatusBarColor(ThemeType themeType) {
|
||||
public int toStatusBarColor(@NonNull Context context) {
|
||||
return statusBarColor;
|
||||
}
|
||||
|
||||
@ -50,12 +42,5 @@ public class ContactColors {
|
||||
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);
|
||||
// }
|
||||
|
||||
}
|
||||
|
@ -46,7 +46,6 @@ 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;
|
||||
@ -196,8 +195,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.toConversationColor(ThemeType.LIGHT) :
|
||||
recipients.getColor(context).toConversationColor(ThemeType.LIGHT));
|
||||
Drawable recipientPhoto = recipient.getContactPhoto().asDrawable(context, recipients == null ? ContactColors.UNKNOWN_COLOR.toConversationColor(context) :
|
||||
recipients.getColor(context).toConversationColor(context));
|
||||
|
||||
if (recipientPhoto != null) {
|
||||
Bitmap recipientPhotoBitmap = BitmapUtil.createFromDrawable(recipientPhoto, largeIconTargetSize, largeIconTargetSize);
|
||||
|
Loading…
x
Reference in New Issue
Block a user