Java Code Examples for android.widget.ExpandableListView#getPackedPositionGroup()

The following examples show how to use android.widget.ExpandableListView#getPackedPositionGroup() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
	super.onLayout(changed, l, t, r, b);
	final long flatPostion = getExpandableListPosition(getFirstVisiblePosition());
	final int groupPos = ExpandableListView
			.getPackedPositionGroup(flatPostion);
	final int childPos = ExpandableListView
			.getPackedPositionChild(flatPostion);
	int state = mAdapter.getPinnedHeaderState(groupPos, childPos);
	
	if (mHeaderView != null && mAdapter != null && state != mOldState) {
		mOldState = state;
		mHeaderView.layout(0, 0, mHeaderViewWidth, mHeaderViewHeight);
	}

	configureHeaderView(groupPos, childPos);
}
 
Example 2
Source Project: delion   File: RecentTabsPage.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    // Would prefer to have this context menu view managed internal to RecentTabsGroupView
    // Unfortunately, setting either onCreateContextMenuListener or onLongClickListener
    // disables the native onClick (expand/collapse) behaviour of the group view.
    ExpandableListView.ExpandableListContextMenuInfo info =
            (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;

    int type = ExpandableListView.getPackedPositionType(info.packedPosition);
    int groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition);

    if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
        mAdapter.getGroup(groupPosition).onCreateContextMenuForGroup(menu, mActivity);
    } else if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
        int childPosition = ExpandableListView.getPackedPositionChild(info.packedPosition);
        mAdapter.getGroup(groupPosition).onCreateContextMenuForChild(childPosition, menu,
                mActivity);
    }
}
 
Example 3
Source Project: AndroidChromium   File: RecentTabsPage.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    // Would prefer to have this context menu view managed internal to RecentTabsGroupView
    // Unfortunately, setting either onCreateContextMenuListener or onLongClickListener
    // disables the native onClick (expand/collapse) behaviour of the group view.
    ExpandableListView.ExpandableListContextMenuInfo info =
            (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;

    int type = ExpandableListView.getPackedPositionType(info.packedPosition);
    int groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition);

    if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
        mAdapter.getGroup(groupPosition).onCreateContextMenuForGroup(menu, mActivity);
    } else if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
        int childPosition = ExpandableListView.getPackedPositionChild(info.packedPosition);
        mAdapter.getGroup(groupPosition).onCreateContextMenuForChild(childPosition, menu,
                mActivity);
    }
}
 
Example 4
/**
 * 点击 HeaderView 触发的事件
 */
private void headerViewClick() {
	long packedPosition = getExpandableListPosition(this
			.getFirstVisiblePosition());

	int groupPosition = ExpandableListView
			.getPackedPositionGroup(packedPosition);

	if (mAdapter.getHeadViewClickStatus(groupPosition) == 1) {
		this.collapseGroup(groupPosition);
		mAdapter.onHeadViewClick(groupPosition, 0);
	} else {
		this.expandGroup(groupPosition);
		mAdapter.onHeadViewClick(groupPosition, 1);
	}

	this.setSelectedGroup(groupPosition);
}
 
Example 5
@Override
protected void onLayout(boolean changed, int left, int top, int right,
		int bottom) {
	super.onLayout(changed, left, top, right, bottom);
	final long flatPostion = getExpandableListPosition(getFirstVisiblePosition());
	final int groupPos = ExpandableListView
			.getPackedPositionGroup(flatPostion);
	final int childPos = ExpandableListView
			.getPackedPositionChild(flatPostion);
	int state = mAdapter.getTreeHeaderState(groupPos, childPos);
	if (mHeaderView != null && mAdapter != null && state != mOldState) {
		mOldState = state;
		mHeaderView.layout(0, 0, mHeaderViewWidth, mHeaderViewHeight);
	}

	configureHeaderView(groupPos, childPos);
}
 
Example 6
static ExpandableListPosition obtainPosition(long packedPosition) {
  if (packedPosition == ExpandableListView.PACKED_POSITION_VALUE_NULL) {
    return null;
  }

  ExpandableListPosition elp = getRecycledOrCreate();
  elp.groupPos = ExpandableListView.getPackedPositionGroup(packedPosition);
  if (ExpandableListView.getPackedPositionType(packedPosition) ==
      ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
    elp.type = CHILD;
    elp.childPos = ExpandableListView.getPackedPositionChild(packedPosition);
  } else {
    elp.type = GROUP;
  }
  return elp;
}
 
Example 7
Source Project: 365browser   File: RecentTabsPage.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    // Would prefer to have this context menu view managed internal to RecentTabsGroupView
    // Unfortunately, setting either onCreateContextMenuListener or onLongClickListener
    // disables the native onClick (expand/collapse) behaviour of the group view.
    ExpandableListView.ExpandableListContextMenuInfo info =
            (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;

    int type = ExpandableListView.getPackedPositionType(info.packedPosition);
    int groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition);

    if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
        mAdapter.getGroup(groupPosition).onCreateContextMenuForGroup(menu, mActivity);
    } else if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
        int childPosition = ExpandableListView.getPackedPositionChild(info.packedPosition);
        mAdapter.getGroup(groupPosition).onCreateContextMenuForChild(childPosition, menu,
                mActivity);
    }
}
 
Example 8
@Override
public boolean onContextItemSelected(MenuItem menuItem) {
	MyLog.entry("menuItem = " + menuItem);

	final ExpandableListView.ExpandableListContextMenuInfo listItem = (ExpandableListView.ExpandableListContextMenuInfo) menuItem.getMenuInfo();
	final int groupPosition = ExpandableListView.getPackedPositionGroup(listItem.packedPosition);

	//final MonsterInfoModel monsterInfo = getGroupMonsterItem(menuItem.getMenuInfo());

	switch (menuItem.getItemId()) {
		case MENU_ID_SELECT_ALL:
			mAdapter.flagAllChildren(groupPosition, true);
			break;
		case MENU_ID_DESELECT_ALL:
			mAdapter.flagAllChildren(groupPosition, false);
			break;
		default:
	}

	MyLog.exit();
	return true;
}
 
Example 9
@SuppressWarnings("unchecked")
private List<ChooseModelContainer<SyncedMonsterModel>> getGroupChildMonsterItems(ContextMenu.ContextMenuInfo menuInfo) {
	MyLog.entry("menuInfo = " + menuInfo);

	final ExpandableListView.ExpandableListContextMenuInfo listItem = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
	final int groupPosition = ExpandableListView.getPackedPositionGroup(listItem.packedPosition);

	final List<ChooseModelContainer<SyncedMonsterModel>> monsterItems = new ArrayList<ChooseModelContainer<SyncedMonsterModel>>();
	final int childCount = adapter.getChildrenCount(groupPosition);

	for (int i = 0; i < childCount; i++) {
		final ChooseModelContainer<SyncedMonsterModel> monsterItem = adapter.getChild(groupPosition, i);
		monsterItems.add(monsterItem);
	}

	MyLog.exit();
	return monsterItems;
}
 
Example 10
Source Project: TreeView   File: TreeView.java    License: Apache License 2.0 6 votes vote down vote up
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);

    final long listPosition = getExpandableListPosition(getFirstVisiblePosition());
    final int groupPos = ExpandableListView.getPackedPositionGroup(listPosition);
    final int childPos = ExpandableListView.getPackedPositionChild(listPosition);

    int state = mUpdater.getHeaderState(groupPos, childPos);
    if (mHeaderView != null && mUpdater != null && state != mOldState) {
        mOldState = state;
        mHeaderView.layout(0, 0, mHeaderWidth, mHeaderHeight);
    }

    updateHeaderView(groupPos, childPos);
}
 
Example 11
Source Project: Dainty   File: HistoryListView.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressLint("ClickableViewAccessibility")
@Override
public boolean onTouchEvent(MotionEvent ev) {
    if (mDockingHeaderVisible) {
        Rect rect = new Rect();
        mDockingHeader.getDrawingRect(rect);

        switch (ev.getAction()) {
            case MotionEvent.ACTION_DOWN:
                if (rect.contains((int)ev.getX(), (int)ev.getY())) {
                    // 阻止事件被list view的item消费
                    return true;
                }
                break;
            case MotionEvent.ACTION_UP:
                long flatPosition = getExpandableListPosition(getFirstVisiblePosition());
                int groupPos = ExpandableListView.getPackedPositionGroup(flatPosition);
                if (rect.contains((int)ev.getX(), (int)ev.getY()) &&
                        mDockingHeaderState == IDockingController.DOCKING_HEADER_DOCKED) {
                    // handle header view click event (do group expansion & collapse)
                    if (isGroupExpanded(groupPos)) {
                        collapseGroup(groupPos);
                    } else {
                        expandGroup(groupPos);
                    }
                    return true;
                }
                break;
        }
    }

    return super.onTouchEvent(ev);
}
 
Example 12
Source Project: FireFiles   File: RootsFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    int itemType = ExpandableListView.getPackedPositionType(id);
    int childPosition;
    int groupPosition;

    if ( itemType == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
        childPosition = ExpandableListView.getPackedPositionChild(id);
        groupPosition = ExpandableListView.getPackedPositionGroup(id);
        final Item item = (Item) mAdapter.getChild(groupPosition, childPosition);
        if (item instanceof AppItem) {
            showAppDetails(((AppItem) item).info);
            return true;
        } else if (item instanceof BookmarkItem) {
            removeBookark((BookmarkItem)item);
            return true;
        }  else {
            return false;
        }

    } else if(itemType == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
        groupPosition = ExpandableListView.getPackedPositionGroup(id);
        return false;

    } else {
        return false;
    }
}
 
Example 13
Source Project: FireFiles   File: RootsFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
    int itemType = ExpandableListView.getPackedPositionType(id);
    int childPosition;
    int groupPosition;

    if ( itemType == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
        childPosition = ExpandableListView.getPackedPositionChild(id);
        groupPosition = ExpandableListView.getPackedPositionGroup(id);
        final Item item = (Item) mAdapter.getChild(groupPosition, childPosition);
        if (item instanceof AppItem) {
            showAppDetails(((AppItem) item).info);
            return true;
        } else if (item instanceof BookmarkItem) {
            removeBookark((BookmarkItem)item);
            return true;
        }  else {
            return false;
        }

    } else if(itemType == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
        groupPosition = ExpandableListView.getPackedPositionGroup(id);
        return false;

    } else {
        return false;
    }
}
 
Example 14
@Override
public void onScroll(AbsListView view, int firstVisibleItem,
		int visibleItemCount, int totalItemCount) {
	final long flatPos = getExpandableListPosition(firstVisibleItem);
	int groupPosition = ExpandableListView.getPackedPositionGroup(flatPos);
	int childPosition = ExpandableListView.getPackedPositionChild(flatPos);

	configureHeaderView(groupPosition, childPosition);
}
 
Example 15
Source Project: TreeView   File: TreeView.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount,
                     int totalItemCount) {
    final long listPosition = getExpandableListPosition(firstVisibleItem);
    int groupPos = ExpandableListView.getPackedPositionGroup(listPosition);
    int childPos = ExpandableListView.getPackedPositionChild(listPosition);

    updateHeaderView(groupPos, childPos);
}
 
Example 16
private MonsterInfoModel getGroupMonsterItem(ContextMenu.ContextMenuInfo menuInfo) {
	MyLog.entry("menuInfo = " + menuInfo);

	final ExpandableListView.ExpandableListContextMenuInfo listItem = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
	final int groupPosition = ExpandableListView.getPackedPositionGroup(listItem.packedPosition);
	final MonsterInfoModel result = adapter.getGroup(groupPosition);

	MyLog.exit();
	return result;
}
 
Example 17
@SuppressWarnings("unchecked")
private ChooseModelContainer<SyncedMonsterModel> getChildMonsterItem(ContextMenu.ContextMenuInfo menuInfo) {
	MyLog.entry("menuInfo = " + menuInfo);

	final ExpandableListView.ExpandableListContextMenuInfo listItem = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
	int groupPosition = ExpandableListView.getPackedPositionGroup(listItem.packedPosition);
	int childPosition = ExpandableListView.getPackedPositionChild(listItem.packedPosition);
	final ChooseModelContainer result = adapter.getChild(groupPosition, childPosition);

	MyLog.exit();
	return result;
}
 
Example 18
@Override
public boolean onSingleTapUp(MotionEvent e) {
	int pos = itemListHandler.getListView().pointToPosition((int) e.getX(), (int) e.getY());
	if (pos < 0) { return true; }
	long expPos = itemListHandler.getListView().getExpandableListPosition(pos);
	int groupPos = ExpandableListView.getPackedPositionGroup(expPos);
	int childPos = ExpandableListView.getPackedPositionChild(expPos);
	if (childPos >= 0) {
		itemListHandler.onItemClicked(groupPos, childPos);
	}
	else {
		itemListHandler.onGroupClicked(groupPos);
	}
	return true;
}
 
Example 19
public int getLastVisibleGroup() {
    int lastVis = getLastVisiblePosition();
    long packedPosition = getExpandableListPosition(lastVis);
    return ExpandableListView.getPackedPositionGroup(packedPosition);
}
 
Example 20
Source Project: sa-sdk-android   File: ViewUtil.java    License: Apache License 2.0 4 votes vote down vote up
public static ViewNode getViewNode(View view, int viewIndex) {
    int viewPosition = getViewPosition(view, viewIndex);
    ViewParent parentObject = view.getParent();
    if (parentObject == null) {
        return null;
    }
    if (!WindowHelper.isDecorView(view.getClass()) || (parentObject instanceof View)) {
        if (parentObject instanceof View) {
            View parentView = (View) parentObject;
            StringBuilder opx = new StringBuilder();
            StringBuilder px = new StringBuilder();
            String viewName = ViewUtil.getCanonicalName(view.getClass());
            Object fragment = null;
            String listPos = null;
            // 处理嵌套场景,如果父 View 是列表类型控件,将父 View 的列表位置传递给非列表类型子控件; 列表类型子控件则直接用自身位置。
            ViewParent parent = parentView.getParent();
            if (parent instanceof View) {
                View listParentView = (View) parent;
                if (sViewCache == null) {
                    sViewCache = new SparseArray<String>();
                }
                String parentPos = (String) sViewCache.get(listParentView.hashCode());
                if (!TextUtils.isEmpty(parentPos)) {
                    listPos = parentPos;
                }
            }
            if (parentView instanceof ExpandableListView) {
                ExpandableListView listParent = (ExpandableListView) parentView;
                long elp = listParent.getExpandableListPosition(viewPosition);
                if (ExpandableListView.getPackedPositionType(elp) != 2) {
                    int groupIdx = ExpandableListView.getPackedPositionGroup(elp);
                    int childIdx = ExpandableListView.getPackedPositionChild(elp);
                    if (childIdx != -1) {
                        listPos = String.format(Locale.CHINA, "%d:%d", groupIdx, childIdx);
                        px.append(opx).append("/ELVG[").append(groupIdx).append("]/ELVC[-]/").append(viewName).append("[0]");
                        opx.append("/ELVG[").append(groupIdx).append("]/ELVC[").append(childIdx).append("]/").append(viewName).append("[0]");
                    } else {
                        listPos = String.format(Locale.CHINA, "%d", groupIdx);
                        px.append(opx).append("/ELVG[-]/").append(viewName).append("[0]");
                        opx.append("/ELVG[").append(groupIdx).append("]/").append(viewName).append("[0]");
                    }
                } else if (viewPosition < listParent.getHeaderViewsCount()) {
                    opx.append("/ELH[").append(viewPosition).append("]/").append(viewName).append("[0]");
                    px.append("/ELH[").append(viewPosition).append("]/").append(viewName).append("[0]");
                } else {
                    int footerIndex = viewPosition - (listParent.getCount() - listParent.getFooterViewsCount());
                    opx.append("/ELF[").append(footerIndex).append("]/").append(viewName).append("[0]");
                    px.append("/ELF[").append(footerIndex).append("]/").append(viewName).append("[0]");
                }
            } else if (ViewUtil.isListView(parentView)) {
                listPos = String.format(Locale.CHINA, "%d", viewPosition);
                px.append(opx).append("/").append(viewName).append("[-]");
                opx.append("/").append(viewName).append("[").append(listPos).append("]");
            } else if (ViewUtil.instanceOfSupportSwipeRefreshLayout(parentView)) {
                opx.append("/").append(viewName).append("[0]");
                px.append("/").append(viewName).append("[0]");
            } else if ((fragment = ViewUtil.instanceOfFragmentRootView(parentView, view)) != null) {
                viewName = ViewUtil.getCanonicalName(fragment.getClass());
                opx.append("/").append(viewName).append("[0]");
                px.append("/").append(viewName).append("[0]");
            } else {
                viewPosition = VisualUtil.getChildIndex(parentObject, view);
                opx.append("/").append(viewName).append("[").append(viewPosition).append("]");
                px.append("/").append(viewName).append("[").append(viewPosition).append("]");
            }
            if (WindowHelper.isDecorView(parentView.getClass())) {
                if (opx.length() > 0) {
                    opx.deleteCharAt(0);
                }
                if (px.length() > 0) {
                    px.deleteCharAt(0);
                }
            }
            if (!TextUtils.isEmpty(listPos)) {
                if (sViewCache == null) {
                    sViewCache = new SparseArray<String>();
                }
                sViewCache.put(parentView.hashCode(), listPos);
            }
            ViewNode viewNode = getViewContentAndType(view);
            return new ViewNode(listPos, opx.toString(), px.toString(), viewNode.getViewContent(), viewNode.getViewType());
        }
    }
    return null;
}