use of android.support.v7.app.AppCompatActivity in project FastAdapter by mikepenz.
the class ExpandableMultiselectDeleteSampleActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
findViewById(android.R.id.content).setSystemUiVisibility(findViewById(android.R.id.content).getSystemUiVisibility() | View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
//as we use an icon from Android-Iconics via xml we add the IconicsLayoutInflater
//https://github.com/mikepenz/Android-Iconics
LayoutInflaterCompat.setFactory(getLayoutInflater(), new IconicsLayoutInflater(getDelegate()));
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_sample);
// get RecyclerView
final RecyclerView rv = (RecyclerView) findViewById(R.id.rv);
// Handle Toolbar
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setTitle(R.string.sample_collapsible);
//style our ui
new MaterializeBuilder().withActivity(this).build();
//create our FastAdapter
fastItemAdapter = new FastItemAdapter<>();
fastItemAdapter.withPositionBasedStateManagement(false).withSelectable(true).withMultiSelect(true).withSelectOnLongClick(true).withOnPreClickListener(new FastAdapter.OnClickListener<IItem>() {
@Override
public boolean onClick(View v, IAdapter<IItem> adapter, IItem item, int position) {
//we handle the default onClick behavior for the actionMode. This will return null if it didn't do anything and you can handle a normal onClick
Boolean res = mActionModeHelper.onClick(ExpandableMultiselectDeleteSampleActivity.this, item);
// so that the click listener is not fired
if (res != null && !res)
return true;
return res != null ? res : false;
}
}).withOnClickListener(new FastAdapter.OnClickListener<IItem>() {
@Override
public boolean onClick(View v, IAdapter<IItem> adapter, IItem item, int position) {
// check if the actionMode consumes the click. This returns true, if it does, false if not
if (!mActionModeHelper.isActive())
Toast.makeText(ExpandableMultiselectDeleteSampleActivity.this, ((SimpleSubItem) item).name + " clicked!", Toast.LENGTH_SHORT).show();
// else
// mFastAdapter.notifyItemChanged(position); // im Bsp. ist das nicht nötig, k.A. warum ich das machen muss!
mRangeSelectorHelper.onClick();
return false;
}
}).withOnPreLongClickListener(new FastAdapter.OnLongClickListener<IItem>() {
@Override
public boolean onLongClick(View v, IAdapter<IItem> adapter, IItem item, int position) {
boolean actionModeWasActive = mActionModeHelper.isActive();
ActionMode actionMode = mActionModeHelper.onLongClick((AppCompatActivity) ExpandableMultiselectDeleteSampleActivity.this, position);
mRangeSelectorHelper.onLongClick(position);
if (actionMode != null) {
//we want color our CAB
ExpandableMultiselectDeleteSampleActivity.this.findViewById(R.id.action_mode_bar).setBackgroundColor(UIUtils.getThemeColorFromAttrOrRes(ExpandableMultiselectDeleteSampleActivity.this, R.attr.colorPrimary, R.color.material_drawer_primary));
// start the drag selection
mDragSelectTouchListener.startDragSelection(position);
}
//if we have no actionMode we do not consume the event
return actionMode != null && !actionModeWasActive;
}
});
// provide a custom title provider that even shows the count of sub items
mActionModeHelper = new ActionModeHelper(fastItemAdapter, R.menu.cab, new ActionBarCallBack()).withTitleProvider(new ActionModeHelper.ActionModeTitleProvider() {
@Override
public String getTitle(int selected) {
return selected + "/" + SubItemUtil.countItems(fastItemAdapter.getItemAdapter(), false);
}
}).withSupportSubItems(true);
// this will take care of selecting range of items via long press on the first and afterwards on the last item
mRangeSelectorHelper = new RangeSelectorHelper(fastItemAdapter).withSavedInstanceState(savedInstanceState).withActionModeHelper(mActionModeHelper);
// setup the drag select listener and add it to the RecyclerView
mDragSelectTouchListener = new DragSelectTouchListener().withSelectListener(new DragSelectTouchListener.OnDragSelectListener() {
@Override
public void onSelectChange(int start, int end, boolean isSelected) {
mRangeSelectorHelper.selectRange(start, end, isSelected, true);
// we handled the long press, so we reset the range selector
mRangeSelectorHelper.reset();
}
});
rv.addOnItemTouchListener(mDragSelectTouchListener);
// do basic RecyclerView setup
rv.setLayoutManager(new LinearLayoutManager(this));
rv.setItemAnimator(new SlideDownAlphaAnimator());
rv.setAdapter(fastItemAdapter);
//fill with some sample data
List<IItem> items = new ArrayList<>();
for (int i = 0; i < 20; i++) {
if (i % 2 == 0) {
final HeaderSelectionItem expandableItem = new HeaderSelectionItem();
expandableItem.withSubSelectionProvider(new HeaderSelectionItem.ISubSelectionProvider() {
@Override
public int getSelectedSubItems() {
return SubItemUtil.countSelectedSubItems(fastItemAdapter, expandableItem);
}
}).withName("Test " + (i + 1)).withDescription("ID: " + (i + 1)).withIdentifier(i + 1);
//.withIsExpanded(true) don't use this in such a setup, use adapter.expand() to expand all items instead
//add subitems so we can showcase the collapsible functionality
List<IItem> subItems = new LinkedList<>();
for (int ii = 1; ii <= 5; ii++) {
final SimpleSubItem sampleItem = new SimpleSubItem();
sampleItem.withName("-- Test " + (i + 1) + "." + ii).withDescription("ID: " + (i + 1) * 100 + ii).withIdentifier((i + 1) * 100 + ii);
subItems.add(sampleItem);
}
expandableItem.withSubItems(subItems);
items.add(expandableItem);
} else {
SimpleSubItem sampleItem = new SimpleSubItem();
sampleItem.withName("Test " + (i + 1)).withDescription("ID: " + (i + 1)).withIdentifier(i + 1);
items.add(sampleItem);
}
}
fastItemAdapter.add(items);
fastItemAdapter.expand();
fastItemAdapter.withSelectionListener(new ISelectionListener() {
@Override
public void onSelectionChanged(IItem item, boolean selected) {
if (item instanceof SimpleSubItem) {
IItem headerItem = ((SimpleSubItem) item).getParent();
if (headerItem != null) {
int pos = fastItemAdapter.getAdapterPosition(headerItem);
// Important: notify the header directly, not via the notifyadapterItemChanged!
// we just want to update the view and we are sure, nothing else has to be done
fastItemAdapter.notifyItemChanged(pos);
}
}
}
});
//restore selections (this has to be done after the items were added
fastItemAdapter.withSavedInstanceState(savedInstanceState);
//set the back arrow in the toolbar
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(false);
// restore action mode
if (savedInstanceState != null)
mActionModeHelper.checkActionMode(this);
}
use of android.support.v7.app.AppCompatActivity in project Timber by naman14.
the class BaseNowplayingFragment method setSongDetails.
public void setSongDetails(View view) {
albumart = (ImageView) view.findViewById(R.id.album_art);
shuffle = (ImageView) view.findViewById(R.id.shuffle);
repeat = (ImageView) view.findViewById(R.id.repeat);
next = (MaterialIconView) view.findViewById(R.id.next);
previous = (MaterialIconView) view.findViewById(R.id.previous);
mPlayPause = (PlayPauseButton) view.findViewById(R.id.playpause);
playPauseFloating = (FloatingActionButton) view.findViewById(R.id.playpausefloating);
playPauseWrapper = view.findViewById(R.id.playpausewrapper);
songtitle = (TextView) view.findViewById(R.id.song_title);
songalbum = (TextView) view.findViewById(R.id.song_album);
songartist = (TextView) view.findViewById(R.id.song_artist);
songduration = (TextView) view.findViewById(R.id.song_duration);
elapsedtime = (TextView) view.findViewById(R.id.song_elapsed_time);
timelyView11 = (TimelyView) view.findViewById(R.id.timelyView11);
timelyView12 = (TimelyView) view.findViewById(R.id.timelyView12);
timelyView13 = (TimelyView) view.findViewById(R.id.timelyView13);
timelyView14 = (TimelyView) view.findViewById(R.id.timelyView14);
timelyView15 = (TimelyView) view.findViewById(R.id.timelyView15);
hourColon = (TextView) view.findViewById(R.id.hour_colon);
mProgress = (SeekBar) view.findViewById(R.id.song_progress);
mCircularProgress = (CircularSeekBar) view.findViewById(R.id.song_progress_circular);
recyclerView = (RecyclerView) view.findViewById(R.id.queue_recyclerview);
Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
if (toolbar != null) {
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
final ActionBar ab = ((AppCompatActivity) getActivity()).getSupportActionBar();
ab.setDisplayHomeAsUpEnabled(true);
ab.setTitle("");
}
if (mPlayPause != null && getActivity() != null) {
mPlayPause.setColor(ContextCompat.getColor(getContext(), android.R.color.white));
}
if (playPauseFloating != null) {
playPauseDrawable.setColorFilter(TimberUtils.getBlackWhiteColor(accentColor), PorterDuff.Mode.MULTIPLY);
playPauseFloating.setImageDrawable(playPauseDrawable);
if (MusicPlayer.isPlaying())
playPauseDrawable.transformToPause(false);
else
playPauseDrawable.transformToPlay(false);
}
if (mCircularProgress != null) {
mCircularProgress.setCircleProgressColor(accentColor);
mCircularProgress.setPointerColor(accentColor);
mCircularProgress.setPointerHaloColor(accentColor);
}
if (timelyView11 != null) {
String time = TimberUtils.makeShortTimeString(getActivity(), MusicPlayer.position() / 1000);
if (time.length() < 5) {
timelyView11.setVisibility(View.GONE);
timelyView12.setVisibility(View.GONE);
hourColon.setVisibility(View.GONE);
changeDigit(timelyView13, time.charAt(0) - '0');
changeDigit(timelyView14, time.charAt(2) - '0');
changeDigit(timelyView15, time.charAt(3) - '0');
} else if (time.length() == 5) {
timelyView12.setVisibility(View.VISIBLE);
changeDigit(timelyView12, time.charAt(0) - '0');
changeDigit(timelyView13, time.charAt(1) - '0');
changeDigit(timelyView14, time.charAt(3) - '0');
changeDigit(timelyView15, time.charAt(4) - '0');
} else {
timelyView11.setVisibility(View.VISIBLE);
hourColon.setVisibility(View.VISIBLE);
changeDigit(timelyView11, time.charAt(0) - '0');
changeDigit(timelyView12, time.charAt(2) - '0');
changeDigit(timelyView13, time.charAt(3) - '0');
changeDigit(timelyView14, time.charAt(5) - '0');
changeDigit(timelyView15, time.charAt(6) - '0');
}
}
setSongDetails();
}
use of android.support.v7.app.AppCompatActivity in project Timber by naman14.
the class AlbumSongsAdapter method setOnPopupMenuListener.
private void setOnPopupMenuListener(ItemHolder itemHolder, final int position) {
itemHolder.menu.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final PopupMenu menu = new PopupMenu(mContext, v);
menu.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch(item.getItemId()) {
case R.id.popup_song_play:
MusicPlayer.playAll(mContext, songIDs, position, -1, TimberUtils.IdType.NA, false);
break;
case R.id.popup_song_play_next:
long[] ids = new long[1];
ids[0] = arraylist.get(position).id;
MusicPlayer.playNext(mContext, ids, -1, TimberUtils.IdType.NA);
break;
case R.id.popup_song_goto_album:
NavigationUtils.goToAlbum(mContext, arraylist.get(position).albumId);
break;
case R.id.popup_song_goto_artist:
NavigationUtils.goToArtist(mContext, arraylist.get(position).artistId);
break;
case R.id.popup_song_addto_queue:
long[] id = new long[1];
id[0] = arraylist.get(position).id;
MusicPlayer.addToQueue(mContext, id, -1, TimberUtils.IdType.NA);
break;
case R.id.popup_song_addto_playlist:
AddPlaylistDialog.newInstance(arraylist.get(position)).show(((AppCompatActivity) mContext).getSupportFragmentManager(), "ADD_PLAYLIST");
break;
case R.id.popup_song_share:
TimberUtils.shareTrack(mContext, arraylist.get(position).id);
break;
case R.id.popup_song_delete:
long[] deleteIds = { arraylist.get(position).id };
TimberUtils.showDeleteDialog(mContext, arraylist.get(position).title, deleteIds, AlbumSongsAdapter.this, position);
break;
}
return false;
}
});
menu.inflate(R.menu.popup_song);
menu.show();
}
});
}
use of android.support.v7.app.AppCompatActivity in project Timber by naman14.
the class MainFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container, false);
Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
final ActionBar ab = ((AppCompatActivity) getActivity()).getSupportActionBar();
ab.setHomeAsUpIndicator(R.drawable.ic_menu);
ab.setDisplayHomeAsUpEnabled(true);
viewPager = (ViewPager) rootView.findViewById(R.id.viewpager);
if (viewPager != null) {
setupViewPager(viewPager);
viewPager.setOffscreenPageLimit(2);
}
TabLayout tabLayout = (TabLayout) rootView.findViewById(R.id.tabs);
tabLayout.setupWithViewPager(viewPager);
return rootView;
}
use of android.support.v7.app.AppCompatActivity in project Timber by naman14.
the class PlaylistFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_playlist, container, false);
Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.toolbar);
pager = (MultiViewPager) rootView.findViewById(R.id.playlistpager);
recyclerView = (RecyclerView) rootView.findViewById(R.id.recyclerview);
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
final ActionBar ab = ((AppCompatActivity) getActivity()).getSupportActionBar();
ab.setHomeAsUpIndicator(R.drawable.ic_menu);
ab.setDisplayHomeAsUpEnabled(true);
ab.setTitle(R.string.playlists);
playlists = PlaylistLoader.getPlaylists(getActivity(), showAuto);
playlistcount = playlists.size();
if (isDefault) {
initPager();
} else {
initRecyclerView();
}
return rootView;
}
Aggregations