android.content.MutableContextWrapper Java Examples

The following examples show how to use android.content.MutableContextWrapper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: AndroidHybridLib   Author: snailycy   File: WebViewPool.java    License: Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #2
Source Project: mobile-sdk-android   Author: appnexus   File: ViewUtil.java    License: Apache License 2.0 6 votes vote down vote up
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();
}
 
Example #3
Source Project: mobile-sdk-android   Author: appnexus   File: ANNativeAdResponse.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressLint("SetJavaScriptEnabled")
public RedirectWebView(final Context context) {
    super(new MutableContextWrapper(context));

    WebviewUtil.setWebViewSettings(this);
    this.setWebViewClient(new WebViewClient() {

        @Override
        public void onPageFinished(WebView view, String url) {
            Clog.v(Clog.browserLogTag, "Opening URL: " + url);
            ViewUtil.removeChildFromParent(RedirectWebView.this);
            if (progressDialog != null && progressDialog.isShowing()) {
                progressDialog.dismiss();
            }

            startBrowserActivity(context);
        }
    });
}
 
Example #4
Source Project: mobile-sdk-android   Author: appnexus   File: MRAIDAdActivity.java    License: Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example #5
Source Project: FastWebView   Author: Ryan-Shz   File: FastWebViewPool.java    License: MIT License 5 votes vote down vote up
public static void release(FastWebView webView) {
    if (webView == null) {
        return;
    }
    webView.release();
    MutableContextWrapper wrapper = (MutableContextWrapper) webView.getContext();
    wrapper.setBaseContext(wrapper.getApplicationContext());
    sPool.release(webView);
    LogUtils.d("release webview instance to pool.");
}
 
Example #6
Source Project: AndroidHybridLib   Author: snailycy   File: WebViewPool.java    License: Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #7
Source Project: AndroidHybridLib   Author: snailycy   File: WebViewPool.java    License: Apache License 2.0 5 votes vote down vote up
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();
    }
}
 
Example #8
Source Project: AndroidHybridLib   Author: snailycy   File: WrapperWebView.java    License: Apache License 2.0 5 votes vote down vote up
@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();
    }
}
 
Example #9
Source Project: react-native-preloader   Author: markzhai   File: ReactPreLoader.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * 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);
}
 
Example #10
Source Project: turbolinks-android   Author: turbolinks   File: TurbolinksHelper.java    License: MIT License 5 votes vote down vote up
/**
 * <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;
}
 
Example #11
Source Project: mobile-sdk-android   Author: appnexus   File: VideoWebView.java    License: Apache License 2.0 5 votes vote down vote up
public VideoWebView(Context context, VideoAd owner, AdViewRequestManager manager) {
    super(new MutableContextWrapper(context));
    this.owner = owner;
    this.manager = manager;
    setupSettings();
    setup();
}
 
Example #12
Source Project: mobile-sdk-android   Author: appnexus   File: InstreamVideoView.java    License: Apache License 2.0 5 votes vote down vote up
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());
    }
}
 
Example #13
Source Project: mobile-sdk-android   Author: appnexus   File: InterstitialAdActivity.java    License: Apache License 2.0 5 votes vote down vote up
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);
}
 
Example #14
Source Project: mobile-sdk-android   Author: appnexus   File: AdWebView.java    License: Apache License 2.0 5 votes vote down vote up
public AdWebView(AdView adView, UTAdRequester requester) {
    super(new MutableContextWrapper(adView.getContext()));
    this.adView = adView;
    this.caller_requester = requester;
    this.initialMraidStateString = MRAIDImplementation.MRAID_INIT_STATE_STRINGS[
            MRAIDImplementation.MRAID_INIT_STATE.STARTING_DEFAULT.ordinal()];
    setupSettings();
    setup();
}
 
Example #15
Source Project: mobile-sdk-android   Author: appnexus   File: AdView.java    License: Apache License 2.0 5 votes vote down vote up
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;
}
 
Example #16
Source Project: AndroidHybridLib   Author: snailycy   File: WrapperWebView.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * 绑定新的Context
 *
 * @param context
 */
public void bindNewContext(Context context) {
    if (getContext() instanceof MutableContextWrapper) {
        ((MutableContextWrapper) getContext()).setBaseContext(context);
    }
}
 
Example #17
Source Project: react-native-preloader   Author: markzhai   File: MrReactActivity.java    License: Apache License 2.0 4 votes vote down vote up
@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();
}
 
Example #18
Source Project: mobile-sdk-android   Author: appnexus   File: VideoWebView.java    License: Apache License 2.0 4 votes vote down vote up
protected Context getContextFromMutableContext() {
    if (this.getContext() instanceof MutableContextWrapper) {
        return ((MutableContextWrapper) this.getContext()).getBaseContext();
    }
    return this.getContext();
}
 
Example #19
Source Project: mobile-sdk-android   Author: appnexus   File: InstreamVideoView.java    License: Apache License 2.0 4 votes vote down vote up
InstreamVideoView(Context context, AttributeSet attrs, int defStyle) {
    super(new MutableContextWrapper(context), attrs, defStyle);
    setup(context);
}
 
Example #20
Source Project: mobile-sdk-android   Author: appnexus   File: AdWebView.java    License: Apache License 2.0 4 votes vote down vote up
protected Context getContextFromMutableContext() {
    if (this.getContext() instanceof MutableContextWrapper) {
        return ((MutableContextWrapper) this.getContext()).getBaseContext();
    }
    return this.getContext();
}