You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
226 lines
10 KiB
226 lines
10 KiB
/*
|
|
* 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; // 导入Context类
|
|
import android.database.Cursor; // 导入Cursor类
|
|
import android.text.TextUtils; // 导入TextUtils类
|
|
|
|
import net.micode.notes.data.Contact; // 导入Contact类
|
|
import net.micode.notes.data.Notes; // 导入Notes类
|
|
import net.micode.notes.data.Notes.NoteColumns; // 导入Notes列类
|
|
import net.micode.notes.tool.DataUtils; // 导入数据工具类
|
|
|
|
public class NoteItemData { // 定义笔记项数据类
|
|
static final String [] PROJECTION = new String [] { // 定义要查询的列数组
|
|
NoteColumns.ID, // 笔记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; // 背景颜色ID列索引
|
|
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; // 是否有多个笔记在文件夹下
|
|
|
|
// 构造函数,接收上下文和游标作为参数
|
|
public NoteItemData(Context context, Cursor cursor) {
|
|
mId = cursor.getLong(ID_COLUMN); // 从游标中获取笔记ID
|
|
mAlertDate = cursor.getLong(ALERTED_DATE_COLUMN); // 从游标中获取警报日期
|
|
mBgColorId = cursor.getInt(BG_COLOR_ID_COLUMN); // 从游标中获取背景颜色ID
|
|
mCreatedDate = cursor.getLong(CREATED_DATE_COLUMN); // 从游标中获取创建日期
|
|
mHasAttachment = (cursor.getInt(HAS_ATTACHMENT_COLUMN) > 0) ? true : false; // 根据游标中的信息判断是否有附件
|
|
mModifiedDate = cursor.getLong(MODIFIED_DATE_COLUMN); // 从游标中获取修改日期
|
|
mNotesCount = cursor.getInt(NOTES_COUNT_COLUMN); // 从游标中获取笔记数量
|
|
mParentId = cursor.getLong(PARENT_ID_COLUMN); // 从游标中获取父级ID
|
|
mSnippet = cursor.getString(SNIPPET_COLUMN); // 从游标中获取摘要
|
|
mSnippet = mSnippet.replace(NoteEditActivity.TAG_CHECKED, "").replace( // 清除已勾选标记
|
|
NoteEditActivity.TAG_UNCHECKED, "");
|
|
mType = cursor.getInt(TYPE_COLUMN); // 从游标中获取笔记类型
|
|
mWidgetId = cursor.getInt(WIDGET_ID_COLUMN); // 从游标中获取小部件ID
|
|
mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN); // 从游标中获取小部件类型
|
|
|
|
mPhoneNumber = ""; // 初始化联系电话为空
|
|
if (mParentId == Notes.ID_CALL_RECORD_FOLDER) { // 如果父级ID为通话记录文件夹
|
|
mPhoneNumber = DataUtils.getCallNumberByNoteId(context.getContentResolver(), mId); // 根据笔记ID获取通话记录电话号码
|
|
if (!TextUtils.isEmpty(mPhoneNumber)) { // 如果电话号码不为空
|
|
mName = Contact.getContact(context, mPhoneNumber); // 获取联系人的名称
|
|
if (mName == null) { // 如果没有联系人名称
|
|
mName = mPhoneNumber; // 将名称设置为电话号码
|
|
}
|
|
}
|
|
}
|
|
|
|
if (mName == null) { // 如果名称还是为null
|
|
mName = ""; // 设置为空字符串
|
|
}
|
|
checkPostion(cursor); // 检查位置信息
|
|
}
|
|
|
|
private void checkPostion(Cursor cursor) { // 检查当前项目在游标中的位置信息
|
|
mIsLastItem = cursor.isLast(); // 判断是否为最后一项
|
|
mIsFirstItem = cursor.isFirst(); // 判断是否为第一项
|
|
mIsOnlyOneItem = (cursor.getCount() == 1); // 判断是否为唯一一项
|
|
mIsMultiNotesFollowingFolder = false; // 初始化为false
|
|
mIsOneNoteFollowingFolder = false; // 初始化为false
|
|
|
|
if (mType == Notes.TYPE_NOTE && !mIsFirstItem) { // 如果当前类型为笔记且不是第一项
|
|
int position = cursor.getPosition(); // 获取当前游标位置
|
|
if (cursor.moveToPrevious()) { // 移动游标到上一项
|
|
// 如果上一项是文件夹或系统类型
|
|
if (cursor.getInt(TYPE_COLUMN) == Notes.TYPE_FOLDER
|
|
|| cursor.getInt(TYPE_COLUMN) == Notes.TYPE_SYSTEM) {
|
|
if (cursor.getCount() > (position + 1)) { // 如果游标数量大于当前位置加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; // 返回结果
|
|
}
|
|
|
|
public long getId() { // 获取笔记ID
|
|
return mId; // 返回笔记ID
|
|
}
|
|
|
|
public long getAlertDate() { // 获取警报日期
|
|
return mAlertDate; // 返回警报日期
|
|
}
|
|
|
|
public long getCreatedDate() { // 获取创建日期
|
|
return mCreatedDate; // 返回创建日期
|
|
}
|
|
|
|
public boolean hasAttachment() { // 判断是否有附件
|
|
return mHasAttachment; // 返回结果
|
|
}
|
|
|
|
public long getModifiedDate() { // 获取修改日期
|
|
return mModifiedDate; // 返回修改日期
|
|
}
|
|
|
|
public int getBgColorId() { // 获取背景颜色ID
|
|
return mBgColorId; // 返回背景颜色ID
|
|
}
|
|
|
|
public long getParentId() { // 获取父级ID
|
|
return mParentId; // 返回父级ID
|
|
}
|
|
|
|
public int getNotesCount() { // 获取笔记数量
|
|
return mNotesCount; // 返回笔记数量
|
|
}
|
|
|
|
public long getFolderId () { // 获取文件夹ID
|
|
return mParentId; // 返回父级ID
|
|
}
|
|
|
|
public int getType() { // 获取笔记类型
|
|
return mType; // 返回笔记类型
|
|
}
|
|
|
|
public int getWidgetType() { // 获取小部件类型
|
|
return mWidgetType; // 返回小部件类型
|
|
}
|
|
|
|
public int getWidgetId() { // 获取小部件ID
|
|
return mWidgetId; // 返回小部件ID
|
|
}
|
|
|
|
public String getSnippet() { // 获取摘要
|
|
return mSnippet; // 返回摘要
|
|
}
|
|
|
|
public boolean hasAlert() { // 判断是否有警报
|
|
return (mAlertDate > 0); // 根据警报日期判断
|
|
}
|
|
|
|
public boolean isCallRecord() { // 判断是否为通话记录笔记
|
|
return (mParentId == Notes.ID_CALL_RECORD_FOLDER && !TextUtils.isEmpty(mPhoneNumber)); // 如果父ID为通话记录且电话号码不为空
|
|
}
|
|
|
|
public static int getNoteType(Cursor cursor) { // 根据游标获取笔记类型
|
|
return cursor.getInt(TYPE_COLUMN); // 返回笔记类型
|
|
}
|
|
} |