Skip to content

Commit 1bf5dda

Browse files
seannemann21neslihanturan
authored andcommitted
Allow for settings titles to expand across multiple lines instead of being truncated (#1671)
* Added preference classes that allow for titles with multiple lines for settings with long titles * Added null checks to ensure the title TextView isn't null
1 parent 5cfe709 commit 1bf5dda

File tree

6 files changed

+190
-13
lines changed

6 files changed

+190
-13
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package fr.free.nrw.commons.ui.LongTitlePreferences;
2+
3+
import android.content.Context;
4+
import android.preference.EditTextPreference;
5+
import android.util.AttributeSet;
6+
import android.view.View;
7+
import android.widget.TextView;
8+
9+
/**
10+
* Created by seannemann on 6/27/2018.
11+
*/
12+
13+
public class LongTitleEditTextPreference extends EditTextPreference {
14+
public LongTitleEditTextPreference(Context context, AttributeSet attrs, int defStyleAttr) {
15+
super(context, attrs, defStyleAttr);
16+
}
17+
18+
public LongTitleEditTextPreference(Context context, AttributeSet attrs) {
19+
super(context, attrs);
20+
}
21+
22+
public LongTitleEditTextPreference(Context context) {
23+
24+
super(context);
25+
}
26+
27+
@Override
28+
protected void onBindView(View view)
29+
{
30+
super.onBindView(view);
31+
32+
TextView title= view.findViewById(android.R.id.title);
33+
if (title != null) {
34+
title.setSingleLine(false);
35+
}
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package fr.free.nrw.commons.ui.LongTitlePreferences;
2+
3+
import android.content.Context;
4+
import android.preference.ListPreference;
5+
import android.util.AttributeSet;
6+
import android.view.View;
7+
import android.widget.TextView;
8+
9+
/**
10+
* Created by seannemann on 6/27/2018.
11+
*/
12+
13+
public class LongTitleListPreference extends ListPreference {
14+
public LongTitleListPreference(Context context, AttributeSet attrs) {
15+
super(context, attrs);
16+
}
17+
18+
public LongTitleListPreference(Context context) {
19+
super(context);
20+
}
21+
22+
@Override
23+
protected void onBindView(View view)
24+
{
25+
super.onBindView(view);
26+
27+
TextView title= view.findViewById(android.R.id.title);
28+
if (title != null) {
29+
title.setSingleLine(false);
30+
}
31+
}
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package fr.free.nrw.commons.ui.LongTitlePreferences;
2+
3+
import android.content.Context;
4+
import android.preference.Preference;
5+
import android.util.AttributeSet;
6+
import android.view.View;
7+
import android.widget.TextView;
8+
9+
/**
10+
* Created by seannemann on 6/27/2018.
11+
*/
12+
13+
public class LongTitlePreference extends Preference {
14+
public LongTitlePreference(Context context, AttributeSet attrs, int defStyleAttr) {
15+
super(context, attrs, defStyleAttr);
16+
}
17+
18+
public LongTitlePreference(Context context, AttributeSet attrs) {
19+
super(context, attrs);
20+
}
21+
22+
public LongTitlePreference(Context context) {
23+
super(context);
24+
}
25+
26+
@Override
27+
protected void onBindView(View view)
28+
{
29+
super.onBindView(view);
30+
31+
TextView title= view.findViewById(android.R.id.title);
32+
if (title != null) {
33+
title.setSingleLine(false);
34+
}
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package fr.free.nrw.commons.ui.LongTitlePreferences;
2+
3+
import android.content.Context;
4+
import android.preference.PreferenceCategory;
5+
import android.util.AttributeSet;
6+
import android.view.View;
7+
import android.widget.TextView;
8+
9+
/**
10+
* Created by seannemann on 6/27/2018.
11+
*/
12+
13+
public class LongTitlePreferenceCategory extends PreferenceCategory {
14+
public LongTitlePreferenceCategory(Context context, AttributeSet attrs, int defStyleAttr) {
15+
super(context, attrs, defStyleAttr);
16+
}
17+
18+
public LongTitlePreferenceCategory(Context context, AttributeSet attrs) {
19+
super(context, attrs);
20+
}
21+
22+
public LongTitlePreferenceCategory(Context context) {
23+
super(context);
24+
}
25+
26+
@Override
27+
protected void onBindView(View view)
28+
{
29+
super.onBindView(view);
30+
31+
TextView title= view.findViewById(android.R.id.title);
32+
if (title != null) {
33+
title.setSingleLine(false);
34+
}
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package fr.free.nrw.commons.ui.LongTitlePreferences;
2+
3+
import android.content.Context;
4+
import android.preference.SwitchPreference;
5+
import android.util.AttributeSet;
6+
import android.view.View;
7+
import android.widget.TextView;
8+
9+
/**
10+
* Created by seannemann on 6/27/2018.
11+
*/
12+
13+
public class LongTitleSwitchPreference extends SwitchPreference {
14+
public LongTitleSwitchPreference(Context context, AttributeSet attrs, int defStyleAttr) {
15+
super(context, attrs, defStyleAttr);
16+
}
17+
18+
public LongTitleSwitchPreference(Context context, AttributeSet attrs) {
19+
super(context, attrs);
20+
}
21+
22+
public LongTitleSwitchPreference(Context context) {
23+
super(context);
24+
}
25+
26+
@Override
27+
protected void onBindView(View view)
28+
{
29+
super.onBindView(view);
30+
31+
TextView title= view.findViewById(android.R.id.title);
32+
if (title != null) {
33+
title.setSingleLine(false);
34+
}
35+
}
36+
}

app/src/main/res/xml/preferences.xml

+13-13
Original file line numberDiff line numberDiff line change
@@ -2,58 +2,58 @@
22
<PreferenceScreen
33
xmlns:android="http://schemas.android.com/apk/res/android">
44

5-
<PreferenceCategory
5+
<fr.free.nrw.commons.ui.LongTitlePreferences.LongTitlePreferenceCategory
66
android:title="@string/preference_category_appearance">
77

8-
<SwitchPreference
8+
<fr.free.nrw.commons.ui.LongTitlePreferences.LongTitleSwitchPreference
99
android:title="@string/preference_theme"
1010
android:defaultValue="false"
1111
android:summary="@string/preference_theme_summary"
1212
android:key="theme" />
1313

14-
</PreferenceCategory>
14+
</fr.free.nrw.commons.ui.LongTitlePreferences.LongTitlePreferenceCategory>
1515

16-
<PreferenceCategory
16+
<fr.free.nrw.commons.ui.LongTitlePreferences.LongTitlePreferenceCategory
1717
android:title="@string/preference_category_general">
1818

19-
<ListPreference
19+
<fr.free.nrw.commons.ui.LongTitlePreferences.LongTitleListPreference
2020
android:key="defaultLicense"
2121
android:title="@string/preference_license"
2222
android:entries="@array/pref_defaultLicense_entries"
2323
android:entryValues="@array/pref_defaultLicense_values"
2424
android:defaultValue="@string/license_pref_cc_by_sa_4_0" />
2525

26-
<SwitchPreference
26+
<fr.free.nrw.commons.ui.LongTitlePreferences.LongTitleSwitchPreference
2727
android:key="useExternalStorage"
2828
android:title="@string/use_external_storage"
2929
android:defaultValue="true"
3030
android:summary="@string/use_external_storage_summary" />
3131

32-
<EditTextPreference
32+
<fr.free.nrw.commons.ui.LongTitlePreferences.LongTitleEditTextPreference
3333
android:key="uploads"
3434
android:defaultValue="100"
3535
android:title= "@string/set_limit"
3636
android:inputType="numberDecimal"
3737
android:maxLength="3" />
3838

39-
</PreferenceCategory>
39+
</fr.free.nrw.commons.ui.LongTitlePreferences.LongTitlePreferenceCategory>
4040

4141
<!-- The key 'allowGps' was used before and has since been removed based on the discussion at #1599.
4242
Do not reuse this key unless you revive the same feature with the changes mentioned at #1599.-->
4343

44-
<PreferenceCategory
44+
<fr.free.nrw.commons.ui.LongTitlePreferences.LongTitlePreferenceCategory
4545
android:title="@string/preference_category_feedback">
4646

47-
<Preference
47+
<fr.free.nrw.commons.ui.LongTitlePreferences.LongTitlePreference
4848
android:key="becomeBetaTester"
4949
android:title="@string/become_a_tester_title"
5050
android:summary="@string/become_a_tester_description">
51-
</Preference>
51+
</fr.free.nrw.commons.ui.LongTitlePreferences.LongTitlePreference>
5252

53-
<Preference
53+
<fr.free.nrw.commons.ui.LongTitlePreferences.LongTitlePreference
5454
android:key="sendLogFile"
5555
android:title="@string/send_log_file"
5656
android:summary="@string/send_log_file_description"/>
5757

58-
</PreferenceCategory>
58+
</fr.free.nrw.commons.ui.LongTitlePreferences.LongTitlePreferenceCategory>
5959
</PreferenceScreen>

0 commit comments

Comments
 (0)