@author cenxiaozhong
| 35 | * @author cenxiaozhong |
| 36 | */ |
| 37 | public class VideoImpl implements IVideo, EventInterceptor { |
| 38 | |
| 39 | private Activity mActivity; |
| 40 | private WebView mWebView; |
| 41 | private static final String TAG = VideoImpl.class.getSimpleName(); |
| 42 | private Set<Pair<Integer, Integer>> mFlags = null; |
| 43 | private View mMoiveView = null; |
| 44 | private ViewGroup mMoiveParentView = null; |
| 45 | private WebChromeClient.CustomViewCallback mCallback; |
| 46 | private int mOriginalOrientation; |
| 47 | |
| 48 | public VideoImpl(Activity mActivity, WebView webView) { |
| 49 | this.mActivity = mActivity; |
| 50 | this.mWebView = webView; |
| 51 | mFlags = new HashSet<>(); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) { |
| 56 | Activity mActivity; |
| 57 | if ((mActivity = this.mActivity) == null || mActivity.isFinishing()) { |
| 58 | return; |
| 59 | } |
| 60 | mOriginalOrientation = mActivity.getRequestedOrientation(); |
| 61 | mActivity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); |
| 62 | Window mWindow = mActivity.getWindow(); |
| 63 | Pair<Integer, Integer> mPair = null; |
| 64 | // 保存当前屏幕的状态 |
| 65 | if ((mWindow.getAttributes().flags & WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) == 0) { |
| 66 | mPair = new Pair<>(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, 0); |
| 67 | mWindow.setFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON, |
| 68 | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); |
| 69 | mFlags.add(mPair); |
| 70 | } |
| 71 | if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) |
| 72 | && (mWindow.getAttributes().flags |
| 73 | & WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED) == 0) { |
| 74 | mPair = new Pair<>(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, 0); |
| 75 | mWindow.setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED, |
| 76 | WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED); |
| 77 | mFlags.add(mPair); |
| 78 | } |
| 79 | if (mMoiveView != null) { |
| 80 | callback.onCustomViewHidden(); |
| 81 | return; |
| 82 | } |
| 83 | if (mWebView != null) { |
| 84 | mWebView.setVisibility(View.GONE); |
| 85 | } |
| 86 | if (mMoiveParentView == null) { |
| 87 | FrameLayout mContentView = mActivity.findViewById(android.R.id.content); |
| 88 | mMoiveParentView = new FrameLayout(mActivity); |
| 89 | mMoiveParentView.setBackgroundColor(Color.BLACK); |
| 90 | mContentView.addView(mMoiveParentView); |
| 91 | } |
| 92 | this.mCallback = callback; |
| 93 | mMoiveParentView.addView(this.mMoiveView = view); |
| 94 | mMoiveParentView.setVisibility(View.VISIBLE); |
nothing calls this directly
no outgoing calls
no test coverage detected