Delete 'src/NotesListAdapter.java'

pull/5/head
ple93m5su 2 years ago
parent b443921252
commit 2236bc600f

@ -1,367 +0,0 @@
/*
* 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.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CursorAdapter;
import net.micode.notes.data.Notes;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
/**
* @projectName: xiaomi label
* @package: ui
* @className: NotesListAdapter
* @description: 便CursorAdapter便
* @author: zhangchaoqun
* @createDate: datetime
* @updateUser: user
* @updateDate: datetime
* @updateRemark:
* @version: v1.0
*/
public class NotesListAdapter extends CursorAdapter {
private static final String TAG = "NotesListAdapter";
private Context mContext;
private HashMap<Integer, Boolean> mSelectedIndex;
private int mNotesCount;//便签数
private boolean mChoiceMode;//选择模式标记
/**
* @projectName: xiaomi label
* @package: ui
* @className: AppWidgetAttribute
* @description: widget
* @author: zhangchaoqun
* @createDate: datetime
* @updateUser: user
* @updateDate: datetime
* @updateRemark:
* @version: v1.0
*/
public static class AppWidgetAttribute {
public int widgetId;
public int widgetType;
};
/**
* @description :便
* @param 1:context
* @param 2:
* @param 3:
* @return :NotesListAdapter
* @author zhangchaoqun
*/
public NotesListAdapter(Context context) {
//父类对象置空
super(context, null);
//新建选项下标的hash表
mSelectedIndex = new HashMap<Integer, Boolean>();
mContext = context;
mNotesCount = 0;
}
/**
* @description :使NotesListItem
* @param 1:context
* @param 2:cursor
* @param 3:parent
* @return :View
* @author zhangchaoqun
*/
@Override
public View newView(Context context, Cursor cursor, ViewGroup parent) {
return new NotesListItem(context);
}
/**
* @description :
* @param 1:view
* @param 2:context
* @param 3:cursor
* @return :void
* @author zhangchaoqun
*/
@Override
public void bindView(View view, Context context, Cursor cursor) {
//若view是NotesListItem的一个实例
if (view instanceof NotesListItem) {
//则新建一个项目选项并且用bind跟将view和鼠标内容便签数据捆绑在一起
NoteItemData itemData = new NoteItemData(context, cursor);
((NotesListItem) view).bind(context, itemData, mChoiceMode,
isSelectedItem(cursor.getPosition()));
}
}
/**
* @description :
* @param 1:position
* @param 2:checked
* @param 3:
* @return :void
* @author zhangchaoqun
*/
public void setCheckedItem(final int position, final boolean checked) {
//根据定位和是否勾选设置下标
mSelectedIndex.put(position, checked);
//在修改后刷新activity
notifyDataSetChanged();
}
/**
* @description :
* @param 1:
* @param 2:
* @param 3:
* @return :bool
* @author zhangchaoqun
*/
public boolean isInChoiceMode() {
return mChoiceMode;
}
/**
* @description :mode
* @param 1:mode
* @param 2:
* @param 3:
* @return :void
* @author zhangchaoqun
*/
public void setChoiceMode(boolean mode) {
mSelectedIndex.clear();
mChoiceMode = mode;
}
/**
* @description :
* @param 1:checked
* @param 2:
* @param 3:
* @return :void
* @author zhangchaoqun
*/
public void selectAll(boolean checked) {
//获取光标位置
Cursor cursor = getCursor();
//遍历所有光标可用的位置在判断为便签类型之后勾选单项框
for (int i = 0; i < getCount(); i++) {
if (cursor.moveToPosition(i)) {
if (NoteItemData.getNoteType(cursor) == Notes.TYPE_NOTE) {
setCheckedItem(i, checked);
}
}
}
}
/**
* @description :
* @param 1:
* @param 2:
* @param 3:
* @return :HashSet
* @author zhangchaoqun
*/
public HashSet<Long> getSelectedItemIds() {
//建立hash表
HashSet<Long> itemSet = new HashSet<Long>();
//遍历所有的关键
for (Integer position : mSelectedIndex.keySet()) {
//若光标位置可用
if (mSelectedIndex.get(position) == true) {
Long id = getItemId(position);
//原文件不需要添加
if (id == Notes.ID_ROOT_FOLDER) {
Log.d(TAG, "Wrong item id, should not happen");
}
//否则将id该下标加入选项集合中
else {
itemSet.add(id);
}
}
}
return itemSet;
}
/**
* @description :Widget
* @param 1:
* @param 2:
* @param 3:
* @return :HashSetwidget
* @author zhangchaoqun
*/
public HashSet<AppWidgetAttribute> getSelectedWidget() {
HashSet<AppWidgetAttribute> itemSet = new HashSet<AppWidgetAttribute>();
for (Integer position : mSelectedIndex.keySet()) {
if (mSelectedIndex.get(position) == true) {
Cursor c = (Cursor) getItem(position);
//光标位置可用的话就建立新的Widget属性并编辑下标和类型最后添加到选项集中
if (c != null) {
AppWidgetAttribute widget = new AppWidgetAttribute();
NoteItemData item = new NoteItemData(mContext, c);
widget.widgetId = item.getWidgetId();
widget.widgetType = item.getWidgetType();
itemSet.add(widget);
/**
* Don't close cursor here, only the adapter could close it
*/
} else {
Log.e(TAG, "Invalid cursor");
return null;
}
}
}
return itemSet;
}
/**
* @description :
* @param 1:
* @param 2:
* @param 3:
* @return :int
* @author zhangchaoqun
*/
public int getSelectedCount() {
//首先获取选项下标的值
Collection<Boolean> values = mSelectedIndex.values();
if (null == values) {
return 0;
}
//初始化叠加器
Iterator<Boolean> iter = values.iterator();
int count = 0;
while (iter.hasNext()) {
//若value值为真计数则+1
if (true == iter.next()) {
count++;
}
}
return count;
}
/**
* @description :
* @param 1:
* @param 2:
* @param 3:
* @return :boolean
* @author zhangchaoqun
*/
public boolean isAllSelected() {
//获取选项数看是否等于便签的个数
int checkedCount = getSelectedCount();
return (checkedCount != 0 && checkedCount == mNotesCount);
}
/**
* @description :
* @param 1:position
* @param 2:
* @param 3:
* @return :bool
* @author zhangchaoqun
*/
public boolean isSelectedItem(final int position) {
if (null == mSelectedIndex.get(position)) {
return false;
}
return mSelectedIndex.get(position);
}
/**
* @description :activity便
* @param 1:
* @param 2:
* @param 3:
* @return :void
* @author zhangchaoqun
*/
@Override
protected void onContentChanged() {
super.onContentChanged();
calcNotesCount();
}
/**
* @description :activity便
* @param 1:cursor
* @param 2:
* @param 3:
* @return :void
* @author zhangchaoqun
*/
@Override
public void changeCursor(Cursor cursor) {
super.changeCursor(cursor);
calcNotesCount();
}
/**
* @description :便
* @param 1:
* @param 2:
* @param 3:
* @return :void
* @author zhangchaoqun
*/
private void calcNotesCount() {
mNotesCount = 0;
//获取总数同时遍历
for (int i = 0; i < getCount(); i++) {
Cursor c = (Cursor) getItem(i);
//若该位置不为空并且文本类型为便签就+1
if (c != null) {
if (NoteItemData.getNoteType(c) == Notes.TYPE_NOTE) {
mNotesCount++;
}
}
//否则报错
else {
Log.e(TAG, "Invalid cursor");
return;
}
}
}
}
Loading…
Cancel
Save