Skip to content

Commit

Permalink
Refactor colorization to support dark theme.
Browse files Browse the repository at this point in the history
// FREEBIE
  • Loading branch information
moxie0 committed Jul 1, 2015
1 parent eacfca3 commit ce2f66a
Show file tree
Hide file tree
Showing 32 changed files with 836 additions and 231 deletions.
1 change: 1 addition & 0 deletions res/values/attrs.xml
Original file line number Diff line number Diff line change
@@ -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"/>
Expand Down
4 changes: 4 additions & 0 deletions res/values/themes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand All @@ -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>
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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>
Expand Down
17 changes: 8 additions & 9 deletions src/org/thoughtcrime/securesms/ConversationActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@
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;
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;
Expand Down Expand Up @@ -225,7 +226,7 @@ protected void onResume() {
initializeIme();

titleView.setTitle(recipients);
setActionBarColor(recipients.getColor());
setActionBarColor(recipients.getColor(this));
setBlockedUserState(recipients);
calculateCharactersRemaining();

Expand Down Expand Up @@ -809,7 +810,7 @@ public void onModified(final Recipients recipients) {
public void run() {
titleView.setTitle(recipients);
setBlockedUserState(recipients);
setActionBarColor(recipients.getColor());
setActionBarColor(recipients.getColor(ConversationActivity.this));
}
});
}
Expand Down Expand Up @@ -1000,15 +1001,13 @@ protected void onPostExecute(Long result) {
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));
}
}

Expand Down
6 changes: 4 additions & 2 deletions src/org/thoughtcrime/securesms/ConversationItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
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;
Expand All @@ -39,6 +40,7 @@
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;
Expand Down Expand Up @@ -192,14 +194,14 @@ public MessageRecord getMessageRecord() {
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);
}

Expand Down
38 changes: 19 additions & 19 deletions src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,17 @@
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;
Expand All @@ -36,7 +39,6 @@
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
{
Expand Down Expand Up @@ -117,17 +119,14 @@ private void initializeToolbar() {
}

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);
Expand Down Expand Up @@ -194,6 +193,7 @@ private void setSummaries(Recipients recipients) {
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());

Expand All @@ -218,13 +218,9 @@ private void setSummaries(Recipients recipients) {
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);
Expand Down Expand Up @@ -298,16 +294,20 @@ private class ColorChangeListener implements Preference.OnPreferenceChangeListen

@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 (selectedColor == null) return false;

if (preference.isEnabled() && value != recipients.getColor().get()) {
recipients.setColor(Optional.of(value));
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();
Expand Down
28 changes: 28 additions & 0 deletions src/org/thoughtcrime/securesms/color/BlueGreyMaterialColor.java
Original file line number Diff line number Diff line change
@@ -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 changes: 32 additions & 0 deletions src/org/thoughtcrime/securesms/color/BlueMaterialColor.java
Original file line number Diff line number Diff line change
@@ -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 changes: 28 additions & 0 deletions src/org/thoughtcrime/securesms/color/BrownMaterialColor.java
Original file line number Diff line number Diff line change
@@ -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 changes: 32 additions & 0 deletions src/org/thoughtcrime/securesms/color/CyanMaterialColor.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
32 changes: 32 additions & 0 deletions src/org/thoughtcrime/securesms/color/DeepOrangeMaterialColor.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Loading

0 comments on commit ce2f66a

Please sign in to comment.