Skip to content

Commit 8b4e09a

Browse files
committed
Add change Dpi
Signed-off-by: Dev4Mod <[email protected]>
1 parent 443889f commit 8b4e09a

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

app/src/main/java/com/wmods/wppenhacer/xposed/features/customization/CustomView.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import android.graphics.drawable.shapes.RectShape;
1919
import android.os.Bundle;
2020
import android.text.TextUtils;
21+
import android.util.DisplayMetrics;
2122
import android.util.Log;
2223
import android.util.LruCache;
2324
import android.view.View;
@@ -50,6 +51,7 @@
5051
import java.util.Arrays;
5152
import java.util.HashMap;
5253
import java.util.Objects;
54+
import java.util.Properties;
5355
import java.util.concurrent.CompletableFuture;
5456

5557
import 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

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,4 +407,6 @@
407407
<string name="download_folder_permission">Download Folder Permission</string>
408408
<string name="lite_mode">Lite Mode</string>
409409
<string name="lite_mode_sum">Lite Mode disables most theme features and the connection bridge that keeps WhatsApp always active is turned off.</string>
410+
<string name="change_default_dpi">Change Default DPI</string>
411+
<string name="change_default_dpi_sum">Change the DPI setting for the application. Use 0 to reset to default.</string>
410412
</resources>

app/src/main/res/xml/fragment_customization.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,13 @@
106106
app:key="css_theme"
107107
app:title="@string/custom_theme_css" />
108108

109+
<EditTextPreference
110+
android:summary="@string/change_default_dpi_sum"
111+
app:defaultValue="0"
112+
app:dependency="custom_filters"
113+
app:key="change_dpi"
114+
app:title="@string/change_default_dpi" />
115+
109116
<com.wmods.wppenhacer.preference.ThemePreference
110117
android:key="folder_theme"
111118
app:dependency="custom_filters"

0 commit comments

Comments
 (0)