Skip to content

Commit

Permalink
User-selectable contact colors.
Browse files Browse the repository at this point in the history
// FREEBIE
  • Loading branch information
moxie0 committed Jun 28, 2015
1 parent fb9f16a commit 296796e
Show file tree
Hide file tree
Showing 11 changed files with 423 additions and 4 deletions.
4 changes: 4 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ dependencies {
compile ('com.android.support:support-v4-preferencefragment:1.0.0@aar'){
exclude module: 'support-v4'
}
compile ('com.android.support:gridlayout-v7:22.2.0') {
exclude module: 'support-v4'
}

compile 'com.squareup.dagger:dagger:1.2.2'
compile ("com.doomonafireball.betterpickers:library:1.5.3") {
exclude group: 'com.android.support', module: 'support-v4'
Expand Down
24 changes: 24 additions & 0 deletions res/layout/color_preference_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<!--
Copyright 2013 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="@dimen/color_grid_item_size"
android:layout_height="@dimen/color_grid_item_size">

<ImageView
android:id="@+id/color_view"
android:layout_width="36dp"
android:layout_height="36dp"
android:layout_gravity="center"
android:scaleType="fitXY" />
</FrameLayout>
21 changes: 21 additions & 0 deletions res/layout/color_preference_items.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!--
Copyright 2013 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->

<android.support.v7.widget.GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/color_grid"
android:padding="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:orientation="horizontal"
app:columnCount="5"/>
20 changes: 20 additions & 0 deletions res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,24 @@
<item>2</item>
</string-array>

<string-array name="default_color_choice_values" translatable="false">
<item>#ffE57373</item>
<item>#ffF06292</item>
<item>#ffBA68C8</item>
<item>#ff9575CD</item>
<item>#ff7986CB</item>
<item>#ff64B5F6</item>
<item>#ff4FC3F7</item>
<item>#ff4DD0E1</item>
<item>#FF4DB6AC</item>
<item>#FF81C784</item>
<item>#FFAED581</item>
<item>#FFDCE775</item>
<item>#FFFFD54F</item>
<item>#FFFFB74D</item>
<item>#FFFF8A65</item>
<item>#FFA1887F</item>
<item>#FF90A4AE</item>
</string-array>

</resources>
7 changes: 7 additions & 0 deletions res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,11 @@
<attr name="lockscreen_watermark" format="reference" />

<attr name="recipient_preference_blocked" format="color"/>

<declare-styleable name="ColorPreference">
<attr name="itemLayout" format="reference" />
<attr name="choices" format="reference" />
<attr name="numColumns" format="integer" />
</declare-styleable>

</resources>
3 changes: 3 additions & 0 deletions res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@

<integer name="media_overview_cols">3</integer>
<dimen name="message_details_table_row_pad">10dp</dimen>

<dimen name="color_grid_extra_padding">32dp</dimen>
<dimen name="color_grid_item_size">48dp</dimen>
</resources>
2 changes: 2 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,8 @@
<string name="recipient_preferences__ringtone">Ringtone</string>
<string name="recipient_preferences__vibrate">Vibrate</string>
<string name="recipient_preferences__block">Block</string>
<string name="recipient_preferences__color">Color</string>
<string name="recipient_preferences__color_for_this_contact">Color for this contact</string>

<!-- registration_activity -->
<string name="registration_activity__textsecure_can_use_instant_messages_to_avoid_sms_charges_when_communicating_with_other_textsecure_users">
Expand Down
14 changes: 13 additions & 1 deletion res/xml/recipient_preferences.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
android:key="pref_key_recipient_mute"
android:title="@string/recipient_preferences__mute_conversation"
Expand All @@ -24,6 +25,17 @@
android:defaultValue="0"
android:persistent="false"/>

<org.thoughtcrime.securesms.preferences.ColorPreference
android:key="pref_key_recipient_color"
android:title="@string/recipient_preferences__color"
android:summary="@string/recipient_preferences__color_for_this_contact"
android:defaultValue="@android:color/black"
android:negativeButtonText="@null"
android:positiveButtonText="@null"
android:persistent="false"
app:numColumns="5" />


<Preference android:key="pref_key_recipient_block"
android:title="@string/recipient_preferences__block" />

Expand Down
3 changes: 0 additions & 3 deletions src/org/thoughtcrime/securesms/ConversationActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import android.view.View.OnFocusChangeListener;
import android.view.View.OnKeyListener;
import android.view.ViewStub;
import android.view.WindowManager;
import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
Expand All @@ -53,7 +52,6 @@

import com.afollestad.materialdialogs.AlertDialogWrapper;
import com.google.protobuf.ByteString;
import com.readystatesoftware.systembartint.SystemBarTintManager;

import org.thoughtcrime.securesms.TransportOptions.OnTransportChangedListener;
import org.thoughtcrime.securesms.components.AnimatingToggle;
Expand Down Expand Up @@ -806,7 +804,6 @@ private void initializeResources() {

@Override
public void onModified(final Recipients recipients) {
Log.w(TAG, "onModified()");
titleView.post(new Runnable() {
@Override
public void run() {
Expand Down
37 changes: 37 additions & 0 deletions src/org/thoughtcrime/securesms/RecipientPreferenceActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
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;
Expand All @@ -28,11 +29,13 @@
import org.thoughtcrime.securesms.crypto.MasterSecret;
import org.thoughtcrime.securesms.database.DatabaseFactory;
import org.thoughtcrime.securesms.database.RecipientPreferenceDatabase.VibrateState;
import org.thoughtcrime.securesms.preferences.ColorPreference;
import org.thoughtcrime.securesms.recipients.RecipientFactory;
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
{
Expand All @@ -44,6 +47,7 @@ public class RecipientPreferenceActivity extends PassphraseRequiredActionBarActi
private static final String PREFERENCE_TONE = "pref_key_recipient_ringtone";
private static final String PREFERENCE_VIBRATE = "pref_key_recipient_vibrate";
private static final String PREFERENCE_BLOCK = "pref_key_recipient_block";
private static final String PREFERENCE_COLOR = "pref_key_recipient_color";

private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme();
private final DynamicLanguage dynamicLanguage = new DynamicLanguage();
Expand Down Expand Up @@ -156,6 +160,8 @@ public void onCreate(Bundle icicle) {
.setOnPreferenceClickListener(new MuteClickedListener());
this.findPreference(PREFERENCE_BLOCK)
.setOnPreferenceClickListener(new BlockClickedListener());
this.findPreference(PREFERENCE_COLOR)
.setOnPreferenceChangeListener(new ColorChangeListener());
}

@Override
Expand All @@ -174,6 +180,7 @@ private void setSummaries(Recipients recipients) {
CheckBoxPreference mutePreference = (CheckBoxPreference) this.findPreference(PREFERENCE_MUTED);
RingtonePreference ringtonePreference = (RingtonePreference) this.findPreference(PREFERENCE_TONE);
ListPreference vibratePreference = (ListPreference) this.findPreference(PREFERENCE_VIBRATE);
ColorPreference colorPreference = (ColorPreference) this.findPreference(PREFERENCE_COLOR);
Preference blockPreference = this.findPreference(PREFERENCE_BLOCK);

mutePreference.setChecked(recipients.isMuted());
Expand All @@ -199,6 +206,14 @@ private void setSummaries(Recipients recipients) {
vibratePreference.setValueIndex(2);
}

if (recipients.getColor().isPresent()) {
colorPreference.setValue(recipients.getColor().get());
colorPreference.setEnabled(true);
} else {
colorPreference.setValue(getResources().getColor(R.color.textsecure_primary));
colorPreference.setEnabled(false);
}

if (!recipients.isSingleRecipient() || recipients.isGroupRecipient()) {
blockPreference.setEnabled(false);
} else {
Expand Down Expand Up @@ -267,6 +282,28 @@ protected Void doInBackground(Void... params) {
}
}

private class ColorChangeListener implements Preference.OnPreferenceChangeListener {

@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
final int value = (Integer)newValue;

if (value != recipients.getColor().get()) {
recipients.setColor(Optional.of(value));

new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
DatabaseFactory.getRecipientPreferenceDatabase(getActivity())
.setColor(recipients, value);
return null;
}
}.execute();
}
return true;
}
}

private class MuteClickedListener implements Preference.OnPreferenceClickListener {
@Override
public boolean onPreferenceClick(Preference preference) {
Expand Down
Loading

0 comments on commit 296796e

Please sign in to comment.