From 89a2782429b066b2762c0ddff581b4d86757cdde Mon Sep 17 00:00:00 2001 From: Thomas Date: Sat, 30 Apr 2022 10:06:07 +0200 Subject: [PATCH] comment #6 - Allow to increase the font size for the whole app. --- .../app/fedilab/android/BaseMainActivity.java | 46 +++++++++++++++++++ .../android/activities/BaseActivity.java | 2 + .../fedilab/android/helper/ThemeHelper.java | 22 +++++++++ .../FragmentNotificationsSettings.java | 3 +- app/src/main/res/layout/popup_text_size.xml | 38 +++++++++++++++ app/src/main/res/menu/main.xml | 4 ++ app/src/main/res/values/strings.xml | 1 + 7 files changed, 114 insertions(+), 2 deletions(-) create mode 100644 app/src/main/res/layout/popup_text_size.xml diff --git a/app/src/main/java/app/fedilab/android/BaseMainActivity.java b/app/src/main/java/app/fedilab/android/BaseMainActivity.java index 59ae449c..9064ddf1 100644 --- a/app/src/main/java/app/fedilab/android/BaseMainActivity.java +++ b/app/src/main/java/app/fedilab/android/BaseMainActivity.java @@ -36,6 +36,9 @@ import android.view.MenuItem; import android.view.SubMenu; import android.view.View; import android.view.inputmethod.InputMethodManager; +import android.widget.LinearLayout; +import android.widget.SeekBar; +import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -426,6 +429,49 @@ public abstract class BaseMainActivity extends BaseActivity implements NetworkSt Intent intent = new Intent(BaseMainActivity.this, ProxyActivity.class); startActivity(intent); return true; + } else if (itemId == R.id.action_size) { + float scale = sharedpreferences.getFloat(getString(R.string.SET_FONT_SCALE), 1.0f); + + AlertDialog.Builder builder = new AlertDialog.Builder(BaseMainActivity.this, Helper.dialogStyle()); + builder.setTitle(R.string.text_size); + View popup_quick_settings = getLayoutInflater().inflate(R.layout.popup_text_size, new LinearLayout(BaseMainActivity.this), false); + builder.setView(popup_quick_settings); + SeekBar set_text_size = popup_quick_settings.findViewById(R.id.set_text_size); + final TextView set_text_size_value = popup_quick_settings.findViewById(R.id.set_text_size_value); + set_text_size_value.setText(String.format("%s%%", scale * 100)); + + set_text_size.setMax(20); + + set_text_size.setProgress((((int) (scale * 100) - 80) / 5)); + + set_text_size.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { + @Override + public void onStopTrackingTouch(SeekBar seekBar) { + } + + @Override + public void onStartTrackingTouch(SeekBar seekBar) { + } + + @Override + public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) { + + int value = 80 + progress * 5; + float scale = (float) (value) / 100.0f; + set_text_size_value.setText(String.format("%s%%", value)); + SharedPreferences.Editor editor = sharedpreferences.edit(); + editor.putFloat(getString(R.string.SET_FONT_SCALE), scale); + editor.apply(); + } + }); + builder.setPositiveButton(R.string.validate, (dialog, which) -> { + BaseMainActivity.this.recreate(); + recreate(); + dialog.dismiss(); + }) + .setIcon(android.R.drawable.ic_dialog_alert) + .show(); + return true; } return true; }); diff --git a/app/src/main/java/app/fedilab/android/activities/BaseActivity.java b/app/src/main/java/app/fedilab/android/activities/BaseActivity.java index 90dd682b..a61b0665 100644 --- a/app/src/main/java/app/fedilab/android/activities/BaseActivity.java +++ b/app/src/main/java/app/fedilab/android/activities/BaseActivity.java @@ -25,6 +25,7 @@ import com.vanniktech.emoji.EmojiManager; import com.vanniktech.emoji.one.EmojiOneProvider; import app.fedilab.android.helper.Helper; +import app.fedilab.android.helper.ThemeHelper; @SuppressLint("Registered") @@ -38,6 +39,7 @@ public class BaseActivity extends CyaneaAppCompatActivity { @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); + ThemeHelper.adjustFontScale(this, getResources().getConfiguration()); Helper.setLocale(this); } diff --git a/app/src/main/java/app/fedilab/android/helper/ThemeHelper.java b/app/src/main/java/app/fedilab/android/helper/ThemeHelper.java index aad12090..d09a8a0a 100644 --- a/app/src/main/java/app/fedilab/android/helper/ThemeHelper.java +++ b/app/src/main/java/app/fedilab/android/helper/ThemeHelper.java @@ -14,15 +14,20 @@ package app.fedilab.android.helper; * You should have received a copy of the GNU General Public License along with Fedilab; if not, * see . */ +import static android.content.Context.WINDOW_SERVICE; + import android.app.Activity; import android.content.Context; import android.content.Intent; import android.content.SharedPreferences; import android.content.res.ColorStateList; +import android.content.res.Configuration; import android.content.res.Resources; import android.os.Bundle; +import android.util.DisplayMetrics; import android.util.TypedValue; import android.view.View; +import android.view.WindowManager; import android.view.animation.Animation; import android.view.animation.TranslateAnimation; @@ -368,4 +373,21 @@ public class ThemeHelper { public interface SlideAnimation { void onAnimationEnded(); } + + + /** + * Allow to change font scale in activities + * + * @param activity - Activity + * @param configuration - Configuration + */ + public static void adjustFontScale(Activity activity, Configuration configuration) { + SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(activity); + configuration.fontScale = prefs.getFloat(activity.getString(R.string.SET_FONT_SCALE), 1.0f); + DisplayMetrics metrics = activity.getResources().getDisplayMetrics(); + WindowManager wm = (WindowManager) activity.getSystemService(WINDOW_SERVICE); + wm.getDefaultDisplay().getMetrics(metrics); + metrics.scaledDensity = configuration.fontScale * metrics.density; + activity.getBaseContext().getResources().updateConfiguration(configuration, metrics); + } } diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentNotificationsSettings.java b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentNotificationsSettings.java index ecd84ab2..2e8e13e3 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentNotificationsSettings.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/settings/FragmentNotificationsSettings.java @@ -28,7 +28,6 @@ import androidx.preference.ListPreference; import androidx.preference.Preference; import androidx.preference.PreferenceCategory; import androidx.preference.PreferenceFragmentCompat; -import androidx.preference.PreferenceManager; import androidx.preference.PreferenceScreen; import app.fedilab.android.R; @@ -74,7 +73,7 @@ public class FragmentNotificationsSettings extends PreferenceFragmentCompat impl return; } - SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(requireActivity()); + ListPreference SET_NOTIFICATION_TYPE = findPreference(getString(R.string.SET_NOTIFICATION_TYPE)); if (SET_NOTIFICATION_TYPE != null) { SET_NOTIFICATION_TYPE.getContext().setTheme(Helper.dialogStyle()); diff --git a/app/src/main/res/layout/popup_text_size.xml b/app/src/main/res/layout/popup_text_size.xml new file mode 100644 index 00000000..17a0a016 --- /dev/null +++ b/app/src/main/res/layout/popup_text_size.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/menu/main.xml b/app/src/main/res/menu/main.xml index 0642c09c..9efab0d9 100644 --- a/app/src/main/res/menu/main.xml +++ b/app/src/main/res/menu/main.xml @@ -13,6 +13,10 @@ android:id="@+id/action_proxy" android:title="@string/proxy_set" app:showAsAction="never" /> + SET_NOTIF_POLL SET_NOTIF_MEDIA SET_NOTIF_STATUS + SET_FONT_SCALE SET_NOTIF_FOLLOW_FILTER SET_NOTIF_ADD_FILTER SET_NOTIF_MENTION_FILTER