--- /dev/null
+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;
+ }
+}