@Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { if (mOnListItemSelectedListener != null) { final BaseExpandableListAdapter adapter = getAdapter(); if (adapter == null) { return false; } Object data = adapter.getChild(groupPosition, childPosition); mOnListItemSelectedListener.onListItemSelected(data); return true; } return false; }
@Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { if (mOnListItemSelectedListener != null) { final BaseExpandableListAdapter adapter = getAdapter(); if (adapter == null) { return false; } Object group = adapter.getGroup(groupPosition); mOnListItemSelectedListener.onListGroupSelected(group); return true; } return false; }
@Override public void setAdapter(ExpandableListAdapter adapter) { super.setAdapter(adapter); mAdapter = adapter; mHeaderView = adapter.getGroupView(0, false, null, this); boolean isBaseAdapter = adapter instanceof BaseExpandableListAdapter; if (cacheHeaderViews == null) { if (isBaseAdapter) { int typeCount = ((BaseExpandableListAdapter) adapter).getGroupTypeCount(); cacheHeaderViews = new SparseArray<>(typeCount); } cacheHeaderViews = new SparseArray<>(1); } if (mHeaderView != null) { int groupType = 0; if (isBaseAdapter) { groupType = ((BaseExpandableListAdapter) adapter).getGroupType(0); cacheHeaderViews.put(groupType, mHeaderView); } cacheHeaderViews.put(groupType, mHeaderView); } }
@Override protected void updateUI() { if (!isAdded()) { return; } if (isErrorResponse()) { showErrorUI(); return; } if (hasTags()) { BaseExpandableListAdapter adapter = new MyExpandableListAdapter(getActivity(), getTags()); StatsUIHelper.reloadGroupViews(getActivity(), adapter, mGroupIdToExpandedMap, mList, getMaxNumberOfItemsToShowInList()); showHideNoResultsUI(false); } else { showHideNoResultsUI(true); } }
@Override protected void updateUI() { if (!isAdded()) { return; } if (isErrorResponse()) { showErrorUI(); return; } if (!isDataEmpty() && ((ClicksModel) mDatamodels[0]).getClickGroups().size() > 0) { BaseExpandableListAdapter adapter = new MyExpandableListAdapter(getActivity(), ((ClicksModel) mDatamodels[0]).getClickGroups()); StatsUIHelper.reloadGroupViews(getActivity(), adapter, mGroupIdToExpandedMap, mList, getMaxNumberOfItemsToShowInList()); showHideNoResultsUI(false); } else { showHideNoResultsUI(true); } }
@Override protected void updateUI() { if (!isAdded()) { return; } if (isErrorResponse()) { showErrorUI(); return; } if (hasReferrers()) { BaseExpandableListAdapter adapter = new MyExpandableListAdapter(getActivity(), getReferrersGroups()); StatsUIHelper.reloadGroupViews(getActivity(), adapter, mGroupIdToExpandedMap, mList, getMaxNumberOfItemsToShowInList()); showHideNoResultsUI(false); } else { showHideNoResultsUI(true); } }
@Override protected void updateUI() { if (!isAdded()) { return; } if (isErrorResponse()) { showErrorUI(); return; } if (isDataEmpty()) { showHideNoResultsUI(true); return; } List<AuthorModel> authors = ((AuthorsModel) mDatamodels[0]).getAuthors(); if (authors == null || authors.size() == 0) { showHideNoResultsUI(true); return; } BaseExpandableListAdapter adapter = new MyExpandableListAdapter(getActivity(), authors); StatsUIHelper.reloadGroupViews(getActivity(), adapter, mGroupIdToExpandedMap, mList, getMaxNumberOfItemsToShowInList()); showHideNoResultsUI(false); }
private void parseVersion(ArrayList<BranchItem> data, JSONArray jsonArray) { data.clear(); int len = jsonArray.length(); for (int i = 0; i < len; ++i) { BranchItem item = new BranchItem(jsonArray.optJSONObject(i)); data.add(item); if (item.is_default_branch && (mVersion == null || mVersion.isEmpty())) { switchVersion(item.name); } } ((BaseExpandableListAdapter) versionAdapter).notifyDataSetChanged(); }
/** * 离线地图下载回调方法 */ @Override public void onDownload(int status, int completeCode, String downName) { switch (status) { case OfflineMapStatus.SUCCESS: changeOfflineMapTitle(OfflineMapStatus.SUCCESS); break; case OfflineMapStatus.LOADING: OfflineMapActivity.this.completeCode = completeCode; break; case OfflineMapStatus.UNZIP: OfflineMapActivity.this.completeCode = completeCode; changeOfflineMapTitle(OfflineMapStatus.UNZIP); break; case OfflineMapStatus.WAITING: break; case OfflineMapStatus.PAUSE: break; case OfflineMapStatus.STOP: break; case OfflineMapStatus.ERROR: break; default: break; } ((BaseExpandableListAdapter) adapter).notifyDataSetChanged(); }
@Override protected void bindData(BaseExpandableListAdapter adapter, ExpandableListData<Group, Item, MapKey> data) { if (adapter instanceof AbsArrayExpandableListAdapter == false) { return; } ((AbsArrayExpandableListAdapter)adapter).setData(data); adapter.notifyDataSetChanged(); }
@SuppressWarnings("unchecked") protected void bindAdapterView() { final View fragmentView = getView(); if (fragmentView == null) { return; } ExpandableListView oldAdapterView = mAdapterView; if (oldAdapterView != null) { oldAdapterView.clearDisappearingChildren(); oldAdapterView.clearAnimation(); oldAdapterView.setAdapter((BaseExpandableListAdapter)null); oldAdapterView.setOnChildClickListener(null); oldAdapterView.setOnGroupClickListener(null); oldAdapterView.setVisibility(View.GONE); oldAdapterView.setEmptyView(null); } mAdapter = onCreateAdapter(); mAdapterView = (ExpandableListView) fragmentView.findViewById( getAdapterViewId()); if (mAdapterView != null) { mAdapterView.setAdapter(mAdapter); mAdapterView.setOnChildClickListener(this); mAdapterView.setOnGroupClickListener(this); mAdapterView.setVisibility(View.VISIBLE); mAdapterView.scheduleLayoutAnimation(); final View emptyView = fragmentView.findViewById(getEmptyViewId()); if (emptyView != null) { mAdapterView.setEmptyView(emptyView); } } }
@Override public void run() { if (mAdapter instanceof BaseExpandableListAdapter == false) { return; } ((BaseExpandableListAdapter)mAdapter).notifyDataSetChanged(); }
@Override public int getRealChildType(int groupPosition, int childPosition) { if (mInnerAdapter instanceof BaseExpandableListAdapter) { BaseExpandableListAdapter baseAdapter = (BaseExpandableListAdapter) mInnerAdapter; return baseAdapter.getChildType(groupPosition, childPosition); } return 0; }
@Override public int getRealChildTypeCount() { if (mInnerAdapter instanceof BaseExpandableListAdapter) { BaseExpandableListAdapter baseAdapter = (BaseExpandableListAdapter) mInnerAdapter; return baseAdapter.getChildTypeCount(); } return 1; }
protected void refreshHeader() { if (mHeaderView == null) { return; } int firstVisiblePos = getFirstVisiblePosition(); int pos = firstVisiblePos + 1; int firstVisibleGroupPos = getPackedPositionGroup(getExpandableListPosition(firstVisiblePos)); int group = getPackedPositionGroup(getExpandableListPosition(pos)); int type = mAdapter instanceof BaseExpandableListAdapter ? ((BaseExpandableListAdapter) mAdapter).getGroupType(firstVisibleGroupPos) : 0; View convertView = cacheHeaderViews == null ? null : cacheHeaderViews.get(type); mHeaderView = mAdapter.getGroupView(firstVisibleGroupPos, false, convertView, this); if (group == firstVisibleGroupPos + 1) { View view = getChildAt(1); if (view == null) { return; } if (view.getTop() <= mHeaderHeight) { int delta = mHeaderHeight - view.getTop(); mHeaderView.layout(0, -delta, mHeaderWidth, mHeaderHeight - delta); } else { mHeaderView.layout(0, 0, mHeaderWidth, mHeaderHeight); } } else { mHeaderView.layout(0, 0, mHeaderWidth, mHeaderHeight); } if (mHeaderUpdateListener != null) { mHeaderUpdateListener.updatePinnedHeader(mHeaderView, firstVisibleGroupPos); } }
/** * Provides the visible child views. * The map key is the group position. * The map values are the visible child views. * * @param expandableListView the listview * @param adapter the linked adapter * @return visible views map */ public static HashMap<Integer, List<Integer>> getVisibleChildViews(ExpandableListView expandableListView, BaseExpandableListAdapter adapter) { HashMap<Integer, List<Integer>> map = new HashMap<>(); long firstPackedPosition = expandableListView.getExpandableListPosition(expandableListView.getFirstVisiblePosition()); int firstGroupPosition = ExpandableListView.getPackedPositionGroup(firstPackedPosition); int firstChildPosition = ExpandableListView.getPackedPositionChild(firstPackedPosition); long lastPackedPosition = expandableListView.getExpandableListPosition(expandableListView.getLastVisiblePosition()); int lastGroupPosition = ExpandableListView.getPackedPositionGroup(lastPackedPosition); int lastChildPosition = ExpandableListView.getPackedPositionChild(lastPackedPosition); for (int groupPos = firstGroupPosition; groupPos <= lastGroupPosition; groupPos++) { ArrayList<Integer> list = new ArrayList<>(); int startChildPos = (groupPos == firstGroupPosition) ? firstChildPosition : 0; int endChildPos = (groupPos == lastGroupPosition) ? lastChildPosition : adapter.getChildrenCount(groupPos) - 1; for (int index = startChildPos; index <= endChildPos; index++) { list.add(index); } map.put(groupPos, list); } return map; }
public MergeExpandableListAdapter(BaseExpandableListAdapter... adapters) { groupTyper = new ViewTyper(); childTyper = new ViewTyper(); for (BaseExpandableListAdapter adapter: adapters) { add(adapter); } }
@Override public int getGroupCount() { int sum = 0; for (BaseExpandableListAdapter adapter : adapters) { sum += adapter.getGroupCount(); } return sum; }
@Override public void populateView(View view, Cursor cursor, BaseExpandableListAdapter adapter, int flags) { int position = cursor.getPosition(); // set list title TextView title = (TextView) view.findViewById(android.R.id.title); if (title != null) { title.setText(getTitle(cursor, view.getContext())); } // set list elements TextView text2 = (TextView) view.findViewById(android.R.id.text2); int childrenCount = adapter.getChildrenCount(position); if (text2 != null && ((ExpandableGroupDescriptorAdapter) adapter).childCursorLoaded(position)) { Resources res = view.getContext().getResources(); text2.setText(res.getQuantityString(R.plurals.number_of_tasks, childrenCount, childrenCount)); } // show/hide divider View divider = view.findViewById(R.id.divider); if (divider != null) { divider.setVisibility((flags & FLAG_IS_EXPANDED) != 0 && childrenCount > 0 ? View.VISIBLE : View.GONE); } View colorbar = view.findViewById(R.id.colorbar1); if (colorbar != null) { colorbar.setVisibility(View.GONE); } }
public BaseExpandableListAdapter getAdapter() { return mAdapter; }
protected BaseExpandableListAdapter createAdapter() { return new ExpandableMyListAdapter(getActivity(), mData); }
private Position(BaseExpandableListAdapter adapter, int adapterPos, int group) { this.adapter = adapter; this.adapterPos = adapterPos; this.group = group; }
public void add(BaseExpandableListAdapter adapter) { groupTyper.addTypes(adapter.getGroupTypeCount()); childTyper.addTypes(adapter.getChildTypeCount()); adapter.registerDataSetObserver(observer); adapters.add(adapter); }
public HeadedExpandableListAdapter(BaseExpandableListAdapter mainAdapter, int headerLayout, int headerResText) { super(new HeaderAdapter(headerLayout, headerResText), mainAdapter); }
public AdapterWrapper(BaseExpandableListAdapter adapter) { this.adapter = adapter; }
@Override public void populateView(View view, Cursor cursor, BaseExpandableListAdapter adapter, int flags) { TextView title = (TextView) getView(view, android.R.id.title); boolean isClosed = cursor.getInt(13) > 0; resetFlingView(view); if (title != null) { String text = cursor.getString(5); title.setText(text); if (isClosed) { title.setPaintFlags(title.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); } else { title.setPaintFlags(title.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG); } } setDueDate((TextView) getView(view, R.id.task_due_date), null, INSTANCE_DUE_ADAPTER.get(cursor), isClosed); View divider = getView(view, R.id.divider); if (divider != null) { divider.setVisibility((flags & FLAG_IS_LAST_CHILD) != 0 ? View.GONE : View.VISIBLE); } // display priority int priority = TaskFieldAdapters.PRIORITY.get(cursor); View priorityView = getView(view, R.id.task_priority_view_medium); priorityView.setBackgroundResource(android.R.color.transparent); priorityView.setVisibility(View.VISIBLE); if (priority > 0 && priority < 5) { priorityView.setBackgroundResource(R.color.priority_red); } if (priority == 5) { priorityView.setBackgroundResource(R.color.priority_yellow); } if (priority > 5 && priority <= 9) { priorityView.setBackgroundResource(R.color.priority_green); } new ProgressBackgroundView(getView(view, R.id.percentage_background_view)) .update(new NullSafe<>(TaskFieldAdapters.PERCENT_COMPLETE.get(cursor))); setColorBar(view, cursor); setDescription(view, cursor); setOverlay(view, cursor.getPosition(), cursor.getCount()); }
@Override public void populateView(View view, Cursor cursor, BaseExpandableListAdapter adapter, int flags) { TextView title = getView(view, android.R.id.title); boolean isClosed = cursor.getInt(13) > 0; resetFlingView(view); if (title != null) { String text = cursor.getString(5); title.setText(text); if (isClosed) { title.setPaintFlags(title.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); } else { title.setPaintFlags(title.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG); } } setDueDate((TextView) getView(view, R.id.task_due_date), null, INSTANCE_DUE_ADAPTER.get(cursor), isClosed); View divider = getView(view, R.id.divider); if (divider != null) { divider.setVisibility((flags & FLAG_IS_LAST_CHILD) != 0 ? View.GONE : View.VISIBLE); } // display priority int priority = TaskFieldAdapters.PRIORITY.get(cursor); View priorityView = getView(view, R.id.task_priority_view_medium); priorityView.setBackgroundResource(android.R.color.transparent); priorityView.setVisibility(View.VISIBLE); if (priority > 0 && priority < 5) { priorityView.setBackgroundResource(R.color.priority_red); } if (priority == 5) { priorityView.setBackgroundResource(R.color.priority_yellow); } if (priority > 5 && priority <= 9) { priorityView.setBackgroundResource(R.color.priority_green); } new ProgressBackgroundView(getView(view, R.id.percentage_background_view)) .update(new NullSafe<>(TaskFieldAdapters.PERCENT_COMPLETE.get(cursor))); setColorBar(view, cursor); setDescription(view, cursor); setOverlay(view, cursor.getPosition(), cursor.getCount()); }
@Override public void populateView(View view, Cursor cursor, BaseExpandableListAdapter adapter, int flags) { int position = cursor.getPosition(); // set list title TextView title = (TextView) view.findViewById(android.R.id.title); if (title != null) { title.setText(getTitle(cursor, view.getContext())); } // set list elements TextView text2 = (TextView) view.findViewById(android.R.id.text2); int childrenCount = adapter.getChildrenCount(position); if (text2 != null && ((ExpandableGroupDescriptorAdapter) adapter).childCursorLoaded(position)) { Resources res = view.getContext().getResources(); text2.setText(res.getQuantityString(R.plurals.number_of_tasks, childrenCount, childrenCount)); } // show/hide divider View divider = view.findViewById(R.id.divider); if (divider != null) { divider.setVisibility((flags & FLAG_IS_EXPANDED) != 0 && childrenCount > 0 ? View.VISIBLE : View.GONE); } View colorbar1 = view.findViewById(R.id.colorbar1); View colorbar2 = view.findViewById(R.id.colorbar2); if ((flags & FLAG_IS_EXPANDED) != 0) { if (colorbar1 != null) { colorbar1.setBackgroundColor(cursor.getInt(2)); colorbar1.setVisibility(View.GONE); } if (colorbar2 != null) { colorbar2.setVisibility(View.GONE); } } else { if (colorbar1 != null) { colorbar1.setVisibility(View.GONE); } if (colorbar2 != null) { colorbar2.setBackgroundColor(cursor.getInt(2)); colorbar2.setVisibility(View.GONE); } } }
@SuppressLint("NewApi") @Override public void populateView(View view, Cursor cursor, BaseExpandableListAdapter adapter, int flags) { TextView title = getView(view, android.R.id.title); boolean isClosed = TaskFieldAdapters.IS_CLOSED.get(cursor); resetFlingView(view); if (title != null) { String text = TaskFieldAdapters.TITLE.get(cursor); // float score = TaskFieldAdapters.SCORE.get(cursor); title.setText(text); if (isClosed) { title.setPaintFlags(title.getPaintFlags() | Paint.STRIKE_THRU_TEXT_FLAG); } else { title.setPaintFlags(title.getPaintFlags() & ~Paint.STRIKE_THRU_TEXT_FLAG); } } setDueDate((TextView) getView(view, R.id.task_due_date), null, INSTANCE_DUE_ADAPTER.get(cursor), isClosed); View divider = getView(view, R.id.divider); if (divider != null) { divider.setVisibility((flags & FLAG_IS_LAST_CHILD) != 0 ? View.GONE : View.VISIBLE); } // display priority int priority = TaskFieldAdapters.PRIORITY.get(cursor); View priorityView = getView(view, R.id.task_priority_view_medium); priorityView.setBackgroundResource(android.R.color.transparent); priorityView.setVisibility(View.VISIBLE); if (priority > 0 && priority < 5) { priorityView.setBackgroundResource(R.color.priority_red); } if (priority == 5) { priorityView.setBackgroundResource(R.color.priority_yellow); } if (priority > 5 && priority <= 9) { priorityView.setBackgroundResource(R.color.priority_green); } new ProgressBackgroundView(getView(view, R.id.percentage_background_view)) .update(new NullSafe<>(TaskFieldAdapters.PERCENT_COMPLETE.get(cursor))); setColorBar(view, cursor); setDescription(view, cursor); setOverlay(view, cursor.getPosition(), cursor.getCount()); }
/** * Populate a view in an {@link ExpandableListView}. * * @param view * The {@link View} to populate. * @param cursor * A {@link Cursor} that points to the current data item. * @param adapter * The {@link BaseExpandableListAdapter}. * @param flags * Some flags that give additional information about the view. Any combination of {@link #FLAG_IS_EXPANDED} or {@link #FLAG_IS_LAST_CHILD}. */ public void populateView(View view, Cursor cursor, BaseExpandableListAdapter adapter, int flags);
abstract protected void bindData(BaseExpandableListAdapter adapter, ExpandableListData<Group, Item, MapKey> data);
abstract protected BaseExpandableListAdapter onCreateAdapter();