|
|
@ -0,0 +1,306 @@
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
* 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.ui;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
|
|
|
import android.text.TextUtils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import net.micode.notes.data.Contact;
|
|
|
|
|
|
|
|
import net.micode.notes.data.Notes;
|
|
|
|
|
|
|
|
import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
|
|
|
|
import net.micode.notes.tool.DataUtils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 这个类表示一个笔记项目的数据模型,用于存储与笔记项相关的信息
|
|
|
|
|
|
|
|
public class NoteItemData {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 定义了一个查询投影(Projection),包括从数据库中获取笔记的相关字段
|
|
|
|
|
|
|
|
static final String [] PROJECTION = new String [] {
|
|
|
|
|
|
|
|
NoteColumns.ID, // 笔记的唯一标识符
|
|
|
|
|
|
|
|
NoteColumns.ALERTED_DATE, // 提醒日期
|
|
|
|
|
|
|
|
NoteColumns.BG_COLOR_ID, // 背景颜色ID
|
|
|
|
|
|
|
|
NoteColumns.CREATED_DATE, // 创建日期
|
|
|
|
|
|
|
|
NoteColumns.HAS_ATTACHMENT, // 是否包含附件
|
|
|
|
|
|
|
|
NoteColumns.MODIFIED_DATE, // 修改日期
|
|
|
|
|
|
|
|
NoteColumns.NOTES_COUNT, // 笔记数量
|
|
|
|
|
|
|
|
NoteColumns.PARENT_ID, // 父项ID
|
|
|
|
|
|
|
|
NoteColumns.SNIPPET, // 笔记的摘要
|
|
|
|
|
|
|
|
NoteColumns.TYPE, // 笔记的类型
|
|
|
|
|
|
|
|
NoteColumns.WIDGET_ID, // 小部件ID
|
|
|
|
|
|
|
|
NoteColumns.WIDGET_TYPE, // 小部件类型
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 定义常量,表示数据库查询结果的每一列索引位置
|
|
|
|
|
|
|
|
private static final int ID_COLUMN = 0; // 笔记ID
|
|
|
|
|
|
|
|
private static final int ALERTED_DATE_COLUMN = 1; // 提醒日期列索引
|
|
|
|
|
|
|
|
private static final int BG_COLOR_ID_COLUMN = 2; // 背景颜色列索引
|
|
|
|
|
|
|
|
private static final int CREATED_DATE_COLUMN = 3; // 创建日期列索引
|
|
|
|
|
|
|
|
private static final int HAS_ATTACHMENT_COLUMN = 4; // 附件标志列索引
|
|
|
|
|
|
|
|
private static final int MODIFIED_DATE_COLUMN = 5; // 修改日期列索引
|
|
|
|
|
|
|
|
private static final int NOTES_COUNT_COLUMN = 6; // 笔记数量列索引
|
|
|
|
|
|
|
|
private static final int PARENT_ID_COLUMN = 7; // 父项ID列索引
|
|
|
|
|
|
|
|
private static final int SNIPPET_COLUMN = 8; // 摘要列索引
|
|
|
|
|
|
|
|
private static final int TYPE_COLUMN = 9; // 类型列索引
|
|
|
|
|
|
|
|
private static final int WIDGET_ID_COLUMN = 10; // 小部件ID列索引
|
|
|
|
|
|
|
|
private static final int WIDGET_TYPE_COLUMN = 11; // 小部件类型列索引
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 定义了类中各个属性,用来存储从数据库查询出来的笔记项数据
|
|
|
|
|
|
|
|
private long mId; // 笔记的ID
|
|
|
|
|
|
|
|
private long mAlertDate; // 提醒时间
|
|
|
|
|
|
|
|
private int mBgColorId; // 背景颜色ID
|
|
|
|
|
|
|
|
private long mCreatedDate; // 创建时间
|
|
|
|
|
|
|
|
private boolean mHasAttachment; // 是否有附件
|
|
|
|
|
|
|
|
private long mModifiedDate; // 修改时间
|
|
|
|
|
|
|
|
private int mNotesCount; // 笔记数量
|
|
|
|
|
|
|
|
private long mParentId; // 父笔记ID
|
|
|
|
|
|
|
|
private String mSnippet; // 笔记摘要
|
|
|
|
|
|
|
|
private int mType; // 笔记类型
|
|
|
|
|
|
|
|
private int mWidgetId; // 小部件ID
|
|
|
|
|
|
|
|
private int mWidgetType; // 小部件类型
|
|
|
|
|
|
|
|
private String mName; // 笔记项的名称
|
|
|
|
|
|
|
|
private String mPhoneNumber; // 笔记项关联的电话号码
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 以下是用于标记笔记在显示列表中的状态的布尔值
|
|
|
|
|
|
|
|
private boolean mIsLastItem; // 是否是最后一个笔记项
|
|
|
|
|
|
|
|
private boolean mIsFirstItem; // 是否是第一个笔记项
|
|
|
|
|
|
|
|
private boolean mIsOnlyOneItem; // 是否是唯一的一个笔记项
|
|
|
|
|
|
|
|
private boolean mIsOneNoteFollowingFolder; // 是否是跟随文件夹的第一个笔记
|
|
|
|
|
|
|
|
private boolean mIsMultiNotesFollowingFolder; // 是否是跟随文件夹的多个笔记
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 这里可以写上构造函数、getter和setter方法等,用于初始化和访问这些字段
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 构造函数,初始化 NoteItemData 对象,使用 Context 和 Cursor 作为输入参数
|
|
|
|
|
|
|
|
public NoteItemData(Context context, Cursor cursor) {
|
|
|
|
|
|
|
|
// 从 Cursor 中获取 ID,存储到 mId
|
|
|
|
|
|
|
|
mId = cursor.getLong(ID_COLUMN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取警告日期(ALERTED_DATE_COLUMN),并存储为 mAlertDate
|
|
|
|
|
|
|
|
mAlertDate = cursor.getLong(ALERTED_DATE_COLUMN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取背景颜色ID(BG_COLOR_ID_COLUMN),并存储为 mBgColorId
|
|
|
|
|
|
|
|
mBgColorId = cursor.getInt(BG_COLOR_ID_COLUMN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取创建日期(CREATED_DATE_COLUMN),并存储为 mCreatedDate
|
|
|
|
|
|
|
|
mCreatedDate = cursor.getLong(CREATED_DATE_COLUMN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否有附件(HAS_ATTACHMENT_COLUMN),存储为 mHasAttachment
|
|
|
|
|
|
|
|
mHasAttachment = (cursor.getInt(HAS_ATTACHMENT_COLUMN) > 0) ? true : false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取修改日期(MODIFIED_DATE_COLUMN),并存储为 mModifiedDate
|
|
|
|
|
|
|
|
mModifiedDate = cursor.getLong(MODIFIED_DATE_COLUMN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取笔记数量(NOTES_COUNT_COLUMN),并存储为 mNotesCount
|
|
|
|
|
|
|
|
mNotesCount = cursor.getInt(NOTES_COUNT_COLUMN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取父项 ID(PARENT_ID_COLUMN),并存储为 mParentId
|
|
|
|
|
|
|
|
mParentId = cursor.getLong(PARENT_ID_COLUMN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取笔记的内容摘要(SNIPPET_COLUMN),并清除标记(如果存在)
|
|
|
|
|
|
|
|
mSnippet = cursor.getString(SNIPPET_COLUMN);
|
|
|
|
|
|
|
|
mSnippet = mSnippet.replace(NoteEditActivity.TAG_CHECKED, "").replace(NoteEditActivity.TAG_UNCHECKED, "");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取笔记类型(TYPE_COLUMN),并存储为 mType
|
|
|
|
|
|
|
|
mType = cursor.getInt(TYPE_COLUMN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取小部件 ID(WIDGET_ID_COLUMN),并存储为 mWidgetId
|
|
|
|
|
|
|
|
mWidgetId = cursor.getInt(WIDGET_ID_COLUMN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取小部件类型(WIDGET_TYPE_COLUMN),并存储为 mWidgetType
|
|
|
|
|
|
|
|
mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 默认初始化手机号为空字符串
|
|
|
|
|
|
|
|
mPhoneNumber = "";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果该笔记的父级 ID 是电话记录文件夹的 ID,获取电话记录的号码,并尝试获取联系人名称
|
|
|
|
|
|
|
|
if (mParentId == Notes.ID_CALL_RECORD_FOLDER) {
|
|
|
|
|
|
|
|
// 获取与该笔记 ID 对应的电话记录号码
|
|
|
|
|
|
|
|
mPhoneNumber = DataUtils.getCallNumberByNoteId(context.getContentResolver(), mId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果手机号不为空,尝试获取联系人名称
|
|
|
|
|
|
|
|
if (!TextUtils.isEmpty(mPhoneNumber)) {
|
|
|
|
|
|
|
|
mName = Contact.getContact(context, mPhoneNumber);
|
|
|
|
|
|
|
|
// 如果没有找到联系人,使用手机号作为名称
|
|
|
|
|
|
|
|
if (mName == null) {
|
|
|
|
|
|
|
|
mName = mPhoneNumber;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果联系人名称为空,初始化为空字符串
|
|
|
|
|
|
|
|
if (mName == null) {
|
|
|
|
|
|
|
|
mName = "";
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 调用 checkPostion 方法来判断该笔记在 Cursor 中的位置
|
|
|
|
|
|
|
|
checkPostion(cursor);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 检查该笔记在 Cursor 中的位置
|
|
|
|
|
|
|
|
private void checkPostion(Cursor cursor) {
|
|
|
|
|
|
|
|
// 判断是否是 Cursor 中的最后一项
|
|
|
|
|
|
|
|
mIsLastItem = cursor.isLast() ? true : false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否是 Cursor 中的第一项
|
|
|
|
|
|
|
|
mIsFirstItem = cursor.isFirst() ? true : false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断 Cursor 中是否只有一项
|
|
|
|
|
|
|
|
mIsOnlyOneItem = (cursor.getCount() == 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 默认设置为 false,表示不是多个笔记跟随文件夹
|
|
|
|
|
|
|
|
mIsMultiNotesFollowingFolder = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 默认设置为 false,表示不是一个笔记跟随文件夹
|
|
|
|
|
|
|
|
mIsOneNoteFollowingFolder = false;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 如果当前笔记类型是普通笔记(TYPE_NOTE)并且不是第一项
|
|
|
|
|
|
|
|
if (mType == Notes.TYPE_NOTE && !mIsFirstItem) {
|
|
|
|
|
|
|
|
int position = cursor.getPosition(); // 获取当前笔记在 Cursor 中的位置
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 尝试将 Cursor 移动到上一项
|
|
|
|
|
|
|
|
if (cursor.moveToPrevious()) {
|
|
|
|
|
|
|
|
// 如果上一项是文件夹或系统类型的笔记,检查后续笔记的数量
|
|
|
|
|
|
|
|
if (cursor.getInt(TYPE_COLUMN) == Notes.TYPE_FOLDER
|
|
|
|
|
|
|
|
|| cursor.getInt(TYPE_COLUMN) == Notes.TYPE_SYSTEM) {
|
|
|
|
|
|
|
|
// 如果后续还有笔记,设置为多个笔记跟随文件夹
|
|
|
|
|
|
|
|
if (cursor.getCount() > (position + 1)) {
|
|
|
|
|
|
|
|
mIsMultiNotesFollowingFolder = true;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// 否则,设置为一个笔记跟随文件夹
|
|
|
|
|
|
|
|
mIsOneNoteFollowingFolder = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// 如果无法移动到上一项,抛出异常
|
|
|
|
|
|
|
|
if (!cursor.moveToNext()) {
|
|
|
|
|
|
|
|
throw new IllegalStateException("cursor move to previous but can't move back");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否是单个笔记文件夹
|
|
|
|
|
|
|
|
public boolean isOneFollowingFolder() {
|
|
|
|
|
|
|
|
return mIsOneNoteFollowingFolder; // 返回是否是“单个笔记文件夹”状态的布尔值
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否是多个笔记文件夹
|
|
|
|
|
|
|
|
public boolean isMultiFollowingFolder() {
|
|
|
|
|
|
|
|
return mIsMultiNotesFollowingFolder; // 返回是否是“多个笔记文件夹”状态的布尔值
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断当前项是否是最后一个项
|
|
|
|
|
|
|
|
public boolean isLast() {
|
|
|
|
|
|
|
|
return mIsLastItem; // 返回当前项是否是最后一个项的布尔值
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取笔记的名称
|
|
|
|
|
|
|
|
public String getCallName() {
|
|
|
|
|
|
|
|
return mName; // 返回笔记名称
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断当前项是否是第一个项
|
|
|
|
|
|
|
|
public boolean isFirst() {
|
|
|
|
|
|
|
|
return mIsFirstItem; // 返回当前项是否是第一个项的布尔值
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否是唯一一项
|
|
|
|
|
|
|
|
public boolean isSingle() {
|
|
|
|
|
|
|
|
return mIsOnlyOneItem; // 返回是否是唯一一项的布尔值
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取笔记的ID
|
|
|
|
|
|
|
|
public long getId() {
|
|
|
|
|
|
|
|
return mId; // 返回笔记的唯一标识符(ID)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取笔记的提醒时间
|
|
|
|
|
|
|
|
public long getAlertDate() {
|
|
|
|
|
|
|
|
return mAlertDate; // 返回笔记的提醒时间
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取笔记的创建时间
|
|
|
|
|
|
|
|
public long getCreatedDate() {
|
|
|
|
|
|
|
|
return mCreatedDate; // 返回笔记的创建时间
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断笔记是否有附件
|
|
|
|
|
|
|
|
public boolean hasAttachment() {
|
|
|
|
|
|
|
|
return mHasAttachment; // 返回笔记是否有附件的布尔值
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取笔记的修改时间
|
|
|
|
|
|
|
|
public long getModifiedDate() {
|
|
|
|
|
|
|
|
return mModifiedDate; // 返回笔记的最后修改时间
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取笔记的背景颜色ID
|
|
|
|
|
|
|
|
public int getBgColorId() {
|
|
|
|
|
|
|
|
return mBgColorId; // 返回笔记的背景颜色ID
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取父文件夹ID
|
|
|
|
|
|
|
|
public long getParentId() {
|
|
|
|
|
|
|
|
return mParentId; // 返回笔记的父文件夹ID
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取笔记中的内容数量
|
|
|
|
|
|
|
|
public int getNotesCount() {
|
|
|
|
|
|
|
|
return mNotesCount; // 返回笔记的内容数量
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取父文件夹的ID(重复调用了getParentId方法,功能与getParentId相同)
|
|
|
|
|
|
|
|
public long getFolderId () {
|
|
|
|
|
|
|
|
return mParentId; // 返回笔记的文件夹ID(等同于getParentId)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取笔记的类型
|
|
|
|
|
|
|
|
public int getType() {
|
|
|
|
|
|
|
|
return mType; // 返回笔记的类型ID
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取笔记的widget类型
|
|
|
|
|
|
|
|
public int getWidgetType() {
|
|
|
|
|
|
|
|
return mWidgetType; // 返回笔记的widget类型ID
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取笔记的widget ID
|
|
|
|
|
|
|
|
public int getWidgetId() {
|
|
|
|
|
|
|
|
return mWidgetId; // 返回笔记的widget ID
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取笔记的摘要内容
|
|
|
|
|
|
|
|
public String getSnippet() {
|
|
|
|
|
|
|
|
return mSnippet; // 返回笔记的摘要信息
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断笔记是否设置了提醒
|
|
|
|
|
|
|
|
public boolean hasAlert() {
|
|
|
|
|
|
|
|
return (mAlertDate > 0); // 如果提醒日期大于0,说明有提醒
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 判断是否是通话记录
|
|
|
|
|
|
|
|
public boolean isCallRecord() {
|
|
|
|
|
|
|
|
return (mParentId == Notes.ID_CALL_RECORD_FOLDER && !TextUtils.isEmpty(mPhoneNumber));
|
|
|
|
|
|
|
|
// 判断父文件夹ID是否为通话记录文件夹,且手机号码不为空
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 获取笔记类型,从数据库Cursor中提取笔记类型
|
|
|
|
|
|
|
|
public static int getNoteType(Cursor cursor) {
|
|
|
|
|
|
|
|
return cursor.getInt(TYPE_COLUMN); // 从Cursor中获取笔记类型字段的值
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|