Skip to content

Commit 1456b7c

Browse files
committed
Text size choice in the setting interface is more convenient
1 parent 0df515b commit 1456b7c

File tree

5 files changed

+116
-2
lines changed

5 files changed

+116
-2
lines changed

build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ buildscript {
2121
google()
2222
}
2323
dependencies {
24-
classpath 'com.android.tools.build:gradle:3.0.0'
24+
classpath 'com.android.tools.build:gradle:3.0.1'
2525
classpath 'me.tatarka:gradle-retrolambda:3.2.5'
2626
classpath 'me.tatarka.retrolambda.projectlombok:lombok.ast:0.2.3.a2'
2727
classpath "org.sonarsource.scanner.gradle:sonarqube-gradle-plugin:2.6"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package it.feio.android.omninotes;
2+
3+
import android.app.AlertDialog;
4+
import android.content.Context;
5+
import android.content.DialogInterface;
6+
import android.preference.ListPreference;
7+
import android.support.annotation.NonNull;
8+
import android.util.AttributeSet;
9+
import android.view.View;
10+
import android.view.ViewGroup;
11+
import android.widget.ArrayAdapter;
12+
import android.widget.CheckedTextView;
13+
import android.widget.TextView;
14+
15+
import it.feio.android.checklistview.utils.DensityUtil;
16+
import it.feio.android.omninotes.utils.Fonts;
17+
18+
public class FontSizeListPreference extends ListPreference {
19+
20+
private int clickedDialogEntryIndex;
21+
22+
23+
public FontSizeListPreference(Context context, AttributeSet attrs) {
24+
super(context, attrs);
25+
}
26+
27+
@Override
28+
protected void onBindView(View view) {
29+
super.onBindView(view);
30+
TextView summary = (TextView) view.findViewById(android.R.id.summary);
31+
Fonts.overrideTextSize(getContext(),getSharedPreferences(),summary);
32+
}
33+
34+
@Override
35+
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
36+
37+
ArrayAdapter<CharSequence> adapter = new ArrayAdapter<CharSequence>(getContext(),
38+
R.layout.settings_font_size_dialog_item, getEntries()) {
39+
@NonNull
40+
@Override
41+
public View getView(int position, View convertView, @NonNull ViewGroup parent) {
42+
CheckedTextView view = (CheckedTextView) convertView;
43+
if (view == null) {
44+
view = (CheckedTextView) View.inflate(getContext(),
45+
R.layout.settings_font_size_dialog_item, null);
46+
}
47+
view.setText(getEntries()[position]);
48+
Context privateContext = getContext().getApplicationContext();
49+
float currentSize = DensityUtil.pxToDp(((TextView) View.inflate(getContext(),
50+
R.layout.settings_font_size_dialog_item, null)).getTextSize(), privateContext);
51+
float offset = privateContext.getResources().getIntArray(
52+
R.array.text_size_offset)[position];
53+
view.setTextSize(currentSize + offset);
54+
return view;
55+
}
56+
};
57+
clickedDialogEntryIndex = findIndexOfValue(getValue());
58+
builder.setSingleChoiceItems(adapter, clickedDialogEntryIndex,
59+
(dialog, which) -> {
60+
clickedDialogEntryIndex = which;
61+
FontSizeListPreference.this.onClick(dialog, DialogInterface.BUTTON_POSITIVE);
62+
dialog.dismiss();
63+
});
64+
builder.setPositiveButton(null, null);
65+
}
66+
67+
@Override
68+
protected void onDialogClosed(boolean positiveResult) {
69+
super.onDialogClosed(positiveResult);
70+
71+
if (positiveResult && clickedDialogEntryIndex >= 0 && getEntryValues() != null) {
72+
String val = getEntryValues()[clickedDialogEntryIndex].toString();
73+
if (callChangeListener(val)) {
74+
setValue(val);
75+
}
76+
}
77+
}
78+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:layout_width="match_parent"
3+
android:layout_height="?android:attr/listPreferredItemHeightSmall"
4+
android:height="48dp"
5+
android:gravity="center_vertical"
6+
android:paddingEnd="?android:attr/listPreferredItemPaddingRight"
7+
android:paddingLeft="?android:attr/listPreferredItemPaddingLeft"
8+
android:paddingRight="?android:attr/listPreferredItemPaddingRight"
9+
android:paddingStart="?android:attr/listPreferredItemPaddingLeft"
10+
android:textAppearance="?android:attr/textAppearanceListItemSmall"
11+
android:drawableLeft="?android:attr/listChoiceIndicatorSingle"
12+
android:drawableStart="?android:attr/listChoiceIndicatorSingle" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:layout_width="match_parent"
4+
android:layout_height="wrap_content"
5+
android:padding="?android:attr/listPreferredItemPaddingLeft">
6+
7+
<TextView android:id="@+android:id/title"
8+
android:layout_width="wrap_content"
9+
android:layout_height="wrap_content"
10+
android:singleLine="true"
11+
android:ellipsize="marquee"
12+
android:textAppearance="?android:attr/textAppearanceListItemSmall"
13+
android:fadingEdge="horizontal" />
14+
15+
<TextView android:id="@android:id/summary"
16+
android:layout_width="wrap_content"
17+
android:layout_height="wrap_content"
18+
android:layout_below="@android:id/title"
19+
android:layout_alignStart="@android:id/title"
20+
android:textAppearance="?android:attr/textAppearanceSmall"
21+
android:layout_alignLeft="@android:id/title" />
22+
23+
</RelativeLayout>

omniNotes/src/main/res/xml/settings_interface.xml

+2-1
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
android:key="settings_language"
2525
android:title="@string/settings_choose_language"/>
2626

27-
<ListPreference
27+
<it.feio.android.omninotes.FontSizeListPreference
2828
android:entries="@array/text_size"
2929
android:entryValues="@array/text_size_values"
3030
android:key="settings_text_size"
3131
android:title="@string/settings_text_size"
32+
android:layout="@layout/settings_font_size_item"
3233
android:defaultValue="default"/>
3334

3435
<ListPreference

0 commit comments

Comments
 (0)