合并 #1

Merged
pnrjg3ike merged 1 commits from chengwenyuan into main 2 months ago

@ -0,0 +1,347 @@
/*
* (c) 2010-2011, The MiCode (www.micode.net)
*
* Apache License, Version 2.0
* 使
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
*
*
*/
package net.micode.notes.tool; // 定义包名
import android.content.Context; // Android 上下文类
import android.database.Cursor; // 数据库游标
import android.os.Environment; // 外部存储环境类
import android.text.TextUtils; // 文本工具类
import android.text.format.DateFormat; // 日期格式化工具类
import android.util.Log; // 日志工具类
import net.micode.notes.R; // 资源类
import net.micode.notes.data.Notes; // 笔记数据类
import net.micode.notes.data.Notes.DataColumns; // 笔记数据列类
import net.micode.notes.data.Notes.DataConstants; // 笔记数据常量类
import net.micode.notes.data.Notes.NoteColumns; // 笔记列类
import java.io.File; // 文件类
import java.io.FileNotFoundException; // 文件未找到异常
import java.io.FileOutputStream; // 文件输出流
import java.io.IOException; // 输入输出异常
import java.io.PrintStream; // 打印流
public class BackupUtils {
private static final String TAG = "BackupUtils"; // 日志标签
// 单例模式相关
private static BackupUtils sInstance; // 单例对象
// 获取单例对象
public static synchronized BackupUtils getInstance(Context context) {
if (sInstance == null) {
sInstance = new BackupUtils(context); // 如果为空则新建一个实例
}
return sInstance; // 返回单例对象
}
/**
*
*/
// 当前sd卡未挂载
public static final int STATE_SD_CARD_UNMOUONTED = 0;
// 备份文件不存在
public static final int STATE_BACKUP_FILE_NOT_EXIST = 1;
// 数据格式不正确,可能被其他程序更改
public static final int STATE_DATA_DESTROIED = 2;
// 运行时异常导致备份或恢复失败
public static final int STATE_SYSTEM_ERROR = 3;
// 备份或恢复成功
public static final int STATE_SUCCESS = 4;
private TextExport mTextExport; // 文本导出器
// 构造函数
private BackupUtils(Context context) {
mTextExport = new TextExport(context); // 初始化文本导出器
}
// 检查外部存储是否可用
private static boolean externalStorageAvailable() {
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}
// 导出到文本
public int exportToText() {
return mTextExport.exportToText(); // 调用文本导出器的导出方法
}
// 获取导出文本文件名
public String getExportedTextFileName() {
return mTextExport.mFileName; // 返回文本导出器的文件名
}
// 获取导出文本文件目录
public String getExportedTextFileDir() {
return mTextExport.mFileDirectory; // 返回文本导出器的文件目录
}
// 内部类:文本导出器
private static class TextExport {
// 笔记查询投影数组
private static final String[] NOTE_PROJECTION = {
NoteColumns.ID,
NoteColumns.MODIFIED_DATE,
NoteColumns.SNIPPET,
NoteColumns.TYPE
};
// 数据列索引
private static final int NOTE_COLUMN_ID = 0;
private static final int NOTE_COLUMN_MODIFIED_DATE = 1;
private static final int NOTE_COLUMN_SNIPPET = 2;
// 数据查询投影数组
private static final String[] DATA_PROJECTION = {
DataColumns.CONTENT,
DataColumns.MIME_TYPE,
DataColumns.DATA1,
DataColumns.DATA2,
DataColumns.DATA3,
DataColumns.DATA4,
};
// 数据列索引
private static final int DATA_COLUMN_CONTENT = 0;
private static final int DATA_COLUMN_MIME_TYPE = 1;
private static final int DATA_COLUMN_CALL_DATE = 2;
private static final int DATA_COLUMN_PHONE_NUMBER = 4;
// 文本格式数组
private final String [] TEXT_FORMAT;
// 文本格式索引
private static final int FORMAT_FOLDER_NAME = 0;
private static final int FORMAT_NOTE_DATE = 1;
private static final int FORMAT_NOTE_CONTENT = 2;
private Context mContext; // Android 上下文
private String mFileName; // 文件名
private String mFileDirectory; // 文件目录
// 构造函数
public TextExport(Context context) {
TEXT_FORMAT = context.getResources().getStringArray(R.array.format_for_exported_note); // 初始化文本格式
mContext = context; // 初始化上下文
mFileName = ""; // 初始化文件名
mFileDirectory = ""; // 初始化文件目录
}
// 获取指定格式字符串
private String getFormat(int id) {
return TEXT_FORMAT[id]; // 返回文本格式数组中的字符串
}
/**
* ID
*/
private void exportFolderToText(String folderId, PrintStream ps) {
// 查询属于此文件夹的笔记
Cursor notesCursor = mContext.getContentResolver().query(Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION, NoteColumns.PARENT_ID + "=?", new String[] {
folderId
}, null);
if (notesCursor != null) {
if (notesCursor.moveToFirst()) {
do {
// 打印笔记的最后修改日期
ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
mContext.getString(R.string.format_datetime_mdhm),
notesCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
// 查询属于此笔记的数据
String noteId = notesCursor.getString(NOTE_COLUMN_ID);
exportNoteToText(noteId, ps); // 导出笔记到文本
} while (notesCursor.moveToNext());
}
notesCursor.close(); // 关闭游标
}
}
/**
* ID
*/
private void exportNoteToText(String noteId, PrintStream ps) {
Cursor dataCursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI,
DATA_PROJECTION, DataColumns.NOTE_ID + "=?", new String[] {
noteId
}, null);
if (dataCursor != null) {
if (dataCursor.moveToFirst()) {
do {
String mimeType = dataCursor.getString(DATA_COLUMN_MIME_TYPE);
if (DataConstants.CALL_NOTE.equals(mimeType)) {
// 打印电话号码
String phoneNumber = dataCursor.getString(DATA_COLUMN_PHONE_NUMBER);
long callDate = dataCursor.getLong(DATA_COLUMN_CALL_DATE);
String location = dataCursor.getString(DATA_COLUMN_CONTENT);
if (!TextUtils.isEmpty(phoneNumber)) {
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
phoneNumber));
}
// 打印通话日期
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT), DateFormat
.format(mContext.getString(R.string.format_datetime_mdhm),
callDate)));
// 打印通话附件位置
if (!TextUtils.isEmpty(location)) {
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
location));
}
} else if (DataConstants.NOTE.equals(mimeType)) {
String content = dataCursor.getString(DATA_COLUMN_CONTENT);
if (!TextUtils.isEmpty(content)) {
ps.println(String.format(getFormat(FORMAT_NOTE_CONTENT),
content));
}
}
} while (dataCursor.moveToNext());
}
dataCursor.close(); // 关闭游标
}
// 打印笔记之间的分隔线
try {
ps.write(new byte[] {
Character.LINE_SEPARATOR, Character.LETTER_NUMBER
});
} catch (IOException e) {
Log.e(TAG, e.toString()); // 记录错误日志
}
}
/**
*
*/
public int exportToText() {
if (!externalStorageAvailable()) {
Log.d(TAG, "Media was not mounted"); // 记录日志:媒体未挂载
return STATE_SD_CARD_UNMOUONTED; // 返回状态sd卡未挂载
}
PrintStream ps = getExportToTextPrintStream(); // 获取打印流
if (ps == null) {
Log.e(TAG, "get print stream error"); // 记录日志:获取打印流错误
return STATE_SYSTEM_ERROR; // 返回状态:系统错误
}
// 首先导出文件夹及其笔记
Cursor folderCursor = mContext.getContentResolver().query(
Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION,"(" + NoteColumns.TYPE + "=" + Notes.TYPE_FOLDER + " AND "
+ NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER + ") OR "
+ NoteColumns.ID + "=" + Notes.ID_CALL_RECORD_FOLDER, null, null);
if (folderCursor != null) {
if (folderCursor.moveToFirst()) {
do {
// 打印文件夹的名称
String folderName = "";
if(folderCursor.getLong(NOTE_COLUMN_ID) == Notes.ID_CALL_RECORD_FOLDER) {
folderName = mContext.getString(R.string.call_record_folder_name);
} else {
folderName = folderCursor.getString(NOTE_COLUMN_SNIPPET);
}
if (!TextUtils.isEmpty(folderName)) {
ps.println(String.format(getFormat(FORMAT_FOLDER_NAME), folderName));
}
String folderId = folderCursor.getString(NOTE_COLUMN_ID);
exportFolderToText(folderId, ps); // 导出文件夹到文本
} while (folderCursor.moveToNext());
}
folderCursor.close(); // 关闭游标
}
// 导出根文件夹中的笔记
Cursor noteCursor = mContext.getContentResolver().query(
Notes.CONTENT_NOTE_URI,
NOTE_PROJECTION,
NoteColumns.TYPE + "=" + +Notes.TYPE_NOTE + " AND " + NoteColumns.PARENT_ID
+ "=0", null, null);
if (noteCursor != null) {
if (noteCursor.moveToFirst()) {
do {
ps.println(String.format(getFormat(FORMAT_NOTE_DATE), DateFormat.format(
mContext.getString(R.string.format_datetime_mdhm),
noteCursor.getLong(NOTE_COLUMN_MODIFIED_DATE))));
// 查询属于此笔记的数据
String noteId = noteCursor.getString(NOTE_COLUMN_ID);
exportNoteToText(noteId, ps); // 导出笔记到文本
} while (noteCursor.moveToNext());
}
noteCursor.close(); // 关闭游标
}
ps.close(); // 关闭打印流
return STATE_SUCCESS; // 返回状态:成功
}
/**
*
*/
private PrintStream getExportToTextPrintStream() {
File file = generateFileMountedOnSDcard(mContext, R.string.file_path,
R.string.file_name_txt_format);
if (file == null) {
Log.e(TAG, "create file to exported failed"); // 记录日志:创建导出文件失败
return null;
}
mFileName = file.getName(); // 设置文件名
mFileDirectory = mContext.getString(R.string.file_path); // 设置文件目录
PrintStream ps = null;
try {
FileOutputStream fos = new FileOutputStream(file); // 创建文件输出流
ps = new PrintStream(fos); // 创建打印流
} catch (FileNotFoundException e) {
e.printStackTrace(); // 打印堆栈跟踪
return null;
} catch (NullPointerException e) {
e.printStackTrace(); // 打印堆栈跟踪
return null;
}
return ps; // 返回打印流
}
}
/**
* SD
*/
private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) {
StringBuilder sb = new StringBuilder(); // 创建字符串构建器
sb.append(Environment.getExternalStorageDirectory()); // 追加外部存储目录
sb.append(context.getString(filePathResId)); // 追加文件路径资源ID
File filedir = new File(sb.toString()); // 创建文件目录
sb.append(context.getString( // 追加格式化后的文件名
fileNameFormatResId,
DateFormat.format(context.getString(R.string.format_date_ymd),
System.currentTimeMillis())));
File file = new File(sb.toString()); // 创建文件
try {
if (!filedir.exists()) { // 如果文件目录不存在
filedir.mkdir(); // 创建目录
}
if (!file.exists()) { // 如果文件不存在
file.createNewFile(); // 创建新文件
}
return file; // 返回文件
} catch (SecurityException e) {
e.printStackTrace(); // 打印堆栈跟踪
} catch (IOException e) {
e.printStackTrace(); // 打印堆栈跟踪
}
return null; // 返回null
}
}

@ -0,0 +1,306 @@
/*
* (c) 2010-2011, The MiCode (www.micode.net)
*
* Apache License, Version 2.0
* 使
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
*
*
*/
package net.micode.notes.tool; // 定义包名
import android.content.ContentProviderOperation; // 用于执行内容提供者操作
import android.content.ContentProviderResult; // 用于处理内容提供者操作的结果
import android.content.ContentResolver; // 用于访问内容提供者
import android.content.ContentUris; // 用于构建内容URI
import android.content.ContentValues; // 用于存储键值对
import android.content.OperationApplicationException; // 操作应用异常
import android.database.Cursor; // 用于访问数据库的游标
import android.os.RemoteException; // 远程异常
import android.util.Log; // 日志类
import net.micode.notes.data.Notes; // 笔记数据类
import net.micode.notes.data.Notes.CallNote; // 通话笔记数据类
import net.micode.notes.data.Notes.NoteColumns; // 笔记列数据类
import net.micode.notes.ui.NotesListAdapter.AppWidgetAttribute; // 小部件属性类
import java.util.ArrayList; // 动态数组
import java.util.HashSet; // 哈希集合
public class DataUtils {
public static final String TAG = "DataUtils"; // 日志标签
// 批量删除笔记
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) {
if (ids == null) {
Log.d(TAG, "the ids is null"); // 如果id为null记录日志并返回true
return true;
}
if (ids.size() == 0) {
Log.d(TAG, "no id is in the hashset"); // 如果哈希集中没有id记录日志并返回true
return true;
}
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); // 应用批量操作
if (results == null || results.length == 0 || results[0] == null) {
Log.d(TAG, "delete notes failed, ids:" + ids.toString()); // 删除失败,记录日志
return false;
}
return true; // 删除成功
} catch (RemoteException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); // 远程异常,记录错误日志
} catch (OperationApplicationException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); // 操作应用异常,记录错误日志
}
return false; // 异常时返回false
}
// 将笔记移动到另一个文件夹
public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) {
ContentValues values = new ContentValues(); // 创建ContentValues对象
values.put(NoteColumns.PARENT_ID, desFolderId); // 设置目标文件夹id
values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId); // 设置原始文件夹id
values.put(NoteColumns.LOCAL_MODIFIED, 1); // 设置本地修改标志为1
resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null); // 更新笔记
}
// 批量将笔记移动到指定文件夹
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids,
long folderId) {
if (ids == null) {
Log.d(TAG, "the ids is null"); // id为null时记录日志并返回true
return true;
}
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); // 设置目标文件夹id
builder.withValue(NoteColumns.LOCAL_MODIFIED, 1); // 设置本地修改标志为1
operationList.add(builder.build()); // 添加到操作列表
}
try {
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList); // 应用批量操作
if (results == null || results.length == 0 || results[0] == null) {
Log.d(TAG, "delete notes failed, ids:" + ids.toString()); // 删除失败,记录日志
return false;
}
return true; // 删除成功
} catch (RemoteException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); // 远程异常,记录错误日志
} catch (OperationApplicationException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); // 操作应用异常,记录错误日志
}
return false; // 异常时返回false
}
/**
*
*/
public static int getUserFolderCount(ContentResolver resolver) {
Cursor cursor =resolver.query(Notes.CONTENT_NOTE_URI,
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;
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(); // 关闭游标
}
}
}
return count; // 返回文件夹数量
}
// 检查笔记在数据库中是否可见
public static boolean visibleInNoteDatabase(ContentResolver resolver, long noteId, int type) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null,
NoteColumns.TYPE + "=? AND " + NoteColumns.PARENT_ID + "<>" + Notes.ID_TRASH_FOLER,
new String [] {String.valueOf(type)},
null);
boolean exist = false;
if (cursor != null) {
if (cursor.getCount() > 0) {
exist = true; // 笔记存在且可见
}
cursor.close();
}
return exist; // 返回笔记是否可见
}
// 检查笔记在数据库中是否存在
public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null, null, null, null);
boolean exist = false;
if (cursor != null) {
if (cursor.getCount() > 0) {
exist = true; // 笔记存在
}
cursor.close();
}
return exist; // 返回笔记是否存在
}
// 检查数据在数据库中是否存在
public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId),
null, null, null, null);
boolean exist = false;
if (cursor != null) {
if (cursor.getCount() > 0) {
exist = true; // 数据存在
}
cursor.close();
}
return exist; // 返回数据是否存在
}
// 检查指定名称的文件夹是否可见
public static boolean checkVisibleFolderName(ContentResolver resolver, String name) {
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;
if(cursor != null) {
if(cursor.getCount() > 0) {
exist = true; // 文件夹存在且可见
}
cursor.close();
}
return exist; // 返回文件夹是否可见
}
// 获取文件夹笔记小部件
public static HashSet<AppWidgetAttribute> getFolderNoteWidget(ContentResolver resolver, long folderId) {
Cursor c = resolver.query(Notes.CONTENT_NOTE_URI,
new String[] { NoteColumns.WIDGET_ID, NoteColumns.WIDGET_TYPE },
NoteColumns.PARENT_ID + "=?",
new String[] { String.valueOf(folderId) },
null);
HashSet<AppWidgetAttribute> set = null;
if (c != null) {
if (c.moveToFirst()) {
set = new HashSet<AppWidgetAttribute>();
do {
try {
AppWidgetAttribute widget = new AppWidgetAttribute();
widget.widgetId = c.getInt(0); // 获取小部件ID
widget.widgetType = c.getInt(1); // 获取小部件类型
set.add(widget); // 添加到集合中
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, e.toString()); // 异常,记录错误日志
}
} while (c.moveToNext());
}
c.close(); // 关闭游标
}
return set; // 返回小部件集合
}
// 根据笔记ID获取呼叫号码
public static String getCallNumberByNoteId(ContentResolver resolver, long noteId) {
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);
if (cursor != null && cursor.moveToFirst()) {
try {
return cursor.getString(0); // 获取呼叫号码
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, "Get call number fails " + e.toString()); // 异常,记录错误日志
} finally {
cursor.close(); // 关闭游标
}
}
return ""; // 未找到时返回空字符串
}
// 根据电话号码和呼叫日期获取笔记ID
public static long getNoteIdByPhoneNumberAndCallDate(ContentResolver resolver, String phoneNumber, long callDate) {
Cursor cursor = resolver.query(Notes.CONTENT_DATA_URI,
new String [] { CallNote.NOTE_ID },
CallNote.CALL_DATE + "=? AND " + CallNote.MIME_TYPE + "=? AND PHONE_NUMBERS_EQUAL("
+ CallNote.PHONE_NUMBER + ",?)",
new String [] { String.valueOf(callDate), CallNote.CONTENT_ITEM_TYPE, phoneNumber },
null);
if (cursor != null) {
if (cursor.moveToFirst()) {
try {
return cursor.getLong(0); // 获取笔记ID
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, "Get call note id fails " + e.toString()); // 异常,记录错误日志
}
}
cursor.close(); // 关闭游标
}
return 0; // 未找到时返回0
}
// 根据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; // 返回格式化后的摘要
}
}

@ -0,0 +1,112 @@
/*
* (c) 2010-2011, The MiCode (www.micode.net)
*
* Apache License, Version 2.0
* 使
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
*
*
*/
package net.micode.notes.tool; // 定义包名
public class GTaskStringUtils {
// 定义GTASK JSON动作ID
public final static String GTASK_JSON_ACTION_ID = "action_id";
// 定义GTASK JSON动作列表
public final static String GTASK_JSON_ACTION_LIST = "action_list";
// 定义GTASK JSON动作类型
public final static String GTASK_JSON_ACTION_TYPE = "action_type";
// 定义GTASK JSON动作类型创建
public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create";
// 定义GTASK JSON动作类型获取全部
public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all";
// 定义GTASK JSON动作类型移动
public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move";
// 定义GTASK JSON动作类型更新
public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update";
// 定义GTASK JSON创建者ID
public final static String GTASK_JSON_CREATOR_ID = "creator_id";
// 定义GTASK JSON子实体
public final static String GTASK_JSON_CHILD_ENTITY = "child_entity";
// 定义GTASK JSON客户端版本
public final static String GTASK_JSON_CLIENT_VERSION = "client_version";
// 定义GTASK JSON完成状态
public final static String GTASK_JSON_COMPLETED = "completed";
// 定义GTASK JSON当前列表ID
public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id";
// 定义GTASK JSON默认列表ID
public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id";
// 定义GTASK JSON已删除
public final static String GTASK_JSON_DELETED = "deleted";
// 定义GTASK JSON目标列表
public final static String GTASK_JSON_DEST_LIST = "dest_list";
// 定义GTASK JSON目标父级
public final static String GTASK_JSON_DEST_PARENT = "dest_parent";
// 定义GTASK JSON目标父级类型
public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type";
// 定义GTASK JSON实体变化
public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta";
// 定义GTASK JSON实体类型
public final static String GTASK_JSON_ENTITY_TYPE = "entity_type";
// 定义GTASK JSON获取已删除
public final static String GTASK_JSON_GET_DELETED = "get_deleted";
// 定义GTASK JSON ID
public final static String GTASK_JSON_ID = "id";
// 定义GTASK JSON 索引
public final static String GTASK_JSON_INDEX = "index";
// 定义GTASK JSON最后修改时间
public final static String GTASK_JSON_LAST_MODIFIED = "last_modified";
// 定义GTASK JSON最新同步点
public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point";
// 定义GTASK JSON列表ID
public final static String GTASK_JSON_LIST_ID = "list_id";
// 定义GTASK JSON列表
public final static String GTASK_JSON_LISTS = "lists";
// 定义GTASK JSON名称
public final static String GTASK_JSON_NAME = "name";
// 定义GTASK JSON新ID
public final static String GTASK_JSON_NEW_ID = "new_id";
// 定义GTASK JSON备注
public final static String GTASK_JSON_NOTES = "notes";
// 定义GTASK JSON父级ID
public final static String GTASK_JSON_PARENT_ID = "parent_id";
// 定义GTASK JSON前一个兄弟ID
public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id";
// 定义GTASK JSON结果
public final static String GTASK_JSON_RESULTS = "results";
// 定义GTASK JSON源列表
public final static String GTASK_JSON_SOURCE_LIST = "source_list";
// 定义GTASK JSON任务
public final static String GTASK_JSON_TASKS = "tasks";
// 定义GTASK JSON类型
public final static String GTASK_JSON_TYPE = "type";
// 定义GTASK JSON类型组
public final static String GTASK_JSON_TYPE_GROUP = "GROUP";
// 定义GTASK JSON类型任务
public final static String GTASK_JSON_TYPE_TASK = "TASK";
// 定义GTASK JSON用户
public final static String GTASK_JSON_USER = "user";
// 定义MIUI文件夹前缀
public final static String MIUI_FOLDER_PREFFIX = "[MIUI_Notes]";
// 定义默认文件夹名称
public final static String FOLDER_DEFAULT = "Default";
// 定义通话笔记文件夹名称
public final static String FOLDER_CALL_NOTE = "Call_Note";
// 定义元数据文件夹名称
public final static String FOLDER_META = "METADATA";
// 定义元数据GTASK ID头部
public final static String META_HEAD_GTASK_ID = "meta_gid";
// 定义元数据笔记头部
public final static String META_HEAD_NOTE = "meta_note";
// 定义元数据数据头部
public final static String META_HEAD_DATA = "meta_data";
// 定义元数据笔记名称
public final static String META_NOTE_NAME = "[META INFO] DON'T UPDATE AND DELETE";
}

@ -0,0 +1,211 @@
```java
/*
* (c) 2010-2011, The MiCode (www.micode.net)
*
* Apache License, Version 2.0
* 使
*
*
* http://www.apache.org/licenses/LICENSE-2.0
*
*
*
*
*/
package net.micode.notes.tool; // 定义包名
import android.content.Context; // Android 上下文
import android.preference.PreferenceManager; // 偏好管理器
import net.micode.notes.R; // 资源类
import net.micode.notes.ui.NotesPreferenceActivity; // 笔记偏好活动
public class ResourceParser {
// 定义颜色常量
public static final int YELLOW = 0;
public static final int BLUE = 1;
public static final int WHITE = 2;
public static final int GREEN = 3;
public static final int RED = 4;
// 定义默认背景颜色
public static final int BG_DEFAULT_COLOR = YELLOW;
// 定义字体大小常量
public static final int TEXT_SMALL = 0;
public static final int TEXT_MEDIUM = 1;
public static final int TEXT_LARGE = 2;
public static final int TEXT_SUPER = 3;
// 定义默认字体大小
public static final int BG_DEFAULT_FONT_SIZE = TEXT_MEDIUM;
// 笔记背景资源类
public static class NoteBgResources {
// 编辑状态下的背景资源数组
private final static int [] BG_EDIT_RESOURCES = new int [] {
R.drawable.edit_yellow,
R.drawable.edit_blue,
R.drawable.edit_white,
R.drawable.edit_green,
R.drawable.edit_red
};
// 编辑状态下标题的背景资源数组
private final static int [] BG_EDIT_TITLE_RESOURCES = new int [] {
R.drawable.edit_title_yellow,
R.drawable.edit_title_blue,
R.drawable.edit_title_white,
R.drawable.edit_title_green,
R.drawable.edit_title_red
};
// 获取笔记背景资源
public static int getNoteBgResource(int id) {
return BG_EDIT_RESOURCES[id];
}
// 获取笔记标题背景资源
public static int getNoteTitleBgResource(int id) {
return BG_EDIT_TITLE_RESOURCES[id];
}
}
// 获取默认背景ID
public static int getDefaultBgId(Context context) {
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) {
// 如果设置了背景颜色则随机返回一个颜色ID
return (int) (Math.random() * NoteBgResources.BG_EDIT_RESOURCES.length);
} else {
// 否则返回默认颜色ID
return BG_DEFAULT_COLOR;
}
}
// 笔记项目背景资源类
public static class NoteItemBgResources {
// 第一个项目的背景资源数组
private final static int [] BG_FIRST_RESOURCES = new int [] {
R.drawable.list_yellow_up,
R.drawable.list_blue_up,
R.drawable.list_white_up,
R.drawable.list_green_up,
R.drawable.list_red_up
};
// 普通项目的背景资源数组
private final static int [] BG_NORMAL_RESOURCES = new int [] {
R.drawable.list_yellow_middle,
R.drawable.list_blue_middle,
R.drawable.list_white_middle,
R.drawable.list_green_middle,
R.drawable.list_red_middle
};
// 最后一个项目的背景资源数组
private final static int [] BG_LAST_RESOURCES = new int [] {
R.drawable.list_yellow_down,
R.drawable.list_blue_down,
R.drawable.list_white_down,
R.drawable.list_green_down,
R.drawable.list_red_down,
};
// 单个项目的背景资源数组
private final static int [] BG_SINGLE_RESOURCES = new int [] {
R.drawable.list_yellow_single,
R.drawable.list_blue_single,
R.drawable.list_white_single,
R.drawable.list_green_single,
R.drawable.list_red_single
};
// 获取第一个项目的背景资源
public static int getNoteBgFirstRes(int id) {
return BG_FIRST_RESOURCES[id];
}
// 获取最后一个项目的背景资源
public static int getNoteBgLastRes(int id) {
return BG_LAST_RESOURCES[id];
}
// 获取单个项目的背景资源
public static int getNoteBgSingleRes(int id) {
return BG_SINGLE_RESOURCES[id];
}
// 获取普通项目的背景资源
public static int getNoteBgNormalRes(int id) {
return BG_NORMAL_RESOURCES[id];
}
// 获取文件夹背景资源
public static int getFolderBgRes() {
return R.drawable.list_folder;
}
}
// 小部件背景资源类
public static class WidgetBgResources {
// 2x 小部件背景资源数组
private final static int [] BG_2X_RESOURCES = new int [] {
R.drawable.widget_2x_yellow,
R.drawable.widget_2x_blue,
R.drawable.widget_2x_white,
R.drawable.widget_2x_green,
R.drawable.widget_2x_red,
};
// 获取2x小部件背景资源
public static int getWidget2xBgResource(int id) {
return BG_2X_RESOURCES[id];
}
// 4x 小部件背景资源数组
private final static int [] BG_4X_RESOURCES = new int [] {
R.drawable.widget_4x_yellow,
R.drawable.widget_4x_blue,
R.drawable.widget_4x_white,
R.drawable.widget_4x_green,
R.drawable.widget_4x_red
};
// 获取4x小部件背景资源
public static int getWidget4xBgResource(int id) {
return BG_4X_RESOURCES[id];
}
}
// 文本外观资源类
public static class TextAppearanceResources {
// 字体外观资源数组
private final static int [] TEXTAPPEARANCE_RESOURCES = new int [] {
R.style.TextAppearanceNormal,
R.style.TextAppearanceMedium,
R.style.TextAppearanceLarge,
R.style.TextAppearanceSuper
};
// 获取字体外观资源
public static int getTexAppearanceResource(int id) {
/**
* HACKME: Fix bug of store the resource id in shared preference.
* The id may larger than the length of resources, in this case,
* return the {@link ResourceParser#BG_DEFAULT_FONT_SIZE}
*/
if (id >= TEXTAPPEARANCE_RESOURCES.length) {
return BG_DEFAULT_FONT_SIZE;
}
return TEXTAPPEARANCE_RESOURCES[id];
}
// 获取资源数组的长度
public static int getResourcesSize() {
return TEXTAPPEARANCE_RESOURCES.length;
}
}
}
```
Loading…
Cancel
Save