|
|
/*
|
|
|
* 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.text.format.DateUtils;
|
|
|
import android.view.View;
|
|
|
import android.widget.CheckBox;
|
|
|
import android.widget.ImageView;
|
|
|
import android.widget.LinearLayout;
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
import net.micode.notes.R;
|
|
|
import net.micode.notes.data.Notes;
|
|
|
import net.micode.notes.tool.DataUtils;
|
|
|
import net.micode.notes.tool.ResourceParser.NoteItemBgResources;
|
|
|
|
|
|
|
|
|
public class NotesListItem extends LinearLayout {//构建便签列表的各个项目的详细具体信息
|
|
|
private ImageView mAlert;//闹钟图片
|
|
|
private TextView mTitle;//文本标题
|
|
|
private TextView mTime;//时间
|
|
|
private TextView mCallName;//名称
|
|
|
private NoteItemData mItemData;//标签数据
|
|
|
private CheckBox mCheckBox;//勾选框
|
|
|
|
|
|
public NotesListItem(Context context) {//初始化基本信息
|
|
|
super(context);//调整调用父类构造函数的顺序
|
|
|
inflate(context, R.layout.note_item, this);//将xml定义的一个布局找出来
|
|
|
mAlert = (ImageView) findViewById(R.id.iv_alert_icon);//从contentView中查找指定ID的View
|
|
|
mTitle = (TextView) findViewById(R.id.tv_title);//获取题目
|
|
|
mTime = (TextView) findViewById(R.id.tv_time);//获取创建或修改时间
|
|
|
mCallName = (TextView) findViewById(R.id.tv_name);//获取联系人姓名
|
|
|
mCheckBox = (CheckBox) findViewById(android.R.id.checkbox);//获取复选框
|
|
|
}
|
|
|
|
|
|
public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) {//根据data的属性对各个控件的属性的控制
|
|
|
if (choiceMode && data.getType() == Notes.TYPE_NOTE) {//如果当前处于选择模式下且数据类型为便签
|
|
|
mCheckBox.setVisibility(View.VISIBLE);//设置View可见
|
|
|
mCheckBox.setChecked(checked);//设置勾选
|
|
|
} else {
|
|
|
mCheckBox.setVisibility(View.GONE);//设置复选框不可见
|
|
|
}
|
|
|
|
|
|
mItemData = data;//把数据传给标签
|
|
|
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {//设置控件属性,通过判断保存到文件夹的ID、当前ID以及父ID之间关系决定
|
|
|
mCallName.setVisibility(View.GONE);//设置联系人名字不可见
|
|
|
mAlert.setVisibility(View.VISIBLE);//设置闹钟图标可见
|
|
|
mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem);//设置外观风格
|
|
|
mTitle.setText(context.getString(R.string.call_record_folder_name)//设置标题内容为文件夹名字、文件数和便签数
|
|
|
+ context.getString(R.string.format_folder_files_count, data.getNotesCount()));
|
|
|
mAlert.setImageResource(R.drawable.call_record);//设置图片来源
|
|
|
} else if (data.getParentId() == Notes.ID_CALL_RECORD_FOLDER) {//关于闹钟的设置
|
|
|
mCallName.setVisibility(View.VISIBLE);//设置联系人姓名可见
|
|
|
mCallName.setText(data.getCallName());//设置联系人姓名的文本内容
|
|
|
mTitle.setTextAppearance(context,R.style.TextAppearanceSecondaryItem);//设置title文本风格
|
|
|
mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet()));//设置title的文本内容为便签内容的前面片段
|
|
|
if (data.hasAlert()) {//如果时间提醒存在,设置图片来源,将时间提醒图标定为可见
|
|
|
mAlert.setImageResource(R.drawable.clock);//图片来源的设置
|
|
|
mAlert.setVisibility(View.VISIBLE);//将提醒图标设置为可见
|
|
|
} else {//否则将提醒图标设置为不可见
|
|
|
mAlert.setVisibility(View.GONE);
|
|
|
}
|
|
|
} else {//如果父类和当前id均与保存在文件夹中的id不同
|
|
|
mCallName.setVisibility(View.GONE);//设置联系人姓名不可见
|
|
|
mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem);//设置title的文本格式
|
|
|
|
|
|
if (data.getType() == Notes.TYPE_FOLDER) {//设置Type格式
|
|
|
mTitle.setText(data.getSnippet()//设置便签标题内容为便签的前面部分的内容+文件数+便签数
|
|
|
+ context.getString(R.string.format_folder_files_count,
|
|
|
data.getNotesCount()));//设置内容,从data编辑的日期中获取时间
|
|
|
mAlert.setVisibility(View.GONE);//设置时间提醒图标为不可见
|
|
|
} else {//如果不是文件夹类型,设置便签的title为便签内容的前面片段
|
|
|
mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet()));
|
|
|
if (data.hasAlert()) {//若当前便签存在提醒闹钟时间,则显示相应的图片
|
|
|
mAlert.setImageResource(R.drawable.clock);//将提醒图标设置为闹钟样式
|
|
|
mAlert.setVisibility(View.VISIBLE);//设置提醒闹钟可见
|
|
|
} else {//否则设置提醒图标不可见
|
|
|
mAlert.setVisibility(View.GONE);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate()));//将时间设置为编辑便签的时间
|
|
|
|
|
|
setBackground(data);//从data里编辑的日期中获取内容和相关时间
|
|
|
}
|
|
|
|
|
|
private void setBackground(NoteItemData data) {//根据data的文件属性来设置背景
|
|
|
int id = data.getBgColorId();//获取id,用此id用来获取背景颜色
|
|
|
if (data.getType() == Notes.TYPE_NOTE) {//根据data的属性来是否为Note属性,分为4种情况
|
|
|
if (data.isSingle() || data.isOneFollowingFolder()) {//单个数据或只有一个子文件夹
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgSingleRes(id));//设置背景来源为id的单个数据
|
|
|
} else if (data.isLast()) {//若当前便签为最后一个,设置背景来源为id的最后一个数据
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgLastRes(id));
|
|
|
} else if (data.isFirst() || data.isMultiFollowingFolder()) {//若是第一个数据或者有很多个子文件夹, 设置背景来源为id的第一个数据
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgFirstRes(id));
|
|
|
} else {
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgNormalRes(id));//将便签设置为普通类型便签的背景
|
|
|
}
|
|
|
} else {//则将背景设置为文件夹的背景
|
|
|
setBackgroundResource(NoteItemBgResources.getFolderBgRes());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public NoteItemData getItemData() {
|
|
|
return mItemData;
|
|
|
}//返回当前便签的数据信息
|
|
|
}
|