下面列出了怎么用org.apache.cordova.CordovaPreferences的API类实例代码及写法,或者点击链接到github查看源代码。
private static Context setGlobalPrefs(Context context, CordovaPreferences preferences) {
if (!hasSetStaticPref) {
hasSetStaticPref = true;
ApplicationInfo ai = null;
try {
ai = context.getPackageManager().getApplicationInfo(context.getApplicationContext().getPackageName(), PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException e) {
throw new RuntimeException(e);
}
boolean prefAnimatable = preferences == null ? false : preferences.getBoolean("CrosswalkAnimatable", false);
boolean manifestAnimatable = ai.metaData == null ? false : ai.metaData.getBoolean("CrosswalkAnimatable");
// Selects between a TextureView (obeys framework transforms applied to view) or a SurfaceView (better performance).
XWalkPreferences.setValue(XWalkPreferences.ANIMATABLE_XWALK_VIEW, prefAnimatable || manifestAnimatable);
if ((ai.flags & ApplicationInfo.FLAG_DEBUGGABLE) != 0) {
XWalkPreferences.setValue(XWalkPreferences.REMOTE_DEBUGGING, true);
}
XWalkPreferences.setValue(XWalkPreferences.JAVASCRIPT_CAN_OPEN_WINDOW, true);
XWalkPreferences.setValue(XWalkPreferences.ALLOW_UNIVERSAL_ACCESS_FROM_FILE, true);
}
return context;
}
@Test
public void checkBackgroundIntentCheck() {
StandardActivity activity = (StandardActivity) mActivityRule.getActivity();
final SystemWebView webView = (SystemWebView) activity.getWindow().getCurrentFocus();
CordovaWebView webInterface = webView.getCordovaWebView();
CordovaPreferences prefs = webInterface.getPreferences();
assertFalse(prefs.getInteger("backgroundcolor", Color.BLACK) == Color.GREEN);
}
/**
* Create the Bridge with a reference to the main {@link Activity} for the
* app, and a reference to the {@link WebView} our app will use.
* @param context
* @param webView
*/
public Bridge(Activity context, WebView webView, List<Class<? extends Plugin>> initialPlugins, CordovaInterfaceImpl cordovaInterface, PluginManager pluginManager, CordovaPreferences preferences) {
this.context = context;
this.webView = webView;
this.initialPlugins = initialPlugins;
this.cordovaInterface = cordovaInterface;
this.preferences = preferences;
// Start our plugin execution threads and handlers
handlerThread.start();
taskHandler = new Handler(handlerThread.getLooper());
Config.load(getActivity());
// Initialize web view and message handler for it
this.initWebView();
this.msgHandler = new MessageHandler(this, webView, pluginManager);
// Grab any intent info that our app was launched with
Intent intent = context.getIntent();
Uri intentData = intent.getData();
this.intentUri = intentData;
// Register our core plugins
this.registerAllPlugins();
this.loadWebView();
}
@Override
public void init(CordovaInterface cordova, List<PluginEntry> pluginEntries, CordovaPreferences preferences) {
this.cordova = cordova;
this.preferences = preferences;
this.pluginManager = new PluginManager(this, this.cordova, pluginEntries);
this.resourceApi = new CordovaResourceApi(this.context, this.pluginManager);
this.pluginManager.init();
}
public void init(CordovaInterface cordova, List<PluginEntry> pluginEntries, CordovaPreferences preferences, WebView webView) {
this.cordova = cordova;
this.webView = webView;
this.preferences = preferences;
this.pluginManager = new PluginManager(this, this.cordova, pluginEntries);
this.resourceApi = new CordovaResourceApi(this.context, this.pluginManager);
nativeToJsMessageQueue = new NativeToJsMessageQueue();
nativeToJsMessageQueue.addBridgeMode(new CapacitorEvalBridgeMode(webView, this.cordova));
nativeToJsMessageQueue.setBridgeMode(0);
this.cookieManager = new CapacitorCordovaCookieManager(webView);
this.pluginManager.init();
}
/** Used when created via reflection. */
public InjectWebViewEngine(Context context, CordovaPreferences preferences) {
this(new InjectWebView(context));
//super(context, preferences);
Log.w("inject", "InjectWebViewEngine");
}
/** Used when created via reflection. */
public CordovaGeckoViewEngine(Context context, CordovaPreferences preferences) {
mCtx = context;
webView = new CordovaGeckoView(this);
//testView = new SystemWebView(context);
prefs = preferences;
}
private static int getLogLevel(CordovaPreferences preferences) {
String logLevel = preferences.getString("LogLevel", "ERROR");
if ("VERBOSE".equals(logLevel)) {
return android.util.Log.VERBOSE;
} else if ("DEBUG".equals(logLevel)) {
return android.util.Log.DEBUG;
} else if ("INFO".equals(logLevel)) {
return android.util.Log.INFO;
} else if ("WARN".equals(logLevel)) {
return android.util.Log.WARN;
} else {
return android.util.Log.ERROR;
}
}
/** Used when created via reflection. */
public SystemWebViewEngine(Context context, CordovaPreferences preferences) {
this(new SystemWebView(context), preferences);
}
public SystemWebViewEngine(SystemWebView webView, CordovaPreferences preferences) {
this.preferences = preferences;
this.webView = webView;
cookieManager = new SystemCookieManager(webView);
}
/** Used when created via reflection. */
public SystemWebViewEngine(Context context, CordovaPreferences preferences) {
this(new SystemWebView(context), preferences);
}
public SystemWebViewEngine(SystemWebView webView, CordovaPreferences preferences) {
this.preferences = preferences;
this.webView = webView;
cookieManager = new SystemCookieManager(webView);
}
/** Used when created via reflection. */
public SystemWebViewEngine(Context context, CordovaPreferences preferences) {
this(new SystemWebView(context), preferences);
}
public SystemWebViewEngine(SystemWebView webView, CordovaPreferences preferences) {
this.preferences = preferences;
this.webView = webView;
cookieManager = new SystemCookieManager(webView);
}
/** Used when created via reflection. */
public X5WebViewEngine(Context context, CordovaPreferences preferences) {
this(new X5WebView(context), preferences);
}
public X5WebViewEngine(X5WebView webView, CordovaPreferences preferences) {
this.preferences = preferences;
this.webView = webView;
cookieManager = new X5CookieManager(webView);
}
/** Used when created via reflection. */
public X5WebViewEngine(Context context, CordovaPreferences preferences) {
this(new X5WebView(context), preferences);
}
public X5WebViewEngine(X5WebView webView, CordovaPreferences preferences) {
this.preferences = preferences;
this.webView = webView;
cookieManager = new X5CookieManager(webView);
}
/** Used when created via reflection. */
public SystemWebViewEngine(Context context, CordovaPreferences preferences) {
this(new SystemWebView(context), preferences);
}
public SystemWebViewEngine(SystemWebView webView, CordovaPreferences preferences) {
this.preferences = preferences;
this.webView = webView;
cookieManager = new SystemCookieManager(webView);
}
/** Used when created via reflection. */
public SystemWebViewEngine(Context context, CordovaPreferences preferences) {
this(new SystemWebView(context), preferences);
}
public SystemWebViewEngine(SystemWebView webView, CordovaPreferences preferences) {
this.preferences = preferences;
this.webView = webView;
cookieManager = new SystemCookieManager(webView);
}
/**
* Used when created via reflection.
*/
public X5WebViewEngine(Context context, CordovaPreferences preferences) {
this(new X5WebView(context), preferences);
}
public X5WebViewEngine(X5WebView webView, CordovaPreferences preferences) {
this.preferences = preferences;
this.webView = webView;
cookieManager = new X5CookieManager(webView);
}
@Override
public CordovaPreferences getPreferences() {
return this.preferences;
}
/** Used when created via reflection. */
public SystemWebViewEngine(Context context, CordovaPreferences preferences) {
this(new SystemWebView(context), preferences);
}
public SystemWebViewEngine(SystemWebView webView, CordovaPreferences preferences) {
this.preferences = preferences;
this.webView = webView;
cookieManager = new SystemCookieManager(webView);
}
/** Used when created via reflection. */
public X5WebViewEngine(Context context, CordovaPreferences preferences) {
this(new X5WebView(context), preferences);
}
public X5WebViewEngine(X5WebView webView, CordovaPreferences preferences) {
this.preferences = preferences;
this.webView = webView;
cookieManager = new X5CookieManager(webView);
}
/** Used when created via reflection. */
public SystemWebViewEngine(Context context, CordovaPreferences preferences) {
this(new SystemWebView(context), preferences);
}