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.
TeamProject/doc/精读代码(注释)/闵心诚注释/ui/NotesListItem.java

123 lines
7.2 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/*
* 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;//第19到30行导入各种类
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);//super()它的主要作用是调整调用父类构造函数的顺序
inflate(context, R.layout.note_item, this);//Inflate()作用就是将xml定义的一个布局找出来
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) {//根据data的属性对各个控件的属性的控制主要是可见性Visibility内容setText格式setTextAppearance
if (choiceMode && data.getType() == Notes.TYPE_NOTE) {//语句:如果当前处于选择模式下且数据类型为便签
mCheckBox.setVisibility(View.VISIBLE);//设置View可见
mCheckBox.setChecked(checked);//设置勾选
} else {
mCheckBox.setVisibility(View.GONE);
}
mItemData = data;//把数据传给标签
if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) {//设置控件属性通过判断保存到文件夹的ID、当前ID以及父ID之间关系决定
mCallName.setVisibility(View.GONE);//设置setText 的style
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);//语句设置title文本风格
mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet()));//语句设置title的文本内容为便签内容的前面片段
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);//语句设置title的文本格式
if (data.getType() == Notes.TYPE_FOLDER) {//设置Type格式
mTitle.setText(data.getSnippet()//设置便签标题内容为便签的前面部分的内容+文件数+便签数
+ context.getString(R.string.format_folder_files_count,//语句设置文件夹的title为“名字+count
data.getNotesCount()));//设置时间从data编辑的日期获取
mAlert.setVisibility(View.GONE);//语句:设置图标不可见
} else {//如果不是文件夹类型
mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet()));//语句:设置便签的title为便签内容的前面片段
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) {//通过data设置背景
int id = data.getBgColorId();//语句获取id用此id用来获取背景颜色
if (data.getType() == Notes.TYPE_NOTE) {//四种不同背景来源
if (data.isSingle() || data.isOneFollowingFolder()) {//单个数据或只有一个子文件夹
setBackgroundResource(NoteItemBgResources.getNoteBgSingleRes(id));//设置背景来源为id的单个数据
} else if (data.isLast()) {//最后一个数据
setBackgroundResource(NoteItemBgResources.getNoteBgLastRes(id));//设置背景来源为id的最后一个数据
} else if (data.isFirst() || data.isMultiFollowingFolder()) {//第一个数据或多个子文件夹
setBackgroundResource(NoteItemBgResources.getNoteBgFirstRes(id));
} else {
setBackgroundResource(NoteItemBgResources.getNoteBgNormalRes(id));//设置背景来源为id的普通数据
}
} else {
setBackgroundResource(NoteItemBgResources.getFolderBgRes());//设置背景来源为文件夹
}
}
public NoteItemData getItemData() {
return mItemData;
}//返回当前便签的数据信息
}