public synchronized WrapperWebView getWebView() { WrapperWebView webView = null; if (sAvailable.size() > 0) { webView = sAvailable.get(0); sAvailable.remove(0); } else { // 无可用的webview时,自动扩容 webView = new WrapperWebView(new MutableContextWrapper(mContext)); ViewGroup.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); webView.setLayoutParams(layoutParams); } sInUse.add(webView); webView.loadUrl(""); return webView; }
public static Context getTopContext(View view) { if (view == null) { return null; } ViewParent parent = view.getParent(); if ((parent == null) || !(parent instanceof View)) { if(view.getContext() instanceof MutableContextWrapper){ return ((MutableContextWrapper)view.getContext()).getBaseContext(); } return view.getContext(); } //noinspection ConstantConditions while ((parent.getParent() != null) && (parent.getParent() instanceof View)) { parent = parent.getParent(); } return ((View) parent).getContext(); }
@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(); } }
public void initWebViewPool(Context context) { this.mContext = context; for (int i = 0; i < mPoolSize; i++) { ViewGroup.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); // 引入Context中间层MutableContextWrapper WrapperWebView webView = new WrapperWebView(new MutableContextWrapper(mContext)); webView.setLayoutParams(layoutParams); sAvailable.add(webView); } }
public synchronized void resetWebView(WrapperWebView webView) { ((MutableContextWrapper) webView.getContext()).setBaseContext(mContext); webView.reset(); sInUse.remove(webView); if (sAvailable.size() < mPoolSize) {//保存个数不能大于池子的大小 sAvailable.add(webView); } else { // 扩容出来的临时webview直接回收 webView.destroy(); } }
@Override public void onClick(View view) { if (view.getId() == R.id.btn_close) { if (getContext() instanceof MutableContextWrapper) { Context baseContext = ((MutableContextWrapper) getContext()).getBaseContext(); if (baseContext instanceof Activity) { ((Activity) baseContext).finish(); } } else if (getContext() instanceof Activity) { ((Activity) getContext()).finish(); } } else if (view.getId() == R.id.btn_refresh) { reload(); } }
protected XinWebView useWebView(Context ctx) { XinWebView view = getWebView(); if (view != null) { ((MutableContextWrapper) view.getContext()).setBaseContext(ctx); view.setIsUsed(true); } return view; }
private XinWebView reuseWebView(Context context) { createWebView(); doConfig(); if (mWebView != null) { ((MutableContextWrapper) mWebView.getContext()).setBaseContext(context); mWebView.setIsUsed(true); } return mWebView; }
/** * Pre-load {@link ReactRootView} to local {@link Map}, you may want to * load it in previous activity. */ public static void init(Activity activity, ReactInfo reactInfo) { if (CACHE_VIEW_MAP.get(reactInfo.getMainComponentName()) != null) { return; } ReactRootView rootView = new ReactRootView(new MutableContextWrapper(activity)); rootView.startReactApplication( ((ReactApplication) activity.getApplication()).getReactNativeHost().getReactInstanceManager(), reactInfo.getMainComponentName(), reactInfo.getLaunchOptions()); CACHE_VIEW_MAP.put(reactInfo.getMainComponentName(), rootView); }
/** * <p>Creates the shared webView used throughout the lifetime of the TurbolinksSession.</p> * * @param applicationContext An application context. * @return The shared WebView. */ static WebView createWebView(Context applicationContext) { MutableContextWrapper contextWrapper = new MutableContextWrapper(applicationContext); WebView webView = new WebView(contextWrapper); configureWebViewDefaults(webView); setWebViewLayoutParams(webView); return webView; }
public void setRetainedView(View view) { if(!(view.getContext() instanceof MutableContextWrapper)){ throw new IllegalStateException("View must be created with inflateRetainableView"); } mRetainedView = view; }
public View getRetainedView(Context context) { if(mRetainedView != null){ MutableContextWrapper mutable = (MutableContextWrapper)mRetainedView.getContext(); mutable.setBaseContext(context); } return mRetainedView; }
public VideoWebView(Context context, VideoAd owner, VideoRequestManager manager) { super(new MutableContextWrapper(context)); this.owner = owner; this.manager = manager; setupSettings(); setup(); }
private void updateMutableContext(ViewGroup layout) { // Update the MutableContext Wrapper. with the new activity context. if(this.getContext() instanceof MutableContextWrapper) { ((MutableContextWrapper)this.getContext()).setBaseContext(layout.getContext()); } // Update the MutableContext Wrapper. with the new activity context. if(this.videoWebView.getContext() instanceof MutableContextWrapper) { ((MutableContextWrapper)this.videoWebView.getContext()).setBaseContext(layout.getContext()); } }
private void setIAdView(InterstitialAdView av) { adView = av; if (adView == null) return; adView.setAdImplementation(this); layout.setBackgroundColor(adView.getBackgroundColor()); layout.removeAllViews(); if (adView.getParent() != null) { ((ViewGroup) adView.getParent()).removeAllViews(); } InterstitialAdQueueEntry iAQE = adView.getAdQueue().poll(); // To be safe, ads from the future will be considered to have expired // if now-p.first is less than 0, the ad will be considered to be from the future while (iAQE != null && (now - iAQE.getTime() > InterstitialAdView.MAX_AGE || now - iAQE.getTime() < 0)) { Clog.w(Clog.baseLogTag, Clog.getString(R.string.too_old)); iAQE = adView.getAdQueue().poll(); } if ((iAQE == null) || !(iAQE.getView() instanceof AdWebView)) return; webView = (AdWebView) iAQE.getView(); // Update the context if(webView.getContext() instanceof MutableContextWrapper) { ((MutableContextWrapper) webView.getContext()).setBaseContext(adActivity); } // lock orientation to ad request orientation //@TODO need to change this check condition to reflect MRAID spec if(!(webView.getCreativeWidth()==1 && webView.getCreativeHeight()==1)) { AdActivity.lockToConfigOrientation(adActivity, webView.getOrientation()); } layout.addView(webView); }
public AdWebView(AdView adView) { super(new MutableContextWrapper(adView.getContext())); this.adView = adView; this.initialMraidStateString = MRAIDImplementation.MRAID_INIT_STATE_STRINGS[ MRAIDImplementation.MRAID_INIT_STATE.STARTING_DEFAULT.ordinal()]; setupSettings(); setup(); }
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; }
/** * 绑定新的Context * * @param context */ public void bindNewContext(Context context) { if (getContext() instanceof MutableContextWrapper) { ((MutableContextWrapper) getContext()).setBaseContext(context); } }
protected XinWebView initWebView() { XinWebView view = new XinWebView(new MutableContextWrapper(getApplication())); put(view); return view; }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (getUseDeveloperSupport() && Build.VERSION.SDK_INT >= 23) { // Get permission to show redbox in dev builds. if (!Settings.canDrawOverlays(this)) { Intent serviceIntent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION); startActivity(serviceIntent); FLog.w(ReactConstants.TAG, REDBOX_PERMISSION_MESSAGE); Toast.makeText(this, REDBOX_PERMISSION_MESSAGE, Toast.LENGTH_LONG).show(); } } mReactRootView = ReactPreLoader.getRootView(getReactInfo()); if (mReactRootView != null) { Log.i(TAG, "use pre-load view"); MutableContextWrapper contextWrapper = (MutableContextWrapper) mReactRootView.getContext(); contextWrapper.setBaseContext(this); try { ViewGroup viewGroup = (ViewGroup) mReactRootView.getParent(); if (viewGroup != null) { viewGroup.removeView(mReactRootView); } } catch (Exception exception) { Log.e(TAG, "getParent error", exception); } } else { Log.i(TAG, "createRootView"); mReactRootView = createRootView(); if (mReactRootView != null) { mReactRootView.startReactApplication( getReactNativeHost().getReactInstanceManager(), getMainComponentName(), getLaunchOptions()); } } setContentView(mReactRootView); mDoubleTapReloadRecognizer = new DoubleTapReloadRecognizer(); }
public static View inflateRetainableView(Context context, int layoutId, ViewGroup container) { LayoutInflater inflater = LayoutInflater.from(context) .cloneInContext(new MutableContextWrapper(context)); return inflater.inflate(layoutId, container, false); }
void loadURLInCorrectBrowser(String url) { if (!owner.getOpensNativeBrowser()) { Clog.d(Clog.baseLogTag, Clog.getString(R.string.opening_inapp)); //If it's a direct URL to the play store, just open it. if (checkForApp(url)) { return; } try { final WebView out; // Unless disabled by the user, handle redirects in background if (owner.getLoadsInBackground()) { // Otherwise, create an invisible 1x1 webview to load the landing // page and detect if we're redirecting to a market url out = new RedirectWebView(this.getContext()); out.loadUrl(url); out.setVisibility(View.GONE); // owner.addView(out); if (this.owner.getShowLoadingIndicator()) { //Show a dialog box progressDialog = new ProgressDialog(this.getContextFromMutableContext()); progressDialog.setCancelable(true); progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialogInterface) { out.stopLoading(); } }); progressDialog.setMessage(getContext().getResources().getString(R.string.loading)); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.show(); } } else { // Stick the URL directly into the new activity. out = new WebView(new MutableContextWrapper(getContext())); WebviewUtil.setWebViewSettings(out); out.loadUrl(url); openInAppBrowser(out); } } catch (Exception e) { // Catches PackageManager$NameNotFoundException for webview Clog.e(Clog.baseLogTag, "Exception initializing the redirect webview: " + e.getMessage()); } } else { Clog.d(Clog.baseLogTag, Clog.getString(R.string.opening_native)); openNativeIntent(url); } }
protected Context getContextFromMutableContext() { if (this.getContext() instanceof MutableContextWrapper) { return ((MutableContextWrapper) this.getContext()).getBaseContext(); } return this.getContext(); }
InstreamVideoView(Context context, AttributeSet attrs, int defStyle) { super(new MutableContextWrapper(context), attrs, defStyle); setup(context); }
void loadURLInCorrectBrowser(String url) { if (!adView.getOpensNativeBrowser()) { Clog.d(Clog.baseLogTag, Clog.getString(R.string.opening_inapp)); //If it's a direct URL to the play store, just open it. if (checkForApp(url)) { return; } try { final WebView out; // Unless disabled by the user, handle redirects in background if (adView.getLoadsInBackground()) { // Otherwise, create an invisible 1x1 webview to load the landing // page and detect if we're redirecting to a market url out = new RedirectWebView(this.getContext()); out.loadUrl(url); out.setVisibility(View.GONE); adView.addView(out); if (this.adView.getShowLoadingIndicator()) { //Show a dialog box progressDialog = new ProgressDialog(this.getContextFromMutableContext()); progressDialog.setCancelable(true); progressDialog.setOnCancelListener(new DialogInterface.OnCancelListener() { @Override public void onCancel(DialogInterface dialogInterface) { out.stopLoading(); } }); progressDialog.setMessage(getContext().getResources().getString(R.string.loading)); progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER); progressDialog.show(); } } else { // Stick the URL directly into the new activity. out = new WebView(new MutableContextWrapper(getContext())); WebviewUtil.setWebViewSettings(out); out.loadUrl(url); openInAppBrowser(out); } }catch (Exception e){ // Catches PackageManager$NameNotFoundException for webview Clog.e(Clog.baseLogTag, "Exception initializing the redirect webview: " + e.getMessage()); } } else { Clog.d(Clog.baseLogTag, Clog.getString(R.string.opening_native)); openNativeIntent(url); triggerBrowserLaunchEvent(); } }