List of usage examples for android.widget ExpandableListView getPackedPositionChild
public static int getPackedPositionChild(long packedPosition)
From source file:com.granita.tasks.TaskListFragment.java
@Override public void onFlingStart(ListView listView, View listElement, int position, int direction) { // control the visibility of the views that reveal behind a flinging element regarding the fling direction int rightFlingViewId = mGroupDescriptor.getElementViewDescriptor().getFlingRevealRightViewId(); int leftFlingViewId = mGroupDescriptor.getElementViewDescriptor().getFlingRevealLeftViewId(); TextView rightFlingView = null;//from w w w . j a v a 2 s .c o m TextView leftFlingView = null; if (rightFlingViewId != -1) { rightFlingView = (TextView) listElement.findViewById(rightFlingViewId); } if (leftFlingViewId != -1) { leftFlingView = (TextView) listElement.findViewById(leftFlingViewId); } Resources resources = getActivity().getResources(); // change title and icon regarding the task status long packedPos = mExpandableListView.getExpandableListPosition(position); if (ExpandableListView.getPackedPositionType(packedPos) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { ExpandableListAdapter listAdapter = mExpandableListView.getExpandableListAdapter(); Cursor cursor = (Cursor) listAdapter.getChild(ExpandableListView.getPackedPositionGroup(packedPos), ExpandableListView.getPackedPositionChild(packedPos)); if (cursor != null) { int taskStatus = cursor.getInt(cursor.getColumnIndex(Instances.STATUS)); if (leftFlingView != null && rightFlingView != null) { if (taskStatus == Instances.STATUS_COMPLETED) { leftFlingView.setText(R.string.fling_task_delete); leftFlingView.setCompoundDrawablesWithIntrinsicBounds( resources.getDrawable(R.drawable.content_discard), null, null, null); rightFlingView.setText(R.string.fling_task_uncomplete); rightFlingView.setCompoundDrawablesWithIntrinsicBounds(null, null, resources.getDrawable(R.drawable.content_remove_light), null); } else { leftFlingView.setText(R.string.fling_task_complete); leftFlingView.setCompoundDrawablesWithIntrinsicBounds( resources.getDrawable(R.drawable.ic_action_complete), null, null, null); rightFlingView.setText(R.string.fling_task_edit); rightFlingView.setCompoundDrawablesWithIntrinsicBounds(null, null, resources.getDrawable(R.drawable.content_edit), null); } } } } if (rightFlingView != null) { rightFlingView.setVisibility(direction != FlingDetector.LEFT_FLING ? View.GONE : View.VISIBLE); } if (leftFlingView != null) { leftFlingView.setVisibility(direction != FlingDetector.RIGHT_FLING ? View.GONE : View.VISIBLE); } }
From source file:com.googlecode.networklog.AppFragment.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo; int type = ExpandableListView.getPackedPositionType(info.packedPosition); int group = ExpandableListView.getPackedPositionGroup(info.packedPosition); int child = ExpandableListView.getPackedPositionChild(info.packedPosition); MenuInflater inflater = getActivity().getMenuInflater(); inflater.inflate(R.layout.app_context_menu, menu); if (type != ExpandableListView.PACKED_POSITION_TYPE_CHILD) { menu.findItem(R.id.app_copy_ip).setVisible(false); menu.findItem(R.id.app_whois_ip).setVisible(false); }/*from w w w. ja v a2s .com*/ GroupItem groupItem = (GroupItem) adapter.getGroup(group); if (NetworkLogService.toastBlockedApps.get(groupItem.app.packageName) != null) { menu.findItem(R.id.app_toggle_app_notifications).setTitle(R.string.enable_notifications); } else { menu.findItem(R.id.app_toggle_app_notifications).setTitle(R.string.disable_notifications); } if (NetworkLogService.blockedApps.get(groupItem.app.packageName) != null) { menu.findItem(R.id.app_toggle_app_logging).setTitle(R.string.unblock_app); } else { menu.findItem(R.id.app_toggle_app_logging).setTitle(R.string.block_app); } }
From source file:com.granita.tasks.TaskListFragment.java
@Override public boolean onFlingEnd(ListView v, View listElement, int pos, int direction) { long packedPos = mExpandableListView.getExpandableListPosition(pos); if (ExpandableListView.getPackedPositionType(packedPos) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { ExpandableListAdapter listAdapter = mExpandableListView.getExpandableListAdapter(); Cursor cursor = (Cursor) listAdapter.getChild(ExpandableListView.getPackedPositionGroup(packedPos), ExpandableListView.getPackedPositionChild(packedPos)); if (cursor != null) { // TODO: for now we get the id of the task, not the instance, once we support recurrence we'll have to change that Long taskId = cursor.getLong(cursor.getColumnIndex(Instances.TASK_ID)); if (taskId != null) { boolean closed = cursor.getLong(cursor.getColumnIndex(Instances.IS_CLOSED)) > 0; String title = cursor.getString(cursor.getColumnIndex(Instances.TITLE)); // TODO: use the instance URI once we support recurrence Uri taskUri = ContentUris.withAppendedId(Tasks.getContentUri(mAuthority), taskId); if (direction == FlingDetector.RIGHT_FLING) { if (closed) { removeTask(taskUri, title); // we do not know for sure if the task has been removed since the user is asked for confirmation first, so return false return false; } else { return setCompleteTask(taskUri, title, true); }/*from w w w . j a va 2s .c o m*/ } else if (direction == FlingDetector.LEFT_FLING) { if (closed) { return setCompleteTask(taskUri, title, false); } else { openTaskEditor(taskUri, cursor.getString(cursor.getColumnIndex(Instances.ACCOUNT_TYPE))); return false; } } } } } return false; }
From source file:com.googlecode.networklog.AppFragment.java
@Override public boolean onContextItemSelected(MenuItem item) { if (!(item.getMenuInfo() instanceof ExpandableListContextMenuInfo)) return super.onContextItemSelected(item); ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo(); int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition); int childPos = ExpandableListView.getPackedPositionChild(info.packedPosition); ChildItem childItem;/* w w w . ja v a2 s . co m*/ GroupItem groupItem; switch (item.getItemId()) { case R.id.app_copy_ip: childItem = (ChildItem) adapter.getChild(groupPos, childPos); copyIpAddress(childItem); return true; case R.id.app_whois_ip: childItem = (ChildItem) adapter.getChild(groupPos, childPos); whoisIpAddress(childItem); return true; case R.id.app_graph: groupItem = (GroupItem) adapter.getGroup(groupPos); showGraph(groupItem.app.uid); return true; case R.id.app_toggle_app_notifications: groupItem = (GroupItem) adapter.getGroup(groupPos); if (NetworkLogService.toastBlockedApps.remove(groupItem.app.packageName) == null) { NetworkLogService.toastBlockedApps.put(groupItem.app.packageName, groupItem.app.packageName); } new SelectToastApps().saveBlockedApps(NetworkLog.context, NetworkLogService.toastBlockedApps); return true; case R.id.app_toggle_app_logging: groupItem = (GroupItem) adapter.getGroup(groupPos); if (NetworkLogService.blockedApps.remove(groupItem.app.packageName) == null) { NetworkLogService.blockedApps.put(groupItem.app.packageName, groupItem.app.packageName); } new SelectBlockedApps().saveBlockedApps(NetworkLog.context, NetworkLogService.blockedApps); return true; default: return super.onContextItemSelected(item); } }
From source file:org.totschnig.myexpenses.fragment.CategoryList.java
@Override public boolean dispatchCommandSingle(int command, ContextMenu.ContextMenuInfo info) { ManageCategories ctx = (ManageCategories) getActivity(); ExpandableListContextMenuInfo elcmi = (ExpandableListContextMenuInfo) info; int type = ExpandableListView.getPackedPositionType(elcmi.packedPosition); Cursor c;//w ww. j a va 2 s . c o m boolean isMain; int group = ExpandableListView.getPackedPositionGroup(elcmi.packedPosition), child = ExpandableListView.getPackedPositionChild(elcmi.packedPosition); if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { c = mAdapter.getChild(group, child); isMain = false; } else { c = mGroupCursor; isMain = true; } if (c == null || c.getCount() == 0) { //observed on Blackberry Z10 return false; } String label = c.getString(c.getColumnIndex(KEY_LABEL)); switch (command) { case R.id.EDIT_COMMAND: ctx.editCat(label, elcmi.id); return true; case R.id.SELECT_COMMAND: if (!isMain && ctx.helpVariant.equals(ManageCategories.HelpVariant.select_mapping)) { mGroupCursor.moveToPosition(group); label = mGroupCursor.getString(mGroupCursor.getColumnIndex(KEY_LABEL)) + TransactionList.CATEGORY_SEPARATOR + label; } doSelection(elcmi.id, label, isMain); finishActionMode(); return true; case R.id.CREATE_COMMAND: ctx.createCat(elcmi.id); return true; } return super.dispatchCommandSingle(command, info); }
From source file:de.mrapp.android.adapter.expandablelist.AbstractExpandableListAdapter.java
/** * Creates and returns an {@link AdapterView.OnItemLongClickListener}, which is invoked, when an * item of the adapter has been long-clicked. * * @return The listener, which has been created, as an instance of the type {@link * AdapterView.OnItemLongClickListener}//from ww w . j a v a2 s .com */ private AdapterView.OnItemLongClickListener createAdapterViewOnItemLongClickListener() { return new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(final AdapterView<?> parent, final View view, final int position, final long id) { int itemType = ExpandableListView.getPackedPositionType(id); if (itemType == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { int groupIndex = ExpandableListView.getPackedPositionGroup(id); if (groupIndex == Integer.MAX_VALUE) { if (position < adapterView.getHeaderViewsCount()) { return notifyOnHeaderLongClicked(view, position); } else { int headerCount = adapterView.getHeaderViewsCount(); int itemCount = getGroupCount() + getChildCount(); return notifyOnFooterLongClicked(view, position - headerCount - itemCount); } } else { int childIndex = ExpandableListView.getPackedPositionChild(id); return notifyOnChildLongClicked(getChild(groupIndex, childIndex), childIndex, getGroup(groupIndex), groupIndex); } } else if (itemType == ExpandableListView.PACKED_POSITION_TYPE_GROUP) { int groupIndex = ExpandableListView.getPackedPositionGroup(id); return notifyOnGroupLongClicked(getGroup(groupIndex), groupIndex); } return false; } }; }
From source file:com.money.manager.ex.home.HomeFragment.java
private QueryAccountBills getSelectedAccount(android.view.MenuItem item) { ExpandableListView.ExpandableListContextMenuInfo info = null; ContextMenu.ContextMenuInfo menuInfo = item.getMenuInfo(); // clicking any context item in child fragments will also come here. We need only // the context menu items from the Home fragment. if (menuInfo instanceof ExpandableListView.ExpandableListContextMenuInfo) { info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo; }//from ww w. j a v a 2s . c o m if (info == null) return null; int groupPos, childPos; int type = ExpandableListView.getPackedPositionType(info.packedPosition); if (type != ExpandableListView.PACKED_POSITION_TYPE_CHILD) return null; // Get the account. groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition); childPos = ExpandableListView.getPackedPositionChild(info.packedPosition); HomeAccountsExpandableAdapter accountsAdapter = (HomeAccountsExpandableAdapter) mExpandableListView .getExpandableListAdapter(); QueryAccountBills account = null; try { account = (QueryAccountBills) accountsAdapter.getChild(groupPos, childPos); } catch (Exception e) { Timber.e(e, "getting the selected account id"); } return account; }
From source file:de.mrapp.android.adapter.expandablelist.AbstractExpandableListAdapter.java
/** * Creates and returns an {@link AdapterView.OnItemLongClickListener}, which is invoked, when an * item of the adapter has been long-clicked. * * @return The listener, which has been created, as an instance of the type {@link * AdapterView.OnItemLongClickListener}/*from www . j a v a 2s . c o m*/ */ private AdapterView.OnItemLongClickListener createExpandableGridViewOnItemLongClickListener() { return new AdapterView.OnItemLongClickListener() { @Override public boolean onItemLongClick(final AdapterView<?> parent, final View view, final int position, final long id) { int itemType = ExpandableGridView.getPackedPositionType(id); if (itemType == ExpandableGridView.PACKED_POSITION_TYPE_CHILD) { int groupIndex = ExpandableGridView.getPackedPositionGroup(id); if (groupIndex == Integer.MAX_VALUE) { if (position < expandableGridView.getHeaderViewsCount()) { return notifyOnHeaderLongClicked(view, position); } else { int headerCount = adapterView.getHeaderViewsCount(); int itemCount = getGroupCount() + getChildCount(); return notifyOnFooterLongClicked(view, position - headerCount - itemCount); } } else { int childIndex = ExpandableListView.getPackedPositionChild(id); return notifyOnChildLongClicked(getChild(groupIndex, childIndex), childIndex, getGroup(groupIndex), groupIndex); } } else if (itemType == ExpandableListView.PACKED_POSITION_TYPE_GROUP) { int groupIndex = ExpandableListView.getPackedPositionGroup(id); return notifyOnGroupLongClicked(getGroup(groupIndex), groupIndex); } return false; } }; }
From source file:im.neon.util.VectorUtils.java
/** * Provides the visible child views.//from w w w. j a va 2s . c o m * 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; }