|
|
/*
|
|
|
* 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 [] {//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,//父id
|
|
|
NoteColumns.SNIPPET,//文件夹名称或者文本注释内容
|
|
|
NoteColumns.TYPE,//某一列note的种类,是text note还是folder
|
|
|
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,主要利用光标cursor获取的东西
|
|
|
mId = cursor.getLong(ID_COLUMN);//从cursor中获取数据
|
|
|
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确定电话号码
|
|
|
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;//如果匹配失败,就把phonenumber设置为name
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (mName == null) {//如果没有对name复制成功,则把name设置为空值
|
|
|
mName = "";
|
|
|
}
|
|
|
checkPostion(cursor);//检查光标位置
|
|
|
}
|
|
|
|
|
|
private void checkPostion(Cursor cursor) {//通过光标所处位置设置标记
|
|
|
mIsLastItem = cursor.isLast() ? true : false;//分别为各种描述状态的变量进行赋值
|
|
|
mIsFirstItem = cursor.isFirst() ? true : false;
|
|
|
mIsOnlyOneItem = (cursor.getCount() == 1);
|
|
|
mIsMultiNotesFollowingFolder = false;//初始化“多重子文件”“单一子文件”2个标记
|
|
|
mIsOneNoteFollowingFolder = false;
|
|
|
|
|
|
if (mType == Notes.TYPE_NOTE && !mIsFirstItem) {//是NOTE格式且不是第一个item
|
|
|
int position = cursor.getPosition();//光标指向的位置
|
|
|
if (cursor.moveToPrevious()) {//获取光标位置并看向上一行
|
|
|
if (cursor.getInt(TYPE_COLUMN) == Notes.TYPE_FOLDER//若光标满足SYSTEM或FOLDER格式
|
|
|
|| cursor.getInt(TYPE_COLUMN) == Notes.TYPE_SYSTEM) {//数据行数大于当前位置+1则设置是多重子文件
|
|
|
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;
|
|
|
}//若父id为保存至文件夹模式的id且电话号码不空,则返回真
|
|
|
|
|
|
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() {//判断便签项是否为CallRecord
|
|
|
return (mParentId == Notes.ID_CALL_RECORD_FOLDER && !TextUtils.isEmpty(mPhoneNumber));// 如果父类id保存至文件夹模式并且电话号码单元不为空
|
|
|
}
|
|
|
|
|
|
public static int getNoteType(Cursor cursor) {
|
|
|
return cursor.getInt(TYPE_COLUMN);
|
|
|
}//获得便签的类型
|
|
|
}
|