lyt_brand
JUNNE_TOPIC1 3 weeks ago
parent 66477b8b40
commit ca3342b097

@ -0,0 +1,390 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.model;
import android.content.ContentProviderOperation;
import android.content.ContentProviderResult;
import android.content.ContentUris;
import android.content.ContentValues;
import android.content.Context;
import android.content.OperationApplicationException;
import android.net.Uri;
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.DataColumns;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.Notes.TextNote;
import java.util.ArrayList;
/**
*
*
*/
public class Note {
// 用于存储笔记的差异值,即笔记有改动的属性值
private ContentValues mNoteDiffValues;
// 用于存储笔记的数据,包括文本数据和通话数据
private NoteData mNoteData;
// 日志标签,用于在日志中标识该类的信息
private static final String TAG = "Note";
/**
* ID
*
* @param context 访
* @param folderId ID
* @return ID
*/
public static synchronized long getNewNoteId(Context context, long folderId) {
// 创建一个新的 ContentValues 对象,用于存储要插入数据库的笔记信息
ContentValues values = new ContentValues();
// 获取当前时间作为笔记的创建时间
long createdTime = System.currentTimeMillis();
// 将创建时间添加到 ContentValues 中
values.put(NoteColumns.CREATED_DATE, createdTime);
// 将修改时间设置为创建时间,因为是新创建的笔记
values.put(NoteColumns.MODIFIED_DATE, createdTime);
// 设置笔记的类型为普通笔记
values.put(NoteColumns.TYPE, Notes.TYPE_NOTE);
// 标记笔记为本地已修改
values.put(NoteColumns.LOCAL_MODIFIED, 1);
// 设置笔记所属文件夹的 ID
values.put(NoteColumns.PARENT_ID, folderId);
// 使用内容解析器插入新笔记,并获取插入后的 URI
Uri uri = context.getContentResolver().insert(Notes.CONTENT_NOTE_URI, values);
long noteId = 0;
try {
// 从 URI 中提取笔记的 ID
noteId = Long.valueOf(uri.getPathSegments().get(1));
} catch (NumberFormatException e) {
// 若提取 ID 时出现异常,记录错误日志
Log.e(TAG, "Get note id error :" + e.toString());
noteId = 0;
}
if (noteId == -1) {
// 若笔记 ID 为 -1抛出异常表示笔记 ID 错误
throw new IllegalStateException("Wrong note id:" + noteId);
}
return noteId;
}
/**
*
*/
public Note() {
mNoteDiffValues = new ContentValues();
mNoteData = new NoteData();
}
/**
*
*
* @param key
* @param value
*/
public void setNoteValue(String key, String value) {
mNoteDiffValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
}
/**
*
*
* @param key
* @param value
*/
public void setTextData(String key, String value) {
mNoteData.setTextData(key, value);
}
/**
* ID
*
* @param id ID
*/
public void setTextDataId(long id) {
mNoteData.setTextDataId(id);
}
/**
* ID
*
* @return ID
*/
public long getTextDataId() {
return mNoteData.mTextDataId;
}
/**
* ID
*
* @param id ID
*/
public void setCallDataId(long id) {
mNoteData.setCallDataId(id);
}
/**
*
*
* @param key
* @param value
*/
public void setCallData(String key, String value) {
mNoteData.setCallData(key, value);
}
/**
*
*
* @return true false
*/
public boolean isLocalModified() {
return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified();
}
/**
*
*
* @param context 访
* @param noteId ID
* @return true false
*/
public boolean syncNote(Context context, long noteId) {
if (noteId <= 0) {
// 若笔记 ID 不合法,抛出异常
throw new IllegalArgumentException("Wrong note id:" + noteId);
}
if (!isLocalModified()) {
// 若笔记未被修改,直接返回 true
return true;
}
/**
* LOCAL_MODIFIED MODIFIED_DATE
* 使
*/
if (context.getContentResolver().update(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), mNoteDiffValues, null,
null) == 0) {
// 若更新笔记失败,记录错误日志
Log.e(TAG, "Update note error, should not happen");
// 不返回,继续执行后续操作
}
// 清空笔记的差异值
mNoteDiffValues.clear();
if (mNoteData.isLocalModified()
&& (mNoteData.pushIntoContentResolver(context, noteId) == null)) {
// 若笔记数据被修改且同步失败,返回 false
return false;
}
return true;
}
/**
*
*/
private class NoteData {
// 文本数据的 ID
private long mTextDataId;
// 存储文本数据的 ContentValues 对象
private ContentValues mTextDataValues;
// 通话数据的 ID
private long mCallDataId;
// 存储通话数据的 ContentValues 对象
private ContentValues mCallDataValues;
// 日志标签,用于在日志中标识该内部类的信息
private static final String TAG = "NoteData";
/**
* ContentValues ID 0
*/
public NoteData() {
mTextDataValues = new ContentValues();
mCallDataValues = new ContentValues();
mTextDataId = 0;
mCallDataId = 0;
}
/**
*
*
* @return true false
*/
boolean isLocalModified() {
return mTextDataValues.size() > 0 || mCallDataValues.size() > 0;
}
/**
* ID
*
* @param id ID
*/
void setTextDataId(long id) {
if(id <= 0) {
// 若文本数据 ID 不合法,抛出异常
throw new IllegalArgumentException("Text data id should larger than 0");
}
mTextDataId = id;
}
/**
* ID
*
* @param id ID
*/
void setCallDataId(long id) {
if (id <= 0) {
// 若通话数据 ID 不合法,抛出异常
throw new IllegalArgumentException("Call data id should larger than 0");
}
mCallDataId = id;
}
/**
*
*
* @param key
* @param value
*/
void setCallData(String key, String value) {
mCallDataValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
}
/**
*
*
* @param key
* @param value
*/
void setTextData(String key, String value) {
mTextDataValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
}
/**
*
*
* @param context 访
* @param noteId ID
* @return URI null
*/
Uri pushIntoContentResolver(Context context, long noteId) {
/**
* ID
*/
if (noteId <= 0) {
// 若笔记 ID 不合法,抛出异常
throw new IllegalArgumentException("Wrong note id:" + noteId);
}
// 创建一个 ContentProviderOperation 列表,用于批量操作
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
// ContentProviderOperation 构建器
ContentProviderOperation.Builder builder = null;
if(mTextDataValues.size() > 0) {
// 若文本数据有修改
mTextDataValues.put(DataColumns.NOTE_ID, noteId);
if (mTextDataId == 0) {
// 若文本数据 ID 为 0说明是新的文本数据
mTextDataValues.put(DataColumns.MIME_TYPE, TextNote.CONTENT_ITEM_TYPE);
// 插入新的文本数据
Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI,
mTextDataValues);
try {
// 获取插入后的文本数据 ID
setTextDataId(Long.valueOf(uri.getPathSegments().get(1)));
} catch (NumberFormatException e) {
// 若获取 ID 失败,记录错误日志并清空文本数据
Log.e(TAG, "Insert new text data fail with noteId" + noteId);
mTextDataValues.clear();
return null;
}
} else {
// 若文本数据 ID 不为 0说明是更新已有的文本数据
builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mTextDataId));
builder.withValues(mTextDataValues);
operationList.add(builder.build());
}
// 清空文本数据的 ContentValues 对象
mTextDataValues.clear();
}
if(mCallDataValues.size() > 0) {
// 若通话数据有修改
mCallDataValues.put(DataColumns.NOTE_ID, noteId);
if (mCallDataId == 0) {
// 若通话数据 ID 为 0说明是新的通话数据
mCallDataValues.put(DataColumns.MIME_TYPE, CallNote.CONTENT_ITEM_TYPE);
// 插入新的通话数据
Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI,
mCallDataValues);
try {
// 获取插入后的通话数据 ID
setCallDataId(Long.valueOf(uri.getPathSegments().get(1)));
} catch (NumberFormatException e) {
// 若获取 ID 失败,记录错误日志并清空通话数据
Log.e(TAG, "Insert new call data fail with noteId" + noteId);
mCallDataValues.clear();
return null;
}
} else {
// 若通话数据 ID 不为 0说明是更新已有的通话数据
builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mCallDataId));
builder.withValues(mCallDataValues);
operationList.add(builder.build());
}
// 清空通话数据的 ContentValues 对象
mCallDataValues.clear();
}
if (operationList.size() > 0) {
try {
// 批量执行 ContentProviderOperation 列表中的操作
ContentProviderResult[] results = context.getContentResolver().applyBatch(
Notes.AUTHORITY, operationList);
return (results == null || results.length == 0 || results[0] == null) ? null
: ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId);
} catch (RemoteException e) {
// 若执行批量操作时出现远程异常,记录错误日志
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
return null;
} catch (OperationApplicationException e) {
// 若执行批量操作时出现操作应用异常,记录错误日志
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage()));
return null;
}
}
return null;
}
}
}

@ -0,0 +1,523 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.model;
import android.appwidget.AppWidgetManager;
import android.content.ContentUris;
import android.content.Context;
import android.database.Cursor;
import android.text.TextUtils;
import android.util.Log;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.CallNote;
import net.micode.notes.data.Notes.DataColumns;
import net.micode.notes.data.Notes.DataConstants;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.data.Notes.TextNote;
import net.micode.notes.tool.ResourceParser.NoteBgResources;
/**
* WorkingNote 便
* 便便
*/
public class WorkingNote {
// 便签对象,用于管理便签的各种数据
private Note mNote;
// 便签的 ID
private long mNoteId;
// 便签的内容
private String mContent;
// 便签的模式
private int mMode;
// 便签的提醒日期
private long mAlertDate;
// 便签的修改日期
private long mModifiedDate;
// 便签的背景颜色 ID
private int mBgColorId;
// 便签小部件的 ID
private int mWidgetId;
// 便签小部件的类型
private int mWidgetType;
// 便签所在文件夹的 ID
private long mFolderId;
// 上下文对象,用于访问系统资源和执行操作
private Context mContext;
// 日志标签,用于调试日志输出
private static final String TAG = "WorkingNote";
// 标记便签是否已被删除
private boolean mIsDeleted;
// 便签设置更改监听器,用于监听便签设置的变化
private NoteSettingChangedListener mNoteSettingStatusListener;
// 数据查询的投影列,用于从数据库中查询数据
public static final String[] DATA_PROJECTION = new String[] {
DataColumns.ID,
DataColumns.CONTENT,
DataColumns.MIME_TYPE,
DataColumns.DATA1,
DataColumns.DATA2,
DataColumns.DATA3,
DataColumns.DATA4,
};
// 便签查询的投影列,用于从数据库中查询便签信息
public static final String[] NOTE_PROJECTION = new String[] {
NoteColumns.PARENT_ID,
NoteColumns.ALERTED_DATE,
NoteColumns.BG_COLOR_ID,
NoteColumns.WIDGET_ID,
NoteColumns.WIDGET_TYPE,
NoteColumns.MODIFIED_DATE
};
// 数据 ID 列的索引
private static final int DATA_ID_COLUMN = 0;
// 数据内容列的索引
private static final int DATA_CONTENT_COLUMN = 1;
// 数据 MIME 类型列的索引
private static final int DATA_MIME_TYPE_COLUMN = 2;
// 数据模式列的索引
private static final int DATA_MODE_COLUMN = 3;
// 便签父文件夹 ID 列的索引
private static final int NOTE_PARENT_ID_COLUMN = 0;
// 便签提醒日期列的索引
private static final int NOTE_ALERTED_DATE_COLUMN = 1;
// 便签背景颜色 ID 列的索引
private static final int NOTE_BG_COLOR_ID_COLUMN = 2;
// 便签小部件 ID 列的索引
private static final int NOTE_WIDGET_ID_COLUMN = 3;
// 便签小部件类型列的索引
private static final int NOTE_WIDGET_TYPE_COLUMN = 4;
// 便签修改日期列的索引
private static final int NOTE_MODIFIED_DATE_COLUMN = 5;
/**
* 便
*
* @param context
* @param folderId 便 ID
*/
private WorkingNote(Context context, long folderId) {
mContext = context;
// 初始化提醒日期为 0表示没有提醒
mAlertDate = 0;
// 初始化修改日期为当前时间
mModifiedDate = System.currentTimeMillis();
mFolderId = folderId;
mNote = new Note();
// 初始化便签 ID 为 0表示新便签还未分配 ID
mNoteId = 0;
// 标记便签未被删除
mIsDeleted = false;
// 初始化便签模式为 0
mMode = 0;
// 初始化小部件类型为无效类型
mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
}
/**
* 便
*
* @param context
* @param noteId 便 ID
* @param folderId 便 ID
*/
private WorkingNote(Context context, long noteId, long folderId) {
mContext = context;
mNoteId = noteId;
mFolderId = folderId;
// 标记便签未被删除
mIsDeleted = false;
mNote = new Note();
// 加载便签信息
loadNote();
}
/**
* 便 ID ID ID
*/
private void loadNote() {
// 查询便签信息
Cursor cursor = mContext.getContentResolver().query(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, mNoteId), NOTE_PROJECTION, null,
null, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
// 获取便签所在文件夹的 ID
mFolderId = cursor.getLong(NOTE_PARENT_ID_COLUMN);
// 获取便签的背景颜色 ID
mBgColorId = cursor.getInt(NOTE_BG_COLOR_ID_COLUMN);
// 获取便签小部件的 ID
mWidgetId = cursor.getInt(NOTE_WIDGET_ID_COLUMN);
// 获取便签小部件的类型
mWidgetType = cursor.getInt(NOTE_WIDGET_TYPE_COLUMN);
// 获取便签的提醒日期
mAlertDate = cursor.getLong(NOTE_ALERTED_DATE_COLUMN);
// 获取便签的修改日期
mModifiedDate = cursor.getLong(NOTE_MODIFIED_DATE_COLUMN);
}
// 关闭游标
cursor.close();
} else {
// 记录错误日志
Log.e(TAG, "No note with id:" + mNoteId);
// 抛出异常,表示找不到指定 ID 的便签
throw new IllegalArgumentException("Unable to find note with id " + mNoteId);
}
// 加载便签的数据
loadNoteData();
}
/**
* 便便
*/
private void loadNoteData() {
// 查询便签的数据
Cursor cursor = mContext.getContentResolver().query(Notes.CONTENT_DATA_URI, DATA_PROJECTION,
DataColumns.NOTE_ID + "=?", new String[] {
String.valueOf(mNoteId)
}, null);
if (cursor != null) {
if (cursor.moveToFirst()) {
do {
// 获取数据的 MIME 类型
String type = cursor.getString(DATA_MIME_TYPE_COLUMN);
if (DataConstants.NOTE.equals(type)) {
// 如果是普通便签类型,获取便签内容和模式
mContent = cursor.getString(DATA_CONTENT_COLUMN);
mMode = cursor.getInt(DATA_MODE_COLUMN);
// 设置便签的文本数据 ID
mNote.setTextDataId(cursor.getLong(DATA_ID_COLUMN));
} else if (DataConstants.CALL_NOTE.equals(type)) {
// 如果是通话便签类型,设置通话数据 ID
mNote.setCallDataId(cursor.getLong(DATA_ID_COLUMN));
} else {
// 记录日志,表示遇到错误的便签类型
Log.d(TAG, "Wrong note type with type:" + type);
}
} while (cursor.moveToNext());
}
// 关闭游标
cursor.close();
} else {
// 记录错误日志
Log.e(TAG, "No data with id:" + mNoteId);
// 抛出异常,表示找不到指定 ID 的便签数据
throw new IllegalArgumentException("Unable to find note's data with id " + mNoteId);
}
}
/**
* 便
*
* @param context
* @param folderId 便 ID
* @param widgetId 便 ID
* @param widgetType 便
* @param defaultBgColorId 便 ID
* @return 便
*/
public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,
int widgetType, int defaultBgColorId) {
// 创建一个新的便签对象
WorkingNote note = new WorkingNote(context, folderId);
// 设置便签的背景颜色 ID
note.setBgColorId(defaultBgColorId);
// 设置便签小部件的 ID
note.setWidgetId(widgetId);
// 设置便签小部件的类型
note.setWidgetType(widgetType);
return note;
}
/**
* ID 便
*
* @param context
* @param id 便 ID
* @return 便
*/
public static WorkingNote load(Context context, long id) {
return new WorkingNote(context, id, 0);
}
/**
* 便
*
* @return true false
*/
public synchronized boolean saveNote() {
if (isWorthSaving()) {
if (!existInDatabase()) {
// 如果便签不在数据库中,创建一个新的便签 ID
if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) {
// 记录错误日志
Log.e(TAG, "Create new note fail with id:" + mNoteId);
return false;
}
}
// 同步便签数据到数据库
mNote.syncNote(mContext, mNoteId);
/**
* 便
*/
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE
&& mNoteSettingStatusListener != null) {
// 通知监听器小部件内容发生变化
mNoteSettingStatusListener.onWidgetChanged();
}
return true;
} else {
return false;
}
}
/**
* 便
*
* @return true false
*/
public boolean existInDatabase() {
return mNoteId > 0;
}
/**
* 便
*
* @return true false
*/
private boolean isWorthSaving() {
if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent))
|| (existInDatabase() && !mNote.isLocalModified())) {
return false;
} else {
return true;
}
}
/**
* 便
*
* @param l
*/
public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
mNoteSettingStatusListener = l;
}
/**
* 便
*
* @param date
* @param set
*/
public void setAlertDate(long date, boolean set) {
if (date != mAlertDate) {
mAlertDate = date;
// 设置便签的提醒日期
mNote.setNoteValue(NoteColumns.ALERTED_DATE, String.valueOf(mAlertDate));
}
if (mNoteSettingStatusListener != null) {
// 通知监听器提醒日期发生变化
mNoteSettingStatusListener.onClockAlertChanged(date, set);
}
}
/**
* 便
*
* @param mark true
*/
public void markDeleted(boolean mark) {
mIsDeleted = mark;
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE && mNoteSettingStatusListener != null) {
// 通知监听器小部件内容发生变化
mNoteSettingStatusListener.onWidgetChanged();
}
}
/**
* 便 ID
*
* @param id ID
*/
public void setBgColorId(int id) {
if (id != mBgColorId) {
mBgColorId = id;
if (mNoteSettingStatusListener != null) {
// 通知监听器背景颜色发生变化
mNoteSettingStatusListener.onBackgroundColorChanged();
}
// 设置便签的背景颜色 ID
mNote.setNoteValue(NoteColumns.BG_COLOR_ID, String.valueOf(id));
}
}
/**
* 便
*
* @param mode
*/
public void setCheckListMode(int mode) {
if (mMode != mode) {
if (mNoteSettingStatusListener != null) {
// 通知监听器检查列表模式发生变化
mNoteSettingStatusListener.onCheckListModeChanged(mMode, mode);
}
mMode = mode;
// 设置便签的文本数据模式
mNote.setTextData(TextNote.MODE, String.valueOf(mMode));
}
}
/**
* 便
*
* @param type
*/
public void setWidgetType(int type) {
if (type != mWidgetType) {
mWidgetType = type;
// 设置便签的小部件类型
mNote.setNoteValue(NoteColumns.WIDGET_TYPE, String.valueOf(mWidgetType));
}
}
/**
* 便 ID
*
* @param id ID
*/
public void setWidgetId(int id) {
if (id != mWidgetId) {
mWidgetId = id;
// 设置便签的小部件 ID
mNote.setNoteValue(NoteColumns.WIDGET_ID, String.valueOf(mWidgetId));
}
}
/**
* 便
*
* @param text
*/
public void setWorkingText(String text) {
if (!TextUtils.equals(mContent, text)) {
mContent = text;
// 设置便签的文本数据内容
mNote.setTextData(DataColumns.CONTENT, mContent);
}
}
/**
* 便便
*
* @param phoneNumber
* @param callDate
*/
public void convertToCallNote(String phoneNumber, long callDate) {
// 设置通话便签的通话日期
mNote.setCallData(CallNote.CALL_DATE, String.valueOf(callDate));
// 设置通话便签的电话号码
mNote.setCallData(CallNote.PHONE_NUMBER, phoneNumber);
// 设置便签的父文件夹 ID 为通话记录文件夹的 ID
mNote.setNoteValue(NoteColumns.PARENT_ID, String.valueOf(Notes.ID_CALL_RECORD_FOLDER));
}
/**
* 便
*
* @return true false
*/
public boolean hasClockAlert() {
return (mAlertDate > 0 ? true : false);
}
public String getContent() {
return mContent;
}
public long getAlertDate() {
return mAlertDate;
}
public long getModifiedDate() {
return mModifiedDate;
}
public int getBgColorResId() {
return NoteBgResources.getNoteBgResource(mBgColorId);
}
public int getBgColorId() {
return mBgColorId;
}
public int getTitleBgResId() {
return NoteBgResources.getNoteTitleBgResource(mBgColorId);
}
public int getCheckListMode() {
return mMode;
}
public long getNoteId() {
return mNoteId;
}
public long getFolderId() {
return mFolderId;
}
public int getWidgetId() {
return mWidgetId;
}
public int getWidgetType() {
return mWidgetType;
}
public interface NoteSettingChangedListener {
/**
* Called when the background color of current note has just changed
*/
void onBackgroundColorChanged();
/**
* Called when user set clock
*/
void onClockAlertChanged(long date, boolean set);
/**
* Call when user create note from widget
*/
void onWidgetChanged();
/**
* Call when switch between check list mode and normal mode
* @param oldMode is previous mode before change
* @param newMode is new mode
*/
void onCheckListModeChanged(int oldMode, int newMode);
}
}

@ -0,0 +1,226 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.widget;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.util.Log;
import android.widget.RemoteViews;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.data.Notes.NoteColumns;
import net.micode.notes.tool.ResourceParser;
import net.micode.notes.ui.NoteEditActivity;
import net.micode.notes.ui.NotesListActivity;
/**
* NoteWidgetProvider AppWidgetProvider
*
*/
public abstract class NoteWidgetProvider extends AppWidgetProvider {
// 查询笔记信息时使用的投影,指定要查询的列
public static final String [] PROJECTION = new String [] {
NoteColumns.ID,
NoteColumns.BG_COLOR_ID,
NoteColumns.SNIPPET
};
// 笔记 ID 在投影数组中的索引
public static final int COLUMN_ID = 0;
// 笔记背景颜色 ID 在投影数组中的索引
public static final int COLUMN_BG_COLOR_ID = 1;
// 笔记摘要在投影数组中的索引
public static final int COLUMN_SNIPPET = 2;
// 日志标签,用于在日志中标识该类的相关信息
private static final String TAG = "NoteWidgetProvider";
/**
*
* ID
*
* @param context
* @param appWidgetIds ID
*/
@Override
public void onDeleted(Context context, int[] appWidgetIds) {
// 创建 ContentValues 对象,用于存储要更新的字段和值
ContentValues values = new ContentValues();
// 将笔记的小部件 ID 设置为无效值
values.put(NoteColumns.WIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID);
// 遍历被删除的小部件 ID 数组
for (int i = 0; i < appWidgetIds.length; i++) {
// 更新笔记数据库中对应小部件 ID 的笔记记录
context.getContentResolver().update(Notes.CONTENT_NOTE_URI,
values,
NoteColumns.WIDGET_ID + "=?",
new String[] { String.valueOf(appWidgetIds[i])});
}
}
/**
* ID
*
* @param context
* @param widgetId ID
* @return null
*/
private Cursor getNoteWidgetInfo(Context context, int widgetId) {
// 查询笔记数据库,获取指定小部件 ID 且不在回收站的笔记信息
return context.getContentResolver().query(Notes.CONTENT_NOTE_URI,
PROJECTION,
NoteColumns.WIDGET_ID + "=? AND " + NoteColumns.PARENT_ID + "<>?",
new String[] { String.valueOf(widgetId), String.valueOf(Notes.ID_TRASH_FOLER) },
null);
}
/**
*
*
* @param context
* @param appWidgetManager
* @param appWidgetIds ID
*/
protected void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// 调用带隐私模式参数的更新方法,隐私模式为 false
update(context, appWidgetManager, appWidgetIds, false);
}
/**
*
* ID
*
* @param context
* @param appWidgetManager
* @param appWidgetIds ID
* @param privacyMode
*/
private void update(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds,
boolean privacyMode) {
// 遍历要更新的小部件 ID 数组
for (int i = 0; i < appWidgetIds.length; i++) {
// 检查小部件 ID 是否有效
if (appWidgetIds[i] != AppWidgetManager.INVALID_APPWIDGET_ID) {
// 获取默认的背景颜色 ID
int bgId = ResourceParser.getDefaultBgId(context);
// 初始化笔记摘要为空字符串
String snippet = "";
// 创建一个启动笔记编辑活动的意图
Intent intent = new Intent(context, NoteEditActivity.class);
// 设置意图标志,确保活动以单顶模式启动
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
// 将小部件 ID 作为额外数据添加到意图中
intent.putExtra(Notes.INTENT_EXTRA_WIDGET_ID, appWidgetIds[i]);
// 将小部件类型作为额外数据添加到意图中
intent.putExtra(Notes.INTENT_EXTRA_WIDGET_TYPE, getWidgetType());
// 获取指定小部件 ID 的笔记信息游标
Cursor c = getNoteWidgetInfo(context, appWidgetIds[i]);
if (c != null && c.moveToFirst()) {
// 检查是否存在多条具有相同小部件 ID 的笔记记录
if (c.getCount() > 1) {
// 记录错误日志
Log.e(TAG, "Multiple message with same widget id:" + appWidgetIds[i]);
// 关闭游标
c.close();
return;
}
// 从游标中获取笔记摘要
snippet = c.getString(COLUMN_SNIPPET);
// 从游标中获取笔记背景颜色 ID
bgId = c.getInt(COLUMN_BG_COLOR_ID);
// 将笔记 ID 作为额外数据添加到意图中
intent.putExtra(Intent.EXTRA_UID, c.getLong(COLUMN_ID));
// 设置意图的动作类型为查看
intent.setAction(Intent.ACTION_VIEW);
} else {
// 如果没有找到笔记信息,设置默认的提示信息
snippet = context.getResources().getString(R.string.widget_havenot_content);
// 设置意图的动作类型为插入或编辑
intent.setAction(Intent.ACTION_INSERT_OR_EDIT);
}
// 关闭游标
if (c != null) {
c.close();
}
// 创建 RemoteViews 对象,用于设置小部件的布局
RemoteViews rv = new RemoteViews(context.getPackageName(), getLayoutId());
// 设置小部件的背景图片资源
rv.setImageViewResource(R.id.widget_bg_image, getBgResourceId(bgId));
// 将背景颜色 ID 作为额外数据添加到意图中
intent.putExtra(Notes.INTENT_EXTRA_BACKGROUND_ID, bgId);
/**
* 宿
*/
PendingIntent pendingIntent = null;
if (privacyMode) {
// 如果开启隐私模式,设置小部件文本为隐私模式提示信息
rv.setTextViewText(R.id.widget_text,
context.getString(R.string.widget_under_visit_mode));
// 创建启动笔记列表活动的待定意图
pendingIntent = PendingIntent.getActivity(context, appWidgetIds[i], new Intent(
context, NotesListActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
} else {
// 如果未开启隐私模式,设置小部件文本为笔记摘要
rv.setTextViewText(R.id.widget_text, snippet);
// 创建启动笔记编辑活动的待定意图
pendingIntent = PendingIntent.getActivity(context, appWidgetIds[i], intent,
PendingIntent.FLAG_UPDATE_CURRENT);
}
// 设置小部件文本的点击事件为待定意图
rv.setOnClickPendingIntent(R.id.widget_text, pendingIntent);
// 更新指定小部件 ID 的小部件布局
appWidgetManager.updateAppWidget(appWidgetIds[i], rv);
}
}
}
/**
* ID ID
*
*
* @param bgId ID
* @return ID
*/
protected abstract int getBgResourceId(int bgId);
/**
* ID
*
*
* @return ID
*/
protected abstract int getLayoutId();
/**
*
*
*
* @return
*/
protected abstract int getWidgetType();
}

@ -0,0 +1,77 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.widget;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.tool.ResourceParser;
/**
* NoteWidgetProvider_2x NoteWidgetProvider 2x
* 2x
*/
public class NoteWidgetProvider_2x extends NoteWidgetProvider {
/**
*
* update
*
* @param context
* @param appWidgetManager
* @param appWidgetIds ID
*/
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// 调用父类的 update 方法进行小部件更新
super.update(context, appWidgetManager, appWidgetIds);
}
/**
* 2x ID
*
* @return 2x ID R.layout.widget_2x
*/
@Override
protected int getLayoutId() {
return R.layout.widget_2x;
}
/**
* ID 2x ID
* ResourceParser WidgetBgResources
*
* @param bgId ID
* @return 2x ID
*/
@Override
protected int getBgResourceId(int bgId) {
return ResourceParser.WidgetBgResources.getWidget2xBgResource(bgId);
}
/**
* 2x
*
* @return 2x Notes.TYPE_WIDGET_2X
*/
@Override
protected int getWidgetType() {
return Notes.TYPE_WIDGET_2X;
}
}

@ -0,0 +1,76 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.widget;
import android.appwidget.AppWidgetManager;
import android.content.Context;
import net.micode.notes.R;
import net.micode.notes.data.Notes;
import net.micode.notes.tool.ResourceParser;
/**
* NoteWidgetProvider_4x NoteWidgetProvider 4x
* 4x
*/
public class NoteWidgetProvider_4x extends NoteWidgetProvider {
/**
*
* update
*
* @param context
* @param appWidgetManager
* @param appWidgetIds ID
*/
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
// 调用父类的 update 方法进行小部件更新
super.update(context, appWidgetManager, appWidgetIds);
}
/**
* 4x ID
*
* @return 4x ID R.layout.widget_4x
*/
protected int getLayoutId() {
return R.layout.widget_4x;
}
/**
* ID 4x ID
* ResourceParser WidgetBgResources
*
* @param bgId ID
* @return 4x ID
*/
@Override
protected int getBgResourceId(int bgId) {
return ResourceParser.WidgetBgResources.getWidget4xBgResource(bgId);
}
/**
* 4x
*
* @return 4x Notes.TYPE_WIDGET_4X
*/
@Override
protected int getWidgetType() {
return Notes.TYPE_WIDGET_4X;
}
}

@ -0,0 +1,441 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.tool;
import android.content.Context;
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;
// 获取 BackupUtils 的单例实例
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;
// 私有构造函数,确保只能通过 getInstance 方法获取实例
private BackupUtils(Context context) {
// 初始化 TextExport 实例
mTextExport = new TextExport(context);
}
// 检查外部存储是否可用
private static boolean externalStorageAvailable() {
// 检查外部存储的状态是否为已挂载
return Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState());
}
// 将笔记数据导出为文本文件
public int exportToText() {
// 调用 TextExport 类的 exportToText 方法进行导出操作
return mTextExport.exportToText();
}
// 获取导出的文本文件的文件名
public String getExportedTextFileName() {
// 返回 TextExport 类中保存的文件名
return mTextExport.mFileName;
}
// 获取导出的文本文件的目录
public String getExportedTextFileDir() {
// 返回 TextExport 类中保存的文件目录
return mTextExport.mFileDirectory;
}
// 内部类,用于实现将笔记数据导出为文本文件的具体逻辑
private static class TextExport {
// 查询笔记信息时使用的投影,指定要查询的列
private static final String[] NOTE_PROJECTION = {
NoteColumns.ID,
NoteColumns.MODIFIED_DATE,
NoteColumns.SNIPPET,
NoteColumns.TYPE
};
// 笔记 ID 在投影数组中的索引
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;
// 笔记数据 MIME 类型在投影数组中的索引
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;
// 导出的文本文件的文件名
private String mFileName;
// 导出的文本文件的目录
private String mFileDirectory;
// 构造函数,初始化 TextExport 类的实例
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];
}
/**
*
*
* @param folderId ID
* @param ps
*/
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))));
// 获取笔记的 ID
String noteId = notesCursor.getString(NOTE_COLUMN_ID);
// 将该笔记导出为文本
exportNoteToText(noteId, ps);
} while (notesCursor.moveToNext());
}
// 关闭游标,释放资源
notesCursor.close();
}
}
/**
* ID
*
* @param noteId ID
* @param ps
*/
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 {
// 获取数据的 MIME 类型
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());
}
}
/**
*
*
* @return STATE_SD_CARD_UNMOUONTEDSTATE_SYSTEM_ERROR STATE_SUCCESS
*/
public int exportToText() {
// 检查外部存储是否可用
if (!externalStorageAvailable()) {
// 记录日志信息
Log.d(TAG, "Media was not mounted");
// 返回 SD 卡未挂载的状态码
return STATE_SD_CARD_UNMOUONTED;
}
// 获取用于导出文本的打印流
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));
}
// 获取文件夹 ID
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))));
// 获取笔记的 ID
String noteId = noteCursor.getString(NOTE_COLUMN_ID);
// 将该笔记导出为文本
exportNoteToText(noteId, ps);
} while (noteCursor.moveToNext());
}
// 关闭游标,释放资源
noteCursor.close();
}
// 关闭打印流
ps.close();
// 返回导出成功的状态码
return STATE_SUCCESS;
}
/**
*
*
* @return null
*/
private PrintStream getExportToTextPrintStream() {
// 生成一个存储在 SD 卡上的文件
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");
// 返回 null 表示创建文件失败
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();
// 返回 null 表示文件未找到
return null;
} catch (NullPointerException e) {
// 打印异常堆栈信息
e.printStackTrace();
// 返回 null 表示空指针异常
return null;
}
// 返回打印流对象
return ps;
}
}
/**
* SD
*
* @param context
* @param filePathResId ID
* @param fileNameFormatResId ID
* @return null
*/
private static File generateFileMountedOnSDcard(Context context, int filePathResId, int fileNameFormatResId) {
// 创建一个 StringBuilder 对象,用于构建文件路径
StringBuilder sb = new StringBuilder();
// 添加外部存储目录
sb.append(Environment.getExternalStorageDirectory());
// 添加文件路径
sb.append(context.getString(filePathResId));
// 创建文件目录对象
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();
}
// 如果出现异常,返回 null
return null;
}
}

@ -0,0 +1,467 @@
//*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.tool;
import android.content.ContentProviderOperation;
import android.content.ContentProviderResult;
import android.content.ContentResolver;
import android.content.ContentUris;
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";
/**
*
*
* @param resolver
* @param ids ID
* @return true false
*/
public static boolean batchDeleteNotes(ContentResolver resolver, HashSet<Long> ids) {
// 检查传入的 ID 集合是否为空
if (ids == null) {
// 如果为空,记录日志并返回 true
Log.d(TAG, "the ids is null");
return true;
}
// 检查 ID 集合的大小是否为 0
if (ids.size() == 0) {
// 如果为 0记录日志并返回 true
Log.d(TAG, "no id is in the hashset");
return true;
}
// 创建一个用于存储内容提供者操作的列表
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
// 遍历 ID 集合
for (long id : ids) {
// 检查是否为系统根文件夹的 ID如果是则不进行删除操作并记录错误日志
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) {
// 如果无效,记录日志并返回 false
Log.d(TAG, "delete notes failed, ids:" + ids.toString());
return false;
}
// 操作成功,返回 true
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()));
}
// 发生异常,返回 false
return false;
}
/**
*
*
* @param resolver
* @param id ID
* @param srcFolderId ID
* @param desFolderId ID
*/
public static void moveNoteToFoler(ContentResolver resolver, long id, long srcFolderId, long desFolderId) {
// 创建一个 ContentValues 对象,用于存储要更新的字段和值
ContentValues values = new ContentValues();
// 设置笔记的父文件夹 ID 为目标文件夹 ID
values.put(NoteColumns.PARENT_ID, desFolderId);
// 设置笔记的原始父文件夹 ID 为源文件夹 ID
values.put(NoteColumns.ORIGIN_PARENT_ID, srcFolderId);
// 设置笔记的本地修改标志为 1
values.put(NoteColumns.LOCAL_MODIFIED, 1);
// 执行更新操作,将笔记移动到目标文件夹
resolver.update(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id), values, null, null);
}
/**
*
*
* @param resolver
* @param ids ID
* @param folderId ID
* @return true false
*/
public static boolean batchMoveToFolder(ContentResolver resolver, HashSet<Long> ids,
long folderId) {
// 检查传入的 ID 集合是否为空
if (ids == null) {
// 如果为空,记录日志并返回 true
Log.d(TAG, "the ids is null");
return true;
}
// 创建一个用于存储内容提供者操作的列表
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
// 遍历 ID 集合
for (long id : ids) {
// 创建一个更新操作的构建器
ContentProviderOperation.Builder builder = ContentProviderOperation
.newUpdate(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, id));
// 设置笔记的父文件夹 ID 为目标文件夹 ID
builder.withValue(NoteColumns.PARENT_ID, folderId);
// 设置笔记的本地修改标志为 1
builder.withValue(NoteColumns.LOCAL_MODIFIED, 1);
// 将构建好的更新操作添加到操作列表中
operationList.add(builder.build());
}
try {
// 应用批量操作并获取操作结果
ContentProviderResult[] results = resolver.applyBatch(Notes.AUTHORITY, operationList);
// 检查操作结果是否为空或无效
if (results == null || results.length == 0 || results[0] == null) {
// 如果无效,记录日志并返回 false
Log.d(TAG, "delete notes failed, ids:" + ids.toString());
return false;
}
// 操作成功,返回 true
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()));
}
// 发生异常,返回 false
return false;
}
/**
*
*
* @param resolver
* @return
*/
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);
// 初始化文件夹数量为 0
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;
}
/**
*
*
* @param resolver
* @param noteId ID
* @param type
* @return true false
*/
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);
// 初始化存在标志为 false
boolean exist = false;
// 检查游标是否不为空
if (cursor != null) {
// 检查游标中的记录数量是否大于 0
if (cursor.getCount() > 0) {
// 如果大于 0说明笔记存在设置存在标志为 true
exist = true;
}
// 关闭游标
cursor.close();
}
// 返回存在标志
return exist;
}
/**
*
*
* @param resolver
* @param noteId ID
* @return true false
*/
public static boolean existInNoteDatabase(ContentResolver resolver, long noteId) {
// 查询笔记数据库,检查笔记是否存在
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId),
null, null, null, null);
// 初始化存在标志为 false
boolean exist = false;
// 检查游标是否不为空
if (cursor != null) {
// 检查游标中的记录数量是否大于 0
if (cursor.getCount() > 0) {
// 如果大于 0说明笔记存在设置存在标志为 true
exist = true;
}
// 关闭游标
cursor.close();
}
// 返回存在标志
return exist;
}
/**
*
*
* @param resolver
* @param dataId ID
* @return true false
*/
public static boolean existInDataDatabase(ContentResolver resolver, long dataId) {
// 查询数据数据库,检查数据是否存在
Cursor cursor = resolver.query(ContentUris.withAppendedId(Notes.CONTENT_DATA_URI, dataId),
null, null, null, null);
// 初始化存在标志为 false
boolean exist = false;
// 检查游标是否不为空
if (cursor != null) {
// 检查游标中的记录数量是否大于 0
if (cursor.getCount() > 0) {
// 如果大于 0说明数据存在设置存在标志为 true
exist = true;
}
// 关闭游标
cursor.close();
}
// 返回存在标志
return exist;
}
/**
*
*
* @param resolver
* @param name
* @return true false
*/
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);
// 初始化存在标志为 false
boolean exist = false;
// 检查游标是否不为空
if(cursor != null) {
// 检查游标中的记录数量是否大于 0
if(cursor.getCount() > 0) {
// 如果大于 0说明文件夹名称已存在设置存在标志为 true
exist = true;
}
// 关闭游标
cursor.close();
}
// 返回存在标志
return exist;
}
/**
*
*
* @param resolver
* @param folderId ID
* @return null
*/
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);
// 初始化小部件属性集合为 null
HashSet<AppWidgetAttribute> set = null;
// 检查游标是否不为空
if (c != null) {
// 将游标移动到第一行
if (c.moveToFirst()) {
// 创建一个小部件属性集合
set = new HashSet<AppWidgetAttribute>();
do {
try {
// 创建一个小部件属性对象
AppWidgetAttribute widget = new AppWidgetAttribute();
// 从游标中获取小部件 ID
widget.widgetId = c.getInt(0);
// 从游标中获取小部件类型
widget.widgetType = c.getInt(1);
// 将小部件属性对象添加到集合中
set.add(widget);
} catch (IndexOutOfBoundsException e) {
// 捕获索引越界异常并记录错误日志
Log.e(TAG, e.toString());
}
} while (c.moveToNext());
}
// 关闭游标
c.close();
}
// 返回小部件属性集合
return set;
}
/**
* ID
*
* @param resolver
* @param noteId ID
* @return
*/
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
*
* @param resolver
* @param phoneNumber
* @param callDate
* @return ID 0
*/
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);
} catch (IndexOutOfBoundsException e) {
Log.e(TAG, "Get call note id fails " + e.toString());
}
}
cursor.close();
}
return 0;
}
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,163 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.tool;
/**
* Google GTask JSON
* GTask 使
*/
public class GTaskStringUtils {
// 表示动作 ID 的 JSON 键名
public final static String GTASK_JSON_ACTION_ID = "action_id";
// 表示动作列表的 JSON 键名
public final static String GTASK_JSON_ACTION_LIST = "action_list";
// 表示动作类型的 JSON 键名
public final static String GTASK_JSON_ACTION_TYPE = "action_type";
// 表示创建动作类型的 JSON 值
public final static String GTASK_JSON_ACTION_TYPE_CREATE = "create";
// 表示获取所有数据动作类型的 JSON 值
public final static String GTASK_JSON_ACTION_TYPE_GETALL = "get_all";
// 表示移动动作类型的 JSON 值
public final static String GTASK_JSON_ACTION_TYPE_MOVE = "move";
// 表示更新动作类型的 JSON 值
public final static String GTASK_JSON_ACTION_TYPE_UPDATE = "update";
// 表示创建者 ID 的 JSON 键名
public final static String GTASK_JSON_CREATOR_ID = "creator_id";
// 表示子实体的 JSON 键名
public final static String GTASK_JSON_CHILD_ENTITY = "child_entity";
// 表示客户端版本的 JSON 键名
public final static String GTASK_JSON_CLIENT_VERSION = "client_version";
// 表示任务是否完成的 JSON 键名
public final static String GTASK_JSON_COMPLETED = "completed";
// 表示当前列表 ID 的 JSON 键名
public final static String GTASK_JSON_CURRENT_LIST_ID = "current_list_id";
// 表示默认列表 ID 的 JSON 键名
public final static String GTASK_JSON_DEFAULT_LIST_ID = "default_list_id";
// 表示是否删除的 JSON 键名
public final static String GTASK_JSON_DELETED = "deleted";
// 表示目标列表的 JSON 键名
public final static String GTASK_JSON_DEST_LIST = "dest_list";
// 表示目标父实体的 JSON 键名
public final static String GTASK_JSON_DEST_PARENT = "dest_parent";
// 表示目标父实体类型的 JSON 键名
public final static String GTASK_JSON_DEST_PARENT_TYPE = "dest_parent_type";
// 表示实体增量的 JSON 键名
public final static String GTASK_JSON_ENTITY_DELTA = "entity_delta";
// 表示实体类型的 JSON 键名
public final static String GTASK_JSON_ENTITY_TYPE = "entity_type";
// 表示获取已删除数据的 JSON 键名
public final static String GTASK_JSON_GET_DELETED = "get_deleted";
// 表示 ID 的 JSON 键名
public final static String GTASK_JSON_ID = "id";
// 表示索引的 JSON 键名
public final static String GTASK_JSON_INDEX = "index";
// 表示最后修改时间的 JSON 键名
public final static String GTASK_JSON_LAST_MODIFIED = "last_modified";
// 表示最新同步点的 JSON 键名
public final static String GTASK_JSON_LATEST_SYNC_POINT = "latest_sync_point";
// 表示列表 ID 的 JSON 键名
public final static String GTASK_JSON_LIST_ID = "list_id";
// 表示列表集合的 JSON 键名
public final static String GTASK_JSON_LISTS = "lists";
// 表示名称的 JSON 键名
public final static String GTASK_JSON_NAME = "name";
// 表示新 ID 的 JSON 键名
public final static String GTASK_JSON_NEW_ID = "new_id";
// 表示备注的 JSON 键名
public final static String GTASK_JSON_NOTES = "notes";
// 表示父实体 ID 的 JSON 键名
public final static String GTASK_JSON_PARENT_ID = "parent_id";
// 表示前一个兄弟实体 ID 的 JSON 键名
public final static String GTASK_JSON_PRIOR_SIBLING_ID = "prior_sibling_id";
// 表示结果的 JSON 键名
public final static String GTASK_JSON_RESULTS = "results";
// 表示源列表的 JSON 键名
public final static String GTASK_JSON_SOURCE_LIST = "source_list";
// 表示任务集合的 JSON 键名
public final static String GTASK_JSON_TASKS = "tasks";
// 表示类型的 JSON 键名
public final static String GTASK_JSON_TYPE = "type";
// 表示组类型的 JSON 值
public final static String GTASK_JSON_TYPE_GROUP = "GROUP";
// 表示任务类型的 JSON 值
public final static String GTASK_JSON_TYPE_TASK = "TASK";
// 表示用户的 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";
// 元数据头部 Google 任务 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";
}
11

@ -0,0 +1,270 @@
/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.micode.notes.tool;
import android.content.Context;
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
};
/**
* ID ID
* @param id ID
* @return ID
*/
public static int getNoteBgResource(int id) {
return BG_EDIT_RESOURCES[id];
}
/**
* ID ID
* @param id ID
* @return ID
*/
public static int getNoteTitleBgResource(int id) {
return BG_EDIT_TITLE_RESOURCES[id];
}
}
/**
* ID
* ID
* ID
* @param context
* @return ID
*/
public static int getDefaultBgId(Context context) {
if (PreferenceManager.getDefaultSharedPreferences(context).getBoolean(
NotesPreferenceActivity.PREFERENCE_SET_BG_COLOR_KEY, false)) {
return (int) (Math.random() * NoteBgResources.BG_EDIT_RESOURCES.length);
} else {
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
};
/**
* ID ID
* @param id ID
* @return ID
*/
public static int getNoteBgFirstRes(int id) {
return BG_FIRST_RESOURCES[id];
}
/**
* ID ID
* @param id ID
* @return ID
*/
public static int getNoteBgLastRes(int id) {
return BG_LAST_RESOURCES[id];
}
/**
* ID ID
* @param id ID
* @return ID
*/
public static int getNoteBgSingleRes(int id) {
return BG_SINGLE_RESOURCES[id];
}
/**
* ID ID
* @param id ID
* @return ID
*/
public static int getNoteBgNormalRes(int id) {
return BG_NORMAL_RESOURCES[id];
}
/**
* ID
* @return 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,
};
/**
* ID 2x ID
* @param id ID
* @return 2x ID
*/
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
};
/**
* ID 4x ID
* @param id ID
* @return 4x ID
*/
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
};
/**
* ID ID
* ID ID
* @param id ID
* @return ID
*/
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];
}
/**
*
* @return
*/
public static int getResourcesSize() {
return TEXTAPPEARANCE_RESOURCES.length;
}
}
}

@ -0,0 +1 @@
assdjgyuguyhgnb6
Loading…
Cancel
Save