这里才是修改的部分,上一个是报告

zjh
zhangjinhan 8 months ago
parent ebb86149a9
commit 8f91162e7e

@ -25,10 +25,12 @@ import android.util.Log;
import java.util.HashMap;
// 联系人类,用于从设备中获取联系人信息
public class Contact {
private static HashMap<String, String> sContactCache;
private static final String TAG = "Contact";
private static HashMap<String, String> sContactCache; // 缓存联系人信息,以提高查询效率
private static final String TAG = "Contact"; // 日志标签
// 查询联系人时使用的 SQL 选择条件,确保电话号码匹配且 MIME 类型为电话号码类型
private static final String CALLER_ID_SELECTION = "PHONE_NUMBERS_EQUAL(" + Phone.NUMBER
+ ",?) AND " + Data.MIMETYPE + "='" + Phone.CONTENT_ITEM_TYPE + "'"
+ " AND " + Data.RAW_CONTACT_ID + " IN "
@ -36,6 +38,7 @@ public class Contact {
+ " FROM phone_lookup"
+ " WHERE min_match = '+')";
// 根据电话号码获取联系人姓名,首先检查缓存,然后查询数据库
public static String getContact(Context context, String phoneNumber) {
if(sContactCache == null) {
sContactCache = new HashMap<String, String>();

@ -17,6 +17,8 @@
package net.micode.notes.data;
import android.net.Uri;
// Notes 类定义了笔记应用中使用的常量和接口
public class Notes {
public static final String AUTHORITY = "micode_notes";
public static final String TAG = "Notes";
@ -46,6 +48,7 @@ public class Notes {
public static final int TYPE_WIDGET_2X = 0;
public static final int TYPE_WIDGET_4X = 1;
// DataConstants 类定义了不同类型的笔记数据常量
public static class DataConstants {
public static final String NOTE = TextNote.CONTENT_ITEM_TYPE;
public static final String CALL_NOTE = CallNote.CONTENT_ITEM_TYPE;
@ -61,6 +64,7 @@ public class Notes {
*/
public static final Uri CONTENT_DATA_URI = Uri.parse("content://" + AUTHORITY + "/data");
// NoteColumns 接口定义了笔记和文件夹的公共列名
public interface NoteColumns {
/**
* The unique ID for a row
@ -86,7 +90,6 @@ public class Notes {
*/
public static final String MODIFIED_DATE = "modified_date";
/**
* Alert date
* <P> Type: INTEGER (long) </P>
@ -167,6 +170,7 @@ public class Notes {
public static final String VERSION = "version";
}
// DataColumns 接口定义了笔记数据的公共列名
public interface DataColumns {
/**
* The unique ID for a row
@ -204,7 +208,6 @@ public class Notes {
*/
public static final String CONTENT = "content";
/**
* Generic data column, the meaning is {@link #MIMETYPE} specific, used for
* integer data type
@ -241,6 +244,7 @@ public class Notes {
public static final String DATA5 = "data5";
}
// TextNote 类定义了文本笔记的相关信息和 URI
public static final class TextNote implements DataColumns {
/**
* Mode to indicate the text in check list mode or not
@ -257,6 +261,7 @@ public class Notes {
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note");
}
// CallNote 类定义了通话记录相关的信息和 URI
public static final class CallNote implements DataColumns {
/**
* Call date for this record

@ -1,19 +1,3 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.data;
import android.content.ContentValues;
@ -26,7 +10,7 @@ import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.DataConstants;
import net.micode.notes.data.Notes.NoteColumns;
// NotesDatabaseHelper 类用于管理笔记应用的 SQLite 数据库
public class NotesDatabaseHelper extends SQLiteOpenHelper {
private static final String DB_NAME = "note.db";
@ -206,10 +190,12 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" WHERE " + NoteColumns.PARENT_ID + "=old." + NoteColumns.ID + ";" +
" END";
// 构造函数,初始化数据库名称和版本
public NotesDatabaseHelper(Context context) {
super(context, DB_NAME, null, DB_VERSION);
}
// 创建笔记表及其触发器,并插入系统文件夹
public void createNoteTable(SQLiteDatabase db) {
db.execSQL(CREATE_NOTE_TABLE_SQL);
reCreateNoteTableTriggers(db);
@ -217,6 +203,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
Log.d(TAG, "note table has been created");
}
// 重新创建笔记表的触发器
private void reCreateNoteTableTriggers(SQLiteDatabase db) {
db.execSQL("DROP TRIGGER IF EXISTS increase_folder_count_on_update");
db.execSQL("DROP TRIGGER IF EXISTS decrease_folder_count_on_update");
@ -235,6 +222,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER);
}
// 创建系统文件夹
private void createSystemFolder(SQLiteDatabase db) {
ContentValues values = new ContentValues();
@ -270,6 +258,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.insert(TABLE.NOTE, null, values);
}
// 创建数据表及其触发器,并创建索引
public void createDataTable(SQLiteDatabase db) {
db.execSQL(CREATE_DATA_TABLE_SQL);
reCreateDataTableTriggers(db);
@ -277,6 +266,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
Log.d(TAG, "data table has been created");
}
// 重新创建数据表的触发器
private void reCreateDataTableTriggers(SQLiteDatabase db) {
db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_insert");
db.execSQL("DROP TRIGGER IF EXISTS update_note_content_on_update");
@ -287,6 +277,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER);
}
// 获取 NotesDatabaseHelper 的单例实例
static synchronized NotesDatabaseHelper getInstance(Context context) {
if (mInstance == null) {
mInstance = new NotesDatabaseHelper(context);
@ -294,12 +285,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
return mInstance;
}
// 创建数据库时调用,初始化数据库结构
@Override
public void onCreate(SQLiteDatabase db) {
createNoteTable(db);
createDataTable(db);
}
// 数据库版本升级时调用,处理数据库结构的变更
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
boolean reCreateTriggers = false;
@ -333,6 +326,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
}
}
// 从版本 1 升级到版本 2重新创建表结构
private void upgradeToV2(SQLiteDatabase db) {
db.execSQL("DROP TABLE IF EXISTS " + TABLE.NOTE);
db.execSQL("DROP TABLE IF EXISTS " + TABLE.DATA);
@ -340,6 +334,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
createDataTable(db);
}
// 从版本 2 升级到版本 3添加系统回收站文件夹
private void upgradeToV3(SQLiteDatabase db) {
// drop unused triggers
db.execSQL("DROP TRIGGER IF EXISTS update_note_modified_date_on_insert");
@ -355,6 +350,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.insert(TABLE.NOTE, null, values);
}
// 从版本 3 升级到版本 4添加版本控制字段
private void upgradeToV4(SQLiteDatabase db) {
db.execSQL("ALTER TABLE " + TABLE.NOTE + " ADD COLUMN " + NoteColumns.VERSION
+ " INTEGER NOT NULL DEFAULT 0");

@ -16,7 +16,6 @@
package net.micode.notes.data;
import android.app.SearchManager;
import android.content.ContentProvider;
import android.content.ContentUris;
@ -34,7 +33,7 @@ import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.NotesDatabaseHelper.TABLE;
// NotesProvider 类继承自 ContentProvider负责处理与笔记数据相关的数据库操作
public class NotesProvider extends ContentProvider {
private static final UriMatcher mMatcher;
@ -79,12 +78,14 @@ public class NotesProvider extends ContentProvider {
+ " AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER
+ " AND " + NoteColumns.TYPE + "=" + Notes.TYPE_NOTE;
// 初始化 ContentProvider获取数据库帮助类实例
@Override
public boolean onCreate() {
mHelper = NotesDatabaseHelper.getInstance(getContext());
return true;
}
// 根据 URI 查询数据,返回 Cursor 对象
@Override
public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs,
String sortOrder) {
@ -147,6 +148,7 @@ public class NotesProvider extends ContentProvider {
return c;
}
// 插入新的笔记或笔记数据到数据库中
@Override
public Uri insert(Uri uri, ContentValues values) {
SQLiteDatabase db = mHelper.getWritableDatabase();
@ -181,6 +183,7 @@ public class NotesProvider extends ContentProvider {
return ContentUris.withAppendedId(uri, insertedId);
}
// 根据 URI 删除笔记或笔记数据
@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
int count = 0;
@ -227,6 +230,7 @@ public class NotesProvider extends ContentProvider {
return count;
}
// 根据 URI 更新笔记或笔记数据
@Override
public int update(Uri uri, ContentValues values, String selection, String[] selectionArgs) {
int count = 0;
@ -267,10 +271,12 @@ public class NotesProvider extends ContentProvider {
return count;
}
// 处理查询条件字符串
private String parseSelection(String selection) {
return (!TextUtils.isEmpty(selection) ? " AND (" + selection + ')' : "");
}
// 增加笔记的版本号
private void increaseNoteVersion(long id, String selection, String[] selectionArgs) {
StringBuilder sql = new StringBuilder(120);
sql.append("UPDATE ");
@ -296,6 +302,7 @@ public class NotesProvider extends ContentProvider {
mHelper.getWritableDatabase().execSQL(sql.toString());
}
// 返回与给定 URI 对应的 MIME 类型
@Override
public String getType(Uri uri) {
// TODO Auto-generated method stub

Loading…
Cancel
Save