Java Code Examples for android.widget.ExpandableListView#PACKED_POSITION_TYPE_CHILD

The following examples show how to use android.widget.ExpandableListView#PACKED_POSITION_TYPE_CHILD . 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
Source File: RecentTabsPage.java    From delion with 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 2
Source File: RecentTabsPage.java    From AndroidChromium with 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 File: ExpandableListPosition.java    From expandable-recycler-view with MIT License 6 votes vote down vote up
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 4
Source File: RecentTabsPage.java    From 365browser with 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 5
Source File: AllTasksListFragment.java    From ActivityLauncher with ISC License 6 votes vote down vote up
@Override
public void onCreateContextMenu(@NonNull ContextMenu menu, @NonNull View v,
                                ContextMenuInfo menuInfo) {
    menu.add(Menu.NONE, 0, Menu.NONE, R.string.context_action_shortcut);
    menu.add(Menu.NONE, 1, Menu.NONE, R.string.context_action_launch);

    ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuInfo;
    ExpandableListView list = getView().findViewById(R.id.expandableListView1);

    switch (ExpandableListView.getPackedPositionType(info.packedPosition)) {
        case ExpandableListView.PACKED_POSITION_TYPE_CHILD:
            MyActivityInfo activity = (MyActivityInfo) list.getExpandableListAdapter().getChild(ExpandableListView.getPackedPositionGroup(info.packedPosition), ExpandableListView.getPackedPositionChild(info.packedPosition));
            menu.setHeaderIcon(activity.icon);
            menu.setHeaderTitle(activity.name);
            menu.add(Menu.NONE, 2, Menu.NONE, R.string.context_action_edit);
            break;
        case ExpandableListView.PACKED_POSITION_TYPE_GROUP:
            MyPackageInfo pack = (MyPackageInfo) list.getExpandableListAdapter().getGroup(ExpandableListView.getPackedPositionGroup(info.packedPosition));
            menu.setHeaderIcon(pack.icon);
            menu.setHeaderTitle(pack.name);
            break;
    }

    super.onCreateContextMenu(menu, v, menuInfo);
}
 
Example 6
Source File: RootsFragment.java    From FireFiles with 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 7
Source File: RootsFragment.java    From FireFiles with 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 8
Source File: RootsFragment.java    From FireFiles with 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 9
Source File: DisplayLightNovelDetailsFragment.java    From coolreader with MIT License 5 votes vote down vote up
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
	super.onCreateContextMenu(menu, v, menuInfo);
	ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;

	MenuInflater inflater = getSherlockActivity().getMenuInflater();
	int type = ExpandableListView.getPackedPositionType(info.packedPosition);
	if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
		inflater.inflate(R.menu.novel_details_volume_context_menu, menu);
	} else if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
		inflater.inflate(R.menu.novel_details_chapter_context_menu, menu);
	}
}
 
Example 10
Source File: DisplayLightNovelDetailsActivity.java    From coolreader with MIT License 5 votes vote down vote up
@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
	super.onCreateContextMenu(menu, v, menuInfo);
	ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;

	MenuInflater inflater = getMenuInflater();
	int type = ExpandableListView.getPackedPositionType(info.packedPosition);
	if (type == ExpandableListView.PACKED_POSITION_TYPE_GROUP) {
		inflater.inflate(R.menu.novel_details_volume_context_menu, menu);
	} else if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
		inflater.inflate(R.menu.novel_details_chapter_context_menu, menu);
	}
}
 
Example 11
Source File: OPDSActivity.java    From document-viewer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @see android.app.Activity#onCreateContextMenu(android.view.ContextMenu, android.view.View, android.view.ContextMenu.ContextMenuInfo)
 */
@Override
public void onCreateContextMenu(final ContextMenu menu, final View v, final ContextMenuInfo menuInfo) {
    if (menuInfo instanceof ExpandableListContextMenuInfo) {
        final ExpandableListContextMenuInfo cmi = (ExpandableListContextMenuInfo) menuInfo;
        final int type = ExpandableListView.getPackedPositionType(cmi.packedPosition);
        final int groupPosition = ExpandableListView.getPackedPositionGroup(cmi.packedPosition);
        final int childPosition = ExpandableListView.getPackedPositionChild(cmi.packedPosition);
        // System.out.println("OPDSActivity.onCreateContextMenu(): " + type + ", " + groupPosition + ", "
        // + childPosition);
        switch (type) {
            case ExpandableListView.PACKED_POSITION_TYPE_NULL:
                onCreateContextMenu(menu);
                return;
            case ExpandableListView.PACKED_POSITION_TYPE_GROUP:
                final Entry entry = getController().adapter.getGroup(groupPosition);
                if (entry instanceof Feed) {
                    onCreateFeedContextMenu(menu, (Feed) entry);
                } else if (entry instanceof Book) {
                    onCreateBookContextMenu(menu, (Book) entry);
                }
                return;
            case ExpandableListView.PACKED_POSITION_TYPE_CHILD:
                final Entry group = getController().adapter.getGroup(groupPosition);
                final Object child = getController().adapter.getChild(groupPosition, childPosition);
                if (child instanceof Link) {
                    onCreateLinkContextMenu(menu, (Book) group, (Link) child);
                } else if (child instanceof Feed) {
                    onCreateFacetContextMenu(menu, (Feed) group, (Feed) child);
                }
                return;
        }
    }
    onCreateContextMenu(menu);
}
 
Example 12
Source File: TaskListFragment.java    From opentasks with Apache License 2.0 5 votes vote down vote up
@Override
public int canFling(ListView v, int pos)
{
    long packedPos = mExpandableListView.getExpandableListPosition(pos);
    if (packedPos != ExpandableListView.PACKED_POSITION_VALUE_NULL
            && ExpandableListView.getPackedPositionType(packedPos) == ExpandableListView.PACKED_POSITION_TYPE_CHILD)
    {
        return FlingDetector.RIGHT_FLING | FlingDetector.LEFT_FLING;
    }
    else
    {
        return 0;
    }
}
 
Example 13
Source File: LeadersListFragment.java    From 4pdaClient-plus with Apache License 2.0 4 votes vote down vote up
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
                                ContextMenu.ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);
    ExpandableListView.ExpandableListContextMenuInfo info =
            (ExpandableListView.ExpandableListContextMenuInfo) menuInfo;

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

    if (type == ExpandableListView.PACKED_POSITION_TYPE_CHILD) {
        Object o = getAdapter().getChild(groupPosition, childPosition);
        if (o == null) return;
        final LeadUser leadUser = ((LeadUser) o);

        final List<MenuListDialog> list = new ArrayList<>();
        list.add(new MenuListDialog(App.getInstance().getString(R.string.list_forums), () -> {
            if (leadUser.isAllForumsOwner()) {
                MainActivity.showListFragment(new ForumBrickInfo().getName(), null);
            } else {
                CharSequence[] forumTitles = new CharSequence[leadUser.getForums().size()];
                int i = 0;
                for (Forum f : leadUser.getForums()) {
                    forumTitles[i++] = f.getTitle();
                }
                Context context = getContext();
                if (context != null)
                    new MaterialDialog.Builder(context)
                            .title(R.string.forums)
                            .items(forumTitles)
                            .itemsCallbackSingleChoice(-1, (dialog, view, i1, forumTitles1) -> {
                                ForumTopicsListFragment.showForumTopicsList(
                                        leadUser.getForums().get(i1).getId(), leadUser.getForums().get(i1).getTitle());
                                return true; // allow selection
                            })
                            .show();
            }
        }));
        ForumUser.onCreateContextMenu(getContext(), list, leadUser.getId().toString(), leadUser.getNick().toString());
        ExtUrl.showContextDialog(getContext(), null, list);
    }
}
 
Example 14
Source File: AllTasksListFragment.java    From ActivityLauncher with ISC License 4 votes vote down vote up
@Override
public boolean onContextItemSelected(MenuItem item) {
    ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) item.getMenuInfo();
    ExpandableListView list = getView().findViewById(R.id.expandableListView1);

    switch (ExpandableListView.getPackedPositionType(info.packedPosition)) {
        case ExpandableListView.PACKED_POSITION_TYPE_CHILD:
            MyActivityInfo activity = (MyActivityInfo) list.getExpandableListAdapter().getChild(ExpandableListView.getPackedPositionGroup(info.packedPosition), ExpandableListView.getPackedPositionChild(info.packedPosition));
            switch (item.getItemId()) {
                case 0:
                    LauncherIconCreator.createLauncherIcon(getActivity(), activity);
                    break;
                case 1:
                    LauncherIconCreator.launchActivity(getActivity(), activity.component_name);
                    break;
                case 2:
                    DialogFragment dialog = new ShortcutEditDialogFragment();
                    Bundle args = new Bundle();
                    args.putParcelable("activity", activity.component_name);
                    dialog.setArguments(args);
                    dialog.show(getFragmentManager(), "ShortcutEditor");
                    break;
            }
            break;

        case ExpandableListView.PACKED_POSITION_TYPE_GROUP:
            MyPackageInfo pack = (MyPackageInfo) list.getExpandableListAdapter().getGroup(ExpandableListView.getPackedPositionGroup(info.packedPosition));
            switch (item.getItemId()) {
                case 0:
                    boolean success = LauncherIconCreator.createLauncherIcon(getActivity(), pack);
                    Toast.makeText(getActivity(), getString(R.string.error_no_default_activity), Toast.LENGTH_LONG).show();
                    break;
                case 1:
                    PackageManager pm = getActivity().getPackageManager();
                    Intent intent = pm.getLaunchIntentForPackage(pack.package_name);
                    if (intent != null) {
                        Toast.makeText(getActivity(), String.format(getText(R.string.starting_application).toString(), pack.name), Toast.LENGTH_LONG).show();
                        getActivity().startActivity(intent);
                    } else {
                        Toast.makeText(getActivity(), getString(R.string.error_no_default_activity), Toast.LENGTH_LONG).show();
                    }
                    break;
            }
    }
    return super.onContextItemSelected(item);
}
 
Example 15
Source File: TaskListFragment.java    From opentasks with Apache License 2.0 4 votes vote down vote up
@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)
        {
            long instanceId = cursor.getLong(cursor.getColumnIndex(Instances._ID));

            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(Instances.getContentUri(mAuthority), instanceId);

            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);
                }
            }
            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;
}