List of usage examples for android.widget ExpandableListView getPackedPositionGroup
public static int getPackedPositionGroup(long packedPosition)
From source file:org.videolan.vlc.gui.audio.AudioBrowserFragment.java
@Override public boolean onContextItemSelected(MenuItem item) { if (!getUserVisibleHint()) return super.onContextItemSelected(item); ContextMenuInfo menuInfo = item.getMenuInfo(); if (menuInfo == null) return super.onContextItemSelected(item); int startPosition; int groupPosition; int childPosition; List<String> medias; int id = item.getItemId(); boolean useAllItems = (id == R.id.audio_list_browser_play_all || id == R.id.audio_list_browser_append_all); boolean append = (id == R.id.audio_list_browser_append || id == R.id.audio_list_browser_append_all); if (ExpandableListContextMenuInfo.class.isInstance(menuInfo)) { ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuInfo; groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition); childPosition = ExpandableListView.getPackedPositionChild(info.packedPosition); if (childPosition < 0) childPosition = 0;// w ww.ja va2 s. c om } else { AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; groupPosition = info.position; childPosition = 0; } if (id == R.id.audio_list_browser_delete) { AlertDialog alertDialog = CommonDialogs.deleteMedia(getActivity(), mSongsAdapter.getLocation(groupPosition).get(0), new VlcRunnable(mSongsAdapter.getItem(groupPosition)) { @Override public void run(Object o) { Media aMedia = (Media) o; mMediaLibrary.getMediaItems().remove(aMedia); updateLists(); } }); alertDialog.show(); return true; } if (id == R.id.audio_list_browser_set_song) { AudioUtil.setRingtone(mSongsAdapter.getItem(groupPosition), getActivity()); return true; } if (useAllItems) { startPosition = groupPosition; medias = mSongsAdapter.getLocations(); } else { startPosition = 0; switch (mFlingViewGroup.getPosition()) { case MODE_SONG: medias = mSongsAdapter.getLocation(groupPosition); break; case MODE_ARTIST: medias = mArtistsAdapter.getPlaylist(groupPosition, childPosition); break; case MODE_ALBUM: medias = mAlbumsAdapter.getPlaylist(groupPosition, childPosition); break; case MODE_GENRE: medias = mGenresAdapter.getPlaylist(groupPosition, childPosition); break; default: return true; } } if (append) mAudioController.append(medias); else mAudioController.load(medias, startPosition); AudioPlayerActivity.start(getActivity()); return super.onContextItemSelected(item); }
From source file:the.joevlc.AudioBrowserFragment.java
@Override public boolean onContextItemSelected(MenuItem item) { ContextMenuInfo menuInfo = item.getMenuInfo(); if (menuInfo == null) return super.onContextItemSelected(item); int startPosition; int groupPosition; int childPosition; List<String> medias; int id = item.getItemId(); boolean useAllItems = (id == R.id.audio_list_browser_play_all || id == R.id.audio_list_browser_append_all); boolean append = (id == R.id.audio_list_browser_append || id == R.id.audio_list_browser_append_all); if (ExpandableListContextMenuInfo.class.isInstance(menuInfo)) { ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuInfo; groupPosition = ExpandableListView.getPackedPositionGroup(info.packedPosition); childPosition = ExpandableListView.getPackedPositionChild(info.packedPosition); if (childPosition < 0) childPosition = 0;/*from ww w. j a v a2 s .com*/ } else { AdapterContextMenuInfo info = (AdapterContextMenuInfo) menuInfo; groupPosition = info.position; childPosition = 0; } if (id == R.id.audio_list_browser_delete) { AlertDialog alertDialog = CommonDialogs.deleteMedia(getActivity(), mSongsAdapter.getLocation(groupPosition).get(0), new VlcRunnable(mSongsAdapter.getItem(groupPosition)) { @Override public void run(Object o) { Media aMedia = (Media) o; mMediaLibrary.getMediaItems().remove(aMedia); updateLists(); } }); alertDialog.show(); return true; } if (id == R.id.audio_list_browser_set_song) { AudioUtil.setRingtone(mSongsAdapter.getItem(groupPosition), getActivity()); return true; } if (useAllItems) { startPosition = groupPosition; medias = mSongsAdapter.getLocations(); } else { startPosition = 0; switch (mFlingViewGroup.getPosition()) { case MODE_SONG: medias = mSongsAdapter.getLocation(groupPosition); break; case MODE_ARTIST: medias = mArtistsAdapter.getPlaylist(groupPosition, childPosition); break; case MODE_ALBUM: medias = mAlbumsAdapter.getPlaylist(groupPosition, childPosition); break; case MODE_GENRE: medias = mGenresAdapter.getPlaylist(groupPosition, childPosition); break; default: return true; } } if (append) mAudioController.append(medias); else mAudioController.load(medias, startPosition); AudioPlayerActivity.start(getActivity()); return super.onContextItemSelected(item); }
From source file:com.iskrembilen.quasseldroid.gui.fragments.BufferFragment.java
private void initActionMenu() { actionModeData.actionModeCallbackNetwork = new ActionMode.Callback() { @Override//from ww w . j a va2s . c om public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.buffer_contextual_menu_networks, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.context_menu_connect: BufferHelper.connectNetwork(actionModeData.id); mode.finish(); return true; case R.id.context_menu_disconnect: BufferHelper.disconnectNetwork(actionModeData.id); mode.finish(); return true; default: return false; } } @Override public void onDestroyActionMode(ActionMode mode) { // actionModeData.listItem.setActivated(false); actionModeData.actionMode = null; } }; actionModeData.actionModeCallbackBuffer = new ActionMode.Callback() { @Override public boolean onCreateActionMode(ActionMode mode, Menu menu) { MenuInflater inflater = mode.getMenuInflater(); inflater.inflate(R.menu.buffer_contextual_menu_channels, menu); return true; } @Override public boolean onPrepareActionMode(ActionMode mode, Menu menu) { return false; // Return false if nothing is done } @Override public boolean onActionItemClicked(ActionMode mode, MenuItem item) { switch (item.getItemId()) { case R.id.context_menu_join: BufferHelper.joinChannel(actionModeData.id, bufferListAdapter.networks); mode.finish(); return true; case R.id.context_menu_part: BufferHelper.partChannel(actionModeData.id, bufferListAdapter.networks); mode.finish(); return true; case R.id.context_menu_delete: BufferHelper.showDeleteConfirmDialog(getSherlockActivity(), actionModeData.id); mode.finish(); return true; case R.id.context_menu_hide_temp: BufferHelper.tempHideChannel(actionModeData.id); mode.finish(); return true; case R.id.context_menu_hide_perm: BufferHelper.permHideChannel(actionModeData.id); mode.finish(); return true; default: return false; } } // Called when the user exits the action mode @Override public void onDestroyActionMode(ActionMode mode) { // actionModeData.listItem.setActivated(false); actionModeData.actionMode = null; } }; bufferList.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { long packedPosition = bufferList.getExpandableListPosition(position); int groupPosition = ExpandableListView.getPackedPositionGroup(packedPosition); int childPosition = ExpandableListView.getPackedPositionChild(packedPosition); if (ExpandableListView .getPackedPositionType(packedPosition) == ExpandableListView.PACKED_POSITION_TYPE_CHILD) { Buffer buffer = bufferListAdapter.getChild(groupPosition, childPosition); actionModeData.actionMode = getSherlockActivity() .startActionMode(actionModeData.actionModeCallbackBuffer); actionModeData.id = buffer.getInfo().id; actionModeData.listItem = view; if (buffer.getInfo().type == BufferInfo.Type.QueryBuffer) { actionModeData.actionMode.getMenu().findItem(R.id.context_menu_part).setVisible(false); actionModeData.actionMode.getMenu().findItem(R.id.context_menu_delete).setVisible(true); actionModeData.actionMode.getMenu().findItem(R.id.context_menu_join).setVisible(false); actionModeData.actionMode.getMenu().findItem(R.id.context_menu_hide_temp).setVisible(true); actionModeData.actionMode.getMenu().findItem(R.id.context_menu_hide_perm).setVisible(true); } else if (buffer.isActive()) { actionModeData.actionMode.getMenu().findItem(R.id.context_menu_part).setVisible(true); actionModeData.actionMode.getMenu().findItem(R.id.context_menu_join).setVisible(false); actionModeData.actionMode.getMenu().findItem(R.id.context_menu_delete).setVisible(false); actionModeData.actionMode.getMenu().findItem(R.id.context_menu_hide_temp).setVisible(true); actionModeData.actionMode.getMenu().findItem(R.id.context_menu_hide_perm).setVisible(true); } else { actionModeData.actionMode.getMenu().findItem(R.id.context_menu_part).setVisible(false); actionModeData.actionMode.getMenu().findItem(R.id.context_menu_delete).setVisible(true); actionModeData.actionMode.getMenu().findItem(R.id.context_menu_join).setVisible(true); actionModeData.actionMode.getMenu().findItem(R.id.context_menu_hide_temp).setVisible(true); actionModeData.actionMode.getMenu().findItem(R.id.context_menu_hide_perm).setVisible(true); } } else if (ExpandableListView .getPackedPositionType(packedPosition) == ExpandableListView.PACKED_POSITION_TYPE_GROUP) { Network network = bufferListAdapter.getGroup(groupPosition); actionModeData.actionMode = getSherlockActivity() .startActionMode(actionModeData.actionModeCallbackNetwork); actionModeData.id = network.getId(); actionModeData.listItem = view; if (network.isConnected()) { actionModeData.actionMode.getMenu().findItem(R.id.context_menu_disconnect).setVisible(true); actionModeData.actionMode.getMenu().findItem(R.id.context_menu_connect).setVisible(false); } else { actionModeData.actionMode.getMenu().findItem(R.id.context_menu_disconnect) .setVisible(false); actionModeData.actionMode.getMenu().findItem(R.id.context_menu_connect).setVisible(true); } } return true; } }); }
From source file:com.miz.mizuu.fragments.ShowSeasonsFragment.java
@Override public void onViewCreated(View view, Bundle savedInstanceState) { super.onViewCreated(view, savedInstanceState); if (setBackground && !MizLib.isPortrait(getActivity()) && MizLib.isTablet(getActivity())) view.findViewById(R.id.container).setBackgroundColor(Color.parseColor("#101010")); pbar = (ProgressBar) view.findViewById(R.id.progressbar); if (useGridView) mGridView = (StickyGridHeadersGridView) view.findViewById(R.id.gridView); else/*from w w w . j a va 2 s . c o m*/ mListView = (ExpandableListView) view.findViewById(R.id.listView); if (useGridView) { mGridView.setAreHeadersSticky(false); mGridView.setAdapter(mGridAdapter); } else { mListView.setAdapter(mListAdapter); mListView.setGroupIndicator(null); } if (useGridView) mGridView.setAdapter(mGridAdapter); else mListView.setAdapter(mListAdapter); getCollectionView().setFastScrollEnabled(true); getCollectionView().setDrawSelectorOnTop(true); getCollectionView().setSelector(R.drawable.buttonstyle); if (!useGridView) { mListView.setOnChildClickListener(new OnChildClickListener() { @Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { int position = getEpisodeNumber(groupPosition, childPosition); if (position >= 0) { if (mActionMode != null) mActionMode.finish(); if (!isPortrait) { mListView.setItemChecked(MizLib.flatPosition(mListView, groupPosition, childPosition), true); selectedEpisodeIndex = position; } selectEpisode(shownEpisodes.get(position)); } return true; } }); } else { mGridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) { if (position >= 0) { if (mActionMode != null) mActionMode.finish(); if (!isPortrait) { getCollectionView().setItemChecked(position, true); selectedEpisodeIndex = position; } selectEpisode(shownEpisodes.get(position)); } } }); } getCollectionView().setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int position, long arg3) { if (position >= 0) { if (!useGridView && ExpandableListView .getPackedPositionType(arg3) == ExpandableListView.PACKED_POSITION_TYPE_GROUP) // This is a group, let's dismiss it return false; if (mActionMode != null) return false; getCollectionView().setItemChecked(position, true); if (!useGridView) { int pos = getEpisodeNumber(ExpandableListView.getPackedPositionGroup(arg3), ExpandableListView .getPackedPositionChild(mListView.getExpandableListPosition(position))); selectedEpisodeIndex = pos; selectEpisode(shownEpisodes.get(pos)); } else { selectedEpisodeIndex = position; selectEpisode(shownEpisodes.get(position)); } mActionMode = getActivity().startActionMode(mActionModeCallback); } return true; } }); loadEpisodes(0, true); }
From source file:il.ac.shenkar.todos.view.MainActivity.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, v, menuInfo); MenuInflater inflater = getMenuInflater(); inflater.inflate(R.menu.context_menu, menu); menu.setHeaderTitle("Task Menu"); ExpandableListView.ExpandableListContextMenuInfo info = (ExpandableListView.ExpandableListContextMenuInfo) menuInfo; // stores current item position int position = ExpandableListView.getPackedPositionGroup(info.packedPosition); // current task description String taskDescription = taskListModel.getTaskAt(position).getTaskDescription(); // is task marked as important boolean isImportant = taskListModel.getTaskAt(position).isImportant(); if (Utils.ENGLISH_LANGUAGE == false) { // make hebrew menu menu.setHeaderTitle(" "); Utils.makeHebrewContextMenu(menu); if (taskDescription.equals(Utils.DEFAULT_DESCRIPTION)) { MenuItem item = menu.findItem(R.id.editDescription); item.setTitle(" "); }//from w w w. j a v a 2 s. c o m if (isImportant) { MenuItem item = menu.findItem(R.id.markImportant); item.setTitle(" - "); } } else { // checks if description is empty if (taskDescription.equals(Utils.DEFAULT_DESCRIPTION)) { MenuItem item = menu.findItem(R.id.editDescription); item.setTitle("Add Task Description"); } if (isImportant) { MenuItem item = menu.findItem(R.id.markImportant); item.setTitle("Mark As Unimportant"); } } }
From source file:il.ac.shenkar.todos.view.MainActivity.java
@Override public boolean onContextItemSelected(MenuItem menuItem) { ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuItem.getMenuInfo(); // holds current item position int index = ExpandableListView.getPackedPositionGroup(info.packedPosition); currentPosition = index;//from ww w.ja va2 s . c o m // determines which item was selected at the menu switch (menuItem.getItemId()) { case R.id.editTitle: alertDialog = new AlertDialogs(); alertDialog.setArguments(getArguments(Utils.DIALOG_TEXT_ENTRY, index, Utils.EDIT_TITLE)); alertDialog.show(getFragmentManager(), "ShowAlertDialog"); return true; case R.id.editDescription: alertDialog = new AlertDialogs(); alertDialog.setArguments(getArguments(Utils.DIALOG_LONG_TEXT_ENTRY, index, Utils.EDIT_DESCRIPTION)); alertDialog.show(getFragmentManager(), "ShowAlertDialog"); return true; case R.id.markImportant: // mark the task as important/unimportant boolean important = taskListModel.getTaskAt(index).isImportant(); taskListModel.getTaskAt(index).setImportant(!important); taskListModel.getDataBase().updateTask(taskListModel.getTaskAt(index)); adapter.notifyDataSetChanged(); return true; case R.id.deleteTask: taskToUndo = taskListModel.getTaskAt(index); taskListModel.removeTask(index); mediaPlayer.playAudio(Utils.DELETE_SOUND); taskAlarms.disableTaskAlerts(taskToUndo); adapter.notifyDataSetChanged(); showUndo(viewContainer); return true; case R.id.setLocation: alertDialog = new AlertDialogs(); alertDialog.setArguments(getArguments(Utils.DIALOG_TEXT_ENTRY, index, Utils.SET_LOCATION)); alertDialog.show(getFragmentManager(), "ShowAlertDialog"); return true; case R.id.share: shareTask(index); default: return super.onContextItemSelected(menuItem); } }
From source file:im.vector.activity.HomeActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { if (CommonActivityUtils.shouldRestartApp()) { Log.e(LOG_TAG, "Restart the application."); CommonActivityUtils.restartApp(this); }/*from 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, null, HomeActivity.this.getResources().getColor(R.color.vector_title_color)); 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 roomSession = Matrix.getInstance(HomeActivity.this) .getSession(roomSummary.getMatrixId()); String roomId = roomSummary.getRoomId(); Room room = roomSession.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:ivl.android.moneybalance.ExpenseListActivity.java
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { if (v.getId() == R.id.expense_list) { ExpandableListContextMenuInfo info = (ExpandableListContextMenuInfo) menuInfo; int group = ExpandableListView.getPackedPositionGroup(info.packedPosition); int child = ExpandableListView.getPackedPositionChild(info.packedPosition); if (child != -1) { Expense expense = (Expense) adapter.getChild(group, child); menu.setHeaderTitle(expense.getTitle()); menu.add(0, ITEM_DELETE, 0, R.string.menu_delete); }// w w w . j a va 2 s . c om } }
From source file:net.etuldan.sparss.fragment.EditFeedsListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_edit_feed_list, container, false); mListView = (DragNDropExpandableListView) rootView.findViewById(android.R.id.list); mListView.setFastScrollEnabled(true); mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); mListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { @Override/*from w w w. j a va 2 s. c o m*/ public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { startActivity(new Intent(Intent.ACTION_EDIT).setData(FeedColumns.CONTENT_URI(id))); return true; } }); mListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { if (v.findViewById(R.id.indicator).getVisibility() != View.VISIBLE) { // This is no a real group startActivity(new Intent(Intent.ACTION_EDIT).setData(FeedColumns.CONTENT_URI(id))); return true; } return false; } }); mListView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { ActionBarActivity activity = (ActionBarActivity) getActivity(); if (activity != null) { String title = ((TextView) view.findViewById(android.R.id.text1)).getText().toString(); Matcher m = Pattern.compile("(.*) \\([0-9]+\\)$").matcher(title); if (m.matches()) { title = m.group(1); } long feedId = mListView.getItemIdAtPosition(position); ActionMode actionMode; if (view.findViewById(R.id.indicator).getVisibility() == View.VISIBLE) { // This is a group actionMode = activity.startSupportActionMode(mGroupActionModeCallback); } else { // This is a feed actionMode = activity.startSupportActionMode(mFeedActionModeCallback); } actionMode.setTag(new Pair<>(feedId, title)); mListView.setItemChecked(position, true); } return true; } }); mListView.setAdapter(new FeedsCursorAdapter(getActivity(), FeedColumns.GROUPS_CONTENT_URI)); mListView.setDragNDropListener(new DragNDropListener() { boolean fromHasGroupIndicator = false; @Override public void onStopDrag(View itemView) { } @Override public void onStartDrag(View itemView) { fromHasGroupIndicator = itemView.findViewById(R.id.indicator).getVisibility() == View.VISIBLE; } @Override public void onDrop(final int flatPosFrom, final int flatPosTo) { final boolean fromIsGroup = ExpandableListView.getPackedPositionType(mListView .getExpandableListPosition(flatPosFrom)) == ExpandableListView.PACKED_POSITION_TYPE_GROUP; final boolean toIsGroup = ExpandableListView.getPackedPositionType(mListView .getExpandableListPosition(flatPosTo)) == ExpandableListView.PACKED_POSITION_TYPE_GROUP; final boolean fromIsFeedWithoutGroup = fromIsGroup && !fromHasGroupIndicator; View toView = mListView.getChildAt(flatPosTo - mListView.getFirstVisiblePosition()); boolean toIsFeedWithoutGroup = toIsGroup && toView.findViewById(R.id.indicator).getVisibility() != View.VISIBLE; final long packedPosTo = mListView.getExpandableListPosition(flatPosTo); final int packedGroupPosTo = ExpandableListView.getPackedPositionGroup(packedPosTo); if ((fromIsFeedWithoutGroup || !fromIsGroup) && toIsGroup && !toIsFeedWithoutGroup) { new AlertDialog.Builder(getActivity()) // .setTitle(R.string.to_group_title) // .setMessage(R.string.to_group_message) // .setPositiveButton(R.string.to_group_into, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ContentValues values = new ContentValues(); values.put(FeedColumns.PRIORITY, 1); values.put(FeedColumns.GROUP_ID, mListView.getItemIdAtPosition(flatPosTo)); ContentResolver cr = getActivity().getContentResolver(); cr.update(FeedColumns.CONTENT_URI(mListView.getItemIdAtPosition(flatPosFrom)), values, null, null); cr.notifyChange(FeedColumns.GROUPS_CONTENT_URI, null); } }).setNegativeButton(R.string.to_group_above, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { moveItem(fromIsGroup, toIsGroup, fromIsFeedWithoutGroup, packedPosTo, packedGroupPosTo, flatPosFrom); } }).show(); } else { moveItem(fromIsGroup, toIsGroup, fromIsFeedWithoutGroup, packedPosTo, packedGroupPosTo, flatPosFrom); } } @Override public void onDrag(int x, int y, ListView listView) { } }); return rootView; }
From source file:com.viktorrudometkin.burramys.fragment.EditFeedsListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_edit_feed_list, container, false); mListView = (DragNDropExpandableListView) rootView.findViewById(android.R.id.list); mListView.setFastScrollEnabled(true); mListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); mListView.setOnChildClickListener(new ExpandableListView.OnChildClickListener() { @Override//from w w w. j a va 2s. c o m public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { startActivity(new Intent(Intent.ACTION_EDIT).setData(FeedColumns.CONTENT_URI(id))); return true; } }); mListView.setOnGroupClickListener(new ExpandableListView.OnGroupClickListener() { @Override public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) { if (v.findViewById(R.id.indicator).getVisibility() != View.VISIBLE) { // This is no a real group startActivity(new Intent(Intent.ACTION_EDIT).setData(FeedColumns.CONTENT_URI(id))); return true; } return false; } }); mListView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { AppCompatActivity activity = (AppCompatActivity) getActivity(); if (activity != null) { String title = ((TextView) view.findViewById(android.R.id.text1)).getText().toString(); Matcher m = Pattern.compile("(.*) \\([0-9]+\\)$").matcher(title); if (m.matches()) { title = m.group(1); } long feedId = mListView.getItemIdAtPosition(position); ActionMode actionMode; if (view.findViewById(R.id.indicator).getVisibility() == View.VISIBLE) { // This is a group actionMode = activity.startSupportActionMode(mGroupActionModeCallback); } else { // This is a feed actionMode = activity.startSupportActionMode(mFeedActionModeCallback); } actionMode.setTag(new Pair<>(feedId, title)); mListView.setItemChecked(position, true); } return true; } }); mListView.setAdapter(new FeedsCursorAdapter(getActivity(), FeedColumns.GROUPS_CONTENT_URI)); mListView.setDragNDropListener(new DragNDropListener() { boolean fromHasGroupIndicator = false; @Override public void onStopDrag(View itemView) { } @Override public void onStartDrag(View itemView) { fromHasGroupIndicator = itemView.findViewById(R.id.indicator).getVisibility() == View.VISIBLE; } @Override public void onDrop(final int flatPosFrom, final int flatPosTo) { final boolean fromIsGroup = ExpandableListView.getPackedPositionType(mListView .getExpandableListPosition(flatPosFrom)) == ExpandableListView.PACKED_POSITION_TYPE_GROUP; final boolean toIsGroup = ExpandableListView.getPackedPositionType(mListView .getExpandableListPosition(flatPosTo)) == ExpandableListView.PACKED_POSITION_TYPE_GROUP; final boolean fromIsFeedWithoutGroup = fromIsGroup && !fromHasGroupIndicator; View toView = mListView.getChildAt(flatPosTo - mListView.getFirstVisiblePosition()); boolean toIsFeedWithoutGroup = toIsGroup && toView.findViewById(R.id.indicator).getVisibility() != View.VISIBLE; final long packedPosTo = mListView.getExpandableListPosition(flatPosTo); final int packedGroupPosTo = ExpandableListView.getPackedPositionGroup(packedPosTo); if ((fromIsFeedWithoutGroup || !fromIsGroup) && toIsGroup && !toIsFeedWithoutGroup) { new AlertDialog.Builder(getActivity()) // .setTitle(R.string.to_group_title) // .setMessage(R.string.to_group_message) // .setPositiveButton(R.string.to_group_into, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { ContentValues values = new ContentValues(); values.put(FeedColumns.PRIORITY, 1); values.put(FeedColumns.GROUP_ID, mListView.getItemIdAtPosition(flatPosTo)); ContentResolver cr = getActivity().getContentResolver(); cr.update(FeedColumns.CONTENT_URI(mListView.getItemIdAtPosition(flatPosFrom)), values, null, null); cr.notifyChange(FeedColumns.GROUPS_CONTENT_URI, null); } }).setNegativeButton(R.string.to_group_above, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { moveItem(fromIsGroup, toIsGroup, fromIsFeedWithoutGroup, packedPosTo, packedGroupPosTo, flatPosFrom); } }).show(); } else { moveItem(fromIsGroup, toIsGroup, fromIsFeedWithoutGroup, packedPosTo, packedGroupPosTo, flatPosFrom); } } @Override public void onDrag(int x, int y, ListView listView) { } }); return rootView; }