List of usage examples for android.widget ExpandableListView getPackedPositionChild
public static int getPackedPositionChild(long packedPosition)
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 ww. j a v a 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: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. ja v a 2 s .com*/ 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); }//ww w. jav a2 s . co m } }
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;/* w ww .j ava 2 s . c o m*/ 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 w ww .j a v a2 s . c om } } else { return false; } return true; }
From source file:com.money.manager.ex.home.HomeFragment.java
/** * Context menu for account entries./* w w w.ja v 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;/* w ww.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); }/*from w ww.jav a 2s.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:com.viktorrudometkin.burramys.fragment.EditFeedsListFragment.java
private void moveItem(boolean fromIsGroup, boolean toIsGroup, boolean fromIsFeedWithoutGroup, long packedPosTo, int packedGroupPosTo, int flatPosFrom) { ContentValues values = new ContentValues(); ContentResolver cr = getActivity().getContentResolver(); if (fromIsGroup && toIsGroup) { values.put(FeedColumns.PRIORITY, packedGroupPosTo + 1); cr.update(FeedColumns.CONTENT_URI(mListView.getItemIdAtPosition(flatPosFrom)), values, null, null); } else if (!fromIsGroup && toIsGroup) { values.put(FeedColumns.PRIORITY, packedGroupPosTo + 1); values.putNull(FeedColumns.GROUP_ID); cr.update(FeedColumns.CONTENT_URI(mListView.getItemIdAtPosition(flatPosFrom)), values, null, null); } else if ((!fromIsGroup && !toIsGroup) || (fromIsFeedWithoutGroup && !toIsGroup)) { int groupPrio = ExpandableListView.getPackedPositionChild(packedPosTo) + 1; values.put(FeedColumns.PRIORITY, groupPrio); int flatGroupPosTo = mListView .getFlatListPosition(ExpandableListView.getPackedPositionForGroup(packedGroupPosTo)); values.put(FeedColumns.GROUP_ID, mListView.getItemIdAtPosition(flatGroupPosTo)); cr.update(FeedColumns.CONTENT_URI(mListView.getItemIdAtPosition(flatPosFrom)), values, null, null); }//from ww w . java 2s . com }
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 w w.ja v 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; }