data包中类的标注

pull/10/head
djq 11 months ago
parent 0b4628e50a
commit 1ec24dadf0

@ -1,79 +0,0 @@
/*
* 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.Context;
import android.database.Cursor;
import android.provider.ContactsContract.CommonDataKinds.Phone;
import android.provider.ContactsContract.Data;
import android.telephony.PhoneNumberUtils;
import android.util.Log;
import java.util.HashMap;
public class Contact {//联系人
//定义了一个静态的HashMap变量sContactCache和一个静态的字符串常量TAG。
private static HashMap<String, String> sContactCache;
private static final String TAG = "Contact";
//定义字符串常量CALLER_ID_SELECTION包含了整个查询的语句其中使用了安卓提供的一些函数和常量比如PHONE_NUMBERS_EQUAL函数和Phone.NUMBER常量。
//该查询语句作用是从小米设备的联系人数据库中设法获取和指定电话号码匹配的联系人的信息。
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 "
+ "(SELECT raw_contact_id "
+ " FROM phone_lookup"
+ " WHERE min_match = '+')";
//定义了一个getContact用来接收context对象和电话号码作为参数该方法先检查sContactCache中是否已经缓存了号码对应联系人信息是的话直接返回联系人姓名。
//否则就构造一个查询语句查询成功后将姓名缓存到sContactCache中,返回姓名失败的话就返回null
public static String getContact(Context context, String phoneNumber) {
if(sContactCache == null) {
sContactCache = new HashMap<String, String>();
}
if(sContactCache.containsKey(phoneNumber)) {
return sContactCache.get(phoneNumber);
}
//将电话号码中的"+"替换为最小匹配的呼叫者ID以生成新的查询条件。
//使用查询条件在联系人数据的URI(Data.CONTENT_URI)上进行查询,查询的结果只包含联系人的显示名称(Phone.DISPLAY_NAME)。
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);
//如果查询结果不为空将第一个结果的显示名称存储在缓存中并返回该名称否则记录日志并返回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;
}
}
}

@ -25,48 +25,77 @@ import android.util.Log;
import java.util.HashMap;
public class Contact {//联系人
//定义了一个静态的HashMap变量sContactCache和一个静态的字符串常量TAG。
private static HashMap<String, String> sContactCache;
private static final String TAG = "Contact";
//定义字符串常量CALLER_ID_SELECTION包含了整个查询的语句其中使用了安卓提供的一些函数和常量比如PHONE_NUMBERS_EQUAL函数和Phone.NUMBER常量。
//该查询语句作用是从小米设备的联系人数据库中设法获取和指定电话号码匹配的联系人的信息。
/**
* @Package: net.micode.notes.data
* @ClassName: Contact
* @Description:
* ContactgetContact
* 使
* @Author: Dong Jiaqi
* @CreateDate: 12/21/2023 19:31 PM
*/
public class Contact {
private static HashMap<String, String> sContactCache;//定义了一个静态的HashMap变量sContactCache
private static final String TAG = "Contact";//定义了一个静态的字符串常量TAG
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 "
+ "(SELECT raw_contact_id "
+ " FROM phone_lookup"
+ " WHERE min_match = '+')";
/*
*CALLER_ID_SELECTION,
*使PHONE_NUMBERS_EQUAL,使ID.
*/
//定义了一个getContact用来接收context对象和电话号码作为参数该方法先检查sContactCache中是否已经缓存了号码对应联系人信息是的话直接返回联系人姓名。
//否则就构造一个查询语句查询成功后将姓名缓存到sContactCache中,返回姓名失败的话就返回null
/**
* getContact,
* getContact2contextphoneNumber,Context,访;
* 3sContactCache.get(phoneNumber)sContactCacheHashMap
* name; nullIndexOutOfBoundsException
*/
public static String getContact(Context context, String phoneNumber) {
if(sContactCache == null) {
if(sContactCache == null) {//确保HashMap对象不会空始终指向一个实例化的HashMap对象
sContactCache = new HashMap<String, String>();
}
if(sContactCache.containsKey(phoneNumber)) {
return sContactCache.get(phoneNumber);
}
//将电话号码中的"+"替换为最小匹配的呼叫者ID以生成新的查询条件。
//使用查询条件在联系人数据的URI(Data.CONTENT_URI)上进行查询,查询的结果只包含联系人的显示名称(Phone.DISPLAY_NAME)。
String selection = CALLER_ID_SELECTION.replace("+",
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber));
PhoneNumberUtils.toCallerIDMinMatch(phoneNumber)); //获取电话号码的最小匹配形式比如字母换数字然后用replace方发将CALLER_ID_SELECTION中的"+"替换为最小匹配后的电话号码
Cursor cursor = context.getContentResolver().query(
Data.CONTENT_URI,
new String [] { Phone.DISPLAY_NAME },
selection,
new String[] { phoneNumber },
null);
/*
*context.getContentResolver()query()
*Data.CONTENT_URIData.CONTENT_URIURI
*new String []{Phone.DISPLAY_NAME}
*selection
*new String[] {phoneNumber}
*null
*/
//如果查询结果不为空将第一个结果的显示名称存储在缓存中并返回该名称否则记录日志并返回null。
//如果查询结果不为空,将第一个结果的显示名称存储在缓存中,并返回该名称;否则,记录到错误日志并返回null。
if (cursor != null && cursor.moveToFirst()) {
/*
* namesContactCache
* IndexOutOfBoundsExceptiondebug
* 使try-catch-finally
*
*/
try {
String name = cursor.getString(0);
sContactCache.put(phoneNumber, name);
return name;
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, " Cursor get string error " + e.toString());
Log.e(TAG, " Cursor get string error " + e.toString());//调用Log.e()方法,把错误信息写到日志。
return null;
} finally {
cursor.close();

@ -17,6 +17,18 @@
package net.micode.notes.data;
import android.net.Uri;
/**
* @Package: net.micode.notes.data
* @ClassName: Notes
* @Description:
* NotesURI
*
*
* ID IDID
* URI 便
* @Author: Dong Jiaqi
* @CreateDate: 12/22/2023 0:53 AM
*/
public class Notes {
public static final String AUTHORITY = "micode_notes";
public static final String TAG = "Notes";
@ -46,6 +58,7 @@ public class Notes {
public static final int TYPE_WIDGET_2X = 0;
public static final int TYPE_WIDGET_4X = 1;
//定义了一个静态内部类DataConstants包含2个变量NOTE和CALL_NOTE前者用于表示数据类型为文本笔记类型后者用于表示数据类型为通话类型
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 +74,10 @@ 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
@ -167,6 +184,10 @@ public class Notes {
public static final String VERSION = "version";
}
/**
* DataColumns
* 访使便
*/
public interface DataColumns {
/**
* The unique ID for a row
@ -241,28 +262,34 @@ public class Notes {
public static final String DATA5 = "data5";
}
/**
* TextNoteDataColumns
*/
public static final class TextNote implements DataColumns {
/**
* Mode to indicate the text in check list mode or not
* <P> Type: Integer 1:check list mode 0: normal mode </P>
*/
public static final String MODE = DATA1;
public static final String MODE = DATA1;//表示文本笔记的模式用来指示是否处于检查模式当中值为1表示检查模式为0表示普通模式
public static final int MODE_CHECK_LIST = 1;
public static final int MODE_CHECK_LIST = 1;//表示检查列表模式的常量值。
public static final String CONTENT_TYPE = "vnd.android.cursor.dir/text_note";
public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/text_note";
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note");
public static final Uri CONTENT_URI = Uri.parse("content://" + AUTHORITY + "/text_note");//表示文本笔记的内容URI用来访问和操作笔记中的数值是两者拼合成的URI
}
/**
* CallNoteDataColumns
*/
public static final class CallNote implements DataColumns {
/**
* Call date for this record
* <P> Type: INTEGER (long) </P>
*/
public static final String CALL_DATE = DATA1;
public static final String CALL_DATE = DATA1;//表示通话笔记的通话日期
/**
* Phone number for this record

@ -26,7 +26,17 @@ import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.DataConstants;
import net.micode.notes.data.Notes.NoteColumns;
/**
* @Package: net.micode.notes.data
* @ClassName: NotesDatabaseHelper
* @Description:
* 便NotesDatabaseHelper,SQLiteOpenHelper
* ,便
* 5
* 便
* @Author: Dong Jiaqi
* @CreateDate: 12/23/2023 0:44 AM
*/
public class NotesDatabaseHelper extends SQLiteOpenHelper {
private static final String DB_NAME = "note.db";
@ -61,7 +71,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
NoteColumns.ORIGIN_PARENT_ID + " INTEGER NOT NULL DEFAULT 0," +
NoteColumns.GTASK_ID + " TEXT NOT NULL DEFAULT ''," +
NoteColumns.VERSION + " INTEGER NOT NULL DEFAULT 0" +
")";
")";//这是用于创建便签表的SQL语句定义了便签表的结构包含便签各种属性和字段存储了用户创建的所有便签的信息。
private static final String CREATE_DATA_TABLE_SQL =
"CREATE TABLE " + TABLE.DATA + "(" +
@ -76,14 +86,14 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
DataColumns.DATA3 + " TEXT NOT NULL DEFAULT ''," +
DataColumns.DATA4 + " TEXT NOT NULL DEFAULT ''," +
DataColumns.DATA5 + " TEXT NOT NULL DEFAULT ''" +
")";
")";//这是用于定义数据表结构的SQL语句存储了与便签相关的数据信息包括了各种附加数据用来扩展便签功能。
private static final String CREATE_DATA_NOTE_ID_INDEX_SQL =
"CREATE INDEX IF NOT EXISTS note_id_index ON " +
TABLE.DATA + "(" + DataColumns.NOTE_ID + ");";
/**
* Increase folder's note count when move note to the folder
* 便便
*/
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER increase_folder_count_on_update "+
@ -95,7 +105,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
* Decrease folder's note count when move note from folder
* 便便
*/
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_UPDATE_TRIGGER =
"CREATE TRIGGER decrease_folder_count_on_update " +
@ -108,7 +118,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
* Increase folder's note count when insert new note to the folder
* 便便
*/
private static final String NOTE_INCREASE_FOLDER_COUNT_ON_INSERT_TRIGGER =
"CREATE TRIGGER increase_folder_count_on_insert " +
@ -120,7 +130,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
* Decrease folder's note count when delete note from the folder
* 便便
*/
private static final String NOTE_DECREASE_FOLDER_COUNT_ON_DELETE_TRIGGER =
"CREATE TRIGGER decrease_folder_count_on_delete " +
@ -133,7 +143,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
* Update note's content when insert data with type {@link DataConstants#NOTE}
* 便{@link DataConstants#NOTE}
*/
private static final String DATA_UPDATE_NOTE_CONTENT_ON_INSERT_TRIGGER =
"CREATE TRIGGER update_note_content_on_insert " +
@ -172,7 +182,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
* Delete datas belong to note which has been deleted
* 便
*/
private static final String NOTE_DELETE_DATA_ON_DELETE_TRIGGER =
"CREATE TRIGGER delete_data_on_delete " +
@ -183,7 +193,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
* Delete notes belong to folder which has been deleted
* 便
*/
private static final String FOLDER_DELETE_NOTES_ON_DELETE_TRIGGER =
"CREATE TRIGGER folder_delete_notes_on_delete " +
@ -194,7 +204,7 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
" END";
/**
* Move notes belong to folder which has been moved to trash folder
* 便
*/
private static final String FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER =
"CREATE TRIGGER folder_move_notes_on_trash " +
@ -210,6 +220,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
super(context, DB_NAME, null, DB_VERSION);
}
/**
* 便
* @param SQLiteDatabasedb便
*/
public void createNoteTable(SQLiteDatabase db) {
db.execSQL(CREATE_NOTE_TABLE_SQL);
reCreateNoteTableTriggers(db);
@ -217,6 +231,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
Log.d(TAG, "note table has been created");
}
/**
* 便便
* @param db
*/
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 +253,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL(FOLDER_MOVE_NOTES_ON_TRASH_TRIGGER);
}
/**
*
* @param db
*/
private void createSystemFolder(SQLiteDatabase db) {
ContentValues values = new ContentValues();
@ -277,6 +299,10 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
Log.d(TAG, "data table has been created");
}
/**
* 33
* @param db
*/
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 +313,15 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
db.execSQL(DATA_UPDATE_NOTE_CONTENT_ON_DELETE_TRIGGER);
}
/**
* NotesDatabaseHelper
* 访便使访
* @param context Context
* ,Context contextNoteDatabaseHelper
*
* @return mInstancenull
* mInstance
*/
static synchronized NotesDatabaseHelper getInstance(Context context) {
if (mInstance == null) {
mInstance = new NotesDatabaseHelper(context);
@ -300,11 +335,21 @@ public class NotesDatabaseHelper extends SQLiteOpenHelper {
createDataTable(db);
}
/**
* ,,
* @param db
* @param oldVersion
* @param newVersion
*/
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
boolean reCreateTriggers = false;
boolean skipV2 = false;
/**
*
*
*/
if (oldVersion == 1) {
upgradeToV2(db);
skipV2 = true; // this upgrade including the upgrade from v2 to v3

Loading…
Cancel
Save