|
|
@@ -0,0 +1,128 @@
|
|
|
+package com.sheep.gamegroup.util;
|
|
|
+
|
|
|
+import android.app.Activity;
|
|
|
+import android.content.Intent;
|
|
|
+import android.net.Uri;
|
|
|
+import android.text.TextUtils;
|
|
|
+import android.webkit.JavascriptInterface;
|
|
|
+
|
|
|
+import com.sheep.gamegroup.model.entity.UserEntity;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.ClassFileHelper;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.G;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.PackageUtil;
|
|
|
+import com.sheep.jiuyan.samllsheep.utils.SpUtils;
|
|
|
+import com.zhy.http.okhttp.OkHttpUtils;
|
|
|
+import com.zhy.http.okhttp.callback.FileCallBack;
|
|
|
+
|
|
|
+import java.io.File;
|
|
|
+
|
|
|
+import okhttp3.Call;
|
|
|
+
|
|
|
+/**
|
|
|
+ * Created by ljy on 2018/6/25.
|
|
|
+ */
|
|
|
+
|
|
|
+public class WebviewJs {
|
|
|
+ private Activity activity;
|
|
|
+ private int taskId;
|
|
|
+
|
|
|
+ public WebviewJs(Activity activity) {
|
|
|
+ this.activity = activity;
|
|
|
+ }
|
|
|
+
|
|
|
+ public WebviewJs(Activity activity, int taskId) {
|
|
|
+ this.activity = activity;
|
|
|
+ this.taskId = taskId;
|
|
|
+ }
|
|
|
+
|
|
|
+ @JavascriptInterface
|
|
|
+ public void setTitle(final String title) {
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @JavascriptInterface
|
|
|
+ public void setCanGoBack() {
|
|
|
+ }
|
|
|
+
|
|
|
+ @JavascriptInterface
|
|
|
+ public void downloadFile(final String url, final String name) {
|
|
|
+ OkHttpUtils.get()
|
|
|
+ .url(url)
|
|
|
+ .build()
|
|
|
+ .execute(new FileCallBack(ClassFileHelper.DIR, name) {
|
|
|
+ @Override
|
|
|
+ public void onError(Call call, Exception e, int id) {
|
|
|
+ G.showToast("下载文件失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void onResponse(File response, int id) {
|
|
|
+ if (name.endsWith(".png") || name.endsWith(".jpg")) {//图片
|
|
|
+ Intent intent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
|
|
|
+ Uri uri = Uri.fromFile(response);
|
|
|
+ intent.setData(uri);
|
|
|
+ activity.sendBroadcast(intent); // 发送广播通知相册
|
|
|
+ }
|
|
|
+ G.showToast("下载文件成功");
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ @JavascriptInterface
|
|
|
+ public void startApp(String pkg, String cls) {
|
|
|
+ PackageUtil.startApp(activity, pkg);
|
|
|
+ }
|
|
|
+
|
|
|
+ @JavascriptInterface
|
|
|
+ public void gotoLogin() {
|
|
|
+ Jump2View.getInstance().gotoLoginAgain();
|
|
|
+ }
|
|
|
+ @JavascriptInterface
|
|
|
+ public void gotoWeb(String url, String title) {
|
|
|
+ if(!TextUtils.isEmpty(url)) {
|
|
|
+ if (TextUtils.isEmpty(title)) {
|
|
|
+ Jump2View.getInstance().goWeb(activity, url);//启动浏览器h5
|
|
|
+ } else {
|
|
|
+ Jump2View.getInstance().goWeb(activity, url, title);//进入小绵羊h5界面
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ @JavascriptInterface
|
|
|
+ public void gotoRecharge() {
|
|
|
+ Jump2View.getInstance().goRechargeAct(activity, null);//进入充值绵羊币界面
|
|
|
+ }
|
|
|
+
|
|
|
+ @JavascriptInterface
|
|
|
+ public String getInvitationCode(){
|
|
|
+ String invitationCode = "";
|
|
|
+ try{
|
|
|
+ UserEntity userEntity = MyDbManager.getInstance().dbFindUser();
|
|
|
+ invitationCode = userEntity.getInvitation_code();
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return invitationCode;
|
|
|
+ }
|
|
|
+ @JavascriptInterface
|
|
|
+ public String popShare(String url, String type) {
|
|
|
+ CommonUtil.getInstance().popShare(activity, url, type);
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+ @JavascriptInterface
|
|
|
+ public String getHeader() {
|
|
|
+ return SpUtils.getOpenId(activity);
|
|
|
+ }
|
|
|
+
|
|
|
+ @JavascriptInterface
|
|
|
+ public String getWcUrl(String url) {
|
|
|
+ if(!TextUtils.isEmpty(url)){
|
|
|
+ Jump2View.getInstance().goWeb(activity, url);
|
|
|
+ }
|
|
|
+ return "";
|
|
|
+ }
|
|
|
+
|
|
|
+ @JavascriptInterface
|
|
|
+ public int getTaskId(){
|
|
|
+ return taskId;
|
|
|
+ }
|
|
|
+}
|