|
|
/*
|
|
|
* 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;//第19到30行导入各种类
|
|
|
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);//super()它的主要作用是调整调用父类构造函数的顺序
|
|
|
inflate(context, R.layout.note_item, this);//Inflate()作用就是将xml定义的一个布局找出来
|
|
|
mAlert = (ImageView) findViewById(R.id.iv_alert_icon);//findViewById用于从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的属性对各个控件的属性的控制,主要是可见性Visibility,内容setText,格式setTextAppearance
|
|
|
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()));//设置title的内容(文件夹名字+数量)
|
|
|
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 {
|
|
|
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()));//设置便签标题内容为便签的前面部分的内容+文件数+便签数
|
|
|
mAlert.setVisibility(View.GONE);//设置图标不可见
|
|
|
} else {
|
|
|
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);//设置背景
|
|
|
}
|
|
|
|
|
|
private void setBackground(NoteItemData data) {//通过data设置背景
|
|
|
int id = data.getBgColorId();//获取id,用此id用来获取背景颜色
|
|
|
if (data.getType() == Notes.TYPE_NOTE) {//若是note型文件,则4种情况,对于4种不同情况的背景来源
|
|
|
if (data.isSingle() || data.isOneFollowingFolder()) {//单个数据或只有一个子文件夹
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgSingleRes(id));
|
|
|
} else if (data.isLast()) {//最后一个数据
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgLastRes(id));
|
|
|
} else if (data.isFirst() || data.isMultiFollowingFolder()) {//设置背景来源为id的最后一个数据
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgFirstRes(id));//.若不是Note类型则使用文件夹背景来源
|
|
|
} else {
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgNormalRes(id));//设置背景来源为id的普通数据
|
|
|
}
|
|
|
} else {//如果不是便签类型的数据
|
|
|
setBackgroundResource(NoteItemBgResources.getFolderBgRes());//设置背景来源为文件夹
|
|
|
}
|
|
|
}
|
|
|
|
|
|
public NoteItemData getItemData() {
|
|
|
return mItemData;
|
|
|
}//返回当前便签的数据信息
|
|
|
}
|