|
|
|
@ -1,17 +1,15 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
|
|
|
* 版权所有 (c) 2010-2011, MiCode 开源社区 (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
|
|
|
|
|
* 本文件授权使用 Apache License, Version 2.0(以下简称“许可证”);
|
|
|
|
|
* 除非符合许可证规定,否则不得使用此文件。
|
|
|
|
|
* 您可以从以下网址获取许可证副本:
|
|
|
|
|
*
|
|
|
|
|
* 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;
|
|
|
|
@ -25,9 +23,12 @@ import net.micode.notes.data.Notes;
|
|
|
|
|
import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
|
import net.micode.notes.tool.DataUtils;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* NoteItemData 类用于封装便签项的数据。
|
|
|
|
|
* 它从数据库游标中提取便签的相关信息,并提供访问这些信息的方法。
|
|
|
|
|
*/
|
|
|
|
|
public class NoteItemData {
|
|
|
|
|
static final String [] PROJECTION = new String [] {
|
|
|
|
|
static final String[] PROJECTION = new String[] {
|
|
|
|
|
NoteColumns.ID,
|
|
|
|
|
NoteColumns.ALERTED_DATE,
|
|
|
|
|
NoteColumns.BG_COLOR_ID,
|
|
|
|
@ -43,23 +44,20 @@ public class NoteItemData {
|
|
|
|
|
NoteColumns.TOP,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
private static final int ID_COLUMN = 0;
|
|
|
|
|
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;
|
|
|
|
|
private static final int SNIPPET_COLUMN = 8;
|
|
|
|
|
private static final int TYPE_COLUMN = 9;
|
|
|
|
|
private static final int WIDGET_ID_COLUMN = 10;
|
|
|
|
|
private static final int WIDGET_TYPE_COLUMN = 11;
|
|
|
|
|
private static final int TOP_STATE_COLUMN = 12;
|
|
|
|
|
|
|
|
|
|
/** 以下这些数据,对照着NotesDatabaseHelper.java看
|
|
|
|
|
* 都是数据行里设置好的属性
|
|
|
|
|
* @zhoukexing 2023/12/25 20:22 */
|
|
|
|
|
private static final int ID_COLUMN = 0;
|
|
|
|
|
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;
|
|
|
|
|
private static final int SNIPPET_COLUMN = 8;
|
|
|
|
|
private static final int TYPE_COLUMN = 9;
|
|
|
|
|
private static final int WIDGET_ID_COLUMN = 10;
|
|
|
|
|
private static final int WIDGET_TYPE_COLUMN = 11;
|
|
|
|
|
private static final int TOP_STATE_COLUMN = 12;
|
|
|
|
|
|
|
|
|
|
private long mId;
|
|
|
|
|
private long mAlertDate;
|
|
|
|
|
private int mBgColorId;
|
|
|
|
@ -83,19 +81,16 @@ public class NoteItemData {
|
|
|
|
|
private boolean mIsMultiNotesFollowingFolder;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @method: NoteItemData
|
|
|
|
|
* @description: 描述一下方法的作用
|
|
|
|
|
* @date: 2023/12/25 19:58
|
|
|
|
|
* @author: zhoukexing
|
|
|
|
|
* @param: [context, cursor]
|
|
|
|
|
* @return:
|
|
|
|
|
* 构造函数,从游标中初始化便签项数据。
|
|
|
|
|
* @param context 应用上下文。
|
|
|
|
|
* @param cursor 数据库游标。
|
|
|
|
|
*/
|
|
|
|
|
public NoteItemData(Context context, Cursor cursor) { // 把cursor理解为这样一个指针,指向一个表格 @zhoukexing 2023/12/25 20:12
|
|
|
|
|
mId = cursor.getLong(ID_COLUMN); // 可以根据传入的列号获取到表格里对应列的值 @zhoukexing 2023/12/25 20:12
|
|
|
|
|
public NoteItemData(Context context, Cursor cursor) {
|
|
|
|
|
mId = cursor.getLong(ID_COLUMN);
|
|
|
|
|
mAlertDate = cursor.getLong(ALERTED_DATE_COLUMN);
|
|
|
|
|
mBgColorId = cursor.getInt(BG_COLOR_ID_COLUMN);
|
|
|
|
|
mCreatedDate = cursor.getLong(CREATED_DATE_COLUMN);
|
|
|
|
|
mHasAttachment = (cursor.getInt(HAS_ATTACHMENT_COLUMN) > 0) ? true : false;
|
|
|
|
|
mHasAttachment = (cursor.getInt(HAS_ATTACHMENT_COLUMN) > 0);
|
|
|
|
|
mModifiedDate = cursor.getLong(MODIFIED_DATE_COLUMN);
|
|
|
|
|
mNotesCount = cursor.getInt(NOTES_COUNT_COLUMN);
|
|
|
|
|
mParentId = cursor.getLong(PARENT_ID_COLUMN);
|
|
|
|
@ -108,9 +103,8 @@ public class NoteItemData {
|
|
|
|
|
mTop = cursor.getInt(TOP_STATE_COLUMN);
|
|
|
|
|
|
|
|
|
|
mPhoneNumber = "";
|
|
|
|
|
if (mParentId == Notes.ID_CALL_RECORD_FOLDER) { //Q: 文件夹为什么有电话记录之说?怎么是通过一个便签的父文件夹来判断便签内有无电话号码?@zkx 2023/12/25
|
|
|
|
|
if (mParentId == Notes.ID_CALL_RECORD_FOLDER) {
|
|
|
|
|
mPhoneNumber = DataUtils.getCallNumberByNoteId(context.getContentResolver(), mId);
|
|
|
|
|
// 根据电话号码锁定联系人名称,若不在联系人里,直接使用电话号码 @zhoukexing 2023/12/25 20:17
|
|
|
|
|
if (!TextUtils.isEmpty(mPhoneNumber)) {
|
|
|
|
|
mName = Contact.getContact(context, mPhoneNumber);
|
|
|
|
|
if (mName == null) {
|
|
|
|
@ -122,12 +116,16 @@ public class NoteItemData {
|
|
|
|
|
if (mName == null) {
|
|
|
|
|
mName = "";
|
|
|
|
|
}
|
|
|
|
|
checkPostion(cursor);
|
|
|
|
|
checkPosition(cursor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void checkPostion(Cursor cursor) {
|
|
|
|
|
mIsLastItem = cursor.isLast() ? true : false;
|
|
|
|
|
mIsFirstItem = cursor.isFirst() ? true : false;
|
|
|
|
|
/**
|
|
|
|
|
* 检查便签项在列表中的位置。
|
|
|
|
|
* @param cursor 数据库游标。
|
|
|
|
|
*/
|
|
|
|
|
private void checkPosition(Cursor cursor) {
|
|
|
|
|
mIsLastItem = cursor.isLast();
|
|
|
|
|
mIsFirstItem = cursor.isFirst();
|
|
|
|
|
mIsOnlyOneItem = (cursor.getCount() == 1);
|
|
|
|
|
mIsMultiNotesFollowingFolder = false;
|
|
|
|
|
mIsOneNoteFollowingFolder = false;
|
|
|
|
@ -144,101 +142,148 @@ public class NoteItemData {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (!cursor.moveToNext()) {
|
|
|
|
|
throw new IllegalStateException("cursor move to previous but can't move back");
|
|
|
|
|
throw new IllegalStateException("Cursor moved to previous but can't move back");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检查是否为单个便签跟随文件夹。
|
|
|
|
|
* @return true 表示是单个便签跟随文件夹,false 表示不是。
|
|
|
|
|
*/
|
|
|
|
|
public boolean isOneFollowingFolder() {
|
|
|
|
|
return mIsOneNoteFollowingFolder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检查是否为多个便签跟随文件夹。
|
|
|
|
|
* @return true 表示是多个便签跟随文件夹,false 表示不是。
|
|
|
|
|
*/
|
|
|
|
|
public boolean isMultiFollowingFolder() {
|
|
|
|
|
return mIsMultiNotesFollowingFolder;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检查是否为最后一个便签项。
|
|
|
|
|
* @return true 表示是最后一个便签项,false 表示不是。
|
|
|
|
|
*/
|
|
|
|
|
public boolean isLast() {
|
|
|
|
|
return mIsLastItem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取电话联系人名称。
|
|
|
|
|
* @return 电话联系人名称。
|
|
|
|
|
*/
|
|
|
|
|
public String getCallName() {
|
|
|
|
|
return mName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检查是否为第一个便签项。
|
|
|
|
|
* @return true 表示是第一个便签项,false 表示不是。
|
|
|
|
|
*/
|
|
|
|
|
public boolean isFirst() {
|
|
|
|
|
return mIsFirstItem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检查是否为唯一的便签项。
|
|
|
|
|
* @return true 表示是唯一的便签项,false 表示不是。
|
|
|
|
|
*/
|
|
|
|
|
public boolean isSingle() {
|
|
|
|
|
return mIsOnlyOneItem;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getTop(){
|
|
|
|
|
/**
|
|
|
|
|
* 获取便签的置顶状态。
|
|
|
|
|
* @return 便签的置顶状态。
|
|
|
|
|
*/
|
|
|
|
|
public int getTop() {
|
|
|
|
|
return mTop;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取便签的 ID。
|
|
|
|
|
* @return 便签的 ID。
|
|
|
|
|
*/
|
|
|
|
|
public long getId() {
|
|
|
|
|
return mId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取便签的提醒日期。
|
|
|
|
|
* @return 便签的提醒日期。
|
|
|
|
|
*/
|
|
|
|
|
public long getAlertDate() {
|
|
|
|
|
return mAlertDate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取便签的创建日期。
|
|
|
|
|
* @return 便签的创建日期。
|
|
|
|
|
*/
|
|
|
|
|
public long getCreatedDate() {
|
|
|
|
|
return mCreatedDate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 检查便签是否包含附件。
|
|
|
|
|
* @return true 表示包含附件,false 表示不包含。
|
|
|
|
|
*/
|
|
|
|
|
public boolean hasAttachment() {
|
|
|
|
|
return mHasAttachment;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取便签的修改日期。
|
|
|
|
|
* @return 便签的修改日期。
|
|
|
|
|
*/
|
|
|
|
|
public long getModifiedDate() {
|
|
|
|
|
return mModifiedDate;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取便签的背景颜色 ID。
|
|
|
|
|
* @return 便签的背景颜色 ID。
|
|
|
|
|
*/
|
|
|
|
|
public int getBgColorId() {
|
|
|
|
|
return mBgColorId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取便签的父文件夹 ID。
|
|
|
|
|
* @return 便签的父文件夹 ID。
|
|
|
|
|
*/
|
|
|
|
|
public long getParentId() {
|
|
|
|
|
return mParentId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取便签的数量。
|
|
|
|
|
* @return 便签的数量。
|
|
|
|
|
*/
|
|
|
|
|
public int getNotesCount() {
|
|
|
|
|
return mNotesCount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public long getFolderId () {
|
|
|
|
|
/**
|
|
|
|
|
* 获取便签的文件夹 ID。
|
|
|
|
|
* @return 便签的文件夹 ID。
|
|
|
|
|
*/
|
|
|
|
|
public long getFolderId() {
|
|
|
|
|
return mParentId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取便签的类型。
|
|
|
|
|
* @return 便签的类型。
|
|
|
|
|
*/
|
|
|
|
|
public int getType() {
|
|
|
|
|
return mType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getWidgetType() {
|
|
|
|
|
return mWidgetType;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public int getWidgetId() {
|
|
|
|
|
return mWidgetId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public String getSnippet() {
|
|
|
|
|
return mSnippet;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean hasAlert() {
|
|
|
|
|
return (mAlertDate > 0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public boolean isCallRecord() {
|
|
|
|
|
return (mParentId == Notes.ID_CALL_RECORD_FOLDER && !TextUtils.isEmpty(mPhoneNumber));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static int getNoteType(Cursor cursor) {
|
|
|
|
|
return cursor.getInt(TYPE_COLUMN);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/**
|
|
|
|
|
* 获取便签的小部件类型。
|
|
|
|
|
* @return 便签
|