use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.
the class SongDetailDialog method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Activity context = getActivity();
final Song song = getArguments().getParcelable("song");
MaterialDialog dialog = new MaterialDialog.Builder(context).customView(R.layout.dialog_file_details, true).title(context.getResources().getString(R.string.label_details)).positiveText(android.R.string.ok).build();
View dialogView = dialog.getCustomView();
final TextView fileName = dialogView.findViewById(R.id.file_name);
final TextView filePath = dialogView.findViewById(R.id.file_path);
final TextView fileSize = dialogView.findViewById(R.id.file_size);
final TextView fileFormat = dialogView.findViewById(R.id.file_format);
final TextView trackLength = dialogView.findViewById(R.id.track_length);
final TextView bitRate = dialogView.findViewById(R.id.bitrate);
final TextView samplingRate = dialogView.findViewById(R.id.sampling_rate);
fileName.setText(makeTextWithTitle(context, R.string.label_file_name, "-"));
filePath.setText(makeTextWithTitle(context, R.string.label_file_path, "-"));
fileSize.setText(makeTextWithTitle(context, R.string.label_file_size, "-"));
fileFormat.setText(makeTextWithTitle(context, R.string.label_file_format, "-"));
trackLength.setText(makeTextWithTitle(context, R.string.label_track_length, "-"));
bitRate.setText(makeTextWithTitle(context, R.string.label_bit_rate, "-"));
samplingRate.setText(makeTextWithTitle(context, R.string.label_sampling_rate, "-"));
if (song != null) {
final File songFile = new File(song.data);
if (songFile.exists()) {
fileName.setText(makeTextWithTitle(context, R.string.label_file_name, songFile.getName()));
filePath.setText(makeTextWithTitle(context, R.string.label_file_path, songFile.getAbsolutePath()));
fileSize.setText(makeTextWithTitle(context, R.string.label_file_size, getFileSizeString(songFile.length())));
try {
AudioFile audioFile = AudioFileIO.read(songFile);
AudioHeader audioHeader = audioFile.getAudioHeader();
fileFormat.setText(makeTextWithTitle(context, R.string.label_file_format, audioHeader.getFormat()));
trackLength.setText(makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(audioHeader.getTrackLength() * 1000)));
bitRate.setText(makeTextWithTitle(context, R.string.label_bit_rate, audioHeader.getBitRate() + " kb/s"));
samplingRate.setText(makeTextWithTitle(context, R.string.label_sampling_rate, audioHeader.getSampleRate() + " Hz"));
} catch (@NonNull CannotReadException | IOException | TagException | ReadOnlyFileException | InvalidAudioFrameException e) {
Log.e(TAG, "error while reading the song file", e);
// fallback
trackLength.setText(makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(song.duration)));
}
} else {
// fallback
fileName.setText(makeTextWithTitle(context, R.string.label_file_name, song.title));
trackLength.setText(makeTextWithTitle(context, R.string.label_track_length, MusicUtil.getReadableDurationString(song.duration)));
}
}
return dialog;
}
use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.
the class SongShareDialog method onCreateDialog.
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Song song = getArguments().getParcelable("song");
final String currentlyListening = getString(R.string.currently_listening_to_x_by_x, song.title, song.artistName);
return new MaterialDialog.Builder(getActivity()).title(R.string.what_do_you_want_to_share).items(getString(R.string.the_audio_file), "\u201C" + currentlyListening + "\u201D").itemsCallback((materialDialog, view, i, charSequence) -> {
switch(i) {
case 0:
startActivity(Intent.createChooser(MusicUtil.createShareSongFileIntent(song, getContext()), null));
break;
case 1:
getActivity().startActivity(Intent.createChooser(new Intent().setAction(Intent.ACTION_SEND).putExtra(Intent.EXTRA_TEXT, currentlyListening).setType("text/plain"), null));
break;
}
}).build();
}
use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.
the class ShuffleHelper method makeShuffleList.
public static void makeShuffleList(@NonNull List<Song> listToShuffle, final int current) {
if (listToShuffle.isEmpty())
return;
if (current >= 0) {
Song song = listToShuffle.remove(current);
Collections.shuffle(listToShuffle);
listToShuffle.add(0, song);
} else {
Collections.shuffle(listToShuffle);
}
}
use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.
the class AlbumLoader method getAlbum.
@NonNull
public static Album getAlbum(@NonNull final Context context, long albumId) {
List<Song> songs = SongLoader.getSongs(SongLoader.makeSongCursor(context, AudioColumns.ALBUM_ID + "=?", new String[] { String.valueOf(albumId) }, getSongLoaderSortOrder(context)));
Album album = new Album(songs);
sortSongsByTrackNumber(album);
return album;
}
use of com.kabouzeid.gramophone.model.Song in project Phonograph by kabouzeid.
the class AppWidgetCard method performUpdate.
/**
* Update all active widget instances by pushing changes
*/
public void performUpdate(final MusicService service, final int[] appWidgetIds) {
final RemoteViews appWidgetView = new RemoteViews(service.getPackageName(), R.layout.app_widget_card);
final boolean isPlaying = service.isPlaying();
final Song song = service.getCurrentSong();
// Set the titles and artwork
if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
} else {
appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE);
appWidgetView.setTextViewText(R.id.title, song.title);
appWidgetView.setTextViewText(R.id.text, getSongArtistAndAlbum(song));
}
// Set correct drawable for pause state
int playPauseRes = isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, playPauseRes, MaterialValueHelper.getSecondaryTextColor(service, true))));
// Set prev/next button drawables
appWidgetView.setImageViewBitmap(R.id.button_next, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getSecondaryTextColor(service, true))));
appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(service, true))));
// Link actions buttons to intents
linkButtons(service, appWidgetView);
if (imageSize == 0)
imageSize = service.getResources().getDimensionPixelSize(R.dimen.app_widget_card_image_size);
if (cardRadius == 0f)
cardRadius = service.getResources().getDimension(R.dimen.app_widget_card_radius);
// Load the album cover async and push the update on completion
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().centerCrop().into(new SimpleTarget<BitmapPaletteWrapper>(imageSize, imageSize) {
@Override
public void onResourceReady(BitmapPaletteWrapper resource, GlideAnimation<? super BitmapPaletteWrapper> glideAnimation) {
Palette palette = resource.getPalette();
update(resource.getBitmap(), palette.getVibrantColor(palette.getMutedColor(MaterialValueHelper.getSecondaryTextColor(service, true))));
}
@Override
public void onLoadFailed(Exception e, Drawable errorDrawable) {
super.onLoadFailed(e, errorDrawable);
update(null, MaterialValueHelper.getSecondaryTextColor(service, true));
}
private void update(@Nullable Bitmap bitmap, int color) {
// Set correct drawable for pause state
int playPauseRes = isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, playPauseRes, color)));
// Set prev/next button drawables
appWidgetView.setImageViewBitmap(R.id.button_next, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, color)));
appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, color)));
final Drawable image = getAlbumArtDrawable(service.getResources(), bitmap);
final Bitmap roundedBitmap = createRoundedBitmap(image, imageSize, imageSize, cardRadius, 0, cardRadius, 0);
appWidgetView.setImageViewBitmap(R.id.image, roundedBitmap);
pushUpdate(service, appWidgetIds, appWidgetView);
}
});
}
});
}
Aggregations