You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
java/ui/FoldersListAdapter.java

146 lines
4.1 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/*
* Copyright (c) 2010-2011, The MiCode Open Source Community (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
*
* 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;
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它为笔记本应用的文件夹列表提供了数据适配器。
*/
public class FoldersListAdapter extends CursorAdapter {
/**
* 数据库投影字段。
*/
public static final String [] PROJECTION = {
NoteColumns.ID,
NoteColumns.SNIPPET
};
/**
* ID 列索引。
*/
public static final int ID_COLUMN = 0;
/**
* 名称列索引。
*/
public static final int NAME_COLUMN = 1;
/**
* FoldersListAdapter 的构造方法。
* @param context 上下文环境。
* @param c Cursor包含文件夹列表数据。
*/
public FoldersListAdapter(Context context, Cursor c) {
super(context, c);
// TODO: 自动生成的构造函数存根
}
/**
* 创建一个新的 View 对象。
* @param context 上下文环境。
* @param cursor Cursor包含文件夹数据。
* @param parent ViewGroup新 View 将被添加到这个容器中。
* @return 新的 View 对象。
*/
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return new FolderListItem(context);
}
/**
* 将 Cursor 中的数据绑定到指定 View 中。
* @param view 用于显示数据的 View。
* @param context 上下文环境。
* @param cursor 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 的内部类,继承自 LinearLayout。
*/
private class FolderListItem extends LinearLayout {
/**
* TextView用于显示文件夹名称。
*/
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);
}
/**
* 绑定文件夹名称到 TextView。
* @param name 文件夹名称。
*/
public void bind(String name) {
mName.setText(name);
}
}
}