我在左侧有 ListView 的布局,在其他区域有 Webview。
当我想在 WebView 中播放视频时,视频在右侧被剪切。
安卓版本:4.0.4
布局xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/main_layout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<ListView
android:layout_width="150dp"
android:layout_height="match_parent"
android:background="#334455">
</ListView>
<org.apache.cordova.CordovaWebView
android:id="@+id/reading_pane_rss_erss_erss_web_view_container"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
我在左侧有 ListView 的布局,在其他区域有 Webview。
当我想在 WebView 中播放视频时,视频在右侧被剪切。
安卓版本:4.0.4 活动代码:
public class VideoActivityNew extends Activity implements CordovaInterface{
private CordovaWebView mWebView;
private FrameLayout mCustomViewContainer;
private View mCustomView;
private CustomViewCallback mCustomViewCallback;
private FrameLayout mFullscreenContainer;
protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS =
new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT);
private View mVideoProgressView = null;
private ViewFlipper mViewFlipper;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
mCustomViewContainer = new FrameLayout(getApplicationContext());
mCustomViewContainer.setVisibility(View.GONE);
mWebView = new CordovaWebView(this);
mWebView = (CordovaWebView) findViewById(R.id.reading_pane_rss_erss_erss_web_view_container);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setFixedFontFamily("DroidSansHebrew.ttf");
mWebView.getSettings().setPluginState(PluginState.ON);
mWebView.getSettings().setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NORMAL);
mWebView.getSettings().setSupportZoom(true);
mWebView.setInitialScale(1);
mWebView.getSettings().setUseWideViewPort(true);
mWebView.getSettings().setJavaScriptCanOpenWindowsAutomatically(false);
mWebView.setScrollbarFadingEnabled(true);
mWebView.setScrollBarStyle(View.SCROLLBARS_OUTSIDE_OVERLAY);
mWebView.getSettings().setBuiltInZoomControls(true);
if (Build.VERSION.SDK_INT >= 11)
mWebView.getSettings().setDisplayZoomControls(false);
mWebView.setWebChromeClient(new CordovaChromeClient((CordovaInterface) this) {
FrameLayout.LayoutParams COVER_SCREEN_GRAVITY_CENTER = new
FrameLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT, Gravity.CENTER);
@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
super.onShowCustomView(view, callback);
showCustomView(view, callback);
}
@Override
public void onHideCustomView() {
hideCustomView();
}
@Override
public View getVideoLoadingProgressView() {
if (mVideoProgressView == null) {
LayoutInflater inflater = LayoutInflater.from(VideoActivityNew.this);
mVideoProgressView = inflater.inflate(R.layout.video_loading_progress, null);
}
return mVideoProgressView;
}
});
mWebView.setWebViewClient(new CordovaWebViewClient(this, mWebView)
{
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.startsWith("about:blank")) {
return true;
}
mWebView.loadUrl(url);
return true;
}
public void onPageFinished(WebView view, String url) {
mWebView.scrollTo(0, 0);
// mWebProgressBar.setVisibility(View.INVISIBLE);
}
});
String data = "<html dir=\"ltr\">\n" +
"<head>\n" +
"</head>\n" +
"<body>\n" +
"<div class=rumbleitem><font></font></div>\n" +
"<div class=rumbleitem><font><script type=\"text/javascript\" src=\"http://admin.brightcove.com/js/BrightcoveExperiences.js\"></script>\n" +
"<iframe class=\"youtube\" id=\"ytplayer\" type=\"text/html\" width=\"588\" height=\"392\"src=\"http://www.youtube.com/embed/dCzI521sgqE?fs=1&wmode=opaque&showinfo=0\" frameborder=\"0\"></iframe>\n" +
"<div class=\"dek\">\n" +
"<p style1=\"font-family: tahoma, arial, helvetica, sans-serif; font-size: 12px;\">Democrats and Republicans can agree on one thing: Kevin Spacey. The White House Correspondents' Dinner began with a spoof of the hit series 'House of Cards,’ as Spacey reprised his role—while politicians from both sides of the aisle made cameos. As Spacey's Frank Underwood says, 'That's what real bipartisanship looks like.'<br>\n" +
"</p>\n" +
"<p style1=\"font-family: tahoma, arial, helvetica, sans-serif; font-size: 12px;\"></p>\n" +
"</div>\n" +
"</font>\n" +
"</div>\n" +
"</body>\n" +
"</html>";
mWebView.loadData(data, "text/html", "utf-8");
}
private void showCustomView(View view, WebChromeClient.CustomViewCallback callback) {
if (mCustomView != null) {
callback.onCustomViewHidden();
return;
}
VideoActivityNew.this.getWindow().getDecorView();
FrameLayout decor = (FrameLayout) getWindow().getDecorView();
mFullscreenContainer = new FullscreenHolder(VideoActivityNew.this);
mFullscreenContainer.addView(view, COVER_SCREEN_PARAMS);
decor.addView(mFullscreenContainer, COVER_SCREEN_PARAMS);
mCustomView = view;
setStatusBarVisibility(false);
mCustomViewCallback = callback;
}
private void hideCustomView() {
if (mCustomView == null)
return;
setStatusBarVisibility(true);
FrameLayout decor = (FrameLayout) getWindow().getDecorView();
decor.removeView(mFullscreenContainer);
mFullscreenContainer = null;
mCustomView = null;
mCustomViewCallback.onCustomViewHidden();
}
@Override
public void cancelLoadUrl() {
// TODO Auto-generated method stub
}
@Override
public Activity getActivity() {
// TODO Auto-generated method stub
return this;
}
@Override
public Context getContext() {
// TODO Auto-generated method stub
return null;
}
@Override
public Object onMessage(String arg0, Object arg1) {
// TODO Auto-generated method stub
return null;
}
@Override
public void setActivityResultCallback(IPlugin arg0) {
// TODO Auto-generated method stub
}
@Override
public void startActivityForResult(IPlugin arg0, Intent arg1, int arg2) {
// TODO Auto-generated method stub
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
if (mCustomView != null) hideCustomView();
return true;
}
return super.onKeyDown(keyCode, event);
}
static class FullscreenHolder extends FrameLayout {
public FullscreenHolder(Context ctx) {
super(ctx);
setBackgroundColor(ctx.getResources().getColor(android.R.color.black));
}
@Override
public boolean onTouchEvent(MotionEvent evt) {
return true;
}
}
private void setStatusBarVisibility(boolean visible) {
int flag = visible ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setFlags(flag, WindowManager.LayoutParams.FLAG_FULLSCREEN);
}
}