|
|
|
@ -816,3 +816,73 @@ public class GTaskClient {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
package net.micode.notes.ui; // 定义包名
|
|
|
|
|
|
|
|
|
|
import android.content.Context; // 导入上下文类
|
|
|
|
|
import android.database.Cursor; // 导入游标类
|
|
|
|
|
import android.view.View; // 导入视图类
|
|
|
|
|
import android.view.ViewGroup; // 导入视图组类
|
|
|
|
|
import android.widget.CursorAdapter; // 导入游标适配器类
|
|
|
|
|
import android.widget.LinearLayout; // 导入线性布局类
|
|
|
|
|
import android.widget.TextView; // 导入文本视图类
|
|
|
|
|
|
|
|
|
|
import net.micode.notes.R; // 导入资源类
|
|
|
|
|
import net.micode.notes.data.Notes; // 导入笔记数据类
|
|
|
|
|
import net.micode.notes.data.Notes.NoteColumns; // 导入笔记列类
|
|
|
|
|
|
|
|
|
|
public class FoldersListAdapter extends CursorAdapter { // 定义文件夹列表适配器类,继承自 CursorAdapter
|
|
|
|
|
public static final String [] PROJECTION = { // 定义需要查询的字段数组
|
|
|
|
|
NoteColumns.ID, // 笔记 ID 列
|
|
|
|
|
NoteColumns.SNIPPET // 笔记摘要列
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static final int ID_COLUMN = 0; // ID 列索引
|
|
|
|
|
public static final int NAME_COLUMN = 1; // 名称列索引
|
|
|
|
|
|
|
|
|
|
// 构造函数,接受上下文和游标作为参数
|
|
|
|
|
public FoldersListAdapter(Context context, Cursor c) {
|
|
|
|
|
super(context, c); // 调用父类构造函数
|
|
|
|
|
// TODO Auto-generated constructor stub
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建新的视图
|
|
|
|
|
@Override
|
|
|
|
|
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
|
|
|
|
return new FolderListItem(context); // 返回新的文件夹列表项视图
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 绑定视图与数据
|
|
|
|
|
@Override
|
|
|
|
|
public void bindView(View view, Context context, Cursor cursor) {
|
|
|
|
|
if (view instanceof FolderListItem) { // 如果视图是 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); // 绑定文件夹名称到视图
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 根据位置获取文件夹名称
|
|
|
|
|
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 { // 继承自 LinearLayout
|
|
|
|
|
private TextView mName; // 存储文件夹名称的文本视图
|
|
|
|
|
|
|
|
|
|
// 构造函数,接受上下文作为参数
|
|
|
|
|
public FolderListItem(Context context) {
|
|
|
|
|
super(context); // 调用父类构造函数
|
|
|
|
|
inflate(context, R.layout.folder_list_item, this); // 加载布局文件
|
|
|
|
|
mName = (TextView) findViewById(R.id.tv_folder_name); // 初始化文件夹名称文本视图
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 绑定文件夹名称到文本视图
|
|
|
|
|
public void bind(String name) {
|
|
|
|
|
mName.setText(name); // 设置文本视图的文本为文件夹名称
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|