Example usage for android.widget ExpandableListView getPackedPositionGroup

List of usage examples for android.widget ExpandableListView getPackedPositionGroup

Introduction

In this page you can find the example usage for android.widget ExpandableListView getPackedPositionGroup.

Prototype

public static int getPackedPositionGroup(long packedPosition) 

Source Link

Document

Gets the group position from a packed position.

Usage

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 ww . j a  v a2s .co 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;//from   w ww  . j a  va2 s .com
    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 w w.j  a  v a2  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.OnItemClickListener}, which is invoked, when an
 * item of the adapter has been clicked.
 *
 * @return The listener, which has been created, as an instance of the type {@link
 * AdapterView.OnItemClickListener}/*from  w ww  .  j  a v a  2  s.c om*/
 */
private AdapterView.OnItemClickListener createAdapterViewOnItemClickListener() {
    return new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(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()) {
                        notifyOnHeaderClicked(view, position);
                    } else {
                        int headerCount = expandableGridView.getHeaderViewsCount();
                        int itemCount = getGroupCount() - getChildCount();
                        notifyOnFooterClicked(view, position - headerCount - itemCount);
                    }
                }
            }
        }

    };
}

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 w  ww .  j  a va2 s  .co m
 */
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   w  w  w  . jav  a 2  s .  co 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}/*w  ww  . j av  a2 s . com*/
 */
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. ja va2 s.  co 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;
}

From source file:org.totschnig.myexpenses.fragment.CategoryList.java

@Override
protected void configureMenuLegacy(Menu menu, ContextMenu.ContextMenuInfo menuInfo, int listId) {
    super.configureMenuLegacy(menu, menuInfo, listId);
    if (expandableListSelectionType == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
        ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuInfo;
        int groupPos = ExpandableListView.getPackedPositionGroup(info.packedPosition);
        configureMenuInternal(menu, hasChildren(groupPos));
    }/*from ww  w  .  j  a  v  a 2 s .c o  m*/
}

From source file:org.totschnig.myexpenses.fragment.CategoryList.java

@Override
protected void configureMenu11(Menu menu, int count, AbsListView lv) {
    super.configureMenu11(menu, count, lv);
    if (expandableListSelectionType == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
        SparseBooleanArray checkedItemPositions = mListView.getCheckedItemPositions();
        boolean hasChildren = false;
        for (int i = 0; i < checkedItemPositions.size(); i++) {
            if (checkedItemPositions.valueAt(i)) {
                int position = checkedItemPositions.keyAt(i);
                long pos = mListView.getExpandableListPosition(position);
                int groupPos = ExpandableListView.getPackedPositionGroup(pos);
                if (hasChildren(groupPos)) {
                    hasChildren = true;/*from  ww  w  . j  a va 2  s  .c  o  m*/
                    break;
                }
            }
        }
        configureMenuInternal(menu, hasChildren);
    }
}