Example usage for org.apache.cordova CordovaWebView getUrl

List of usage examples for org.apache.cordova CordovaWebView getUrl

Introduction

In this page you can find the example usage for org.apache.cordova CordovaWebView getUrl.

Prototype

String getUrl();

Source Link

Usage

From source file:com.intel.xdk.player.Player.java

License:Apache License

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    //get convenience reference to activity
    activity = cordova.getActivity();//from  w w w  . jav  a  2  s.c  o  m

    //get the current url
    final CordovaWebView wv = webView;
    activity.runOnUiThread(new Runnable() {
        public void run() {
            currentUrl = wv.getUrl();
        }
    });

    //turn on remote debugging
    // activity.runOnUiThread(new Runnable() {
    //     public void run() {
    //         if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    //          try {
    //              Method m = WebView.class.getMethod("setWebContentsDebuggingEnabled", boolean.class);
    //              m.invoke(WebView.class, true);
    //          } catch (Exception e) {
    //              // TODO Auto-generated catch block
    //              e.printStackTrace();
    //          }
    //         }
    //     }
    // });

    soundPool = new SoundPool(30, AudioManager.STREAM_MUSIC, 100);
    soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
        public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
            soundLoaded(sampleId, status);
        }
    });
    hasLoadSoundCallback = true;
}

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();
                }
            }

        }
    });

}