Merge pull request #10528 from osmandapp/Fix_10437

Fix #10437
This commit is contained in:
Vitaliy 2021-01-06 19:09:48 +02:00 committed by GitHub
commit 6b9fe7027e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 67 additions and 15 deletions

View file

@ -14,7 +14,7 @@
app:theme="?attr/toolbar_theme"
android:background="?attr/pstsTabBackground"/>
<WebView
<net.osmand.plus.widgets.WebViewEx
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

View file

@ -63,7 +63,8 @@
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp">
<WebView
<net.osmand.plus.widgets.WebViewEx
android:id="@+id/content_web_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

View file

@ -4,7 +4,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView android:id="@+id/webView"
<net.osmand.plus.widgets.WebViewEx
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"/>

View file

@ -4,12 +4,12 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
<net.osmand.plus.widgets.WebViewEx
android:id="@+id/webView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</WebView>
</net.osmand.plus.widgets.WebViewEx>
<include layout="@layout/mapillary_no_internet"
android:id="@+id/mapillaryNoInternetLayout"

View file

@ -3,7 +3,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<WebView
<net.osmand.plus.widgets.WebViewEx
android:id="@+id/printDialogWebview"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View file

@ -74,7 +74,7 @@
android:layout_height="0dp"
android:layout_weight="1">
<WebView
<net.osmand.plus.widgets.WebViewEx
android:id="@+id/content_web_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />

View file

@ -23,12 +23,13 @@ import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import net.osmand.plus.widgets.WebViewEx;
/**
* WebView that its scroll position can be observed.
*/
public class ObservableWebView extends WebView implements Scrollable {
public class ObservableWebView extends WebViewEx implements Scrollable {
// Fields that should be saved onSaveInstanceState
private int mPrevScrollY;

View file

@ -3,7 +3,6 @@
*/
package net.osmand.plus.activities;
import android.view.Window;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import android.annotation.SuppressLint;

View file

@ -1,6 +1,7 @@
package net.osmand.plus.mapcontextmenu.builders.cards;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
@ -23,6 +24,7 @@ import androidx.core.content.ContextCompat;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.widgets.WebViewEx;
public abstract class AbstractCard {
@ -55,7 +57,7 @@ public abstract class AbstractCard {
@SuppressLint("SetJavaScriptEnabled")
@SuppressWarnings("deprecation")
protected static void openUrl(@NonNull Context ctx,
protected static void openUrl(@NonNull Activity ctx,
@NonNull OsmandApplication app,
@Nullable String title,
@NonNull String url,
@ -90,7 +92,7 @@ public abstract class AbstractCard {
}
});
final WebView wv = new WebView(ctx);
final WebView wv = new WebViewEx(ctx);
wv.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {

View file

@ -19,6 +19,7 @@ import com.google.android.material.appbar.AppBarLayout;
import net.osmand.AndroidUtils;
import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndDialogFragment;
import net.osmand.plus.widgets.WebViewEx;
public class GpxDescriptionDialogFragment extends BaseOsmAndDialogFragment {
@ -48,7 +49,7 @@ public class GpxDescriptionDialogFragment extends BaseOsmAndDialogFragment {
AppBarLayout appBar = new AppBarLayout(ctx);
appBar.addView(topBar);
WebView webView = new WebView(ctx);
WebView webView = new WebViewEx(ctx);
webView.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
webView.getSettings().setTextZoom((int) (getResources().getConfiguration().fontScale * 100f));
Bundle args = getArguments();

View file

@ -0,0 +1,49 @@
package net.osmand.plus.widgets;
import android.content.Context;
import android.content.res.Configuration;
import android.os.Build;
import android.util.AttributeSet;
import android.webkit.WebView;
import net.osmand.plus.OsmandApplication;
public class WebViewEx extends WebView {
public WebViewEx(Context context) {
super(context);
fixWebViewResetsLocaleToUserDefault(context);
}
public WebViewEx(Context context, AttributeSet attrs) {
super(context, attrs);
fixWebViewResetsLocaleToUserDefault(context);
}
public WebViewEx(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
fixWebViewResetsLocaleToUserDefault(context);
}
public WebViewEx(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
fixWebViewResetsLocaleToUserDefault(context);
}
public WebViewEx(Context context, AttributeSet attrs, int defStyleAttr, boolean privateBrowsing) {
super(context, attrs, defStyleAttr, privateBrowsing);
fixWebViewResetsLocaleToUserDefault(context);
}
public void fixWebViewResetsLocaleToUserDefault(Context ctx) {
// issue details: https://issuetracker.google.com/issues/37113860
// also see: https://gist.github.com/amake/0ac7724681ac1c178c6f95a5b09f03ce
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
OsmandApplication app = (OsmandApplication) ctx.getApplicationContext();
app.checkPreferredLocale();
ctx.getResources().updateConfiguration(
new Configuration(app.getResources().getConfiguration()),
ctx.getResources().getDisplayMetrics());
}
}
}

View file

@ -17,7 +17,6 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;
@ -28,7 +27,6 @@ import androidx.appcompat.widget.PopupMenu;
import androidx.appcompat.widget.Toolbar;
import androidx.browser.customtabs.CustomTabsIntent;
import androidx.core.content.ContextCompat;
import androidx.core.view.MotionEventCompat;
import androidx.fragment.app.FragmentActivity;
import androidx.fragment.app.FragmentManager;