diff --git a/app/build.gradle b/app/build.gradle
index 1dba1b5..481dab8 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -6,8 +6,8 @@ android {
applicationId "my.project.sakuraproject"
minSdkVersion 21
targetSdkVersion 29
- versionCode 9
- versionName "1.8.1"
+ versionCode 10
+ versionName "1.8.2"
ndk{abiFilters "armeabi", "armeabi-v7a", "x86"}
resConfigs"zh"
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 112ad1c..e537bfb 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -6,6 +6,7 @@
+
+
+ parent) {
public void setDefaultPlayer() {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(Utils.getString(R.string.select_player));
- builder.setSingleChoiceItems(playerItems, (Integer) SharedPreferencesUtils.getParam(getApplicationContext(), "player", 0), new DialogInterface.OnClickListener() {
- @Override
- public void onClick(DialogInterface dialog, int which) {
- switch (which) {
- case 0:
- SharedPreferencesUtils.setParam(getApplicationContext(), "player", 0);
- player_default.setText(playerItems[0]);
- break;
- case 1:
- SharedPreferencesUtils.setParam(getApplicationContext(), "player", 1);
- player_default.setText(playerItems[1]);
- break;
- }
- dialog.dismiss();
+ builder.setSingleChoiceItems(playerItems, (Integer) SharedPreferencesUtils.getParam(getApplicationContext(), "player", 0), (dialog, which) -> {
+ switch (which) {
+ case 0:
+ SharedPreferencesUtils.setParam(getApplicationContext(), "player", 0);
+ player_default.setText(playerItems[0]);
+ break;
+ case 1:
+ SharedPreferencesUtils.setParam(getApplicationContext(), "player", 1);
+ player_default.setText(playerItems[1]);
+ break;
+ }
+ dialog.dismiss();
+ });
+ AlertDialog alertDialog = builder.create();
+ alertDialog.show();
+ }
+
+ public void setX5State() {
+ AlertDialog.Builder builder = new AlertDialog.Builder(this);
+ builder.setTitle("请选择");
+ builder.setSingleChoiceItems(x5Items, Utils.loadX5() ? 0 : 1, (dialog, which) -> {
+ switch (which){
+ case 0:
+ if (TbsVideo.canUseTbsPlayer(SettingActivity.this)) {
+ SharedPreferencesUtils.setParam(getApplicationContext(),"loadX5",true);
+ x5_state.setText(x5Items[0]);
+ }else
+ application.showErrorToastMsg("X5内核未能加载成功,无法启用");
+ break;
+ case 1:
+ SharedPreferencesUtils.setParam(getApplicationContext(),"loadX5",false);
+ x5_state.setText(x5Items[1]);
+ break;
}
+ dialog.dismiss();
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
diff --git a/app/src/main/java/my/project/sakuraproject/main/webview/normal/DefaultNormalWebActivity.java b/app/src/main/java/my/project/sakuraproject/main/webview/normal/DefaultNormalWebActivity.java
new file mode 100644
index 0000000..7994fc4
--- /dev/null
+++ b/app/src/main/java/my/project/sakuraproject/main/webview/normal/DefaultNormalWebActivity.java
@@ -0,0 +1,212 @@
+package my.project.sakuraproject.main.webview.normal;
+
+import android.content.Context;
+import android.content.pm.ActivityInfo;
+import android.os.Bundle;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.webkit.WebChromeClient;
+import android.webkit.WebSettings;
+import android.webkit.WebView;
+import android.widget.FrameLayout;
+import android.widget.LinearLayout;
+import android.widget.ProgressBar;
+
+import butterknife.BindView;
+import butterknife.OnClick;
+import my.project.sakuraproject.R;
+import my.project.sakuraproject.main.base.BaseActivity;
+import my.project.sakuraproject.main.base.Presenter;
+import my.project.sakuraproject.util.Utils;
+
+public class DefaultNormalWebActivity extends BaseActivity {
+ private String url;
+ @BindView(R.id.webview)
+ NormalWebView normalWebView;
+ @BindView(R.id.progressBar)
+ ProgressBar pg;
+ /**
+ * 视频全屏参数
+ */
+ protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
+ private View customView;
+ private FrameLayout fullscreenContainer;
+ private WebChromeClient.CustomViewCallback customViewCallback;
+ private Boolean isFullscreen = false;
+ @BindView(R.id.activity_main)
+ LinearLayout linearLayout;
+
+ @Override
+ protected Presenter createPresenter() {
+ return null;
+ }
+
+ @Override
+ protected void loadData() {}
+
+ @Override
+ protected int setLayoutRes() {
+ return R.layout.activity_default_webview_normal;
+ }
+
+ @Override
+ protected void init() {
+ hideGap();
+ getBundle();
+ initWebView();
+ }
+
+ @Override
+ protected void initBeforeView() {
+ }
+
+ public void getBundle() {
+ Bundle bundle = getIntent().getExtras();
+ if (!bundle.isEmpty()) {
+ url = bundle.getString("url");
+ }
+ }
+
+ public void initWebView() {
+ normalWebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
+ if (Utils.checkHasNavigationBar(this)) {
+ ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) linearLayout.getLayoutParams();
+ params.setMargins(0,
+ 0,
+ 0,
+ Utils.getNavigationBarHeight(this));
+ linearLayout.setLayoutParams(params);
+ }
+
+ normalWebView.loadUrl(url);
+ initHardwareAccelerate();
+ normalWebView.setWebChromeClient(new WebChromeClient() {
+ @Override
+ public void onProgressChanged(WebView view, int newProgress) {
+ if (newProgress == 100) {
+ pg.setVisibility(View.GONE);
+ } else {
+ pg.setVisibility(View.VISIBLE);
+ pg.setProgress(newProgress);
+ }
+ }
+
+ //*** 视频播放相关的方法 **//*
+ @Override
+ public View getVideoLoadingProgressView() {
+ FrameLayout frameLayout = new FrameLayout(DefaultNormalWebActivity.this);
+ frameLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ return frameLayout;
+ }
+
+ @Override
+ public void onShowCustomView(View view, CustomViewCallback callback) {
+ showCustomView(view, callback);
+ }
+
+ @Override
+ public void onHideCustomView() {
+ hideCustomView();
+ }
+ });
+ }
+
+ /**
+ * 视频播放全屏
+ **/
+ private void showCustomView(View view, WebChromeClient.CustomViewCallback callback) {
+ // if a view already exists then immediately terminate the new one
+ if (customView != null) {
+ callback.onCustomViewHidden();
+ return;
+ }
+ DefaultNormalWebActivity.this.getWindow().getDecorView();
+ FrameLayout decor = (FrameLayout) getWindow().getDecorView();
+ fullscreenContainer = new DefaultNormalWebActivity.FullscreenHolder(DefaultNormalWebActivity.this);
+ fullscreenContainer.addView(view, COVER_SCREEN_PARAMS);
+ decor.addView(fullscreenContainer, COVER_SCREEN_PARAMS);
+ customView = view;
+ isFullscreen = true;
+ hideNavBar();
+ customViewCallback = callback;
+ // 设置横屏
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
+ }
+
+ /**
+ * 隐藏视频全屏
+ */
+ private void hideCustomView() {
+ if (customView == null) {
+ return;
+ }
+ isFullscreen = false;
+ showNavBar();
+ FrameLayout decor = (FrameLayout) getWindow().getDecorView();
+ decor.removeView(fullscreenContainer);
+ fullscreenContainer = null;
+ customView = null;
+ customViewCallback.onCustomViewHidden();
+ normalWebView.setVisibility(View.VISIBLE);
+ // 设置竖屏
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+ }
+
+ /**
+ * 全屏容器界面
+ */
+ static class FullscreenHolder extends FrameLayout {
+
+ public FullscreenHolder(Context ctx) {
+ super(ctx);
+ setBackgroundColor(ctx.getResources().getColor(android.R.color.black));
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent evt) {
+ return true;
+ }
+ }
+
+ /**
+ * 启用硬件加速
+ */
+ private void initHardwareAccelerate() {
+ try {
+ getWindow().setFlags(
+ WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
+ WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
+ } catch (Exception e) {
+ }
+ }
+
+ @Override
+ public void onBackPressed() {
+ if (isFullscreen) hideCustomView();
+ else finish();
+ }
+
+ //销毁Webview
+ @Override
+ protected void onDestroy() {
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+ //释放资源
+ if (normalWebView != null)
+ normalWebView.destroy();
+ super.onDestroy();
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ if (isFullscreen) hideNavBar();
+ else showNavBar();
+ }
+
+ @OnClick(R.id.back)
+ public void back() {
+ finish();
+ }
+}
diff --git a/app/src/main/java/my/project/sakuraproject/main/webview/normal/NormalWebActivity.java b/app/src/main/java/my/project/sakuraproject/main/webview/normal/NormalWebActivity.java
new file mode 100644
index 0000000..0dd4b69
--- /dev/null
+++ b/app/src/main/java/my/project/sakuraproject/main/webview/normal/NormalWebActivity.java
@@ -0,0 +1,535 @@
+package my.project.sakuraproject.main.webview.normal;
+
+import android.app.ProgressDialog;
+import android.content.Context;
+import android.content.Intent;
+import android.content.pm.ActivityInfo;
+import android.os.Bundle;
+import android.util.Patterns;
+import android.view.LayoutInflater;
+import android.view.Menu;
+import android.view.MenuItem;
+import android.view.MotionEvent;
+import android.view.View;
+import android.view.ViewGroup;
+import android.view.WindowManager;
+import android.webkit.WebChromeClient;
+import android.webkit.WebSettings;
+import android.webkit.WebView;
+import android.widget.Button;
+import android.widget.FrameLayout;
+import android.widget.ProgressBar;
+import android.widget.TextView;
+
+import androidx.coordinatorlayout.widget.CoordinatorLayout;
+import androidx.recyclerview.widget.GridLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
+import com.google.android.material.bottomsheet.BottomSheetDialog;
+import com.google.android.material.floatingactionbutton.FloatingActionButton;
+import com.r0adkll.slidr.Slidr;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import butterknife.BindView;
+import butterknife.OnClick;
+import my.project.sakuraproject.R;
+import my.project.sakuraproject.adapter.DramaAdapter;
+import my.project.sakuraproject.adapter.WebviewAdapter;
+import my.project.sakuraproject.api.Api;
+import my.project.sakuraproject.application.Sakura;
+import my.project.sakuraproject.bean.AnimeDescBean;
+import my.project.sakuraproject.bean.ApiBean;
+import my.project.sakuraproject.bean.WebviewBean;
+import my.project.sakuraproject.database.DatabaseUtil;
+import my.project.sakuraproject.main.base.BaseActivity;
+import my.project.sakuraproject.main.base.Presenter;
+import my.project.sakuraproject.main.video.VideoContract;
+import my.project.sakuraproject.main.video.VideoPresenter;
+import my.project.sakuraproject.main.webview.x5.DefaultX5WebActivity;
+import my.project.sakuraproject.util.SharedPreferencesUtils;
+import my.project.sakuraproject.util.Utils;
+import my.project.sakuraproject.util.VideoUtils;
+
+public class NormalWebActivity extends BaseActivity implements VideoContract.View {
+ private final static String REFERER = "referer";
+ private List list = new ArrayList<>();
+ private String url = "", diliUrl = "";
+ private String animeTitle;
+ private String witchTitle;
+ private String api = Api.SOURCE_1_API;
+ private String newUrl = "";
+ @BindView(R.id.webview)
+ NormalWebView normalWebView;
+ private ProgressBar pg;
+ private List dramaList = new ArrayList<>();
+ private DramaAdapter dramaAdapter;
+ private BottomSheetDialog mBottomSheetDialog;
+ private ProgressDialog p;
+ @BindView(R.id.drama)
+ FloatingActionButton drama;
+ @BindView(R.id.title)
+ TextView title;
+ /**
+ * 视频全屏参数
+ */
+ protected static final FrameLayout.LayoutParams COVER_SCREEN_PARAMS = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
+ private View customView;
+ private FrameLayout fullscreenContainer;
+ private WebChromeClient.CustomViewCallback customViewCallback;
+ private VideoPresenter presenter;
+ private List apiList;
+ private WebSettings webSettings;
+ private boolean mModel = false;
+ private MenuItem menuItem;
+ private Boolean isFullscreen = false;
+ @BindView(R.id.activity_main)
+ CoordinatorLayout coordinatorLayout;
+
+ @Override
+ protected Presenter createPresenter() {
+ return null;
+ }
+
+ @Override
+ protected void loadData() {
+
+ }
+
+ @Override
+ protected int setLayoutRes() {
+ return R.layout.activity_webview_normal;
+ }
+
+ @Override
+ protected void init() {
+ Slidr.attach(this, Utils.defaultInit());
+ hideGap();
+ getBundle();
+ initFab();
+ initView();
+ initApiData();
+ initAdapter();
+ initWebView();
+ }
+
+ @Override
+ protected void initBeforeView() {
+ }
+
+ public void initFab() {
+ if (Utils.checkHasNavigationBar(this)) {
+ ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) drama.getLayoutParams();
+ params.setMargins(Utils.dpToPx(this, 16),
+ Utils.dpToPx(this, 16),
+ Utils.dpToPx(this, 16),
+ Utils.getNavigationBarHeight(this));
+ drama.setLayoutParams(params);
+ }
+ }
+
+ public void getBundle() {
+ Bundle bundle = getIntent().getExtras();
+ if (!bundle.isEmpty()) {
+ witchTitle = bundle.getString("witchTitle");
+ animeTitle = bundle.getString("title");
+ url = bundle.getString("url");
+ diliUrl = bundle.getString("dili");
+ dramaList = (List) bundle.getSerializable("list");
+ }
+ }
+
+ public void initView() {
+ pg = findViewById(R.id.progressBar);
+ if (Utils.checkHasNavigationBar(this)) {
+ ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) coordinatorLayout.getLayoutParams();
+ params.setMargins(0,
+ 0,
+ 0,
+ Utils.getNavigationBarHeight(this));
+ coordinatorLayout.setLayoutParams(params);
+ }
+ }
+
+ private void initApiData() {
+ apiList = DatabaseUtil.queryAllApi();
+ }
+
+ public void initAdapter() {
+ list.add(new WebviewBean(Utils.getString(R.string.source_1), Api.SOURCE_1_API, true, false, false));
+ list.add(new WebviewBean(Utils.getString(R.string.source_2), Api.SOURCE_2_API, false, false, false));
+ list.add(new WebviewBean(Utils.getString(R.string.source_3), Api.SOURCE_3_API, false, false, false));
+ list.add(new WebviewBean(Utils.getString(R.string.source_4), Api.SOURCE_4_API, false, false, false));
+ list.add(new WebviewBean(Utils.getString(R.string.source_5), Api.SOURCE_5_API, false, false, false));
+ list.add(new WebviewBean(Utils.getString(R.string.source_6), Api.SOURCE_6_API, false, false, false));
+ if (apiList.size() > 0) {
+ for (int i = 0; i < apiList.size(); i++) {
+ list.add(new WebviewBean(apiList.get(i).getTitle(), apiList.get(i).getUrl(), false, false, false));
+ }
+ }
+ list.add(new WebviewBean(Utils.getString(R.string.source_8), "", false, true, false));
+ list.add(new WebviewBean(Utils.getString(R.string.source_9), "", false, false, true));
+ View dramaView = LayoutInflater.from(this).inflate(R.layout.dialog_webview, null);
+ RecyclerView lineRecyclerView = dramaView.findViewById(R.id.line_list);
+ lineRecyclerView.setNestedScrollingEnabled(false);
+ lineRecyclerView.setLayoutManager(new GridLayoutManager(this, 4));
+ WebviewAdapter webviewAdapter = new WebviewAdapter(this, list);
+ webviewAdapter.setOnItemClickListener((adapter, view, position) -> {
+ if (list.get(position).isOriginalPage()) {
+ Utils.viewInChrome(NormalWebActivity.this, diliUrl);
+ } else if (list.get(position).isOriginalAddress()) {
+ Utils.viewInChrome(NormalWebActivity.this, url);
+ } else {
+ mBottomSheetDialog.dismiss();
+ for (int i = 0; i < list.size(); i++) {
+ list.get(i).setSelect(false);
+ }
+ list.get(position).setSelect(true);
+ adapter.notifyDataSetChanged();
+ Map map = new HashMap<>();
+ map.put(REFERER, diliUrl);
+ api = list.get(position).getUrl();
+ newUrl = api + url;
+ normalWebView.loadUrl(newUrl, map);
+ }
+ });
+ lineRecyclerView.setAdapter(webviewAdapter);
+ RecyclerView dramaRecyclerView = dramaView.findViewById(R.id.drama_list);
+ dramaRecyclerView.setNestedScrollingEnabled(false);
+ TextView titleTextView = dramaView.findViewById(R.id.title);
+ titleTextView.setText(animeTitle);
+ dramaRecyclerView.setLayoutManager(new GridLayoutManager(this, 5));
+ dramaAdapter = new DramaAdapter(this, dramaList);
+ dramaAdapter.setOnItemClickListener((adapter, view, position) -> {
+ if (!Utils.isFastClick()) return;
+ setResult(0x20);
+ mBottomSheetDialog.dismiss();
+ final AnimeDescBean bean = (AnimeDescBean) adapter.getItem(position);
+ switch (bean.getType()) {
+ case "play":
+ p = Utils.getProDialog(NormalWebActivity.this, R.string.parsing);
+ Button v = (Button) adapter.getViewByPosition(dramaRecyclerView, position, R.id.tag_group);
+ v.setBackgroundResource(R.drawable.button_selected);
+ v.setTextColor(getResources().getColor(R.color.item_selected_color));
+ bean.setSelect(true);
+ diliUrl = VideoUtils.getUrl(bean.getUrl());
+ witchTitle = animeTitle + " - " + bean.getTitle();
+ presenter = new VideoPresenter(animeTitle, diliUrl, NormalWebActivity.this);
+ presenter.loadData(true);
+ break;
+ }
+
+ });
+ dramaRecyclerView.setAdapter(dramaAdapter);
+ mBottomSheetDialog = new BottomSheetDialog(this);
+ mBottomSheetDialog.setContentView(dramaView);
+ }
+
+ public void goToPlay(List list) {
+ if (list.size() == 1) oneSource(list);
+ else multipleSource(list);
+ }
+
+ public void initWebView() {
+ webSettings = normalWebView.getSettings();
+// webSettings.setUserAgentString(PHONE_USER_AGENT);
+ getWindow().getDecorView().addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
+ ArrayList outView = new ArrayList<>();
+ getWindow().getDecorView().findViewsWithText(outView, "下载该视频", View.FIND_VIEWS_WITH_TEXT);
+ if (outView != null && outView.size() > 0) {
+ outView.get(0).setVisibility(View.GONE);
+ }
+ });
+ normalWebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
+ //视频源地址
+// URL urlHost;
+// try {
+// urlHost = new URL(url);
+// } catch (MalformedURLException e) {
+// e.printStackTrace();
+// }
+ newUrl = Api.SOURCE_1_API + url;
+ normalWebView.loadUrl(newUrl);
+ initHardwareAccelerate();
+ normalWebView.setWebChromeClient(new WebChromeClient() {
+ @Override
+ public void onProgressChanged(WebView view, int newProgress) {
+ if (newProgress == 100) {
+ pg.setVisibility(View.GONE);
+ } else {
+ pg.setVisibility(View.VISIBLE);
+ pg.setProgress(newProgress);
+ }
+ }
+
+ /** 视频播放相关的方法 **/
+ @Override
+ public View getVideoLoadingProgressView() {
+ FrameLayout frameLayout = new FrameLayout(NormalWebActivity.this);
+ frameLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
+ return frameLayout;
+ }
+
+ @Override
+ public void onShowCustomView(View view, CustomViewCallback callback) {
+ showCustomView(view, callback);
+ }
+
+ @Override
+ public void onHideCustomView() {
+ hideFullCustomView();
+ }
+ });
+ }
+
+ /**
+ * 视频播放全屏
+ **/
+ private void showCustomView(View view, WebChromeClient.CustomViewCallback callback) {
+ // if a view already exists then immediately terminate the new one
+ if (customView != null) {
+ callback.onCustomViewHidden();
+ return;
+ }
+ NormalWebActivity.this.getWindow().getDecorView();
+ FrameLayout decor = (FrameLayout) getWindow().getDecorView();
+ fullscreenContainer = new FullscreenHolder(NormalWebActivity.this);
+ fullscreenContainer.addView(view, COVER_SCREEN_PARAMS);
+ decor.addView(fullscreenContainer, COVER_SCREEN_PARAMS);
+ customView = view;
+ isFullscreen = true;
+ hideNavBar();
+ customViewCallback = callback;
+ // 设置横屏
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
+ }
+
+ /**
+ * 隐藏视频全屏
+ */
+ private void hideFullCustomView() {
+ if (customView == null) {
+ return;
+ }
+ isFullscreen = false;
+ showNavBar();
+ FrameLayout decor = (FrameLayout) getWindow().getDecorView();
+ decor.removeView(fullscreenContainer);
+ fullscreenContainer = null;
+ customView = null;
+ customViewCallback.onCustomViewHidden();
+ normalWebView.setVisibility(View.VISIBLE);
+ // 设置竖屏
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
+ }
+
+
+ @Override
+ public void cancelDialog() {
+ Utils.cancelProDialog(p);
+ }
+
+ @Override
+ public void getVideoSuccess(List list) {
+ runOnUiThread(() -> goToPlay(list));
+ }
+
+ @Override
+ public void getVideoEmpty() {
+ runOnUiThread(() -> VideoUtils.showErrorInfo(NormalWebActivity.this, diliUrl));
+ }
+
+ @Override
+ public void getVideoError() {
+ //网络出错
+ runOnUiThread(() -> application.showToastMsg(Utils.getString(R.string.error_700)));
+ }
+
+ @Override
+ public void showSuccessDramaView(List list) {
+ dramaList = list;
+ runOnUiThread(() -> dramaAdapter.setNewData(dramaList));
+ }
+
+ @Override
+ public void errorDramaView() {
+ runOnUiThread(() -> application.showToastMsg(Utils.getString(R.string.get_drama_error)));
+ }
+
+ /**
+ * 全屏容器界面
+ */
+ static class FullscreenHolder extends FrameLayout {
+
+ public FullscreenHolder(Context ctx) {
+ super(ctx);
+ setBackgroundColor(ctx.getResources().getColor(android.R.color.black));
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent evt) {
+ return true;
+ }
+ }
+
+ /**
+ * 启用硬件加速
+ */
+ private void initHardwareAccelerate() {
+ try {
+ getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
+ WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ public void onBackPressed() {
+ if (isFullscreen){
+ hideFullCustomView();
+ }else {
+ if (normalWebView.canGoBack()) normalWebView.goBack();//返回上个页面
+ else finish();
+ }
+
+ }
+
+ @Override
+ protected void onResume() {
+ super.onResume();
+ if (isFullscreen) hideNavBar();
+ else showNavBar();
+ }
+
+ @Override
+ protected void onDestroy() {
+ //销毁Webview
+ if (normalWebView != null)
+ normalWebView.destroy();
+ if (null != presenter)
+ presenter.detachView();
+ super.onDestroy();
+ }
+
+
+ /**
+ * 只有一个播放地址
+ *
+ * @param list
+ */
+ private void oneSource(List list) {
+ playAnime(VideoUtils.getVideoUrl(list.get(0)));
+ }
+
+ /**
+ * 多个播放地址
+ *
+ * @param list
+ */
+ private void multipleSource(List list) {
+ VideoUtils.showMultipleVideoSources(this,
+ list,
+ (dialog, index) ->
+ playAnime(VideoUtils.getVideoUrl(list.get(index)))
+ );
+ }
+
+ private void playAnime(String animeUrl) {
+ url = animeUrl;
+ if (Patterns.WEB_URL.matcher(animeUrl.replace(" ", "")).matches()) {
+ if (animeUrl.contains("jx.618g.com")) {
+ url = animeUrl.replaceAll("http://jx.618g.com/\\?url=", "");
+ loadUrl();
+ } else if (animeUrl.contains(".mp4") || animeUrl.contains(".m3u8")) {
+ switch ((Integer) SharedPreferencesUtils.getParam(getApplicationContext(), "player", 0)) {
+ case 0:
+ //调用播放器
+ VideoUtils.openPlayer(false, NormalWebActivity.this, witchTitle, url, animeTitle, diliUrl, dramaList);
+ break;
+ case 1:
+ Utils.selectVideoPlayer(this, url);
+ break;
+ }
+ }else {
+ Sakura.getInstance().showToastMsg(Utils.getString(R.string.should_be_used_web));
+ if (Utils.loadX5())
+ startActivity(new Intent(NormalWebActivity.this, DefaultX5WebActivity.class).putExtra("url", url));
+ else
+ startActivity(new Intent(NormalWebActivity.this, DefaultNormalWebActivity.class).putExtra("url", url));
+ this.finish();
+ }
+ } else {
+ Sakura.getInstance().showToastMsg(Utils.getString(R.string.maybe_can_not_play));
+ if (Utils.loadX5())
+ startActivity(new Intent(NormalWebActivity.this, DefaultX5WebActivity.class).putExtra("url",String.format(Api.PARSE_API, url)));
+ else
+ startActivity(new Intent(NormalWebActivity.this, DefaultNormalWebActivity.class).putExtra("url",String.format(Api.PARSE_API, url)));
+ }
+ }
+
+ /**
+ * 加载新地址
+ */
+ private void loadUrl() {
+// toolbar.setTitle(witchTitle);
+ //视频源地址
+// URL urlHost;
+// try {
+// urlHost = new URL(url);
+// toolbar.setSubtitle(urlHost.getHost());
+// } catch (MalformedURLException e) {
+// e.printStackTrace();
+// }
+ title.setText(witchTitle);
+ newUrl = api + url;
+ normalWebView.loadUrl(newUrl);
+ }
+
+ @Override
+ public boolean onCreateOptionsMenu(Menu menu) {
+ getMenuInflater().inflate(R.menu.web_menu, menu);
+ menuItem = menu.findItem(R.id.model);
+ return true;
+ }
+
+ @OnClick(R.id.drama)
+ public void dramaClick() {
+ if (!mBottomSheetDialog.isShowing()) mBottomSheetDialog.show();
+ }
+
+ @Override
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case R.id.model:
+ if (mModel) {
+ //切换成手机版
+ mModel = false;
+ webSettings.setUserAgentString(NormalWebView.PHONE_USER_AGENT);
+ menuItem.setIcon(R.drawable.baseline_stay_primary_portrait_white_48dp);
+ menuItem.setTitle(Utils.getString(R.string.phone_model));
+ application.showToastMsg("已切换成手机版");
+ } else {
+ //切换成电脑版
+ mModel = true;
+ webSettings.setUserAgentString(NormalWebView.PC_USER_AGENT);
+ menuItem.setIcon(R.drawable.baseline_language_white_48dp);
+ menuItem.setTitle(Utils.getString(R.string.pc_model));
+ application.showToastMsg("已切换成电脑版");
+ }
+ Map map = new HashMap<>();
+ map.put(REFERER, diliUrl);
+ normalWebView.loadUrl(newUrl, map);
+ break;
+ }
+ return super.onOptionsItemSelected(item);
+ }
+
+ @OnClick(R.id.back)
+ public void back() {
+ finish();
+ }
+}
diff --git a/app/src/main/java/my/project/sakuraproject/main/webview/normal/NormalWebView.java b/app/src/main/java/my/project/sakuraproject/main/webview/normal/NormalWebView.java
new file mode 100644
index 0000000..bbf6cf1
--- /dev/null
+++ b/app/src/main/java/my/project/sakuraproject/main/webview/normal/NormalWebView.java
@@ -0,0 +1,62 @@
+package my.project.sakuraproject.main.webview.normal;
+
+import android.annotation.SuppressLint;
+import android.content.Context;
+import android.util.AttributeSet;
+import android.webkit.WebSettings;
+import android.webkit.WebView;
+import android.webkit.WebViewClient;
+
+public class NormalWebView extends WebView {
+ public final static String PC_USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36";
+ public final static String PHONE_USER_AGENT = "Mozilla/5.0 (Linux; Android 9; ONEPLUS A6010 Build/PKQ1.180716.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.158 Mobile Safari/537.36";
+ private WebViewClient client = new WebViewClient() {
+ // 防止加载网页时调起系统浏览器
+ public boolean shouldOverrideUrlLoading(WebView view, String url) {
+ view.loadUrl(url);
+ return true;
+ }
+ };
+
+ public NormalWebView(Context arg0) {
+ super(arg0);
+ setBackgroundColor(85621);
+ }
+
+ @SuppressLint("SetJavaScriptEnabled")
+ public NormalWebView(Context arg0, AttributeSet arg1) {
+ super(arg0, arg1);
+
+ this.setWebViewClient(client);
+ // this.setWebChromeClient(chromeClient);
+ // WebStorage webStorage = WebStorage.getInstance();
+ initWebViewSettings();
+ this.setClickable(true);
+ }
+
+ private void initWebViewSettings() {
+ WebSettings webSetting = this.getSettings();
+ webSetting.setJavaScriptEnabled(true);
+ webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
+ webSetting.setAllowFileAccess(false);
+ webSetting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
+ webSetting.setSupportZoom(false);
+ webSetting.setBuiltInZoomControls(false);
+ webSetting.setUseWideViewPort(true);
+ webSetting.setSupportMultipleWindows(true);
+ // webSetting.setLoadWithOverviewMode(true);
+ webSetting.setAppCacheEnabled(true);
+ //是否调节内容 是否全屏
+ webSetting.setLoadWithOverviewMode(true);
+ // webSetting.setDatabaseEnabled(true);
+ webSetting.setDomStorageEnabled(true);
+ webSetting.setGeolocationEnabled(false);
+ webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
+ // webSetting.setPageCacheCapacity(IX5WebSettings.DEFAULT_CACHE_CAPACITY);
+ webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
+ // webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
+ webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);
+ webSetting.setUserAgentString(PC_USER_AGENT);
+ }
+
+}
diff --git a/app/src/main/java/my/project/sakuraproject/main/webview/DefaultWebActivity.java b/app/src/main/java/my/project/sakuraproject/main/webview/x5/DefaultX5WebActivity.java
similarity index 77%
rename from app/src/main/java/my/project/sakuraproject/main/webview/DefaultWebActivity.java
rename to app/src/main/java/my/project/sakuraproject/main/webview/x5/DefaultX5WebActivity.java
index 30fab4a..99ecc12 100644
--- a/app/src/main/java/my/project/sakuraproject/main/webview/DefaultWebActivity.java
+++ b/app/src/main/java/my/project/sakuraproject/main/webview/x5/DefaultX5WebActivity.java
@@ -1,11 +1,9 @@
-package my.project.sakuraproject.main.webview;
+package my.project.sakuraproject.main.webview.x5;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
-import android.os.Build;
import android.os.Bundle;
-import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
@@ -18,9 +16,7 @@
import com.tencent.smtt.export.external.interfaces.IX5WebChromeClient;
import com.tencent.smtt.sdk.WebChromeClient;
import com.tencent.smtt.sdk.WebView;
-import com.tencent.smtt.sdk.WebViewClient;
-import java.lang.reflect.Method;
import java.util.ArrayList;
import butterknife.BindView;
@@ -31,10 +27,10 @@
import my.project.sakuraproject.services.ClearVideoCacheService;
import my.project.sakuraproject.util.Utils;
-public class DefaultWebActivity extends BaseActivity {
+public class DefaultX5WebActivity extends BaseActivity {
private String url;
@BindView(R.id.x5_webview)
- X5WebView mX5WebView;
+ X5WebView x5WebView;
@BindView(R.id.progressBar)
ProgressBar pg;
/**
@@ -58,7 +54,7 @@ protected void loadData() {}
@Override
protected int setLayoutRes() {
- return R.layout.activity_default_webview;
+ return R.layout.activity_default_webview_x5;
}
@Override
@@ -80,6 +76,7 @@ public void getBundle() {
}
public void initWebView() {
+ x5WebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
if (Utils.checkHasNavigationBar(this)) {
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) linearLayout.getLayoutParams();
params.setMargins(0,
@@ -95,24 +92,9 @@ public void initWebView() {
outView.get(0).setVisibility(View.GONE);
}
});
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- mX5WebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
- }
- //需要升级complieversion为21以上,不升级的话,用反射的方式来实现,如下代码所示
- try {
- Method m = WebSettings.class.getMethod("setMixedContentMode", int.class);
- if (m == null) {
- Log.e("WebSettings", "Error getting setMixedContentMode method");
- } else {
- m.invoke(mX5WebView.getSettings(), 2); // 2 = MIXED_CONTENT_COMPATIBILITY_MODE
- Log.i("WebSettings", "Successfully set MIXED_CONTENT_COMPATIBILITY_MODE");
- }
- } catch (Exception ex) {
- Log.e("WebSettings", "Error calling setMixedContentMode: " + ex.getMessage(), ex);
- }
- mX5WebView.loadUrl(url);
+ x5WebView.loadUrl(url);
initHardwareAccelerate();
- if (null != mX5WebView.getX5WebViewExtension()) {
+ if (null != x5WebView.getX5WebViewExtension()) {
Bundle data = new Bundle();
data.putBoolean("standardFullScreen", false);
//true表示标准全屏,false表示X5全屏;不设置默认false,
@@ -120,9 +102,10 @@ public void initWebView() {
//false:关闭小窗;true:开启小窗;不设置默认true,
data.putInt("DefaultVideoScreen", 2);
//1:以页面内开始播放,2:以全屏开始播放;不设置默认:1
- mX5WebView.getX5WebViewExtension().invokeMiscMethod("setVideoParams", data);
- } else application.showErrorToastMsg("X5内核加载失败");
- mX5WebView.setWebChromeClient(new WebChromeClient() {
+ x5WebView.getX5WebViewExtension().invokeMiscMethod("setVideoParams", data);
+ }
+// else application.showErrorToastMsg("X5内核加载失败");
+ x5WebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
if (newProgress == 100) {
@@ -136,7 +119,7 @@ public void onProgressChanged(WebView view, int newProgress) {
//*** 视频播放相关的方法 **//*
@Override
public View getVideoLoadingProgressView() {
- FrameLayout frameLayout = new FrameLayout(DefaultWebActivity.this);
+ FrameLayout frameLayout = new FrameLayout(DefaultX5WebActivity.this);
frameLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
return frameLayout;
}
@@ -151,12 +134,6 @@ public void onHideCustomView() {
hideCustomView();
}
});
- mX5WebView.setWebViewClient(new WebViewClient() {
- @Override
- public void onPageFinished(WebView view, String url) {
- super.onPageFinished(view, url);
- }
- });
}
/**
@@ -168,9 +145,9 @@ private void showCustomView(View view, IX5WebChromeClient.CustomViewCallback cal
callback.onCustomViewHidden();
return;
}
- DefaultWebActivity.this.getWindow().getDecorView();
+ DefaultX5WebActivity.this.getWindow().getDecorView();
FrameLayout decor = (FrameLayout) getWindow().getDecorView();
- fullscreenContainer = new DefaultWebActivity.FullscreenHolder(DefaultWebActivity.this);
+ fullscreenContainer = new DefaultX5WebActivity.FullscreenHolder(DefaultX5WebActivity.this);
fullscreenContainer.addView(view, COVER_SCREEN_PARAMS);
decor.addView(fullscreenContainer, COVER_SCREEN_PARAMS);
customView = view;
@@ -178,7 +155,7 @@ private void showCustomView(View view, IX5WebChromeClient.CustomViewCallback cal
hideNavBar();
customViewCallback = callback;
// 设置横屏
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
}
/**
@@ -195,7 +172,7 @@ private void hideCustomView() {
fullscreenContainer = null;
customView = null;
customViewCallback.onCustomViewHidden();
- mX5WebView.setVisibility(View.VISIBLE);
+ x5WebView.setVisibility(View.VISIBLE);
// 设置竖屏
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
@@ -230,7 +207,8 @@ private void initHardwareAccelerate() {
@Override
public void onBackPressed() {
- finish();
+ if (isFullscreen) hideCustomView();
+ else finish();
}
//销毁Webview
@@ -238,8 +216,8 @@ public void onBackPressed() {
protected void onDestroy() {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
//释放资源
- if (mX5WebView != null)
- mX5WebView.destroy();
+ if (x5WebView != null)
+ x5WebView.destroy();
startService(new Intent(this, ClearVideoCacheService.class));
super.onDestroy();
}
diff --git a/app/src/main/java/my/project/sakuraproject/main/webview/WebActivity.java b/app/src/main/java/my/project/sakuraproject/main/webview/x5/X5WebActivity.java
similarity index 83%
rename from app/src/main/java/my/project/sakuraproject/main/webview/WebActivity.java
rename to app/src/main/java/my/project/sakuraproject/main/webview/x5/X5WebActivity.java
index ffc3310..5f5ebef 100644
--- a/app/src/main/java/my/project/sakuraproject/main/webview/WebActivity.java
+++ b/app/src/main/java/my/project/sakuraproject/main/webview/x5/X5WebActivity.java
@@ -1,12 +1,10 @@
-package my.project.sakuraproject.main.webview;
+package my.project.sakuraproject.main.webview.x5;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
-import android.os.Build;
import android.os.Bundle;
-import android.util.Log;
import android.util.Patterns;
import android.view.LayoutInflater;
import android.view.Menu;
@@ -21,6 +19,10 @@
import android.widget.ProgressBar;
import android.widget.TextView;
+import androidx.coordinatorlayout.widget.CoordinatorLayout;
+import androidx.recyclerview.widget.GridLayoutManager;
+import androidx.recyclerview.widget.RecyclerView;
+
import com.google.android.material.bottomsheet.BottomSheetDialog;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.r0adkll.slidr.Slidr;
@@ -28,15 +30,11 @@
import com.tencent.smtt.sdk.WebChromeClient;
import com.tencent.smtt.sdk.WebView;
-import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import androidx.coordinatorlayout.widget.CoordinatorLayout;
-import androidx.recyclerview.widget.GridLayoutManager;
-import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.OnClick;
import my.project.sakuraproject.R;
@@ -52,14 +50,14 @@
import my.project.sakuraproject.main.base.Presenter;
import my.project.sakuraproject.main.video.VideoContract;
import my.project.sakuraproject.main.video.VideoPresenter;
-import my.project.sakuraproject.services.ClearVideoCacheService;
+import my.project.sakuraproject.main.webview.normal.DefaultNormalWebActivity;
import my.project.sakuraproject.util.SharedPreferencesUtils;
import my.project.sakuraproject.util.Utils;
import my.project.sakuraproject.util.VideoUtils;
-public class WebActivity extends BaseActivity implements VideoContract.View {
- private final static String PC_USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36";
- private final static String PHONE_USER_AGENT = "Mozilla/5.0 (Linux; Android 9; ONEPLUS A6010 Build/PKQ1.180716.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.158 Mobile Safari/537.36";
+;
+
+public class X5WebActivity extends BaseActivity implements VideoContract.View {
private final static String REFERER = "referer";
private List list = new ArrayList<>();
private String url = "", diliUrl = "";
@@ -68,7 +66,7 @@ public class WebActivity extends BaseActivity implements VideoContract.View {
private String api = Api.SOURCE_1_API;
private String newUrl = "";
@BindView(R.id.x5_webview)
- X5WebView mX5WebView;
+ X5WebView x5WebView;
private ProgressBar pg;
private List dramaList = new ArrayList<>();
private DramaAdapter dramaAdapter;
@@ -106,7 +104,7 @@ protected void loadData() {
@Override
protected int setLayoutRes() {
- return R.layout.activity_webview;
+ return R.layout.activity_webview_x5;
}
@Override
@@ -184,9 +182,9 @@ public void initAdapter() {
WebviewAdapter webviewAdapter = new WebviewAdapter(this, list);
webviewAdapter.setOnItemClickListener((adapter, view, position) -> {
if (list.get(position).isOriginalPage()) {
- Utils.viewInChrome(WebActivity.this, diliUrl);
+ Utils.viewInChrome(X5WebActivity.this, diliUrl);
} else if (list.get(position).isOriginalAddress()) {
- Utils.viewInChrome(WebActivity.this, url);
+ Utils.viewInChrome(X5WebActivity.this, url);
} else {
mBottomSheetDialog.dismiss();
for (int i = 0; i < list.size(); i++) {
@@ -198,7 +196,7 @@ public void initAdapter() {
map.put(REFERER, diliUrl);
api = list.get(position).getUrl();
newUrl = api + url;
- mX5WebView.loadUrl(newUrl, map);
+ x5WebView.loadUrl(newUrl, map);
}
});
lineRecyclerView.setAdapter(webviewAdapter);
@@ -215,14 +213,14 @@ public void initAdapter() {
final AnimeDescBean bean = (AnimeDescBean) adapter.getItem(position);
switch (bean.getType()) {
case "play":
- p = Utils.getProDialog(WebActivity.this, R.string.parsing);
+ p = Utils.getProDialog(X5WebActivity.this, R.string.parsing);
Button v = (Button) adapter.getViewByPosition(dramaRecyclerView, position, R.id.tag_group);
v.setBackgroundResource(R.drawable.button_selected);
v.setTextColor(getResources().getColor(R.color.item_selected_color));
bean.setSelect(true);
diliUrl = VideoUtils.getUrl(bean.getUrl());
witchTitle = animeTitle + " - " + bean.getTitle();
- presenter = new VideoPresenter(animeTitle, diliUrl, WebActivity.this);
+ presenter = new VideoPresenter(animeTitle, diliUrl, X5WebActivity.this);
presenter.loadData(true);
break;
}
@@ -239,8 +237,8 @@ public void goToPlay(List list) {
}
public void initWebView() {
- webSettings = mX5WebView.getSettings();
- webSettings.setUserAgentString(PHONE_USER_AGENT);
+ webSettings = x5WebView.getSettings();
+// webSettings.setUserAgentString(PHONE_USER_AGENT);
getWindow().getDecorView().addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
ArrayList outView = new ArrayList<>();
getWindow().getDecorView().findViewsWithText(outView, "下载该视频", View.FIND_VIEWS_WITH_TEXT);
@@ -248,21 +246,7 @@ public void initWebView() {
outView.get(0).setVisibility(View.GONE);
}
});
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
- mX5WebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
- }
- //需要升级complieversion为21以上,不升级的话,用反射的方式来实现,如下代码所示
- try {
- Method m = WebSettings.class.getMethod("setMixedContentMode", int.class);
- if (m == null) {
- Log.e("WebSettings", "Error getting setMixedContentMode method");
- } else {
- m.invoke(mX5WebView.getSettings(), 2); // 2 = MIXED_CONTENT_COMPATIBILITY_MODE
- Log.i("WebSettings", "Successfully set MIXED_CONTENT_COMPATIBILITY_MODE");
- }
- } catch (Exception ex) {
- Log.e("WebSettings", "Error calling setMixedContentMode: " + ex.getMessage(), ex);
- }
+ x5WebView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_COMPATIBILITY_MODE);
//视频源地址
// URL urlHost;
// try {
@@ -271,9 +255,9 @@ public void initWebView() {
// e.printStackTrace();
// }
newUrl = Api.SOURCE_1_API + url;
- mX5WebView.loadUrl(newUrl);
+ x5WebView.loadUrl(newUrl);
initHardwareAccelerate();
- if (null != mX5WebView.getX5WebViewExtension()) {
+ if (null != x5WebView.getX5WebViewExtension()) {
Bundle data = new Bundle();
data.putBoolean("standardFullScreen", false);
//true表示标准全屏,false表示X5全屏;不设置默认false,
@@ -281,9 +265,10 @@ public void initWebView() {
//false:关闭小窗;true:开启小窗;不设置默认true,
data.putInt("DefaultVideoScreen", 2);
//1:以页面内开始播放,2:以全屏开始播放;不设置默认:1
- mX5WebView.getX5WebViewExtension().invokeMiscMethod("setVideoParams", data);
- } else application.showErrorToastMsg("X5内核加载失败");
- mX5WebView.setWebChromeClient(new WebChromeClient() {
+ x5WebView.getX5WebViewExtension().invokeMiscMethod("setVideoParams", data);
+ }
+// else application.showErrorToastMsg("X5内核加载失败");
+ x5WebView.setWebChromeClient(new WebChromeClient() {
@Override
public void onProgressChanged(WebView view, int newProgress) {
if (newProgress == 100) {
@@ -297,7 +282,7 @@ public void onProgressChanged(WebView view, int newProgress) {
/** 视频播放相关的方法 **/
@Override
public View getVideoLoadingProgressView() {
- FrameLayout frameLayout = new FrameLayout(WebActivity.this);
+ FrameLayout frameLayout = new FrameLayout(X5WebActivity.this);
frameLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
return frameLayout;
}
@@ -323,9 +308,9 @@ private void showCustomView(View view, IX5WebChromeClient.CustomViewCallback cal
callback.onCustomViewHidden();
return;
}
- WebActivity.this.getWindow().getDecorView();
+ X5WebActivity.this.getWindow().getDecorView();
FrameLayout decor = (FrameLayout) getWindow().getDecorView();
- fullscreenContainer = new FullscreenHolder(WebActivity.this);
+ fullscreenContainer = new FullscreenHolder(X5WebActivity.this);
fullscreenContainer.addView(view, COVER_SCREEN_PARAMS);
decor.addView(fullscreenContainer, COVER_SCREEN_PARAMS);
customView = view;
@@ -333,7 +318,7 @@ private void showCustomView(View view, IX5WebChromeClient.CustomViewCallback cal
hideNavBar();
customViewCallback = callback;
// 设置横屏
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
+ setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
}
/**
@@ -350,7 +335,7 @@ private void hideFullCustomView() {
fullscreenContainer = null;
customView = null;
customViewCallback.onCustomViewHidden();
- mX5WebView.setVisibility(View.VISIBLE);
+ x5WebView.setVisibility(View.VISIBLE);
// 设置竖屏
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
@@ -368,7 +353,7 @@ public void getVideoSuccess(List list) {
@Override
public void getVideoEmpty() {
- runOnUiThread(() -> VideoUtils.showErrorInfo(WebActivity.this, diliUrl));
+ runOnUiThread(() -> VideoUtils.showErrorInfo(X5WebActivity.this, diliUrl));
}
@Override
@@ -418,8 +403,13 @@ private void initHardwareAccelerate() {
@Override
public void onBackPressed() {
- if (mX5WebView.canGoBack()) mX5WebView.goBack();//返回上个页面
- else finish();
+ if (isFullscreen){
+ hideFullCustomView();
+ }else {
+ if (x5WebView.canGoBack()) x5WebView.goBack();//返回上个页面
+ else finish();
+ }
+
}
@Override
@@ -432,11 +422,10 @@ protected void onResume() {
@Override
protected void onDestroy() {
//销毁Webview
- if (mX5WebView != null)
- mX5WebView.destroy();
+ if (x5WebView != null)
+ x5WebView.destroy();
if (null != presenter)
presenter.detachView();
- startService(new Intent(this, ClearVideoCacheService.class));
super.onDestroy();
}
@@ -473,7 +462,7 @@ private void playAnime(String animeUrl) {
switch ((Integer) SharedPreferencesUtils.getParam(getApplicationContext(), "player", 0)) {
case 0:
//调用播放器
- VideoUtils.openPlayer(false, WebActivity.this, witchTitle, url, animeTitle, diliUrl, dramaList);
+ VideoUtils.openPlayer(false, X5WebActivity.this, witchTitle, url, animeTitle, diliUrl, dramaList);
break;
case 1:
Utils.selectVideoPlayer(this, url);
@@ -481,12 +470,18 @@ private void playAnime(String animeUrl) {
}
}else {
Sakura.getInstance().showToastMsg(Utils.getString(R.string.should_be_used_web));
- startActivity(new Intent(WebActivity.this, DefaultWebActivity.class).putExtra("url", url));
+ if (Utils.loadX5())
+ startActivity(new Intent(X5WebActivity.this, DefaultX5WebActivity.class).putExtra("url", url));
+ else
+ startActivity(new Intent(X5WebActivity.this, DefaultNormalWebActivity.class).putExtra("url", url));
this.finish();
}
} else {
Sakura.getInstance().showToastMsg(Utils.getString(R.string.maybe_can_not_play));
- startActivity(new Intent(WebActivity.this, DefaultWebActivity.class).putExtra("url",String.format(Api.PARSE_API, url)));
+ if (Utils.loadX5())
+ startActivity(new Intent(X5WebActivity.this, DefaultX5WebActivity.class).putExtra("url",String.format(Api.PARSE_API, url)));
+ else
+ startActivity(new Intent(X5WebActivity.this, DefaultNormalWebActivity.class).putExtra("url",String.format(Api.PARSE_API, url)));
}
}
@@ -505,7 +500,7 @@ private void loadUrl() {
// }
title.setText(witchTitle);
newUrl = api + url;
- mX5WebView.loadUrl(newUrl);
+ x5WebView.loadUrl(newUrl);
}
@Override
@@ -527,21 +522,21 @@ public boolean onOptionsItemSelected(MenuItem item) {
if (mModel) {
//切换成手机版
mModel = false;
- webSettings.setUserAgent(PHONE_USER_AGENT);
+ webSettings.setUserAgentString(X5WebView.PHONE_USER_AGENT);
menuItem.setIcon(R.drawable.baseline_stay_primary_portrait_white_48dp);
menuItem.setTitle(Utils.getString(R.string.phone_model));
application.showToastMsg("已切换成手机版");
} else {
//切换成电脑版
mModel = true;
- webSettings.setUserAgent(PC_USER_AGENT);
+ webSettings.setUserAgentString(X5WebView.PC_USER_AGENT);
menuItem.setIcon(R.drawable.baseline_language_white_48dp);
menuItem.setTitle(Utils.getString(R.string.pc_model));
application.showToastMsg("已切换成电脑版");
}
Map map = new HashMap<>();
map.put(REFERER, diliUrl);
- mX5WebView.loadUrl(newUrl, map);
+ x5WebView.loadUrl(newUrl, map);
break;
}
return super.onOptionsItemSelected(item);
diff --git a/app/src/main/java/my/project/sakuraproject/main/webview/X5WebView.java b/app/src/main/java/my/project/sakuraproject/main/webview/x5/X5WebView.java
similarity index 80%
rename from app/src/main/java/my/project/sakuraproject/main/webview/X5WebView.java
rename to app/src/main/java/my/project/sakuraproject/main/webview/x5/X5WebView.java
index c8efb0b..4553f7d 100644
--- a/app/src/main/java/my/project/sakuraproject/main/webview/X5WebView.java
+++ b/app/src/main/java/my/project/sakuraproject/main/webview/x5/X5WebView.java
@@ -1,4 +1,4 @@
-package my.project.sakuraproject.main.webview;
+package my.project.sakuraproject.main.webview.x5;
import android.annotation.SuppressLint;
import android.content.Context;
@@ -9,7 +9,8 @@
import com.tencent.smtt.sdk.WebViewClient;
public class X5WebView extends WebView {
-
+ public final static String PC_USER_AGENT = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36";
+ public final static String PHONE_USER_AGENT = "Mozilla/5.0 (Linux; Android 9; ONEPLUS A6010 Build/PKQ1.180716.001; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/66.0.3359.158 Mobile Safari/537.36";
private WebViewClient client = new WebViewClient() {
// 防止加载网页时调起系统浏览器
public boolean shouldOverrideUrlLoading(WebView view, String url) {
@@ -31,7 +32,7 @@ public X5WebView(Context arg0, AttributeSet arg1) {
// this.setWebChromeClient(chromeClient);
// WebStorage webStorage = WebStorage.getInstance();
initWebViewSettings();
- this.getView().setClickable(true);
+ this.setClickable(true);
}
private void initWebViewSettings() {
@@ -56,6 +57,7 @@ private void initWebViewSettings() {
webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
// webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
webSetting.setCacheMode(WebSettings.LOAD_NO_CACHE);
+ webSetting.setUserAgent(PC_USER_AGENT);
}
}
diff --git a/app/src/main/java/my/project/sakuraproject/services/ClearVideoCacheService.java b/app/src/main/java/my/project/sakuraproject/services/ClearVideoCacheService.java
index 0526173..afb96ae 100644
--- a/app/src/main/java/my/project/sakuraproject/services/ClearVideoCacheService.java
+++ b/app/src/main/java/my/project/sakuraproject/services/ClearVideoCacheService.java
@@ -4,9 +4,10 @@
import android.content.Intent;
import android.os.IBinder;
+import androidx.annotation.Nullable;
+
import java.io.File;
-import androidx.annotation.Nullable;
import my.project.sakuraproject.util.Utils;
public class ClearVideoCacheService extends Service {
diff --git a/app/src/main/java/my/project/sakuraproject/util/Utils.java b/app/src/main/java/my/project/sakuraproject/util/Utils.java
index 49fcbe1..632fc64 100644
--- a/app/src/main/java/my/project/sakuraproject/util/Utils.java
+++ b/app/src/main/java/my/project/sakuraproject/util/Utils.java
@@ -576,4 +576,12 @@ public static int dpToPx(Context context, float dp) {
float scale = context.getResources().getDisplayMetrics().density;
return (int) ((dp * scale) + 0.5f);
}
+
+ /**
+ * 是否启用x5内核
+ * @return
+ */
+ public static boolean loadX5() {
+ return (boolean) SharedPreferencesUtils.getParam(getContext(), "loadX5", false);
+ }
}
diff --git a/app/src/main/java/my/project/sakuraproject/util/VideoUtils.java b/app/src/main/java/my/project/sakuraproject/util/VideoUtils.java
index 962a487..3cf7db3 100644
--- a/app/src/main/java/my/project/sakuraproject/util/VideoUtils.java
+++ b/app/src/main/java/my/project/sakuraproject/util/VideoUtils.java
@@ -17,7 +17,8 @@
import my.project.sakuraproject.application.Sakura;
import my.project.sakuraproject.bean.AnimeDescBean;
import my.project.sakuraproject.main.player.PlayerActivity;
-import my.project.sakuraproject.main.webview.WebActivity;
+import my.project.sakuraproject.main.webview.normal.NormalWebActivity;
+import my.project.sakuraproject.main.webview.x5.X5WebActivity;
public class VideoUtils {
private static AlertDialog alertDialog;
@@ -40,7 +41,7 @@ public static void showErrorInfo(Context context, String HTML_url) {
alertDialog.show();
alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v -> {
alertDialog.dismiss();
-// context.startActivity(new Intent(context, DefaultWebActivity.class).putExtra("url", HTML_url));
+// context.startActivity(new Intent(context, DefaultNormalWebActivity.class).putExtra("url", HTML_url));
Utils.viewInChrome(context, HTML_url);
});
alertDialog.getButton(AlertDialog.BUTTON_NEGATIVE).setOnClickListener(v -> alertDialog.dismiss());
@@ -130,9 +131,15 @@ public static void openWebview(boolean isDescActivity, Activity activity, String
bundle.putString("dili", diliUrl);
bundle.putSerializable("list", (Serializable) list);
if (isDescActivity)
- activity.startActivityForResult(new Intent(activity, WebActivity.class).putExtras(bundle), 0x10);
+ if (Utils.loadX5())
+ activity.startActivityForResult(new Intent(activity, X5WebActivity.class).putExtras(bundle), 0x10);
+ else
+ activity.startActivityForResult(new Intent(activity, NormalWebActivity.class).putExtras(bundle), 0x10);
else {
- activity.startActivity(new Intent(activity, WebActivity.class).putExtras(bundle));
+ if (Utils.loadX5())
+ activity.startActivity(new Intent(activity, X5WebActivity.class).putExtras(bundle));
+ else
+ activity.startActivity(new Intent(activity, NormalWebActivity.class).putExtras(bundle));
activity.finish();
}
}
diff --git a/app/src/main/res/layout/activity_default_webview_normal.xml b/app/src/main/res/layout/activity_default_webview_normal.xml
new file mode 100644
index 0000000..3821fa8
--- /dev/null
+++ b/app/src/main/res/layout/activity_default_webview_normal.xml
@@ -0,0 +1,59 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_default_webview.xml b/app/src/main/res/layout/activity_default_webview_x5.xml
similarity index 97%
rename from app/src/main/res/layout/activity_default_webview.xml
rename to app/src/main/res/layout/activity_default_webview_x5.xml
index c9a06ca..68accc2 100644
--- a/app/src/main/res/layout/activity_default_webview.xml
+++ b/app/src/main/res/layout/activity_default_webview_x5.xml
@@ -50,7 +50,7 @@
android:progressDrawable="@drawable/pg"
android:visibility="gone" />
-
diff --git a/app/src/main/res/layout/activity_setting.xml b/app/src/main/res/layout/activity_setting.xml
index b35547e..8b25756 100644
--- a/app/src/main/res/layout/activity_setting.xml
+++ b/app/src/main/res/layout/activity_setting.xml
@@ -133,6 +133,40 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_webview.xml b/app/src/main/res/layout/activity_webview_x5.xml
similarity index 97%
rename from app/src/main/res/layout/activity_webview.xml
rename to app/src/main/res/layout/activity_webview_x5.xml
index d2e2fe4..2608228 100644
--- a/app/src/main/res/layout/activity_webview.xml
+++ b/app/src/main/res/layout/activity_webview_x5.xml
@@ -56,7 +56,7 @@
android:visibility="gone" />
-
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index e6127f6..7e11489 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -24,7 +24,7 @@
再按一次退出程序
注意事项
- 一些老番可能需要使用WebView播放(做了兼容但未测试,默认加载腾讯x5内核,首次可能会加载失败,尝试杀进程重启应用或卸载重装应用,若是你使用的设备版本太高则需等待官方适配后才能加载成功)。\n新番多数可以直接使用内置播放器或外部播放器播放(某些可能第一次播放失败,需多尝试几次)。\n注:并不是所有番剧都能正常播放(多为网站本身原因)~
+ 一些番剧可能需要使用WebView播放。\n新番多数可以直接使用内置播放器或外部播放器播放(某些可能第一次播放失败,需多尝试几次)。\n注:并不是所有番剧都能正常播放(多为网站本身原因)~
OJBK
未能获取到任何信息
@@ -69,6 +69,9 @@
自定义解析接口
0
+ X5内核(若webView闪退则需禁用该项)
+ 启用
+ 禁用
设置参数
确定
修改
@@ -117,7 +120,7 @@
OnePlus 7 Pro : Android 10
当前版本
最后编译日期
- 2019年10月14日
+ 2019年11月12日
缓存目录
/SakuraAnime/\n卸载后自行删除此目录
Github