|
|
@ -13,9 +13,9 @@
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*该类定义在 net.micode.notes.tool 包下,并导入了Android和Java的一些核心类。这些导入的类提供了对内容提供者操作、日志记录、游标以及存储值的支持。 */
|
|
|
|
package net.micode.notes.tool;
|
|
|
|
package net.micode.notes.tool;
|
|
|
|
|
|
|
|
/*定义了一个公共类 DataUtils,并创建了一个常量 TAG 用于日志记录。 */
|
|
|
|
import android.content.ContentProviderOperation;
|
|
|
|
import android.content.ContentProviderOperation;
|
|
|
|
import android.content.ContentProviderResult;
|
|
|
|
import android.content.ContentProviderResult;
|
|
|
|
import android.content.ContentResolver;
|
|
|
|
import android.content.ContentResolver;
|
|
|
@ -34,7 +34,9 @@ import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*这个方法实现了根据一组ID批量删除笔记的功能。
|
|
|
|
|
|
|
|
它首先检查ID集合是否为空,并创建一个操作列表。
|
|
|
|
|
|
|
|
通过 ContentResolver 执行删除操作,成功后返回 true,失败则返回 false。 */
|
|
|
|
public class DataUtils {
|
|
|
|
public class DataUtils {
|
|
|
|
public static final String TAG = "DataUtils";
|
|
|
|
public static final String TAG = "DataUtils";
|
|
|
|
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) {
|
|
|
|
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) {
|
|
|
@ -71,7 +73,9 @@ public class DataUtils {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*此方法将指定的笔记移动到目标文件夹。
|
|
|
|
|
|
|
|
更新笔记的父文件夹ID并标记为本地修改。 */
|
|
|
|
|
|
|
|
/*查询非系统文件夹的数量。异常处理用于确保在查询失败时释放游标资源。 */
|
|
|
|
public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) {
|
|
|
|
public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) {
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
values.put(NoteColumns.PARENT_ID, desFolderId);
|
|
|
|
values.put(NoteColumns.PARENT_ID, desFolderId);
|
|
|
@ -88,7 +92,15 @@ public class DataUtils {
|
|
|
|
* @param: [resolver, ids, folderId]
|
|
|
|
* @param: [resolver, ids, folderId]
|
|
|
|
* @return: boolean
|
|
|
|
* @return: boolean
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids, long folderId) {
|
|
|
|
/*检查数据库中是否存在特定类型的可见笔记。 */
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 批量将便签移动到指定文件夹
|
|
|
|
|
|
|
|
* @param resolver ContentResolver对象
|
|
|
|
|
|
|
|
* @param ids 需要移动的便签ID集合
|
|
|
|
|
|
|
|
* @param folderId 目标文件夹ID
|
|
|
|
|
|
|
|
* @return 是否移动成功
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids, long folderId) {
|
|
|
|
if (ids == null) {
|
|
|
|
if (ids == null) {
|
|
|
|
Log.d(TAG, "the ids is null");
|
|
|
|
Log.d(TAG, "the ids is null");
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
@ -116,12 +128,14 @@ public class DataUtils {
|
|
|
|
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
|
|
|
|
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Get the all folder count except system folders {@link Notes#TYPE_SYSTEM}}
|
|
|
|
* 获取用户文件夹的数量(不包括系统文件夹)
|
|
|
|
|
|
|
|
* @param resolver ContentResolver对象
|
|
|
|
|
|
|
|
* @return 用户文件夹的数量
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public static int getUserFolderCount(ContentResolver resolver) {
|
|
|
|
public static int getUserFolderCount(ContentResolver resolver) {
|
|
|
|
Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI,
|
|
|
|
Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI,
|
|
|
|
new String[] { "COUNT(*)" },
|
|
|
|
new String[] { "COUNT(*)" },
|
|
|
|
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?",
|
|
|
|
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?",
|
|
|
@ -141,23 +155,16 @@ public class DataUtils {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
|
|
|
|
* @Method visibleInNoteDatabase
|
|
|
|
/**
|
|
|
|
* @Date 2024/12/13 9:08
|
|
|
|
* 检查数据库中是否存在指定ID和类型的便签
|
|
|
|
* @param resolver
|
|
|
|
* @param resolver ContentResolver对象
|
|
|
|
* @param noteId
|
|
|
|
* @param noteId 便签ID
|
|
|
|
* @param type
|
|
|
|
* @param type 便签类型
|
|
|
|
* @Author lenovo
|
|
|
|
* @return 是否存在
|
|
|
|
* @Return boolean
|
|
|
|
|
|
|
|
* @Description 访问数据库中是否有 noteId 对应的便签
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) {
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
|
|
* withAppendedId 将 URI 和 ID 连接成一个新的URI
|
|
|
|
|
|
|
|
* query 返回 Uri 中符合 selection 的表格
|
|
|
|
|
|
|
|
* lenovo 2024/12/13 9:06
|
|
|
|
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) {
|
|
|
|
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
|
|
|
|
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER,
|
|
|
|
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER,
|
|
|
@ -172,9 +179,15 @@ public class DataUtils {
|
|
|
|
cursor.close();
|
|
|
|
cursor.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return exist;
|
|
|
|
return exist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 检查数据库中是否存在指定ID的便签
|
|
|
|
|
|
|
|
* @param resolver ContentResolver对象
|
|
|
|
|
|
|
|
* @param noteId 便签ID
|
|
|
|
|
|
|
|
* @return 是否存在
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {
|
|
|
|
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
|
|
|
|
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
|
|
|
|
null, null, null, null);
|
|
|
|
null, null, null, null);
|
|
|
|
|
|
|
|
|
|
|
@ -186,9 +199,15 @@ public class DataUtils {
|
|
|
|
cursor.close();
|
|
|
|
cursor.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return exist;
|
|
|
|
return exist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 检查数据库中是否存在指定ID的数据
|
|
|
|
|
|
|
|
* @param resolver ContentResolver对象
|
|
|
|
|
|
|
|
* @param dataId 数据ID
|
|
|
|
|
|
|
|
* @return 是否存在
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {
|
|
|
|
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId),
|
|
|
|
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId),
|
|
|
|
null, null, null, null);
|
|
|
|
null, null, null, null);
|
|
|
|
|
|
|
|
|
|
|
@ -200,9 +219,15 @@ public class DataUtils {
|
|
|
|
cursor.close();
|
|
|
|
cursor.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return exist;
|
|
|
|
return exist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static boolean checkVisibleFolderName(ContentResolver resolver, String name) {
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 检查数据库中是否存在指定名称的可见文件夹
|
|
|
|
|
|
|
|
* @param resolver ContentResolver对象
|
|
|
|
|
|
|
|
* @param name 文件夹名称
|
|
|
|
|
|
|
|
* @return 是否存在
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static boolean checkVisibleFolderName(ContentResolver resolver, String name) {
|
|
|
|
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null,
|
|
|
|
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null,
|
|
|
|
NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER +
|
|
|
|
NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER +
|
|
|
|
" AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER +
|
|
|
|
" AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER +
|
|
|
@ -216,9 +241,15 @@ public class DataUtils {
|
|
|
|
cursor.close();
|
|
|
|
cursor.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return exist;
|
|
|
|
return exist;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static HashSet<AppWidgetAttribute> getFolderNoteWidget(ContentResolver resolver, long folderId) {
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 获取指定文件夹中的小部件属性集合
|
|
|
|
|
|
|
|
* @param resolver ContentResolver对象
|
|
|
|
|
|
|
|
* @param folderId 文件夹ID
|
|
|
|
|
|
|
|
* @return 小部件属性集合
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static HashSet<AppWidgetAttribute> getFolderNoteWidget(ContentResolver resolver, long folderId) {
|
|
|
|
Cursor c = resolver.query(Notes.CONTENT_NOTE_URI,
|
|
|
|
Cursor c = resolver.query(Notes.CONTENT_NOTE_URI,
|
|
|
|
new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE },
|
|
|
|
new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE },
|
|
|
|
NoteColumns.PARENT_ID + "=?",
|
|
|
|
NoteColumns.PARENT_ID + "=?",
|
|
|
@ -243,9 +274,15 @@ public class DataUtils {
|
|
|
|
c.close();
|
|
|
|
c.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return set;
|
|
|
|
return set;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 根据便签ID获取电话号码
|
|
|
|
|
|
|
|
* @param resolver ContentResolver对象
|
|
|
|
|
|
|
|
* @param noteId 便签ID
|
|
|
|
|
|
|
|
* @return 电话号码
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {
|
|
|
|
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
|
|
|
|
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
|
|
|
|
new String [] { CallNote.PHONE_NUMBER },
|
|
|
|
new String [] { CallNote.PHONE_NUMBER },
|
|
|
|
CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?",
|
|
|
|
CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?",
|
|
|
@ -262,9 +299,16 @@ public class DataUtils {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) {
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 根据电话号码和通话日期获取便签ID
|
|
|
|
|
|
|
|
* @param resolver ContentResolver对象
|
|
|
|
|
|
|
|
* @param phoneNumber 电话号码
|
|
|
|
|
|
|
|
* @param callDate 通话日期
|
|
|
|
|
|
|
|
* @return 便签ID
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) {
|
|
|
|
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
|
|
|
|
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
|
|
|
|
new String [] { CallNote.NOTE_ID },
|
|
|
|
new String [] { CallNote.NOTE_ID },
|
|
|
|
CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL("
|
|
|
|
CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL("
|
|
|
@ -283,9 +327,15 @@ public class DataUtils {
|
|
|
|
cursor.close();
|
|
|
|
cursor.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static String getSnippetById(ContentResolver resolver, long noteId) {
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 根据便签ID获取便签摘要
|
|
|
|
|
|
|
|
* @param resolver ContentResolver对象
|
|
|
|
|
|
|
|
* @param noteId 便签ID
|
|
|
|
|
|
|
|
* @return 便签摘要
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static String getSnippetById(ContentResolver resolver, long noteId) {
|
|
|
|
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI,
|
|
|
|
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI,
|
|
|
|
new String [] { NoteColumns.SNIPPET },
|
|
|
|
new String [] { NoteColumns.SNIPPET },
|
|
|
|
NoteColumns.ID + "=?",
|
|
|
|
NoteColumns.ID + "=?",
|
|
|
@ -301,9 +351,14 @@ public class DataUtils {
|
|
|
|
return snippet;
|
|
|
|
return snippet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
throw new IllegalArgumentException("Note is not found with id: " + noteId);
|
|
|
|
throw new IllegalArgumentException("Note is not found with id: " + noteId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static String getFormattedSnippet(String snippet) {
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 格式化便签摘要
|
|
|
|
|
|
|
|
* @param snippet 便签摘要
|
|
|
|
|
|
|
|
* @return 格式化后的便签摘要
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static String getFormattedSnippet(String snippet) {
|
|
|
|
if (snippet != null) {
|
|
|
|
if (snippet != null) {
|
|
|
|
snippet = snippet.trim();
|
|
|
|
snippet = snippet.trim();
|
|
|
|
int index = snippet.indexOf('\n');
|
|
|
|
int index = snippet.indexOf('\n');
|
|
|
@ -312,14 +367,19 @@ public class DataUtils {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return snippet;
|
|
|
|
return snippet;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static Cursor searchInNoteDatabase(ContentResolver resolver, String query) {
|
|
|
|
/**
|
|
|
|
|
|
|
|
* 在数据库中搜索包含指定查询内容的便签
|
|
|
|
|
|
|
|
* @param resolver ContentResolver对象
|
|
|
|
|
|
|
|
* @param query 查询内容
|
|
|
|
|
|
|
|
* @return 包含查询结果的Cursor对象
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
public static Cursor searchInNoteDatabase(ContentResolver resolver, String query) {
|
|
|
|
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
|
|
|
|
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
|
|
|
|
new String[]{NoteColumns.ID},
|
|
|
|
new String[]{NoteColumns.ID},
|
|
|
|
Notes.DataColumns.CONTENT + " LIKE'%" + query +"%'",
|
|
|
|
Notes.DataColumns.CONTENT + " LIKE'%" + query +"%'",
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null);
|
|
|
|
null);
|
|
|
|
return cursor;
|
|
|
|
return cursor;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|