|
|
|
|
/*
|
|
|
|
|
* 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;
|
|
|
|
|
|
|
|
|
|
// 引入Android库和自定义类、工具类
|
|
|
|
|
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; // 引用资源ID文件
|
|
|
|
|
import net.micode.notes.data.Notes; // Notes类,表示笔记数据
|
|
|
|
|
import net.micode.notes.tool.DataUtils; // 数据工具类,可能用于处理或转换数据
|
|
|
|
|
import net.micode.notes.tool.ResourceParser.NoteItemBgResources; // 资源解析器,用于获取笔记项背景资源
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class NotesListItem extends LinearLayout {
|
|
|
|
|
// 定义UI控件
|
|
|
|
|
private ImageView mAlert; // 用于显示警告图标
|
|
|
|
|
private TextView mTitle; // 用于显示标题
|
|
|
|
|
private TextView mTime; // 用于显示时间
|
|
|
|
|
private TextView mCallName; // 用于显示来电名称
|
|
|
|
|
private NoteItemData mItemData; // 用于存储与该视图项相关的数据
|
|
|
|
|
private CheckBox mCheckBox; // 用于显示复选框,支持选择模式
|
|
|
|
|
|
|
|
|
|
// 构造函数,初始化视图
|
|
|
|
|
public NotesListItem(Context context) {
|
|
|
|
|
super(context); // 调用父类LinearLayout的构造函数
|
|
|
|
|
inflate(context, R.layout.note_item, this); // 从布局文件加载视图
|
|
|
|
|
mAlert = (ImageView) findViewById(R.id.iv_alert_icon); // 绑定警告图标
|
|
|
|
|
mTitle = (TextView) findViewById(R.id.tv_title); // 绑定标题TextView
|
|
|
|
|
mTime = (TextView) findViewById(R.id.tv_time); // 绑定时间TextView
|
|
|
|
|
mCallName = (TextView) findViewById(R.id.tv_name); // 绑定来电名称TextView
|
|
|
|
|
mCheckBox = (CheckBox) findViewById(android.R.id.checkbox); // 绑定复选框
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 绑定数据到视图
|
|
|
|
|
public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) {
|
|
|
|
|
// 如果处于选择模式且数据类型为笔记,则显示复选框并设置其选中状态
|
|
|
|
|
if (choiceMode && data.getType() == Notes.TYPE_NOTE) {
|
|
|
|
|
mCheckBox.setVisibility(View.VISIBLE); // 显示复选框
|
|
|
|
|
mCheckBox.setChecked(checked); // 设置复选框的选中状态
|
|
|
|
|
} else {
|
|
|
|
|
mCheckBox.setVisibility(View.GONE); // 否则隐藏复选框
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mItemData = data; // 存储绑定的数据
|
|
|
|
|
// 如果数据ID为通话记录文件夹ID
|
|
|
|
|
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
|
|
|
|
|
mCallName.setVisibility(View.GONE); // 隐藏来电名称TextView
|
|
|
|
|
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); // 设置警告图标为通话记录图标
|
|
|
|
|
}
|
|
|
|
|
// 如果数据的父ID是通话记录文件夹ID
|
|
|
|
|
else if (data.getParentId() == Notes.ID_CALL_RECORD_FOLDER) {
|
|
|
|
|
mCallName.setVisibility(View.VISIBLE); // 显示来电名称TextView
|
|
|
|
|
mCallName.setText(data.getCallName()); // 设置来电名称
|
|
|
|
|
mTitle.setTextAppearance(context, R.style.TextAppearanceSecondaryItem); // 设置标题样式
|
|
|
|
|
mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet())); // 设置标题文本
|
|
|
|
|
if (data.hasAlert()) { // 如果有提醒
|
|
|
|
|
mAlert.setImageResource(R.drawable.clock); // 设置警告图标为时钟图标
|
|
|
|
|
mAlert.setVisibility(View.VISIBLE); // 显示警告图标
|
|
|
|
|
} else {
|
|
|
|
|
mAlert.setVisibility(View.GONE); // 否则隐藏警告图标
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 处理其他普通笔记或文件夹项
|
|
|
|
|
else {
|
|
|
|
|
mCallName.setVisibility(View.GONE); // 隐藏来电名称TextView
|
|
|
|
|
mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem); // 设置标题样式
|
|
|
|
|
|
|
|
|
|
// 如果是文件夹类型的笔记
|
|
|
|
|
if (data.getType() == Notes.TYPE_FOLDER) {
|
|
|
|
|
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) {
|
|
|
|
|
// 获取背景颜色的ID,根据 NoteItemData 对象的不同状态来设置不同的背景资源
|
|
|
|
|
int id = data.getBgColorId();
|
|
|
|
|
|
|
|
|
|
// 判断数据类型,如果是普通笔记(TYPE_NOTE)
|
|
|
|
|
if (data.getType() == Notes.TYPE_NOTE) {
|
|
|
|
|
// 如果该笔记是单一的,或者是跟随文件夹的第一个笔记
|
|
|
|
|
if (data.isSingle() || data.isOneFollowingFolder()) {
|
|
|
|
|
// 设置背景为 "单个笔记" 的背景资源
|
|
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgSingleRes(id));
|
|
|
|
|
}
|
|
|
|
|
// 如果该笔记是最后一个笔记
|
|
|
|
|
else if (data.isLast()) {
|
|
|
|
|
// 设置背景为 "最后一个笔记" 的背景资源
|
|
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgLastRes(id));
|
|
|
|
|
}
|
|
|
|
|
// 如果该笔记是第一个,或者是多重跟随文件夹中的笔记
|
|
|
|
|
else if (data.isFirst() || data.isMultiFollowingFolder()) {
|
|
|
|
|
// 设置背景为 "第一个笔记" 的背景资源
|
|
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgFirstRes(id));
|
|
|
|
|
}
|
|
|
|
|
// 否则,设置普通笔记的背景
|
|
|
|
|
else {
|
|
|
|
|
setBackgroundResource(NoteItemBgResources.getNoteBgNormalRes(id));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 如果不是普通笔记(即为文件夹类型)
|
|
|
|
|
else {
|
|
|
|
|
// 设置为文件夹的背景资源
|
|
|
|
|
setBackgroundResource(NoteItemBgResources.getFolderBgRes());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public NoteItemData getItemData() {
|
|
|
|
|
return mItemData;
|
|
|
|
|
}
|
|
|
|
|
}
|