1818import android .graphics .drawable .shapes .RectShape ;
1919import android .os .Bundle ;
2020import android .text .TextUtils ;
21+ import android .util .DisplayMetrics ;
2122import android .util .Log ;
2223import android .util .LruCache ;
2324import android .view .View ;
5051import java .util .Arrays ;
5152import java .util .HashMap ;
5253import java .util .Objects ;
54+ import java .util .Properties ;
5355import java .util .concurrent .CompletableFuture ;
5456
5557import cz .vutbr .web .css .CSSFactory ;
@@ -75,6 +77,7 @@ public class CustomView extends Feature {
7577 private static File themeDir ;
7678 private final HashMap <String , Drawable > chacheDrawables = new HashMap <>();
7779 private final HashMap <String , DocumentFile > chacheUris = new HashMap <>();
80+ private Properties properties ;
7881
7982 public CustomView (@ NonNull ClassLoader loader , @ NonNull XSharedPreferences preferences ) {
8083 super (loader , preferences );
@@ -92,6 +95,10 @@ public void doHook() throws Throwable {
9295 if ((TextUtils .isEmpty (filter_itens ) && TextUtils .isEmpty (folder_theme ) && TextUtils .isEmpty (custom_css )) || !prefs .getBoolean ("custom_filters" , true ))
9396 return ;
9497
98+ properties = Utils .extractProperties (prefs .getString ("custom_css" , "" ));
99+
100+ changeDPI ();
101+
95102 hookDrawableViews ();
96103
97104 themeDir = new File (ThemePreference .rootDirectory , folder_theme );
@@ -105,11 +112,46 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable {
105112 var activity = (Activity ) param .thisObject ;
106113 View rootView = activity .getWindow ().getDecorView ().getRootView ();
107114 rootView .getViewTreeObserver ().addOnGlobalLayoutListener (() -> CompletableFuture .runAsync (() -> registerCssRules (activity , (ViewGroup ) rootView , sheet )));
115+
108116 }
109117 });
110118
111119 }
112120
121+ private void changeDPI () {
122+
123+ String dpiStr = null ;
124+ if (!Objects .equals (prefs .getString ("change_dpi" , "0" ), "0" )) {
125+ dpiStr = prefs .getString ("change_dpi" , "0" );
126+ } else if (properties .getProperty ("change_dpi" ) != null ) {
127+ dpiStr = properties .getProperty ("change_dpi" );
128+ }
129+
130+ if (dpiStr == null ) return ;
131+
132+ int dpi = 0 ;
133+ try {
134+ dpi = Integer .parseInt (dpiStr );
135+ } catch (NumberFormatException e ) {
136+ logDebug ("Error parsing dpi: " + e .getMessage ());
137+ }
138+ if (dpi != 0 ) {
139+ dpi = dpi == 0 ? Integer .parseInt (properties .getProperty ("change_dpi" )) : dpi ;
140+ var res = Utils .getApplication ().getResources ();
141+ DisplayMetrics runningMetrics = res .getDisplayMetrics ();
142+ DisplayMetrics newMetrics ;
143+ if (runningMetrics != null ) {
144+ newMetrics = new DisplayMetrics ();
145+ newMetrics .setTo (runningMetrics );
146+ } else {
147+ newMetrics = res .getDisplayMetrics ();
148+ }
149+ newMetrics .density = dpi / 160f ;
150+ newMetrics .densityDpi = dpi ;
151+ res .getDisplayMetrics ().setTo (newMetrics );
152+ }
153+ }
154+
113155 private void hookDrawableViews () {
114156 XposedHelpers .findAndHookMethod (View .class , "setBackground" , Drawable .class , new XC_MethodHook () {
115157 @ Override
0 commit comments