Просмотр исходного кода

添加获取通话记录的方法供js调用

zengjiebin лет назад: 7
Родитель
Сommit
63f8ce7782

+ 4 - 0
app/src/main/AndroidManifest.xml

@@ -91,8 +91,12 @@
     <uses-permission android:name="android.permission.CAMERA" />
     <uses-permission android:name="android.permission.RECORD_AUDIO" />
     <uses-permission android:name="android.permission.INTERNET" />
+    <!-- 读联系人权限 -->
     <uses-permission android:name="android.permission.READ_CONTACTS" />
+    <!-- 写联系人权限 -->
     <uses-permission android:name="android.permission.WRITE_CONTACTS" />
+    <!-- 读短信权限 -->
+    <uses-permission android:name="android.permission.READ_SMS" />
 
     <uses-feature android:name="android.hardware.camera" />
     <uses-feature android:name="android.hardware.camera.autofocus" />

+ 6 - 9
app/src/main/java/com/sheep/gamegroup/module/game/adapter/AdpAllWelfare.java

@@ -4,10 +4,9 @@ import android.support.annotation.Nullable;
 import android.widget.ImageView;
 import android.widget.TextView;
 
-import com.chad.library.adapter.base.BaseQuickAdapter;
-import com.chad.library.adapter.base.BaseViewHolder;
 import com.sheep.gamegroup.model.entity.Release_task;
 import com.sheep.gamegroup.model.entity.TaskEty;
+import com.sheep.gamegroup.util.Jump2View;
 import com.sheep.gamegroup.util.ViewHolder;
 import com.sheep.gamegroup.util.ViewUtil;
 import com.sheep.gamegroup.view.adapter.AdbCommonRecycler;
@@ -27,7 +26,7 @@ public class AdpAllWelfare extends AdbCommonRecycler<Release_task> {
 
     @Override
     public int getViewIdByType(int type) {
-        return R.layout.item_hp_refresh_welfare;
+        return R.layout.item_all_welfare;
     }
 
     @Override
@@ -38,14 +37,14 @@ public class AdpAllWelfare extends AdbCommonRecycler<Release_task> {
         TextView item_time_tv = holder.itemView.findViewById(R.id.item_time_tv);
         TextView item_info_tv = holder.itemView.findViewById(R.id.item_info_tv);
         TextView item_value_tv = holder.itemView.findViewById(R.id.item_value_tv);
-        TextView item_btn_tv = holder.itemView.findViewById(R.id.item_btn_tv);
+//        TextView item_btn_tv = holder.itemView.findViewById(R.id.item_btn_tv);
         TextView item_vip_tv = holder.itemView.findViewById(R.id.item_vip_tv);
 
-        if(release_task == null){
+        if (release_task == null) {
             return;
         }
         TaskEty taskEty = release_task.getTask();
-        if(taskEty == null){
+        if (taskEty == null) {
             return;
         }
         ViewUtil.setGameImage(item_icon_iv, taskEty.getIcon());
@@ -55,8 +54,6 @@ public class AdpAllWelfare extends AdbCommonRecycler<Release_task> {
         ViewUtil.setText(item_info_tv, release_task.getWelfareInfo());
         ViewUtil.setText(item_value_tv, release_task.getWelfareValue());
         ViewUtil.setVisibility(item_vip_tv, release_task.isVipWelfare());
-        ViewUtil.setOnClickListener(item_btn_tv, view -> {
-            //TODO 领取福利
-        });
+        ViewUtil.setOnClickListener(holder.itemView, view -> Jump2View.getInstance().goEntity(release_task));
     }
 }

+ 5 - 0
app/src/main/java/com/sheep/gamegroup/util/ContactUtil.java

@@ -44,6 +44,11 @@ public class ContactUtil {
                 map.put("mobile", number);
                 list.add(map);
             }
+            try {
+                cursor.close();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
         }
         return list;
     }

+ 8 - 1
app/src/main/java/com/sheep/gamegroup/util/Jump2View.java

@@ -1832,7 +1832,14 @@ public class Jump2View {
      */
     public void goEntity(Release_task item) {
         if(item != null){
-            goTaskDetailView(SheepApp.getInstance().getCurrentActivity(), item.getId());
+            switch (item.getTask().getTask_type()){
+                case 1019:
+                    goWeb(SheepApp.getInstance().getCurrentActivity(), new WebParams(Config.getUrlByPath(Config.PATH_WELFARE_DETAIL, "id", item.getId())).setTitle(item.getName()));
+                    break;
+                default:
+                    goTaskDetailView(SheepApp.getInstance().getCurrentActivity(), item.getId());
+                    break;
+            }
         }
     }
     /**

+ 116 - 0
app/src/main/java/com/sheep/gamegroup/util/SMSUtil.java

@@ -0,0 +1,116 @@
+package com.sheep.gamegroup.util;
+
+import android.content.ContentResolver;
+import android.content.Context;
+import android.database.Cursor;
+import android.net.Uri;
+import android.provider.CallLog;
+
+import com.alibaba.fastjson.JSONObject;
+import com.sheep.gamegroup.absBase.AbsObserver;
+import com.sheep.jiuyan.samllsheep.SheepApp;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import io.reactivex.Observable;
+import io.reactivex.ObservableOnSubscribe;
+import io.reactivex.android.schedulers.AndroidSchedulers;
+import io.reactivex.schedulers.Schedulers;
+import rx.functions.Action1;
+
+/**
+ * Created by realicing on 2019/3/27.
+ * realicing@sina.com
+ * 小绵羊3.5.3新增 -- 获取通话记录
+ */
+public class SMSUtil {
+    public static List<Map<String, Object>> getCallLog(Context context) {
+        List<Map<String, Object>> list = new ArrayList<>();
+        ContentResolver cr = context.getContentResolver();
+        if(cr == null){
+            return list;
+        }
+        Uri uri = CallLog.Calls.CONTENT_URI;
+        String[] projection = new String[] {
+                CallLog.Calls.CACHED_NAME// 通话记录的联系人
+                , CallLog.Calls.NUMBER// 通话记录的电话号码
+                , CallLog.Calls.DATE// 通话记录的日期
+                , CallLog.Calls.DURATION// 通话时长
+                , CallLog.Calls.TYPE// 通话类型
+        };
+        Cursor cursor = cr.query(uri, projection, null, null, null);
+        if (cursor != null) {
+            while (cursor.moveToNext()) {
+                Map<String, Object> map = new HashMap<>();
+                String name = cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_NAME));  //姓名
+                String number = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER));  //号码
+                long dateLong = cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DATE)); //获取通话日期
+                int duration = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.DURATION));//获取通话时长,值为多少秒
+                int type = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.TYPE)); //获取通话类型:1.呼入2.呼出3.未接
+                String date = TimeUtil.TimeStamp2Date(dateLong, "yyyy/MM/dd HH:mm");
+                map.put("name", name);
+                map.put("mobile", number);
+                map.put("date", date);
+                map.put("dateLong", dateLong);
+                map.put("duration", duration);
+                map.put("type", type);
+                list.add(map);
+            }
+            try {
+                cursor.close();
+            } catch (Exception e) {
+                e.printStackTrace();
+            }
+        }
+        return list;
+    }
+
+
+
+    public static void getCallLog(Action1<String> action1) {
+        JSONObject result = new JSONObject();
+        if(TestUtil.isDev()) {
+            result.put("explain",
+                    "String name = cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_NAME));  //姓名\n" +
+                            "String number = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER));  //号码\n" +
+                            "long dateLong = cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DATE)); //获取通话日期\n" +
+                            "int duration = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.DURATION));//获取通话时长,值为多少秒\n" +
+                            "int type = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.TYPE)); //获取通话类型:1.呼入2.呼出3.未接\n" +
+                            "String date = TimeUtil.TimeStamp2Date(dateLong, \"yyyy/MM/dd HH:mm\");");
+        }
+        Observable.create((ObservableOnSubscribe<JSONObject>) observableEmitter -> {
+            try {
+                long time = System.currentTimeMillis();
+                List<Map<String, Object>> list = getCallLog(SheepApp.getInstance());
+                result.put("code", 200);
+                result.put("msg", "获取通话记录成功");
+                result.put("takeTime", System.currentTimeMillis() - time);
+                result.put("data", list);
+                result.put("total", ListUtil.size(list));
+            } catch (Throwable throwable) {
+                throwable.printStackTrace();
+                result.put("code", 500);
+                result.put("msg", throwable.getMessage());
+            }
+            observableEmitter.onNext(result);
+        })
+                .subscribeOn(Schedulers.io())
+                .observeOn(AndroidSchedulers.mainThread())
+                .subscribe(new AbsObserver<JSONObject>() {
+                    @Override
+                    public void onNext(JSONObject result) {
+                        action1.call(result.toJSONString());
+                    }
+
+                    @Override
+                    public void onError(Throwable throwable) {
+                        result.put("code", 600);
+                        result.put("msg", throwable.getMessage());
+                        action1.call(result.toJSONString());
+                    }
+                });
+    }
+}

+ 5 - 0
app/src/main/java/com/sheep/gamegroup/util/js/KFZSJs.java

@@ -26,6 +26,7 @@ import com.sheep.gamegroup.util.Jump2View;
 import com.sheep.gamegroup.util.LogUtil;
 import com.sheep.gamegroup.util.MainTab;
 import com.sheep.gamegroup.util.QQUtil;
+import com.sheep.gamegroup.util.SMSUtil;
 import com.sheep.gamegroup.util.SysAppUtil;
 import com.sheep.gamegroup.util.ViewUtil;
 import com.sheep.gamegroup.util.share.ShareLinkConfig;
@@ -413,4 +414,8 @@ public class KFZSJs {
     public void getAllContact() {
         ContactUtil.getAllContactList(result -> activity.loadJs(String.format(Locale.CHINA, "onGetAllContact('%s')", result)));
     }
+    @JavascriptInterface
+    public void getAllCallLog() {
+        SMSUtil.getCallLog(result -> activity.loadJs(String.format(Locale.CHINA, "onGetAllCallLog('%s')", result)));
+    }
 }

+ 13 - 3
app/src/main/java/com/sheep/jiuyan/samllsheep/Config.java

@@ -2,6 +2,7 @@ package com.sheep.jiuyan.samllsheep;
 
 import android.text.TextUtils;
 
+import com.sheep.gamegroup.util.StringUtils;
 import com.sheep.gamegroup.util.TestUtil;
 import com.sheep.gamegroup.util.js.BaseActWeb;
 
@@ -43,6 +44,8 @@ public class Config {
     private static final String STATION_APPOINT_TASK = "/appoint_task/#";
     //随便打
     private static final String STATION_SUI_BIAN_DA = "/casual_call/#";
+    //福利
+    private static final String STATION_WELFARE = "/small_sheep_welfare/#";
 
     //path
     //有范商城地址的 key
@@ -75,6 +78,8 @@ public class Config {
     public static final String PATH_APPOINT_TASK_LIST = STATION_APPOINT_TASK + "/appoint-task-list";
     //随便打首页
     public static final String PATH_SBD_HOME = STATION_SUI_BIAN_DA + "/";
+    //福利
+    public static final String PATH_WELFARE_DETAIL = STATION_WELFARE + "/detail";
     //small_station地址 key
     public static final String KEY_SMALL_STATION_URL = "small_station_url";
     //small_station地址
@@ -89,12 +94,17 @@ public class Config {
     public static void initSMALL_STATION_URL(){
         SMALL_STATION_URL = TextUtils.equals(SheepApp.getInstance().getConnectAddress().name(), "sheep") ? SMALL_STATION_URL_SHEEP : SMALL_STATION_URL_TEST;
     }
-    public static String getUrlByPath(String path, String...query){
+    public static String getUrlByPath(String path, Object...query){
         String url = SMALL_STATION_URL + path;
         if(query != null && query.length > 0){
-            for (int i = 0; i + 1 < query.length; ) {
-                url = BaseActWeb.addUrlQuery(url, query[i++], query[i++]);
+            StringBuilder stringBuilder = new StringBuilder(url);
+            for (int i = 0; i + 1 < query.length;) {
+                stringBuilder.append(i == 0 && !url.contains("?") ? "?" : "&");
+                stringBuilder.append(query[i++]);
+                stringBuilder.append("=");
+                stringBuilder.append(query[i++]);
             }
+            return stringBuilder.toString();
         }
         return url;
     }

+ 11 - 3
app/src/main/res/layout/item_all_welfare.xml

@@ -38,14 +38,18 @@
 
     <TextView
         android:id="@+id/item_name_tv"
-        android:layout_width="wrap_content"
+        android:layout_width="0dp"
         android:layout_height="wrap_content"
+        android:maxLines="2"
+        android:ellipsize="end"
         android:layout_marginStart="5dp"
+        android:layout_marginEnd="5dp"
         android:text="王者荣耀皮肤"
         android:textColor="#ff333333"
         android:textSize="14sp"
         app:layout_constraintBottom_toBottomOf="@id/item_song_iv"
         app:layout_constraintStart_toEndOf="@id/item_song_iv"
+        app:layout_constraintEnd_toStartOf="@id/item_value_tv"
         app:layout_constraintTop_toTopOf="@id/item_song_iv" />
 
     <TextView
@@ -61,13 +65,17 @@
 
     <TextView
         android:id="@+id/item_info_tv"
-        android:layout_width="wrap_content"
+        android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:text="内容:xx皮肤、xx皮肤"
         android:textColor="#ff999999"
+        android:singleLine="true"
+        android:ellipsize="end"
         android:textSize="11sp"
+        android:layout_marginEnd="5dp"
         app:layout_constraintBottom_toBottomOf="@id/item_icon_iv"
-        app:layout_constraintStart_toStartOf="@id/item_song_iv" />
+        app:layout_constraintStart_toStartOf="@id/item_song_iv"
+        app:layout_constraintEnd_toStartOf="@id/item_vip_tv"/>
 
     <TextView
         android:id="@+id/item_value_tv"

+ 1 - 1
app/src/main/res/values/str_appstore_strings.xml

@@ -14,7 +14,7 @@
     <string name="personal_center">个人中心</string>
     <string name="main_tab_find">发现</string>
     <string name="main_tab_invite">邀请</string>
-    <string name="main_tab_make_money">赚钱</string>
+    <string name="main_tab_make_money">首页</string>
 
 
     <string name="toast_download_task_out_of_rang">请稍候,最多可同时下载%s款游戏哦</string>