Skip to content

Commit

Permalink
add setTextZoom function
Browse files Browse the repository at this point in the history
  • Loading branch information
tuanway committed Aug 17, 2023
1 parent db0e835 commit ebff8a7
Show file tree
Hide file tree
Showing 7 changed files with 184 additions and 3 deletions.
14 changes: 14 additions & 0 deletions phonegap/medias.obj
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,13 @@ uuid:"6D2F63B3-12F7-4EA2-9FBC-F83FA068BD89"
},
{
encapsulation:0,
mimeType:"text/javascript",
name:"lib/android/plugins/phonegap-plugin-mobile-accessibility/www/mobile-accessibility.js",
typeid:37,
uuid:"F8A08DA3-143D-4F85-9EF3-92D6678229D2"
},
{
encapsulation:0,
mimeType:"application/javascript",
name:"lib/android/plugins/uk.co.workingedge.phonegap.plugin.launchnavigator/www/android/launchnavigator.js",
typeid:37,
Expand Down Expand Up @@ -918,6 +925,13 @@ uuid:"668BE720-2ACB-4440-AA8B-FCFBF666AA7F"
},
{
encapsulation:0,
mimeType:"text/javascript",
name:"lib/ios/plugins/phonegap-plugin-mobile-accessibility/www/mobile-accessibility.js",
typeid:37,
uuid:"1EE0B329-BD48-4D30-9DC9-D7B2A01AAEA8"
},
{
encapsulation:0,
mimeType:"application/javascript",
name:"lib/ios/plugins/uk.co.workingedge.phonegap.plugin.launchnavigator/www/common.js",
typeid:37,
Expand Down
12 changes: 11 additions & 1 deletion phonegap/medias/lib/android/cordova_plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,15 @@ module.exports = [
"cordova.plugins.notification.badge"
]
},
{
"id": "phonegap-plugin-mobile-accessibility.mobile-accessibility",
"file": "plugins/phonegap-plugin-mobile-accessibility/www/mobile-accessibility.js",
"pluginId": "phonegap-plugin-mobile-accessibility",
"clobbers": [
"window.MobileAccessibility"
]
}

];
module.exports.metadata =
// TOP OF METADATA
Expand Down Expand Up @@ -469,7 +478,8 @@ module.exports.metadata =
"cordova-plugin-screen-orientation": "3.0.2",
"cordova-plugin-actionsheet": "2.3.3",
"cordova-plugin-dialogs": "2.0.2",
"uk.co.workingedge.phonegap.plugin.launchnavigator": "5.0.5"
"uk.co.workingedge.phonegap.plugin.launchnavigator": "5.0.5",
"phonegap-plugin-mobile-accessibility": "1.0.9"
};
// BOTTOM OF METADATA
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
cordova.define("phonegap-plugin-mobile-accessibility.mobile-accessibility", function(require, exports, module) {
var exec = require('cordova/exec');

var MobileAccessibility = function() {
this._usePreferredTextZoom = false;
};

/**
* Asynchronous call to native MobileAccessibility to return the current text zoom percent value for the WebView.
* @param {function} callback A callback method to receive the asynchronous result from the native MobileAccessibility.
*/
MobileAccessibility.prototype.getTextZoom = function(callback) {
exec(callback, null, "MobileAccessibility", "getTextZoom", []);
};

MobileAccessibility.prototype.setFontScaleToOne = function(callback) {
exec(callback, null, "MobileAccessibility", "setFontScaleToOne", []);
};

/**
* Asynchronous call to native MobileAccessibility to set the current text zoom percent value for the WebView.
* @param {Number} textZoom A percentage value by which text in the WebView should be scaled.
* @param {function} callback A callback method to receive the asynchronous result from the native MobileAccessibility.
*/
MobileAccessibility.prototype.setTextZoom = function(textZoom, callback) {
exec(callback, null, "MobileAccessibility", "setTextZoom", [textZoom]);
};

/**
* Asynchronous call to native MobileAccessibility to retrieve the user's preferred text zoom from system settings and apply it to the application WebView.
* @param {function} callback A callback method to receive the asynchronous result from the native MobileAccessibility.
*/
MobileAccessibility.prototype.updateTextZoom = function(callback) {
exec(callback, null, "MobileAccessibility", "updateTextZoom", []);
};

MobileAccessibility.prototype.usePreferredTextZoom = function(bool) {
var currentValue = window.localStorage.getItem("MobileAccessibility.usePreferredTextZoom") === "true";

if (arguments.length === 0) {
return currentValue;
}

if (currentValue !== bool) {
window.localStorage.setItem("MobileAccessibility.usePreferredTextZoom", bool);
}

var callback = function(){
// Wrapping updateTextZoom call in a function to stop
// the event parameter propagation. This fixes an error
// on resume where cordova tried to call apply() on the
// event, expecting a function.
mobileAccessibility.updateTextZoom();
};

document.removeEventListener("resume", callback);

if (bool) {
// console.log("We should update the text zoom at this point: " + bool)
document.addEventListener("resume", callback, false);
mobileAccessibility.updateTextZoom();
} else {
mobileAccessibility.setTextZoom(100);
mobileAccessibility.setFontScaleToOne();
}

return Boolean(bool);
};

var mobileAccessibility = new MobileAccessibility();

module.exports = mobileAccessibility;

});
11 changes: 10 additions & 1 deletion phonegap/medias/lib/ios/cordova_plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -463,6 +463,14 @@ cordova.define('cordova/plugin_list', function(require, exports, module) {
"cordova.plugins.notification.badge"
]
},
{
"id": "phonegap-plugin-mobile-accessibility.mobile-accessibility",
"file": "plugins/phonegap-plugin-mobile-accessibility/www/mobile-accessibility.js",
"pluginId": "phonegap-plugin-mobile-accessibility",
"clobbers": [
"window.MobileAccessibility"
]
}
];
module.exports.metadata = {
"cordova-plugin-statusbar": "2.4.3",
Expand Down Expand Up @@ -492,6 +500,7 @@ cordova.define('cordova/plugin_list', function(require, exports, module) {
"uk.co.workingedge.phonegap.plugin.launchnavigator": "5.0.4",
"cordova-plugin-cleartext": "1.0.0",
"cordova-plugin-printer": "0.7.3",
"cordova-plugin-print-pdf": "4.0.2"
"cordova-plugin-print-pdf": "4.0.2",
"phonegap-plugin-mobile-accessibility": "1.0.9"
};
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
cordova.define("phonegap-plugin-mobile-accessibility.mobile-accessibility", function(require, exports, module) {
var exec = require('cordova/exec');

var MobileAccessibility = function() {
this._usePreferredTextZoom = false;
};

/**
* Asynchronous call to native MobileAccessibility to return the current text zoom percent value for the WebView.
* @param {function} callback A callback method to receive the asynchronous result from the native MobileAccessibility.
*/
MobileAccessibility.prototype.getTextZoom = function(callback) {
exec(callback, null, "MobileAccessibility", "getTextZoom", []);
};

MobileAccessibility.prototype.setFontScaleToOne = function(callback) {
exec(callback, null, "MobileAccessibility", "setFontScaleToOne", []);
};

/**
* Asynchronous call to native MobileAccessibility to set the current text zoom percent value for the WebView.
* @param {Number} textZoom A percentage value by which text in the WebView should be scaled.
* @param {function} callback A callback method to receive the asynchronous result from the native MobileAccessibility.
*/
MobileAccessibility.prototype.setTextZoom = function(textZoom, callback) {
exec(callback, null, "MobileAccessibility", "setTextZoom", [textZoom]);
};

/**
* Asynchronous call to native MobileAccessibility to retrieve the user's preferred text zoom from system settings and apply it to the application WebView.
* @param {function} callback A callback method to receive the asynchronous result from the native MobileAccessibility.
*/
MobileAccessibility.prototype.updateTextZoom = function(callback) {
exec(callback, null, "MobileAccessibility", "updateTextZoom", []);
};

MobileAccessibility.prototype.usePreferredTextZoom = function(bool) {
var currentValue = window.localStorage.getItem("MobileAccessibility.usePreferredTextZoom") === "true";

if (arguments.length === 0) {
return currentValue;
}

if (currentValue !== bool) {
window.localStorage.setItem("MobileAccessibility.usePreferredTextZoom", bool);
}

var callback = function(){
// Wrapping updateTextZoom call in a function to stop
// the event parameter propagation. This fixes an error
// on resume where cordova tried to call apply() on the
// event, expecting a function.
mobileAccessibility.updateTextZoom();
};

document.removeEventListener("resume", callback);

if (bool) {
// console.log("We should update the text zoom at this point: " + bool)
document.addEventListener("resume", callback, false);
mobileAccessibility.updateTextZoom();
} else {
mobileAccessibility.setTextZoom(100);
mobileAccessibility.setFontScaleToOne();
}

return Boolean(bool);
};

var mobileAccessibility = new MobileAccessibility();

module.exports = mobileAccessibility;

});
Binary file modified phonegap/ng_web_packages/svyphonegap.zip
Binary file not shown.
2 changes: 1 addition & 1 deletion phonegap/solution_settings.obj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
onOpenMethodID:"B620101F-7C53-471B-AE3B-CBFD16D05767",
typeid:43,
uuid:"DA9286A0-7C85-4E70-B306-22ED1E9E9B93",
version:"1.1.8"
version:"1.2.0"

0 comments on commit ebff8a7

Please sign in to comment.