Merge pull request '代码注释(王苒苒)' (#2) from Wangranran into main
commit
a3bd979cb9
@ -0,0 +1,98 @@
|
||||
|
||||
/**
|
||||
* 自定义日期时间选择器视图。
|
||||
*/
|
||||
public class DateTimePicker extends FrameLayout {
|
||||
// 类成员变量和常量定义
|
||||
private static final boolean DEFAULT_ENABLE_STATE = true;
|
||||
private static final int HOURS_IN_HALF_DAY = 12;
|
||||
// ... 其他常量定义
|
||||
|
||||
// 日期时间选择器的组件
|
||||
private final NumberPicker mDateSpinner;
|
||||
private final NumberPicker mHourSpinner;
|
||||
private final NumberPicker mMinuteSpinner;
|
||||
private final NumberPicker mAmPmSpinner;
|
||||
private Calendar mDate;
|
||||
|
||||
// 日期显示值数组
|
||||
private String[] mDateDisplayValues = new String[DAYS_IN_ALL_WEEK];
|
||||
|
||||
// AM/PM标志
|
||||
private boolean mIsAm;
|
||||
|
||||
// 是否为24小时视图
|
||||
private boolean mIs24HourView;
|
||||
|
||||
// 启用状态
|
||||
private boolean mIsEnabled = DEFAULT_ENABLE_STATE;
|
||||
|
||||
// 初始化标志
|
||||
private boolean mInitialising;
|
||||
|
||||
// 日期时间改变监听器
|
||||
private OnDateTimeChangedListener mOnDateTimeChangedListener;
|
||||
|
||||
// NumberPicker值改变监听器
|
||||
private NumberPicker.OnValueChangeListener mOnDateChangedListener = new NumberPicker.OnValueChangeListener() {
|
||||
@Override
|
||||
public void onValueChange(NumberPicker picker, int oldVal, int newVal) {
|
||||
// 日期改变时的处理逻辑
|
||||
}
|
||||
};
|
||||
// ... 其他监听器定义
|
||||
|
||||
/**
|
||||
* 定义日期时间改变监听器接口。
|
||||
*/
|
||||
public interface OnDateTimeChangedListener {
|
||||
void onDateTimeChanged(DateTimePicker view, int year, int month,
|
||||
int dayOfMonth, int hourOfDay, int minute);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造函数。
|
||||
*/
|
||||
public DateTimePicker(Context context) {
|
||||
// ... 实现代码
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前日期。
|
||||
* @param date 长整型日期值。
|
||||
*/
|
||||
public void setCurrentDate(long date) {
|
||||
// ... 实现代码
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前年份。
|
||||
* @return 当前年份。
|
||||
*/
|
||||
public int getCurrentYear() {
|
||||
// ... 实现代码
|
||||
}
|
||||
|
||||
// ... 其他日期时间组件的getter和setter方法
|
||||
|
||||
/**
|
||||
* 设置是否为24小时视图。
|
||||
* @param is24HourView 是否为24小时视图。
|
||||
*/
|
||||
public void set24HourView(boolean is24HourView) {
|
||||
// ... 实现代码
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置日期时间改变监听器。
|
||||
* @param callback 监听器回调。
|
||||
*/
|
||||
public void setOnDateTimeChangedListener(OnDateTimeChangedListener callback) {
|
||||
// ... 实现代码
|
||||
}
|
||||
|
||||
private void onDateTimeChanged() {
|
||||
// 通知监听器日期时间改变
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,92 @@
|
||||
/**
|
||||
* 日期时间选择器对话框,允许用户设置日期和时间。
|
||||
*/
|
||||
public class DateTimePickerDialog extends AlertDialog implements OnClickListener {
|
||||
// 当前日期时间
|
||||
private Calendar mDate = Calendar.getInstance();
|
||||
// 是否为24小时视图
|
||||
private boolean mIs24HourView;
|
||||
// 日期时间设置监听器
|
||||
private OnDateTimeSetListener mOnDateTimeSetListener;
|
||||
// 日期时间选择器组件
|
||||
private DateTimePicker mDateTimePicker;
|
||||
|
||||
/**
|
||||
* 日期时间设置监听器接口。
|
||||
*/
|
||||
public interface OnDateTimeSetListener {
|
||||
void OnDateTimeSet(AlertDialog dialog, long date);
|
||||
}
|
||||
|
||||
/**
|
||||
* 构造函数。
|
||||
* @param context 上下文对象
|
||||
* @param date 初始日期时间
|
||||
*/
|
||||
public DateTimePickerDialog(Context context, long date) {
|
||||
super(context);
|
||||
mDateTimePicker = new DateTimePicker(context);
|
||||
setView(mDateTimePicker);
|
||||
// 设置日期时间改变监听器
|
||||
mDateTimePicker.setOnDateTimeChangedListener(new OnDateTimeChangedListener() {
|
||||
public void onDateTimeChanged(DateTimePicker view, int year, int month,
|
||||
int dayOfMonth, int hourOfDay, int minute) {
|
||||
mDate.set(Calendar.YEAR, year);
|
||||
mDate.set(Calendar.MONTH, month);
|
||||
mDate.set(Calendar.DAY_OF_MONTH, dayOfMonth);
|
||||
mDate.set(Calendar.HOUR_OF_DAY, hourOfDay);
|
||||
mDate.set(Calendar.MINUTE, minute);
|
||||
updateTitle(mDate.getTimeInMillis());
|
||||
}
|
||||
});
|
||||
mDate.setTimeInMillis(date);
|
||||
mDate.set(Calendar.SECOND, 0);
|
||||
mDateTimePicker.setCurrentDate(mDate.getTimeInMillis());
|
||||
// 设置确认和取消按钮
|
||||
setButton(context.getString(R.string.datetime_dialog_ok), this);
|
||||
setButton2(context.getString(R.string.datetime_dialog_cancel), (OnClickListener)null);
|
||||
// 设置24小时视图
|
||||
set24HourView(DateFormat.is24HourFormat(this.getContext()));
|
||||
updateTitle(mDate.getTimeInMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置是否为24小时视图。
|
||||
* @param is24HourView 是否为24小时视图
|
||||
*/
|
||||
public void set24HourView(boolean is24HourView) {
|
||||
mIs24HourView = is24HourView;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置日期时间设置监听器。
|
||||
* @param callBack 监听器回调
|
||||
*/
|
||||
public void setOnDateTimeSetListener(OnDateTimeSetListener callBack) {
|
||||
mOnDateTimeSetListener = callBack;
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新对话框标题为当前日期时间。
|
||||
* @param date 长整型日期时间值
|
||||
*/
|
||||
private void updateTitle(long date) {
|
||||
int flag =
|
||||
DateUtils.FORMAT_SHOW_YEAR |
|
||||
DateUtils.FORMAT_SHOW_DATE |
|
||||
DateUtils.FORMAT_SHOW_TIME;
|
||||
flag |= mIs24HourView ? DateUtils.FORMAT_24HOUR : DateUtils.FORMAT_12HOUR;
|
||||
setTitle(DateUtils.formatDateTime(this.getContext(), date, flag));
|
||||
}
|
||||
|
||||
/**
|
||||
* 点击事件处理。
|
||||
* @param arg0 对话框接口
|
||||
* @param arg1 按钮索引
|
||||
*/
|
||||
public void onClick(DialogInterface arg0, int arg1) {
|
||||
if (mOnDateTimeSetListener != null) {
|
||||
mOnDateTimeSetListener.OnDateTimeSet(this, mDate.getTimeInMillis());
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,87 @@
|
||||
/**
|
||||
* 文件夹列表适配器,用于显示和管理文件夹列表项。
|
||||
*/
|
||||
public class FoldersListAdapter extends CursorAdapter {
|
||||
// 投影数组,用于查询数据库时指定需要哪些列
|
||||
public static final String [] PROJECTION = {
|
||||
NoteColumns.ID,
|
||||
NoteColumns.SNIPPET
|
||||
};
|
||||
|
||||
// 列索引常量
|
||||
public static final int ID_COLUMN = 0;
|
||||
public static final int NAME_COLUMN = 1;
|
||||
|
||||
/**
|
||||
* 构造函数。
|
||||
* @param context 上下文对象,提供应用环境信息。
|
||||
* @param c 数据库游标,包含文件夹数据。
|
||||
*/
|
||||
public FoldersListAdapter(Context context, Cursor c) {
|
||||
super(context, c);
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新的列表项视图。
|
||||
* @param context 上下文对象。
|
||||
* @param cursor 数据库游标。
|
||||
* @param parent 父视图组。
|
||||
* @return 新的列表项视图。
|
||||
*/
|
||||
@Override
|
||||
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
||||
return new FolderListItem(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定数据到列表项视图。
|
||||
* @param view 列表项视图。
|
||||
* @param context 上下文对象。
|
||||
* @param cursor 数据库游标。
|
||||
*/
|
||||
@Override
|
||||
public void bindView(View view, Context context, Cursor cursor) {
|
||||
if (view instanceof FolderListItem) {
|
||||
String folderName = (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context
|
||||
.getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN);
|
||||
((FolderListItem) view).bind(folderName);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定位置的文件夹名称。
|
||||
* @param context 上下文对象。
|
||||
* @param position 列表项位置。
|
||||
* @return 文件夹名称。
|
||||
*/
|
||||
public String getFolderName(Context context, int position) {
|
||||
Cursor cursor = (Cursor) getItem(position);
|
||||
return (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ? context
|
||||
.getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN);
|
||||
}
|
||||
|
||||
/**
|
||||
* 自定义文件夹列表项视图。
|
||||
*/
|
||||
private class FolderListItem extends LinearLayout {
|
||||
private TextView mName;
|
||||
|
||||
/**
|
||||
* 构造函数。
|
||||
* @param context 上下文对象。
|
||||
*/
|
||||
public FolderListItem(Context context) {
|
||||
super(context);
|
||||
inflate(context, R.layout.folder_list_item, this);
|
||||
mName = (TextView) findViewById(R.id.tv_folder_name);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定文件夹名称到视图。
|
||||
* @param name 文件夹名称。
|
||||
*/
|
||||
public void bind(String name) {
|
||||
mName.setText(name);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,98 @@
|
||||
/**
|
||||
* 便签项数据类,封装单个便签项的相关信息。
|
||||
*/
|
||||
public class NoteItemData {
|
||||
// 数据库查询字段投影
|
||||
static final String [] PROJECTION = new String [] {
|
||||
NoteColumns.ID,
|
||||
NoteColumns.ALERTED_DATE,
|
||||
// ... 其他字段
|
||||
};
|
||||
|
||||
// 列索引常量
|
||||
private static final int ID_COLUMN = 0;
|
||||
private static final int ALERTED_DATE_COLUMN = 1;
|
||||
// ... 其他列索引常量
|
||||
|
||||
// 便签项属性
|
||||
private long mId;
|
||||
private long mAlertDate;
|
||||
private int mBgColorId;
|
||||
private long mCreatedDate;
|
||||
private boolean mHasAttachment;
|
||||
private long mModifiedDate;
|
||||
private int mNotesCount;
|
||||
private long mParentId;
|
||||
private String mSnippet;
|
||||
private int mType;
|
||||
private int mWidgetId;
|
||||
private int mWidgetType;
|
||||
private String mName;
|
||||
private String mPhoneNumber;
|
||||
|
||||
// 位置相关标志
|
||||
private boolean mIsLastItem;
|
||||
private boolean mIsFirstItem;
|
||||
private boolean mIsOnlyOneItem;
|
||||
private boolean mIsOneNoteFollowingFolder;
|
||||
private boolean mIsMultiNotesFollowingFolder;
|
||||
|
||||
/**
|
||||
* 构造函数,从数据库游标中初始化便签项数据。
|
||||
* @param context 上下文对象,用于访问资源和数据。
|
||||
* @param cursor 数据库游标,包含便签项的数据。
|
||||
*/
|
||||
public NoteItemData(Context context, Cursor cursor) {
|
||||
// 从游标中获取数据并初始化成员变量
|
||||
// ... 初始化代码
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查便签项在列表中的位置,设置位置相关标志。
|
||||
* @param cursor 数据库游标。
|
||||
*/
|
||||
private void checkPostion(Cursor cursor) {
|
||||
// 设置位置相关标志的逻辑
|
||||
// ... 实现代码
|
||||
}
|
||||
|
||||
// 获取器方法,用于获取便签项的属性值
|
||||
public boolean isOneFollowingFolder() {
|
||||
return mIsOneNoteFollowingFolder;
|
||||
}
|
||||
|
||||
public boolean isMultiFollowingFolder() {
|
||||
return mIsMultiNotesFollowingFolder;
|
||||
}
|
||||
|
||||
public boolean isLast() {
|
||||
return mIsLastItem;
|
||||
}
|
||||
|
||||
public String getCallName() {
|
||||
return mName;
|
||||
}
|
||||
|
||||
public boolean isFirst() {
|
||||
return mIsFirstItem;
|
||||
}
|
||||
|
||||
public boolean isSingle() {
|
||||
return mIsOnlyOneItem;
|
||||
}
|
||||
|
||||
public long getId() {
|
||||
return mId;
|
||||
}
|
||||
|
||||
// ... 其他获取器方法
|
||||
|
||||
/**
|
||||
* 根据游标获取便签类型。
|
||||
* @param cursor 数据库游标。
|
||||
* @return 便签类型。
|
||||
*/
|
||||
public static int getNoteType(Cursor cursor) {
|
||||
return cursor.getInt(TYPE_COLUMN);
|
||||
}
|
||||
}
|
@ -0,0 +1,219 @@
|
||||
/**
|
||||
* 便签列表适配器,用于管理和显示便签列表的数据。
|
||||
*/
|
||||
public class NotesListAdapter extends CursorAdapter {
|
||||
// 日志标签
|
||||
private static final String TAG = "NotesListAdapter";
|
||||
// 类成员变量
|
||||
private Context mContext; // 上下文对象
|
||||
private HashMap<Integer, Boolean> mSelectedIndex; // 保存选中状态的索引
|
||||
private int mNotesCount; // 便签计数
|
||||
private boolean mChoiceMode; // 是否处于选择模式
|
||||
|
||||
/**
|
||||
* 应用小部件属性类。
|
||||
*/
|
||||
public static class AppWidgetAttribute {
|
||||
public int widgetId; // 小部件ID
|
||||
public int widgetType; // 小部件类型
|
||||
};
|
||||
|
||||
/**
|
||||
* 构造函数。
|
||||
* @param context 上下文对象
|
||||
*/
|
||||
public NotesListAdapter(Context context) {
|
||||
super(context, null);
|
||||
mSelectedIndex = new HashMap<Integer, Boolean>();
|
||||
mContext = context;
|
||||
mNotesCount = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建新的列表项视图。
|
||||
* @param context 上下文对象
|
||||
* @param cursor 游标对象
|
||||
* @param parent 父视图组
|
||||
* @return 新的列表项视图
|
||||
*/
|
||||
@Override
|
||||
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
||||
return new NotesListItem(context);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定数据到列表项视图。
|
||||
* @param view 列表项视图
|
||||
* @param context 上下文对象
|
||||
* @param cursor 游标对象
|
||||
*/
|
||||
@Override
|
||||
public void bindView(View view, Context context, Cursor cursor) {
|
||||
if (view instanceof NotesListItem) {
|
||||
NoteItemData itemData = new NoteItemData(context, cursor);
|
||||
((NotesListItem) view).bind(context, itemData, mChoiceMode, isSelectedItem(cursor.getPosition()));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置列表项的选中状态。
|
||||
* @param position 列表项位置
|
||||
* @param checked 是否选中
|
||||
*/
|
||||
public void setCheckedItem(final int position, final boolean checked) {
|
||||
mSelectedIndex.put(position, checked);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取是否处于选择模式。
|
||||
* @return 是否处于选择模式
|
||||
*/
|
||||
public boolean isInChoiceMode() {
|
||||
return mChoiceMode;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置选择模式。
|
||||
* @param mode 是否开启选择模式
|
||||
*/
|
||||
public void setChoiceMode(boolean mode) {
|
||||
mSelectedIndex.clear();
|
||||
mChoiceMode = mode;
|
||||
}
|
||||
|
||||
/**
|
||||
* 全选或全不选。
|
||||
* @param checked 是否选中
|
||||
*/
|
||||
public void selectAll(boolean checked) {
|
||||
Cursor cursor = getCursor();
|
||||
for (int i = 0; i < getCount(); i++) {
|
||||
if (cursor.moveToPosition(i)) {
|
||||
if (NoteItemData.getNoteType(cursor) == Notes.TYPE_NOTE) {
|
||||
setCheckedItem(i, checked);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取选中的便签ID集合。
|
||||
* @return 选中的便签ID集合
|
||||
*/
|
||||
public HashSet<Long> getSelectedItemIds() {
|
||||
HashSet<Long> itemSet = new HashSet<Long>();
|
||||
for (Integer position : mSelectedIndex.keySet()) {
|
||||
if (mSelectedIndex.get(position) == true) {
|
||||
Long id = getItemId(position);
|
||||
if (id == Notes.ID_ROOT_FOLDER) {
|
||||
Log.d(TAG, "Wrong item id, should not happen");
|
||||
} else {
|
||||
itemSet.add(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
return itemSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取选中的小部件属性集合。
|
||||
* @return 选中的小部件属性集合
|
||||
*/
|
||||
public HashSet<AppWidgetAttribute> getSelectedWidget() {
|
||||
HashSet<AppWidgetAttribute> itemSet = new HashSet<AppWidgetAttribute>();
|
||||
for (Integer position : mSelectedIndex.keySet()) {
|
||||
if (mSelectedIndex.get(position) == true) {
|
||||
Cursor c = (Cursor) getItem(position);
|
||||
if (c != null) {
|
||||
AppWidgetAttribute widget = new AppWidgetAttribute();
|
||||
NoteItemData item = new NoteItemData(mContext, c);
|
||||
widget.widgetId = item.getWidgetId();
|
||||
widget.widgetType = item.getWidgetType();
|
||||
itemSet.add(widget);
|
||||
} else {
|
||||
Log.e(TAG, "Invalid cursor");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
return itemSet;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取选中数量。
|
||||
* @return 选中数量
|
||||
*/
|
||||
public int getSelectedCount() {
|
||||
Collection<Boolean> values = mSelectedIndex.values();
|
||||
if (null == values) {
|
||||
return 0;
|
||||
}
|
||||
Iterator<Boolean> iter = values.iterator();
|
||||
int count = 0;
|
||||
while (iter.hasNext()) {
|
||||
if (true == iter.next()) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否全部选中。
|
||||
* @return 是否全部选中
|
||||
*/
|
||||
public boolean isAllSelected() {
|
||||
int checkedCount = getSelectedCount();
|
||||
return (checkedCount != 0 && checkedCount == mNotesCount);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断指定位置的项是否选中。
|
||||
* @param position 项的位置
|
||||
* @return 是否选中
|
||||
*/
|
||||
public boolean isSelectedItem(final int position) {
|
||||
if (null == mSelectedIndex.get(position)) {
|
||||
return false;
|
||||
}
|
||||
return mSelectedIndex.get(position);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当内容变化时调用。
|
||||
*/
|
||||
@Override
|
||||
protected void onContentChanged() {
|
||||
super.onContentChanged();
|
||||
calcNotesCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* 更改游标。
|
||||
* @param cursor 新的游标
|
||||
*/
|
||||
@Override
|
||||
public void changeCursor(Cursor cursor) {
|
||||
super.changeCursor(cursor);
|
||||
calcNotesCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* 计算便签数量。
|
||||
*/
|
||||
private void calcNotesCount() {
|
||||
mNotesCount = 0;
|
||||
for (int i = 0; i < getCount(); i++) {
|
||||
Cursor c = (Cursor) getItem(i);
|
||||
if (c != null) {
|
||||
if (NoteItemData.getNoteType(c) == Notes.TYPE_NOTE) {
|
||||
mNotesCount++;
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "Invalid cursor");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,124 @@
|
||||
/**
|
||||
* 便签列表项视图,用于展示单个便签项的界面元素。
|
||||
*/
|
||||
public class NotesListItem extends LinearLayout {
|
||||
// 类成员变量
|
||||
private ImageView mAlert; // 提醒图标
|
||||
private TextView mTitle; // 便签标题
|
||||
private TextView mTime; // 便签修改时间
|
||||
private TextView mCallName; // 通话记录姓名
|
||||
private NoteItemData mItemData; // 便签项数据
|
||||
private CheckBox mCheckBox; // 选择框
|
||||
|
||||
/**
|
||||
* 构造函数。
|
||||
* @param context 上下文对象
|
||||
*/
|
||||
public NotesListItem(Context context) {
|
||||
super(context);
|
||||
// inflate the layout for this view
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 绑定数据到视图。
|
||||
* @param context 上下文对象
|
||||
* @param data 便签项数据
|
||||
* @param choiceMode 是否处于选择模式
|
||||
* @param checked 是否选中
|
||||
*/
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置背景资源。
|
||||
* @param 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());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取便签项数据。
|
||||
* @return 便签项数据
|
||||
*/
|
||||
public NoteItemData getItemData() {
|
||||
return mItemData;
|
||||
}
|
||||
}
|
Loading…
Reference in new issue