| | |
| | | import android.app.Notification; |
| | | import android.app.NotificationManager; |
| | | import android.content.Intent; |
| | | import android.content.pm.ActivityInfo; |
| | | import android.content.res.Configuration; |
| | | import android.net.http.SslError; |
| | | import android.os.Bundle; |
| | | import android.support.annotation.NonNull; |
| | | import android.support.annotation.Nullable; |
| | |
| | | import android.view.View; |
| | | import android.view.View.OnClickListener; |
| | | import android.view.ViewGroup; |
| | | import android.view.WindowManager; |
| | | import android.webkit.ConsoleMessage; |
| | | import android.webkit.SslErrorHandler; |
| | | import android.webkit.WebChromeClient; |
| | | import android.webkit.WebResourceRequest; |
| | | import android.webkit.WebSettings; |
| | | import android.webkit.WebView; |
| | | import android.webkit.WebViewClient; |
| | | import android.widget.FrameLayout; |
| | | import android.widget.LinearLayout; |
| | | import android.widget.ProgressBar; |
| | | import android.widget.TextView; |
| | | |
| | | import com.lcjian.library.RetainViewFragment; |
| | | import com.tencent.smtt.export.external.interfaces.ConsoleMessage; |
| | | import com.tencent.smtt.export.external.interfaces.SslError; |
| | | import com.tencent.smtt.export.external.interfaces.SslErrorHandler; |
| | | import com.tencent.smtt.export.external.interfaces.WebResourceRequest; |
| | | import com.tencent.smtt.sdk.WebChromeClient; |
| | | import com.tencent.smtt.sdk.WebSettings; |
| | | import com.tencent.smtt.sdk.WebView; |
| | | import com.tencent.smtt.sdk.WebViewClient; |
| | | import com.tencent.smtt.export.external.interfaces.IX5WebChromeClient; |
| | | import com.umeng.analytics.MobclickAgent; |
| | | import com.weikou.beibeivideo.BeibeiVideoApplication; |
| | | import com.weikou.beibeivideo.R; |
| | |
| | | import com.weikou.beibeivideo.ui.login.LoginActivity; |
| | | import com.weikou.beibeivideo.util.BeibeiConstant; |
| | | import com.weikou.beibeivideo.util.ConfigUtil; |
| | | import com.weikou.beibeivideo.util.UserUtil; |
| | | import com.weikou.beibeivideo.util.ad.AdUtil; |
| | | import com.weikou.beibeivideo.util.browser.PPJavaInterface; |
| | | import com.weikou.beibeivideo.util.ui.IPageEventListener; |
| | | import com.weikou.beibeivideo.util.x5.X5WebView; |
| | | |
| | | public class PPTVPlayFragment extends RetainViewFragment implements OnClickListener { |
| | | private static int REQUEST_CODE_LOGIN = 1001; |
| | | private final static int REQUEST_CODE_LOGIN = 1001; |
| | | |
| | | private final static int REQUEST_CODE_VIP = 1002; |
| | | |
| | | |
| | | private final static String TAG = PPTVPlayFragment.class.getSimpleName(); |
| | | |
| | | private TextView tv_top_bar_left; |
| | | private X5WebView webview; |
| | | private android.webkit.WebView webview; |
| | | FrameLayout fl_ad; |
| | | FrameLayout fl_container; |
| | | |
| | | private boolean showAd = true; |
| | | |
| | | private void initX5WebView(View view) { |
| | | private void initWebView(View view) { |
| | | fl_ad = view.findViewById(R.id.fl_ad); |
| | | webview = view.findViewById(R.id.webview); |
| | | webview.setWebViewClient(new WebViewClient() { |
| | |
| | | @Override |
| | | public void onPageFinished(WebView webView, String s) { |
| | | super.onPageFinished(webView, s); |
| | | if (showAd) |
| | | playAd(); |
| | | else { |
| | | showAd = true; |
| | | adPlayFinish(); |
| | | } |
| | | } |
| | | |
| | | @Override |
| | |
| | | }); |
| | | |
| | | webview.setWebChromeClient(new WebChromeClient() { |
| | | |
| | | View myVideoView; |
| | | View myNormalView; |
| | | CustomViewCallback callback; |
| | | |
| | | @Override |
| | | public void onReceivedTitle(WebView view, String title) { |
| | |
| | | Log.i(TAG, consoleMessage.message()); |
| | | return super.onConsoleMessage(consoleMessage); |
| | | } |
| | | |
| | | /** |
| | | * 全屏播放配置 |
| | | */ |
| | | @Override |
| | | public void onShowCustomView(View view, |
| | | CustomViewCallback customViewCallback) { |
| | | View normalView = fl_container; |
| | | ViewGroup viewGroup = (ViewGroup) normalView.getParent(); |
| | | viewGroup.removeView(normalView); |
| | | viewGroup.addView(view); |
| | | myVideoView = view; |
| | | myNormalView = normalView; |
| | | callback = customViewCallback; |
| | | getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); |
| | | WindowManager.LayoutParams attrs = getActivity().getWindow().getAttributes(); |
| | | attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN; |
| | | getActivity().getWindow().setAttributes(attrs); |
| | | } |
| | | |
| | | @Override |
| | | public void onHideCustomView() { |
| | | if (callback != null) { |
| | | callback.onCustomViewHidden(); |
| | | callback = null; |
| | | } |
| | | if (myVideoView != null) { |
| | | ViewGroup viewGroup = (ViewGroup) myVideoView.getParent(); |
| | | viewGroup.removeView(myVideoView); |
| | | viewGroup.addView(myNormalView); |
| | | } |
| | | getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
| | | WindowManager.LayoutParams attrs = getActivity().getWindow().getAttributes(); |
| | | attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN; |
| | | getActivity().getWindow().setAttributes(attrs); |
| | | } |
| | | }); |
| | | WebSettings webSetting = webview.getSettings(); |
| | | webSetting.setJavaScriptEnabled(true); |
| | |
| | | webview.addJavascriptInterface(new PPJavaInterface(BeibeiVideoApplication.application, new PPJavaInterface.IEventListener() { |
| | | @Override |
| | | public void onLogin() { |
| | | webview.post(new Runnable() { |
| | | if (getActivity() != null) |
| | | getActivity().runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | Intent intent = new Intent(getContext(), LoginActivity.class); |
| | |
| | | @Override |
| | | public void onTryPlayFinish() { |
| | | Log.i(TAG, "onTryPlayFinish"); |
| | | webview.post(new Runnable() { |
| | | if (getActivity() != null) |
| | | getActivity().runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
| | | if (vipDialog != null && !vipDialog.isShowing()) |
| | | vipDialog.show(); |
| | | } |
| | |
| | | |
| | | @Override |
| | | public void onPlayFinish() { |
| | | webview.post(new Runnable() { |
| | | if (getActivity() != null) |
| | | getActivity().runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | new AlertDialog.Builder(getContext()).setMessage("playFinish方法被调用").create().show(); |
| | | } |
| | | }); |
| | | |
| | |
| | | @Override |
| | | public void onCreateView(View contentView, Bundle savedInstanceState) { |
| | | initView(contentView); |
| | | String url = "http://vip.pptv.com/activity/2021/pg_bwysdqmovie?cid=32159127&vid=32159127&programtype=3"; |
| | | String url = "http://vip.pptv.com/activity/2021/pg_bwysdqmovie?cid=32159127&vid=32159127&programtype=2"; |
| | | url = "https://acmd.api.pptv.com/2021/bwysdqmovie_thrid_h5.html?cid=32159127&vid=32159127&programtype=3"; |
| | | webview.loadUrl(url); |
| | | } |
| | | |
| | | |
| | | private void initView(View view) { |
| | | initX5WebView(view); |
| | | initWebView(view); |
| | | tv_top_bar_left = view.findViewById(R.id.tv_top_bar_left); |
| | | tv_top_bar_left.setOnClickListener(this); |
| | | fl_container = view.findViewById(R.id.fl_container); |
| | | vipDialog = new VIPDialog.Builder(getActivity()).setCloseListener(new OnClickListener() { |
| | | @Override |
| | | public void onClick(View v) { |
| | |
| | | @Override |
| | | public void onClick(View v) { |
| | | vipDialog.dismiss(); |
| | | startActivity(new Intent(BeibeiVideoApplication.application, BrowserActivity.class).putExtra("url", ConfigUtil.getVipLink(BeibeiVideoApplication.application))); |
| | | startActivityForResult(new Intent(BeibeiVideoApplication.application, BrowserActivity.class).putExtra("url", ConfigUtil.getVipLink(BeibeiVideoApplication.application)), REQUEST_CODE_VIP); |
| | | } |
| | | }).create(); |
| | | |
| | | //测试 |
| | | // fl_container.postDelayed(new Runnable() { |
| | | // @Override |
| | | // public void run() { |
| | | // getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); |
| | | // if (!vipDialog.isShowing()) |
| | | // vipDialog.show(); |
| | | // } |
| | | // }, 10000); |
| | | } |
| | | |
| | | Dialog vipDialog; |
| | |
| | | Log.d(TAG, "onActivityResdult:" + requestCode); |
| | | //从登录返回来的 |
| | | if (requestCode == REQUEST_CODE_LOGIN && resultCode == Activity.RESULT_OK) { |
| | | |
| | | switch (requestCode) { |
| | | case REQUEST_CODE_VIP: |
| | | |
| | | break; |
| | | |
| | | case REQUEST_CODE_LOGIN: { |
| | | Log.d(TAG, "登录成功"); |
| | | showAd = false; |
| | | webview.reload(); |
| | | } |
| | | break; |
| | | |
| | | } |
| | | |
| | | |
| | | } |
| | | super.onActivityResult(requestCode, resultCode, data); |
| | | } |
| | | |
| | | private synchronized void playAd() { |
| | | //VIP永久免广告 |
| | | if (UserUtil.isVIP(getContext())) { |
| | | adPlayFinish(); |
| | | return; |
| | | } |
| | | |
| | | fl_ad.setVisibility(View.VISIBLE); |
| | | mVideoDetailVideoAdFragment = new PlayVideoPreADFragment(); |
| | | mVideoDetailVideoAdFragment.setPageEventListener(new IPageEventListener() { |
| | |
| | | mVideoDetailVideoAdFragment.loadVideoAD(new PlayVideoPreADFragment.IVideoAdListener() { |
| | | @Override |
| | | public void finishPlay() { |
| | | if (mVideoDetailVideoAdFragment.isAdded()) |
| | | getChildFragmentManager().beginTransaction().remove(mVideoDetailVideoAdFragment).commitAllowingStateLoss(); |
| | | fl_ad.setVisibility(View.GONE); |
| | | adPlayFinish(); |
| | |
| | | @Override |
| | | public void noAd() { |
| | | fl_ad.setVisibility(View.GONE); |
| | | if (mVideoDetailVideoAdFragment.isAdded()) |
| | | getChildFragmentManager().beginTransaction().remove(mVideoDetailVideoAdFragment).commitAllowingStateLoss(); |
| | | adPlayFinish(); |
| | | } |
| | |
| | | |
| | | |
| | | private void adPlayFinish() { |
| | | if (webview != null) |
| | | webview.loadUrl("javascript:adPlayFinish()"); |
| | | } |
| | | } |