package com.weikou.beibeivideo.ui.media;
|
|
import android.app.Notification;
|
import android.app.NotificationChannel;
|
import android.app.NotificationManager;
|
import android.content.Context;
|
import android.content.Intent;
|
import android.graphics.BitmapFactory;
|
import android.graphics.Color;
|
import android.net.Uri;
|
import android.os.Build;
|
import android.os.Bundle;
|
import android.os.Handler;
|
import android.os.Message;
|
import androidx.core.app.NotificationCompat;
|
import android.util.Log;
|
import android.view.View;
|
import android.view.View.OnClickListener;
|
import android.widget.FrameLayout;
|
import android.widget.Toast;
|
|
import com.lcjian.library.RetainViewFragment;
|
import com.lcjian.library.util.ManifestDataUtil;
|
import com.tencent.smtt.export.external.TbsCoreSettings;
|
import com.tencent.smtt.export.external.interfaces.SslError;
|
import com.tencent.smtt.export.external.interfaces.SslErrorHandler;
|
import com.tencent.smtt.sdk.QbSdk;
|
import com.umeng.analytics.MobclickAgent;
|
import com.weikou.beibeivideo.entity.AccumulateRule;
|
import com.weikou.beibeivideo.entity.PlayUrl;
|
import com.weikou.beibeivideo.entity.video.ChangeVideoEvent;
|
import com.weikou.beibeivideo.util.downutil.DownFiles;
|
import com.weikou.beibeivideo.util.downutil.DownFiles.IProgress;
|
import com.weikou.beibeivideo.util.x5.X5WebView;
|
import com.weikou.beibeivideo.R;
|
|
import org.greenrobot.eventbus.EventBus;
|
import org.greenrobot.eventbus.Subscribe;
|
|
import java.util.HashMap;
|
|
/**
|
* 网页加载页面
|
*
|
* @author Administrator
|
*/
|
public class IQYVideoFragment extends RetainViewFragment implements
|
OnClickListener {
|
private X5WebView webview;
|
private FrameLayout fl_webview;
|
|
@Override
|
public int getContentResource() {
|
return R.layout.fragment_iqiyi_video;
|
}
|
|
@Override
|
public void onCreateView(View contentView, Bundle savedInstanceState) {
|
fl_webview = contentView.findViewById(R.id.fl_webview);
|
contentView.findViewById(R.id.iv_back).setOnClickListener(this);
|
webview = new X5WebView(fl_webview.getContext());
|
webview.setDownloadListener(new com.tencent.smtt.sdk.DownloadListener() {
|
|
@Override
|
public void onDownloadStart(String arg0, String arg1, String arg2,
|
String arg3, long arg4) {
|
}
|
|
});
|
fl_webview.addView(webview, new FrameLayout.LayoutParams(
|
FrameLayout.LayoutParams.MATCH_PARENT,
|
FrameLayout.LayoutParams.MATCH_PARENT));
|
com.tencent.smtt.sdk.WebSettings webSettings = webview.getSettings();
|
webSettings.setJavaScriptEnabled(true);
|
webSettings.setDomStorageEnabled(true);
|
|
webview.setDownloadListener(new MyWebViewDownLoadListener());
|
webview.setWebViewClient(new com.tencent.smtt.sdk.WebViewClient() {
|
@Override
|
public boolean shouldOverrideUrlLoading(com.tencent.smtt.sdk.WebView view, String url) {
|
if (url != null && url.startsWith("weixin://")) {
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
|
startActivity(intent);
|
return true;
|
}
|
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(fl_webview.getContext(), VideoDetailActivity2.class);
|
Bundle bundle = new Bundle();
|
bundle.putString("Id", params[1]);
|
bundle.putString("ResourceId", params[2]);
|
bundle.putString("DetailId", params[3]);
|
bundle.putString("Share", "0");
|
bundle.putString("ThirdType", "0");
|
intent.putExtras(bundle);
|
startActivity(intent);
|
}
|
return true;
|
}
|
return super.shouldOverrideUrlLoading(view, url);
|
|
}
|
|
|
@Override
|
public void onPageFinished(com.tencent.smtt.sdk.WebView webView, String s) {
|
super.onPageFinished(webView, s);
|
VideoDetailActivity.hideImage();
|
}
|
|
@Override
|
public void onReceivedSslError(com.tencent.smtt.sdk.WebView webView, SslErrorHandler sslErrorHandler, SslError sslError) {
|
sslErrorHandler.proceed();
|
}
|
});
|
webview.setWebChromeClient(new com.tencent.smtt.sdk.WebChromeClient() {
|
|
@Override
|
public void onReceivedTitle(com.tencent.smtt.sdk.WebView view, String title) {
|
}
|
|
@Override
|
public void onProgressChanged(com.tencent.smtt.sdk.WebView webView, int i) {
|
super.onProgressChanged(webView, i);
|
}
|
});
|
PlayUrl playUrl = (PlayUrl) getArguments().getSerializable("playUrl");
|
if (playUrl != null) {
|
webview.loadUrl(playUrl.getUrl());
|
}
|
VideoDetailActivity.hideImage();
|
|
}
|
|
// 文件下载监听
|
|
private class MyWebViewDownLoadListener implements com.tencent.smtt.sdk.DownloadListener {
|
|
@Override
|
public void onDownloadStart(String url, String userAgent,
|
String contentDisposition, String mimetype, long contentLength) {
|
startDownLoadFile(url);
|
/*
|
* Uri uri = Uri.parse(url); Intent intent = new
|
* Intent(Intent.ACTION_VIEW, uri);
|
* startActivity(intent);
|
*/
|
}
|
}
|
|
private NotificationManager manager;
|
private Notification notif;
|
private Notification.Builder oBuilder;
|
private NotificationCompat.Builder builder;
|
int j = -1;
|
|
private void startDownLoadFile(String url) {
|
|
new DownFiles(fl_webview.getContext(), new IProgress() {
|
|
@Override
|
public void getProgress(int p) {
|
// stub
|
if (p > 99) {
|
handler.sendEmptyMessage(1);
|
Log.i("DownFiles", "getProgress下载进度:" + p);
|
} else {
|
if (manager == null) {
|
Toast.makeText(fl_webview.getContext(), "文件已经开始下载",
|
Toast.LENGTH_SHORT).show();
|
manager = (NotificationManager) (fl_webview.getContext().getSystemService(Context.NOTIFICATION_SERVICE));
|
String id = "UMENG_CHANNEL";
|
String description = ManifestDataUtil.getAppMetaData(fl_webview.getContext(), id);
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
int importance = NotificationManager.IMPORTANCE_HIGH;
|
NotificationChannel mChannel = new NotificationChannel(id, "123", importance);
|
mChannel.setDescription(description);
|
mChannel.enableLights(true);
|
mChannel.setLightColor(Color.RED);
|
mChannel.enableVibration(true);
|
mChannel.setVibrationPattern(new long[]{100, 200, 300, 400, 500, 400, 300, 200, 400});
|
manager.createNotificationChannel(mChannel);
|
oBuilder = new Notification.Builder(fl_webview.getContext(), id);
|
oBuilder.setContentTitle("影视大全")
|
.setSmallIcon(R.drawable.ic_launcher)
|
.setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher))
|
.setContentText("热门应用下载")
|
.setAutoCancel(true)
|
.build();
|
} else {
|
builder = new NotificationCompat.Builder(fl_webview.getContext());
|
builder.setContentTitle("影视大全")
|
.setContentText("热门应用下载")
|
.setSmallIcon(R.drawable.ic_launcher)
|
.setOngoing(true);//无效
|
}
|
}
|
|
Message msg = handler.obtainMessage();
|
if (j != p) {
|
msg.what = 0;
|
msg.arg1 = p;
|
handler.sendMessage(msg);
|
}
|
j = p;
|
}
|
}
|
}).execute(url);
|
}
|
|
private Handler handler = new Handler() {
|
@Override
|
public void handleMessage(Message msg) {
|
super.handleMessage(msg);
|
switch (msg.what) {
|
case 0:
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
oBuilder.setContentText(msg.arg1 + "%");
|
notif = oBuilder.build();
|
} else {
|
builder.setContentText(msg.arg1 + "%");
|
notif = builder.build();
|
}
|
manager.notify(0, notif);
|
break;
|
case 1:
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
oBuilder.setContentText("下载完成");
|
notif = oBuilder.build();
|
} else {
|
builder.setContentText("下载完成");
|
notif = builder.build();
|
}
|
manager.notify(0, notif);
|
j = 100;
|
manager.cancelAll();
|
break;
|
default:
|
break;
|
}
|
}
|
};
|
|
@Override
|
public void onResume() {
|
super.onResume();
|
webview.reload();
|
}
|
|
@Override
|
public void onPause() {
|
super.onPause();
|
}
|
|
@Override
|
public void onClick(View v) {
|
switch (v.getId()) {
|
case R.id.iv_back: {
|
EventBus.getDefault().post(new AccumulateRule());// 播放界面返回替代使用AccumulateRule
|
// class
|
}
|
default:
|
break;
|
}
|
}
|
|
@Subscribe
|
public void onEventMainThread(ChangeVideoEvent changeVideoEvent) {
|
if ("VideoPlayerFragment".equals(changeVideoEvent.getTag())) {
|
changeVideoEvent.setTag("VideoDetailActivity");
|
EventBus.getDefault().post(changeVideoEvent);
|
}
|
}
|
}
|