List of usage examples for android.widget FrameLayout getFocusedChild
public View getFocusedChild()
From source file:de.madvertise.android.sdk.MadvertiseMraidView.java
public MadvertiseMraidView(Context context) { super(context); setVerticalScrollBarEnabled(false);//w w w. java 2 s . c om setHorizontalScrollBarEnabled(false); setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY); setBackgroundColor(Color.TRANSPARENT); WebSettings settings = getSettings(); settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); settings.setJavaScriptEnabled(true); //settings.setPluginsEnabled(true); // Initialize the default expand properties. DisplayMetrics metrics = getContext().getResources().getDisplayMetrics(); mExpandProperties = new ExpandProperties(metrics.widthPixels, metrics.heightPixels); MadvertiseUtil.logMessage(null, Log.INFO, "Setting default expandProperties : " + mExpandProperties.toJson().toString()); // This bridge stays available until this view is destroyed, hence no // reloading when displaying new ads is necessary. addJavascriptInterface(mBridge, "mraid_bridge"); setWebViewClient(new WebViewClient() { private boolean mError = false; @Override public boolean shouldOverrideUrlLoading(WebView view, final String url) { post(new Runnable() { @Override public void run() { if (mListener != null) { mListener.onAdClicked(); } final Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url), getContext().getApplicationContext(), MadvertiseActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getContext().startActivity(intent); } }); return true; } @Override public void onPageFinished(WebView view, String url) { super.onPageFinished(view, url); if (!url.endsWith("mraid.js") && !mError) { MadvertiseUtil.logMessage(null, Log.DEBUG, "Setting mraid to default"); checkReady(); // Close button in default size for interstitial ads if (mPlacementType == MadvertiseUtil.PLACEMENT_TYPE_INTERSTITIAL) { mCloseButton = addCloseButtonToViewGroup(((ViewGroup) getParent())); mCloseButton.setImageResource(android.R.drawable.ic_menu_close_clear_cancel); } } } @Override public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { super.onReceivedError(view, errorCode, description, failingUrl); mError = true; } }); // Comment this in to enable video tag-capability. this.setWebChromeClient(new WebChromeClient() { @Override public void onShowCustomView(View view, CustomViewCallback callback) { MadvertiseUtil.logMessage(null, Log.INFO, "showing VideoView"); super.onShowCustomView(view, callback); if (view instanceof FrameLayout) { FrameLayout frame = (FrameLayout) view; if (frame.getFocusedChild() instanceof VideoView) { mVideo = (VideoView) ((FrameLayout) view).getFocusedChild(); frame.removeView(mVideo); ((ViewGroup) getParent()).addView(mVideo); // Will also be called onError mVideo.setOnCompletionListener(new OnCompletionListener() { @Override public void onCompletion(MediaPlayer player) { player.stop(); } }); mVideo.setOnErrorListener(new OnErrorListener() { @Override public boolean onError(MediaPlayer mp, int what, int extra) { MadvertiseUtil.logMessage(null, Log.WARN, "Error while playing video"); if (mListener != null) { mListener.onError(new IOException("Error while playing video")); } // We return false in order to call // onCompletion() return false; } }); mVideo.start(); } } } @Override public void onHideCustomView() { if (mVideo != null) { ((ViewGroup) getParent()).removeView(mVideo); if (mVideo.isPlaying()) { mVideo.stopPlayback(); } } } }); }