package com.mibao.jytparent.all.views; import java.util.List; import com.mibao.jytparent.R; import android.annotation.SuppressLint; import android.app.Activity; import android.app.ProgressDialog; import android.content.Intent; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.net.Uri; import android.os.Bundle; import android.os.Handler; import android.view.View; import android.webkit.WebChromeClient; import android.webkit.WebSettings; import android.webkit.WebSettings.PluginState; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.FrameLayout; public class ActFlashPlay extends Activity { private FrameLayout mFullscreenContainer; private FrameLayout mContentView; private View mCustomView = null; private WebView mWebView; private String videoid = ""; ProgressDialog mProgressDialog; private Handler mHandler = new Handler(); @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.youku); Intent intent = getIntent(); videoid = intent.getExtras().getString("recordurl"); String s = "
swf" + ""; initViews(); initWebView(); if (getPhoneAndroidSDK() >= 14) {// 4.0 需打开硬件加速 getWindow().setFlags(0x1000000, 0x1000000); } try { Thread.sleep(1000);// 主线程暂停下,否则容易白屏,原因未知 } catch (InterruptedException e) { // TODO 自动生成的 catch 块 e.printStackTrace(); } mProgressDialog = ProgressDialog.show(this, "请稍等...", "加载flash中...", true); mWebView.setWebChromeClient(new WebChromeClient() { @Override public void onProgressChanged(WebView view, int newProgress) { // TODO Auto-generated method stub super.onProgressChanged(view, newProgress); System.out.println("newProgress:" + String.valueOf(newProgress)); if (newProgress == 100) { new Handler().postDelayed(new Runnable() { @Override public void run() { // TODO Auto-generated method stub mProgressDialog.dismiss(); } }, 1000); } } }); // mWebView.loadUrl("http://player.youku.com/player.php/sid/XNzYxNzQ1MDAw/v.swf/"); if (checkinstallornotadobeflashapk()) { mWebView.loadData(s, "text/html; charset=UTF-8", null); } else { installadobeapk(); } // mWebView.loadUrl("file:///android_asset/1234.html"); } private void initViews() { mFullscreenContainer = (FrameLayout) findViewById(R.id.fullscreen_custom_content); mContentView = (FrameLayout) findViewById(R.id.main_content); mWebView = (WebView) findViewById(R.id.webview_player); } private void initWebView() { WebSettings settings = mWebView.getSettings(); settings.setJavaScriptEnabled(true); settings.setJavaScriptCanOpenWindowsAutomatically(true); settings.setPluginState(PluginState.ON); // settings.setPluginsEnabled(true); settings.setAllowFileAccess(true); settings.setLoadWithOverviewMode(true); mWebView.setWebChromeClient(new MyWebChromeClient()); mWebView.setWebViewClient(new MyWebViewClient()); } class MyWebChromeClient extends WebChromeClient { private CustomViewCallback mCustomViewCallback; private int mOriginalOrientation = 1; @Override public void onShowCustomView(View view, CustomViewCallback callback) { // TODO Auto-generated method stub onShowCustomView(view, mOriginalOrientation, callback); super.onShowCustomView(view, callback); } public void onShowCustomView(View view, int requestedOrientation, WebChromeClient.CustomViewCallback callback) { if (mCustomView != null) { callback.onCustomViewHidden(); return; } if (getPhoneAndroidSDK() >= 14) { mFullscreenContainer.addView(view); mCustomView = view; mCustomViewCallback = callback; mOriginalOrientation = getRequestedOrientation(); mContentView.setVisibility(View.INVISIBLE); mFullscreenContainer.setVisibility(View.VISIBLE); mFullscreenContainer.bringToFront(); setRequestedOrientation(mOriginalOrientation); } } public void onHideCustomView() { mContentView.setVisibility(View.VISIBLE); if (mCustomView == null) { return; } mCustomView.setVisibility(View.GONE); mFullscreenContainer.removeView(mCustomView); mCustomView = null; mFullscreenContainer.setVisibility(View.GONE); try { mCustomViewCallback.onCustomViewHidden(); } catch (Exception e) { } // Show the content view. setRequestedOrientation(mOriginalOrientation); } } class MyWebViewClient extends WebViewClient { @Override public boolean shouldOverrideUrlLoading(WebView view, String url) { // TODO Auto-generated method stub view.loadUrl(url); return super.shouldOverrideUrlLoading(view, url); } } public static int getPhoneAndroidSDK() { // TODO Auto-generated method stub int version = 0; try { version = Integer.valueOf(android.os.Build.VERSION.SDK); } catch (NumberFormatException e) { e.printStackTrace(); } return version; } // 检查机子是否安装的有Adobe Flash相关APK private boolean checkinstallornotadobeflashapk() { PackageManager pm = getPackageManager(); List infoList = pm .getInstalledPackages(PackageManager.GET_SERVICES); for (PackageInfo info : infoList) { if ("com.adobe.flashplayer".equals(info.packageName)) { return true; } } return false; } // 安装Adobe Flash APK @SuppressLint("JavascriptInterface") private void installadobeapk() { mWebView.addJavascriptInterface(new AndroidBridge(), "android"); mWebView.loadUrl("http://www.liqucn.com/rj/30347.shtml"); } private class AndroidBridge { public void goMarket() { mHandler.post(new Runnable() { public void run() { Intent installIntent = new Intent( "android.intent.action.VIEW"); installIntent.setData(Uri .parse("market://details?id=com.adobe.flashplayer")); startActivity(installIntent); } }); } } @Override public void onPause() {// 继承自Activity super.onPause(); mWebView.onPause(); } @Override public void onResume() {// 继承自Activity super.onResume(); mWebView.onResume(); } }