Enable full viewport for most devices

master
M66B 2 months ago
parent ccdbd532c1
commit 1214bbf0bb

@ -184,6 +184,8 @@ public class ApplicationEx extends Application
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(@NonNull Thread thread, @NonNull Throwable ex) {
WebViewEx.checkLayer(ApplicationEx.this, ex);
if (!crash_reports && Log.isOwnFault(ex)) {
Log.e(ex);

@ -280,11 +280,6 @@ public class WebViewEx extends WebView implements DownloadListener, View.OnLongC
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
// java.lang.IllegalStateException: Unable to create layer for WebViewEx, size 768x4864 max size 8192 color type 4 has context 1
// at android.os.MessageQueue.nativePollOnce(MessageQueue.java:-2)
// at android.os.MessageQueue.next(MessageQueue.java:326)
// at android.os.Looper.loop(Looper.java:183)
// at android.app.ActivityThread.main(ActivityThread.java:7266)
if (viewportHeight == 0)
heightMeasureSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
else
@ -488,10 +483,11 @@ public class WebViewEx extends WebView implements DownloadListener, View.OnLongC
}
static int getDefaultViewportHeight(Context context) {
if (Helper.isGoogle() && Build.VERSION.SDK_INT > Build.VERSION_CODES.UPSIDE_DOWN_CAKE /* Android 14 */)
return DEFAULT_VIEWPORT_HEIGHT * 2;
else
if ((Helper.isSamsung() || Helper.isHuawei()) &&
Build.VERSION.SDK_INT <= Build.VERSION_CODES.P /* Android 9 */)
return DEFAULT_VIEWPORT_HEIGHT;
else
return 0;
}
@NonNull
@ -525,6 +521,26 @@ public class WebViewEx extends WebView implements DownloadListener, View.OnLongC
return (large ? "Mozilla/5.0" : "Mozilla/5.0 (Mobile)");
}
static void checkLayer(Context context, Throwable ex) {
// java.lang.IllegalStateException: Unable to create layer for WebViewEx, size 768x4864 max size 8192 color type 4 has context 1
// at android.os.MessageQueue.nativePollOnce(MessageQueue.java:-2)
// at android.os.MessageQueue.next(MessageQueue.java:326)
// at android.os.Looper.loop(Looper.java:183)
// at android.app.ActivityThread.main(ActivityThread.java:7266)
try {
if (ex == null)
return;
if (ex instanceof IllegalStateException &&
ex.getMessage() != null &&
ex.getMessage().contains("Unable to create layer")) {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
prefs.edit().putInt("viewport_height", DEFAULT_VIEWPORT_HEIGHT).commit();
} else
checkLayer(context, ex.getCause());
} catch (Throwable ignored) {
}
}
interface IWebView {
void onSizeChanged(int w, int h, int ow, int oh);

Loading…
Cancel
Save