Search in sources :

Example 6 with Song

use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.

the class PlayingNotificationImpl method update.

@Override
public synchronized void update() {
    stopped = false;
    final Song song = service.getCurrentSong();
    final boolean isPlaying = service.isPlaying();
    final RemoteViews notificationLayout = new RemoteViews(service.getPackageName(), R.layout.notification);
    final RemoteViews notificationLayoutBig = new RemoteViews(service.getPackageName(), R.layout.notification_big);
    if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
        notificationLayout.setViewVisibility(R.id.media_titles, View.INVISIBLE);
    } else {
        notificationLayout.setViewVisibility(R.id.media_titles, View.VISIBLE);
        notificationLayout.setTextViewText(R.id.title, song.title);
        notificationLayout.setTextViewText(R.id.text, song.artistName);
    }
    if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName) && TextUtils.isEmpty(song.albumName)) {
        notificationLayoutBig.setViewVisibility(R.id.media_titles, View.INVISIBLE);
    } else {
        notificationLayoutBig.setViewVisibility(R.id.media_titles, View.VISIBLE);
        notificationLayoutBig.setTextViewText(R.id.title, song.title);
        notificationLayoutBig.setTextViewText(R.id.text, song.artistName);
        notificationLayoutBig.setTextViewText(R.id.text2, song.albumName);
    }
    linkButtons(notificationLayout, notificationLayoutBig);
    Intent action = new Intent(service, MainActivity.class);
    action.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    final PendingIntent clickIntent = PendingIntent.getActivity(service, 0, action, 0);
    final PendingIntent deleteIntent = buildPendingIntent(service, MusicService.ACTION_QUIT, null);
    final Notification notification = new NotificationCompat.Builder(service, NOTIFICATION_CHANNEL_ID).setSmallIcon(R.drawable.ic_notification).setContentIntent(clickIntent).setDeleteIntent(deleteIntent).setCategory(NotificationCompat.CATEGORY_SERVICE).setPriority(NotificationCompat.PRIORITY_MAX).setVisibility(NotificationCompat.VISIBILITY_PUBLIC).setContent(notificationLayout).setCustomBigContentView(notificationLayoutBig).setOngoing(isPlaying).build();
    final int bigNotificationImageSize = service.getResources().getDimensionPixelSize(R.dimen.notification_big_image_size);
    service.runOnUiThread(new Runnable() {

        @Override
        public void run() {
            if (target != null) {
                Glide.clear(target);
            }
            target = SongGlideRequest.Builder.from(Glide.with(service), song).checkIgnoreMediaStore(service).generatePalette(service).build().into(new SimpleTarget<BitmapPaletteWrapper>(bigNotificationImageSize, bigNotificationImageSize) {

                @Override
                public void onResourceReady(BitmapPaletteWrapper resource, GlideAnimation<? super BitmapPaletteWrapper> glideAnimation) {
                    update(resource.getBitmap(), PhonographColorUtil.getColor(resource.getPalette(), Color.TRANSPARENT));
                }

                @Override
                public void onLoadFailed(Exception e, Drawable errorDrawable) {
                    super.onLoadFailed(e, errorDrawable);
                    update(null, Color.WHITE);
                }

                private void update(@Nullable Bitmap bitmap, int bgColor) {
                    if (bitmap != null) {
                        notificationLayout.setImageViewBitmap(R.id.image, bitmap);
                        notificationLayoutBig.setImageViewBitmap(R.id.image, bitmap);
                    } else {
                        notificationLayout.setImageViewResource(R.id.image, R.drawable.default_album_art);
                        notificationLayoutBig.setImageViewResource(R.id.image, R.drawable.default_album_art);
                    }
                    if (!PreferenceUtil.getInstance(service).coloredNotification()) {
                        bgColor = Color.WHITE;
                    }
                    setBackgroundColor(bgColor);
                    setNotificationContent(ColorUtil.isColorLight(bgColor));
                    if (stopped)
                        // notification has been stopped before loading was finished
                        return;
                    updateNotifyModeAndPostNotification(notification);
                }

                private void setBackgroundColor(int color) {
                    notificationLayout.setInt(R.id.root, "setBackgroundColor", color);
                    notificationLayoutBig.setInt(R.id.root, "setBackgroundColor", color);
                }

                private void setNotificationContent(boolean dark) {
                    int primary = MaterialValueHelper.getPrimaryTextColor(service, dark);
                    int secondary = MaterialValueHelper.getSecondaryTextColor(service, dark);
                    Bitmap prev = ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, primary), 1.5f);
                    Bitmap next = ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, primary), 1.5f);
                    Bitmap playPause = ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp, primary), 1.5f);
                    notificationLayout.setTextColor(R.id.title, primary);
                    notificationLayout.setTextColor(R.id.text, secondary);
                    notificationLayout.setImageViewBitmap(R.id.action_prev, prev);
                    notificationLayout.setImageViewBitmap(R.id.action_next, next);
                    notificationLayout.setImageViewBitmap(R.id.action_play_pause, playPause);
                    notificationLayoutBig.setTextColor(R.id.title, primary);
                    notificationLayoutBig.setTextColor(R.id.text, secondary);
                    notificationLayoutBig.setTextColor(R.id.text2, secondary);
                    notificationLayoutBig.setImageViewBitmap(R.id.action_prev, prev);
                    notificationLayoutBig.setImageViewBitmap(R.id.action_next, next);
                    notificationLayoutBig.setImageViewBitmap(R.id.action_play_pause, playPause);
                }
            });
        }
    });
}
Also used : BitmapPaletteWrapper(com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) Notification(android.app.Notification) Song(com.kabouzeid.gramophone.model.Song) RemoteViews(android.widget.RemoteViews) Bitmap(android.graphics.Bitmap) PendingIntent(android.app.PendingIntent)

Example 7 with Song

use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.

the class AlbumDetailActivity method onOptionsItemSelected.

@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
    int id = item.getItemId();
    final List<Song> songs = adapter.getDataSet();
    switch(id) {
        case R.id.action_sleep_timer:
            new SleepTimerDialog().show(getSupportFragmentManager(), "SET_SLEEP_TIMER");
            return true;
        case R.id.action_equalizer:
            NavigationUtil.openEqualizer(this);
            return true;
        case R.id.action_shuffle_album:
            MusicPlayerRemote.openAndShuffleQueue(songs, true);
            return true;
        case R.id.action_play_next:
            MusicPlayerRemote.playNext(songs);
            return true;
        case R.id.action_add_to_current_playing:
            MusicPlayerRemote.enqueue(songs);
            return true;
        case R.id.action_add_to_playlist:
            AddToPlaylistDialog.create(songs).show(getSupportFragmentManager(), "ADD_PLAYLIST");
            return true;
        case R.id.action_delete_from_device:
            DeleteSongsDialog.create(songs).show(getSupportFragmentManager(), "DELETE_SONGS");
            return true;
        case android.R.id.home:
            super.onBackPressed();
            return true;
        case R.id.action_tag_editor:
            Intent intent = new Intent(this, AlbumTagEditorActivity.class);
            intent.putExtra(AbsTagEditorActivity.EXTRA_ID, getAlbum().getId());
            startActivityForResult(intent, TAG_EDITOR_REQUEST);
            return true;
        case R.id.action_go_to_artist:
            NavigationUtil.goToArtist(this, getAlbum().getArtistId());
            return true;
        case R.id.action_wiki:
            if (wikiDialog == null) {
                wikiDialog = new MaterialDialog.Builder(this).title(album.getTitle()).positiveText(android.R.string.ok).build();
            }
            if (PreferenceUtil.isAllowedToDownloadMetadata(this)) {
                if (wiki != null) {
                    wikiDialog.setContent(wiki);
                    wikiDialog.show();
                } else {
                    Toast.makeText(this, getResources().getString(R.string.wiki_unavailable), Toast.LENGTH_SHORT).show();
                }
            } else {
                wikiDialog.show();
                loadWiki();
            }
            return true;
    }
    return super.onOptionsItemSelected(item);
}
Also used : Song(com.kabouzeid.gramophone.model.Song) SleepTimerDialog(com.kabouzeid.gramophone.dialogs.SleepTimerDialog) Intent(android.content.Intent)

Example 8 with Song

use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.

the class PlaylistDetailActivity method setUpRecyclerView.

private void setUpRecyclerView() {
    ViewUtil.setUpFastScrollRecyclerViewColor(this, ((FastScrollRecyclerView) recyclerView), ThemeStore.accentColor(this));
    recyclerView.setLayoutManager(new LinearLayoutManager(this));
    if (playlist instanceof AbsCustomPlaylist) {
        adapter = new PlaylistSongAdapter(this, new ArrayList<>(), R.layout.item_list, false, this);
        recyclerView.setAdapter(adapter);
    } else {
        recyclerViewDragDropManager = new RecyclerViewDragDropManager();
        final GeneralItemAnimator animator = new RefactoredDefaultItemAnimator();
        adapter = new OrderablePlaylistSongAdapter(this, new ArrayList<>(), R.layout.item_list, false, this, (fromPosition, toPosition) -> {
            if (PlaylistsUtil.moveItem(PlaylistDetailActivity.this, playlist.id, fromPosition, toPosition)) {
                Song song = adapter.getDataSet().remove(fromPosition);
                adapter.getDataSet().add(toPosition, song);
                adapter.notifyItemMoved(fromPosition, toPosition);
            }
        });
        wrappedAdapter = recyclerViewDragDropManager.createWrappedAdapter(adapter);
        recyclerView.setAdapter(wrappedAdapter);
        recyclerView.setItemAnimator(animator);
        recyclerViewDragDropManager.attachRecyclerView(recyclerView);
    }
    adapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {

        @Override
        public void onChanged() {
            super.onChanged();
            checkIsEmpty();
        }
    });
}
Also used : MaterialCab(com.afollestad.materialcab.MaterialCab) Context(android.content.Context) Bundle(android.os.Bundle) ViewUtil(com.kabouzeid.gramophone.util.ViewUtil) ButterKnife(butterknife.ButterKnife) NonNull(androidx.annotation.NonNull) PlaylistSongLoader(com.kabouzeid.gramophone.loader.PlaylistSongLoader) MusicPlayerRemote(com.kabouzeid.gramophone.helper.MusicPlayerRemote) LoaderManager(androidx.loader.app.LoaderManager) WrappedAsyncTaskLoader(com.kabouzeid.gramophone.misc.WrappedAsyncTaskLoader) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) BindView(butterknife.BindView) ThemeStore(com.kabouzeid.appthemehelper.ThemeStore) Playlist(com.kabouzeid.gramophone.model.Playlist) LoaderIds(com.kabouzeid.gramophone.interfaces.LoaderIds) OrderablePlaylistSongAdapter(com.kabouzeid.gramophone.adapter.song.OrderablePlaylistSongAdapter) PlaylistsUtil(com.kabouzeid.gramophone.util.PlaylistsUtil) PhonographColorUtil(com.kabouzeid.gramophone.util.PhonographColorUtil) PlaylistLoader(com.kabouzeid.gramophone.loader.PlaylistLoader) Menu(android.view.Menu) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) RefactoredDefaultItemAnimator(com.h6ah4i.android.widget.advrecyclerview.animator.RefactoredDefaultItemAnimator) AbsCustomPlaylist(com.kabouzeid.gramophone.model.AbsCustomPlaylist) R(com.kabouzeid.gramophone.R) Loader(androidx.loader.content.Loader) WrapperAdapterUtils(com.h6ah4i.android.widget.advrecyclerview.utils.WrapperAdapterUtils) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) SongAdapter(com.kabouzeid.gramophone.adapter.song.SongAdapter) Song(com.kabouzeid.gramophone.model.Song) PlaylistMenuHelper(com.kabouzeid.gramophone.helper.menu.PlaylistMenuHelper) RecyclerViewDragDropManager(com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager) List(java.util.List) TextView(android.widget.TextView) AbsSlidingMusicPanelActivity(com.kabouzeid.gramophone.ui.activities.base.AbsSlidingMusicPanelActivity) GeneralItemAnimator(com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator) CabHolder(com.kabouzeid.gramophone.interfaces.CabHolder) PlaylistSongAdapter(com.kabouzeid.gramophone.adapter.song.PlaylistSongAdapter) Toolbar(androidx.appcompat.widget.Toolbar) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) OrderablePlaylistSongAdapter(com.kabouzeid.gramophone.adapter.song.OrderablePlaylistSongAdapter) PlaylistSongAdapter(com.kabouzeid.gramophone.adapter.song.PlaylistSongAdapter) ArrayList(java.util.ArrayList) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) RefactoredDefaultItemAnimator(com.h6ah4i.android.widget.advrecyclerview.animator.RefactoredDefaultItemAnimator) Song(com.kabouzeid.gramophone.model.Song) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) AbsCustomPlaylist(com.kabouzeid.gramophone.model.AbsCustomPlaylist) RecyclerView(androidx.recyclerview.widget.RecyclerView) FastScrollRecyclerView(com.simplecityapps.recyclerview_fastscroll.views.FastScrollRecyclerView) GeneralItemAnimator(com.h6ah4i.android.widget.advrecyclerview.animator.GeneralItemAnimator) OrderablePlaylistSongAdapter(com.kabouzeid.gramophone.adapter.song.OrderablePlaylistSongAdapter) RecyclerViewDragDropManager(com.h6ah4i.android.widget.advrecyclerview.draggable.RecyclerViewDragDropManager)

Example 9 with Song

use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.

the class PlayingNotificationImpl24 method update.

@Override
public synchronized void update() {
    stopped = false;
    final Song song = service.getCurrentSong();
    final boolean isPlaying = service.isPlaying();
    final int playButtonResId = isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
    Intent action = new Intent(service, MainActivity.class);
    action.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
    final PendingIntent clickIntent = PendingIntent.getActivity(service, 0, action, 0);
    final ComponentName serviceName = new ComponentName(service, MusicService.class);
    Intent intent = new Intent(MusicService.ACTION_QUIT);
    intent.setComponent(serviceName);
    final PendingIntent deleteIntent = PendingIntent.getService(service, 0, intent, 0);
    final int bigNotificationImageSize = service.getResources().getDimensionPixelSize(R.dimen.notification_big_image_size);
    service.runOnUiThread(() -> SongGlideRequest.Builder.from(Glide.with(service), song).checkIgnoreMediaStore(service).generatePalette(service).build().into(new SimpleTarget<BitmapPaletteWrapper>(bigNotificationImageSize, bigNotificationImageSize) {

        @Override
        public void onResourceReady(BitmapPaletteWrapper resource, GlideAnimation<? super BitmapPaletteWrapper> glideAnimation) {
            Palette palette = resource.getPalette();
            update(resource.getBitmap(), palette.getVibrantColor(palette.getMutedColor(Color.TRANSPARENT)));
        }

        @Override
        public void onLoadFailed(Exception e, Drawable errorDrawable) {
            update(null, Color.TRANSPARENT);
        }

        void update(Bitmap bitmap, int color) {
            if (bitmap == null)
                bitmap = BitmapFactory.decodeResource(service.getResources(), R.drawable.default_album_art);
            NotificationCompat.Action playPauseAction = new NotificationCompat.Action(playButtonResId, service.getString(R.string.action_play_pause), retrievePlaybackAction(ACTION_TOGGLE_PAUSE));
            NotificationCompat.Action previousAction = new NotificationCompat.Action(R.drawable.ic_skip_previous_white_24dp, service.getString(R.string.action_previous), retrievePlaybackAction(ACTION_REWIND));
            NotificationCompat.Action nextAction = new NotificationCompat.Action(R.drawable.ic_skip_next_white_24dp, service.getString(R.string.action_next), retrievePlaybackAction(ACTION_SKIP));
            NotificationCompat.Builder builder = new NotificationCompat.Builder(service, NOTIFICATION_CHANNEL_ID).setSmallIcon(R.drawable.ic_notification).setSubText(song.albumName).setLargeIcon(bitmap).setContentIntent(clickIntent).setDeleteIntent(deleteIntent).setContentTitle(song.title).setContentText(song.artistName).setOngoing(isPlaying).setShowWhen(false).addAction(previousAction).addAction(playPauseAction).addAction(nextAction);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                builder.setStyle(new MediaStyle().setMediaSession(service.getMediaSession().getSessionToken()).setShowActionsInCompactView(0, 1, 2)).setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
                if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O && PreferenceUtil.getInstance(service).coloredNotification())
                    builder.setColor(color);
            }
            if (stopped)
                // notification has been stopped before loading was finished
                return;
            updateNotifyModeAndPostNotification(builder.build());
        }
    }));
}
Also used : Palette(androidx.palette.graphics.Palette) MediaStyle(androidx.media.app.NotificationCompat.MediaStyle) BitmapPaletteWrapper(com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper) Drawable(android.graphics.drawable.Drawable) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) GlideAnimation(com.bumptech.glide.request.animation.GlideAnimation) SimpleTarget(com.bumptech.glide.request.target.SimpleTarget) Song(com.kabouzeid.gramophone.model.Song) Bitmap(android.graphics.Bitmap) NotificationCompat(androidx.core.app.NotificationCompat) ComponentName(android.content.ComponentName) PendingIntent(android.app.PendingIntent)

Example 10 with Song

use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.

the class MainActivity method updateNavigationDrawerHeader.

private void updateNavigationDrawerHeader() {
    if (!MusicPlayerRemote.getPlayingQueue().isEmpty()) {
        Song song = MusicPlayerRemote.getCurrentSong();
        if (navigationDrawerHeader == null) {
            navigationDrawerHeader = navigationView.inflateHeaderView(R.layout.navigation_drawer_header);
            // noinspection ConstantConditions
            navigationDrawerHeader.setOnClickListener(v -> {
                drawerLayout.closeDrawers();
                if (getPanelState() == SlidingUpPanelLayout.PanelState.COLLAPSED) {
                    expandPanel();
                }
            });
        }
        ((TextView) navigationDrawerHeader.findViewById(R.id.title)).setText(song.title);
        ((TextView) navigationDrawerHeader.findViewById(R.id.text)).setText(MusicUtil.getSongInfoString(song));
        SongGlideRequest.Builder.from(Glide.with(this), song).checkIgnoreMediaStore(this).build().into(((ImageView) navigationDrawerHeader.findViewById(R.id.image)));
    } else {
        if (navigationDrawerHeader != null) {
            navigationView.removeHeaderView(navigationDrawerHeader);
            navigationDrawerHeader = null;
        }
    }
}
Also used : Song(com.kabouzeid.gramophone.model.Song) TextView(android.widget.TextView) ImageView(android.widget.ImageView)

Aggregations

Song (com.kabouzeid.gramophone.model.Song)37 Drawable (android.graphics.drawable.Drawable)11 Intent (android.content.Intent)8 Bitmap (android.graphics.Bitmap)7 Point (android.graphics.Point)6 NonNull (androidx.annotation.NonNull)6 Activity (android.app.Activity)5 RemoteViews (android.widget.RemoteViews)5 BitmapPaletteWrapper (com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper)5 AbsSlidingMusicPanelActivity (com.kabouzeid.gramophone.ui.activities.base.AbsSlidingMusicPanelActivity)5 Context (android.content.Context)4 AsyncTask (android.os.AsyncTask)4 TextView (android.widget.TextView)4 AppCompatActivity (androidx.appcompat.app.AppCompatActivity)4 Palette (androidx.palette.graphics.Palette)4 PendingIntent (android.app.PendingIntent)3 View (android.view.View)3 SleepTimerDialog (com.kabouzeid.gramophone.dialogs.SleepTimerDialog)3 ArrayList (java.util.ArrayList)3 ContentValues (android.content.ContentValues)2