diff --git a/Data包.java b/Data包.java deleted file mode 100644 index 7d702ac..0000000 --- a/Data包.java +++ /dev/null @@ -1,119 +0,0 @@ -Data包部分关键代码注释: -一、Contact类 -public static String getContact(Context context, String phoneNumber) { - // 检查缓存是否已初始化,若未初始化则创建一个新的 HashMap - if(sContactCache == null) { - sContactCache = new HashMap(); - } - - // 检查缓存中是否已存在该手机号对应的姓名 - if(sContactCache.containsKey(phoneNumber)) { - return sContactCache.get(phoneNumber); // 从缓存中获取并返回 - } - - // 构建查询条件 - String selection = CALLER_ID_SELECTION.replace("+", - PhoneNumberUtils.toCallerIDMinMatch(phoneNumber)); - - // 查询联系人数据库 - Cursor cursor = context.getContentResolver().query( - Data.CONTENT_URI, - new String [] { Phone.DISPLAY_NAME }, - selection, - new String[] { phoneNumber }, - null); - - // 处理查询结果 - if (cursor != null && cursor.moveToFirst()) { - try { - // 获取联系人姓名并缓存 - String name = cursor.getString(0); - sContactCache.put(phoneNumber, name); - return name; - } catch (IndexOutOfBoundsException e) { - // 日志记录异常 - Log.e(TAG, " Cursor get string error " + e.toString()); - return null; - } finally { - cursor.close(); // 确保关闭游标以释放资源 - } - } else { - Log.d(TAG, "No contact matched with number:" + phoneNumber); // 无匹配结果 - return null; - } -} -二、Notes类 -public static final String AUTHORITY = "micode_notes"; // 内容提供者的授权标识 - -public static final int TYPE_NOTE = 0; // 笔记类型 -public static final int TYPE_FOLDER = 1; // 文件夹类型 -public static final int TYPE_SYSTEM = 2; // 系统类型 - -// 定义系统文件夹的标识符 -public static final int ID_ROOT_FOLDER = 0; // 根文件夹 -public static final int ID_TEMPARAY_FOLDER = -1; // 临时文件夹 -public static final int ID_CALL_RECORD_FOLDER = -2; // 通话记录文件夹 - -// Uri 查询所有笔记和文件夹 -public static final Uri CONTENT_NOTE_URI = Uri.parse("content://" + AUTHORITY + "/note"); -// Uri 查询数据 -public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data"); -三、NotesDatabaseHelper类 -private static final String CREATE_NOTE_TABLE_SQL = // 创建笔记表的 SQL 语句 - "CREATE TABLE " + TABLE.NOTE + "(" + - NoteColumns.ID + " INTEGER PRIMARY KEY," + // 主键 ID - NoteColumns.PARENT_ID + " INTEGER NOT NULL DEFAULT 0," + // 父级 ID - NoteColumns.ALERTED_DATE + " INTEGER NOT NULL DEFAULT 0," + // 警报日期 - // 其他列定义... - ")"; - -public void createNoteTable(SQLiteDatabase db) { - db.execSQL(CREATE_NOTE_TABLE_SQL); // 执行创建笔记表的 SQL - reCreateNoteTableTriggers(db); // 重新创建触发器 - createSystemFolder(db); // 创建系统文件夹 -} - -@Override -public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - // 处理数据库版本升级逻辑 - if (oldVersion == 1) { - upgradeToV2(db); // 升级到版本 2 - oldVersion++; - } - // 其他升级逻辑... -} -四、NotesProvider类 -public boolean onCreate() { - mHelper = NotesDatabaseHelper.getInstance(getContext()); // 初始化数据库助手 - return true; -} - -public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { - Cursor c = null; - SQLiteDatabase db = mHelper.getReadableDatabase(); // 获取可读数据库 - switch (mMatcher.match(uri)) { // 根据 URI 进行不同的查询操作 - case URI_NOTE: - c = db.query(TABLE.NOTE, projection, selection, selectionArgs, null, null, sortOrder); // 查询笔记表 - break; - // 其他情况... - } - if (c != null) { - c.setNotificationUri(getContext().getContentResolver(), uri); // 设置通知 URI - } - return c; // 返回查询结果 -} - -public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) { - int count = 0; - SQLiteDatabase db = mHelper.getWritableDatabase(); // 获取可写数据库 - switch (mMatcher.match(uri)) { - case URI_NOTE: - count = db.update(TABLE.NOTE, values, selection, selectionArgs); // 更新笔记 - break; - // 其他情况... - } - if (count > 0) { - getContext().getContentResolver().notifyChange(uri, null); // 通知数据变化 - } - return count; // 返回更新的行数 -}