List of usage examples for org.apache.cordova CordovaWebView getPluginManager
PluginManager getPluginManager();
From source file:plugin.google.maps.CordovaGoogleMaps.java
@SuppressLint("NewApi") @Override//from ww w. j a v a 2 s . c o m public void initialize(final CordovaInterface cordova, final CordovaWebView webView) { super.initialize(cordova, webView); if (root != null) { return; } LOG.setLogLevel(LOG.ERROR); activity = cordova.getActivity(); final View view = webView.getView(); view.getViewTreeObserver().addOnScrollChangedListener(CordovaGoogleMaps.this); root = (ViewGroup) view.getParent(); pluginManager = webView.getPluginManager(); cordova.getActivity().runOnUiThread(new Runnable() { @SuppressLint("NewApi") public void run() { CURRENT_URL = webView.getUrl(); // Enable this, webView makes draw cache on the Android action bar issue. //View view = webView.getView(); //if (Build.VERSION.SDK_INT >= 21 || "org.xwalk.core.XWalkView".equals(view.getClass().getName())){ // view.setLayerType(View.LAYER_TYPE_HARDWARE, null); // Log.d("Layout", "--> view =" + view.isHardwareAccelerated()); //always false //} // ------------------------------ // Check of Google Play Services // ------------------------------ int checkGooglePlayServices = GooglePlayServicesUtil.isGooglePlayServicesAvailable(activity); Log.d(TAG, "----> checkGooglePlayServices = " + (ConnectionResult.SUCCESS == checkGooglePlayServices)); if (checkGooglePlayServices != ConnectionResult.SUCCESS) { // google play services is missing!!!! /* * Returns status code indicating whether there was an error. Can be one * of following in ConnectionResult: SUCCESS, SERVICE_MISSING, * SERVICE_VERSION_UPDATE_REQUIRED, SERVICE_DISABLED, SERVICE_INVALID. */ Log.e(TAG, "---Google Play Services is not available: " + GooglePlayServicesUtil.getErrorString(checkGooglePlayServices)); boolean isNeedToUpdate = false; String errorMsg = "Google Maps Android API v2 is not available for some reason on this device. Do you install the latest Google Play Services from Google Play Store?"; switch (checkGooglePlayServices) { case ConnectionResult.DEVELOPER_ERROR: errorMsg = "The application is misconfigured. This error is not recoverable and will be treated as fatal. The developer should look at the logs after this to determine more actionable information."; break; case ConnectionResult.INTERNAL_ERROR: errorMsg = "An internal error of Google Play Services occurred. Please retry, and it should resolve the problem."; break; case ConnectionResult.INVALID_ACCOUNT: errorMsg = "You attempted to connect to the service with an invalid account name specified."; break; case ConnectionResult.LICENSE_CHECK_FAILED: errorMsg = "The application is not licensed to the user. This error is not recoverable and will be treated as fatal."; break; case ConnectionResult.NETWORK_ERROR: errorMsg = "A network error occurred. Please retry, and it should resolve the problem."; break; case ConnectionResult.SERVICE_DISABLED: errorMsg = "The installed version of Google Play services has been disabled on this device. Please turn on Google Play Services."; break; case ConnectionResult.SERVICE_INVALID: errorMsg = "The version of the Google Play services installed on this device is not authentic. Please update the Google Play Services from Google Play Store."; isNeedToUpdate = true; break; case ConnectionResult.SERVICE_MISSING: errorMsg = "Google Play services is missing on this device. Please install the Google Play Services."; isNeedToUpdate = true; break; case ConnectionResult.SERVICE_VERSION_UPDATE_REQUIRED: errorMsg = "The installed version of Google Play services is out of date. Please update the Google Play Services from Google Play Store."; isNeedToUpdate = true; break; case ConnectionResult.SIGN_IN_REQUIRED: errorMsg = "You attempted to connect to the service but you are not signed in. Please check the Google Play Services configuration"; break; default: isNeedToUpdate = true; break; } final boolean finalIsNeedToUpdate = isNeedToUpdate; AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity); alertDialogBuilder.setMessage(errorMsg).setCancelable(false).setPositiveButton("Close", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); if (finalIsNeedToUpdate) { try { activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("market://details?id=com.google.android.gms"))); } catch (android.content.ActivityNotFoundException anfe) { activity.startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse( "http://play.google.com/store/apps/details?id=appPackageName"))); } } } }); AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); Log.e(TAG, "Google Play Services is not available."); return; } webView.getView().setBackgroundColor(Color.TRANSPARENT); webView.getView().setOverScrollMode(View.OVER_SCROLL_NEVER); mPluginLayout = new MyPluginLayout(webView, activity); mPluginLayout.isSuspended = true; // Check the API key ApplicationInfo appliInfo = null; try { appliInfo = activity.getPackageManager().getApplicationInfo(activity.getPackageName(), PackageManager.GET_META_DATA); } catch (NameNotFoundException e) { } String API_KEY = appliInfo.metaData.getString("com.google.android.maps.v2.API_KEY"); if ("API_KEY_FOR_ANDROID".equals(API_KEY)) { AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(activity); alertDialogBuilder.setMessage( "Please replace 'API_KEY_FOR_ANDROID' in the platforms/android/AndroidManifest.xml with your API Key!") .setCancelable(false).setPositiveButton("Close", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { dialog.dismiss(); } }); AlertDialog alertDialog = alertDialogBuilder.create(); // show it alertDialog.show(); } CURRENT_URL = webView.getUrl(); //------------------------------ // Initialize Google Maps SDK //------------------------------ if (!initialized) { try { MapsInitializer.initialize(cordova.getActivity()); initialized = true; } catch (Exception e) { e.printStackTrace(); } } } }); }
From source file:plugin.google.maps.Environment.java
@Override public void initialize(final CordovaInterface cordova, final CordovaWebView webView) { pluginManager = webView.getPluginManager(); }
From source file:run.ace.IncomingMessages.java
License:Open Source License
public static Object getInstance(JSONArray message, Activity activity, CordovaWebView webView) throws JSONException { String fullTypeName = message.getString(2); if (fullTypeName.equals("android.content.Context")) { return activity.getApplicationContext(); } else if (fullTypeName.equals("android.app.Activity")) { return activity; } else if (fullTypeName.equals("android.content.Intent")) { return NativeHost.intent; } else if (fullTypeName.equals("HostPage")) { return activity.findViewById(android.R.id.content); } else if (fullTypeName.equals("HostWebView")) { return webView.getView(); } else if (fullTypeName.equals("PluginManager")) { return webView.getPluginManager(); }//w w w. ja v a2 s . co m throw new RuntimeException(fullTypeName + " is not a valid choice for getting an existing instance"); }