2201_75665698 8 months ago
commit 416116628f

@ -1,140 +1,175 @@
/* /*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
* * The MiCode Open Source Community2010-2011
*/
/*
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* Apache License 2.0
*/
/*
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* 使
*/
/*
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 */
* /*
* http://www.apache.org/licenses/LICENSE-2.0
* Apache License 2.0
*/
/*
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
*
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
*
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
/*
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
*
*/
/*
* limitations under the License. * limitations under the License.
*
*/ */
package net.micode.notes.ui; package net.micode.notes.ui;
// 指定包名为net.micode.notes.ui。
import android.content.Context; import android.content.Context;
// 导入Context类用于访问应用程序的环境信息。
import android.database.Cursor; import android.database.Cursor;
// 导入Cursor类用于遍历数据库查询结果。
import android.text.TextUtils; import android.text.TextUtils;
// 导入TextUtils类用于操作文本工具。
import net.micode.notes.data.Contact; import net.micode.notes.data.Contact;
// 导入Contact类用于处理联系人数据。
import net.micode.notes.data.Notes; import net.micode.notes.data.Notes;
// 导入Notes类用于处理便签数据。
import net.micode.notes.data.Notes.NoteColumns; import net.micode.notes.data.Notes.NoteColumns;
// 导入NoteColumns类用于访问便签数据的列。
import net.micode.notes.tool.DataUtils; import net.micode.notes.tool.DataUtils;
// 导入DataUtils类用于数据处理工具。
// NoteItemData类用于封装便签项的数据 // NoteItemData类用于封装便签项的数据
public class NoteItemData { public class NoteItemData {
// 数据库查询的列 // 数据库查询的列
static final String [] PROJECTION = new String [] { static final String [] PROJECTION = new String [] {
NoteColumns.ID, NoteColumns.ID, // 便签ID
NoteColumns.ALERTED_DATE, NoteColumns.ALERTED_DATE, // 便签提醒日期
NoteColumns.BG_COLOR_ID, NoteColumns.BG_COLOR_ID, // 便签背景色ID
NoteColumns.CREATED_DATE, NoteColumns.CREATED_DATE, // 便签创建日期
NoteColumns.HAS_ATTACHMENT, NoteColumns.HAS_ATTACHMENT, // 便签是否有附件
NoteColumns.MODIFIED_DATE, NoteColumns.MODIFIED_DATE, // 便签修改日期
NoteColumns.NOTES_COUNT, NoteColumns.NOTES_COUNT, // 便签数量
NoteColumns.PARENT_ID, NoteColumns.PARENT_ID, // 便签的父ID
NoteColumns.SNIPPET, NoteColumns.SNIPPET, // 便签摘要
NoteColumns.TYPE, NoteColumns.TYPE, // 便签类型
NoteColumns.WIDGET_ID, NoteColumns.WIDGET_ID, // 便签小部件ID
NoteColumns.WIDGET_TYPE, NoteColumns.WIDGET_TYPE, // 便签小部件类型
}; };
// 列索引 // 列索引
private static final int ID_COLUMN = 0; private static final int ID_COLUMN = 0; // ID列索引
private static final int ALERTED_DATE_COLUMN = 1; private static final int ALERTED_DATE_COLUMN = 1; // ALERTED_DATE列索引
private static final int BG_COLOR_ID_COLUMN = 2; private static final int BG_COLOR_ID_COLUMN = 2; // BG_COLOR_ID列索引
private static final int CREATED_DATE_COLUMN = 3; private static final int CREATED_DATE_COLUMN = 3; // CREATED_DATE列索引
private static final int HAS_ATTACHMENT_COLUMN = 4; private static final int HAS_ATTACHMENT_COLUMN = 4; // HAS_ATTACHMENT列索引
private static final int MODIFIED_DATE_COLUMN = 5; private static final int MODIFIED_DATE_COLUMN = 5; // MODIFIED_DATE列索引
private static final int NOTES_COUNT_COLUMN = 6; private static final int NOTES_COUNT_COLUMN = 6; // NOTES_COUNT列索引
private static final int PARENT_ID_COLUMN = 7; private static final int PARENT_ID_COLUMN = 7; // PARENT_ID列索引
private static final int SNIPPET_COLUMN = 8; private static final int SNIPPET_COLUMN = 8; // SNIPPET列索引
private static final int TYPE_COLUMN = 9; private static final int TYPE_COLUMN = 9; // TYPE列索引
private static final int WIDGET_ID_COLUMN = 10; private static final int WIDGET_ID_COLUMN = 10; // WIDGET_ID列索引
private static final int WIDGET_TYPE_COLUMN = 11; private static final int WIDGET_TYPE_COLUMN = 11; // WIDGET_TYPE列索引
// 成员变量,存储便签项的数据 // 成员变量,存储便签项的数据
private long mId; private long mId; // 便签ID
private long mAlertDate; private long mAlertDate; // 便签提醒日期
private int mBgColorId; private int mBgColorId; // 便签背景色ID
private long mCreatedDate; private long mCreatedDate; // 便签创建日期
private boolean mHasAttachment; private boolean mHasAttachment; // 便签是否有附件
private long mModifiedDate; private long mModifiedDate; // 便签修改日期
private int mNotesCount; private int mNotesCount; // 便签数量
private long mParentId; private long mParentId; // 便签的父ID
private String mSnippet; private String mSnippet; // 便签摘要
private int mType; private int mType; // 便签类型
private int mWidgetId; private int mWidgetId; // 便签小部件ID
private int mWidgetType; private int mWidgetType; // 便签小部件类型
private String mName; private String mName; // 便签联系人名称
private String mPhoneNumber; private String mPhoneNumber; // 便签联系人电话号码
// 用于标记便签项的位置状态 // 用于标记便签项的位置状态
private boolean mIsLastItem; private boolean mIsLastItem; // 是否是最后一项
private boolean mIsFirstItem; private boolean mIsFirstItem; // 是否是第一项
private boolean mIsOnlyOneItem; private boolean mIsOnlyOneItem; // 是否只有一项
private boolean mIsOneNoteFollowingFolder; private boolean mIsOneNoteFollowingFolder; // 是否有一个便签项跟随文件夹
private boolean mIsMultiNotesFollowingFolder; private boolean mIsMultiNotesFollowingFolder; // 是否有多个便签项跟随文件夹
// 构造函数,从游标中初始化便签项的数据 // 构造函数,从游标中初始化便签项的数据
public NoteItemData(Context context, Cursor cursor) { public NoteItemData(Context context, Cursor cursor) {
mId = cursor.getLong(ID_COLUMN); // 从游标中获取数据并赋值给成员变量
mAlertDate = cursor.getLong(ALERTED_DATE_COLUMN); mId = cursor.getLong(ID_COLUMN); // 获取便签ID
mBgColorId = cursor.getInt(BG_COLOR_ID_COLUMN); mAlertDate = cursor.getLong(ALERTED_DATE_COLUMN); // 获取便签提醒日期
mCreatedDate = cursor.getLong(CREATED_DATE_COLUMN); mBgColorId = cursor.getInt(BG_COLOR_ID_COLUMN); // 获取便签背景色ID
mHasAttachment = (cursor.getInt(HAS_ATTACHMENT_COLUMN) > 0) ? true : false; mCreatedDate = cursor.getLong(CREATED_DATE_COLUMN); // 获取便签创建日期
mModifiedDate = cursor.getLong(MODIFIED_DATE_COLUMN); mHasAttachment = (cursor.getInt(HAS_ATTACHMENT_COLUMN) > 0) ? true : false; // 判断便签是否有附件
mNotesCount = cursor.getInt(NOTES_COUNT_COLUMN); mModifiedDate = cursor.getLong(MODIFIED_DATE_COLUMN); // 获取便签修改日期
mParentId = cursor.getLong(PARENT_ID_COLUMN); mNotesCount = cursor.getInt(NOTES_COUNT_COLUMN); // 获取便签数量
mSnippet = cursor.getString(SNIPPET_COLUMN); mParentId = cursor.getLong(PARENT_ID_COLUMN); // 获取便签的父ID
mSnippet = mSnippet.replace(NoteEditActivity.TAG_CHECKED, "").replace( mSnippet = cursor.getString(SNIPPET_COLUMN); // 获取便签摘要
NoteEditActivity.TAG_UNCHECKED, ""); mSnippet = mSnippet.replace(NoteEditActivity.TAG_CHECKED, "").replace(NoteEditActivity.TAG_UNCHECKED, ""); // 移除摘要中的特定标签
mType = cursor.getInt(TYPE_COLUMN); mType = cursor.getInt(TYPE_COLUMN); // 获取便签类型
mWidgetId = cursor.getInt(WIDGET_ID_COLUMN); mWidgetId = cursor.getInt(WIDGET_ID_COLUMN); // 获取便签小部件ID
mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN); mWidgetType = cursor.getInt(WIDGET_TYPE_COLUMN); // 获取便签小部件类型
// 如果便签项是通话记录文件夹
mPhoneNumber = ""; mPhoneNumber = "";
if (mParentId == Notes.ID_CALL_RECORD_FOLDER) { if (mParentId == Notes.ID_CALL_RECORD_FOLDER) {
mPhoneNumber = DataUtils.getCallNumberByNoteId(context.getContentResolver(), mId); mPhoneNumber = DataUtils.getCallNumberByNoteId(context.getContentResolver(), mId); // 获取通话记录号码
if (!TextUtils.isEmpty(mPhoneNumber)) { if (!TextUtils.isEmpty(mPhoneNumber)) {
mName = Contact.getContact(context, mPhoneNumber); mName = Contact.getContact(context, mPhoneNumber); // 获取联系人名称
if (mName == null) { if (mName == null) {
mName = mPhoneNumber; mName = mPhoneNumber; // 如果联系人名称为空,则使用电话号码
} }
} }
} }
if (mName == null) { if (mName == null) {
mName = ""; mName = ""; // 如果联系人名称为空,则设置为空字符串
} }
checkPostion(cursor); checkPostion(cursor); // 检查便签项的位置状态
} }
// 检查便签项的位置状态 // 检查便签项的位置状态
private void checkPostion(Cursor cursor) { private void checkPostion(Cursor cursor) {
mIsLastItem = cursor.isLast() ? true : false; // 设置便签项的位置状态标志
mIsFirstItem = cursor.isFirst() ? true : false; mIsLastItem = cursor.isLast() ? true : false; // 是否是最后一项
mIsOnlyOneItem = (cursor.getCount() == 1); mIsFirstItem = cursor.isFirst() ? true : false; // 是否是第一项
mIsMultiNotesFollowingFolder = false; mIsOnlyOneItem = (cursor.getCount() == 1); // 是否只有一项
mIsOneNoteFollowingFolder = false; mIsMultiNotesFollowingFolder = false; // 默认没有多个便签项跟随文件夹
mIsOneNoteFollowingFolder = false; // 默认没有单个便签项跟随文件夹
if (mType == Notes.TYPE_NOTE && !mIsFirstItem) {
int position = cursor.getPosition(); if (mType == Notes.TYPE_NOTE && !mIsFirstItem) { // 如果是便签项且不是第一项
if (cursor.moveToPrevious()) { int position = cursor.getPosition(); // 获取当前位置
if (cursor.getInt(TYPE_COLUMN) == Notes.TYPE_FOLDER if (cursor.moveToPrevious()) { // 移动到前一项
|| cursor.getInt(TYPE_COLUMN) == Notes.TYPE_SYSTEM) { if (cursor.getInt(TYPE_COLUMN) == Notes.TYPE_FOLDER || cursor.getInt(TYPE_COLUMN) == Notes.TYPE_SYSTEM) {
if (cursor.getCount() > (position + 1)) { if (cursor.getCount() > (position + 1)) {
mIsMultiNotesFollowingFolder = true; mIsMultiNotesFollowingFolder = true; // 有多个便签项跟随文件夹
} else { } else {
mIsOneNoteFollowingFolder = true; mIsOneNoteFollowingFolder = true; // 有单个便签项跟随文件夹
} }
} }
if (!cursor.moveToNext()) { if (!cursor.moveToNext()) { // 移动回原来的位置
throw new IllegalStateException("cursor move to previous but can't move back"); throw new IllegalStateException("cursor move to previous but can't move back"); // 如果无法移动回原来的位置,抛出异常
} }
} }
} }
@ -142,90 +177,90 @@ public class NoteItemData {
// 获取便签项的位置状态 // 获取便签项的位置状态
public boolean isOneFollowingFolder() { public boolean isOneFollowingFolder() {
return mIsOneNoteFollowingFolder; return mIsOneNoteFollowingFolder; // 返回是否有单个便签项跟随文件夹
} }
public boolean isMultiFollowingFolder() { public boolean isMultiFollowingFolder() {
return mIsMultiNotesFollowingFolder; return mIsMultiNotesFollowingFolder; // 返回是否有多个便签项跟随文件夹
} }
public boolean isLast() { public boolean isLast() {
return mIsLastItem; return mIsLastItem; // 返回是否是最后一项
} }
public String getCallName() { public String getCallName() {
return mName; return mName; // 返回联系人名称
} }
public boolean isFirst() { public boolean isFirst() {
return mIsFirstItem; return mIsFirstItem; // 返回是否是第一项
} }
public boolean isSingle() { public boolean isSingle() {
return mIsOnlyOneItem; return mIsOnlyOneItem; // 返回是否只有一项
} }
public long getId() { public long getId() {
return mId; return mId; // 返回便签ID
} }
public long getAlertDate() { public long getAlertDate() {
return mAlertDate; return mAlertDate; // 返回便签提醒日期
} }
public long getCreatedDate() { public long getCreatedDate() {
return mCreatedDate; return mCreatedDate; // 返回便签创建日期
} }
public boolean hasAttachment() { public boolean hasAttachment() {
return mHasAttachment; return mHasAttachment; // 返回便签是否有附件
} }
public long getModifiedDate() { public long getModifiedDate() {
return mModifiedDate; return mModifiedDate; // 返回便签修改日期
} }
public int getBgColorId() { public int getBgColorId() {
return mBgColorId; return mBgColorId; // 返回便签背景色ID
} }
public long getParentId() { public long getParentId() {
return mParentId; return mParentId; // 返回便签的父ID
} }
public int getNotesCount() { public int getNotesCount() {
return mNotesCount; return mNotesCount; // 返回便签数量
} }
public long getFolderId () { public long getFolderId() {
return mParentId; return mParentId; // 返回便签文件夹ID与父ID相同
} }
public int getType() { public int getType() {
return mType; return mType; // 返回便签类型
} }
public int getWidgetType() { public int getWidgetType() {
return mWidgetType; return mWidgetType; // 返回便签小部件类型
} }
public int getWidgetId() { public int getWidgetId() {
return mWidgetId; return mWidgetId; // 返回便签小部件ID
} }
public String getSnippet() { public String getSnippet() {
return mSnippet; return mSnippet; // 返回便签摘要
} }
public boolean hasAlert() { public boolean hasAlert() {
return (mAlertDate > 0); return (mAlertDate > 0); // 返回便签是否有提醒即提醒日期是否大于0
} }
public boolean isCallRecord() { public boolean isCallRecord() {
return (mParentId == Notes.ID_CALL_RECORD_FOLDER && !TextUtils.isEmpty(mPhoneNumber)); return (mParentId == Notes.ID_CALL_RECORD_FOLDER && !TextUtils.isEmpty(mPhoneNumber)); // 返回是否是通话记录
} }
public static int getNoteType(Cursor cursor) { public static int getNoteType(Cursor cursor) {
return cursor.getInt(TYPE_COLUMN); return cursor.getInt(TYPE_COLUMN); // 根据游标获取便签类型
} }
} }

@ -1,196 +1,238 @@
/* /*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
* * The MiCode Open Source Community2010-2011
*/
/*
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* Apache License 2.0"许可证"
*/
/*
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* 使
*/
/*
* You may obtain a copy of the License at * You may obtain a copy of the License at
* *
* http://www.apache.org/licenses/LICENSE-2.0 */
* /*
* http://www.apache.org/licenses/LICENSE-2.0
* Apache License 2.0
*/
/*
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
*
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
*
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
*/
/*
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
*
*/
/*
* limitations under the License. * limitations under the License.
*
*/ */
package net.micode.notes.ui; package net.micode.notes.ui;
// 定义包名为net.micode.notes.ui。
import android.content.Context; import android.content.Context;
// 导入Context类用于获取应用程序的环境信息。
import android.database.Cursor; import android.database.Cursor;
// 导入Cursor类用于遍历数据库查询结果。
import android.util.Log; import android.util.Log;
// 导入Log类用于打印日志信息。
import android.view.View; import android.view.View;
// 导入View类用于创建和管理视图。
import android.view.ViewGroup; import android.view.ViewGroup;
// 导入ViewGroup类用于管理布局中的视图组。
import android.widget.CursorAdapter; import android.widget.CursorAdapter;
// 导入CursorAdapter类用于将游标中的数据绑定到视图上。
import net.micode.notes.data.Notes; import net.micode.notes.data.Notes;
// 导入Notes类用于操作便签数据。
import java.util.Collection; import java.util.Collection;
// 导入Collection接口用于处理集合。
import java.util.HashMap; import java.util.HashMap;
// 导入HashMap类用于存储键值对。
import java.util.HashSet; import java.util.HashSet;
// 导入HashSet类用于存储不重复的元素集合。
import java.util.Iterator; import java.util.Iterator;
// 导入Iterator接口用于遍历集合。
// NotesListAdapter是CursorAdapter的子类用于为便签列表提供数据和视图 // NotesListAdapter是CursorAdapter的子类用于为便签列表提供数据和视图
public class NotesListAdapter extends CursorAdapter { public class NotesListAdapter extends CursorAdapter {
private static final String TAG = "NotesListAdapter"; private static final String TAG = "NotesListAdapter";
private Context mContext; // 上下文对象 // 定义TAG常量用于日志输出。
private Context mContext; // 存储上下文对象
private HashMap<Integer, Boolean> mSelectedIndex; // 存储选中状态的哈希图 private HashMap<Integer, Boolean> mSelectedIndex; // 存储选中状态的哈希图
private int mNotesCount; // 便签数量 private int mNotesCount; // 存储便签数量
private boolean mChoiceMode; // 选择模式标志 private boolean mChoiceMode; // 标记是否处于选择模式
// AppWidgetAttribute内部类用于存储小部件的属性 // AppWidgetAttribute内部类用于存储小部件的属性
public static class AppWidgetAttribute { public static class AppWidgetAttribute {
public int widgetId; public int widgetId; // 小部件ID
public int widgetType; public int widgetType; // 小部件类型
}; };
// 构造函数 // NotesListAdapter的构造函数
public NotesListAdapter(Context context) { public NotesListAdapter(Context context) {
super(context, null); super(context, null); // 调用父类构造函数
mSelectedIndex = new HashMap<Integer, Boolean>(); mSelectedIndex = new HashMap<Integer, Boolean>(); // 初始化选中状态哈希图
mContext = context; mContext = context; // 保存上下文对象
mNotesCount = 0; mNotesCount = 0; // 初始化便签数量
} }
// 新建视图 // 新建视图的方法,用于创建新的列表项视图
@Override @Override
public View newView(Context context, Cursor cursor, ViewGroup parent) { public View newView(Context context, Cursor cursor, ViewGroup parent) {
return new NotesListItem(context); return new NotesListItem(context); // 返回一个新的NotesListItem视图
} }
// 绑定视图和数据 // 绑定视图和数据的方法,用于将游标中的数据绑定到视图上
@Override @Override
public void bindView(View view, Context context, Cursor cursor) { public void bindView(View view, Context context, Cursor cursor) {
if (view instanceof NotesListItem) { if (view instanceof NotesListItem) {
NoteItemData itemData = new NoteItemData(context, cursor); NoteItemData itemData = new NoteItemData(context, cursor); // 创建NoteItemData对象
((NotesListItem) view).bind(context, itemData, mChoiceMode, ((NotesListItem) view).bind(context, itemData, mChoiceMode, // 绑定数据到视图
isSelectedItem(cursor.getPosition())); isSelectedItem(cursor.getPosition())); // 传递选择状态
} }
} }
// 设置选中项 // 设置选中项的方法,用于改变项的选中状态
public void setCheckedItem(final int position, final boolean checked) { public void setCheckedItem(final int position, final boolean checked) {
mSelectedIndex.put(position, checked); mSelectedIndex.put(position, checked); // 更新选中状态
notifyDataSetChanged(); notifyDataSetChanged(); // 通知数据改变
} }
// 获取选择模式 // 获取选择模式的方法,用于判断是否处于选择模式
public boolean isInChoiceMode() { public boolean isInChoiceMode() {
return mChoiceMode; return mChoiceMode; // 返回选择模式标志
} }
// 设置选择模式 // 设置选择模式的方法,用于设置选择模式
public void setChoiceMode(boolean mode) { public void setChoiceMode(boolean mode) {
mSelectedIndex.clear(); mSelectedIndex.clear(); // 清除选中状态
mChoiceMode = mode; mChoiceMode = mode; // 设置选择模式标志
} }
// 全选或全不选 // 全选或全不选的方法,用于设置所有项的选中状态
public void selectAll(boolean checked) { public void selectAll(boolean checked) {
Cursor cursor = getCursor(); Cursor cursor = getCursor(); // 获取游标
for (int i = 0; i < getCount(); i++) { for (int i = 0; i < getCount(); i++) {
if (cursor.moveToPosition(i)) { if (cursor.moveToPosition(i)) { // 移动到指定位置
if (NoteItemData.getNoteType(cursor) == Notes.TYPE_NOTE) { if (NoteItemData.getNoteType(cursor) == Notes.TYPE_NOTE) { // 如果是便签类型
setCheckedItem(i, checked); setCheckedItem(i, checked); // 设置选中状态
} }
} }
} }
} }
// 获取选中的便签ID集合 // 获取选中的便签ID集合的方法用于获取所有选中项的ID
public HashSet<Long> getSelectedItemIds() { public HashSet<Long> getSelectedItemIds() {
HashSet<Long> itemSet = new HashSet<Long>(); HashSet<Long> itemSet = new HashSet<Long>(); // 创建ID集合
for (Integer position : mSelectedIndex.keySet()) { for (Integer position : mSelectedIndex.keySet()) { // 遍历选中状态集合
if (mSelectedIndex.get(position) == true) { if (mSelectedIndex.get(position) == true) { // 如果项被选中
Long id = getItemId(position); Long id = getItemId(position); // 获取项的ID
if (id == Notes.ID_ROOT_FOLDER) { if (id == Notes.ID_ROOT_FOLDER) { // 如果ID是根文件夹ID
Log.d(TAG, "Wrong item id, should not happen"); Log.d(TAG, "Wrong item id, should not happen"); // 打印错误日志
} else { } else {
itemSet.add(id); itemSet.add(id); // 添加ID到集合
} }
} }
} }
return itemSet; // 返回ID集合
return itemSet;
} }
// 获取选中的小部件属性集合 // 获取选中的小部件属性集合的方法,用于获取所有选中小部件的属性
public HashSet<AppWidgetAttribute> getSelectedWidget() { public HashSet<AppWidgetAttribute> getSelectedWidget() {
HashSet<AppWidgetAttribute> itemSet = new HashSet<AppWidgetAttribute>(); HashSet<AppWidgetAttribute> itemSet = new HashSet<AppWidgetAttribute>(); // 创建小部件属性集合
for (Integer position : mSelectedIndex.keySet()) { for (Integer position : mSelectedIndex.keySet()) { // 遍历选中状态集合
if (mSelectedIndex.get(position) == true) { if (mSelectedIndex.get(position) == true) { // 如果项被选中
Cursor c = (Cursor) getItem(position); Cursor c = (Cursor) getItem(position); // 获取游标项
if (c != null) { if (c != null) { // 如果游标项不为空
AppWidgetAttribute widget = new AppWidgetAttribute(); AppWidgetAttribute widget = new AppWidgetAttribute(); // 创建小部件属性对象
NoteItemData item = new NoteItemData(mContext, c); NoteItemData item = new NoteItemData(mContext, c); // 创建NoteItemData对象
widget.widgetId = item.getWidgetId(); widget.widgetId = item.getWidgetId(); // 获取小部件ID
widget.widgetType = item.getWidgetType(); widget.widgetType = item.getWidgetType(); // 获取小部件类型
itemSet.add(widget); itemSet.add(widget); // 添加小部件属性到集合
} else { } else {
Log.e(TAG, "Invalid cursor"); Log.e(TAG, "Invalid cursor"); // 打印错误日志
return null; return null; // 返回null
} }
} }
} }
return itemSet; return itemSet; // 返回小部件属性集合
} }
// 获取选中数量 // 获取选中数量的方法,用于计算选中项的数量
public int getSelectedCount() { public int getSelectedCount() {
Collection<Boolean> values = mSelectedIndex.values(); Collection<Boolean> values = mSelectedIndex.values(); // 获取选中状态值集合
if (null == values) { if (null == values) {
return 0; return 0; // 如果集合为空返回0
} }
Iterator<Boolean> iter = values.iterator(); Iterator<Boolean> iter = values.iterator(); // 创建迭代器
int count = 0; int count = 0; // 初始化计数器
while (iter.hasNext()) { while (iter.hasNext()) { // 遍历集合
if (true == iter.next()) { if (true == iter.next()) { // 如果项被选中
count++; count++; // 增加计数器
} }
} }
return count; return count; // 返回选中数量
} }
// 检查是否全部选中 // 检查是否全部选中的方法,用于判断所有项是否被选中
public boolean isAllSelected() { public boolean isAllSelected() {
int checkedCount = getSelectedCount(); int checkedCount = getSelectedCount(); // 获取选中数量
return (checkedCount != 0 && checkedCount == mNotesCount); return (checkedCount != 0 && checkedCount == mNotesCount); // 如果选中数量不等于0且等于便签数量则返回true
} }
// 检查指定位置的项是否被选中 // 检查指定位置的项是否被选中的方法,用于判断特定项的选中状态
public boolean isSelectedItem(final int position) { public boolean isSelectedItem(final int position) {
if (null == mSelectedIndex.get(position)) { if (null == mSelectedIndex.get(position)) { // 如果项的选中状态为null
return false; return false; // 则返回false
} }
return mSelectedIndex.get(position); return mSelectedIndex.get(position); // 否则返回选中状态
} }
// 当内容变化时调用 // 当内容变化时调用的方法,用于更新便签数量
@Override @Override
protected void onContentChanged() { protected void onContentChanged() {
super.onContentChanged(); super.onContentChanged(); // 调用父类方法
calcNotesCount(); calcNotesCount(); // 计算便签数量
} }
// 更改游标时调用 // 更改游标时调用的方法,用于更新便签数量
@Override @Override
public void changeCursor(Cursor cursor) { public void changeCursor(Cursor cursor) {
super.changeCursor(cursor); super.changeCursor(cursor); // 调用父类方法
calcNotesCount(); calcNotesCount(); // 计算便签数量
} }
// 计算便签数量 // 计算便签数量的方法,用于计算游标中的便签数量
private void calcNotesCount() { private void calcNotesCount() {
mNotesCount = 0; mNotesCount = 0; // 初始化便签数量
for (int i = 0; i < getCount(); i++) { for (int i = 0; i < getCount(); i++) { // 遍历游标
Cursor c = (Cursor) getItem(i); Cursor c = (Cursor) getItem(i); // 获取游标项
if (c != null) { if (c != null) { // 如果游标项不为空
if (NoteItemData.getNoteType(c) == Notes.TYPE_NOTE) { if (NoteItemData.getNoteType(c) == Notes.TYPE_NOTE) { // 如果是便签类型
mNotesCount++; mNotesCount++; // 增加便签数量
} }
} else { } else {
Log.e(TAG, "Invalid cursor"); Log.e(TAG, "Invalid cursor"); // 打印错误日志
return; return; // 返回
} }
} }
} }

@ -1,131 +1,163 @@
/* /*
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net) * Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
* * The MiCode Open Source Community2010-2011
*/
/*
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* Apache License 2.0
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
* 使
* You may obtain a copy of the License at * You may obtain a copy of the License at
*
* *
* http://www.apache.org/licenses/LICENSE-2.0 * http://www.apache.org/licenses/LICENSE-2.0
* Apache License 2.0
* *
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
*
* distributed under the License is distributed on an "AS IS" BASIS, * distributed under the License is distributed on an "AS IS" BASIS,
*
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
*
* limitations under the License. * limitations under the License.
*
*/ */
package net.micode.notes.ui; package net.micode.notes.ui;
// 声明该类属于net.micode.notes.ui包。
import android.content.Context; import android.content.Context;
// 导入Context类用于获取应用程序的环境信息。
import android.text.format.DateUtils; import android.text.format.DateUtils;
// 导入DateUtils类用于处理日期和时间。
import android.view.View; import android.view.View;
// 导入View类用于创建和管理视图。
import android.widget.CheckBox; import android.widget.CheckBox;
// 导入CheckBox类用于创建和管理复选框。
import android.widget.ImageView; import android.widget.ImageView;
// 导入ImageView类用于创建和管理图像视图。
import android.widget.LinearLayout; import android.widget.LinearLayout;
// 导入LinearLayout类用于创建和管理线性布局。
import android.widget.TextView; import android.widget.TextView;
// 导入TextView类用于创建和管理文本视图。
import net.micode.notes.R; import net.micode.notes.R;
// 导入R类用于访问资源文件。
import net.micode.notes.data.Notes; import net.micode.notes.data.Notes;
// 导入Notes类用于处理便签数据。
import net.micode.notes.tool.DataUtils; import net.micode.notes.tool.DataUtils;
// 导入DataUtils类用于数据处理工具。
import net.micode.notes.tool.ResourceParser.NoteItemBgResources; import net.micode.notes.tool.ResourceParser.NoteItemBgResources;
// 导入NoteItemBgResources类用于获取便签项背景资源。
// NotesListItem是LinearLayout的子类用于显示单个便签项的视图 // NotesListItem是LinearLayout的子类用于显示单个便签项的视图
public class NotesListItem extends LinearLayout { public class NotesListItem extends LinearLayout {
private ImageView mAlert; // 用于显示提醒图标 private ImageView mAlert; // 成员变量,用于显示提醒图标的ImageView
private TextView mTitle; // 用于显示便签标题 private TextView mTitle; // 成员变量,用于显示便签标题的TextView
private TextView mTime; // 用于显示便签修改时间 private TextView mTime; // 成员变量,用于显示便签修改时间的TextView
private TextView mCallName; // 用于显示通话记录姓名 private TextView mCallName; // 成员变量,用于显示通话记录姓名的TextView
private NoteItemData mItemData; // 存储便签项数据 private NoteItemData mItemData; // 成员变量,存储便签项数据的NoteItemData对象
private CheckBox mCheckBox; // 用于选择模式时显示的复选框 private CheckBox mCheckBox; // 成员变量,用于选择模式时显示的复选框CheckBox
// 构造函数,初始化视图和组件 // 构造函数,初始化视图和组件
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); // 填充布局将note_item布局文件加载到当前LinearLayout中
mAlert = (ImageView) findViewById(R.id.iv_alert_icon); // 初始化提醒图标 mAlert = (ImageView) findViewById(R.id.iv_alert_icon); // 通过ID查找提醒图标的ImageView并赋值给mAlert
mTitle = (TextView) findViewById(R.id.tv_title); // 初始化标题 mTitle = (TextView) findViewById(R.id.tv_title); // 通过ID查找便签标题的TextView并赋值给mTitle
mTime = (TextView) findViewById(R.id.tv_time); // 初始化时间 mTime = (TextView) findViewById(R.id.tv_time); // 通过ID查找便签修改时间的TextView并赋值给mTime
mCallName = (TextView) findViewById(R.id.tv_name); // 初始化通话记录姓名 mCallName = (TextView) findViewById(R.id.tv_name); // 通过ID查找通话记录姓名的TextView并赋值给mCallName
mCheckBox = (CheckBox) findViewById(android.R.id.checkbox); // 初始化复选框 mCheckBox = (CheckBox) findViewById(android.R.id.checkbox); // 通过ID查找复选框并赋值给mCheckBox
} }
// bind方法用于绑定数据和视图 // bind方法用于绑定数据和视图
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); // 否则隐藏复选框
} }
mItemData = data; // 保存便签项数据 mItemData = data; // 保存便签项数据到mItemData
// 根据便签项类型设置视图显示 // 根据便签项类型设置视图显示
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())); // 格式化文件夹文件数量
mAlert.setImageResource(R.drawable.call_record); mAlert.setImageResource(R.drawable.call_record); // 设置提醒图标资源
} else if (data.getParentId() == Notes.ID_CALL_RECORD_FOLDER) { } else if (data.getParentId() == Notes.ID_CALL_RECORD_FOLDER) {
mCallName.setVisibility(View.VISIBLE); mCallName.setVisibility(View.VISIBLE); // 如果父ID是通话记录文件夹则显示通话记录姓名
mCallName.setText(data.getCallName()); mCallName.setText(data.getCallName()); // 设置通话记录姓名文本
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); // 否则隐藏提醒图标
} }
} else { } else {
mCallName.setVisibility(View.GONE); mCallName.setVisibility(View.GONE); // 隐藏通话记录姓名
mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem); mTitle.setTextAppearance(context, R.style.TextAppearancePrimaryItem); // 设置标题文本样式
// 设置标题和提醒图标 // 设置标题和提醒图标
if (data.getType() == Notes.TYPE_FOLDER) { if (data.getType() == Notes.TYPE_FOLDER) {
mTitle.setText(data.getSnippet() mTitle.setText(data.getSnippet() // 如果类型为文件夹,则设置标题文本
+ context.getString(R.string.format_folder_files_count, + context.getString(R.string.format_folder_files_count, data.getNotesCount())); // 格式化文件夹文件数量
data.getNotesCount())); mAlert.setVisibility(View.GONE); // 隐藏提醒图标
mAlert.setVisibility(View.GONE);
} else { } else {
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); // 否则隐藏提醒图标
} }
} }
} }
// 设置修改时间显示 // 设置修改时间显示
mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate())); mTime.setText(DateUtils.getRelativeTimeSpanString(data.getModifiedDate())); // 将修改时间格式化为相对时间字符串
// 设置背景 // 设置背景
setBackground(data); setBackground(data); // 根据便签项数据设置背景
} }
// setBackground方法用于设置便签项的背景 // setBackground方法用于设置便签项的背景
private void setBackground(NoteItemData data) { private void setBackground(NoteItemData data) {
int id = data.getBgColorId(); int id = data.getBgColorId(); // 获取便签项的背景色ID
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 {
setBackgroundResource(NoteItemBgResources.getFolderBgRes()); setBackgroundResource(NoteItemBgResources.getFolderBgRes()); // 如果不是便签项,则设置文件夹的背景资源
} }
} }
// getItemData方法用于获取绑定的便签项数据 // getItemData方法用于获取绑定的便签项数据
public NoteItemData getItemData() { public NoteItemData getItemData() {
return mItemData; return mItemData; // 返回绑定的便签项数据
} }
} }
Loading…
Cancel
Save