mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-26 03:53:09 +08:00
Provide CordovaPlugin with CordovaPreferences. Add new Plugin.initialize()
This adds CordovaPlugin.initialize() (no args) and deprecates CordovaPlugin.initialize(app, webView). This will allow us to refactor more easily by using the package-private privateInitialize() to set fields.
This commit is contained in:
parent
d31ee20ba5
commit
04ccb06e3f
@ -47,16 +47,12 @@ public class App extends CordovaPlugin {
|
||||
/**
|
||||
* Sets the context of the Command. This can then be used to do things like
|
||||
* get file paths associated with the Activity.
|
||||
*
|
||||
* @param cordova The context of the main Activity.
|
||||
* @param webView The CordovaWebView Cordova is running in.
|
||||
*/
|
||||
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
||||
super.initialize(cordova, webView);
|
||||
@Override
|
||||
public void initialize() {
|
||||
this.initTelephonyReceiver();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Executes the request and returns PluginResult.
|
||||
*
|
||||
|
@ -227,7 +227,7 @@ public class CordovaActivity extends Activity implements CordovaInterface {
|
||||
}
|
||||
|
||||
appView = makeWebView();
|
||||
appView.init(this, makeWebViewClient(appView), makeChromeClient(appView), pluginEntries, whitelist);
|
||||
appView.init(this, makeWebViewClient(appView), makeChromeClient(appView), pluginEntries, whitelist, preferences);
|
||||
|
||||
// TODO: Have the views set this themselves.
|
||||
if (preferences.getBoolean("DisallowOverscroll", false)) {
|
||||
@ -240,6 +240,7 @@ public class CordovaActivity extends Activity implements CordovaInterface {
|
||||
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
protected void loadConfig() {
|
||||
ConfigXmlParser parser = new ConfigXmlParser();
|
||||
parser.parse(this);
|
||||
|
@ -32,20 +32,31 @@ import android.net.Uri;
|
||||
* Plugins must extend this class and override one of the execute methods.
|
||||
*/
|
||||
public class CordovaPlugin {
|
||||
@Deprecated // This is never set.
|
||||
public String id;
|
||||
public CordovaWebView webView; // WebView object
|
||||
public CordovaInterface cordova;
|
||||
protected CordovaPreferences preferences;
|
||||
|
||||
/**
|
||||
* @param cordova The context of the main Activity.
|
||||
* @param webView The associated CordovaWebView.
|
||||
*/
|
||||
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
||||
void privateInitialize(CordovaInterface cordova, CordovaWebView webView, CordovaPreferences preferences) {
|
||||
assert this.cordova == null;
|
||||
this.cordova = cordova;
|
||||
this.webView = webView;
|
||||
this.preferences = preferences;
|
||||
initialize(cordova, webView);
|
||||
initialize();
|
||||
}
|
||||
|
||||
@Deprecated // Override initialize() instead.
|
||||
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
||||
}
|
||||
|
||||
/**
|
||||
* This is where you can do start-up logic with protected fields set.
|
||||
*/
|
||||
protected void initialize() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes the request.
|
||||
*
|
||||
|
@ -92,6 +92,7 @@ public class CordovaWebView extends WebView {
|
||||
private Whitelist whitelist;
|
||||
// The URL passed to loadUrl(), not necessarily the URL of the current page.
|
||||
String loadedUrl;
|
||||
private CordovaPreferences preferences;
|
||||
|
||||
class ActivityResult {
|
||||
|
||||
@ -135,7 +136,7 @@ public class CordovaWebView extends WebView {
|
||||
|
||||
// Use two-phase init so that the control will work with XML layouts.
|
||||
public void init(CordovaInterface cordova, CordovaWebViewClient webViewClient, CordovaChromeClient webChromeClient,
|
||||
List<PluginEntry> pluginEntries, Whitelist whitelist) {
|
||||
List<PluginEntry> pluginEntries, Whitelist whitelist, CordovaPreferences preferences) {
|
||||
if (this.cordova != null) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
@ -143,6 +144,7 @@ public class CordovaWebView extends WebView {
|
||||
this.viewClient = webViewClient;
|
||||
this.chromeClient = webChromeClient;
|
||||
this.whitelist = whitelist;
|
||||
this.preferences = preferences;
|
||||
super.setWebChromeClient(webChromeClient);
|
||||
super.setWebViewClient(webViewClient);
|
||||
|
||||
@ -903,4 +905,8 @@ public class CordovaWebView extends WebView {
|
||||
public CordovaResourceApi getResourceApi() {
|
||||
return resourceApi;
|
||||
}
|
||||
|
||||
public CordovaPreferences getPreferences() {
|
||||
return preferences;
|
||||
}
|
||||
}
|
||||
|
@ -98,7 +98,7 @@ public class PluginEntry {
|
||||
Class<?> c = getClassByName(this.pluginClass);
|
||||
if (isCordovaPlugin(c)) {
|
||||
this.plugin = (CordovaPlugin) c.newInstance();
|
||||
this.plugin.initialize(ctx, webView);
|
||||
this.plugin.privateInitialize(ctx, webView, webView.getPreferences());
|
||||
return plugin;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
Loading…
Reference in New Issue
Block a user