|
|
/*
|
|
|
* 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;
|
|
|
|
|
|
/**
|
|
|
* 便签列表项视图
|
|
|
* 自定义LinearLayout,用于展示便签列表中的单个项目
|
|
|
* 支持不同类型便签(普通便签、文件夹、通话记录)的差异化显示
|
|
|
* 实现多选模式下的选择框显示与交互
|
|
|
* 根据便签在列表中的位置设置不同背景样式
|
|
|
*/
|
|
|
public class NotesListItem extends LinearLayout {
|
|
|
// 视图组件引用
|
|
|
private ImageView mAlert; // 提醒图标
|
|
|
private TextView mTitle; // 便签标题/内容摘要
|
|
|
private TextView mTime; // 最后修改时间
|
|
|
private TextView mCallName; // 联系人名称(通话记录便签)
|
|
|
private NoteItemData mItemData; // 便签数据模型
|
|
|
private CheckBox mCheckBox; // 多选模式选择框
|
|
|
|
|
|
/**
|
|
|
* 构造函数
|
|
|
* 初始化视图组件并加载布局
|
|
|
* @param context 应用上下文
|
|
|
*/
|
|
|
public NotesListItem(Context context) {
|
|
|
super(context);
|
|
|
// 加载便签列表项布局
|
|
|
inflate(context, R.layout.note_item, this);
|
|
|
// 获取视图组件引用
|
|
|
mAlert = (ImageView) findViewById(R.id.iv_alert_icon);
|
|
|
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);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 绑定数据到视图
|
|
|
* 根据便签类型和状态更新视图显示
|
|
|
* @param context 应用上下文
|
|
|
* @param data 便签数据模型
|
|
|
* @param choiceMode 是否为多选模式
|
|
|
* @param checked 选中状态(多选模式下)
|
|
|
*/
|
|
|
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;
|
|
|
// 处理通话记录文件夹的显示
|
|
|
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {
|
|
|
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);
|
|
|
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);
|
|
|
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);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
// 显示相对时间(如"5分钟前")
|
|
|
mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate()));
|
|
|
|
|
|
// 设置便签项背景
|
|
|
setBackground(data);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 设置便签项背景
|
|
|
* 根据便签类型和在列表中的位置设置不同背景
|
|
|
* @param data 便签数据模型
|
|
|
*/
|
|
|
private void setBackground(NoteItemData data) {
|
|
|
int id = data.getBgColorId();
|
|
|
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());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取便签数据模型
|
|
|
* @return 便签数据模型对象
|
|
|
*/
|
|
|
public NoteItemData getItemData() {
|
|
|
return mItemData;
|
|
|
}
|
|
|
} |