Respect font size and font family preferences

This commit is contained in:
Stefan Niedermann 2020-06-07 18:57:55 +02:00 committed by Niedermann IT-Dienstleistungen
parent 9ec6054aa7
commit 23b10cd719
6 changed files with 34 additions and 20 deletions

View file

@ -3,7 +3,6 @@ package it.niedermann.owncloud.notes.android.fragment;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
import android.graphics.Color;
@ -271,22 +270,6 @@ public abstract class BaseNoteFragment extends BrandedFragment implements Catego
}
}
@SuppressWarnings("WeakerAccess") //PMD...
protected float getFontSizeFromPreferences(SharedPreferences sp) {
final String prefValueSmall = getString(R.string.pref_value_font_size_small);
final String prefValueMedium = getString(R.string.pref_value_font_size_medium);
// final String prefValueLarge = getString(R.string.pref_value_font_size_large);
String fontSize = sp.getString(getString(R.string.pref_key_font_size), prefValueMedium);
if (fontSize.equals(prefValueSmall)) {
return getResources().getDimension(R.dimen.note_font_size_small);
} else if (fontSize.equals(prefValueMedium)) {
return getResources().getDimension(R.dimen.note_font_size_medium);
} else {
return getResources().getDimension(R.dimen.note_font_size_large);
}
}
protected abstract String getContent();
/**

View file

@ -41,6 +41,7 @@ import it.niedermann.owncloud.notes.util.format.ContextBasedRangeFormattingCallb
import static androidx.core.view.ViewCompat.isAttachedToWindow;
import static it.niedermann.owncloud.notes.util.DisplayUtils.searchAndColor;
import static it.niedermann.owncloud.notes.util.NoteUtil.getFontSizeFromPreferences;
public class NoteEditFragment extends SearchableBaseNoteFragment {
@ -169,7 +170,7 @@ public class NoteEditFragment extends SearchableBaseNoteFragment {
binding.editContent.setCustomInsertionActionModeCallback(new ContextBasedFormattingCallback(binding.editContent));
}
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(requireContext().getApplicationContext());
binding.editContent.setTextSize(TypedValue.COMPLEX_UNIT_PX, getFontSizeFromPreferences(sp));
binding.editContent.setTextSize(TypedValue.COMPLEX_UNIT_PX, getFontSizeFromPreferences(requireContext(), sp));
if (sp.getBoolean(getString(R.string.pref_key_font), false)) {
binding.editContent.setTypeface(Typeface.MONOSPACE);
}

View file

@ -48,6 +48,7 @@ import static it.niedermann.owncloud.notes.util.MarkDownUtil.CHECKBOX_UNCHECKED_
import static it.niedermann.owncloud.notes.util.MarkDownUtil.parseCompat;
import static it.niedermann.owncloud.notes.util.NoteLinksUtils.extractNoteRemoteId;
import static it.niedermann.owncloud.notes.util.NoteLinksUtils.replaceNoteLinksWithDummyUrls;
import static it.niedermann.owncloud.notes.util.NoteUtil.getFontSizeFromPreferences;
public class NotePreviewFragment extends SearchableBaseNoteFragment implements OnRefreshListener {
@ -180,7 +181,7 @@ public class NotePreviewFragment extends SearchableBaseNoteFragment implements O
binding.swiperefreshlayout.setOnRefreshListener(this);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(requireActivity().getApplicationContext());
binding.singleNoteContent.setTextSize(TypedValue.COMPLEX_UNIT_PX, getFontSizeFromPreferences(sp));
binding.singleNoteContent.setTextSize(TypedValue.COMPLEX_UNIT_PX, getFontSizeFromPreferences(requireContext(), sp));
if (sp.getBoolean(getString(R.string.pref_key_font), false)) {
binding.singleNoteContent.setTypeface(Typeface.MONOSPACE);
}

View file

@ -36,6 +36,7 @@ import it.niedermann.owncloud.notes.util.NoteLinksUtils;
import static androidx.core.view.ViewCompat.isAttachedToWindow;
import static it.niedermann.owncloud.notes.util.DisplayUtils.searchAndColor;
import static it.niedermann.owncloud.notes.util.MarkDownUtil.parseCompat;
import static it.niedermann.owncloud.notes.util.NoteUtil.getFontSizeFromPreferences;
public class NoteReadonlyFragment extends SearchableBaseNoteFragment {
@ -130,7 +131,7 @@ public class NoteReadonlyFragment extends SearchableBaseNoteFragment {
binding.swiperefreshlayout.setEnabled(false);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(requireActivity().getApplicationContext());
binding.singleNoteContent.setTextSize(TypedValue.COMPLEX_UNIT_PX, getFontSizeFromPreferences(sp));
binding.singleNoteContent.setTextSize(TypedValue.COMPLEX_UNIT_PX, getFontSizeFromPreferences(requireContext(), sp));
if (sp.getBoolean(getString(R.string.pref_key_font), false)) {
binding.singleNoteContent.setTypeface(Typeface.MONOSPACE);
}

View file

@ -1,13 +1,17 @@
package it.niedermann.owncloud.notes.formattinghelp;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.util.TypedValue;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.preference.PreferenceManager;
import com.yydcdut.markdown.MarkdownProcessor;
import com.yydcdut.markdown.syntax.text.TextFactory;
@ -27,6 +31,7 @@ import static it.niedermann.owncloud.notes.util.MarkDownUtil.CHECKBOX_UNCHECKED_
import static it.niedermann.owncloud.notes.util.MarkDownUtil.CHECKBOX_UNCHECKED_STAR;
import static it.niedermann.owncloud.notes.util.MarkDownUtil.getMarkDownConfiguration;
import static it.niedermann.owncloud.notes.util.MarkDownUtil.parseCompat;
import static it.niedermann.owncloud.notes.util.NoteUtil.getFontSizeFromPreferences;
public class FormattingHelpActivity extends BrandedActivity {
@ -105,6 +110,12 @@ public class FormattingHelpActivity extends BrandedActivity {
.build());
binding.content.setMovementMethod(LinkMovementMethod.getInstance());
binding.content.setText(parseCompat(markdownProcessor, content));
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
binding.content.setTextSize(TypedValue.COMPLEX_UNIT_PX, getFontSizeFromPreferences(this, sp));
if (sp.getBoolean(getString(R.string.pref_key_font), false)) {
binding.content.setTypeface(Typeface.MONOSPACE);
}
}
@Override

View file

@ -1,6 +1,7 @@
package it.niedermann.owncloud.notes.util;
import android.content.Context;
import android.content.SharedPreferences;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@ -140,4 +141,20 @@ public class NoteUtil {
public static String extendCategory(@NonNull String category) {
return category.replace("/", " / ");
}
@SuppressWarnings("WeakerAccess") //PMD...
public static float getFontSizeFromPreferences(@NonNull Context context, @NonNull SharedPreferences sp) {
final String prefValueSmall = context.getString(R.string.pref_value_font_size_small);
final String prefValueMedium = context.getString(R.string.pref_value_font_size_medium);
// final String prefValueLarge = getString(R.string.pref_value_font_size_large);
String fontSize = sp.getString(context.getString(R.string.pref_key_font_size), prefValueMedium);
if (fontSize.equals(prefValueSmall)) {
return context.getResources().getDimension(R.dimen.note_font_size_small);
} else if (fontSize.equals(prefValueMedium)) {
return context.getResources().getDimension(R.dimen.note_font_size_medium);
} else {
return context.getResources().getDimension(R.dimen.note_font_size_large);
}
}
}