@Override public void onStart() { super.onStart(); IntentFilter filter = new IntentFilter(); filter.addAction(ApolloService.META_CHANGED); filter.addAction(ApolloService.QUEUE_CHANGED); filter.addAction(ApolloService.PLAYSTATE_CHANGED); getActivity().registerReceiver(mMediaStatusReceiver, filter); }
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); isEditMode(); // Adapter mTrackAdapter = new TrackAdapter( getActivity(), R.layout.listview_items, null, new String[] {}, new int[] {}, 0); mListView.setOnCreateContextMenuListener(this); mListView.setOnItemClickListener(this); mListView.setAdapter(mTrackAdapter); // Important! getLoaderManager().initLoader(0, null, this); }
@Override public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) { menu.add(0, PLAY_SELECTION, 0, getResources().getString(R.string.play_all)); menu.add(0, ADD_TO_PLAYLIST, 0, getResources().getString(R.string.add_to_playlist)); menu.add(0, USE_AS_RINGTONE, 0, getResources().getString(R.string.use_as_ringtone)); if (mEditMode) { menu.add(0, REMOVE, 0, R.string.remove); } menu.add(0, SEARCH, 0, getResources().getString(R.string.search)); AdapterContextMenuInfo mi = (AdapterContextMenuInfo) menuInfo; mSelectedPosition = mi.position; mCursor.moveToPosition(mSelectedPosition); try { mSelectedId = mCursor.getLong(mMediaIdIndex); } catch (IllegalArgumentException ex) { mSelectedId = mi.id; } String title = mCursor.getString(mTitleIndex); menu.setHeaderTitle(title); super.onCreateContextMenu(menu, v, menuInfo); }
@Override public void onStop() { getActivity().unregisterReceiver(mMediaStatusReceiver); super.onStop(); }
@Override public void onSaveInstanceState(Bundle outState) { outState.putAll(getArguments() != null ? getArguments() : new Bundle()); super.onSaveInstanceState(outState); }