From c9b3bbe2fe29926ef3a2f86178de9d3c1563c59b Mon Sep 17 00:00:00 2001 From: TrillGates Date: Mon, 13 Dec 2021 14:10:27 +0800 Subject: [PATCH] =?utf8?q?=E4=BF=9D=E5=AD=98=E7=99=BD=E5=90=8D=E5=8D=95?= =?utf8?q?=E7=9A=84=E8=81=94=E7=B3=BB=E4=BA=BA=E5=88=B0=E6=95=B0=E6=8D=AE?= =?utf8?q?=E5=BA=93=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../support/provider/ICMembersProvider.java | 125 ++++++++++++++++++ .../com/ic/protocols/protocol_beehome.java | 62 +++++---- 2 files changed, 155 insertions(+), 32 deletions(-) create mode 100644 app/src/main/java/com/enqualcomm/support/provider/ICMembersProvider.java diff --git a/app/src/main/java/com/enqualcomm/support/provider/ICMembersProvider.java b/app/src/main/java/com/enqualcomm/support/provider/ICMembersProvider.java new file mode 100644 index 00000000..bc79f211 --- /dev/null +++ b/app/src/main/java/com/enqualcomm/support/provider/ICMembersProvider.java @@ -0,0 +1,125 @@ +package com.enqualcomm.support.provider; + +import android.content.ContentProvider; +import android.content.ContentValues; +import android.content.UriMatcher; +import android.database.Cursor; +import android.database.sqlite.SQLiteDatabase; +import android.net.Uri; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; + +/** + * 音视频通话,通讯录列表 + */ +public class ICMembersProvider extends ContentProvider { + + private static UriMatcher sUriMatcher; + private static final int MATH_CODE_TABLE = 1; + + public static final String PATH = "members"; + //public static final String AUTHORITY = "com.ic.fzd.members"; + public static final String AUTHORITY = "com.ic.provider.member"; + public static final String MEMBERS = "content://" + AUTHORITY + "/" + PATH; + + static { + sUriMatcher = new UriMatcher(UriMatcher.NO_MATCH); + sUriMatcher.addURI(AUTHORITY, PATH, MATH_CODE_TABLE); + } + + private ICDatabaseHelper mDatabase; + + @Override + public boolean onCreate() { + mDatabase = new ICDatabaseHelper(getContext()); + return false; + } + + /** + * 查询数据 + * + * @param uri + * @param projection + * @param selection + * @param selectionArgs + * @param sortOrder + * @return + */ + @Nullable + @Override + public Cursor query(@NonNull Uri uri, + @Nullable String[] projection, + @Nullable String selection, + @Nullable String[] selectionArgs, + @Nullable String sortOrder) { + //匹配规则 + int match = sUriMatcher.match(uri); + SQLiteDatabase readableDatabase = mDatabase.getReadableDatabase(); + if (match == MATH_CODE_TABLE) { + return readableDatabase.query(ICDatabaseHelper.tMembers, + projection, + selection, + selectionArgs, + null, null, sortOrder); + } + return null; + } + + @Nullable + @Override + public String getType(@NonNull Uri uri) { + return null; + } + + @Nullable + @Override + public Uri insert(@NonNull Uri uri, + @Nullable ContentValues values) { + int match = sUriMatcher.match(uri); + if (match == MATH_CODE_TABLE) { + SQLiteDatabase writableDatabase = mDatabase.getWritableDatabase(); + //判断是否有存在吧,确保唯一,删除再添加吧,否则也是添加不进去的 + writableDatabase.delete(ICDatabaseHelper.tMembers, + ICDatabaseHelper.mId + "=?", new String[]{ + values.getAsString(ICDatabaseHelper.mId) + }); + long insert = writableDatabase.insert(ICDatabaseHelper.tMembers, null, values); + getContext().getContentResolver().notifyChange(uri, null); + return Uri.parse(AUTHORITY + "/" + PATH + "/" + insert); + } + return null; + } + + @Override + public int delete(@NonNull Uri uri, + @Nullable String selection, + @Nullable String[] selectionArgs) { + int match = sUriMatcher.match(uri); + if (match == MATH_CODE_TABLE) { + SQLiteDatabase writableDatabase = mDatabase.getWritableDatabase(); + int delete = writableDatabase.delete(ICDatabaseHelper.tMembers, selection, selectionArgs); + if (delete > 0 && getContext() != null) { + getContext().getContentResolver().notifyChange(uri, null); + } + return delete; + } + return 0; + } + + @Override + public int update(@NonNull Uri uri, + @Nullable ContentValues values, + @Nullable String selection, + @Nullable String[] selectionArgs) { + int match = sUriMatcher.match(uri); + if (match == MATH_CODE_TABLE) { + SQLiteDatabase writableDatabase = mDatabase.getWritableDatabase(); + int update = writableDatabase.update(ICDatabaseHelper.tMembers, values, selection, selectionArgs); + if (update > 0 && getContext() != null) { + getContext().getContentResolver().notifyChange(uri, null); + } + return update; + } + return 0; + } +} diff --git a/app/src/main/java/com/ic/protocols/protocol_beehome.java b/app/src/main/java/com/ic/protocols/protocol_beehome.java index 3479c800..ecd5405c 100644 --- a/app/src/main/java/com/ic/protocols/protocol_beehome.java +++ b/app/src/main/java/com/ic/protocols/protocol_beehome.java @@ -24,6 +24,7 @@ import com.enqualcomm.support.bean.VoiceContent; import com.enqualcomm.support.bean.voicePacket; import com.enqualcomm.support.provider.ICAlarmProvider; import com.enqualcomm.support.provider.ICDatabaseHelper; +import com.enqualcomm.support.provider.ICMembersProvider; import com.enqualcomm.support.service.HeartRateManager; import com.enqualcomm.support.service.SilentManager; import com.enqualcomm.support.utils.CellInfoUtil; @@ -938,20 +939,20 @@ public class protocol_beehome { //设置通讯录,白名单(10个) public void handleBP14(Connection connection, String cmd, Runtime runtime) { -// IWBP14,867155030001063,357444,9b44529b|13554820016,,,,,,,,, -/** - * IWBP14,353456789012345,080835, - * D3590D54|135xxxxxxxxxx, - * D3590D54|135xxxxxxxxxx, - * D3590D54|135xxxxxxxxxx, - * D3590D54|135xxxxxxxxxx, - * D3590D54|135xxxxxxxxxx, - * D3590D54|135xxxxxxxxxx, - * D3590D54|135xxxxxxxxxx, - * D3590D54|135xxxxxxxxxx, - * D3590D54|135xxxxxxxxxx, - * D3590D54|135xxxxxxxxxx# - */ + //IWBP14,867155030001063,357444,9b44529b|13554820016,,,,,,,,, + /** + * IWBP14,353456789012345,080835, + * D3590D54|135xxxxxxxxxx, + * D3590D54|135xxxxxxxxxx, + * D3590D54|135xxxxxxxxxx, + * D3590D54|135xxxxxxxxxx, + * D3590D54|135xxxxxxxxxx, + * D3590D54|135xxxxxxxxxx, + * D3590D54|135xxxxxxxxxx, + * D3590D54|135xxxxxxxxxx, + * D3590D54|135xxxxxxxxxx, + * D3590D54|135xxxxxxxxxx# + */ String[] cmdlist = cmd.split(CMDSPLIT); String[] phnums = new String[]{"", "", "", "", "", "", "", "", "", ""}; StringBuffer sb = new StringBuffer().append("recv phone Numbs "); @@ -998,25 +999,26 @@ public class protocol_beehome { String[] tmp = phnums[i].split("\\|"); if (tmp.length == 2) { String name = Util.decodeUnicode2Utf8(tmp[0]); - String phonem = tmp[1]; - ICLogger.i("phnums[" + i + "]=" + phnums[i] + ",split = " + tmp.length + " , name=" + name + ",-" + phonem); - contactArray.add(new Contact(Contact.CATEGORY_CALL, name, phonem)); + String phoneNum = tmp[1]; + //保存到数据库中 + ICLogger.i(i / 2 + " 姓名 " + name + ", 电话 " + phoneNum); + contactArray.add(new Contact(Contact.CATEGORY_CALL, name, phoneNum)); + ContentValues contentValues = new ContentValues(); + contentValues.put(ICDatabaseHelper.fType, ICDatabaseHelper.MemberType.WHITE_LIST); + contentValues.put(ICDatabaseHelper.fPhoneNum, phoneNum); + contentValues.put(ICDatabaseHelper.fID, phoneNum); + contentValues.put(ICDatabaseHelper.fUserName, name); + contentValues.put(ICDatabaseHelper.fCreateTime, System.currentTimeMillis()); + contentValues.put(ICDatabaseHelper.fUpdateTime, System.currentTimeMillis()); + //保存联系人列表,类型为白名单 + runtime.getContextProxy().getResolver().insert(Uri.parse(ICMembersProvider.MEMBERS), contentValues); } else { - ICLogger.i("phnums[" + i + "]=" + phnums[i] + ",split = " + tmp.length); - + ICLogger.i("phoneNumber[" + i + "]=" + phnums[i] + ",split = " + tmp.length); } } -// contactArray.add(new Contact(Contact.CATEGORY_GROUP,"All","666")); -// contactArray.add(new Contact(Contact.CATEGORY_PARTNER,"PARTNER","666")); -// contactArray.add(new Contact(Contact.CATEGORY_CARE,"CARE","666")); -// contactArray.add(new Contact(Contact.CATEGORY_VOLTE,"VOLTE","666")); - - runtime.getDbHelper().saveContacts(contactArray, false, false, true, false, false, false); - } else { ICLogger.i(" BP14 format error!"); } - } @@ -1105,7 +1107,7 @@ public class protocol_beehome { .append(", alarmtype=").append(alarmtype) .toString() ); - + //TODO: alarmlist.add(new Alarm("ST" + alarmtime.substring(0, 2) + "." + alarmtime.substring(2), "W" + repeat, "CON", alarmswitch == 1 ? "ON" : "OFF", "闹铃")); } else { @@ -1114,9 +1116,6 @@ public class protocol_beehome { } }//循环获取alarm数据结束 - runtime.getDbHelper().saveAlarm(alarmlist); - - //do clean and set alarm things } catch (Exception e) { ICLogger.e(e.getMessage(), e); } @@ -2283,7 +2282,6 @@ public class protocol_beehome { } - public void handleBPSQ(String cmd, Connection connection, Runtime runtime) { //IWBPSQ,353456789012345,080835,1,60# //说明: -- 2.17.1