You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
133 lines
6.2 KiB
133 lines
6.2 KiB
/*
|
|
* 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
|
|
*
|
|
* <url id="d0s4nev37oq8u4isp1r0" type="url" status="parsed" title="Apache License, Version 2.0" wc="10467">http://www.apache.org/licenses/LICENSE-2.0</url>
|
|
*
|
|
* 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); // 加载布局文件
|
|
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(); // 获取背景颜色 ID
|
|
// 如果是笔记类型
|
|
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; // 返回笔记项数据
|
|
}
|
|
} |