comment #6 - Allow to increase the font size for the whole app.

pull/17/head
Thomas 3 years ago
parent 920cd706aa
commit 89a2782429

@ -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;
});

@ -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);
}

@ -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 <http://www.gnu.org/licenses>. */
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);
}
}

@ -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());

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:orientation="vertical"
android:padding="@dimen/drawer_padding">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="@string/text_size_change" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginTop="20dp"
android:layout_marginBottom="20dp"
android:orientation="horizontal">
<TextView
android:id="@+id/set_text_size_value"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginStart="10dp" />
<SeekBar
android:id="@+id/set_text_size"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical" />
</LinearLayout>
</androidx.appcompat.widget.LinearLayoutCompat>

@ -13,6 +13,10 @@
android:id="@+id/action_proxy"
android:title="@string/proxy_set"
app:showAsAction="never" />
<item
android:id="@+id/action_size"
android:title="@string/text_size"
app:showAsAction="never" />
<item
android:id="@+id/action_logout_account"
android:title="@string/action_logout_account"

@ -1494,6 +1494,7 @@
<string name="SET_NOTIF_POLL" translatable="false">SET_NOTIF_POLL</string>
<string name="SET_NOTIF_MEDIA" translatable="false">SET_NOTIF_MEDIA</string>
<string name="SET_NOTIF_STATUS" translatable="false">SET_NOTIF_STATUS</string>
<string name="SET_FONT_SCALE" translatable="false">SET_FONT_SCALE</string>
<string name="SET_NOTIF_FOLLOW_FILTER" translatable="false">SET_NOTIF_FOLLOW_FILTER</string>
<string name="SET_NOTIF_ADD_FILTER" translatable="false">SET_NOTIF_ADD_FILTER</string>
<string name="SET_NOTIF_MENTION_FILTER" translatable="false">SET_NOTIF_MENTION_FILTER</string>

Loading…
Cancel
Save