pjfycu7ae 7 months ago
parent 2e7719b809
commit 26953a21ff

@ -1,486 +0,0 @@
/*
* 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;
<<<<<<< HEAD
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
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;
<<<<<<< HEAD
public class Note {
private ContentValues mNoteDiffValues; // 存储笔记的差异值
private NoteData mNoteData; // 存储笔记数据的对象
private static final String TAG = "Note"; // 日志标签
/**
* ID
*/
public static synchronized long getNewNoteId(Context context, long folderId) {
// 创建一个新的笔记并插入到数据库中
ContentValues values = new ContentValues();
long createdTime = System.currentTimeMillis(); // 获取当前时间
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); // 标记为本地修改
values.put(NoteColumns.PARENT_ID, folderId); // 设置父文件夹ID
Uri uri = context.getContentResolver().insert(Notes.CONTENT_NOTE_URI, values); // 插入笔记
long noteId = 0;
try {
noteId = Long.valueOf(uri.getPathSegments().get(1)); // 获取新笔记的ID
} catch (NumberFormatException e) {
Log.e(TAG, "Get note id error :" + e.toString()); // 记录错误日志
noteId = 0;
}
if (noteId == -1) {
throw new IllegalStateException("Wrong note id:" + noteId); // 抛出异常
}
return noteId; // 返回新笔记ID
}
public Note() {
mNoteDiffValues = new ContentValues(); // 初始化差异值
mNoteData = new NoteData(); // 初始化笔记数据
}
// 设置笔记的值
public void setNoteValue(String key, String value) {
mNoteDiffValues.put(key, value); // 设置笔记的值
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); // 标记为本地修改
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); // 更新修改日期
}
// 设置文本数据
public void setTextData(String key, String value) {
mNoteData.setTextData(key, value); // 设置文本数据
}
// 设置文本数据ID
public void setTextDataId(long id) {
mNoteData.setTextDataId(id); // 设置文本数据ID
}
// 获取文本数据ID
public long getTextDataId() {
return mNoteData.mTextDataId; // 获取文本数据ID
}
// 设置通话数据ID
public void setCallDataId(long id) {
mNoteData.setCallDataId(id); // 设置通话数据ID
}
// 设置通话数据
public void setCallData(String key, String value) {
mNoteData.setCallData(key, value); // 设置通话数据
}
// 检查是否有本地修改
public boolean isLocalModified() {
return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified(); // 检查是否有本地修改
}
// 同步笔记到内容解析器
public boolean syncNote(Context context, long noteId) {
if (noteId <= 0) {
throw new IllegalArgumentException("Wrong note id:" + noteId); // 检查笔记ID有效性
}
if (!isLocalModified()) {
return true; // 如果没有本地修改返回true
}
// 更新笔记的本地修改和修改日期
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)) {
return false; // 如果推送失败返回false
}
return true; // 返回成功
}
// 内部类,用于存储笔记数据
private class NoteData {
private long mTextDataId; // 文本数据ID
private ContentValues mTextDataValues; // 文本数据的内容值
private long mCallDataId; // 通话数据ID
private ContentValues mCallDataValues; // 通话数据的内容值
private static final String TAG = "NoteData"; // 日志标签
public NoteData() {
mTextDataValues = new ContentValues(); // 初始化文本数据内容值
mCallDataValues = new ContentValues(); // 初始化通话数据内容值
mTextDataId = 0; // 初始化文本数据ID
mCallDataId = 0; // 初始化通话数据ID
}
// 检查是否有本地修改
boolean isLocalModified() {
return mTextDataValues.size() > 0 || mCallDataValues.size() > 0; // 检查是否有本地修改
}
// 设置文本数据ID
void setTextDataId(long id) {
if(id <= 0) {
throw new IllegalArgumentException("Text data id should larger than 0"); // 检查文本数据ID有效性
}
mTextDataId = id; // 设置文本数据ID
}
// 设置通话数据ID
void setCallDataId(long id) {
if (id <= 0) {
throw new IllegalArgumentException("Call data id should larger than 0"); // 检查通话数据ID有效性
}
mCallDataId = id; // 设置通话数据ID
}
// 设置通话数据
void setCallData(String key, String value) {
mCallDataValues.put(key, value); // 设置通话数据
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); // 标记为本地修改
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); // 更新修改日期
}
// 设置文本数据
void setTextData(String key, String value) {
mTextDataValues.put(key, value); // 设置文本数据
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1); // 标记为本地修改
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis()); // 更新修改日期
}
// 推送数据到内容解析器
Uri pushIntoContentResolver(Context context, long noteId) {
// 检查笔记ID有效性
=======
public class Note {
private ContentValues mNoteDiffValues;
private NoteData mNoteData;
private static final String TAG = "Note";
/**
* Create a new note id for adding a new note to databases
*/
public static synchronized long getNewNoteId(Context context, long folderId) {
// Create a new note in the database
ContentValues values = new ContentValues();
long createdTime = System.currentTimeMillis();
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);
values.put(NoteColumns.PARENT_ID, folderId);
Uri uri = context.getContentResolver().insert(Notes.CONTENT_NOTE_URI, values);
long noteId = 0;
try {
noteId = Long.valueOf(uri.getPathSegments().get(1));
} catch (NumberFormatException e) {
Log.e(TAG, "Get note id error :" + e.toString());
noteId = 0;
}
if (noteId == -1) {
throw new IllegalStateException("Wrong note id:" + noteId);
}
return noteId;
}
public Note() {
mNoteDiffValues = new ContentValues();
mNoteData = new NoteData();
}
public void setNoteValue(String key, String value) {
mNoteDiffValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
}
public void setTextData(String key, String value) {
mNoteData.setTextData(key, value);
}
public void setTextDataId(long id) {
mNoteData.setTextDataId(id);
}
public long getTextDataId() {
return mNoteData.mTextDataId;
}
public void setCallDataId(long id) {
mNoteData.setCallDataId(id);
}
public void setCallData(String key, String value) {
mNoteData.setCallData(key, value);
}
public boolean isLocalModified() {
return mNoteDiffValues.size() > 0 || mNoteData.isLocalModified();
}
public boolean syncNote(Context context, long noteId) {
if (noteId <= 0) {
throw new IllegalArgumentException("Wrong note id:" + noteId);
}
if (!isLocalModified()) {
return true;
}
/**
* In theory, once data changed, the note should be updated on {@link NoteColumns#LOCAL_MODIFIED} and
* {@link NoteColumns#MODIFIED_DATE}. For data safety, though update note fails, we also update the
* note data info
*/
if (context.getContentResolver().update(
ContentUris.withAppendedId(Notes.CONTENT_NOTE_URI, noteId), mNoteDiffValues, null,
null) == 0) {
Log.e(TAG, "Update note error, should not happen");
// Do not return, fall through
}
mNoteDiffValues.clear();
if (mNoteData.isLocalModified()
&& (mNoteData.pushIntoContentResolver(context, noteId) == null)) {
return false;
}
return true;
}
private class NoteData {
private long mTextDataId;
private ContentValues mTextDataValues;
private long mCallDataId;
private ContentValues mCallDataValues;
private static final String TAG = "NoteData";
public NoteData() {
mTextDataValues = new ContentValues();
mCallDataValues = new ContentValues();
mTextDataId = 0;
mCallDataId = 0;
}
boolean isLocalModified() {
return mTextDataValues.size() > 0 || mCallDataValues.size() > 0;
}
void setTextDataId(long id) {
if(id <= 0) {
throw new IllegalArgumentException("Text data id should larger than 0");
}
mTextDataId = id;
}
void setCallDataId(long id) {
if (id <= 0) {
throw new IllegalArgumentException("Call data id should larger than 0");
}
mCallDataId = id;
}
void setCallData(String key, String value) {
mCallDataValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
}
void setTextData(String key, String value) {
mTextDataValues.put(key, value);
mNoteDiffValues.put(NoteColumns.LOCAL_MODIFIED, 1);
mNoteDiffValues.put(NoteColumns.MODIFIED_DATE, System.currentTimeMillis());
}
Uri pushIntoContentResolver(Context context, long noteId) {
/**
* Check for safety
*/
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
if (noteId <= 0) {
throw new IllegalArgumentException("Wrong note id:" + noteId);
}
<<<<<<< HEAD
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>(); // 操作列表
ContentProviderOperation.Builder builder = null; // 操作构建器
// 如果有文本数据,插入或更新
if(mTextDataValues.size() > 0) {
mTextDataValues.put(DataColumns.NOTE_ID, noteId); // 设置笔记ID
if (mTextDataId == 0) {
mTextDataValues.put(DataColumns.MIME_TYPE, TextNote.CONTENT_ITEM_TYPE); // 设置MIME类型
Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI,
mTextDataValues); // 插入文本数据
try {
setTextDataId(Long.valueOf(uri.getPathSegments().get(1))); // 获取文本数据ID
} catch (NumberFormatException e) {
Log.e(TAG, "Insert new text data fail with noteId" + noteId); // 记录插入错误
mTextDataValues.clear(); // 清空文本数据
return null; // 返回null
}
} else {
builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mTextDataId)); // 创建更新操作
builder.withValues(mTextDataValues); // 设置更新值
operationList.add(builder.build()); // 添加到操作列表
}
mTextDataValues.clear(); // 清空文本数据
}
// 如果有通话数据,插入或更新
if(mCallDataValues.size() > 0) {
mCallDataValues.put(DataColumns.NOTE_ID, noteId); // 设置笔记ID
if (mCallDataId == 0) {
mCallDataValues.put(DataColumns.MIME_TYPE, CallNote.CONTENT_ITEM_TYPE); // 设置MIME类型
Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI,
mCallDataValues); // 插入通话数据
try {
setCallDataId(Long.valueOf(uri.getPathSegments().get(1))); // 获取通话数据ID
} catch (NumberFormatException e) {
Log.e(TAG, "Insert new call data fail with noteId" + noteId); // 记录插入错误
mCallDataValues.clear(); // 清空通话数据
return null; // 返回null
}
} else {
builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mCallDataId)); // 创建更新操作
builder.withValues(mCallDataValues); // 设置更新值
operationList.add(builder.build()); // 添加到操作列表
}
mCallDataValues.clear(); // 清空通话数据
}
// 执行批量操作
if (operationList.size() > 0) {
try {
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); // 返回笔记URI
} catch (RemoteException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); // 记录远程异常
return null; // 返回null
} catch (OperationApplicationException e) {
Log.e(TAG, String.format("%s: %s", e.toString(), e.getMessage())); // 记录操作应用异常
return null; // 返回null
}
}
return null; // 返回null
}
}
}
=======
ArrayList<ContentProviderOperation> operationList = new ArrayList<ContentProviderOperation>();
ContentProviderOperation.Builder builder = null;
if(mTextDataValues.size() > 0) {
mTextDataValues.put(DataColumns.NOTE_ID, noteId);
if (mTextDataId == 0) {
mTextDataValues.put(DataColumns.MIME_TYPE, TextNote.CONTENT_ITEM_TYPE);
Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI,
mTextDataValues);
try {
setTextDataId(Long.valueOf(uri.getPathSegments().get(1)));
} catch (NumberFormatException e) {
Log.e(TAG, "Insert new text data fail with noteId" + noteId);
mTextDataValues.clear();
return null;
}
} else {
builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mTextDataId));
builder.withValues(mTextDataValues);
operationList.add(builder.build());
}
mTextDataValues.clear();
}
if(mCallDataValues.size() > 0) {
mCallDataValues.put(DataColumns.NOTE_ID, noteId);
if (mCallDataId == 0) {
mCallDataValues.put(DataColumns.MIME_TYPE, CallNote.CONTENT_ITEM_TYPE);
Uri uri = context.getContentResolver().insert(Notes.CONTENT_DATA_URI,
mCallDataValues);
try {
setCallDataId(Long.valueOf(uri.getPathSegments().get(1)));
} catch (NumberFormatException e) {
Log.e(TAG, "Insert new call data fail with noteId" + noteId);
mCallDataValues.clear();
return null;
}
} else {
builder = ContentProviderOperation.newUpdate(ContentUris.withAppendedId(
Notes.CONTENT_DATA_URI, mCallDataId));
builder.withValues(mCallDataValues);
operationList.add(builder.build());
}
mCallDataValues.clear();
}
if (operationList.size() > 0) {
try {
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;
}
}
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a

@ -1,602 +0,0 @@
/*
* 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;
<<<<<<< HEAD
public class WorkingNote {
// 当前工作笔记对象
private Note mNote;
// 笔记ID
private long mNoteId;
// 笔记内容
private String mContent;
// 笔记模式
private int mMode;
private long mAlertDate; // 提醒日期
private long mModifiedDate; // 修改日期
private int mBgColorId; // 背景颜色ID
private int mWidgetId; // 小部件ID
private int mWidgetType; // 小部件类型
private long mFolderId; // 文件夹ID
private Context mContext; // 上下文
private static final String TAG = "WorkingNote"; // 日志标签
private boolean mIsDeleted; // 是否已删除
private NoteSettingChangedListener mNoteSettingStatusListener; // 笔记设置状态监听器
// 数据投影
=======
public class WorkingNote {
// Note for the working note
private Note mNote;
// Note Id
private long mNoteId;
// Note content
private String mContent;
// Note mode
private int mMode;
private long mAlertDate;
private long mModifiedDate;
private int mBgColorId;
private int mWidgetId;
private int mWidgetType;
private long mFolderId;
private Context mContext;
private static final String TAG = "WorkingNote";
private boolean mIsDeleted;
private NoteSettingChangedListener mNoteSettingStatusListener;
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public static final String[] DATA_PROJECTION = new String[] {
DataColumns.ID,
DataColumns.CONTENT,
DataColumns.MIME_TYPE,
DataColumns.DATA1,
DataColumns.DATA2,
DataColumns.DATA3,
DataColumns.DATA4,
};
<<<<<<< HEAD
// 笔记投影
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
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
};
<<<<<<< HEAD
// 数据列索引
private static final int DATA_ID_COLUMN = 0;
private static final int DATA_CONTENT_COLUMN = 1;
private static final int DATA_MIME_TYPE_COLUMN = 2;
private static final int DATA_MODE_COLUMN = 3;
// 笔记列索引
private static final int NOTE_PARENT_ID_COLUMN = 0;
private static final int NOTE_ALERTED_DATE_COLUMN = 1;
private static final int NOTE_BG_COLOR_ID_COLUMN = 2;
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;
// 新建笔记构造函数
=======
private static final int DATA_ID_COLUMN = 0;
private static final int DATA_CONTENT_COLUMN = 1;
private static final int DATA_MIME_TYPE_COLUMN = 2;
private static final int DATA_MODE_COLUMN = 3;
private static final int NOTE_PARENT_ID_COLUMN = 0;
private static final int NOTE_ALERTED_DATE_COLUMN = 1;
private static final int NOTE_BG_COLOR_ID_COLUMN = 2;
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;
// New note construct
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private WorkingNote(Context context, long folderId) {
mContext = context;
mAlertDate = 0;
mModifiedDate = System.currentTimeMillis();
mFolderId = folderId;
<<<<<<< HEAD
mNote = new Note(); // 初始化笔记对象
mNoteId = 0;
mIsDeleted = false;
mMode = 0;
mWidgetType = Notes.TYPE_WIDGET_INVALIDE; // 默认小部件类型
}
// 现有笔记构造函数
=======
mNote = new Note();
mNoteId = 0;
mIsDeleted = false;
mMode = 0;
mWidgetType = Notes.TYPE_WIDGET_INVALIDE;
}
// Existing note construct
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private WorkingNote(Context context, long noteId, long folderId) {
mContext = context;
mNoteId = noteId;
mFolderId = folderId;
mIsDeleted = false;
<<<<<<< HEAD
mNote = new Note(); // 初始化笔记对象
loadNote(); // 加载笔记数据
}
// 加载笔记信息
=======
mNote = new Note();
loadNote();
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
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()) {
<<<<<<< HEAD
// 从游标中获取笔记信息
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
mFolderId = cursor.getLong(NOTE_PARENT_ID_COLUMN);
mBgColorId = cursor.getInt(NOTE_BG_COLOR_ID_COLUMN);
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);
}
<<<<<<< HEAD
cursor.close(); // 关闭游标
=======
cursor.close();
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
} else {
Log.e(TAG, "No note with id:" + mNoteId);
throw new IllegalArgumentException("Unable to find note with id " + mNoteId);
}
<<<<<<< HEAD
loadNoteData(); // 加载笔记数据
}
// 加载笔记数据
=======
loadNoteData();
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
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 {
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);
<<<<<<< HEAD
mNote.setTextDataId(cursor.getLong(DATA_ID_COLUMN)); // 设置文本数据ID
} else if (DataConstants.CALL_NOTE.equals(type)) {
mNote.setCallDataId(cursor.getLong(DATA_ID_COLUMN)); // 设置通话数据ID
=======
mNote.setTextDataId(cursor.getLong(DATA_ID_COLUMN));
} else if (DataConstants.CALL_NOTE.equals(type)) {
mNote.setCallDataId(cursor.getLong(DATA_ID_COLUMN));
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
} else {
Log.d(TAG, "Wrong note type with type:" + type);
}
} while (cursor.moveToNext());
}
<<<<<<< HEAD
cursor.close(); // 关闭游标
=======
cursor.close();
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
} else {
Log.e(TAG, "No data with id:" + mNoteId);
throw new IllegalArgumentException("Unable to find note's data with id " + mNoteId);
}
}
<<<<<<< HEAD
// 创建空笔记
public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,
int widgetType, int defaultBgColorId) {
WorkingNote note = new WorkingNote(context, folderId);
note.setBgColorId(defaultBgColorId); // 设置默认背景颜色
note.setWidgetId(widgetId); // 设置小部件ID
note.setWidgetType(widgetType); // 设置小部件类型
return note;
}
// 加载现有笔记
=======
public static WorkingNote createEmptyNote(Context context, long folderId, int widgetId,
int widgetType, int defaultBgColorId) {
WorkingNote note = new WorkingNote(context, folderId);
note.setBgColorId(defaultBgColorId);
note.setWidgetId(widgetId);
note.setWidgetType(widgetType);
return note;
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public static WorkingNote load(Context context, long id) {
return new WorkingNote(context, id, 0);
}
<<<<<<< HEAD
// 保存笔记
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public synchronized boolean saveNote() {
if (isWorthSaving()) {
if (!existInDatabase()) {
if ((mNoteId = Note.getNewNoteId(mContext, mFolderId)) == 0) {
Log.e(TAG, "Create new note fail with id:" + mNoteId);
return false;
}
}
<<<<<<< HEAD
mNote.syncNote(mContext, mNoteId); // 同步笔记到数据库
// 更新小部件内容
=======
mNote.syncNote(mContext, mNoteId);
/**
* Update widget content if there exist any widget of this note
*/
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE
&& mNoteSettingStatusListener != null) {
mNoteSettingStatusListener.onWidgetChanged();
}
return true;
} else {
return false;
}
}
<<<<<<< HEAD
// 检查笔记是否存在于数据库中
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public boolean existInDatabase() {
return mNoteId > 0;
}
<<<<<<< HEAD
// 检查笔记是否值得保存
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
private boolean isWorthSaving() {
if (mIsDeleted || (!existInDatabase() && TextUtils.isEmpty(mContent))
|| (existInDatabase() && !mNote.isLocalModified())) {
return false;
} else {
return true;
}
}
<<<<<<< HEAD
// 设置笔记设置状态监听器
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public void setOnSettingStatusChangedListener(NoteSettingChangedListener l) {
mNoteSettingStatusListener = l;
}
<<<<<<< HEAD
// 设置提醒日期
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
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);
}
}
<<<<<<< HEAD
// 标记笔记为已删除
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public void markDeleted(boolean mark) {
mIsDeleted = mark;
if (mWidgetId != AppWidgetManager.INVALID_APPWIDGET_ID
&& mWidgetType != Notes.TYPE_WIDGET_INVALIDE && mNoteSettingStatusListener != null) {
mNoteSettingStatusListener.onWidgetChanged();
}
}
<<<<<<< HEAD
// 设置背景颜色ID
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public void setBgColorId(int id) {
if (id != mBgColorId) {
mBgColorId = id;
if (mNoteSettingStatusListener != null) {
mNoteSettingStatusListener.onBackgroundColorChanged();
}
mNote.setNoteValue(NoteColumns.BG_COLOR_ID, String.valueOf(id));
}
}
<<<<<<< HEAD
// 设置检查列表模式
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public void setCheckListMode(int mode) {
if (mMode != mode) {
if (mNoteSettingStatusListener != null) {
mNoteSettingStatusListener.onCheckListModeChanged(mMode, mode);
}
mMode = mode;
mNote.setTextData(TextNote.MODE, String.valueOf(mMode));
}
}
<<<<<<< HEAD
// 设置小部件类型
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public void setWidgetType(int type) {
if (type != mWidgetType) {
mWidgetType = type;
mNote.setNoteValue(NoteColumns.WIDGET_TYPE, String.valueOf(mWidgetType));
}
}
<<<<<<< HEAD
// 设置小部件ID
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public void setWidgetId(int id) {
if (id != mWidgetId) {
mWidgetId = id;
mNote.setNoteValue(NoteColumns.WIDGET_ID, String.valueOf(mWidgetId));
}
}
<<<<<<< HEAD
// 设置工作文本
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public void setWorkingText(String text) {
if (!TextUtils.equals(mContent, text)) {
mContent = text;
mNote.setTextData(DataColumns.CONTENT, mContent);
}
}
<<<<<<< HEAD
// 转换为通话笔记
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public void convertToCallNote(String phoneNumber, long callDate) {
mNote.setCallData(CallNote.CALL_DATE, String.valueOf(callDate));
mNote.setCallData(CallNote.PHONE_NUMBER, phoneNumber);
mNote.setNoteValue(NoteColumns.PARENT_ID, String.valueOf(Notes.ID_CALL_RECORD_FOLDER));
}
<<<<<<< HEAD
// 检查是否有提醒
public boolean hasClockAlert() {
return (mAlertDate > 0);
}
// 获取笔记内容
=======
public boolean hasClockAlert() {
return (mAlertDate > 0 ? true : false);
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public String getContent() {
return mContent;
}
<<<<<<< HEAD
// 获取提醒日期
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public long getAlertDate() {
return mAlertDate;
}
<<<<<<< HEAD
// 获取修改日期
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public long getModifiedDate() {
return mModifiedDate;
}
<<<<<<< HEAD
// 获取背景颜色资源ID
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public int getBgColorResId() {
return NoteBgResources.getNoteBgResource(mBgColorId);
}
<<<<<<< HEAD
// 获取背景颜色ID
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public int getBgColorId() {
return mBgColorId;
}
<<<<<<< HEAD
// 获取标题背景资源ID
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public int getTitleBgResId() {
return NoteBgResources.getNoteTitleBgResource(mBgColorId);
}
<<<<<<< HEAD
// 获取检查列表模式
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public int getCheckListMode() {
return mMode;
}
<<<<<<< HEAD
// 获取笔记ID
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public long getNoteId() {
return mNoteId;
}
<<<<<<< HEAD
// 获取文件夹ID
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public long getFolderId() {
return mFolderId;
}
<<<<<<< HEAD
// 获取小部件ID
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public int getWidgetId() {
return mWidgetId;
}
<<<<<<< HEAD
// 获取小部件类型
=======
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
public int getWidgetType() {
return mWidgetType;
}
<<<<<<< HEAD
// 笔记设置状态监听器接口
public interface NoteSettingChangedListener {
/**
*
=======
public interface NoteSettingChangedListener {
/**
* Called when the background color of current note has just changed
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
void onBackgroundColorChanged();
/**
<<<<<<< HEAD
*
=======
* Called when user set clock
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
void onClockAlertChanged(long date, boolean set);
/**
<<<<<<< HEAD
*
=======
* Call when user create note from widget
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
*/
void onWidgetChanged();
/**
<<<<<<< HEAD
*
* @param oldMode
* @param newMode
*/
void onCheckListModeChanged(int oldMode, int newMode);
}
}
=======
* 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);
}
}
>>>>>>> e05b61b64084e5e29a71e127701acf0431fab91a
Loading…
Cancel
Save