|
|
|
@ -0,0 +1,127 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
|
|
|
*
|
|
|
|
|
* 根据Apache License, Version 2.0(以下简称“许可证”)授权;
|
|
|
|
|
* 您可能不会使用此文件,除非遵守许可证。
|
|
|
|
|
* 您可以在以下网址获得许可证的副本:
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* 除非适用法律要求或书面同意,否则按照许可证分发的软件
|
|
|
|
|
* 按“原样”分发,不附带任何明示或暗示的保证或条件。
|
|
|
|
|
* 请参阅控制权限和许可证下的限制的具体语言的许可证。
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// NotesListItem 类继承自LinearLayout,用于显示便签列表中的单个项目。
|
|
|
|
|
public class NotesListItem extends LinearLayout {
|
|
|
|
|
private ImageView mAlert; // 用于显示提醒图标的ImageView。
|
|
|
|
|
private TextView mTitle; // 显示便签标题的TextView。
|
|
|
|
|
private TextView mTime; // 显示便签修改时间的TextView。
|
|
|
|
|
private TextView mCallName; // 显示通话记录姓名的TextView。
|
|
|
|
|
private NoteItemData mItemData; // 绑定到此列表项的便签数据。
|
|
|
|
|
private CheckBox mCheckBox; // 用于选择模式的CheckBox。
|
|
|
|
|
|
|
|
|
|
// NotesListItem的构造函数,初始化视图和组件。
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 绑定便签数据到列表项。
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate()));
|
|
|
|
|
|
|
|
|
|
setBackground(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());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取绑定到此列表项的便签数据。
|
|
|
|
|
public NoteItemData getItemData() {
|
|
|
|
|
return mItemData;
|
|
|
|
|
}
|
|
|
|
|
}
|