second 标注

pull/18/head
LQS 11 months ago
parent 89ecd874f6
commit 75744d31e2

@ -34,53 +34,90 @@ import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
/**
* @aPackage : net.micode.notes.tool
* @aClassName: BackupUtils
* @Description:
*
* 使
* @aAuthor: Li Qiushi
* @createdate: 12/23/2023 10:31 AM
*/
public class BackupUtils {
private static final String TAG = "BackupUtils";
// Singleton stuff
private static BackupUtils sInstance;
/**
* BackupUtils
* 使synchronized线
* @param context
* @return sInstance
*/
public static synchronized BackupUtils getInstance(Context context) {
if (sInstance == null) {
sInstance = new BackupUtils(context);
sInstance = new BackupUtils(context);//创建一个新的BackupUtils实例并将其赋值给sInstance
}
return sInstance;
}
/**
* Following states are signs to represents backup or restore
* status
*
*/
// Currently, the sdcard is not mounted
// 当前SD卡未挂载
public static final int STATE_SD_CARD_UNMOUONTED = 0;
// The backup file not exist
// 备份文件不存在
public static final int STATE_BACKUP_FILE_NOT_EXIST = 1;
// The data is not well formated, may be changed by other programs
//数据格式错误
public static final int STATE_DATA_DESTROIED = 2;
// Some run-time exception which causes restore or backup fails
// 系统错误
public static final int STATE_SYSTEM_ERROR = 3;
// Backup or restore success
// 备份或恢复成功
public static final int STATE_SUCCESS = 4;
private TextExport mTextExport;
/**
* Context使TextExport
* @param context
*/
private BackupUtils(Context context) {
mTextExport = new TextExport(context);
}
/**
*
* @return boolean
*/
private static boolean externalStorageAvailable() {
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}
/**
*
* @return int
*/
public int exportToText() {
return mTextExport.exportToText();
}
/**
*
* @return String
*/
public String getExportedTextFileName() {
return mTextExport.mFileName;
}
/**
*
* @return String
*/
public String getExportedTextFileDir() {
return mTextExport.mFileDirectory;
}
@ -125,6 +162,10 @@ public class BackupUtils {
private String mFileName;
private String mFileDirectory;
/**
* ContextTEXT_FORMATmContextmFileNamemFileDirectory
* @param context
*/
public TextExport(Context context) {
TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note);
mContext = context;
@ -132,12 +173,19 @@ public class BackupUtils {
mFileDirectory = "";
}
/**
* id
* @param id
* @return String
*/
private String getFormat(int id) {
return TEXT_FORMAT[id];
}
/**
* Export the folder identified by folder id to text
*
* @param folderId
* @param ps
*/
private void exportFolderToText(String folderId, PrintStream ps) {
// Query notes belong to this folder
@ -146,6 +194,9 @@ public class BackupUtils {
folderId
}, null);
/*
*/
if (notesCursor != null) {
if (notesCursor.moveToFirst()) {
do {
@ -155,7 +206,7 @@ public class BackupUtils {
notesCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
// Query data belong to this note
String noteId = notesCursor.getString(NOTE_COLUMN_ID);
exportNoteToText(noteId, ps);
exportNoteToText(noteId, ps);//将笔记的内容导出为文本
} while (notesCursor.moveToNext());
}
notesCursor.close();
@ -163,9 +214,12 @@ public class BackupUtils {
}
/**
* Export note identified by id to a print stream
* ID
* @param noteId
* @param ps
*/
private void exportNoteToText(String noteId, PrintStream ps) {
//查询与给定noteId相关的数据并将结果存储在Cursor对象dataCursor中
Cursor dataCursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI,
DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] {
noteId
@ -175,6 +229,9 @@ public class BackupUtils {
if (dataCursor.moveToFirst()) {
do {
String mimeType = dataCursor.getString(DATA_COLUMN_MIME_TYPE);
/*
,PrintStreamps
*/
if (DataConstants.CALL_NOTE.equals(mimeType)) {
// Print phone number
String phoneNumber = dataCursor.getString(DATA_COLUMN_PHONE_NUMBER);
@ -194,7 +251,7 @@ public class BackupUtils {
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
location));
}
} else if (DataConstants.NOTE.equals(mimeType)) {
} else if (DataConstants.NOTE.equals(mimeType)) {//表示该记录是一个普通笔记,此时获取笔记的内容并将其格式化后输出到PrintStream对象ps中
String content = dataCursor.getString(DATA_COLUMN_CONTENT);
if (!TextUtils.isEmpty(content)) {
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
@ -205,7 +262,7 @@ public class BackupUtils {
}
dataCursor.close();
}
// print a line separator between note
// 向PrintStream对象ps中写入一个换行符用于分隔不同笔记之间的内容
try {
ps.write(new byte[] {
Character.LINE_SEPARATOR, Character.LETTER_NUMBER
@ -216,14 +273,21 @@ public class BackupUtils {
}
/**
* Note will be exported as text which is user readable
*
* @return int
*/
public int exportToText() {
/*
STATE_SD_CARD_UNMOUONTED
*/
if (!externalStorageAvailable()) {
Log.d(TAG, "Media was not mounted");
return STATE_SD_CARD_UNMOUONTED;
}
/*
PrintStreamps
STATE_SYSTEM_ERROR
*/
PrintStream ps = getExportToTextPrintStream();
if (ps == null) {
Log.e(TAG, "get print stream error");
@ -237,7 +301,9 @@ public class BackupUtils {
+ NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + ") OR "
+ NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER, null, null);
if (folderCursor != null) {
if (folderCursor.moveToFirst()) {
do {
// Print folder's name
@ -247,6 +313,7 @@ public class BackupUtils {
} else {
folderName = folderCursor.getString(NOTE_COLUMN_SNIPPET);
}
//将格式化后的文件夹名称写入打印流ps
if (!TextUtils.isEmpty(folderName)) {
ps.println(String.format(getFormat(FORMAT_FOLDER_NAME), folderName));
}
@ -264,6 +331,10 @@ public class BackupUtils {
NoteColumns.TYPE + "=" + +Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID
+ "=0", null, null);
/*noteCursor
ps
IDexportNoteToText
*/
if (noteCursor != null) {
if (noteCursor.moveToFirst()) {
do {
@ -283,16 +354,21 @@ public class BackupUtils {
}
/**
* Get a print stream pointed to the file {@generateExportedTextFile}
* PrintStream
* @return PrintStream
*/
private PrintStream getExportToTextPrintStream() {
//生成一个文件该文件位于SD卡上
File file = generateFileMountedOnSDcard(mContext, R.string.file_path,
R.string.file_name_txt_format);
/*
Log.e(TAG, "create file to exported failed")
*/
if (file == null) {
Log.e(TAG, "create file to exported failed");
return null;
}
mFileName = file.getName();
mFileName = file.getName();//文件名赋值给成员变量mFileName
mFileDirectory = mContext.getString(R.string.file_path);
PrintStream ps = null;
try {
@ -310,19 +386,27 @@ public class BackupUtils {
}
/**
* Generate the text file to store imported data
* Android
* @param context
* @param filePathResId
* @param fileNameFormatResId
* @return File
*/
private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) {
StringBuilder sb = new StringBuilder();
sb.append(Environment.getExternalStorageDirectory());
sb.append(context.getString(filePathResId));
sb.append(Environment.getExternalStorageDirectory()); //获取外部存储设备的根目录
sb.append(context.getString(filePathResId)); //根据传入的filePathResId参数将指定的路径添加到根目录下
File filedir = new File(sb.toString());
//根据传入的fileNameFormatResId参数和当前日期时间生成文件名并将其添加到目录路径中
sb.append(context.getString(
fileNameFormatResId,
DateFormat.format(context.getString(R.string.format_date_ymd),
System.currentTimeMillis())));
File file = new File(sb.toString());
/*
null
*/
try {
if (!filedir.exists()) {
filedir.mkdir();
@ -338,7 +422,7 @@ public class BackupUtils {
}
return null;
}
}
}

@ -33,21 +33,38 @@ import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute;
import java.util.ArrayList;
import java.util.HashSet;
/**
* @aPackage : net.micode.notes.tool
* @aClassName: DataUtils
* @Description:
* 便
* @aAuthor: Li Qiushi
* @createdate: 12/30/2023 08:31 AM
*/
public class DataUtils {
public static final String TAG = "DataUtils";
/**
*
* @param resolver
* @param ids
* @return boolean
*/
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) {
//判断ids是否为空
if (ids == null) {
Log.d(TAG, "the ids is null");
return true;
}
//判断ids大小是否为0
if (ids.size() == 0) {
Log.d(TAG, "no id is in the hashset");
return true;
}
//创建类存储删除的动作
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
//遍历ID如果发现是根文件夹则不删除
for (long id : ids) {
if(id == Notes.ID_ROOT_FOLDER) {
Log.e(TAG, "Don't delete system folder root");
@ -57,9 +74,10 @@ public class DataUtils {
.newDelete(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
operationList.add(builder.build());
}
//批量删除操作
try {
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
if (results == null || results.length == 0 || results[0] == null) {
if (results.length == 0 || results[0] == null) {
Log.d(TAG, "delete notes failed, ids:" + ids.toString());
return false;
}
@ -72,14 +90,29 @@ public class DataUtils {
return false;
}
/**
*
* @param resolver
* @param id
* @param srcFolderId
* @param desFolderId
*/
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);
//对需要移动的便签进行数据更新然后用update实现
resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null);
}
/**
* id
* @param resolver
* @param ids
* @param folderId
* @return boolean
*/
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids,
long folderId) {
if (ids == null) {
@ -89,13 +122,15 @@ public class DataUtils {
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
for (long id : ids) {
//通过withAppendedId方法为该Uri加上ID
ContentProviderOperation.Builder builder = ContentProviderOperation
.newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
builder.withValue(NoteColumns.PARENT_ID, folderId);
builder.withValue(NoteColumns.LOCAL_MODIFIED, 1);
operationList.add(builder.build());
}
}//将ids里包含的每一列的数据逐次加入到operationList中等待最后的批量处理
//使用ContentResolver的applyBatch方法执行批量更新操作
try {
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
if (results == null || results.length == 0 || results[0] == null) {
@ -112,39 +147,50 @@ public class DataUtils {
}
/**
* Get the all folder count except system folders {@link Notes#TYPE_SYSTEM}}
*
* @param resolver
* @return count
*/
public static int getUserFolderCount(ContentResolver resolver) {
Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI,
new String[] { "COUNT(*)" },
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>?",
//筛选条件源文件不为trash folder即垃圾文件
new String[] { String.valueOf(Notes.TYPE_FOLDER), String.valueOf(Notes.ID_TRASH_FOLER)},
null);
int count = 0;
if(cursor != null) {
if(cursor.moveToFirst()) {
try {
count = cursor.getInt(0);
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, "get folder count failed:" + e.toString());
} finally {
cursor.close();
}
if(cursor != null && cursor.moveToFirst()) {
try {
//获取文件夹的数量并将其赋值给count变量
count = cursor.getInt(0);
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, "get folder count failed:" + e.toString());
} finally {
cursor.close();
}
}
return count;
}
/**
* Note
* @param resolver
* @param noteId
* @param type
* @return boolean
*/
public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null,
//查询条件type符合且不属于垃圾文件夹
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER,
new String [] {String.valueOf(type)},
null);
boolean exist = false;
if (cursor != null) {
//用getCount函数判断cursor是否为空
if (cursor.getCount() > 0) {
exist = true;
}
@ -153,6 +199,12 @@ public class DataUtils {
return exist;
}
/**
* Note
* @param resolver
* @param noteId
* @return boolean
*/
public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null, null, null, null);
@ -167,6 +219,12 @@ public class DataUtils {
return exist;
}
/**
* ID()
* @param resolver
* @param dataId
* @return boolean
*/
public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId),
null, null, null, null);
@ -181,6 +239,12 @@ public class DataUtils {
return exist;
}
/**
* Notes
* @param resolver
* @param name
* @return boolean
*/
public static boolean checkVisibleFolderName(ContentResolver resolver, String name) {
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI, null,
NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER +
@ -188,6 +252,7 @@ public class DataUtils {
" AND " + NoteColumns.SNIPPET + "=?",
new String[] { name }, null);
boolean exist = false;
//通过名字查询文件是否存在
if(cursor != null) {
if(cursor.getCount() > 0) {
exist = true;
@ -197,7 +262,14 @@ public class DataUtils {
return exist;
}
/**
* NotesID
* @param resolver
* @param folderId
* @return HashSet
*/
public static HashSet<AppWidgetAttribute> getFolderNoteWidget(ContentResolver resolver, long folderId) {
//查询条件父ID是传入的folderId
Cursor c = resolver.query(Notes.CONTENT_NOTE_URI,
new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE },
NoteColumns.PARENT_ID + "=?",
@ -211,6 +283,10 @@ public class DataUtils {
do {
try {
AppWidgetAttribute widget = new AppWidgetAttribute();
/*
0NoteColumns.WIDGET_ID
1NoteColumns.WIDGET_TYPE
*/
widget.widgetId = c.getInt(0);
widget.widgetType = c.getInt(1);
set.add(widget);
@ -224,6 +300,12 @@ public class DataUtils {
return set;
}
/**
* ID
* @param resolver
* @param noteId
* @return String
*/
public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String [] { CallNote.PHONE_NUMBER },
@ -243,6 +325,13 @@ public class DataUtils {
return "";
}
/**
* AndroidContentResolverNotes
* @param resolver
* @param phoneNumber
* @param callDate
* @return long
*/
public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) {
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String [] { CallNote.NOTE_ID },
@ -264,7 +353,14 @@ public class DataUtils {
return 0;
}
/**
* noteIdContentResolversnippet
* @param resolver
* @param noteId
* @return String
*/
public static String getSnippetById(ContentResolver resolver, long noteId) {
//查询条件noteId
Cursor cursor = resolver.query(Notes.CONTENT_NOTE_URI,
new String [] { NoteColumns.SNIPPET },
NoteColumns.ID + "=?",
@ -282,6 +378,11 @@ public class DataUtils {
throw new IllegalArgumentException("Note is not found with id: " + noteId);
}
/**
*
* @param snippet
* @return String
*/
public static String getFormattedSnippet(String snippet) {
if (snippet != null) {
snippet = snippet.trim();

@ -15,9 +15,19 @@
*/
package net.micode.notes.tool;
/**
* @aPackage : net.micode.notes.tool
* @aClassName: GTaskStringUtils
* @Description:
* 使jsonObjectstring
* jsonObject"key"便
* @aAuthor: Li Qiushi
* @createdate: 12/30/2023 10:31 AM
*/
public class GTaskStringUtils {
public final static String GTASK_JSON_ACTION_ID = "action_id";
public final static String GTASK_JSON_ACTION_LIST = "action_list";

@ -21,7 +21,22 @@ import android.preference.PreferenceManager;
import net.micode.notes.R;
import net.micode.notes.ui.NotesPreferenceActivity;
/**
* @aPackage : net.micode.notes.tool
* @aClassName: ResourceParser
* @Description:
* R.java
* 使
* R.java
* R.id
* R.drawable 使
* R.layout
* R.menu
* R.String
* R.style 使
* @aAuthor: Li Qiushi
* @createdate: 12/30/2023 10:31 AM
*/
public class ResourceParser {
public static final int YELLOW = 0;
@ -39,6 +54,9 @@ public class ResourceParser {
public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM;
/**
* ID
*/
public static class NoteBgResources {
private final static int [] BG_EDIT_RESOURCES = new int [] {
R.drawable.edit_yellow,

Loading…
Cancel
Save