|
|
|
@ -0,0 +1,86 @@
|
|
|
|
|
package net.micode.notes.ui;
|
|
|
|
|
|
|
|
|
|
// 导入Android系统中处理上下文环境的类,用于访问应用程序的资源和类
|
|
|
|
|
import android.content.Context;
|
|
|
|
|
// 导入Android系统中处理数据库游标的类
|
|
|
|
|
import android.database.Cursor;
|
|
|
|
|
// 导入Android系统中处理视图的类
|
|
|
|
|
import android.view.View;
|
|
|
|
|
// 导入Android系统中处理视图容器的类
|
|
|
|
|
import android.view.ViewGroup;
|
|
|
|
|
// 导入Android系统中处理光标适配器的类
|
|
|
|
|
import android.widget.CursorAdapter;
|
|
|
|
|
// 导入Android系统中处理线性布局的类
|
|
|
|
|
import android.widget.LinearLayout;
|
|
|
|
|
// 导入Android系统中处理文本视图的类
|
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
|
|
// 导入应用程序中的资源类
|
|
|
|
|
import net.micode.notes.R;
|
|
|
|
|
// 导入应用程序中的便签数据类
|
|
|
|
|
import net.micode.notes.data.Notes;
|
|
|
|
|
// 导入应用程序中的便签列类
|
|
|
|
|
import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
|
|
|
|
|
|
// FoldersListAdapter类继承自CursorAdapter,用于将数据库中的便签数据与ListView进行绑定
|
|
|
|
|
public class FoldersListAdapter extends 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; // 名称列的索引
|
|
|
|
|
|
|
|
|
|
// 构造函数,用于创建FoldersListAdapter实例
|
|
|
|
|
public FoldersListAdapter(Context context, Cursor c) {
|
|
|
|
|
super(context, c); // 调用父类构造函数,初始化CursorAdapter
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 创建新的视图
|
|
|
|
|
@Override
|
|
|
|
|
public View newView(Context context, Cursor cursor, ViewGroup parent) {
|
|
|
|
|
// 返回一个新的FolderListItem视图
|
|
|
|
|
return new FolderListItem(context);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 绑定视图与数据
|
|
|
|
|
@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视图
|
|
|
|
|
((FolderListItem) view).bind(folderName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 获取指定位置的文件夹名称
|
|
|
|
|
public String getFolderName(Context context, int position) {
|
|
|
|
|
Cursor cursor = (Cursor) getItem(position); // 获取指定位置的Cursor
|
|
|
|
|
// 根据便签的ID获取文件夹名称
|
|
|
|
|
return (cursor.getLong(ID_COLUMN) == Notes.ID_ROOT_FOLDER) ?
|
|
|
|
|
context.getString(R.string.menu_move_parent_folder) : cursor.getString(NAME_COLUMN);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// FolderListItem类继承自LinearLayout,用于表示一个文件夹列表项
|
|
|
|
|
private class FolderListItem extends LinearLayout {
|
|
|
|
|
private TextView mName; // 文件夹名称的TextView
|
|
|
|
|
|
|
|
|
|
public FolderListItem(Context context) {
|
|
|
|
|
super(context);
|
|
|
|
|
// 加载布局文件
|
|
|
|
|
inflate(context, R.layout.folder_list_item, this);
|
|
|
|
|
// 获取文件夹名称的TextView
|
|
|
|
|
mName = (TextView) findViewById(R.id.tv_folder_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 绑定文件夹名称到TextView
|
|
|
|
|
public void bind(String name) {
|
|
|
|
|
mName.setText(name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|