Skip to content

Commit

Permalink
Slim down some preference screens
Browse files Browse the repository at this point in the history
// FREEBIE
  • Loading branch information
moxie0 committed Apr 22, 2017
1 parent 438a78e commit 2dceef5
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 41 deletions.
15 changes: 15 additions & 0 deletions res/layout/preference_right_summary_widget.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView android:id="@+id/right_summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:gravity="right|center_vertical"
android:textSize="16sp"
android:textColor="@color/signal_primary_dark"/>

</FrameLayout>
2 changes: 2 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,8 @@
<string name="preferences_chats__chats">Chats</string>
<string name="preferences_notifications__message_notifications">Message notifications</string>
<string name="preferences_notifications__events">Events</string>
<string name="preferences_notifications__in_chat_sounds">In-chat sounds</string>
<string name="preferences_notifications__show">Show</string>
<string name="preferences_chats__show_invitation_prompts">Show invitation prompts</string>
<string name="preferences_chats__display_invitation_prompts_for_contacts_without_signal">Display invitation prompts for contacts without Signal</string>
<string name="preferences_chats__message_text_size">Message font size</string>
Expand Down
11 changes: 6 additions & 5 deletions res/xml/preferences_app_protection.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@
android:summary="@string/preferences__change_your_passphrase"
android:dependency="pref_enable_passphrase_temporary"/>

<CheckBoxPreference android:defaultValue="false"
android:key="pref_timeout_passphrase"
android:title="@string/preferences__inactivity_timeout_passphrase"
android:summary="@string/preferences__auto_lock_signal_after_a_specified_time_interval_of_inactivity"
android:dependency="pref_enable_passphrase_temporary"/>
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
android:defaultValue="false"
android:key="pref_timeout_passphrase"
android:title="@string/preferences__inactivity_timeout_passphrase"
android:summary="@string/preferences__auto_lock_signal_after_a_specified_time_interval_of_inactivity"
android:dependency="pref_enable_passphrase_temporary"/>

<Preference android:title="@string/preferences__inactivity_timeout_interval"
android:key="pref_timeout_interval"
Expand Down
24 changes: 13 additions & 11 deletions res/xml/preferences_appearance.xml
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>

<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<ListPreference android:key="pref_theme"
android:title="@string/preferences__theme"
android:entries="@array/pref_theme_entries"
android:entryValues="@array/pref_theme_values"
android:defaultValue="light">
</ListPreference>
<org.thoughtcrime.securesms.preferences.SignalListPreference
android:key="pref_theme"
android:title="@string/preferences__theme"
android:entries="@array/pref_theme_entries"
android:entryValues="@array/pref_theme_values"
android:defaultValue="light">
</org.thoughtcrime.securesms.preferences.SignalListPreference>

<ListPreference android:key="pref_language"
android:title="@string/preferences__language"
android:entries="@array/language_entries"
android:entryValues="@array/language_values"
android:defaultValue="zz"/>
<org.thoughtcrime.securesms.preferences.SignalListPreference
android:key="pref_language"
android:title="@string/preferences__language"
android:entries="@array/language_entries"
android:entryValues="@array/language_values"
android:defaultValue="zz"/>
</PreferenceScreen>
13 changes: 7 additions & 6 deletions res/xml/preferences_chats.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@
<PreferenceCategory android:layout="@layout/preference_divider"/>

<PreferenceCategory android:title="@string/preferences_chats__chats">
<ListPreference android:key="pref_message_body_text_size"
android:title="@string/preferences_chats__message_text_size"
android:entries="@array/pref_message_font_size_entries"
android:entryValues="@array/pref_message_font_size_values"
android:defaultValue="16">
</ListPreference>
<org.thoughtcrime.securesms.preferences.SignalListPreference
android:key="pref_message_body_text_size"
android:title="@string/preferences_chats__message_text_size"
android:entries="@array/pref_message_font_size_entries"
android:entryValues="@array/pref_message_font_size_values"
android:defaultValue="16">
</org.thoughtcrime.securesms.preferences.SignalListPreference>

<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
android:defaultValue="true"
Expand Down
34 changes: 16 additions & 18 deletions res/xml/preferences_notifications.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,20 @@
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
android:key="pref_key_enable_notifications"
android:title="@string/preferences__notifications"
android:summary="@string/preferences__enable_message_notifications"
android:defaultValue="true" />

<RingtonePreference android:dependency="pref_key_enable_notifications"
android:key="pref_key_ringtone"
android:title="@string/preferences__sound"
android:ringtoneType="notification"
android:defaultValue="content://settings/system/notification_sound" />
<org.thoughtcrime.securesms.preferences.SignalRingtonePreference
android:dependency="pref_key_enable_notifications"
android:key="pref_key_ringtone"
android:title="@string/preferences__sound"
android:ringtoneType="notification"
android:defaultValue="content://settings/system/notification_sound" />

<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
android:dependency="pref_key_enable_notifications"
android:key="pref_key_vibrate"
android:defaultValue="true"
android:title="@string/preferences__vibrate"
android:summary="@string/preferences__also_vibrate_when_notified" />
android:title="@string/preferences__vibrate"/>

<org.thoughtcrime.securesms.preferences.LEDColorListPreference
android:key="pref_led_color"
Expand All @@ -41,25 +40,25 @@

<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
android:key="pref_key_inthread_notifications"
android:title="@string/preferences__in_conversation_notifications"
android:summary="@string/preferences__play_inthread_notifications"
android:title="@string/preferences_notifications__in_chat_sounds"
android:dependency="pref_key_enable_notifications"
android:defaultValue="true" />

<ListPreference
<org.thoughtcrime.securesms.preferences.SignalListPreference
android:key="pref_repeat_alerts"
android:defaultValue="0"
android:title="@string/preferences__repeat_alerts"
android:dependency="pref_key_enable_notifications"
android:entries="@array/pref_repeat_alerts_entries"
android:entryValues="@array/pref_repeat_alerts_values" />

<ListPreference android:key="pref_notification_privacy"
android:title="@string/preferences_notifications__display_in_notifications"
android:dependency="pref_key_enable_notifications"
android:defaultValue="all"
android:entries="@array/pref_notification_privacy_entries"
android:entryValues="@array/pref_notification_privacy_values"/>
<org.thoughtcrime.securesms.preferences.SignalListPreference
android:key="pref_notification_privacy"
android:title="@string/preferences_notifications__show"
android:dependency="pref_key_enable_notifications"
android:defaultValue="all"
android:entries="@array/pref_notification_privacy_entries"
android:entryValues="@array/pref_notification_privacy_values"/>
</PreferenceCategory>

<PreferenceCategory android:layout="@layout/preference_divider"/>
Expand All @@ -68,7 +67,6 @@
<org.thoughtcrime.securesms.components.SwitchPreferenceCompat
android:key="pref_enable_new_contacts_notifications"
android:title="@string/preferences_events__contact_joined_signal"
android:summary="@string/preferences__show_a_notification_for_new_signal_contacts"
android:defaultValue="true" />
</PreferenceCategory>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
* @author Moxie Marlinspike
*/

public class LedBlinkPatternListPreference extends ListPreference implements OnSeekBarChangeListener {
public class LedBlinkPatternListPreference extends SignalListPreference implements OnSeekBarChangeListener {

private Context context;
private SeekBar seekBarOn;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package org.thoughtcrime.securesms.preferences;


import android.content.Context;
import android.os.Build;
import android.preference.ListPreference;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.widget.TextView;

import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.util.ViewUtil;

public class SignalListPreference extends ListPreference {

private TextView rightSummary;
private CharSequence summary;

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public SignalListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
initialize();
}

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public SignalListPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initialize();
}

public SignalListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
initialize();
}

public SignalListPreference(Context context) {
super(context);
initialize();
}

private void initialize() {
setWidgetLayoutResource(R.layout.preference_right_summary_widget);
}

@Override
protected void onBindView(View view) {
super.onBindView(view);

this.rightSummary = (TextView)view.findViewById(R.id.right_summary);
setSummary(this.summary);
}

@Override
public void setSummary(CharSequence summary) {
super.setSummary(null);

this.summary = summary;

if (this.rightSummary != null) {
this.rightSummary.setText(summary);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package org.thoughtcrime.securesms.preferences;


import android.content.Context;
import android.os.Build;
import android.preference.RingtonePreference;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.view.View;
import android.widget.TextView;

import org.thoughtcrime.securesms.R;

public class SignalRingtonePreference extends RingtonePreference {

private TextView rightSummary;
private CharSequence summary;

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public SignalRingtonePreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
initialize();
}

public SignalRingtonePreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
initialize();
}

public SignalRingtonePreference(Context context, AttributeSet attrs) {
super(context, attrs);
initialize();
}

public SignalRingtonePreference(Context context) {
super(context);
initialize();
}

private void initialize() {
setWidgetLayoutResource(R.layout.preference_right_summary_widget);
}

@Override
protected void onBindView(View view) {
super.onBindView(view);

this.rightSummary = (TextView)view.findViewById(R.id.right_summary);
setSummary(summary);
}

@Override
public void setSummary(CharSequence summary) {
this.summary = summary;

super.setSummary(null);

if (rightSummary != null) {
rightSummary.setText(summary);
}
}

}

0 comments on commit 2dceef5

Please sign in to comment.