protected Context getContextFromMutableContext() { if (this.getContext() instanceof MutableContextWrapper) { return ((MutableContextWrapper) this.getContext()).getBaseContext(); } return this.getContext(); }
out = new RedirectWebView(this.getContext()); out.loadUrl(url); out.setVisibility(View.GONE); progressDialog.setMessage(getContext().getResources().getString(R.string.loading)); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.show(); out = new WebView(new MutableContextWrapper(getContext())); WebviewUtil.setWebViewSettings(out); out.loadUrl(url);
boolean hasIntent(Intent i) { PackageManager pm = owner.getContext().getPackageManager(); return pm.queryIntentActivities(i, 0).size() > 0; }
implementation.fireViewableChangeEvent(); implementation.setCurrentPosition(left, top, this.getWidth(), this.getHeight()); int orientation = this.getContext().getResources().getConfiguration().orientation; implementation.onOrientationChanged(orientation);
String urlParam = uri.getQueryParameter("url"); if ((webView.getContext() == null) || (urlParam == null) || (!urlParam.startsWith("http"))) { Intent intent = new Intent(webView.getContext(), activity_clz); intent.putExtra(AdActivity.INTENT_KEY_ACTIVITY_TYPE, AdActivity.ACTIVITY_TYPE_BROWSER); WebView browserWebView = new WebView(webView.getContext()); WebviewUtil.setWebViewSettings(browserWebView); BrowserAdActivity.BROWSER_QUEUE.add(browserWebView); webView.getContext().startActivity(intent); } catch (ActivityNotFoundException e) { Toast.makeText(webView.getContext(), R.string.action_cant_be_completed, Toast.LENGTH_SHORT).show();
public void resize(int w, int h, int offset_x, int offset_y, MRAIDImplementation.CUSTOM_CLOSE_POSITION custom_close_position, boolean allow_offscreen) { DisplayMetrics metrics = new DisplayMetrics(); ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay().getMetrics(metrics); FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams( this.getLayoutParams()); if (!implementation.resized) { default_width = lp.width; default_height = lp.height; } h = (int) (h * metrics.density + 0.5); w = (int) (w * metrics.density + 0.5); lp.height = h; lp.width = w; lp.gravity = Gravity.CENTER; if (adView != null) { adView.resize(w, h, offset_x, offset_y, custom_close_position, allow_offscreen, implementation); } if (adView != null) { adView.interacted(); } this.setLayoutParams(lp); }
private void createCalendarEvent(ArrayList<Pair<String, String>> parameters) { W3CEvent event = null; try { if (parameters != null && parameters.size() > 0) { event = W3CEvent.createFromJSON(URLDecoder.decode(parameters.get(0).second, "UTF-8")); } } catch (UnsupportedEncodingException e) { return; } if (event != null) { try { Intent i = event.getInsertIntent(); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); owner.getContext().startActivity(i); owner.fireAdClicked(); Clog.d(Clog.mraidLogTag, Clog.getString(R.string.create_calendar_event)); } catch (ActivityNotFoundException e) { } } }
private void playVideo(ArrayList<Pair<String, String>> parameters) { String uri = null; for (Pair<String, String> bnvp : parameters) { if (bnvp.first.equals("uri")) { uri = bnvp.second; } } if (uri == null) { Clog.d(Clog.mraidLogTag, Clog.getString(R.string.play_vide_no_uri)); return; } Intent i = new Intent(Intent.ACTION_VIEW); i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); try { i.setDataAndType(Uri.parse(URLDecoder.decode(uri, "UTF-8")), "video/mp4"); } catch (UnsupportedEncodingException e) { Clog.d(Clog.mraidLogTag, Clog.getString(R.string.unsupported_encoding)); return; } try { owner.getContext().startActivity(i); owner.fireAdClicked(); } catch (ActivityNotFoundException e) { return; } }
static void handleUrl(AdWebView adWebView, String url) { if ((adWebView == null) || (adWebView.getContext() == null)) { return; } Context context = adWebView.getContext(); Uri uri = Uri.parse(url); String host = uri.getHost(); if (HOST_WEB.equals(host)) { if (adWebView.getUserInteraction()) { launchApp(context); } } else if (HOST_APP.equals(host)) { String auctionInfo = uri.getQueryParameter(KEY_AUCTIONINFO); saveAuctionInfo(auctionInfo); } else if (HOST_CAPTURE.equals(host)) { String auctionID = uri.getQueryParameter(KEY_AUCTIONID); String auctionInfo = buffer.get(auctionID); if (auctionInfo == null) { return; } captureImage(context, adWebView, auctionInfo); } }
private static void callRecordEvent(AdWebView webView, Uri uri) { String urlParam = uri.getQueryParameter("url"); if ((urlParam == null) || (!urlParam.startsWith("http"))) { return; } // Create a invisible webview to fire the url WebView recordEventWebView = new WebView(webView.getContext()); recordEventWebView.setWebViewClient(new WebViewClient() { @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); Clog.d(Clog.baseLogTag, "RecordEvent completed loading: " + url); CookieSyncManager csm = CookieSyncManager.getInstance(); if (csm != null) csm.sync(); } }); recordEventWebView.loadUrl(urlParam); recordEventWebView.setVisibility(View.GONE); webView.addView(recordEventWebView); }
void expand(int w, int h, boolean cust_close, final MRAIDImplementation caller, final boolean allowOrientationChange, final AdActivity.OrientationEnum forceOrientation) { DisplayMetrics metrics = new DisplayMetrics(); ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)) .getDefaultDisplay().getMetrics(metrics);
PackageManager pm = owner.getContext().getPackageManager(); if (pm.checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, owner.getContext().getPackageName()) == PackageManager.PERMISSION_GRANTED) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { setSupports(view, "storePicture", true);
final DownloadManager dm = (DownloadManager) owner.getContext().getSystemService(Context.DOWNLOAD_SERVICE); DownloadManager.Request r = new DownloadManager.Request(Uri.parse(uri_final)); PackageManager pm = owner.getContext().getPackageManager(); if (pm.checkPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, owner.getContext().getPackageName()) == PackageManager.PERMISSION_GRANTED) { r.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, uri_final.split("/")[uri_final.split("/").length - 1]); try {
@Override public void create() { if ((AdView.mraidFullscreenContainer == null) || (AdView.mraidFullscreenImplementation == null)) { Clog.e(Clog.baseLogTag, "Launched MRAID Fullscreen activity with invalid properties"); adActivity.finish(); return; } // remove from any old parents to be safe ViewUtil.removeChildFromParent(AdView.mraidFullscreenContainer); adActivity.setContentView(AdView.mraidFullscreenContainer); if (AdView.mraidFullscreenContainer.getChildAt(0) instanceof AdWebView) { webView = (AdWebView) AdView.mraidFullscreenContainer.getChildAt(0); } // Update the context if(webView.getContext() instanceof MutableContextWrapper) { ((MutableContextWrapper) webView.getContext()).setBaseContext(adActivity); } mraidFullscreenImplementation = AdView.mraidFullscreenImplementation; mraidFullscreenImplementation.setFullscreenActivity(adActivity); if (AdView.mraidFullscreenListener != null) { AdView.mraidFullscreenListener.onCreateCompleted(); } }
boolean useScreenSizeForAddedAccuracy = true; try { a = (Activity) caller.owner.getContext(); } catch (ClassCastException e) { useScreenSizeForAddedAccuracy = false;
protected void close(int w, int h, MRAIDImplementation caller) { // Remove MRAID close button ViewUtil.removeChildFromParent(close_button); close_button = null; if (caller.owner.isFullScreen) { ViewUtil.removeChildFromParent(caller.owner); if (caller.getDefaultContainer() != null) { caller.getDefaultContainer().addView(caller.owner, 0); } if (caller.getFullscreenActivity() != null) { caller.getFullscreenActivity().finish(); } // Reset the context of MutableContext wrapper for banner expand and close case. if (getMediaType().equals(MediaType.BANNER) && (caller.owner.getContext() instanceof MutableContextWrapper)) { ((MutableContextWrapper) caller.owner.getContext()).setBaseContext(getContext()); } } // null these out for safety mraidFullscreenContainer = null; mraidFullscreenImplementation = null; mraidFullscreenListener = null; MRAIDChangeSize(w, h); mraid_is_closing = true; isMRAIDExpanded = false; }
final float scale = caller.owner.getContext().getResources().getDisplayMetrics().density; buttonPxSideLength = (int) (50 * scale);
if (webView.getContext() instanceof MutableContextWrapper) { ((MutableContextWrapper) webView.getContext()).setBaseContext(adActivity);