|
|
@ -50,7 +50,7 @@ public class DataUtils {
|
|
|
|
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
|
|
|
|
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
|
|
|
|
for (long id : ids) {
|
|
|
|
for (long id : ids) {
|
|
|
|
if(id == Notes.ID_ROOT_FOLDER) {
|
|
|
|
if(id == Notes.ID_ROOT_FOLDER) {
|
|
|
|
Log.e(TAG, "Don't delete system folder root");
|
|
|
|
Log.e(TAG, "Don't delete system folder root"); //如果发现是根文件夹,则不删除
|
|
|
|
continue;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ContentProviderOperation.Builder builder = ContentProviderOperation
|
|
|
|
ContentProviderOperation.Builder builder = ContentProviderOperation
|
|
|
@ -58,7 +58,7 @@ public class DataUtils {
|
|
|
|
operationList.add(builder.build());
|
|
|
|
operationList.add(builder.build());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
|
|
|
|
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);//数据库事务,数据库事务是由一组数据库操作序列组成,事务作为一个整体被执行
|
|
|
|
if (results == null || results.length == 0 || results[0] == null) {
|
|
|
|
if (results == null || results.length == 0 || results[0] == null) {
|
|
|
|
Log.d(TAG, "delete notes failed, ids:" + ids.toString());
|
|
|
|
Log.d(TAG, "delete notes failed, ids:" + ids.toString());
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -93,7 +93,8 @@ public class DataUtils {
|
|
|
|
.newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
|
|
|
|
.newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
|
|
|
|
builder.withValue(NoteColumns.PARENT_ID, folderId);
|
|
|
|
builder.withValue(NoteColumns.PARENT_ID, folderId);
|
|
|
|
builder.withValue(NoteColumns.LOCAL_MODIFIED, 1);
|
|
|
|
builder.withValue(NoteColumns.LOCAL_MODIFIED, 1);
|
|
|
|
operationList.add(builder.build());
|
|
|
|
operationList.add(builder.build());//将ids里包含的每一列的数据逐次加入到operationList中,等待最后的批量处理
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
@ -119,7 +120,7 @@ public class DataUtils {
|
|
|
|
new String[] { "COUNT(*)" },
|
|
|
|
new String[] { "COUNT(*)" },
|
|
|
|
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?",
|
|
|
|
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?",
|
|
|
|
new String[] { String.valueOf(Notes.TYPE_FOLDER), String.valueOf(Notes.ID_TRASH_FOLER)},
|
|
|
|
new String[] { String.valueOf(Notes.TYPE_FOLDER), String.valueOf(Notes.ID_TRASH_FOLER)},
|
|
|
|
null);
|
|
|
|
null);//筛选条件:源文件不为trash folder
|
|
|
|
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
int count = 0;
|
|
|
|
if(cursor != null) {
|
|
|
|
if(cursor != null) {
|
|
|
@ -141,11 +142,11 @@ public class DataUtils {
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER,
|
|
|
|
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER,
|
|
|
|
new String [] {String.valueOf(type)},
|
|
|
|
new String [] {String.valueOf(type)},
|
|
|
|
null);
|
|
|
|
null);//查询条件:type符合,且不属于垃圾文件夹
|
|
|
|
|
|
|
|
|
|
|
|
boolean exist = false;
|
|
|
|
boolean exist = false;
|
|
|
|
if (cursor != null) {
|
|
|
|
if (cursor != null) {
|
|
|
|
if (cursor.getCount() > 0) {
|
|
|
|
if (cursor.getCount() > 0) {//用getcount函数判断cursor是否为空
|
|
|
|
exist = true;
|
|
|
|
exist = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
cursor.close();
|
|
|
|
cursor.close();
|
|
|
@ -171,7 +172,7 @@ public class DataUtils {
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
|
|
boolean exist = false;
|
|
|
|
boolean exist = false;//通过名字查询文件是否存在
|
|
|
|
if (cursor != null) {
|
|
|
|
if (cursor != null) {
|
|
|
|
if (cursor.getCount() > 0) {
|
|
|
|
if (cursor.getCount() > 0) {
|
|
|
|
exist = true;
|
|
|
|
exist = true;
|
|
|
@ -202,7 +203,7 @@ public class DataUtils {
|
|
|
|
new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE },
|
|
|
|
new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE },
|
|
|
|
NoteColumns.PARENT_ID + "=?",
|
|
|
|
NoteColumns.PARENT_ID + "=?",
|
|
|
|
new String[] { String.valueOf(folderId) },
|
|
|
|
new String[] { String.valueOf(folderId) },
|
|
|
|
null);
|
|
|
|
null);//查询条件:父ID是传入的folderId;
|
|
|
|
|
|
|
|
|
|
|
|
HashSet<AppWidgetAttribute> set = null;
|
|
|
|
HashSet<AppWidgetAttribute> set = null;
|
|
|
|
if (c != null) {
|
|
|
|
if (c != null) {
|
|
|
@ -211,13 +212,13 @@ public class DataUtils {
|
|
|
|
do {
|
|
|
|
do {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
AppWidgetAttribute widget = new AppWidgetAttribute();
|
|
|
|
AppWidgetAttribute widget = new AppWidgetAttribute();
|
|
|
|
widget.widgetId = c.getInt(0);
|
|
|
|
widget.widgetId = c.getInt(0);//0对应的NoteColumns.WIDGET_ID
|
|
|
|
widget.widgetType = c.getInt(1);
|
|
|
|
widget.widgetType = c.getInt(1);//1对应的NoteColumns.WIDGET_TYPE
|
|
|
|
set.add(widget);
|
|
|
|
set.add(widget);
|
|
|
|
} catch (IndexOutOfBoundsException e) {
|
|
|
|
} catch (IndexOutOfBoundsException e) {
|
|
|
|
Log.e(TAG, e.toString());
|
|
|
|
Log.e(TAG, e.toString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (c.moveToNext());
|
|
|
|
} while (c.moveToNext());//查询下一条
|
|
|
|
}
|
|
|
|
}
|
|
|
|
c.close();
|
|
|
|
c.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -229,11 +230,12 @@ public class DataUtils {
|
|
|
|
new String [] { CallNote.PHONE_NUMBER },
|
|
|
|
new String [] { CallNote.PHONE_NUMBER },
|
|
|
|
CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?",
|
|
|
|
CallNote.NOTE_ID + "=? AND " + CallNote.MIME_TYPE + "=?",
|
|
|
|
new String [] { String.valueOf(noteId), CallNote.CONTENT_ITEM_TYPE },
|
|
|
|
new String [] { String.valueOf(noteId), CallNote.CONTENT_ITEM_TYPE },
|
|
|
|
null);
|
|
|
|
null); //通过数据库操作,查询条件是(callDate和phoneNumber匹配传入参数的值)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
|
|
if (cursor != null && cursor.moveToFirst()) {
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
return cursor.getString(0);
|
|
|
|
return cursor.getString(0);//0对应的CallNote.NOTE_ID
|
|
|
|
} catch (IndexOutOfBoundsException e) {
|
|
|
|
} catch (IndexOutOfBoundsException e) {
|
|
|
|
Log.e(TAG, "Get call number fails " + e.toString());
|
|
|
|
Log.e(TAG, "Get call number fails " + e.toString());
|
|
|
|
} finally {
|
|
|
|
} finally {
|
|
|
@ -249,7 +251,7 @@ public class DataUtils {
|
|
|
|
CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL("
|
|
|
|
CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL("
|
|
|
|
+ CallNote.PHONE_NUMBER + ",?)",
|
|
|
|
+ CallNote.PHONE_NUMBER + ",?)",
|
|
|
|
new String [] { String.valueOf(callDate), CallNote.CONTENT_ITEM_TYPE, phoneNumber },
|
|
|
|
new String [] { String.valueOf(callDate), CallNote.CONTENT_ITEM_TYPE, phoneNumber },
|
|
|
|
null);
|
|
|
|
null);//查询条件:noteId
|
|
|
|
|
|
|
|
|
|
|
|
if (cursor != null) {
|
|
|
|
if (cursor != null) {
|
|
|
|
if (cursor.moveToFirst()) {
|
|
|
|
if (cursor.moveToFirst()) {
|
|
|
@ -282,7 +284,7 @@ public class DataUtils {
|
|
|
|
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) {
|
|
|
|
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');
|
|
|
|