List of usage examples for org.apache.cordova CordovaWebView getView
View getView();
From source file:com.ezartech.ezar.videooverlay.ezAR.java
License:Open Source License
@Override public void initialize(final CordovaInterface cordova, final CordovaWebView cvWebView) { super.initialize(cordova, cvWebView); webViewView = cvWebView.getView(); activity = cordova.getActivity();/*from w w w. j a v a 2 s. c o m*/ activity.runOnUiThread(new Runnable() { @Override public void run() { //configure webview webViewView.setKeepScreenOn(true); webViewView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); //temporarily remove webview from view stack ((ViewGroup) webViewView.getParent()).removeView(webViewView); cordovaViewContainer = new FrameLayout(activity); cordovaViewContainer.setBackgroundColor(Color.BLACK); activity.setContentView(cordovaViewContainer, new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); //create & add videoOverlay to view stack cameraView = new TextureView(activity); cameraView.setSurfaceTextureListener(mSurfaceTextureListener); cordovaViewContainer.addView(cameraView, new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); //add webview on top of videoOverlay cordovaViewContainer.addView(webViewView, new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); ((FrameLayout) cordovaViewContainer.getParent()).addOnLayoutChangeListener(layoutChangeListener); ((FrameLayout) cordovaViewContainer.getParent()).setBackgroundColor(Color.BLACK); } }); }
From source file:com.ezartech.ezar.videooverlay.VideoOverlayPlugin.java
License:Open Source License
@Override public void initialize(final CordovaInterface cordova, final CordovaWebView cvWebView) { super.initialize(cordova, cvWebView); webViewView = cvWebView.getView(); activity = cordova.getActivity();//w w w .jav a2 s .c o m activity.runOnUiThread(new Runnable() { @Override public void run() { //configure webview webViewView.setKeepScreenOn(true); Log.d(TAG, "WebView HW accelerated: " + webViewView.isHardwareAccelerated()); // if (webViewView.isHardwareAccelerated()) { // webViewView.setLayerType(WebView.LAYER_TYPE_HARDWARE, null); // } else { // webViewView.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null); // } //temporarily remove webview from view stack ((ViewGroup) webViewView.getParent()).removeView(webViewView); if (EXPERIMENTAL) { cameraViewContainer = new AspectRatioFrameLayout(cordova.getActivity().getApplicationContext()); cameraViewContainer.setForegroundGravity(Gravity.CENTER); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, Gravity.CENTER); activity.setContentView(cameraViewContainer, params); } else { cameraViewContainer = new FrameLayout(activity); cameraViewContainer.setBackgroundColor(Color.BLACK); activity.setContentView(cameraViewContainer, new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); } //create & add videoOverlay to view stack cameraView = new TextureView(activity); cameraView.setSurfaceTextureListener(mSurfaceTextureListener); cameraViewContainer.addView(cameraView, new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); //add webview on top of videoOverlay cameraViewContainer.addView(webViewView, new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT)); if ("org.xwalk.core.XWalkView".equals(webViewView.getClass().getName()) || "org.crosswalk.engine.XWalkCordovaView".equals(webViewView.getClass().getName())) { try { /* view.setZOrderOnTop(true) * Called just in time as with root.setBackground(...) the color * come in front and take the whoel screen */ webViewView.getClass().getMethod("setZOrderOnTop", boolean.class).invoke(webViewView, true); } catch (Exception e) { } } ((FrameLayout) cameraViewContainer.getParent()).addOnLayoutChangeListener(layoutChangeListener); ((FrameLayout) cameraViewContainer.getParent()).setBackgroundColor(Color.BLACK); } }); }
From source file:com.intel.xdk.device.Device.java
License:Apache License
@Override public void initialize(CordovaInterface cordova, CordovaWebView webView) { super.initialize(cordova, webView); this.activity = cordova.getActivity(); this.webView = webView; //remote site support remoteLayout = new AbsoluteLayout(activity); remoteLayout.setBackgroundColor(Color.BLACK); //hide the remote site display until needed remoteLayout.setVisibility(View.GONE); //create the close button remoteClose = new ImageButton(activity); remoteClose.setBackgroundColor(Color.TRANSPARENT); Drawable remoteCloseImage = null;/*from w w w. j av a 2s . c om*/ remoteCloseImage = activity.getResources().getDrawable( activity.getResources().getIdentifier("remote_close", "drawable", activity.getPackageName())); File remoteCloseImageFile = new File(activity.getFilesDir(), "_intelxdk/remote_close.png"); if (remoteCloseImageFile.exists()) { remoteCloseImage = (Drawable.createFromPath(remoteCloseImageFile.getAbsolutePath())); } else { remoteCloseImage = (activity.getResources().getDrawable( activity.getResources().getIdentifier("remote_close", "drawable", activity.getPackageName()))); } //set the button image //remoteClose.setImageDrawable(remoteCloseImage); remoteClose.setBackgroundDrawable(remoteCloseImage); //set up the button click action remoteClose.setOnClickListener(new OnClickListener() { public void onClick(View v) { closeRemoteSite(); } }); //add the close button remoteLayout.addView(remoteClose); final ViewGroup parent = (ViewGroup) webView.getView().getParent(); activity.runOnUiThread(new Runnable() { public void run() { //hack for mobius if (parent != null) { //add layout to activity root layout parent.addView(remoteLayout, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, Gravity.CENTER)); } } }); //Initialize the orientation. lastOrientation = "unknown"; //Listen to the orientation change. OrientationEventListener listener = new OrientationEventListener(activity) { @Override public void onOrientationChanged(int orientation) { //Log.d("orientation","orientation: " + orientation); String currentOrientation = "unknown"; boolean orientationChanged = false; //int displayOrientation = 0; if (orientation > 345 || orientation < 15) { currentOrientation = "portrait"; displayOrientation = 0; } else if (orientation > 75 && orientation < 105) { currentOrientation = "landscape"; displayOrientation = 90; } else if (orientation > 165 && orientation < 195) { currentOrientation = "portrait"; displayOrientation = 180; } else if (orientation > 255 && orientation < 285) { currentOrientation = "landscape"; displayOrientation = -90; } if (currentOrientation.equals("unknown")) { currentOrientation = lastOrientation; } if (!currentOrientation.equals(lastOrientation)) { orientationChanged = true; Log.d("orientation", "Orientation changes from " + lastOrientation + " to " + currentOrientation + ", current orientation: " + orientation + "."); } if (orientationChanged) { String js = "javascript:try{intel.xdk.device.orientation='" + displayOrientation + "';}catch(e){}var e = document.createEvent('Events');e.initEvent('intel.xdk.device.orientation.change', true, true);e.success=true;e.orientation='" + displayOrientation + "';document.dispatchEvent(e);"; injectJS(js); } lastOrientation = currentOrientation; } }; listener.enable(); //Listener to the screen unlock event. IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON); filter.addAction(Intent.ACTION_SCREEN_OFF); filter.addAction(Intent.ACTION_USER_PRESENT); this.receiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { if (intent.getAction().equals(Intent.ACTION_SCREEN_ON)) { Log.d("screen_on", "Screen is on."); } else if (intent.getAction().equals(Intent.ACTION_SCREEN_OFF)) { Log.d("screen_lock", "Screen is off"); String js = "javascript: var e = document.createEvent('Events');e.initEvent('intel.xdk.device.pause');e.success=true;document.dispatchEvent(e);"; injectJS(js); } else if (intent.getAction().equals(Intent.ACTION_USER_PRESENT)) { Log.d("user_present", "User is present."); String js = "javascript: var e = document.createEvent('Events');e.initEvent('intel.xdk.device.continue');e.success=true;document.dispatchEvent(e);"; injectJS(js); } } }; activity.registerReceiver(receiver, filter); //Listener to the back key down event WebViewKeyListener webViewListener = new WebViewKeyListener(webView); webView.getView().setOnKeyListener(webViewListener); // Wait this many milliseconds max for the TCP connection to be established final int CONNECTION_TIMEOUT = 60 * 1000; // Wait this many milliseconds max for the server to send us data once the connection has been established final int SO_TIMEOUT = 5 * 60 * 1000; persistentHttpClient = new DefaultHttpClient() { @Override protected ClientConnectionManager createClientConnectionManager() { SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", getHttpsSocketFactory(), 443)); HttpParams params = getParams(); HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT); HttpConnectionParams.setSoTimeout(params, SO_TIMEOUT); //HttpProtocolParams.setUserAgent(params, getUserAgent(HttpProtocolParams.getUserAgent(params))); return new ThreadSafeClientConnManager(params, registry); } /** Gets an HTTPS socket factory with SSL Session Caching if such support is available, otherwise falls back to a non-caching factory * @return */ protected SocketFactory getHttpsSocketFactory() { try { Class<?> sslSessionCacheClass = Class.forName("android.net.SSLSessionCache"); Object sslSessionCache = sslSessionCacheClass.getConstructor(Context.class) .newInstance(activity.getApplicationContext()); Method getHttpSocketFactory = Class.forName("android.net.SSLCertificateSocketFactory") .getMethod("getHttpSocketFactory", new Class<?>[] { int.class, sslSessionCacheClass }); return (SocketFactory) getHttpSocketFactory.invoke(null, CONNECTION_TIMEOUT, sslSessionCache); } catch (Exception e) { Log.e("HttpClientProvider", "Unable to use android.net.SSLCertificateSocketFactory to get a SSL session caching socket factory, falling back to a non-caching socket factory", e); return SSLSocketFactory.getSocketFactory(); } } };//Static HttpClient Object //cache references to methods for use in injectJS try { evaluateJavascript = webView.getClass().getMethod("evaluateJavascript", String.class, ValueCallback.class); } catch (Exception e) { } try { sendJavascript = webView.getClass().getMethod("sendJavascript", String.class); } catch (Exception e) { } emptyVC = new ValueCallback<String>() { @Override public void onReceiveValue(String s) { } }; }
From source file:plugin.google.maps.CordovaGoogleMaps.java
@SuppressLint("NewApi") @Override/*from w w w . j a v a 2 s . co 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.GoogleMaps.java
@SuppressLint("NewApi") @Override/*w w w. j a v a 2s . c o m*/ public void initialize(final CordovaInterface cordova, final CordovaWebView webView) { super.initialize(cordova, webView); activity = cordova.getActivity(); density = Resources.getSystem().getDisplayMetrics().density; final View view = webView.getView(); root = (ViewGroup) view.getParent(); // Is this release build version? boolean isRelease = false; try { PackageManager manager = activity.getPackageManager(); ApplicationInfo appInfo = manager.getApplicationInfo(activity.getPackageName(), 0); isRelease = !((appInfo.flags & ApplicationInfo.FLAG_DEBUGGABLE) == ApplicationInfo.FLAG_DEBUGGABLE); } catch (Exception e) { } //Log.i("CordovaLog", "This app uses phonegap-googlemaps-plugin version " + PLUGIN_VERSION); if (!isRelease) { cordova.getThreadPool().execute(new Runnable() { @Override public void run() { try { /* JSONArray params = new JSONArray(); params.put("get"); params.put("http://plugins.cordova.io/api/plugin.google.maps"); HttpRequest httpReq = new HttpRequest(); httpReq.initialize(cordova, null); httpReq.execute("execute", params, new CallbackContext("version_check", webView) { @Override public void sendPluginResult(PluginResult pluginResult) { if (pluginResult.getStatus() == PluginResult.Status.OK.ordinal()) { try { JSONObject result = new JSONObject(pluginResult.getStrMessage()); JSONObject distTags = result.getJSONObject("dist-tags"); String latestVersion = distTags.getString("latest"); if (latestVersion.equals(PLUGIN_VERSION) == false) { Log.i("CordovaLog", "phonegap-googlemaps-plugin version " + latestVersion + " is available."); } } catch (JSONException e) {} } } }); */ } catch (Exception e) { } } }); } cordova.getActivity().runOnUiThread(new Runnable() { @SuppressLint("NewApi") public void run() { /* try { Method method = webView.getClass().getMethod("getSettings"); WebSettings settings = (WebSettings)method.invoke(null); settings.setRenderPriority(RenderPriority.HIGH); settings.setCacheMode(WebSettings.LOAD_NO_CACHE); } catch (Exception e) { e.printStackTrace(); } */ if (Build.VERSION.SDK_INT >= 21) { view.setLayerType(View.LAYER_TYPE_HARDWARE, null); } root.setBackgroundColor(Color.WHITE); if (VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD_MR1) { activity.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN); } if (VERSION.SDK_INT <= Build.VERSION_CODES.ICE_CREAM_SANDWICH_MR1) { Log.d(TAG, "Google Maps Plugin reloads the browser to change the background color as transparent."); view.setBackgroundColor(0); try { Method method = webView.getClass().getMethod("reload"); method.invoke(webView); } catch (Exception e) { e.printStackTrace(); } } } }); }
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.j av a2 s. co m throw new RuntimeException(fullTypeName + " is not a valid choice for getting an existing instance"); }