add shoot text provider.
authorTrillGates <williamtrillgates@gmail.com>
Wed, 4 Aug 2021 06:43:22 +0000 (14:43 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Wed, 4 Aug 2021 06:43:22 +0000 (14:43 +0800)
app/src/main/AndroidManifest.xml
app/src/main/java/com/enqualcomm/support/provider/ShootTextProvider.java [new file with mode: 0644]

index 3a2a862..cf4b15e 100644 (file)
             android:name=".provider.ICNotificationProvider"
             android:authorities="com.ic.notification"
             android:exported="true" />
+        
+        <provider
+            android:name=".provider.ShootTextProvider"
+            android:authorities="com.ic.shoot"
+            android:exported="true" />
 
     </application>
 
diff --git a/app/src/main/java/com/enqualcomm/support/provider/ShootTextProvider.java b/app/src/main/java/com/enqualcomm/support/provider/ShootTextProvider.java
new file mode 100644 (file)
index 0000000..fde93c2
--- /dev/null
@@ -0,0 +1,108 @@
+package com.enqualcomm.support.provider;
+
+import android.content.ContentProvider;
+import android.content.ContentResolver;
+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 ShootTextProvider extends ContentProvider {
+
+
+    public static final String PATH = "text";
+    //com.ic.warning.msg
+    public static final String AUTHORITY = "com.ic.shoot";
+    public static final String SHOOT_TEXT = "content://" + AUTHORITY + "/" + PATH;
+
+
+    private static UriMatcher sUriMatcher;
+
+    private static final int MATH_CODE_TABLE = 1;
+
+
+    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;
+    }
+
+    @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.tb_shoot_text_list,
+                    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);
+        SQLiteDatabase readableDatabase = mDatabase.getReadableDatabase();
+        if (match == MATH_CODE_TABLE) {
+            long insert = readableDatabase.insert(ICDatabaseHelper.tb_shoot_text_list,
+                    null, values);
+            //通知UI更新
+            ContentResolver contentResolver = getContext().getContentResolver();
+            if (contentResolver != null) {
+                contentResolver.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();
+            return writableDatabase.delete(ICDatabaseHelper.tb_shoot_text_list,
+                    selection, selectionArgs);
+        }
+        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.tb_shoot_text_list,
+                    values, selection, selectionArgs);
+            writableDatabase.close();
+            return update;
+        }
+        return 0;
+    }
+}