Added option to ignore media store artwork and instead loading it directly from the song file
This commit is contained in:
parent
da92636180
commit
1dcc447e52
25 changed files with 194 additions and 106 deletions
|
|
@ -0,0 +1,85 @@
|
|||
package com.kabouzeid.gramophone.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Point;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.Display;
|
||||
import android.view.WindowManager;
|
||||
|
||||
import org.jaudiotagger.audio.AudioFile;
|
||||
import org.jaudiotagger.audio.AudioFileIO;
|
||||
import org.jaudiotagger.audio.exceptions.CannotReadException;
|
||||
import org.jaudiotagger.audio.exceptions.InvalidAudioFrameException;
|
||||
import org.jaudiotagger.audio.exceptions.ReadOnlyFileException;
|
||||
import org.jaudiotagger.tag.TagException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @author Karim Abou Zeid (kabouzeid)
|
||||
*/
|
||||
public class ImageUtil {
|
||||
|
||||
@Nullable
|
||||
public static Bitmap getEmbeddedSongArt(File songFile, Context context) {
|
||||
try {
|
||||
AudioFile audioFile = AudioFileIO.read(songFile);
|
||||
byte[] data = audioFile.getTag().getFirstArtwork().getBinaryData();
|
||||
if (data != null) {
|
||||
final BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inPreferredConfig = Bitmap.Config.RGB_565;
|
||||
options.inJustDecodeBounds = true;
|
||||
BitmapFactory.decodeByteArray(data, 0, data.length, options);
|
||||
// Calculate inSampleSize
|
||||
options.inSampleSize = calculateInSampleSize(options, context);
|
||||
// Decode bitmap with inSampleSize set
|
||||
options.inJustDecodeBounds = false;
|
||||
return BitmapFactory.decodeByteArray(data, 0, data.length, options);
|
||||
}
|
||||
} catch (CannotReadException | TagException | IOException | ReadOnlyFileException | InvalidAudioFrameException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static int calculateInSampleSize(BitmapFactory.Options options, Context context) {
|
||||
|
||||
// Raw height and width of image
|
||||
final int height = options.outHeight;
|
||||
final int width = options.outWidth;
|
||||
int reqLength = Math.round(getSmallerScreenSize(context) * 1.5f); // absolute maximum size the album art will ever have
|
||||
|
||||
// setting reqWidth matching to desired 1:1 ratio and screen-size
|
||||
if (width < height) {
|
||||
reqLength = (height / width) * reqLength;
|
||||
} else {
|
||||
reqLength = (width / height) * reqLength;
|
||||
}
|
||||
|
||||
int inSampleSize = 1;
|
||||
|
||||
if (height > reqLength || width > reqLength) {
|
||||
final int halfHeight = height / 2;
|
||||
final int halfWidth = width / 2;
|
||||
|
||||
// Calculate the largest inSampleSize value that is a power of 2 and keeps both
|
||||
// height and width larger than the requested height and width.
|
||||
while ((halfHeight / inSampleSize) > reqLength
|
||||
&& (halfWidth / inSampleSize) > reqLength) {
|
||||
inSampleSize *= 2;
|
||||
}
|
||||
}
|
||||
|
||||
return inSampleSize;
|
||||
}
|
||||
|
||||
private static int getSmallerScreenSize(Context c) {
|
||||
Display display = ((WindowManager) c.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
|
||||
Point size = new Point();
|
||||
display.getSize(size);
|
||||
return Math.min(size.x, size.y);
|
||||
}
|
||||
}
|
||||
|
|
@ -11,14 +11,17 @@ import android.os.Environment;
|
|||
import android.provider.BaseColumns;
|
||||
import android.provider.MediaStore;
|
||||
import android.provider.Settings;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.kabouzeid.gramophone.App;
|
||||
import com.kabouzeid.gramophone.R;
|
||||
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
|
||||
import com.kabouzeid.gramophone.imageloader.PhonographImageDownloader;
|
||||
import com.kabouzeid.gramophone.loader.PlaylistLoader;
|
||||
import com.kabouzeid.gramophone.loader.SongLoader;
|
||||
import com.kabouzeid.gramophone.model.Album;
|
||||
import com.kabouzeid.gramophone.model.Artist;
|
||||
import com.kabouzeid.gramophone.model.DataBaseChangedEvent;
|
||||
import com.kabouzeid.gramophone.model.Playlist;
|
||||
|
|
@ -34,6 +37,14 @@ import java.util.List;
|
|||
public class MusicUtil {
|
||||
public static final String TAG = MusicUtil.class.getSimpleName();
|
||||
|
||||
public static String getAlbumImageLoaderString(Album album) {
|
||||
return PhonographImageDownloader.SCHEME_ALBUM + album.id;
|
||||
}
|
||||
|
||||
public static String getSongImageLoaderString(Song song) {
|
||||
return PhonographImageDownloader.SCHEME_SONG + song.albumId + "#" + song.data;
|
||||
}
|
||||
|
||||
public static Uri getAlbumArtUri(int albumId) {
|
||||
final Uri sArtworkUri = Uri
|
||||
.parse("content://media/external/audio/albumart");
|
||||
|
|
@ -45,6 +56,7 @@ public class MusicUtil {
|
|||
return ContentUris.withAppendedId(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, songId);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public static Intent createShareSongFileIntent(final Song song) {
|
||||
return new Intent()
|
||||
.setAction(Intent.ACTION_SEND)
|
||||
|
|
@ -122,6 +134,7 @@ public class MusicUtil {
|
|||
return new File(createAlbumArtDir(), name + System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@SuppressWarnings("ResultOfMethodCallIgnored")
|
||||
public static File createAlbumArtDir() {
|
||||
File albumArtDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "/.albumart/");
|
||||
if (!albumArtDir.exists()) {
|
||||
|
|
|
|||
|
|
@ -22,8 +22,7 @@ public final class PreferenceUtils {
|
|||
public static final String ALBUM_SORT_ORDER = "album_sort_order";
|
||||
public static final String ALBUM_SONG_SORT_ORDER = "album_song_sort_order";
|
||||
public static final String SONG_SORT_ORDER = "song_sort_order";
|
||||
// public static final String ONLY_ON_WIFI = "auto_download_artist_images";
|
||||
// public static final String DOWNLOAD_MISSING_ARTIST_IMAGES = "auto_download_artist_images";
|
||||
public static final String AUTO_DOWNLOAD_ARTIST_IMAGES_ONLY_ON_WIFI = "auto_download_artist_images_only_on_wifi";
|
||||
public static final String COLORED_ALBUM_FOOTERS = "colored_album_footers";
|
||||
public static final String COLORED_NAVIGATION_BAR = "colored_navigation_bar";
|
||||
public static final String COLORED_NAVIGATION_BAR_ALBUM = "colored_navigation_bar_album";
|
||||
|
|
@ -46,6 +45,7 @@ public final class PreferenceUtils {
|
|||
public static final String ALBUM_ART_ON_LOCKSCREEN = "album_art_on_lockscreen";
|
||||
public static final String LAST_SLEEP_TIMER_VALUE = "last_sleep_timer_value";
|
||||
public static final String NEXT_SLEEP_TIMER_ELAPSED_REALTIME = "next_sleep_timer_elapsed_real_time";
|
||||
public static final String IGNORE_MEDIA_STORE_ARTWORK = "ignore_media_store_artwork";
|
||||
|
||||
private static PreferenceUtils sInstance;
|
||||
|
||||
|
|
@ -111,9 +111,9 @@ public final class PreferenceUtils {
|
|||
return mPreferences.getInt(LAST_START_PAGE, DEFAULT_PAGE);
|
||||
}
|
||||
|
||||
// public final boolean autoDownloadOnlyOnWifi() {
|
||||
// return mPreferences.getBoolean(ONLY_ON_WIFI, false);
|
||||
// }
|
||||
public final boolean autoDownloadArtistImagesOnlyOnWifi() {
|
||||
return mPreferences.getBoolean(AUTO_DOWNLOAD_ARTIST_IMAGES_ONLY_ON_WIFI, false);
|
||||
}
|
||||
|
||||
public final boolean coloredAlbumFooters() {
|
||||
return mPreferences.getBoolean(COLORED_ALBUM_FOOTERS, true);
|
||||
|
|
@ -168,11 +168,6 @@ public final class PreferenceUtils {
|
|||
}
|
||||
}
|
||||
|
||||
// @SuppressLint("CommitPrefEdits")
|
||||
// private void setColoredNavigationBarOtherScreens(boolean coloredNavbar) {
|
||||
// mPreferences.edit().putBoolean(COLORED_NAVIGATION_BAR_OTHER_SCREENS, coloredNavbar).commit();
|
||||
// }
|
||||
|
||||
public final boolean opaqueStatusbarNowPlaying() {
|
||||
return mPreferences.getBoolean(OPAQUE_STATUSBAR_NOW_PLAYING, false);
|
||||
}
|
||||
|
|
@ -201,68 +196,37 @@ public final class PreferenceUtils {
|
|||
return mPreferences.getBoolean(GAPLESS_PLAYBACK, false);
|
||||
}
|
||||
|
||||
public final boolean albumArtOnLockscrenn() {
|
||||
public final boolean albumArtOnLockscreen() {
|
||||
return mPreferences.getBoolean(ALBUM_ART_ON_LOCKSCREEN, true);
|
||||
}
|
||||
|
||||
// public final boolean downloadMissingArtistImages() {
|
||||
// return mPreferences.getBoolean(DOWNLOAD_MISSING_ARTIST_IMAGES, true);
|
||||
// }
|
||||
//
|
||||
public final boolean ignoreMediaStoreArtwork() {
|
||||
return mPreferences.getBoolean(IGNORE_MEDIA_STORE_ARTWORK, false);
|
||||
}
|
||||
|
||||
// private void setSortOrder(final String key, final String value) {
|
||||
// final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
// editor.putString(key, value);
|
||||
// editor.apply();
|
||||
// }
|
||||
|
||||
// public void setArtistSortOrder(final String value) {
|
||||
// setSortOrder(ARTIST_SORT_ORDER, value);
|
||||
// }
|
||||
//
|
||||
public final String getArtistSortOrder() {
|
||||
return mPreferences.getString(ARTIST_SORT_ORDER, SortOrder.ArtistSortOrder.ARTIST_A_Z);
|
||||
}
|
||||
|
||||
// public void setArtistSongSortOrder(final String value) {
|
||||
// setSortOrder(ARTIST_SONG_SORT_ORDER, value);
|
||||
// }
|
||||
|
||||
public final String getArtistSongSortOrder() {
|
||||
return mPreferences.getString(ARTIST_SONG_SORT_ORDER,
|
||||
SortOrder.ArtistSongSortOrder.SONG_A_Z);
|
||||
}
|
||||
|
||||
// public void setArtistAlbumSortOrder(final String value) {
|
||||
// setSortOrder(ARTIST_ALBUM_SORT_ORDER, value);
|
||||
// }
|
||||
|
||||
public final String getArtistAlbumSortOrder() {
|
||||
return mPreferences.getString(ARTIST_ALBUM_SORT_ORDER,
|
||||
SortOrder.ArtistAlbumSortOrder.ALBUM_YEAR_ASC);
|
||||
}
|
||||
|
||||
// public void setAlbumSortOrder(final String value) {
|
||||
// setSortOrder(ALBUM_SORT_ORDER, value);
|
||||
// }
|
||||
|
||||
public final String getAlbumSortOrder() {
|
||||
return mPreferences.getString(ALBUM_SORT_ORDER, SortOrder.AlbumSortOrder.ALBUM_A_Z);
|
||||
}
|
||||
|
||||
// public void setAlbumSongSortOrder(final String value) {
|
||||
// setSortOrder(ALBUM_SONG_SORT_ORDER, value);
|
||||
// }
|
||||
|
||||
public final String getAlbumSongSortOrder() {
|
||||
return mPreferences.getString(ALBUM_SONG_SORT_ORDER,
|
||||
SortOrder.AlbumSongSortOrder.SONG_TRACK_LIST);
|
||||
}
|
||||
|
||||
// public void setSongSortOrder(final String value) {
|
||||
// setSortOrder(SONG_SORT_ORDER, value);
|
||||
// }
|
||||
|
||||
public final String getSongSortOrder() {
|
||||
return mPreferences.getString(SONG_SORT_ORDER, SortOrder.SongSortOrder.SONG_A_Z);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -118,44 +118,6 @@ public class Util {
|
|||
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
|
||||
}
|
||||
|
||||
// public static boolean isOnline(final Context context) {
|
||||
// if (context == null)
|
||||
// return false;
|
||||
//
|
||||
// boolean state = false;
|
||||
// final boolean onlyOnWifi = PreferenceUtils.getInstance(context).autoDownloadOnlyOnWifi();
|
||||
//
|
||||
// /* Monitor network connections */
|
||||
// final ConnectivityManager connectivityManager = (ConnectivityManager) context
|
||||
// .getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
//
|
||||
// /* Wi-Fi connection */
|
||||
// final NetworkInfo wifiNetwork = connectivityManager
|
||||
// .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
|
||||
// if (wifiNetwork != null) {
|
||||
// state = wifiNetwork.isConnectedOrConnecting();
|
||||
// }
|
||||
//
|
||||
// /* Mobile data connection */
|
||||
// final NetworkInfo mbobileNetwork = connectivityManager
|
||||
// .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
|
||||
// if (mbobileNetwork != null) {
|
||||
// if (!onlyOnWifi) {
|
||||
// state = mbobileNetwork.isConnectedOrConnecting();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /* Other networks */
|
||||
// final NetworkInfo activeNetwork = connectivityManager.getActiveNetworkInfo();
|
||||
// if (activeNetwork != null) {
|
||||
// if (!onlyOnWifi) {
|
||||
// state = activeNetwork.isConnectedOrConnecting();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return state;
|
||||
// }
|
||||
|
||||
public static String getFileSizeString(long sizeInBytes) {
|
||||
long fileSizeInKB = sizeInBytes / 1024;
|
||||
long fileSizeInMB = fileSizeInKB / 1024;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue