|
@@ -0,0 +1,358 @@
|
|
|
+package com.guadou.cs_cptservices.ui;
|
|
|
+
|
|
|
+import android.annotation.SuppressLint;
|
|
|
+import android.content.Context;
|
|
|
+import android.content.Intent;
|
|
|
+import android.os.Bundle;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.view.KeyEvent;
|
|
|
+import android.view.View;
|
|
|
+import android.view.ViewGroup;
|
|
|
+import android.view.Window;
|
|
|
+import android.view.WindowManager;
|
|
|
+import android.webkit.JavascriptInterface;
|
|
|
+import android.widget.FrameLayout;
|
|
|
+import android.widget.ProgressBar;
|
|
|
+
|
|
|
+import com.guadou.cs_cptservices.R;
|
|
|
+import com.guadou.cs_cptservices.YYConstants;
|
|
|
+import com.guadou.cs_router.YYRouterService;
|
|
|
+import com.guadou.lib_baselib.base.activity.BaseVMActivity;
|
|
|
+import com.guadou.lib_baselib.base.vm.BaseViewModel;
|
|
|
+import com.guadou.lib_baselib.utils.CheckUtil;
|
|
|
+import com.guadou.lib_baselib.utils.CommUtils;
|
|
|
+import com.guadou.lib_baselib.utils.SPUtils;
|
|
|
+import com.guadou.lib_baselib.utils.StatusBarUtils;
|
|
|
+import com.guadou.lib_baselib.utils.log.YYLogUtils;
|
|
|
+import com.guadou.lib_baselib.view.LoadingDialogManager;
|
|
|
+import com.guadou.lib_baselib.view.MyWebView;
|
|
|
+import com.guadou.lib_baselib.view.titlebar.EasyTitleBar;
|
|
|
+import com.jeremyliao.liveeventbus.LiveEventBus;
|
|
|
+
|
|
|
+import androidx.annotation.Nullable;
|
|
|
+
|
|
|
+
|
|
|
+ * 兼职工作面试的加载Web容器
|
|
|
+ * 全屏的Web页面
|
|
|
+ */
|
|
|
+public class PartTimeTrainWebActivity extends BaseVMActivity<BaseViewModel> {
|
|
|
+
|
|
|
+ private String mWebtitle;
|
|
|
+ private String mWeburl;
|
|
|
+ private ProgressBar mPbWebView;
|
|
|
+ private FrameLayout mFlContent;
|
|
|
+ private MyWebView mWebView;
|
|
|
+ private boolean isHideTitleBar;
|
|
|
+ private EasyTitleBar mTitleBar;
|
|
|
+
|
|
|
+ private String mUrlEndWith;
|
|
|
+
|
|
|
+ public static void startInstance(String webtitle, String weburl) {
|
|
|
+ Context context = CommUtils.getContext();
|
|
|
+ if (context != null) {
|
|
|
+ Intent intent = new Intent(context, PartTimeTrainWebActivity.class);
|
|
|
+ intent.putExtra("webtitle", webtitle);
|
|
|
+ intent.putExtra("weburl", weburl);
|
|
|
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
+ context.startActivity(intent);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("context is null.please check it.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void startInstance(String webtitle, String weburl, boolean hideTitleBar) {
|
|
|
+ Context context = CommUtils.getContext();
|
|
|
+ if (context != null) {
|
|
|
+ Intent intent = new Intent(context, PartTimeTrainWebActivity.class);
|
|
|
+ intent.putExtra("webtitle", webtitle);
|
|
|
+ intent.putExtra("weburl", weburl);
|
|
|
+ intent.putExtra("hideTitleBar", hideTitleBar);
|
|
|
+ intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
|
+ context.startActivity(intent);
|
|
|
+ } else {
|
|
|
+ throw new RuntimeException("context is null.please check it.");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void init(@Nullable Bundle savedInstanceState) {
|
|
|
+
|
|
|
+ initView();
|
|
|
+ initTitles();
|
|
|
+ initWeb();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public int getLayoutIdRes() {
|
|
|
+ if (isHideTitleBar) {
|
|
|
+
|
|
|
+ requestWindowFeature(Window.FEATURE_NO_TITLE);
|
|
|
+
|
|
|
+ getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
|
|
+ }
|
|
|
+ return R.layout.activity_part_time_train_web;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void startObserve() {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void getDataFromIntent(Intent intent) {
|
|
|
+ super.getDataFromIntent(intent);
|
|
|
+ mWebtitle = intent.getStringExtra("webtitle");
|
|
|
+ mWeburl = intent.getStringExtra("weburl");
|
|
|
+ isHideTitleBar = intent.getBooleanExtra("hideTitleBar", false);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private void initTitles() {
|
|
|
+ if (isHideTitleBar) {
|
|
|
+ mTitleBar.setVisibility(View.GONE);
|
|
|
+ mPbWebView.setVisibility(View.GONE);
|
|
|
+ LoadingDialogManager.get().showLoading(this);
|
|
|
+ } else {
|
|
|
+ mTitleBar.setVisibility(View.VISIBLE);
|
|
|
+ mPbWebView.setVisibility(View.VISIBLE);
|
|
|
+ if (!CheckUtil.isEmpty(mWebtitle)) {
|
|
|
+
|
|
|
+ mTitleBar.setTitle(mWebtitle);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 根据百分比和起始颜色和结束颜色 计算当前的RGBA颜色
|
|
|
+ */
|
|
|
+ public int evaluate(float fraction, int startValue, int endValue) {
|
|
|
+ int startA = (startValue >> 24) & 0xff;
|
|
|
+ int startR = (startValue >> 16) & 0xff;
|
|
|
+ int startG = (startValue >> 8) & 0xff;
|
|
|
+ int startB = startValue & 0xff;
|
|
|
+
|
|
|
+ int endA = (endValue >> 24) & 0xff;
|
|
|
+ int endR = (endValue >> 16) & 0xff;
|
|
|
+ int endG = (endValue >> 8) & 0xff;
|
|
|
+ int endB = endValue & 0xff;
|
|
|
+
|
|
|
+ return ((startA + (int) (fraction * (endA - startA))) << 24) |
|
|
|
+ ((startR + (int) (fraction * (endR - startR))) << 16) |
|
|
|
+ ((startG + (int) (fraction * (endG - startG))) << 8) |
|
|
|
+ ((startB + (int) (fraction * (endB - startB))));
|
|
|
+ }
|
|
|
+
|
|
|
+ @SuppressLint("AddJavascriptInterface")
|
|
|
+ private void initWeb() {
|
|
|
+ FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
|
|
+ mWebView = new MyWebView(getApplicationContext());
|
|
|
+ mWebView.setLayoutParams(params);
|
|
|
+ mWebView.addJavascriptInterface(new H5NewCallBackAndroid(), "webkit");
|
|
|
+ mWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
|
|
+
|
|
|
+ int mHeight = CommUtils.dip2px(50);
|
|
|
+
|
|
|
+ mWebView.setMyWebViewScrollListener(new MyWebView.OnScrollListener() {
|
|
|
+ @Override
|
|
|
+ public void onScroll(int scrollY) {
|
|
|
+ if (scrollY >= 0 && scrollY <= mHeight) {
|
|
|
+
|
|
|
+ float percent = 0;
|
|
|
+ if (mHeight != 0) {
|
|
|
+ percent = scrollY / mHeight;
|
|
|
+ }
|
|
|
+
|
|
|
+ mTitleBar.setBackgroundColor(evaluate(percent, CommUtils.getColor(R.color.transparent), CommUtils.getColor(R.color.white)));
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ mTitleBar.setBackgroundColor(CommUtils.getColor(R.color.app_blue));
|
|
|
+
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ mWebView.setOnWebChangeListener(new MyWebView.OnWebChangeListener() {
|
|
|
+ @Override
|
|
|
+ public void titleChange(String title) {
|
|
|
+ if (CheckUtil.isEmpty(mWebtitle)) {
|
|
|
+
|
|
|
+ mTitleBar.setTitle(mWebtitle);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void progressChange(int newProgress) {
|
|
|
+ if (newProgress == 100) {
|
|
|
+
|
|
|
+ LoadingDialogManager.get().dismissLoading();
|
|
|
+ CommUtils.getHandler().postDelayed(() ->
|
|
|
+ mPbWebView.setVisibility(View.GONE), 200);
|
|
|
+
|
|
|
+ } else if (mPbWebView.getVisibility() == View.GONE) {
|
|
|
+ if (!isHideTitleBar) {
|
|
|
+ mPbWebView.setVisibility(View.VISIBLE);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (!isHideTitleBar) {
|
|
|
+
|
|
|
+ if (newProgress < 10) {
|
|
|
+ newProgress = 10;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onInnerLinkChecked() {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onWebLoadError() {
|
|
|
+
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ if (!TextUtils.isEmpty(mWeburl)) {
|
|
|
+ YYLogUtils.w("加载的网页地址:" + mWeburl);
|
|
|
+ mWebView.loadUrl(mWeburl);
|
|
|
+ }
|
|
|
+
|
|
|
+ mFlContent.addView(mWebView);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void initView() {
|
|
|
+
|
|
|
+ StatusBarUtils.immersive(mActivity);
|
|
|
+
|
|
|
+ String tokenStr = SPUtils.getInstance(CommUtils.getContext()).getString(YYConstants.USER_TOKEN, "");
|
|
|
+ int statusBarHeight = StatusBarUtils.getStatusBarHeight(mActivity);
|
|
|
+
|
|
|
+ mUrlEndWith = "?" + "token=" + tokenStr + "&statusBarHeight=" + statusBarHeight;
|
|
|
+
|
|
|
+ mPbWebView = findViewById(R.id.pb_web_view);
|
|
|
+ mFlContent = findViewById(R.id.fl_content);
|
|
|
+ mTitleBar = findViewById(R.id.easy_tittle_part_time_train_web);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ private class H5NewCallBackAndroid {
|
|
|
+
|
|
|
+ @JavascriptInterface
|
|
|
+ public void AdhocTrainingCompleted(Object object) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ String webUrl = "";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ webUrl = YYConstants.PART_TIME_TRAIN_RESULT_URL;
|
|
|
+
|
|
|
+
|
|
|
+ PartTimeTrainWebActivity.startInstance("Training Result", webUrl + mUrlEndWith);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ finish();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @JavascriptInterface
|
|
|
+ public void ToFillPersonalDetail(Object object) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ YYRouterService.INSTANCE.getParttimeComponentServer().startPartTimeJobEditProfileInfoActivity();
|
|
|
+
|
|
|
+
|
|
|
+ finish();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @JavascriptInterface
|
|
|
+ public void ToCheckMyTrainingDetails(Object object) {
|
|
|
+
|
|
|
+ String webUrl = "";
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ webUrl = YYConstants.PART_TIME_TRAIN_ANSWER_URL;
|
|
|
+
|
|
|
+
|
|
|
+ PartTimeTrainWebActivity.startInstance("Online Training", webUrl + mUrlEndWith);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 集成了系统的回退和网页的回退
|
|
|
+ */
|
|
|
+ public boolean onKeyDown(int keyCode, KeyEvent event) {
|
|
|
+ if ((keyCode == KeyEvent.KEYCODE_BACK) && mWebView.canGoBack()) {
|
|
|
+ mWebView.goBack();
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ return super.onKeyDown(keyCode, event);
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onPause() {
|
|
|
+ super.onPause();
|
|
|
+ if (mWebView != null) {
|
|
|
+ mWebView.onPause();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onResume() {
|
|
|
+ super.onResume();
|
|
|
+ if (mWebView != null) {
|
|
|
+ mWebView.onResume();
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ protected void onDestroy() {
|
|
|
+ super.onDestroy();
|
|
|
+ if (mWebView != null) {
|
|
|
+ mWebView.clearCache(true);
|
|
|
+ if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
|
|
|
+ if (mFlContent != null) {
|
|
|
+ mFlContent.removeView(mWebView);
|
|
|
+ }
|
|
|
+ mWebView.removeAllViews();
|
|
|
+ mWebView.destroy();
|
|
|
+ } else {
|
|
|
+ mWebView.removeAllViews();
|
|
|
+ mWebView.destroy();
|
|
|
+ if (mFlContent != null) {
|
|
|
+ mFlContent.removeView(mWebView);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ mWebView = null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+}
|