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
|
* Sets the context of the Command. This can then be used to do things like
|
||||||
* get file paths associated with the Activity.
|
* 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) {
|
@Override
|
||||||
super.initialize(cordova, webView);
|
public void initialize() {
|
||||||
this.initTelephonyReceiver();
|
this.initTelephonyReceiver();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Executes the request and returns PluginResult.
|
* Executes the request and returns PluginResult.
|
||||||
*
|
*
|
||||||
|
@ -227,7 +227,7 @@ public class CordovaActivity extends Activity implements CordovaInterface {
|
|||||||
}
|
}
|
||||||
|
|
||||||
appView = makeWebView();
|
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.
|
// TODO: Have the views set this themselves.
|
||||||
if (preferences.getBoolean("DisallowOverscroll", false)) {
|
if (preferences.getBoolean("DisallowOverscroll", false)) {
|
||||||
@ -240,6 +240,7 @@ public class CordovaActivity extends Activity implements CordovaInterface {
|
|||||||
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
protected void loadConfig() {
|
protected void loadConfig() {
|
||||||
ConfigXmlParser parser = new ConfigXmlParser();
|
ConfigXmlParser parser = new ConfigXmlParser();
|
||||||
parser.parse(this);
|
parser.parse(this);
|
||||||
|
@ -32,20 +32,31 @@ import android.net.Uri;
|
|||||||
* Plugins must extend this class and override one of the execute methods.
|
* Plugins must extend this class and override one of the execute methods.
|
||||||
*/
|
*/
|
||||||
public class CordovaPlugin {
|
public class CordovaPlugin {
|
||||||
|
@Deprecated // This is never set.
|
||||||
public String id;
|
public String id;
|
||||||
public CordovaWebView webView; // WebView object
|
public CordovaWebView webView; // WebView object
|
||||||
public CordovaInterface cordova;
|
public CordovaInterface cordova;
|
||||||
|
protected CordovaPreferences preferences;
|
||||||
|
|
||||||
/**
|
void privateInitialize(CordovaInterface cordova, CordovaWebView webView, CordovaPreferences preferences) {
|
||||||
* @param cordova The context of the main Activity.
|
|
||||||
* @param webView The associated CordovaWebView.
|
|
||||||
*/
|
|
||||||
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
|
|
||||||
assert this.cordova == null;
|
assert this.cordova == null;
|
||||||
this.cordova = cordova;
|
this.cordova = cordova;
|
||||||
this.webView = webView;
|
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.
|
* Executes the request.
|
||||||
*
|
*
|
||||||
|
@ -92,6 +92,7 @@ public class CordovaWebView extends WebView {
|
|||||||
private Whitelist whitelist;
|
private Whitelist whitelist;
|
||||||
// The URL passed to loadUrl(), not necessarily the URL of the current page.
|
// The URL passed to loadUrl(), not necessarily the URL of the current page.
|
||||||
String loadedUrl;
|
String loadedUrl;
|
||||||
|
private CordovaPreferences preferences;
|
||||||
|
|
||||||
class ActivityResult {
|
class ActivityResult {
|
||||||
|
|
||||||
@ -135,7 +136,7 @@ public class CordovaWebView extends WebView {
|
|||||||
|
|
||||||
// Use two-phase init so that the control will work with XML layouts.
|
// Use two-phase init so that the control will work with XML layouts.
|
||||||
public void init(CordovaInterface cordova, CordovaWebViewClient webViewClient, CordovaChromeClient webChromeClient,
|
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) {
|
if (this.cordova != null) {
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
}
|
}
|
||||||
@ -143,6 +144,7 @@ public class CordovaWebView extends WebView {
|
|||||||
this.viewClient = webViewClient;
|
this.viewClient = webViewClient;
|
||||||
this.chromeClient = webChromeClient;
|
this.chromeClient = webChromeClient;
|
||||||
this.whitelist = whitelist;
|
this.whitelist = whitelist;
|
||||||
|
this.preferences = preferences;
|
||||||
super.setWebChromeClient(webChromeClient);
|
super.setWebChromeClient(webChromeClient);
|
||||||
super.setWebViewClient(webViewClient);
|
super.setWebViewClient(webViewClient);
|
||||||
|
|
||||||
@ -903,4 +905,8 @@ public class CordovaWebView extends WebView {
|
|||||||
public CordovaResourceApi getResourceApi() {
|
public CordovaResourceApi getResourceApi() {
|
||||||
return resourceApi;
|
return resourceApi;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CordovaPreferences getPreferences() {
|
||||||
|
return preferences;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -98,7 +98,7 @@ public class PluginEntry {
|
|||||||
Class<?> c = getClassByName(this.pluginClass);
|
Class<?> c = getClassByName(this.pluginClass);
|
||||||
if (isCordovaPlugin(c)) {
|
if (isCordovaPlugin(c)) {
|
||||||
this.plugin = (CordovaPlugin) c.newInstance();
|
this.plugin = (CordovaPlugin) c.newInstance();
|
||||||
this.plugin.initialize(ctx, webView);
|
this.plugin.privateInitialize(ctx, webView, webView.getPreferences());
|
||||||
return plugin;
|
return plugin;
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user