|
|
/*
|
|
|
* 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 {//便签数据的记录,包括各种常量,参数
|
|
|
static final String [] PROJECTION = new String [] {//将便签id,提醒时间,背景颜色id,创建时间,关联桌面挂件,修改时间,便签数量,父文件夹id,文件夹id(便签的一段内容),便签的种类,桌面挂件的id,桌面挂件的类型的名称放在一个PROJECTION的字符串数组里
|
|
|
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,
|
|
|
NoteColumns.SNIPPET,//文件夹名称或者文本注释内容
|
|
|
NoteColumns.TYPE,//note的种类
|
|
|
NoteColumns.WIDGET_ID,//挂件id
|
|
|
NoteColumns.WIDGET_TYPE,//挂件的类型
|
|
|
};
|
|
|
|
|
|
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 long mId;//PROJECT的字符串名称对应的值
|
|
|
private long mAlertDate;
|
|
|
private int mBgColorId;
|
|
|
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;//宽度
|
|
|
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) {//初始化NoteItemData,利用光标和context获取的内容
|
|
|
mId = cursor.getLong(ID_COLUMN);//获取指定数据,并以type类型传回
|
|
|
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;//判断行列
|
|
|
mModifiedDate = cursor.getLong(MODIFIED_DATE_COLUMN);
|
|
|
mNotesCount = cursor.getInt(NOTES_COUNT_COLUMN);
|
|
|
mParentId = cursor.getLong(PARENT_ID_COLUMN);
|
|
|
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);
|
|
|
mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN);
|
|
|
|
|
|
mPhoneNumber = "";//初始化电话号码的信息
|
|
|
if (mParentId == Notes.ID_CALL_RECORD_FOLDER) {//如果父文件的id是call_record_folder
|
|
|
mPhoneNumber = DataUtils.getCallNumberByNoteId(context.getContentResolver(), mId);//使用DataUtils类中定义的函数获取电话号码信息
|
|
|
if (!TextUtils.isEmpty(mPhoneNumber)) {//若mphonenumber里有符合字符串,则用contart功能连接
|
|
|
mName = Contact.getContact(context, mPhoneNumber);//通过phonenumber,调用getContact,利用键值对获取对应的name
|
|
|
if (mName == null) {
|
|
|
mName = mPhoneNumber;//若未保存名字,以号码命名
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (mName == null) {
|
|
|
mName = "";
|
|
|
}//若没有对name复制成功,则把name设置为空值
|
|
|
checkPostion(cursor);//检查光标位置
|
|
|
}
|
|
|
|
|
|
private void checkPostion(Cursor cursor) {//根据光标位置设置标记
|
|
|
mIsLastItem = cursor.isLast() ? true : false;//分别为各种描述状态的变量进行赋值
|
|
|
mIsFirstItem = cursor.isFirst() ? true : false;
|
|
|
mIsOnlyOneItem = (cursor.getCount() == 1);
|
|
|
mIsMultiNotesFollowingFolder = false;
|
|
|
mIsOneNoteFollowingFolder = false;//初始化“多重子文件”“单一子文件”2个标记
|
|
|
|
|
|
if (mType == Notes.TYPE_NOTE && !mIsFirstItem) {//如果对象的类型为便签且不为第一个项
|
|
|
int position = cursor.getPosition();//获得光标位置
|
|
|
if (cursor.moveToPrevious()) {//如果光标移动
|
|
|
if (cursor.getInt(TYPE_COLUMN) == Notes.TYPE_FOLDER//若光标满足SYSTEM或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;
|
|
|
}//若数据父id为保存至文件夹模式的id且满足电话号码单元不为空,则isCallRecord为true
|
|
|
|
|
|
public boolean isLast() {
|
|
|
return mIsLastItem;
|
|
|
}//判断是否为最后一个项
|
|
|
|
|
|
public String getCallName() {
|
|
|
return mName;
|
|
|
}//获得便签的姓名
|
|
|
|
|
|
public boolean isFirst() {
|
|
|
return mIsFirstItem;
|
|
|
}//判断是否是第一个项
|
|
|
|
|
|
public boolean isSingle() {
|
|
|
return mIsOnlyOneItem;
|
|
|
}//判断是否只有一个项
|
|
|
|
|
|
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;
|
|
|
}//获得修改后时间
|
|
|
|
|
|
public int getBgColorId() {
|
|
|
return mBgColorId;
|
|
|
}//获取背景颜色
|
|
|
|
|
|
public long getParentId() {
|
|
|
return mParentId;
|
|
|
}//获取父进程id
|
|
|
|
|
|
public int getNotesCount() {
|
|
|
return mNotesCount;
|
|
|
}//获取便签数量
|
|
|
|
|
|
public long getFolderId () {
|
|
|
return mParentId;
|
|
|
}//获取文件夹id
|
|
|
|
|
|
public int getType() {
|
|
|
return mType;
|
|
|
}//获得项的类型
|
|
|
|
|
|
public int getWidgetType() {
|
|
|
return mWidgetType;
|
|
|
}//获取挂件类型
|
|
|
|
|
|
public int getWidgetId() {
|
|
|
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);
|
|
|
}//获取便签类型
|
|
|
}
|