| | |
| | | package com.weikou.beibeivideo.util.browser; |
| | | |
| | | import android.app.Activity; |
| | | import android.app.Dialog; |
| | | import android.content.Intent; |
| | | import android.content.pm.PackageManager; |
| | | import android.support.v4.content.ContextCompat; |
| | | import androidx.core.content.ContextCompat; |
| | | import android.webkit.JavascriptInterface; |
| | | import android.widget.ImageView; |
| | | import android.widget.TextView; |
| | | |
| | | import com.lcjian.library.util.common.StringUtils; |
| | | import com.tencent.smtt.sdk.WebView; |
| | | import com.weikou.beibeivideo.entity.JumpDetail; |
| | | import com.weikou.beibeivideo.ui.dialog.LoadingDialogUtil; |
| | | import com.weikou.beibeivideo.ui.login.LoginActivity; |
| | | import com.weikou.beibeivideo.ui.login.PhoneLoginActivity; |
| | | import com.weikou.beibeivideo.util.AlibcTradeUtil; |
| | | import com.weikou.beibeivideo.util.JumpActivityUtil; |
| | | |
| | |
| | | TextView tv_top_bar_middle, tv_top_bar_left2, tv_top_bar_right; |
| | | ImageView iv_right; |
| | | WebView webview; |
| | | private boolean boo = false; |
| | | private Dialog loadingDialog; |
| | | |
| | | public BWJavaInterface(Activity activity, WebView webview) { |
| | | super(activity); |
| | | mContext = activity; |
| | | this.webview = webview; |
| | | boo = true; |
| | | loadingDialog = LoadingDialogUtil.getLoadingDialog(activity, ""); |
| | | } |
| | | |
| | | |
| | | public BWJavaInterface(Activity activity, TextView tv_top_bar_middle |
| | | , TextView tv_top_bar_left2, TextView tv_top_bar_right |
| | |
| | | this.tv_top_bar_right = tv_top_bar_right; |
| | | this.iv_right = iv_right; |
| | | this.webview = webview; |
| | | loadingDialog = LoadingDialogUtil.getLoadingDialog(activity, ""); |
| | | } |
| | | |
| | | |
| | | @JavascriptInterface |
| | | public void showLoading() { |
| | | if (loadingDialog != null && !loadingDialog.isShowing() && mContext != null) { |
| | | |
| | | mContext.runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | loadingDialog.show(); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | @JavascriptInterface |
| | | public void hideLoading() { |
| | | if (loadingDialog != null && loadingDialog.isShowing() && mContext != null) { |
| | | mContext.runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | loadingDialog.dismiss(); |
| | | } |
| | | }); |
| | | } |
| | | } |
| | | |
| | | @JavascriptInterface |
| | | public void setTitle(final String title) { |
| | | // tv_top_bar_middle.setText(title); |
| | | if (!boo) |
| | | if (tv_top_bar_middle != null) |
| | | tv_top_bar_middle.post(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | |
| | | } |
| | | } |
| | | mContext.startActivity(intent); |
| | | if (!boo) |
| | | mContext.finish(); |
| | | mContext.finish(); |
| | | } |
| | | |
| | | @JavascriptInterface |
| | | public void finishPage() { |
| | | if (!boo) |
| | | iv_right.post(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | mContext.finish(); |
| | | } |
| | | }); |
| | | mContext.runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | mContext.finish(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | |
| | | @JavascriptInterface |
| | | public void finishPageWithResultOK() { |
| | | mContext.runOnUiThread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | mContext.setResult(Activity.RESULT_OK); |
| | | mContext.finish(); |
| | | } |
| | | }); |
| | | } |
| | | |
| | | /** |
| | |
| | | if (StringUtils.isEmpty(url)) |
| | | return; |
| | | AlibcTradeUtil.openAuthLink(mContext, url); |
| | | } |
| | | |
| | | /** |
| | | * 登录 |
| | | */ |
| | | @JavascriptInterface |
| | | public void login() { |
| | | Intent intent = new Intent(mContext, LoginActivity.class); |
| | | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| | | mContext.startActivity(intent); |
| | | } |
| | | |
| | | |
| | | @JavascriptInterface |
| | | public void jumpWeb() { |
| | | Intent intent = new Intent(mContext, LoginActivity.class); |
| | | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| | | mContext.startActivity(intent); |
| | | } |
| | | |
| | | /** |
| | | * 电话号码绑定 |
| | | */ |
| | | @JavascriptInterface |
| | | public void bindPhone() { |
| | | Intent intent = new Intent(mContext, PhoneLoginActivity.class); |
| | | intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); |
| | | intent.putExtra("login", false); |
| | | mContext.startActivity(intent); |
| | | } |
| | | |
| | | /** |
| | | * 跳转微信小程序 |
| | | * |
| | | * @param userName |
| | | * @param path |
| | | */ |
| | | @JavascriptInterface |
| | | public void jumpWXXCX(String userName, String path) { |
| | | JumpDetail jumpDetail = new JumpDetail(); |
| | | jumpDetail.setType("wxxcx"); |
| | | com.alibaba.fastjson.JSONObject params = new com.alibaba.fastjson.JSONObject(); |
| | | params.put("userName", userName); |
| | | params.put("path", path); |
| | | JumpActivityUtil.jumpPage(mContext, jumpDetail, params); |
| | | } |
| | | |
| | | // 判断权限集合 是否授权 false授权 true未授权 |
| | |
| | | //权限未授权 |
| | | return ContextCompat.checkSelfPermission(mContext, permission) == PackageManager.PERMISSION_DENIED; |
| | | } |
| | | |
| | | |
| | | } |