forked from github/phonegap-mobile-accessibility
Add support for adjusting text in the WebView to the preferred zoom scale on Android.
More robust iOS support is forthcoming, but currently works with iOS7
Dynamic Type Fonts by setting the following css on the body and using
relatively sized fonts sizing for child containers, for example:
body {
font: -apple-system-body;
}
body > .app {
font-family: 'HelveticaNeue-Light', 'HelveticaNeue', Helvetica,
Arial, sans-serif;
font-size:0.75em;
font-weight: 200;
}
This commit is contained in:
+50
-2
@@ -4,8 +4,10 @@ package com.phonegap.plugin.mobileaccessibility;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
import android.view.accessibility.AccessibilityEvent;
|
||||
import android.view.accessibility.AccessibilityManager;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
|
||||
@TargetApi(Build.VERSION_CODES.DONUT)
|
||||
@@ -18,7 +20,6 @@ public class DonutMobileAccessibilityHelper extends
|
||||
public void initialize(MobileAccessibility mobileAccessibility) {
|
||||
mMobileAccessibility = mobileAccessibility;
|
||||
mWebView = mobileAccessibility.webView;
|
||||
mParent = mobileAccessibility.webView.getParentForAccessibility();
|
||||
mAccessibilityManager = (AccessibilityManager) mMobileAccessibility.cordova.getActivity().getSystemService(Context.ACCESSIBILITY_SERVICE);
|
||||
}
|
||||
|
||||
@@ -76,5 +77,52 @@ public class DonutMobileAccessibilityHelper extends
|
||||
|
||||
mAccessibilityManager.sendAccessibilityEvent(event);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public int getTextZoom() {
|
||||
int zoom = 100;
|
||||
WebSettings.TextSize wTextSize = mWebView.getSettings().getTextSize();
|
||||
switch (wTextSize) {
|
||||
case LARGEST:
|
||||
zoom = 200;
|
||||
break;
|
||||
case LARGER:
|
||||
zoom = 150;
|
||||
break;
|
||||
case NORMAL:
|
||||
zoom = 100;
|
||||
break;
|
||||
case SMALLER:
|
||||
zoom = 75;
|
||||
break;
|
||||
case SMALLEST:
|
||||
zoom = 50;
|
||||
break;
|
||||
default:
|
||||
zoom = 100;
|
||||
break;
|
||||
}
|
||||
return zoom;
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Override
|
||||
public void setTextZoom(int textZoom) {
|
||||
final int zoom = textZoom;
|
||||
WebSettings.TextSize wTextSize = WebSettings.TextSize.NORMAL;
|
||||
if (zoom > 115) {
|
||||
wTextSize = WebSettings.TextSize.LARGEST;
|
||||
} else if (zoom > 100) {
|
||||
wTextSize = WebSettings.TextSize.LARGER;
|
||||
} else if (zoom == 100) {
|
||||
wTextSize = WebSettings.TextSize.NORMAL;
|
||||
} else if (zoom > 50) {
|
||||
wTextSize = WebSettings.TextSize.SMALLER;
|
||||
} else {
|
||||
wTextSize = WebSettings.TextSize.SMALLEST;
|
||||
}
|
||||
//Log.i("MobileAccessibility", "fontScale = " + zoom + ", WebSettings.TextSize = " + wTextSize.toString());
|
||||
mWebView.getSettings().setTextSize(wTextSize);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user