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.
117 lines
4.8 KiB
117 lines
4.8 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
|
|
*
|
|
* 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;
|
|
|
|
private ImageView mAlert; // 用于显示提醒图标的 ImageView
|
|
private TextView mTitle; // 显示笔记标题的 TextView
|
|
private TextView mTime; // 显示笔记修改时间的 TextView
|
|
private TextView mCallName; // 显示通话记录名称的 TextView
|
|
private NoteItemData mItemData; // 当前条目关联的数据对象
|
|
private CheckBox mCheckBox; // 如果处于选择模式,用于选择当前条目的 CheckBox
|
|
|
|
|
|
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();
|
|
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;
|
|
}
|
|
}
|