Example usage for android.widget ExpandableListView getPackedPositionType

List of usage examples for android.widget ExpandableListView getPackedPositionType

Introduction

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

Prototype

public static int getPackedPositionType(long packedPosition) 

Source Link

Document

Gets the type of a packed position.

Usage

From source file:org.ale.scanner.zotero.MainActivity.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    MenuInflater inflater = getMenuInflater();
    if (menuInfo instanceof ExpandableListContextMenuInfo) {
        ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuInfo;
        int type = ExpandableListView.getPackedPositionType(info.packedPosition);
        int group = ExpandableListView.getPackedPositionGroup(info.packedPosition);
        if (type != ExpandableListView.PACKED_POSITION_TYPE_NULL) {
            // It's not in the header
            inflater.inflate(R.menu.bib_item_context_menu, menu);
            menu.setHeaderTitle(mItemAdapter.getTitleOfGroup(group));
        }//from  w w  w .ja v  a2 s . com
    } else if (menuInfo instanceof AdapterContextMenuInfo) {
        if (v.getId() != R.id.pending_item_list) {
            AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo;
            inflater.inflate(R.menu.pending_item_context_menu, menu);
            menu.setHeaderTitle(mPendingAdapter.getItem(info.position));
        }
    }
}

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 ww .  j  a v  a 2s .  c o  m

    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   ww w  . j  a  v  a  2s.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:org.junit4android.JunitTestRunnerActivity.java

/**
 * {@inheritDoc}/* w  ww .ja  v a  2 s  . com*/
 *
 * @see android.app.Activity#onCreateContextMenu(android.view.ContextMenu,
 *      android.view.View, android.view.ContextMenu.ContextMenuInfo)
 */
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
    int type = ExpandableListView.getPackedPositionType(info.packedPosition);

    // Only create a context menu for group items
    if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
        selectedTestName = ((TextView) info.targetView).getText().toString();
        menu.setHeaderTitle(selectedTestName);
        menu.add(0, RERUN_MENU_ITEM_ID, 0, "Rerun this test...");
    }
}

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  .ja va  2  s.com*/
    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   www.  j a v a  2 s  .  com
 */
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}//  w  w  w  . j av  a2  s.c om
 */
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;
    }// ww w  . ja  va2 s  .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;
}