|
|
|
@ -1,19 +1,3 @@
|
|
|
|
|
/*
|
|
|
|
|
* 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;
|
|
|
|
@ -28,11 +12,10 @@ import net.micode.notes.R;
|
|
|
|
|
import net.micode.notes.data.Notes;
|
|
|
|
|
import net.micode.notes.data.Notes.NoteColumns;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public class FoldersListAdapter extends CursorAdapter {
|
|
|
|
|
public static final String [] PROJECTION = {
|
|
|
|
|
NoteColumns.ID,
|
|
|
|
|
NoteColumns.SNIPPET
|
|
|
|
|
NoteColumns.ID,
|
|
|
|
|
NoteColumns.SNIPPET
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
public static final int ID_COLUMN = 0;
|
|
|
|
@ -45,12 +28,14 @@ public class FoldersListAdapter extends CursorAdapter {
|
|
|
|
|
|
|
|
|
|
@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);
|
|
|
|
@ -58,6 +43,7 @@ public class FoldersListAdapter extends CursorAdapter {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
@ -68,13 +54,14 @@ public class FoldersListAdapter extends CursorAdapter {
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|