File was renamed from BuWanVideo/src/com/weikou/beibeivideo/ui/mine/FXBrowserActivity.java |
| | |
| | | package com.weikou.beibeivideo.ui.mine; |
| | | package com.weikou.beibeivideo.ui.video; |
| | | |
| | | import android.app.Instrumentation; |
| | | import android.app.Notification; |
| | | import android.app.NotificationChannel; |
| | | import android.app.NotificationManager; |
| | | import android.content.Intent; |
| | | import android.content.pm.ActivityInfo; |
| | | import android.content.res.Configuration; |
| | | import android.graphics.Bitmap; |
| | | import android.graphics.BitmapFactory; |
| | | import android.graphics.Color; |
| | | import android.graphics.PixelFormat; |
| | |
| | | import android.view.WindowManager; |
| | | import android.webkit.ConsoleMessage; |
| | | import android.webkit.DownloadListener; |
| | | import android.webkit.JavascriptInterface; |
| | | 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.Toast; |
| | | |
| | | import com.lcjian.library.util.ManifestDataUtil; |
| | | import com.tencent.smtt.export.external.interfaces.IX5WebChromeClient; |
| | | import com.lcjian.library.util.common.StringUtils; |
| | | import com.umeng.analytics.MobclickAgent; |
| | | import com.weikou.beibeivideo.R; |
| | | import com.weikou.beibeivideo.ui.BaseActivity; |
| | | import com.weikou.beibeivideo.ui.media.VideoDetailActivity; |
| | | import com.weikou.beibeivideo.ui.media.VideoDetailActivity2; |
| | | import com.weikou.beibeivideo.util.browser.BWJavaInterface; |
| | | import com.weikou.beibeivideo.util.downutil.DownFiles; |
| | | import com.weikou.beibeivideo.util.downutil.DownFiles.IProgress; |
| | | import com.weikou.beibeivideo.widget.CustomWebView; |
| | | import com.yeshi.video.player.util.PlayerFullScreenUtil; |
| | | |
| | | public class FXBrowserActivity extends BaseActivity implements OnClickListener { |
| | | public class VideoPlayerBrowserActivity extends BaseActivity implements OnClickListener { |
| | | |
| | | private TextView tv_top_bar_left; |
| | | private TextView tv_url; |
| | | private TextView tv_title; |
| | | private TextView tv_right; |
| | | private CustomWebView webview; |
| | | private WebView webview; |
| | | private FrameLayout fl_webview; |
| | | ProgressBar progressBar; |
| | | |
| | | private final String TAG = "FXBrowserActivity"; |
| | | |
| | | private Runnable playerJSRunnable = null; |
| | | |
| | | @Override |
| | | protected void onCreate(Bundle savedInstanceState) { |
| | |
| | | |
| | | fl_webview = findViewById(R.id.fl_webview); |
| | | tv_top_bar_left.setOnClickListener(this); |
| | | webview = new CustomWebView(FXBrowserActivity.this); |
| | | fl_webview.addView(webview, new FrameLayout.LayoutParams( |
| | | FrameLayout.LayoutParams.MATCH_PARENT, |
| | | FrameLayout.LayoutParams.MATCH_PARENT)); |
| | | webview = findViewById(R.id.webView); |
| | | WebSettings webSettings = webview.getSettings(); |
| | | webSettings.setJavaScriptEnabled(true); |
| | | webSettings.setDomStorageEnabled(true); |
| | | webSettings.setPluginState(WebSettings.PluginState.ON); |
| | | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { |
| | | webSettings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW); |
| | | } |
| | | |
| | | webview.addJavascriptInterface(new YeshiPlayerJavascriptInterface(), "yeshiPlayer"); |
| | | |
| | | webview.setDrawingCacheBackgroundColor(0x00000000); |
| | | webview.setFocusableInTouchMode(true); |
| | |
| | | webview.setWebViewClient(new WebViewClient() { |
| | | @Override |
| | | public boolean shouldOverrideUrlLoading(WebView view, String url) { |
| | | Log.i(TAG, "shouldOverrideUrlLoading:" + url); |
| | | return super.shouldOverrideUrlLoading(view, url); |
| | | } |
| | | |
| | | @Override |
| | | public boolean shouldOverrideUrlLoading(WebView view, WebResourceRequest request) { |
| | | String url = request.getUrl().toString(); |
| | | Log.i(TAG, "shouldOverrideUrlLoading:" + url); |
| | | if (url != null && url.startsWith("buwanprotocol://")) { |
| | | String murl = url.split("buwanprotocol://")[1]; |
| | | String[] params = murl.split("#"); |
| | | if (params[0].equalsIgnoreCase("playvideo")) { |
| | | Intent intent = new Intent(FXBrowserActivity.this, VideoDetailActivity2.class); |
| | | Intent intent = new Intent(VideoPlayerBrowserActivity.this, VideoDetailActivity2.class); |
| | | Bundle bundle = new Bundle(); |
| | | bundle.putString("Id", params[1]); |
| | | bundle.putString("ResourceId", params[2]); |
| | |
| | | return true; |
| | | } else if (!url.startsWith("http")) |
| | | return true; |
| | | return super.shouldOverrideUrlLoading(view, url); |
| | | |
| | | return super.shouldOverrideUrlLoading(view, request); |
| | | } |
| | | |
| | | @Override |
| | | public void onPageStarted(WebView view, String url, Bitmap favicon) { |
| | | Log.i(TAG, "onPageStarted:" + url); |
| | | super.onPageStarted(view, url, favicon); |
| | | } |
| | | |
| | | @Override |
| | | public void onPageFinished(WebView webView, String s) { |
| | | super.onPageFinished(webView, s); |
| | | |
| | | webView.postDelayed(new Runnable() { |
| | | Log.i(TAG, "onPageFinished:" + s); |
| | | if (playerJSRunnable != null) |
| | | webview.removeCallbacks(playerJSRunnable); |
| | | playerJSRunnable = new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | String js = "setInterval(function(){ $('.full-btn').click(function(){"; |
| | | js += "var el= document.getElementById('j-player-layout');"; |
| | | js += "if (el.requestFullscreen) {\n" + |
| | | "el.requestFullscreen();\n" + |
| | | "} else if (el.msRequestFullscreen) {\n" + |
| | | "el.msRequestFullscreen();\n" + |
| | | "} else if (el.mozRequestFullScreen) {\n" + |
| | | "el.mozRequestFullScreen();\n" + |
| | | "} else if (el.webkitRequestFullscreen) {\n" + |
| | | "el.webkitRequestFullscreen();\n" + |
| | | "}"; |
| | | js += "});},2000);"; |
| | | if (webView != null) |
| | | webView.loadUrl("javascript:" + js); |
| | | if (webview == null || webView == null) |
| | | return; |
| | | String js = null; |
| | | String url = webview.getUrl(); |
| | | if (webView != null && !StringUtils.isEmpty(url)) { |
| | | if (url.contains(".fun.tv")) {//风行 |
| | | js = PlayerFullScreenUtil.getFunShionFullScreenJS(getApplicationContext()); |
| | | } else if (url.contains("m.acfun.cn")) {//Acfun |
| | | js = PlayerFullScreenUtil.getAcfunFullScreenJS(getApplicationContext()); |
| | | } |
| | | if (!StringUtils.isEmpty(js)) |
| | | webView.loadUrl("javascript:" + js); |
| | | } |
| | | } |
| | | }, 1000); |
| | | |
| | | }; |
| | | if (playerJSRunnable != null) |
| | | webview.postDelayed(playerJSRunnable, 1000); |
| | | } |
| | | |
| | | @Override |
| | |
| | | progressBar.setMax(100); |
| | | progressBar.setProgressDrawable(this.getResources() |
| | | .getDrawable(R.drawable.color_progressbar)); |
| | | loadHander.sendEmptyMessage(0); |
| | | // loadHander.sendEmptyMessage(0); |
| | | String url = getIntent().getStringExtra("url"); |
| | | webview.loadUrl(url); |
| | | tv_url.setText(url); |
| | | } |
| | | |
| | | Handler loadHander = new Handler() { |
| | | @Override |
| | | public void handleMessage(Message msg) { |
| | | super.handleMessage(msg); |
| | | String url = getIntent().getStringExtra("url"); |
| | | webview.loadUrl(url); |
| | | tv_url.setText(url); |
| | | } |
| | | }; |
| | | |
| | | // 文件下载监听 |
| | | |
| | |
| | | Log.i("DownFiles", "getProgress下载进度:" + p); |
| | | } else { |
| | | if (manager == null) { |
| | | Toast.makeText(FXBrowserActivity.this, "文件已经开始下载", |
| | | Toast.makeText(VideoPlayerBrowserActivity.this, "文件已经开始下载", |
| | | Toast.LENGTH_SHORT).show(); |
| | | manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); |
| | | String id = "UMENG_CHANNEL"; |
| | | String description = ManifestDataUtil.getAppMetaData(FXBrowserActivity.this, id); |
| | | String description = ManifestDataUtil.getAppMetaData(VideoPlayerBrowserActivity.this, id); |
| | | if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
| | | int importance = NotificationManager.IMPORTANCE_HIGH; |
| | | NotificationChannel mChannel = new NotificationChannel(id, "123", importance); |
| | |
| | | mChannel.enableVibration(true); |
| | | mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400}); |
| | | manager.createNotificationChannel(mChannel); |
| | | oBuilder = new Notification.Builder(FXBrowserActivity.this, id); |
| | | oBuilder = new Notification.Builder(VideoPlayerBrowserActivity.this, id); |
| | | oBuilder.setContentTitle("影视大全") |
| | | .setSmallIcon(R.drawable.ic_launcher) |
| | | .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)) |
| | |
| | | .setAutoCancel(true) |
| | | .build(); |
| | | } else { |
| | | builder = new NotificationCompat.Builder(FXBrowserActivity.this); |
| | | builder = new NotificationCompat.Builder(VideoPlayerBrowserActivity.this); |
| | | builder.setContentTitle("影视大全") |
| | | .setContentText("热门应用下载") |
| | | .setSmallIcon(R.drawable.ic_launcher) |
| | |
| | | |
| | | @Override |
| | | protected void onDestroy() { |
| | | if (playerJSRunnable != null) |
| | | webview.removeCallbacks(playerJSRunnable); |
| | | if (webview != null) { |
| | | webview.loadDataWithBaseURL(null, "", "text/html", "utf-8", null); |
| | | webview.clearHistory(); |
| | |
| | | webview.destroy(); |
| | | webview = null; |
| | | } |
| | | |
| | | |
| | | super.onDestroy(); |
| | | } |
| | | |
| | |
| | | findViewById(R.id.top).setVisibility(View.VISIBLE); |
| | | } |
| | | } |
| | | |
| | | class YeshiPlayerJavascriptInterface { |
| | | |
| | | @JavascriptInterface |
| | | public boolean isFullScreen() { |
| | | if ((VideoPlayerBrowserActivity.this.getWindow().getAttributes().flags & WindowManager.LayoutParams.FLAG_FULLSCREEN) |
| | | == WindowManager.LayoutParams.FLAG_FULLSCREEN) { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | @JavascriptInterface |
| | | public void setPortrait() { |
| | | if (isFullScreen()) { |
| | | //模拟返回按钮 |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | Instrumentation inst = new Instrumentation(); |
| | | inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK); |
| | | } |
| | | }).start(); |
| | | |
| | | } |
| | | } |
| | | |
| | | } |
| | | } |