Added option to enlarge text size in distraction free mode

pull/145/head
M66B 6 years ago
parent 43d7add8f4
commit 926ac6cf0a

@ -26,6 +26,7 @@ import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
@ -47,6 +48,7 @@ import android.text.method.LinkMovementMethod;
import android.text.style.ImageSpan;
import android.text.style.URLSpan;
import android.util.Log;
import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
@ -361,6 +363,8 @@ public class FragmentMessage extends FragmentEx {
grpRawHeaders.setVisibility(View.GONE);
grpAttachments.setVisibility(View.GONE);
grpError.setVisibility(View.GONE);
setTextSize();
}
});
@ -383,6 +387,8 @@ public class FragmentMessage extends FragmentEx {
grpRawHeaders.setVisibility(headers ? View.VISIBLE : View.GONE);
grpAttachments.setVisibility(adapter != null && adapter.getItemCount() > 0 ? View.VISIBLE : View.GONE);
setTextSize();
return true;
}
return false;
@ -668,6 +674,7 @@ public class FragmentMessage extends FragmentEx {
boolean inOutbox = EntityFolder.OUTBOX.equals(message.folderType);
menu.findItem(R.id.menu_addresses).setVisible(!free);
menu.findItem(R.id.menu_text_size).setVisible(free);
menu.findItem(R.id.menu_thread).setVisible(message.count > 1);
menu.findItem(R.id.menu_forward).setVisible(message.content && !inOutbox);
menu.findItem(R.id.menu_show_headers).setChecked(headers);
@ -683,6 +690,9 @@ public class FragmentMessage extends FragmentEx {
case R.id.menu_addresses:
onMenuAddresses();
return true;
case R.id.menu_text_size:
onMenuTextSize();
return true;
case R.id.menu_thread:
onMenuThread();
return true;
@ -714,6 +724,15 @@ public class FragmentMessage extends FragmentEx {
grpAddresses.setVisibility(addresses ? View.VISIBLE : View.GONE);
}
private void onMenuTextSize() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
int size = prefs.getInt("size", 0);
size = ++size % 3;
prefs.edit().putInt("size", size).apply();
setTextSize();
}
private void onMenuThread() {
getFragmentManager().popBackStack("thread", FragmentManager.POP_BACK_STACK_INCLUSIVE);
@ -1228,6 +1247,7 @@ public class FragmentMessage extends FragmentEx {
SpannedString ss = new SpannedString(body);
boolean has_images = (ss.getSpans(0, ss.length(), ImageSpan.class).length > 0);
setTextSize();
tvBody.setText(body);
btnImages.setVisibility(has_images && !show_images ? View.VISIBLE : View.GONE);
grpMessage.setVisibility(View.VISIBLE);
@ -1346,4 +1366,20 @@ public class FragmentMessage extends FragmentEx {
}
});
}
private void setTextSize() {
int style = R.style.TextAppearance_AppCompat_Small;
if (free) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getContext());
int size = prefs.getInt("size", 0);
if (size == 1)
style = R.style.TextAppearance_AppCompat_Medium;
else if (size == 2)
style = R.style.TextAppearance_AppCompat_Large;
}
TypedArray ta = getContext().obtainStyledAttributes(style, new int[]{android.R.attr.textSize});
tvBody.setTextSize(TypedValue.COMPLEX_UNIT_PX, ta.getDimensionPixelSize(0, 0));
}
}

@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24.0"
android:viewportHeight="24.0"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M9,4v3h5v12h3L17,7h5L22,4L9,4zM3,12h3v7h3v-7h3L12,9L3,9v3z"/>
</vector>

@ -8,6 +8,12 @@
android:title="@string/title_show_addresses"
app:showAsAction="ifRoom" />
<item
android:id="@+id/menu_text_size"
android:icon="@drawable/baseline_format_size_24"
android:title="@string/title_text_size"
app:showAsAction="ifRoom" />
<item
android:id="@+id/menu_thread"
android:icon="@drawable/baseline_message_24"

@ -214,6 +214,7 @@
<string name="title_style_image">Insert image</string>
<string name="title_add_attachment">Add attachment</string>
<string name="title_show_addresses">Show CC/BCC</string>
<string name="title_text_size">Text size</string>
<string name="title_from_missing">Sender missing</string>
<string name="title_to_missing">Recipient missing</string>

Loading…
Cancel
Save