|
|
|
@ -14,7 +14,10 @@
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 包声明,表明该类所属的包名为net.micode.notes.tool
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
package net.micode.notes.tool;
|
|
|
|
|
|
|
|
|
|
import android.content.ContentProviderOperation;
|
|
|
|
@ -35,6 +38,7 @@ import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute;
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// DataUtils工具类,提供了一系列用于操作笔记数据相关的实用方法
|
|
|
|
|
public class DataUtils {
|
|
|
|
|
// 用于日志记录的标签,方便在日志中识别该类输出的相关信息
|
|
|
|
@ -43,16 +47,26 @@ public class DataUtils {
|
|
|
|
|
// 批量删除笔记的方法,根据给定的ContentResolver和要删除笔记的ID集合来执行删除操作
|
|
|
|
|
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) {
|
|
|
|
|
// 如果传入的ID集合为null,记录日志并返回true(可能表示无需进行删除操作的情况)
|
|
|
|
|
=======
|
|
|
|
|
|
|
|
|
|
public class DataUtils {
|
|
|
|
|
public static final String TAG = "DataUtils";
|
|
|
|
|
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) {
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
if (ids == null) {
|
|
|
|
|
Log.d(TAG, "the ids is null");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 如果ID集合为空,记录日志并返回true(表示没有实际要删除的笔记)
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
if (ids.size() == 0) {
|
|
|
|
|
Log.d(TAG, "no id is in the hashset");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 创建一个用于存储内容提供器操作的列表,后续将批量执行这些操作来删除笔记
|
|
|
|
|
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
|
|
|
|
|
// 遍历要删除的笔记ID集合
|
|
|
|
@ -73,10 +87,25 @@ public class DataUtils {
|
|
|
|
|
// 通过ContentResolver批量执行操作列表中的删除操作,并获取操作结果数组
|
|
|
|
|
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
|
|
|
|
|
// 如果结果数组为null,或者长度为0,或者第一个结果为null,表示删除笔记失败,记录日志并返回false
|
|
|
|
|
=======
|
|
|
|
|
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
|
|
|
|
|
for (long id : ids) {
|
|
|
|
|
if(id == Notes.ID_ROOT_FOLDER) {
|
|
|
|
|
Log.e(TAG, "Don't delete system folder root");
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
ContentProviderOperation.Builder builder = ContentProviderOperation
|
|
|
|
|
.newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
|
|
|
|
|
operationList.add(builder.build());
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
if (results == null || results.length == 0 || results[0] == null) {
|
|
|
|
|
Log.d(TAG, "delete notes failed, ids:" + ids.toString());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 如果成功执行删除操作,返回true
|
|
|
|
|
return true;
|
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
@ -84,11 +113,18 @@ public class DataUtils {
|
|
|
|
|
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
|
|
|
|
|
} catch (OperationApplicationException e) {
|
|
|
|
|
// 如果在应用操作过程中出现异常(比如操作不符合要求等),记录详细的异常信息到日志
|
|
|
|
|
=======
|
|
|
|
|
return true;
|
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
|
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
|
|
|
|
|
} catch (OperationApplicationException e) {
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 将指定笔记移动到指定文件夹的方法,通过更新笔记的相关字段来实现移动操作
|
|
|
|
|
public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) {
|
|
|
|
|
// 创建一个ContentValues对象,用于存储要更新的列和对应的值
|
|
|
|
@ -107,11 +143,24 @@ public class DataUtils {
|
|
|
|
|
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids,
|
|
|
|
|
long folderId) {
|
|
|
|
|
// 如果传入的笔记ID集合为null,记录日志并返回true(可能表示无需进行移动操作的情况)
|
|
|
|
|
=======
|
|
|
|
|
public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) {
|
|
|
|
|
ContentValues values = new ContentValues();
|
|
|
|
|
values.put(NoteColumns.PARENT_ID, desFolderId);
|
|
|
|
|
values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId);
|
|
|
|
|
values.put(NoteColumns.LOCAL_MODIFIED, 1);
|
|
|
|
|
resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids,
|
|
|
|
|
long folderId) {
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
if (ids == null) {
|
|
|
|
|
Log.d(TAG, "the ids is null");
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 创建一个用于存储内容提供器操作的列表,后续将批量执行这些操作来移动笔记
|
|
|
|
|
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
|
|
|
|
|
// 遍历要移动的笔记ID集合
|
|
|
|
@ -124,17 +173,30 @@ public class DataUtils {
|
|
|
|
|
// 设置本地修改标志,可能表示该笔记在本地有过修改操作
|
|
|
|
|
builder.withValue(NoteColumns.LOCAL_MODIFIED, 1);
|
|
|
|
|
// 将构建好的操作添加到操作列表中
|
|
|
|
|
=======
|
|
|
|
|
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
|
|
|
|
|
for (long id : ids) {
|
|
|
|
|
ContentProviderOperation.Builder builder = ContentProviderOperation
|
|
|
|
|
.newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
|
|
|
|
|
builder.withValue(NoteColumns.PARENT_ID, folderId);
|
|
|
|
|
builder.withValue(NoteColumns.LOCAL_MODIFIED, 1);
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
operationList.add(builder.build());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 通过ContentResolver批量执行操作列表中的更新操作,并获取操作结果数组
|
|
|
|
|
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
|
|
|
|
|
// 如果结果数组为null,或者长度为0,或者第一个结果为null,表示移动笔记失败,记录日志并返回false
|
|
|
|
|
=======
|
|
|
|
|
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
if (results == null || results.length == 0 || results[0] == null) {
|
|
|
|
|
Log.d(TAG, "delete notes failed, ids:" + ids.toString());
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 如果成功执行移动操作,返回true
|
|
|
|
|
return true;
|
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
@ -142,12 +204,19 @@ public class DataUtils {
|
|
|
|
|
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
|
|
|
|
|
} catch (OperationApplicationException e) {
|
|
|
|
|
// 如果在应用操作过程中出现异常(比如操作不符合要求等),记录详细的异常信息到日志
|
|
|
|
|
=======
|
|
|
|
|
return true;
|
|
|
|
|
} catch (RemoteException e) {
|
|
|
|
|
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
|
|
|
|
|
} catch (OperationApplicationException e) {
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
* 获取除系统文件夹(参考Notes#TYPE_SYSTEM)之外的所有文件夹数量的方法
|
|
|
|
|
*/
|
|
|
|
|
public static int getUserFolderCount(ContentResolver resolver) {
|
|
|
|
@ -155,12 +224,19 @@ public class DataUtils {
|
|
|
|
|
// 查询的列只需要计数结果,所以使用"COUNT(*)"
|
|
|
|
|
// 查询条件是类型为文件夹(NoteColumns.TYPE对应的是文件夹类型)且父文件夹ID不是回收站文件夹ID
|
|
|
|
|
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI,
|
|
|
|
|
=======
|
|
|
|
|
* Get the all folder count except system folders {@link Notes#TYPE_SYSTEM}}
|
|
|
|
|
*/
|
|
|
|
|
public static int getUserFolderCount(ContentResolver resolver) {
|
|
|
|
|
Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI,
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
new String[] { "COUNT(*)" },
|
|
|
|
|
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?",
|
|
|
|
|
new String[] { String.valueOf(Notes.TYPE_FOLDER), String.valueOf(Notes.ID_TRASH_FOLER)},
|
|
|
|
|
null);
|
|
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 如果游标不为null,表示查询到了结果
|
|
|
|
|
if (cursor!= null) {
|
|
|
|
|
// 将游标移动到第一条记录(因为只有一条计数结果记录)
|
|
|
|
@ -173,6 +249,15 @@ public class DataUtils {
|
|
|
|
|
Log.e(TAG, "get folder count failed:" + e.toString());
|
|
|
|
|
} finally {
|
|
|
|
|
// 关闭游标,释放资源
|
|
|
|
|
=======
|
|
|
|
|
if(cursor != null) {
|
|
|
|
|
if(cursor.moveToFirst()) {
|
|
|
|
|
try {
|
|
|
|
|
count = cursor.getInt(0);
|
|
|
|
|
} catch (IndexOutOfBoundsException e) {
|
|
|
|
|
Log.e(TAG, "get folder count failed:" + e.toString());
|
|
|
|
|
} finally {
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
cursor.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -180,9 +265,13 @@ public class DataUtils {
|
|
|
|
|
return count;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 判断指定笔记在笔记数据库中是否可见(根据特定条件,比如不在回收站等)的方法
|
|
|
|
|
public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) {
|
|
|
|
|
// 通过ContentResolver查询指定笔记的记录,查询条件是类型为指定类型且父文件夹ID不是回收站文件夹ID
|
|
|
|
|
=======
|
|
|
|
|
public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) {
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
|
|
|
|
|
null,
|
|
|
|
|
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER,
|
|
|
|
@ -190,6 +279,7 @@ public class DataUtils {
|
|
|
|
|
null);
|
|
|
|
|
|
|
|
|
|
boolean exist = false;
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 如果游标不为null,表示查询到了结果
|
|
|
|
|
if (cursor!= null) {
|
|
|
|
|
// 如果查询到的记录数量大于0,表示该笔记存在且符合可见条件,设置exist为true
|
|
|
|
@ -197,18 +287,29 @@ public class DataUtils {
|
|
|
|
|
exist = true;
|
|
|
|
|
}
|
|
|
|
|
// 关闭游标,释放资源
|
|
|
|
|
=======
|
|
|
|
|
if (cursor != null) {
|
|
|
|
|
if (cursor.getCount() > 0) {
|
|
|
|
|
exist = true;
|
|
|
|
|
}
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
cursor.close();
|
|
|
|
|
}
|
|
|
|
|
return exist;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 判断指定笔记在笔记数据库中是否存在的方法(简单查询是否有对应记录)
|
|
|
|
|
public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {
|
|
|
|
|
// 通过ContentResolver查询指定笔记的记录,不设置额外的查询条件
|
|
|
|
|
=======
|
|
|
|
|
public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
|
|
|
|
|
null, null, null, null);
|
|
|
|
|
|
|
|
|
|
boolean exist = false;
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 如果游标不为null,表示查询到了结果
|
|
|
|
|
if (cursor!= null) {
|
|
|
|
|
// 如果查询到的记录数量大于0,表示该笔记存在,设置exist为true
|
|
|
|
@ -216,18 +317,29 @@ public class DataUtils {
|
|
|
|
|
exist = true;
|
|
|
|
|
}
|
|
|
|
|
// 关闭游标,释放资源
|
|
|
|
|
=======
|
|
|
|
|
if (cursor != null) {
|
|
|
|
|
if (cursor.getCount() > 0) {
|
|
|
|
|
exist = true;
|
|
|
|
|
}
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
cursor.close();
|
|
|
|
|
}
|
|
|
|
|
return exist;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 判断指定数据(可能是某种关联数据等)在数据数据库中是否存在的方法(简单查询是否有对应记录)
|
|
|
|
|
public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {
|
|
|
|
|
// 通过ContentResolver查询指定数据的记录,不设置额外的查询条件
|
|
|
|
|
=======
|
|
|
|
|
public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId),
|
|
|
|
|
null, null, null, null);
|
|
|
|
|
|
|
|
|
|
boolean exist = false;
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 如果游标不为null,表示查询到了结果
|
|
|
|
|
if (cursor!= null) {
|
|
|
|
|
// 如果查询到的记录数量大于0,表示该数据存在,设置exist为true
|
|
|
|
@ -239,12 +351,25 @@ public class DataUtils {
|
|
|
|
|
// 检查指定名称的文件夹在数据库中是否可见(根据特定条件,如不在回收站且名称匹配等)的方法
|
|
|
|
|
public static boolean checkVisibleFolderName(ContentResolver resolver, String name) {
|
|
|
|
|
// 通过ContentResolver查询符合条件的文件夹记录,查询条件是类型为文件夹、父文件夹ID不是回收站文件夹ID且摘要(可能是名称相关字段)匹配指定名称
|
|
|
|
|
=======
|
|
|
|
|
if (cursor != null) {
|
|
|
|
|
if (cursor.getCount() > 0) {
|
|
|
|
|
exist = true;
|
|
|
|
|
}
|
|
|
|
|
cursor.close();
|
|
|
|
|
}
|
|
|
|
|
return exist;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static boolean checkVisibleFolderName(ContentResolver resolver, String name) {
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null,
|
|
|
|
|
NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER +
|
|
|
|
|
" AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER +
|
|
|
|
|
" AND " + NoteColumns.SNIPPET + "=?",
|
|
|
|
|
new String[] { name }, null);
|
|
|
|
|
boolean exist = false;
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 如果游标不为null,表示查询到了结果
|
|
|
|
|
if (cursor!= null) {
|
|
|
|
|
// 如果查询到的记录数量大于0,表示存在符合条件的文件夹,设置exist为true
|
|
|
|
@ -252,14 +377,24 @@ public class DataUtils {
|
|
|
|
|
exist = true;
|
|
|
|
|
}
|
|
|
|
|
// 关闭游标,释放资源
|
|
|
|
|
=======
|
|
|
|
|
if(cursor != null) {
|
|
|
|
|
if(cursor.getCount() > 0) {
|
|
|
|
|
exist = true;
|
|
|
|
|
}
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
cursor.close();
|
|
|
|
|
}
|
|
|
|
|
return exist;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 获取指定文件夹下所有笔记对应的小部件相关属性集合的方法(可能用于展示小部件相关信息等)
|
|
|
|
|
public static HashSet<AppWidgetAttribute> getFolderNoteWidget(ContentResolver resolver, long folderId) {
|
|
|
|
|
// 通过ContentResolver查询指定文件夹下笔记的小部件ID和小部件类型信息
|
|
|
|
|
=======
|
|
|
|
|
public static HashSet<AppWidgetAttribute> getFolderNoteWidget(ContentResolver resolver, long folderId) {
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
Cursor c = resolver.query(Notes.CONTENT_NOTE_URI,
|
|
|
|
|
new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE },
|
|
|
|
|
NoteColumns.PARENT_ID + "=?",
|
|
|
|
@ -267,13 +402,18 @@ public class DataUtils {
|
|
|
|
|
null);
|
|
|
|
|
|
|
|
|
|
HashSet<AppWidgetAttribute> set = null;
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 如果游标不为null,表示查询到了结果
|
|
|
|
|
if (c!= null) {
|
|
|
|
|
// 将游标移动到第一条记录
|
|
|
|
|
=======
|
|
|
|
|
if (c != null) {
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
if (c.moveToFirst()) {
|
|
|
|
|
set = new HashSet<AppWidgetAttribute>();
|
|
|
|
|
do {
|
|
|
|
|
try {
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 创建一个AppWidgetAttribute对象,用于存储小部件相关属性
|
|
|
|
|
AppWidgetAttribute widget = new AppWidgetAttribute();
|
|
|
|
|
// 从游标中获取小部件ID并赋值给widget对象
|
|
|
|
@ -284,26 +424,41 @@ public class DataUtils {
|
|
|
|
|
set.add(widget);
|
|
|
|
|
} catch (IndexOutOfBoundsException e) {
|
|
|
|
|
// 如果获取数据出现越界异常,记录详细的异常信息到日志
|
|
|
|
|
=======
|
|
|
|
|
AppWidgetAttribute widget = new AppWidgetAttribute();
|
|
|
|
|
widget.widgetId = c.getInt(0);
|
|
|
|
|
widget.widgetType = c.getInt(1);
|
|
|
|
|
set.add(widget);
|
|
|
|
|
} catch (IndexOutOfBoundsException e) {
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
Log.e(TAG, e.toString());
|
|
|
|
|
}
|
|
|
|
|
} while (c.moveToNext());
|
|
|
|
|
}
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 关闭游标,释放资源
|
|
|
|
|
=======
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
c.close();
|
|
|
|
|
}
|
|
|
|
|
return set;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 根据笔记ID获取对应的电话号码的方法(可能是与笔记关联的电话号码)
|
|
|
|
|
public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {
|
|
|
|
|
// 通过ContentResolver查询指定笔记关联的数据表(可能是通话记录相关的数据表),获取电话号码列的值
|
|
|
|
|
// 查询条件是笔记ID匹配且MIME类型匹配(可能用于确定数据类型)
|
|
|
|
|
=======
|
|
|
|
|
public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
|
|
|
|
|
new String [] { CallNote.PHONE_NUMBER },
|
|
|
|
|
CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?",
|
|
|
|
|
new String [] { String.valueOf(noteId), CallNote.CONTENT_ITEM_TYPE },
|
|
|
|
|
null);
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
if (cursor!= null && cursor.moveToFirst()) {
|
|
|
|
|
try {
|
|
|
|
|
// 如果查询到结果且游标移动到第一条记录,获取电话号码字符串并返回
|
|
|
|
@ -313,16 +468,28 @@ public class DataUtils {
|
|
|
|
|
Log.e(TAG, "Get call number fails " + e.toString());
|
|
|
|
|
} finally {
|
|
|
|
|
// 关闭游标,释放资源
|
|
|
|
|
=======
|
|
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
|
|
|
try {
|
|
|
|
|
return cursor.getString(0);
|
|
|
|
|
} catch (IndexOutOfBoundsException e) {
|
|
|
|
|
Log.e(TAG, "Get call number fails " + e.toString());
|
|
|
|
|
} finally {
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
cursor.close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 根据电话号码和通话日期获取对应的笔记ID的方法(可能用于反向查找关联笔记)
|
|
|
|
|
public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) {
|
|
|
|
|
// 通过ContentResolver查询指定数据表(可能是通话记录相关的数据表),获取笔记ID列的值
|
|
|
|
|
// 查询条件是通话日期匹配、MIME类型匹配且电话号码匹配(通过自定义函数PHONE_NUMBERS_EQUAL判断)
|
|
|
|
|
=======
|
|
|
|
|
public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) {
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
|
|
|
|
|
new String [] { CallNote.NOTE_ID },
|
|
|
|
|
CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL("
|
|
|
|
@ -330,6 +497,7 @@ public class DataUtils {
|
|
|
|
|
new String [] { String.valueOf(callDate), CallNote.CONTENT_ITEM_TYPE, phoneNumber },
|
|
|
|
|
null);
|
|
|
|
|
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
if (cursor!= null) {
|
|
|
|
|
if (cursor.moveToFirst()) {
|
|
|
|
|
try {
|
|
|
|
@ -341,9 +509,51 @@ public class DataUtils {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 关闭游标,释放资源
|
|
|
|
|
=======
|
|
|
|
|
if (cursor != null) {
|
|
|
|
|
if (cursor.moveToFirst()) {
|
|
|
|
|
try {
|
|
|
|
|
return cursor.getLong(0);
|
|
|
|
|
} catch (IndexOutOfBoundsException e) {
|
|
|
|
|
Log.e(TAG, "Get call note id fails " + e.toString());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|
cursor.close();
|
|
|
|
|
}
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据笔记ID获取对应的摘要信息的方法
|
|
|
|
|
<<<<<<< HEAD
|
|
|
|
|
// 根据笔记ID获取对应的摘要信息的方法
|
|
|
|
|
=======
|
|
|
|
|
public static String getSnippetById(ContentResolver resolver, long noteId) {
|
|
|
|
|
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI,
|
|
|
|
|
new String [] { NoteColumns.SNIPPET },
|
|
|
|
|
NoteColumns.ID + "=?",
|
|
|
|
|
new String [] { String.valueOf(noteId)},
|
|
|
|
|
null);
|
|
|
|
|
|
|
|
|
|
if (cursor != null) {
|
|
|
|
|
String snippet = "";
|
|
|
|
|
if (cursor.moveToFirst()) {
|
|
|
|
|
snippet = cursor.getString(0);
|
|
|
|
|
}
|
|
|
|
|
cursor.close();
|
|
|
|
|
return snippet;
|
|
|
|
|
}
|
|
|
|
|
throw new IllegalArgumentException("Note is not found with id: " + noteId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static String getFormattedSnippet(String snippet) {
|
|
|
|
|
if (snippet != null) {
|
|
|
|
|
snippet = snippet.trim();
|
|
|
|
|
int index = snippet.indexOf('\n');
|
|
|
|
|
if (index != -1) {
|
|
|
|
|
snippet = snippet.substring(0, index);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return snippet;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
>>>>>>> 2f825b58ba9952e086b1b4b76135e78208e7a2ee
|
|
|
|
|