mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-26 20:33:53 +01:00
fix:App should respect device font-size (#4306)
* * Add adjuctFontScale function to fix issue * Add Javadoc * reformed the codechange * rearrange the codechange * make metric and wm variable final
This commit is contained in:
parent
881239dc59
commit
12547fd34a
1 changed files with 21 additions and 2 deletions
|
|
@ -1,10 +1,11 @@
|
|||
package fr.free.nrw.commons.theme;
|
||||
|
||||
import android.content.res.Configuration;
|
||||
import android.os.Bundle;
|
||||
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.WindowManager;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
|
||||
import fr.free.nrw.commons.R;
|
||||
import fr.free.nrw.commons.di.CommonsDaggerAppCompatActivity;
|
||||
import fr.free.nrw.commons.kvstore.JsonKvStore;
|
||||
|
|
@ -27,6 +28,11 @@ public abstract class BaseActivity extends CommonsDaggerAppCompatActivity {
|
|||
super.onCreate(savedInstanceState);
|
||||
wasPreviouslyDarkTheme = systemThemeUtils.isDeviceInNightMode();
|
||||
setTheme(wasPreviouslyDarkTheme ? R.style.DarkAppTheme : R.style.LightAppTheme);
|
||||
float fontScale = android.provider.Settings.System.getFloat(
|
||||
getBaseContext().getContentResolver(),
|
||||
android.provider.Settings.System.FONT_SCALE,
|
||||
1f);
|
||||
adjustFontScale(getResources().getConfiguration(), fontScale);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -44,4 +50,17 @@ public abstract class BaseActivity extends CommonsDaggerAppCompatActivity {
|
|||
super.onDestroy();
|
||||
compositeDisposable.clear();
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply fontScale on device
|
||||
*/
|
||||
public void adjustFontScale(Configuration configuration, float scale) {
|
||||
configuration.fontScale = scale;
|
||||
final DisplayMetrics metrics = getResources().getDisplayMetrics();
|
||||
final WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
|
||||
wm.getDefaultDisplay().getMetrics(metrics);
|
||||
metrics.scaledDensity = configuration.fontScale * metrics.density;
|
||||
getBaseContext().getResources().updateConfiguration(configuration, metrics);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue