|  |  | @ -30,17 +30,21 @@ import net.micode.notes.tool.DataUtils; | 
			
		
	
		
		
			
				
					
					|  |  |  | import net.micode.notes.tool.ResourceParser.NoteItemBgResources; |  |  |  | import net.micode.notes.tool.ResourceParser.NoteItemBgResources; | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  | //创建便签列表项目选项
 | 
			
		
	
		
		
			
				
					
					|  |  |  | public class NotesListItem extends LinearLayout { |  |  |  | public class NotesListItem extends LinearLayout { | 
			
		
	
		
		
			
				
					
					|  |  |  |     private ImageView mAlert; |  |  |  |     private ImageView mAlert;       //警报
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     private TextView mTitle; |  |  |  |     private TextView mTitle;        //标题
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     private TextView mTime; |  |  |  |     private TextView mTime;         //时间
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     private TextView mCallName; |  |  |  |     private TextView mCallName;     //呼叫名称
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     private NoteItemData mItemData; |  |  |  |     private NoteItemData mItemData; //数据
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |     private CheckBox mCheckBox; |  |  |  |     private CheckBox mCheckBox;     //✔框
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //初始化
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     public NotesListItem(Context context) { |  |  |  |     public NotesListItem(Context context) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         //调整调用父类构造函数的顺序
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         super(context); |  |  |  |         super(context); | 
			
		
	
		
		
			
				
					
					|  |  |  |         inflate(context, R.layout.note_item, this); |  |  |  |         inflate(context, R.layout.note_item, this); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         //findViewById 查找现有试图
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         mAlert = (ImageView) findViewById(R.id.iv_alert_icon); |  |  |  |         mAlert = (ImageView) findViewById(R.id.iv_alert_icon); | 
			
		
	
		
		
			
				
					
					|  |  |  |         mTitle = (TextView) findViewById(R.id.tv_title); |  |  |  |         mTitle = (TextView) findViewById(R.id.tv_title); | 
			
		
	
		
		
			
				
					
					|  |  |  |         mTime = (TextView) findViewById(R.id.tv_time); |  |  |  |         mTime = (TextView) findViewById(R.id.tv_time); | 
			
		
	
	
		
		
			
				
					|  |  | @ -48,18 +52,23 @@ public class NotesListItem extends LinearLayout { | 
			
		
	
		
		
			
				
					
					|  |  |  |         mCheckBox = (CheckBox) findViewById(android.R.id.checkbox); |  |  |  |         mCheckBox = (CheckBox) findViewById(android.R.id.checkbox); | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //根据data的属性对各个控件的属性的控制,主要是可见性Visibility,内容setText,格式setTextAppearance
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) { |  |  |  |     public void bind(Context context, NoteItemData data, boolean choiceMode, boolean checked) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (choiceMode && data.getType() == Notes.TYPE_NOTE) { |  |  |  |         if (choiceMode && data.getType() == Notes.TYPE_NOTE) { | 
			
		
	
		
		
			
				
					
					|  |  |  |             mCheckBox.setVisibility(View.VISIBLE); |  |  |  |             mCheckBox.setVisibility(View.VISIBLE);  //设置为可见
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |             mCheckBox.setChecked(checked); |  |  |  |             mCheckBox.setChecked(checked);          //打勾
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |  |         } else { |  |  |  |         } else {//否则被隐藏
 | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					
					|  |  |  |             mCheckBox.setVisibility(View.GONE); |  |  |  |             mCheckBox.setVisibility(View.GONE); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         //根据data来设置
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         mItemData = data; |  |  |  |         mItemData = data; | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) { |  |  |  |         if (data.getId() == Notes.ID_CALL_RECORD_FOLDER) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //隐藏呼叫名称视图
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             mCallName.setVisibility(View.GONE); |  |  |  |             mCallName.setVisibility(View.GONE); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //显示报警视图
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             mAlert.setVisibility(View.VISIBLE); |  |  |  |             mAlert.setVisibility(View.VISIBLE); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //设置文本外观
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem); |  |  |  |             mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem); | 
			
		
	
		
		
			
				
					
					|  |  |  |             mTitle.setText(context.getString(R.string.call_record_folder_name) |  |  |  |             mTitle.setText(context.getString(R.string.call_record_folder_name) | 
			
		
	
		
		
			
				
					
					|  |  |  |                     + context.getString(R.string.format_folder_files_count, data.getNotesCount())); |  |  |  |                     + context.getString(R.string.format_folder_files_count, data.getNotesCount())); | 
			
		
	
	
		
		
			
				
					|  |  | @ -70,7 +79,7 @@ public class NotesListItem extends LinearLayout { | 
			
		
	
		
		
			
				
					
					|  |  |  |             mTitle.setTextAppearance(context,R.style.TextAppearanceSecondaryItem); |  |  |  |             mTitle.setTextAppearance(context,R.style.TextAppearanceSecondaryItem); | 
			
		
	
		
		
			
				
					
					|  |  |  |             mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet())); |  |  |  |             mTitle.setText(DataUtils.getFormattedSnippet(data.getSnippet())); | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (data.hasAlert()) { |  |  |  |             if (data.hasAlert()) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 mAlert.setImageResource(R.drawable.clock); |  |  |  |                 mAlert.setImageResource(R.drawable.clock);  | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 mAlert.setVisibility(View.VISIBLE); |  |  |  |                 mAlert.setVisibility(View.VISIBLE); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } else { |  |  |  |             } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 mAlert.setVisibility(View.GONE); |  |  |  |                 mAlert.setVisibility(View.GONE); | 
			
		
	
	
		
		
			
				
					|  |  | @ -94,24 +103,29 @@ public class NotesListItem extends LinearLayout { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 } |  |  |  |                 } | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         //设置内容,获取相关时间,从data里编辑的日期中获取
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate())); |  |  |  |         mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate())); | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         setBackground(data); |  |  |  |         setBackground(data); | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
		
		
			
				
					
					|  |  |  | 
 |  |  |  | 
 | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |     //传入data设置背景
 | 
			
		
	
		
		
			
				
					
					|  |  |  |     private void setBackground(NoteItemData data) { |  |  |  |     private void setBackground(NoteItemData data) { | 
			
		
	
		
		
			
				
					
					|  |  |  |         int id = data.getBgColorId(); |  |  |  |         int id = data.getBgColorId(); | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |         //如果是Notes.TYPE_NOTE
 | 
			
		
	
		
		
			
				
					
					|  |  |  |         if (data.getType() == Notes.TYPE_NOTE) { |  |  |  |         if (data.getType() == Notes.TYPE_NOTE) { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //如果是单个且只有一个文件夹
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             if (data.isSingle() || data.isOneFollowingFolder()) { |  |  |  |             if (data.isSingle() || data.isOneFollowingFolder()) { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 setBackgroundResource(NoteItemBgResources.getNoteBgSingleRes(id)); |  |  |  |                 setBackgroundResource(NoteItemBgResources.getNoteBgSingleRes(id)); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } else if (data.isLast()) { |  |  |  |             } else if (data.isLast()) {  //如果是最后一个数据
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 setBackgroundResource(NoteItemBgResources.getNoteBgLastRes(id)); |  |  |  |                 setBackgroundResource(NoteItemBgResources.getNoteBgLastRes(id)); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } else if (data.isFirst() || data.isMultiFollowingFolder()) { |  |  |  |             } else if (data.isFirst() || data.isMultiFollowingFolder()) { //如果是一个数据且有多个子文件夹
 | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					
					|  |  |  |                 setBackgroundResource(NoteItemBgResources.getNoteBgFirstRes(id)); |  |  |  |                 setBackgroundResource(NoteItemBgResources.getNoteBgFirstRes(id)); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } else { |  |  |  |             } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |                 setBackgroundResource(NoteItemBgResources.getNoteBgNormalRes(id)); |  |  |  |                 setBackgroundResource(NoteItemBgResources.getNoteBgNormalRes(id)); | 
			
		
	
		
		
			
				
					
					|  |  |  |             } |  |  |  |             } | 
			
		
	
		
		
			
				
					
					|  |  |  |         } else { |  |  |  |         } else { | 
			
		
	
		
		
			
				
					
					|  |  |  |  |  |  |  |             //若非note则获取文件夹背景来源
 | 
			
		
	
		
		
			
				
					
					|  |  |  |             setBackgroundResource(NoteItemBgResources.getFolderBgRes()); |  |  |  |             setBackgroundResource(NoteItemBgResources.getFolderBgRes()); | 
			
		
	
		
		
			
				
					
					|  |  |  |         } |  |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |  |     } |  |  |  |     } | 
			
		
	
	
		
		
			
				
					|  |  | 
 |