本文整理汇总了Java中com.mikepenz.fastadapter.FastAdapter类的典型用法代码示例。如果您正苦于以下问题:Java FastAdapter类的具体用法?Java FastAdapter怎么用?Java FastAdapter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FastAdapter类属于com.mikepenz.fastadapter包,在下文中一共展示了FastAdapter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: handleStates
import com.mikepenz.fastadapter.FastAdapter; //导入依赖的package包/类
/**
* internal method which correctly set the selected state and expandable state on the newly added items
*
* @param fastAdapter the fastAdapter which manages everything
* @param startPosition the position of the first item to handle
* @param endPosition the position of the last item to handle
*/
public static <Item extends IItem> void handleStates(FastAdapter<Item> fastAdapter, int startPosition, int endPosition) {
for (int i = endPosition; i >= startPosition; i--) {
Item updateItem = fastAdapter.getItem(i);
if (updateItem != null) {
if (updateItem.isSelected()) {
fastAdapter.getSelections().add(i);
} else if (fastAdapter.getSelections().contains(i)) {
fastAdapter.getSelections().remove(i);
}
if (updateItem instanceof IExpandable) {
if (((IExpandable) updateItem).isExpanded() && fastAdapter.getExpanded().indexOfKey(i) < 0) {
fastAdapter.expand(i);
}
}
}
}
}
示例2: notifyCommit
import com.mikepenz.fastadapter.FastAdapter; //导入依赖的package包/类
private void notifyCommit() {
if (mHistory != null) {
if (mHistory.action == ACTION_REMOVE) {
SortedSet<Integer> positions = new TreeSet<>(new Comparator<Integer>() {
@Override
public int compare(Integer lhs, Integer rhs) {
return lhs.compareTo(rhs);
}
});
for (FastAdapter.RelativeInfo<Item> relativeInfo : mHistory.items) {
positions.add(relativeInfo.position);
}
mUndoListener.commitRemove(positions, mHistory.items);
mHistory = null;
}
}
}
示例3: onCreateView
import com.mikepenz.fastadapter.FastAdapter; //导入依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
context = super.getActivity();
View ourView = inflater.inflate(R.layout.fragment_bookmarks, container, false);
noBookmarksLayout = (LinearLayout) ourView.findViewById(R.id.no_bookmarks_layout);
bookmarksList = (RecyclerView) ourView.findViewById(R.id.bookmarks_list);
fastAdapter = new FastAdapter();
itemFastAdapter = new ItemAdapter<>();
fastAdapter.withSelectOnLongClick(false);
fastAdapter.withSelectable(false);
fastAdapter.withOnLongClickListener(this);
bookmarksList.setLayoutManager(new LinearLayoutManager(context));
bookmarksList.setAdapter(itemFastAdapter.wrap(fastAdapter));
return ourView;
}
示例4: getAllItems
import com.mikepenz.fastadapter.FastAdapter; //导入依赖的package包/类
/**
* Gets all items (including sub items) from the FastAdapter
*
* @param fastAdapter the FastAdapter
* @return a list of all items including the whole subItem hirachy
*/
public static <Item extends IItem> List<Item> getAllItems(FastAdapter<Item> fastAdapter) {
int size = fastAdapter.getItemCount();
List<Item> items = new ArrayList<>(size);
for (int i = 0; i < size; i++) {
Item item = fastAdapter.getItem(i);
items.add(item);
addAllSubItems(item, items);
}
return items;
}
示例5: onClick
import com.mikepenz.fastadapter.FastAdapter; //导入依赖的package包/类
@Override
public void onClick(View v, int position, FastAdapter<ImageItem> fastAdapter, ImageItem item) {
item.withStarred(!item.mStarred);
//we animate the heart
item.animateHeart(((ViewGroup) v).getChildAt(0), ((ViewGroup) v).getChildAt(1), item.mStarred);
//we display the info about the click
Toast.makeText(v.getContext(), item.mImageUrl + " - " + item.mStarred, Toast.LENGTH_SHORT).show();
}
示例6: onClick
import com.mikepenz.fastadapter.FastAdapter; //导入依赖的package包/类
@Override
public void onClick(View v, int position, FastAdapter<RadioButtonSampleItem> fastAdapter, RadioButtonSampleItem item) {
if (!item.isSelected()) {
Set<Integer> selections = fastAdapter.getSelections();
if (!selections.isEmpty()) {
int selectedPosition = selections.iterator().next();
fastAdapter.deselect();
fastAdapter.notifyItemChanged(selectedPosition);
}
fastAdapter.select(position);
}
}
示例7: doChange
import com.mikepenz.fastadapter.FastAdapter; //导入依赖的package包/类
private void doChange() {
if (mHistory != null) {
if (mHistory.action == ACTION_REMOVE) {
for (int i = mHistory.items.size() - 1; i >= 0; i--) {
FastAdapter.RelativeInfo<Item> relativeInfo = mHistory.items.get(i);
if (relativeInfo.adapter instanceof IItemAdapter) {
((IItemAdapter) relativeInfo.adapter).remove(relativeInfo.position);
}
}
}
}
}
示例8: getSelectedItems
import com.mikepenz.fastadapter.FastAdapter; //导入依赖的package包/类
/**
* returns a set of selected items, regardless of their visibility
*
* @param adapter the adapter instance
* @return a set of all selected items and subitems
*/
public static Set<IItem> getSelectedItems(FastAdapter adapter) {
Set<IItem> selections = new HashSet<>();
int length = adapter.getItemCount();
List<IItem> items = new ArrayList<>();
for (int i = 0; i < length; i++) {
items.add(adapter.getItem(i));
}
updateSelectedItemsWithCollapsed(selections, items);
return selections;
}
示例9: selectAllSubItems
import com.mikepenz.fastadapter.FastAdapter; //导入依赖的package包/类
/**
* select or unselect all sub itmes underneath an expandable item
*
* @param adapter the adapter instance
* @param header the header who's children should be selected or deselected
* @param select the new selected state of the sub items
* @param notifyParent true, if the parent should be notified about the changes of its children selection state
* @param payload payload for the notifying function
*/
public static <T extends IItem & IExpandable> void selectAllSubItems(final FastAdapter adapter, T header, boolean select, boolean notifyParent, Object payload) {
int subItems = header.getSubItems().size();
int position = adapter.getPosition(header);
if (header.isExpanded()) {
for (int i = 0; i < subItems; i++) {
if (((IItem)header.getSubItems().get(i)).isSelectable()) {
if (select) {
adapter.select(position + i + 1);
} else {
adapter.deselect(position + i + 1);
}
}
if (header.getSubItems().get(i) instanceof IExpandable)
selectAllSubItems(adapter, header, select, notifyParent, payload);
}
} else {
for (int i = 0; i < subItems; i++) {
if (((IItem)header.getSubItems().get(i)).isSelectable()) {
((IItem) header.getSubItems().get(i)).withSetSelected(select);
}
if (header.getSubItems().get(i) instanceof IExpandable)
selectAllSubItems(adapter, header, select, notifyParent, payload);
}
}
// we must notify the view only!
if (notifyParent && position >= 0) {
adapter.notifyItemChanged(position, payload);
}
}
示例10: notifyItemsChanged
import com.mikepenz.fastadapter.FastAdapter; //导入依赖的package包/类
/**
* notifies items (incl. sub items if they are currently extended)
*
* @param adapter the adapter
* @param identifiers set of identifiers that should be notified
* @param restoreExpandedState true, if expanded headers should stay expanded
*/
public static <Item extends IItem & IExpandable> void notifyItemsChanged(final FastAdapter adapter, Set<Long> identifiers, boolean restoreExpandedState) {
int i;
IItem item;
for (i = 0; i < adapter.getItemCount(); i++) {
item = adapter.getItem(i);
if (item instanceof IExpandable) {
notifyItemsChanged(adapter, (Item) item, identifiers, true, restoreExpandedState);
} else if (identifiers.contains(item.getIdentifier())) {
adapter.notifyAdapterItemChanged(i);
}
}
}
示例11: onEventOccurred
import com.mikepenz.fastadapter.FastAdapter; //导入依赖的package包/类
protected final void onEventOccurred(View view, RecyclerView.ViewHolder viewHolder, FastAdapter<T> fastAdapter)
{
//we get the adapterPosition from the viewHolder
int pos = fastAdapter.getHolderAdapterPosition(viewHolder);
//make sure the click was done on a valid item
if (pos != RecyclerView.NO_POSITION) {
//we update our item with the changed property
onEvent(view, pos, fastAdapter, fastAdapter.getItem(pos), viewHolder);
}
}
示例12: createRecyclerView
import com.mikepenz.fastadapter.FastAdapter; //导入依赖的package包/类
private RecyclerView createRecyclerView(FastAdapter adapter, int gravity, int paddingHorizontal) {
RecyclerView actionRecyclerView = new RecyclerView(getContext());
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(getContext(), LinearLayoutManager.HORIZONTAL, false);
actionRecyclerView.setClipToPadding(false);
actionRecyclerView.setPadding(paddingHorizontal, 0, paddingHorizontal, 0);
actionRecyclerView.setLayoutManager(linearLayoutManager);
actionRecyclerView.setAdapter(adapter);
actionRecyclerView.setOverScrollMode(OVER_SCROLL_ALWAYS);
LayoutParams actionRecyclerViewLP = new LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
actionRecyclerViewLP.gravity = gravity;
addView(actionRecyclerView, actionRecyclerViewLP);
return actionRecyclerView;
}
示例13: getAdapter
import com.mikepenz.fastadapter.FastAdapter; //导入依赖的package包/类
/**
* get the adapter (null safe)
*
* @return the FastAdapter used with this drawer
*/
protected FastAdapter<IDrawerItem> getAdapter() {
if (mAdapter == null) {
mAdapter = new FastAdapter<>();
mAdapter.withSelectable(true);
mAdapter.withAllowDeselection(false);
mAdapter.setHasStableIds(mHasStableIds);
mAdapter.withPositionBasedStateManagement(mPositionBasedStateManagement);
//we wrap our main Adapter with the item hosting adapter
mHeaderAdapter.wrap(mItemAdapter.wrap(mFooterAdapter.wrap(mAdapter)));
}
return mAdapter;
}
示例14: bindView
import com.mikepenz.fastadapter.FastAdapter; //导入依赖的package包/类
@Override
public void bindView(ViewHolder viewHolder, List payloads) {
super.bindView(viewHolder, payloads);
viewHolder.tag.setImageTintList(ColorStateList.valueOf(palette.getPrimary()));
withOnItemClickListener(new FastAdapter.OnClickListener<TagItem>() {
@Override
public boolean onClick(View v, IAdapter<TagItem> adapter, TagItem item, int position) {
App.BUS.post(new TagClicked(palette.getName()));
return true;
}
});
}
示例15: bindView
import com.mikepenz.fastadapter.FastAdapter; //导入依赖的package包/类
@Override
public void bindView(ViewHolder viewHolder, List payloads) {
super.bindView(viewHolder, payloads);
viewHolder.title.setText(getAbout().getTitle());
withOnItemClickListener(new FastAdapter.OnClickListener<AboutItem>() {
@Override
public boolean onClick(View v, IAdapter<AboutItem> adapter, AboutItem item, int position) {
App.BUS.post(new AboutUrlClicked(getAbout()));
return true;
}
});
}