|
|
@@ -1,29 +1,19 @@
|
|
|
package com.sheep.gamegroup.view.activity;
|
|
|
|
|
|
import android.app.Activity;
|
|
|
-import android.content.Context;
|
|
|
import android.content.Intent;
|
|
|
-import android.content.pm.ActivityInfo;
|
|
|
import android.content.res.Configuration;
|
|
|
-import android.graphics.PixelFormat;
|
|
|
-import android.os.Build;
|
|
|
import android.support.v4.widget.SwipeRefreshLayout;
|
|
|
import android.support.v7.widget.LinearLayoutManager;
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
import android.text.TextUtils;
|
|
|
-import android.util.Log;
|
|
|
import android.view.KeyEvent;
|
|
|
import android.view.LayoutInflater;
|
|
|
-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.webkit.WebViewClient;
|
|
|
import android.widget.EditText;
|
|
|
-import android.widget.FrameLayout;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.RelativeLayout;
|
|
|
import android.widget.TextView;
|
|
|
@@ -32,9 +22,9 @@ import com.sheep.gamegroup.absBase.BaseActivity;
|
|
|
import com.sheep.gamegroup.event.BigEvent;
|
|
|
import com.sheep.gamegroup.greendao.download.DownLoadInfo;
|
|
|
import com.sheep.gamegroup.helper.TaskHelper;
|
|
|
-import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
import com.sheep.gamegroup.model.entity.Applications;
|
|
|
import com.sheep.gamegroup.model.entity.Article;
|
|
|
+import com.sheep.gamegroup.model.entity.BaseMessage;
|
|
|
import com.sheep.gamegroup.model.util.SheepSubscriber;
|
|
|
import com.sheep.gamegroup.util.CommonUtil;
|
|
|
import com.sheep.gamegroup.util.DataUtil;
|
|
|
@@ -47,6 +37,7 @@ import com.sheep.gamegroup.util.SysAppUtil;
|
|
|
import com.sheep.gamegroup.util.TimeUtil;
|
|
|
import com.sheep.gamegroup.util.ViewHolder;
|
|
|
import com.sheep.gamegroup.util.ViewUtil;
|
|
|
+import com.sheep.gamegroup.util.viewHelper.WebViewVideoHelper;
|
|
|
import com.sheep.gamegroup.view.adapter.AdbCommonRecycler;
|
|
|
import com.sheep.jiuyan.samllsheep.R;
|
|
|
import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
@@ -84,16 +75,6 @@ public class ActArticle extends BaseActivity implements Action1<Integer> {
|
|
|
|
|
|
private int id;
|
|
|
|
|
|
- /**
|
|
|
- * 视频全屏参数
|
|
|
- */
|
|
|
-
|
|
|
-
|
|
|
- protected 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;
|
|
|
-
|
|
|
|
|
|
@BindView(R.id.refresh)
|
|
|
SwipeRefreshLayout refresh;
|
|
|
@@ -107,8 +88,7 @@ public class ActArticle extends BaseActivity implements Action1<Integer> {
|
|
|
RelativeLayout bottom;
|
|
|
//输入框
|
|
|
private EditText input_comment_input;
|
|
|
- WebView webView;
|
|
|
-
|
|
|
+ private WebViewVideoHelper webViewVideoHelper = new WebViewVideoHelper();
|
|
|
@Override
|
|
|
public void initView() {
|
|
|
id = getIntent().getIntExtra("id", 0);
|
|
|
@@ -191,162 +171,6 @@ public class ActArticle extends BaseActivity implements Action1<Integer> {
|
|
|
}
|
|
|
|
|
|
|
|
|
- public void initWebView() {
|
|
|
- WebSettings webSetting = webView.getSettings();
|
|
|
- webSetting.setJavaScriptEnabled(true);
|
|
|
- webSetting.setJavaScriptCanOpenWindowsAutomatically(true);
|
|
|
- webSetting.setAllowFileAccess(true);
|
|
|
- webSetting.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.NARROW_COLUMNS);
|
|
|
-// webSetting.setSupportZoom(true);
|
|
|
-// webSetting.setBuiltInZoomControls(true);
|
|
|
-// webSetting.setUseWideViewPort(true);
|
|
|
- //下面这行会影响setDownloadListener,暂时注释掉,等有空研究一下
|
|
|
-// webSetting.setSupportMultipleWindows(true);
|
|
|
- webSetting.setAppCacheEnabled(true);
|
|
|
- webSetting.setDatabaseEnabled(true);
|
|
|
- webSetting.setDomStorageEnabled(true);
|
|
|
- webSetting.setGeolocationEnabled(true);
|
|
|
- webSetting.setAppCacheMaxSize(Long.MAX_VALUE);
|
|
|
- webSetting.setPluginState(WebSettings.PluginState.ON_DEMAND);
|
|
|
- webSetting.setRenderPriority(WebSettings.RenderPriority.HIGH);
|
|
|
- webSetting.setCacheMode(android.webkit.WebSettings.LOAD_NO_CACHE);
|
|
|
-
|
|
|
-
|
|
|
- webSetting.setCacheMode(android.webkit.WebSettings.LOAD_DEFAULT);
|
|
|
- webSetting.setLoadWithOverviewMode(true);
|
|
|
- getWindow().setFormat(PixelFormat.TRANSLUCENT);
|
|
|
- webView.setWebChromeClient(new WebChromeClient() {
|
|
|
-
|
|
|
- /**视频播放相关的方法*
|
|
|
- *
|
|
|
- */
|
|
|
-
|
|
|
-
|
|
|
- @Override
|
|
|
- public View getVideoLoadingProgressView() {
|
|
|
- FrameLayout frameLayout = new FrameLayout(ActArticle.this);
|
|
|
- frameLayout.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
|
|
|
- return frameLayout;
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onShowCustomView(View view, CustomViewCallback callback) {
|
|
|
- super.onShowCustomView(view, callback);
|
|
|
- showCustomView(view, callback);
|
|
|
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);//设置横屏
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onHideCustomView() {
|
|
|
- hideCustomView();
|
|
|
- setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);//设置竖屏
|
|
|
- super.onHideCustomView();
|
|
|
- }
|
|
|
- });
|
|
|
- webView.setWebViewClient(new WebViewClient() {
|
|
|
- @Override
|
|
|
- public boolean shouldOverrideUrlLoading(WebView view, String url) {
|
|
|
- LogUtil.println(getClass().getSimpleName(), "shouldOverrideUrlLoading", url);
|
|
|
- //Android8.0以下的需要返回true 并且需要loadUrl;8.0之后效果相反
|
|
|
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
|
- return false;
|
|
|
- }
|
|
|
- webView.loadUrl(url);
|
|
|
- return true;
|
|
|
- }
|
|
|
- });
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 视频播放全屏
|
|
|
- */
|
|
|
-
|
|
|
- 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;
|
|
|
- }
|
|
|
-
|
|
|
- ActArticle.this.getWindow().getDecorView();
|
|
|
-
|
|
|
- FrameLayout decor = (FrameLayout) getWindow().getDecorView();
|
|
|
- fullscreenContainer = new FullscreenHolder(ActArticle.this);
|
|
|
- fullscreenContainer.addView(view, COVER_SCREEN_PARAMS);
|
|
|
- decor.addView(fullscreenContainer, COVER_SCREEN_PARAMS);
|
|
|
- customView = view;
|
|
|
- setStatusBarVisibility(false);
|
|
|
- customViewCallback = callback;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 隐藏视频全屏
|
|
|
- */
|
|
|
-
|
|
|
-
|
|
|
- private void hideCustomView() {
|
|
|
- if (customView == null) {
|
|
|
- return;
|
|
|
- }
|
|
|
-
|
|
|
- setStatusBarVisibility(true);
|
|
|
- FrameLayout decor = (FrameLayout) getWindow().getDecorView();
|
|
|
- decor.removeView(fullscreenContainer);
|
|
|
- fullscreenContainer = null;
|
|
|
- customView = null;
|
|
|
- customViewCallback.onCustomViewHidden();
|
|
|
- webView.setVisibility(View.VISIBLE);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 全屏容器界面
|
|
|
- */
|
|
|
-
|
|
|
-
|
|
|
- class FullscreenHolder extends FrameLayout {
|
|
|
-
|
|
|
- public FullscreenHolder(Context ctx) {
|
|
|
- super(ctx);
|
|
|
- setBackgroundColor(ctx.getResources().getColor(android.R.color.black));
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean onTouchEvent(MotionEvent evt) {
|
|
|
- switch (evt.getAction()) {
|
|
|
- case MotionEvent.ACTION_POINTER_UP:
|
|
|
- break;
|
|
|
- }
|
|
|
- return true;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- private void setStatusBarVisibility(boolean visible) {
|
|
|
- int flag = visible ? 0 : WindowManager.LayoutParams.FLAG_FULLSCREEN;
|
|
|
- getWindow().setFlags(flag, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
|
- Log.i("bar------", visible + "");
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public boolean onKeyUp(int keyCode, KeyEvent event) {
|
|
|
- switch (keyCode) {
|
|
|
- case KeyEvent.KEYCODE_BACK:
|
|
|
-/**回退键 事件处理 优先级:
|
|
|
- 视频播放全屏 - 网页回退 - 关闭页面*/
|
|
|
-
|
|
|
- if (customView != null) {
|
|
|
- hideCustomView();
|
|
|
- } else if (webView != null && webView.canGoBack()) {
|
|
|
- webView.goBack();
|
|
|
- } else {
|
|
|
- finish();
|
|
|
- }
|
|
|
- return true;
|
|
|
- default:
|
|
|
- return super.onKeyUp(keyCode, event);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
private void loadTop(View itemView) {
|
|
|
TextView find_information_name = (TextView) itemView.findViewById(R.id.find_information_name);
|
|
|
TextView find_information_time = (TextView) itemView.findViewById(R.id.find_information_time);
|
|
|
@@ -355,9 +179,8 @@ public class ActArticle extends BaseActivity implements Action1<Integer> {
|
|
|
ViewUtil.setText(find_information_time, String.format(Locale.CHINA, "发布时间:%s", TimeUtil.TimeStamp2Date(article.getCreated_at(), "yyyy-MM-dd HH:mm")));
|
|
|
ViewUtil.setText(find_information_look, article.getClicks());
|
|
|
|
|
|
- webView = itemView.findViewById(R.id.find_information_content_wb);
|
|
|
- initWebView();
|
|
|
- CommonUtil.getInstance().setDownloadListener(ActArticle.this, webView);
|
|
|
+ WebView webView = itemView.findViewById(R.id.find_information_content_wb);
|
|
|
+ webViewVideoHelper.init(this, webView);
|
|
|
ViewUtil.loadDataWithBaseURL(webView, article.getContent());
|
|
|
|
|
|
|
|
|
@@ -674,31 +497,40 @@ public class ActArticle extends BaseActivity implements Action1<Integer> {
|
|
|
protected void onResume() {
|
|
|
super.onResume();
|
|
|
taskHelper.onResume();
|
|
|
- try {
|
|
|
- if (webView != null) {
|
|
|
-// webView.resumeTimers();
|
|
|
- webView.onResume();
|
|
|
- webView.getClass().getMethod("onResume").invoke(webView, (Object[]) null);
|
|
|
- }
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
+ webViewVideoHelper.onResume();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public boolean onKeyUp(int keyCode, KeyEvent event) {
|
|
|
+ switch (keyCode) {
|
|
|
+ case KeyEvent.KEYCODE_BACK:
|
|
|
+ webViewVideoHelper.onBackUp();
|
|
|
+ return true;
|
|
|
+ default:
|
|
|
+ return super.onKeyUp(keyCode, event);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ public void onBackPressed() {
|
|
|
+ if(webViewVideoHelper.onBackPressed()){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ super.onBackPressed();
|
|
|
+ }
|
|
|
+ @Override
|
|
|
+ protected void onPause() {
|
|
|
+ super.onPause();
|
|
|
+ webViewVideoHelper.onPause();
|
|
|
+ }
|
|
|
@Override
|
|
|
protected void onDestroy() {
|
|
|
LogUtil.logI("释放资源");
|
|
|
EventBus.getDefault().unregister(this);
|
|
|
taskHelper.destroy();
|
|
|
- if (webView != null) {
|
|
|
-// webView.onPause();
|
|
|
-// webView.freeMemory();
|
|
|
-// webView.removeAllViews();
|
|
|
- webView.destroy();
|
|
|
-// webView = null;
|
|
|
- }
|
|
|
+ webViewVideoHelper.onDestroy();
|
|
|
super.onDestroy();
|
|
|
- ActArticle.this.finish();
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -710,29 +542,6 @@ public class ActArticle extends BaseActivity implements Action1<Integer> {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- @Override
|
|
|
- protected void onPause() {
|
|
|
- super.onPause();
|
|
|
- if (webView != null) {
|
|
|
- webView.onPause();
|
|
|
-// webView.pauseTimers();
|
|
|
- try {
|
|
|
- webView.getClass().getMethod("onPause").invoke(webView, (Object[]) null);
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- @Override
|
|
|
- public void onBackPressed() {
|
|
|
- if (webView != null && webView.canGoBack()) {
|
|
|
- webView.goBack();
|
|
|
- return;
|
|
|
- }
|
|
|
- super.onBackPressed();
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
@Override
|
|
|
public void onConfigurationChanged(Configuration config) {
|