类org.apache.cordova.CordovaInterface源码实例Demo

下面列出了怎么用org.apache.cordova.CordovaInterface的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: cordova-amazon-fireos   文件: FileHelper.java
/**
 * Returns the real path of the given URI string.
 * If the given URI string represents a content:// URI, the real path is retrieved from the media store.
 *
 * @param uriString the URI string of the audio/image/video
 * @param cordova the current application context
 * @return the full path to the file
 */
@SuppressWarnings("deprecation")
public static String getRealPath(String uriString, CordovaInterface cordova) {
    String realPath = null;

    if (uriString.startsWith("content://")) {
        String[] proj = { _DATA };
        Cursor cursor = cordova.getActivity().managedQuery(Uri.parse(uriString), proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(_DATA);
        cursor.moveToFirst();
        realPath = cursor.getString(column_index);
        if (realPath == null) {
            LOG.e(LOG_TAG, "Could get real path for URI string %s", uriString);
        }
    } else if (uriString.startsWith("file://")) {
        realPath = uriString.substring(7);
        if (realPath.startsWith("/android_asset/")) {
            LOG.e(LOG_TAG, "Cannot get real path for URI string %s because it is a file:///android_asset/ URI.", uriString);
            realPath = null;
        }
    } else {
        realPath = uriString;
    }

    return realPath;
}
 
源代码2 项目: reader   文件: Notification.java
/**
 * Show the spinner.
 *
 * @param title     Title of the dialog
 * @param message   The message of the dialog
 */
public synchronized void activityStart(final String title, final String message) {
    if (this.spinnerDialog != null) {
        this.spinnerDialog.dismiss();
        this.spinnerDialog = null;
    }
    final Notification notification = this;
    final CordovaInterface cordova = this.cordova;
    Runnable runnable = new Runnable() {
        public void run() {
            notification.spinnerDialog = createProgressDialog(cordova); // new ProgressDialog(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
            notification.spinnerDialog.setTitle(title);
            notification.spinnerDialog.setMessage(message);
            notification.spinnerDialog.setCancelable(true);
            notification.spinnerDialog.setIndeterminate(true);
            notification.spinnerDialog.setOnCancelListener(
                    new DialogInterface.OnCancelListener() {
                        public void onCancel(DialogInterface dialog) {
                            notification.spinnerDialog = null;
                        }
                    });
            notification.spinnerDialog.show();
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
}
 
/**
 * 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);
    this.sockMan = (ConnectivityManager) cordova.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
    this.connectionCallbackContext = null;

    // We need to listen to connectivity events to update navigator.connection
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                // (The null check is for the ARM Emulator, please use Intel Emulator for better results)
                if(NetworkManager.this.webView != null)
                    updateConnectionInfo(sockMan.getActiveNetworkInfo());
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }

}
 
源代码4 项目: cordova-androidwear   文件: AndroidWearPlugin.java
@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
	super.initialize(cordova, webView);

	Log.d(TAG, "initialize");

	Activity context = cordova.getActivity();

	serviceIntent = new Intent(context, WearProviderService.class);

	Log.d(TAG, "Attempting to start service");
	context.startService(serviceIntent);

	Log.d(TAG, "Attempting to bind to service");
	context.bindService(serviceIntent, serviceConnection,
			Context.BIND_AUTO_CREATE);
}
 
/**
 * 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);
    this.sockMan = (ConnectivityManager) cordova.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
    this.connectionCallbackContext = null;

    // We need to listen to connectivity events to update navigator.connection
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                // (The null check is for the ARM Emulator, please use Intel Emulator for better results)
                if(NetworkManager.this.webView != null)
                    updateConnectionInfo(sockMan.getActiveNetworkInfo());
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }

}
 
/**
 * Requests "dangerous" permissions for the application at runtime. This is a helper method
 * alternative to cordovaInterface.requestPermissions() that does not require the project to be
 * built with cordova-android 5.0.0+
 *
 * @param plugin        The plugin the permissions are being requested for
 * @param requestCode   A requestCode to be passed to the plugin's onRequestPermissionResult()
 *                      along with the result of the permissions request
 * @param permissions   The permissions to be requested
 */
public static void requestPermissions(CordovaPlugin plugin, int requestCode, String[] permissions) {
    try {
        Method requestPermission = CordovaInterface.class.getDeclaredMethod(
                "requestPermissions", CordovaPlugin.class, int.class, String[].class);

        // If there is no exception, then this is cordova-android 5.0.0+
        requestPermission.invoke(plugin.cordova, plugin, requestCode, permissions);
    } catch (NoSuchMethodException noSuchMethodException) {
        // cordova-android version is less than 5.0.0, so permission is implicitly granted
        LOG.d(LOG_TAG, "No need to request permissions " + Arrays.toString(permissions));

        // Notify the plugin that all were granted by using more reflection
        deliverPermissionResult(plugin, requestCode, permissions);
    } catch (IllegalAccessException illegalAccessException) {
        // Should never be caught; this is a public method
        LOG.e(LOG_TAG, "IllegalAccessException when requesting permissions " + Arrays.toString(permissions), illegalAccessException);
    } catch(InvocationTargetException invocationTargetException) {
        // This method does not throw any exceptions, so this should never be caught
        LOG.e(LOG_TAG, "invocationTargetException when requesting permissions " + Arrays.toString(permissions), invocationTargetException);
    }
}
 
/**
 * Constructor.
 *
 * @param context
 * @param attrs
 * @param defStyle
 * @param privateBrowsing
 */
@TargetApi(11)
public CordovaWebView(Context context, AttributeSet attrs, int defStyle, boolean privateBrowsing) {
    super(context, attrs, defStyle, privateBrowsing);
    if (CordovaInterface.class.isInstance(context))
    {
        this.cordova = (CordovaInterface) context;
    }
    else
    {
        Log.d(TAG, "Your activity must implement CordovaInterface to work");
    }
    this.setWebChromeClient(new CordovaChromeClient(this.cordova));
    this.initWebViewClient(this.cordova);
    this.loadConfiguration();
    this.setup();
}
 
源代码8 项目: bluemix-parking-meter   文件: FileHelper.java
/**
 * Returns the real path of the given URI string.
 * If the given URI string represents a content:// URI, the real path is retrieved from the media store.
 *
 * @param uriString the URI string of the audio/image/video
 * @param cordova the current application context
 * @return the full path to the file
 */
@SuppressWarnings("deprecation")
public static String getRealPath(String uriString, CordovaInterface cordova) {
    String realPath = null;

    if (uriString.startsWith("content://")) {
        String[] proj = { _DATA };
        Cursor cursor = cordova.getActivity().managedQuery(Uri.parse(uriString), proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(_DATA);
        cursor.moveToFirst();
        realPath = cursor.getString(column_index);
        if (realPath == null) {
            LOG.e(LOG_TAG, "Could get real path for URI string %s", uriString);
        }
    } else if (uriString.startsWith("file://")) {
        realPath = uriString.substring(7);
        if (realPath.startsWith("/android_asset/")) {
            LOG.e(LOG_TAG, "Cannot get real path for URI string %s because it is a file:///android_asset/ URI.", uriString);
            realPath = null;
        }
    } else {
        realPath = uriString;
    }

    return realPath;
}
 
源代码9 项目: L.TileLayer.Cordova   文件: FileHelper.java
/**
 * Returns the real path of the given URI string.
 * If the given URI string represents a content:// URI, the real path is retrieved from the media store.
 *
 * @param uriString the URI string of the audio/image/video
 * @param cordova the current application context
 * @return the full path to the file
 */
@SuppressWarnings("deprecation")
public static String getRealPath(String uriString, CordovaInterface cordova) {
    String realPath = null;

    if (uriString.startsWith("content://")) {
        String[] proj = { _DATA };
        Cursor cursor = cordova.getActivity().managedQuery(Uri.parse(uriString), proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(_DATA);
        cursor.moveToFirst();
        realPath = cursor.getString(column_index);
        if (realPath == null) {
            LOG.e(LOG_TAG, "Could get real path for URI string %s", uriString);
        }
    } else if (uriString.startsWith("file://")) {
        realPath = uriString.substring(7);
        if (realPath.startsWith("/android_asset/")) {
            LOG.e(LOG_TAG, "Cannot get real path for URI string %s because it is a file:///android_asset/ URI.", uriString);
            realPath = null;
        }
    } else {
        realPath = uriString;
    }

    return realPath;
}
 
源代码10 项目: cordova-plugin-app-launcher   文件: Launcher.java
private void launchAction(final String actionName, final Bundle extras) {
	final CordovaInterface mycordova = cordova;
	final CordovaPlugin plugin = this;
	cordova.getThreadPool().execute(new LauncherRunnable(this.callback) {
		public void run() {
			Intent intent = new Intent(actionName);
			try {
				intent.putExtras(extras);
				mycordova.startActivityForResult(plugin, intent, LAUNCH_REQUEST);
				((Launcher) plugin).callbackLaunched();
			} catch (ActivityNotFoundException e) {
				Log.e(TAG, "Error: Activity for " + actionName + " was not found.");
				e.printStackTrace();
				callbackContext.error("Activity not found for action name.");
			}
		}
	});
}
 
源代码11 项目: reader   文件: FileHelper.java
/**
 * Returns the real path of the given URI string.
 * If the given URI string represents a content:// URI, the real path is retrieved from the media store.
 *
 * @param uriString the URI string of the audio/image/video
 * @param cordova the current application context
 * @return the full path to the file
 */
@SuppressWarnings("deprecation")
public static String getRealPath(String uriString, CordovaInterface cordova) {
    String realPath = null;

    if (uriString.startsWith("content://")) {
        String[] proj = { _DATA };
        Cursor cursor = cordova.getActivity().managedQuery(Uri.parse(uriString), proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(_DATA);
        cursor.moveToFirst();
        realPath = cursor.getString(column_index);
        if (realPath == null) {
            LOG.e(LOG_TAG, "Could get real path for URI string %s", uriString);
        }
    } else if (uriString.startsWith("file://")) {
        realPath = uriString.substring(7);
        if (realPath.startsWith("/android_asset/")) {
            LOG.e(LOG_TAG, "Cannot get real path for URI string %s because it is a file:///android_asset/ URI.", uriString);
            realPath = null;
        }
    } else {
        realPath = uriString;
    }

    return realPath;
}
 
源代码12 项目: AvI   文件: StatusBar.java
/**
 * 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.
 */
@Override
public void initialize(final CordovaInterface cordova, CordovaWebView webView) {
    Log.v(TAG, "StatusBar: initialization");
    super.initialize(cordova, webView);

    this.cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            // Clear flag FLAG_FORCE_NOT_FULLSCREEN which is set initially
            // by the Cordova.
            Window window = cordova.getActivity().getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

            // Read 'StatusBarBackgroundColor' from config.xml, default is #000000.
            setStatusBarBackgroundColor(preferences.getString("StatusBarBackgroundColor", "#000000"));
        }
    });
}
 
源代码13 项目: app-icon   文件: StatusBar.java
/**
 * 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.
 */
@Override
public void initialize(final CordovaInterface cordova, CordovaWebView webView) {
    LOG.v(TAG, "StatusBar: initialization");
    super.initialize(cordova, webView);

    this.cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            // Clear flag FLAG_FORCE_NOT_FULLSCREEN which is set initially
            // by the Cordova.
            Window window = cordova.getActivity().getWindow();
            window.clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

            // Read 'StatusBarBackgroundColor' from config.xml, default is #000000.
            setStatusBarBackgroundColor(preferences.getString("StatusBarBackgroundColor", "#000000"));
        }
    });
}
 
源代码14 项目: L.TileLayer.Cordova   文件: FileHelper.java
/**
 * Returns the real path of the given URI string.
 * If the given URI string represents a content:// URI, the real path is retrieved from the media store.
 *
 * @param uriString the URI string of the audio/image/video
 * @param cordova the current application context
 * @return the full path to the file
 */
@SuppressWarnings("deprecation")
public static String getRealPath(String uriString, CordovaInterface cordova) {
    String realPath = null;

    if (uriString.startsWith("content://")) {
        String[] proj = { _DATA };
        Cursor cursor = cordova.getActivity().managedQuery(Uri.parse(uriString), proj, null, null, null);
        int column_index = cursor.getColumnIndexOrThrow(_DATA);
        cursor.moveToFirst();
        realPath = cursor.getString(column_index);
        if (realPath == null) {
            LOG.e(LOG_TAG, "Could get real path for URI string %s", uriString);
        }
    } else if (uriString.startsWith("file://")) {
        realPath = uriString.substring(7);
        if (realPath.startsWith("/android_asset/")) {
            LOG.e(LOG_TAG, "Cannot get real path for URI string %s because it is a file:///android_asset/ URI.", uriString);
            realPath = null;
        }
    } else {
        realPath = uriString;
    }

    return realPath;
}
 
public GPSController(
        CordovaInterface cordova,
        CallbackContext callbackContext,
        long minDistance,
        long minTime,
        boolean returnCache,
        boolean returnSatelliteData,
        boolean buffer,
        int bufferSize
){
    _cordova = cordova;
    _callbackContext = callbackContext;
    _minDistance = minDistance;
    _minTime = minTime;
    _returnCache = returnCache;
    _returnSatelliteData = returnSatelliteData;
    _buffer = buffer;
    _bufferSize = bufferSize;
}
 
public PluginResult isReady(final CallbackContext callbackContext) {
    CordovaInterface cordova = plugin.cordova;

    cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (interstitialAd != null && interstitialAd.isLoaded()) {
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, true));
            } else {
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, false));
            }
        }
    });

    return null;
}
 
源代码17 项目: phonegapbootcampsite   文件: Notification.java
/**
 * Show the spinner.
 *
 * @param title     Title of the dialog
 * @param message   The message of the dialog
 */
public synchronized void activityStart(final String title, final String message) {
    if (this.spinnerDialog != null) {
        this.spinnerDialog.dismiss();
        this.spinnerDialog = null;
    }
    final CordovaInterface cordova = this.cordova;
    Runnable runnable = new Runnable() {
        public void run() {
            Notification.this.spinnerDialog = ProgressDialog.show(cordova.getActivity(), title, message, true, true,
                    new DialogInterface.OnCancelListener() {
                        public void onCancel(DialogInterface dialog) {
                            Notification.this.spinnerDialog = null;
                        }
                    });
        }
    };
    this.cordova.getActivity().runOnUiThread(runnable);
}
 
源代码18 项目: cordova-plugin-admob-free   文件: BannerExecutor.java
public PluginResult removeAd(CallbackContext callbackContext) {
    CordovaInterface cordova = plugin.cordova;

    Log.w(TAG, "executeDestroyBannerView");

    final CallbackContext delayCallback = callbackContext;
    cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (adView != null) {
                ViewGroup parentView = (ViewGroup) adView.getParent();
                if (parentView != null) {
                    parentView.removeView(adView);
                }
                adView.destroy();
                adView = null;
            }
            bannerVisible = false;
            delayCallback.success();
        }
    });

    return null;
}
 
public PluginResult isReady(final CallbackContext callbackContext) {
    CordovaInterface cordova = plugin.cordova;

    cordova.getActivity().runOnUiThread(new Runnable() {
        @Override
        public void run() {
            if (rewardedVideoAd != null && rewardedVideoAd.isLoaded()) {
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, true));
            } else {
                callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, false));
            }
        }
    });

    return null;
}
 
源代码20 项目: showCaseCordova   文件: NetworkManager.java
/**
 * 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);
    this.sockMan = (ConnectivityManager) cordova.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
    this.connectionCallbackContext = null;

    // We need to listen to connectivity events to update navigator.connection
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                // (The null check is for the ARM Emulator, please use Intel Emulator for better results)
                if(NetworkManager.this.webView != null)
                    updateConnectionInfo(sockMan.getActiveNetworkInfo());
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }

}
 
源代码21 项目: reader   文件: NetworkManager.java
/**
 * 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);
    this.sockMan = (ConnectivityManager) cordova.getActivity().getSystemService(Context.CONNECTIVITY_SERVICE);
    this.connectionCallbackContext = null;

    // We need to listen to connectivity events to update navigator.connection
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    if (this.receiver == null) {
        this.receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                // (The null check is for the ARM Emulator, please use Intel Emulator for better results)
                if(NetworkManager.this.webView != null)
                    updateConnectionInfo(sockMan.getActiveNetworkInfo());
            }
        };
        webView.getContext().registerReceiver(this.receiver, intentFilter);
    }

}
 
private boolean play(final Class activityClass, final String url, final JSONObject options) {
	final CordovaInterface cordovaObj = cordova;
	final CordovaPlugin plugin = this;

	cordova.getActivity().runOnUiThread(new Runnable() {
		public void run() {
			final Intent streamIntent = new Intent(cordovaObj.getActivity().getApplicationContext(), activityClass);
			Bundle extras = new Bundle();
			extras.putString("mediaUrl", url);

			if (options != null) {
				Iterator<String> optKeys = options.keys();
				while (optKeys.hasNext()) {
					try {
						final String optKey = (String)optKeys.next();
						if (options.get(optKey).getClass().equals(String.class)) {
							extras.putString(optKey, (String)options.get(optKey));
							Log.v(TAG, "Added option: " + optKey + " -> " + String.valueOf(options.get(optKey)));
						} else if (options.get(optKey).getClass().equals(Boolean.class)) {
							extras.putBoolean(optKey, (Boolean)options.get(optKey));
							Log.v(TAG, "Added option: " + optKey + " -> " + String.valueOf(options.get(optKey)));
						}

					} catch (JSONException e) {
						Log.e(TAG, "JSONException while trying to read options. Skipping option.");
					}
				}
				streamIntent.putExtras(extras);
			}

			cordovaObj.startActivityForResult(plugin, streamIntent, ACTIVITY_CODE_PLAY_MEDIA);
		}
	});
	return true;
}
 
源代码23 项目: pychat   文件: SystemWebView.java
void init(SystemWebViewEngine parentEngine, CordovaInterface cordova) {
    this.cordova = cordova;
    this.parentEngine = parentEngine;
    if (this.viewClient == null) {
        setWebViewClient(new SystemWebViewClient(parentEngine));
    }

    if (this.chromeClient == null) {
        setWebChromeClient(new SystemWebChromeClient(parentEngine));
    }
}
 
源代码24 项目: a2cardboard   文件: SystemWebViewEngine.java
@Override
public void init(CordovaWebView parentWebView, CordovaInterface cordova, CordovaWebViewEngine.Client client,
          CordovaResourceApi resourceApi, PluginManager pluginManager,
          NativeToJsMessageQueue nativeToJsMessageQueue) {
    if (this.cordova != null) {
        throw new IllegalStateException();
    }
    // Needed when prefs are not passed by the constructor
    if (preferences == null) {
        preferences = parentWebView.getPreferences();
    }
    this.parentWebView = parentWebView;
    this.cordova = cordova;
    this.client = client;
    this.resourceApi = resourceApi;
    this.pluginManager = pluginManager;
    this.nativeToJsMessageQueue = nativeToJsMessageQueue;
    webView.init(this, cordova);

    initWebViewSettings();

    nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode.OnlineEventsBridgeModeDelegate() {
        @Override
        public void setNetworkAvailable(boolean value) {
            webView.setNetworkAvailable(value);
        }
        @Override
        public void runOnUiThread(Runnable r) {
            SystemWebViewEngine.this.cordova.getActivity().runOnUiThread(r);
        }
    }));
    bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue);
    exposeJsInterface(webView, bridge);
}
 
源代码25 项目: reader   文件: Notification.java
@SuppressLint("NewApi")
private AlertDialog.Builder createDialog(CordovaInterface cordova) {
    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    if (currentapiVersion >= android.os.Build.VERSION_CODES.HONEYCOMB) {
        return new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_DEVICE_DEFAULT_LIGHT);
    } else {
        return new AlertDialog.Builder(cordova.getActivity());
    }
}
 
源代码26 项目: x5webview-cordova-plugin   文件: X5WebViewEngine.java
@Override
public void init(CordovaWebView parentWebView, CordovaInterface cordova, Client client,
          CordovaResourceApi resourceApi, PluginManager pluginManager,
          NativeToJsMessageQueue nativeToJsMessageQueue) {
    if (this.cordova != null) {
        throw new IllegalStateException();
    }
    // Needed when prefs are not passed by the constructor
    if (preferences == null) {
        preferences = parentWebView.getPreferences();
    }
    this.parentWebView = parentWebView;
    this.cordova = cordova;
    this.client = client;
    this.resourceApi = resourceApi;
    this.pluginManager = pluginManager;
    this.nativeToJsMessageQueue = nativeToJsMessageQueue;
    webView.init(this, cordova);

    initWebViewSettings();

    nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode.OnlineEventsBridgeModeDelegate() {
        @Override
        public void setNetworkAvailable(boolean value) {
            webView.setNetworkAvailable(value);
        }
        @Override
        public void runOnUiThread(Runnable r) {
            X5WebViewEngine.this.cordova.getActivity().runOnUiThread(r);
        }
    }));
    bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue);
    exposeJsInterface(webView, bridge);
}
 
public NativeToJsMessageQueue(CordovaWebView webView, CordovaInterface cordova) {
    this.cordova = cordova;
    this.webView = webView;
    registeredListeners = new BridgeMode[4];
    registeredListeners[0] = new PollingBridgeMode();
    registeredListeners[1] = new LoadUrlBridgeMode();
    registeredListeners[2] = new OnlineEventsBridgeMode();
    registeredListeners[3] = new PrivateApiBridgeMode();
    reset();
}
 
源代码28 项目: keemob   文件: SystemWebViewEngine.java
@Override
public void init(CordovaWebView parentWebView, CordovaInterface cordova, CordovaWebViewEngine.Client client,
          CordovaResourceApi resourceApi, PluginManager pluginManager,
          NativeToJsMessageQueue nativeToJsMessageQueue) {
    if (this.cordova != null) {
        throw new IllegalStateException();
    }
    // Needed when prefs are not passed by the constructor
    if (preferences == null) {
        preferences = parentWebView.getPreferences();
    }
    this.parentWebView = parentWebView;
    this.cordova = cordova;
    this.client = client;
    this.resourceApi = resourceApi;
    this.pluginManager = pluginManager;
    this.nativeToJsMessageQueue = nativeToJsMessageQueue;
    webView.init(this, cordova);

    initWebViewSettings();

    nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode(new NativeToJsMessageQueue.OnlineEventsBridgeMode.OnlineEventsBridgeModeDelegate() {
        @Override
        public void setNetworkAvailable(boolean value) {
            //sometimes this can be called after calling webview.destroy() on destroy()
            //thus resulting in a NullPointerException
            if(webView!=null) {
               webView.setNetworkAvailable(value); 
            }
        }
        @Override
        public void runOnUiThread(Runnable r) {
            SystemWebViewEngine.this.cordova.getActivity().runOnUiThread(r);
        }
    }));
    nativeToJsMessageQueue.addBridgeMode(new NativeToJsMessageQueue.EvalBridgeMode(this, cordova));
    bridge = new CordovaBridge(pluginManager, nativeToJsMessageQueue);
    exposeJsInterface(webView, bridge);
}
 
源代码29 项目: Vitamio-Cordova-Plugin   文件: Vitamio.java
private boolean play(final Class activityClass, final String url, final JSONObject options) {
	final CordovaInterface cordovaObj = cordova;
	final CordovaPlugin plugin = this;

	cordova.getActivity().runOnUiThread(new Runnable() {
		public void run() {
			final Intent streamIntent = new Intent(cordovaObj.getActivity().getApplicationContext(), activityClass);
			Bundle extras = new Bundle();
			extras.putString("mediaUrl", url);

			if (options != null) {
				Iterator<String> optKeys = options.keys();
				while (optKeys.hasNext()) {
					try {
						final String optKey = (String)optKeys.next();
						if (options.get(optKey).getClass().equals(String.class)) {
							extras.putString(optKey, (String)options.get(optKey));
							Log.v(TAG, "Added option: " + optKey + " -> " + String.valueOf(options.get(optKey)));
						} else if (options.get(optKey).getClass().equals(Boolean.class)) {
							extras.putBoolean(optKey, (Boolean)options.get(optKey));
							Log.v(TAG, "Added option: " + optKey + " -> " + String.valueOf(options.get(optKey)));
						}

					} catch (JSONException e) {
						Log.e(TAG, "JSONException while trying to read options. Skipping option.");
					}
				}
				streamIntent.putExtras(extras);
			}

			cordovaObj.startActivityForResult(plugin, streamIntent, ACTIVITY_CODE_PLAY_MEDIA);
		}
	});
	return true;
}
 
源代码30 项目: phonegapbootcampsite   文件: CordovaWebView.java
/**
 * Constructor.
 *
 * @param context
 */
public CordovaWebView(Context context) {
    super(context);
    if (CordovaInterface.class.isInstance(context))
    {
        this.cordova = (CordovaInterface) context;
    }
    else
    {
        Log.d(TAG, "Your activity must implement CordovaInterface to work");
    }
    this.loadConfiguration();
    this.setup();
}