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:org.mozilla.gecko.AwesomeBar.java

@Override
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, view, menuInfo);
    ListView list = (ListView) view;
    Object selectedItem = null;/*from   w  w  w  .  ja  v a2s  .com*/
    String title = "";

    if (list == findViewById(R.id.history_list)) {
        if (!(menuInfo instanceof ExpandableListView.ExpandableListContextMenuInfo)) {
            Log.e(LOGTAG, "menuInfo is not ExpandableListContextMenuInfo");
            return;
        }

        ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
        int childPosition = ExpandableListView.getPackedPositionChild(info.packedPosition);
        int groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition);

        // Check if long tap is on a header row
        if (groupPosition < 0 || childPosition < 0)
            return;

        ExpandableListView exList = (ExpandableListView) list;
        selectedItem = exList.getExpandableListAdapter().getChild(groupPosition, childPosition);

        // The history list is backed by a SimpleExpandableListAdapter
        @SuppressWarnings("rawtypes")
        Map map = (Map) selectedItem;
        title = (String) map.get(URLColumns.TITLE);
    } else {
        if (!(menuInfo instanceof AdapterView.AdapterContextMenuInfo)) {
            Log.e(LOGTAG, "menuInfo is not AdapterContextMenuInfo");
            return;
        }

        AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
        selectedItem = list.getItemAtPosition(info.position);

        if (!(selectedItem instanceof Cursor)) {
            Log.e(LOGTAG, "item at " + info.position + " is not a Cursor");
            return;
        }

        Cursor cursor = (Cursor) selectedItem;
        title = cursor.getString(cursor.getColumnIndexOrThrow(URLColumns.TITLE));

        // Don't show the context menu for folders
        if (list == findViewById(R.id.bookmarks_list)
                && cursor.getInt(cursor.getColumnIndexOrThrow(Bookmarks.IS_FOLDER)) == 1) {
            selectedItem = null;
        }
    }

    if (selectedItem == null || !((selectedItem instanceof Cursor) || (selectedItem instanceof Map))) {
        mContextMenuSubject = null;
        return;
    }

    mContextMenuSubject = selectedItem;

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.awesomebar_contextmenu, menu);

    if (list != findViewById(R.id.bookmarks_list)) {
        MenuItem removeBookmarkItem = menu.findItem(R.id.remove_bookmark);
        removeBookmarkItem.setVisible(false);
    }

    menu.setHeaderTitle(title);
}

From source file:ivl.android.moneybalance.ExpenseListActivity.java

@Override
public boolean onContextItemSelected(MenuItem item) {
    if (item.getItemId() == ITEM_DELETE) {
        ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();
        int group = ExpandableListView.getPackedPositionGroup(info.packedPosition);
        int child = ExpandableListView.getPackedPositionChild(info.packedPosition);
        if (child != -1) {
            Expense expense = (Expense) adapter.getChild(group, child);
            expenseDataSource.delete(expense.getId());
            refresh();/*from   www .  ja v a  2s  .  c om*/
        }
    } else {
        return false;
    }
    return true;
}

From source file:com.money.manager.ex.home.HomeFragment.java

/**
 * Context menu for account entries.// ww w.jav a2 s.c om
 */
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    if (!(v instanceof ExpandableListView))
        return;

    ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;
    int type = ExpandableListView.getPackedPositionType(info.packedPosition);
    int groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition);
    int childPosition = ExpandableListView.getPackedPositionChild(info.packedPosition);

    // ignore long-press on group items.
    if (type != ExpandableListView.PACKED_POSITION_TYPE_CHILD)
        return;

    // get adapter.
    HomeAccountsExpandableAdapter accountsAdapter = (HomeAccountsExpandableAdapter) mExpandableListView
            .getExpandableListAdapter();
    Object childItem = accountsAdapter.getChild(groupPosition, childPosition);
    QueryAccountBills account = (QueryAccountBills) childItem;

    //        menu.setHeaderIcon(android.R.drawable.ic_menu_manage);
    menu.setHeaderTitle(account.getAccountName());
    String[] menuItems = getResources().getStringArray(R.array.context_menu_account_dashboard);
    for (String menuItem : menuItems) {
        menu.add(menuItem);
    }

    // balance account should work only for transaction accounts.
    AccountService service = new AccountService(getActivity());
    List<String> accountTypes = service.getTransactionAccountTypeNames();
    String accountType = account.getAccountType();
    if (accountTypes.contains(accountType)) {
        menu.add(R.string.balance_account);
    }

    // Investment menu items.
    if (accountType.equals(AccountTypes.INVESTMENT.toString())) {
        menu.add(Menu.NONE, ContextMenuIds.Portfolio.getId(), 0, getString(R.string.portfolio));
    }
}

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

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    aggregateTypes = PrefKey.DISTRIBUTION_AGGREGATE_TYPES.getBoolean(true);
    final ManageCategories ctx = (ManageCategories) getActivity();
    View v;/*from   ww w .j a va  2  s  .  c  o  m*/
    Bundle extras = ctx.getIntent().getExtras();
    mManager = getLoaderManager();
    if (ctx.helpVariant.equals(ManageCategories.HelpVariant.distribution)) {
        showChart = PrefKey.DISTRIBUTION_SHOW_CHART.getBoolean(true);
        mMainColors = new ArrayList<>();
        for (int col : ColorTemplate.PASTEL_COLORS)
            mMainColors.add(col);
        for (int col : ColorTemplate.JOYFUL_COLORS)
            mMainColors.add(col);
        for (int col : ColorTemplate.LIBERTY_COLORS)
            mMainColors.add(col);
        for (int col : ColorTemplate.VORDIPLOM_COLORS)
            mMainColors.add(col);
        for (int col : ColorTemplate.COLORFUL_COLORS)
            mMainColors.add(col);
        mMainColors.add(ColorTemplate.getHoloBlue());

        final long id = Utils.getFromExtra(extras, KEY_ACCOUNTID, 0);
        mAccount = Account.getInstanceFromDb(id);
        if (mAccount == null) {
            TextView tv = new TextView(ctx);
            //noinspection SetTextI18n
            tv.setText("Error loading distribution for account " + id);
            return tv;
        }
        Bundle b = savedInstanceState != null ? savedInstanceState : extras;

        mGrouping = (Grouping) b.getSerializable("grouping");
        if (mGrouping == null)
            mGrouping = Grouping.NONE;
        mGroupingYear = b.getInt("groupingYear");
        mGroupingSecond = b.getInt("groupingSecond");
        getActivity().supportInvalidateOptionsMenu();
        mManager.initLoader(SUM_CURSOR, null, this);
        mManager.initLoader(DATEINFO_CURSOR, null, this);
        v = inflater.inflate(R.layout.distribution_list, container, false);
        mChart = (PieChart) v.findViewById(R.id.chart1);
        mChart.setVisibility(showChart ? View.VISIBLE : View.GONE);
        mChart.setDescription("");

        //Typeface tf = Typeface.createFromAsset(getActivity().getAssets(), "OpenSans-Regular.ttf");

        //mChart.setValueTypeface(tf);
        //mChart.setCenterTextTypeface(Typeface.createFromAsset(getActivity().getAssets(), "OpenSans-Light.ttf"));
        //mChart.setUsePercentValues(true);
        //mChart.setCenterText("Quarterly\nRevenue");
        TypedValue typedValue = new TypedValue();
        getActivity().getTheme().resolveAttribute(android.R.attr.textAppearanceMedium, typedValue, true);
        int[] textSizeAttr = new int[] { android.R.attr.textSize };
        int indexOfAttrTextSize = 0;
        TypedArray a = getActivity().obtainStyledAttributes(typedValue.data, textSizeAttr);
        int textSize = a.getDimensionPixelSize(indexOfAttrTextSize, -1);
        a.recycle();
        mChart.setCenterTextSizePixels(textSize);

        // radius of the center hole in percent of maximum radius
        //mChart.setHoleRadius(60f); 
        //mChart.setTransparentCircleRadius(0f);
        mChart.setDrawSliceText(false);
        mChart.setDrawHoleEnabled(true);
        mChart.setDrawCenterText(true);
        mChart.setRotationEnabled(false);
        mChart.setOnChartValueSelectedListener(new OnChartValueSelectedListener() {

            @Override
            public void onValueSelected(Entry e, int dataSetIndex) {
                int index = e.getXIndex();
                long packedPosition = (lastExpandedPosition == -1)
                        ? ExpandableListView.getPackedPositionForGroup(index)
                        : ExpandableListView.getPackedPositionForChild(lastExpandedPosition, index);
                int flatPosition = mListView.getFlatListPosition(packedPosition);
                mListView.setItemChecked(flatPosition, true);
                mListView.smoothScrollToPosition(flatPosition);
                setCenterText(index);
            }

            @Override
            public void onNothingSelected() {
                mListView.setItemChecked(mListView.getCheckedItemPosition(), false);
            }
        });
    } else {
        v = inflater.inflate(R.layout.categories_list, container, false);
        if (savedInstanceState != null) {
            mFilter = savedInstanceState.getString("filter");
        }
    }
    incomeSumTv = (TextView) v.findViewById(R.id.sum_income);
    expenseSumTv = (TextView) v.findViewById(R.id.sum_expense);
    bottomLine = v.findViewById(R.id.BottomLine);
    updateColor();
    mListView = (ExpandableListView) v.findViewById(R.id.list);
    final View emptyView = v.findViewById(R.id.empty);
    mListView.setEmptyView(emptyView);
    mImportButton = emptyView.findViewById(R.id.importButton);
    mManager.initLoader(SORTABLE_CURSOR, null, this);
    String[] from;
    int[] to;
    if (mAccount != null) {
        from = new String[] { KEY_LABEL, KEY_SUM };
        to = new int[] { R.id.label, R.id.amount };
    } else {
        from = new String[] { KEY_LABEL };
        to = new int[] { R.id.label };
    }
    mAdapter = new MyExpandableListAdapter(ctx, null, R.layout.category_row, R.layout.category_row, from, to,
            from, to);
    mListView.setAdapter(mAdapter);
    if (ctx.helpVariant.equals(ManageCategories.HelpVariant.distribution)) {
        mListView.setOnGroupExpandListener(new OnGroupExpandListener() {
            @Override
            public void onGroupExpand(int groupPosition) {
                if (showChart) {
                    if (lastExpandedPosition != -1 && groupPosition != lastExpandedPosition) {
                        mListView.collapseGroup(lastExpandedPosition);
                    }
                }
                lastExpandedPosition = groupPosition;
            }
        });
        mListView.setOnGroupCollapseListener(new OnGroupCollapseListener() {
            @Override
            public void onGroupCollapse(int groupPosition) {
                if (showChart) {
                    lastExpandedPosition = -1;
                    setData(mGroupCursor, mMainColors);
                    highlight(groupPosition);
                    long packedPosition = ExpandableListView.getPackedPositionForGroup(groupPosition);
                    int flatPosition = mListView.getFlatListPosition(packedPosition);
                    mListView.setItemChecked(flatPosition, true);
                }
            }
        });
        mListView.setOnChildClickListener(new OnChildClickListener() {

            @Override
            public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
                    long id) {
                if (showChart) {
                    long packedPosition = ExpandableListView.getPackedPositionForChild(groupPosition,
                            childPosition);
                    highlight(childPosition);
                    int flatPosition = mListView.getFlatListPosition(packedPosition);
                    mListView.setItemChecked(flatPosition, true);
                    return true;
                }
                return false;
            }
        });
        //the following is relevant when not in touch mode
        mListView.setOnItemSelectedListener(new OnItemSelectedListener() {

            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                if (showChart) {
                    long pos = mListView.getExpandableListPosition(position);
                    int type = ExpandableListView.getPackedPositionType(pos);
                    int group = ExpandableListView.getPackedPositionGroup(pos),
                            child = ExpandableListView.getPackedPositionChild(pos);
                    int highlightedPos;
                    if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
                        if (lastExpandedPosition != group) {
                            mListView.collapseGroup(lastExpandedPosition);
                        }
                        highlightedPos = lastExpandedPosition == -1 ? group : -1;
                    } else {
                        highlightedPos = child;
                    }
                    highlight(highlightedPos);
                }
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {
            }
        });

        mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
        registerForContextMenu(mListView);
    } else {
        registerForContextualActionBar(mListView);
    }
    return v;
}

From source file:org.matrix.console.activity.HomeActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (CommonActivityUtils.shouldRestartApp()) {
        Log.e(LOG_TAG, "Restart the application.");
        CommonActivityUtils.restartApp(this);
    }// w w  w.j a  va2 s  .  c o m

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);

    mMyRoomList = (ExpandableListView) findViewById(R.id.listView_myRooms);
    // the chevron is managed in the header view
    mMyRoomList.setGroupIndicator(null);
    mAdapter = new ConsoleRoomSummaryAdapter(this, Matrix.getMXSessions(this), R.layout.adapter_item_my_rooms,
            R.layout.adapter_room_section_header);

    if (null != savedInstanceState) {
        if (savedInstanceState.containsKey(PUBLIC_ROOMS_LIST_LIST)) {
            Serializable map = savedInstanceState.getSerializable(PUBLIC_ROOMS_LIST_LIST);

            if (null != map) {
                HashMap<String, List<PublicRoom>> hash = (HashMap<String, List<PublicRoom>>) map;
                mPublicRoomsListList = new ArrayList<List<PublicRoom>>(hash.values());
                mHomeServerNames = new ArrayList<>(hash.keySet());
            }
        }
    }

    final Intent intent = getIntent();
    if (intent.hasExtra(EXTRA_JUMP_TO_ROOM_ID)) {
        mAutomaticallyOpenedRoomId = intent.getStringExtra(EXTRA_JUMP_TO_ROOM_ID);
    }

    if (intent.hasExtra(EXTRA_JUMP_MATRIX_ID)) {
        mAutomaticallyOpenedMatrixId = intent.getStringExtra(EXTRA_JUMP_MATRIX_ID);
    }

    if (intent.hasExtra(EXTRA_ROOM_INTENT)) {
        mOpenedRoomIntent = intent.getParcelableExtra(EXTRA_ROOM_INTENT);
    }

    String action = intent.getAction();
    String type = intent.getType();

    // send files from external application
    if ((Intent.ACTION_SEND.equals(action) || Intent.ACTION_SEND_MULTIPLE.equals(action)) && type != null) {
        this.runOnUiThread(new Runnable() {
            @Override
            public void run() {
                CommonActivityUtils.sendFilesTo(HomeActivity.this, intent);
            }
        });
    }

    mMyRoomList.setAdapter(mAdapter);
    Collection<MXSession> sessions = Matrix.getMXSessions(HomeActivity.this);

    // check if  there is some valid session
    // the home activity could be relaunched after an application crash
    // so, reload the sessions before displaying the hidtory
    if (sessions.size() == 0) {
        Log.e(LOG_TAG, "Weird : onCreate : no session");

        if (null != Matrix.getInstance(this).getDefaultSession()) {
            Log.e(LOG_TAG, "No loaded session : reload them");
            startActivity(new Intent(HomeActivity.this, SplashActivity.class));
            HomeActivity.this.finish();
            return;
        }
    }

    for (MXSession session : sessions) {
        addSessionListener(session);
    }

    mMyRoomList.setOnChildClickListener(new ExpandableListView.OnChildClickListener() {
        @Override
        public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition,
                long id) {

            if (mAdapter.isRecentsGroupIndex(groupPosition)) {
                String roomId = null;
                MXSession session = null;

                RoomSummary roomSummary = mAdapter.getRoomSummaryAt(groupPosition, childPosition);
                session = Matrix.getInstance(HomeActivity.this).getSession(roomSummary.getMatrixId());

                roomId = roomSummary.getRoomId();
                Room room = session.getDataHandler().getRoom(roomId);
                // cannot join a leaving room
                if ((null == room) || room.isLeaving()) {
                    roomId = null;
                }

                if (mAdapter.resetUnreadCount(groupPosition, roomId)) {
                    session.getDataHandler().getStore().flushSummary(roomSummary);
                }

                if (null != roomId) {
                    CommonActivityUtils.goToRoomPage(session, roomId, HomeActivity.this, null);
                }

            } else if (mAdapter.isPublicsGroupIndex(groupPosition)) {
                joinPublicRoom(mAdapter.getHomeServerURLAt(groupPosition),
                        mAdapter.getPublicRoomAt(groupPosition, childPosition));
            }

            return true;
        }
    });

    mMyRoomList.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
        @Override
        public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {

            if (ExpandableListView.getPackedPositionType(id) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
                long packedPos = ((ExpandableListView) parent).getExpandableListPosition(position);
                final int groupPosition = ExpandableListView.getPackedPositionGroup(packedPos);

                if (mAdapter.isRecentsGroupIndex(groupPosition)) {
                    final int childPosition = ExpandableListView.getPackedPositionChild(packedPos);

                    FragmentManager fm = HomeActivity.this.getSupportFragmentManager();
                    IconAndTextDialogFragment fragment = (IconAndTextDialogFragment) fm
                            .findFragmentByTag(TAG_FRAGMENT_ROOM_OPTIONS);

                    if (fragment != null) {
                        fragment.dismissAllowingStateLoss();
                    }

                    final Integer[] lIcons = new Integer[] { R.drawable.ic_material_exit_to_app };
                    final Integer[] lTexts = new Integer[] { R.string.action_leave };

                    fragment = IconAndTextDialogFragment.newInstance(lIcons, lTexts);
                    fragment.setOnClickListener(new IconAndTextDialogFragment.OnItemClickListener() {
                        @Override
                        public void onItemClick(IconAndTextDialogFragment dialogFragment, int position) {
                            Integer selectedVal = lTexts[position];

                            if (selectedVal == R.string.action_leave) {
                                HomeActivity.this.runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        final RoomSummary roomSummary = mAdapter.getRoomSummaryAt(groupPosition,
                                                childPosition);
                                        final MXSession session = Matrix.getInstance(HomeActivity.this)
                                                .getSession(roomSummary.getMatrixId());

                                        String roomId = roomSummary.getRoomId();
                                        Room room = session.getDataHandler().getRoom(roomId);

                                        if (null != room) {
                                            room.leave(new SimpleApiCallback<Void>(HomeActivity.this) {
                                                @Override
                                                public void onSuccess(Void info) {
                                                    mAdapter.removeRoomSummary(groupPosition, roomSummary);
                                                    mAdapter.notifyDataSetChanged();
                                                }
                                            });
                                        }
                                    }
                                });
                            }
                        }
                    });

                    fragment.show(fm, TAG_FRAGMENT_ROOM_OPTIONS);

                    return true;
                }
            }

            return false;
        }
    });

    mMyRoomList.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
        @Override
        public void onGroupExpand(int groupPosition) {
            if (mAdapter.isPublicsGroupIndex(groupPosition)) {
                refreshPublicRoomsList();
            }
        }
    });

    mMyRoomList.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() {
        @Override
        public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
            return mAdapter.getGroupCount() < 2;
        }
    });

    mSearchRoomEditText = (EditText) this.findViewById(R.id.editText_search_room);
    mSearchRoomEditText.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(android.text.Editable s) {
            mAdapter.setSearchedPattern(s.toString());
            mMyRoomList.smoothScrollToPosition(0);
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });
}

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

@Override
public boolean dispatchCommandMultiple(int command, SparseBooleanArray positions, Long[] itemIds) {
    ManageCategories ctx = (ManageCategories) getActivity();
    ArrayList<Long> idList;
    switch (command) {
    case R.id.DELETE_COMMAND:
        int mappedTransactionsCount = 0, mappedTemplatesCount = 0, hasChildrenCount = 0;
        idList = new ArrayList<>();
        for (int i = 0; i < positions.size(); i++) {
            Cursor c;/*  w ww  .  j av a 2s  . c o m*/
            if (positions.valueAt(i)) {
                boolean deletable = true;
                int position = positions.keyAt(i);
                long pos = mListView.getExpandableListPosition(position);
                int type = ExpandableListView.getPackedPositionType(pos);
                int group = ExpandableListView.getPackedPositionGroup(pos),
                        child = ExpandableListView.getPackedPositionChild(pos);
                if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
                    c = mAdapter.getChild(group, child);
                    c.moveToPosition(child);
                } else {
                    c = mGroupCursor;
                    c.moveToPosition(group);
                }
                long itemId = c.getLong(c.getColumnIndex(KEY_ROWID));
                Bundle extras = ctx.getIntent().getExtras();
                if ((extras != null && extras.getLong(KEY_ROWID) == itemId)
                        || c.getInt(c.getColumnIndex(DatabaseConstants.KEY_MAPPED_TRANSACTIONS)) > 0) {
                    mappedTransactionsCount++;
                    deletable = false;
                } else if (c.getInt(c.getColumnIndex(DatabaseConstants.KEY_MAPPED_TEMPLATES)) > 0) {
                    mappedTemplatesCount++;
                    deletable = false;
                }
                if (deletable) {
                    if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP
                            && c.getInt(c.getColumnIndex(KEY_CHILD_COUNT)) > 0) {
                        hasChildrenCount++;
                    }
                    idList.add(itemId);
                }
            }
        }
        if (!idList.isEmpty()) {
            Long[] objectIds = idList.toArray(new Long[idList.size()]);
            if (hasChildrenCount > 0) {
                MessageDialogFragment
                        .newInstance(R.string.dialog_title_warning_delete_main_category,
                                getResources().getQuantityString(R.plurals.warning_delete_main_category,
                                        hasChildrenCount, hasChildrenCount),
                                new MessageDialogFragment.Button(android.R.string.yes, R.id.DELETE_COMMAND_DO,
                                        objectIds),
                                null,
                                new MessageDialogFragment.Button(android.R.string.no,
                                        R.id.CANCEL_CALLBACK_COMMAND, null))
                        .show(ctx.getSupportFragmentManager(), "DELETE_CATEGORY");
            } else {
                ctx.dispatchCommand(R.id.DELETE_COMMAND_DO, objectIds);
            }
        }
        if (mappedTransactionsCount > 0 || mappedTemplatesCount > 0) {
            String message = "";
            if (mappedTransactionsCount > 0)
                message += getResources().getQuantityString(R.plurals.not_deletable_mapped_transactions,
                        mappedTransactionsCount, mappedTransactionsCount);
            if (mappedTemplatesCount > 0)
                message += getResources().getQuantityString(R.plurals.not_deletable_mapped_templates,
                        mappedTemplatesCount, mappedTemplatesCount);
            Toast.makeText(getActivity(), message, Toast.LENGTH_LONG).show();
        }
        return true;
    case R.id.SELECT_COMMAND_MULTIPLE:
        ArrayList<String> labelList = new ArrayList<>();
        for (int i = 0; i < positions.size(); i++) {
            Cursor c;
            if (positions.valueAt(i)) {
                int position = positions.keyAt(i);
                long pos = mListView.getExpandableListPosition(position);
                int type = ExpandableListView.getPackedPositionType(pos);
                int group = ExpandableListView.getPackedPositionGroup(pos),
                        child = ExpandableListView.getPackedPositionChild(pos);
                if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
                    c = mAdapter.getChild(group, child);
                    c.moveToPosition(child);
                } else {
                    c = mGroupCursor;
                    c.moveToPosition(group);
                }
                labelList.add(c.getString(c.getColumnIndex(KEY_LABEL)));
            }
        }
        Intent intent = new Intent();
        intent.putExtra(KEY_CATID, ArrayUtils.toPrimitive(itemIds));
        intent.putExtra(KEY_LABEL, TextUtils.join(",", labelList));
        ctx.setResult(ManageCategories.RESULT_FIRST_USER, intent);
        ctx.finish();
        return true;
    case R.id.MOVE_COMMAND:
        final Long[] excludedIds;
        final boolean inGroup = expandableListSelectionType == ExpandableListView.PACKED_POSITION_TYPE_GROUP;
        if (inGroup) {
            excludedIds = itemIds;
        } else {
            idList = new ArrayList<>();
            for (int i = 0; i < positions.size(); i++) {
                if (positions.valueAt(i)) {
                    int position = positions.keyAt(i);
                    long pos = mListView.getExpandableListPosition(position);
                    int group = ExpandableListView.getPackedPositionGroup(pos);
                    mGroupCursor.moveToPosition(group);
                    idList.add(mGroupCursor.getLong(mGroupCursor.getColumnIndex(KEY_ROWID)));
                }
            }
            excludedIds = idList.toArray(new Long[idList.size()]);
        }
        Bundle args = new Bundle(3);
        args.putBoolean(SelectMainCategoryDialogFragment.KEY_WITH_ROOT, !inGroup);
        args.putLongArray(SelectMainCategoryDialogFragment.KEY_EXCLUDED_ID,
                ArrayUtils.toPrimitive(excludedIds));
        args.putLongArray(TaskExecutionFragment.KEY_OBJECT_IDS, ArrayUtils.toPrimitive(itemIds));
        SelectMainCategoryDialogFragment.newInstance(args).show(getFragmentManager(), "SELECT_TARGET");
        return true;
    }
    return false;
}

From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.DisplayStopDataFragment.java

/**
 * {@inheritDoc}/*from  w w w . ja va 2 s  .c om*/
 */
@Override
public boolean onContextItemSelected(final MenuItem item) {
    // Cast the information parameter.
    final ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();

    switch (item.getItemId()) {
    case R.id.displaystopdata_context_menu_addarrivalalert:
        // Get the position where this data lives.
        final int position = ExpandableListView.getPackedPositionGroup(info.packedPosition);
        if (listAdapter != null) {
            final HashMap<String, String> groupData = (HashMap<String, String>) listAdapter.getGroup(position);
            // Fire off the Activity.
            callbacks.onShowAddTimeAlert(stopCode, new String[] { groupData.get(SERVICE_NAME_KEY) });
        }
        return true;
    default:
        return super.onContextItemSelected(item);
    }
}

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  ww w.j  av a2 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: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  ww  . jav  a 2  s.  c o m
    } 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);
    }/* w ww .j  ava2 s.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);
    }
}