|
|
|
@ -1,87 +1,114 @@
|
|
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2010-2011, The MiCode Open Source Community (www.micode.net)
|
|
|
|
|
* 版权所有 (c) 2010-2011, MiCode 开源社区 (www.micode.net)
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
* 本文件授权使用 Apache License, Version 2.0(以下简称“许可证”);
|
|
|
|
|
* 除非符合许可证规定,否则不得使用此文件。
|
|
|
|
|
* 您可以从以下网址获取许可证副本:
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
* 除非适用法律要求或书面同意,否则根据许可证分发的软件
|
|
|
|
|
* 均按“原样”分发,不附带任何明示或暗示的保证或条件。
|
|
|
|
|
* 有关许可权限和限制的具体语言,请参阅许可证。
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
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是Cursor和ListView的接口
|
|
|
|
|
//FoldersListAdapter继承了CursorAdapter的类
|
|
|
|
|
//主要作用是便签数据库和用户的交互
|
|
|
|
|
//这里就是用folder(文件夹)的形式展现给用户
|
|
|
|
|
public static final String [] PROJECTION = {
|
|
|
|
|
NoteColumns.ID,
|
|
|
|
|
NoteColumns.SNIPPET
|
|
|
|
|
};//调用数据库中便签的ID和片段
|
|
|
|
|
|
|
|
|
|
public static final int ID_COLUMN = 0;
|
|
|
|
|
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) {
|
|
|
|
|
//ViewGroup是容器
|
|
|
|
|
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) 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);
|
|
|
|
|
}//根据数据库中标签的ID得到标签的各项内容
|
|
|
|
|
|
|
|
|
|
private class FolderListItem extends 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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* FoldersListAdapter 类用于显示文件夹列表。
|
|
|
|
|
* 它继承自 CursorAdapter,用于将数据库中的文件夹数据绑定到 ListView。
|
|
|
|
|
*/
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构造函数,初始化 FoldersListAdapter。
|
|
|
|
|
* @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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* FolderListItem 类用于表示单个文件夹列表项。
|
|
|
|
|
*/
|
|
|
|
|
private class FolderListItem extends LinearLayout {
|
|
|
|
|
private TextView mName;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 构造函数,初始化 FolderListItem。
|
|
|
|
|
* @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); // 设置文件夹名称
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|