Lots of progress with dynamic theming, the nav drawer now uses a RecyclerView, AboutDeveloperDialogHelper is now a DialogFragment, RTL support (to suppress Lint warnings), other various small fixes, cleaned up and formatted lot of code (and removed un-used resources), R.string.ok > android.R.string.ok, R.string.cancel > android.R.string.cancel, switched dialog helpers to DialogFragments.

This commit is contained in:
Aidan Follestad 2015-04-16 16:47:02 -05:00
commit 7ce86afd74
265 changed files with 2853 additions and 2292 deletions

View file

@ -1,7 +1,6 @@
package com.kabouzeid.gramophone.util;
import android.content.Context;
import android.util.Log;
import java.io.File;
import java.io.FileInputStream;
@ -11,24 +10,19 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
/**
* Created by karim on 22.12.14.
* @author Karim Abou Zeid (kabouzeid)
*/
public final class InternalStorageUtil {
private static final String TAG = InternalStorageUtil.class.getSimpleName();
public static synchronized void writeObject(final Context context, final String key, final Object object) throws IOException {
try {
String tempFileName = "TEMP_" + key;
FileOutputStream fos;
fos = context.openFileOutput(tempFileName, Context.MODE_PRIVATE);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(object);
oos.close();
fos.close();
renameAppFile(context, tempFileName, key);
} catch (IOException e) {
Log.e(TAG, "Writing Object to internal storage failed! Maybe the Object is not serializable?", e);
}
String tempFileName = "TEMP_" + key;
FileOutputStream fos;
fos = context.openFileOutput(tempFileName, Context.MODE_PRIVATE);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(object);
oos.close();
fos.close();
renameAppFile(context, tempFileName, key);
}
public static synchronized void renameAppFile(final Context context, String originalFileName, String newFileName) {

View file

@ -24,7 +24,7 @@ import java.io.IOException;
import java.util.List;
/**
* Created by karim on 29.12.14.
* @author Karim Abou Zeid (kabouzeid)
*/
public class MusicUtil {
public static final String TAG = MusicUtil.class.getSimpleName();
@ -78,12 +78,11 @@ public class MusicUtil {
contentResolver.delete(ContentUris.withAppendedId(localUri, albumId), null, null);
}
public static File getAlbumArtFile(Context context, String name)
throws IOException {
return new File(createAlbumArtDir(context), name + System.currentTimeMillis());
public static File getAlbumArtFile(String name) {
return new File(createAlbumArtDir(), name + System.currentTimeMillis());
}
public static File createAlbumArtDir(Context paramContext) {
public static File createAlbumArtDir() {
File albumArtDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "/.albumart/");
if (!albumArtDir.exists()) {
albumArtDir.mkdirs();
@ -141,7 +140,7 @@ public class MusicUtil {
cursor.moveToNext();
} catch (final SecurityException ex) {
cursor.moveToNext();
} catch (NullPointerException e){
} catch (NullPointerException e) {
Log.e("MusicUtils", "Failed to find file " + name);
}
}

View file

@ -7,12 +7,12 @@ import android.media.audiofx.AudioEffect;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.util.Pair;
import android.support.v7.app.ActionBarActivity;
import android.widget.Toast;
import com.afollestad.materialdialogs.MaterialDialog;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.dialogs.PlayingQueueDialog;
import com.kabouzeid.gramophone.helper.MusicPlayerRemote;
import com.kabouzeid.gramophone.helper.PlayingQueueDialogHelper;
import com.kabouzeid.gramophone.interfaces.KabViewsDisableAble;
import com.kabouzeid.gramophone.misc.AppKeys;
import com.kabouzeid.gramophone.ui.activities.AlbumDetailActivity;
@ -21,7 +21,7 @@ import com.kabouzeid.gramophone.ui.activities.MusicControllerActivity;
import com.kabouzeid.gramophone.ui.activities.PlaylistDetailActivity;
/**
* Created by karim on 12.03.15.
* @author Karim Abou Zeid (kabouzeid)
*/
public class NavigationUtil {
public static void goToArtist(final Activity activity, final int artistId, final Pair[] sharedViews) {
@ -34,7 +34,7 @@ public class NavigationUtil {
final Intent intent = new Intent(activity, ArtistDetailActivity.class);
intent.putExtra(AppKeys.E_ARTIST, artistId);
if (sharedViews != null) {
ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(activity,
@SuppressWarnings("unchecked") ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(activity,
sharedViews
);
ActivityCompat.startActivity(activity, intent, optionsCompat.toBundle());
@ -54,7 +54,7 @@ public class NavigationUtil {
final Intent intent = new Intent(activity, AlbumDetailActivity.class);
intent.putExtra(AppKeys.E_ALBUM, albumId);
if (sharedViews != null) {
ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(activity,
@SuppressWarnings("unchecked") ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(activity,
sharedViews
);
ActivityCompat.startActivity(activity, intent, optionsCompat.toBundle());
@ -71,7 +71,7 @@ public class NavigationUtil {
final Intent intent = new Intent(activity, PlaylistDetailActivity.class);
intent.putExtra(AppKeys.E_PLAYLIST, playlistId);
if (sharedViews != null) {
ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(activity,
@SuppressWarnings("unchecked") ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(activity,
sharedViews
);
ActivityCompat.startActivity(activity, intent, optionsCompat.toBundle());
@ -92,7 +92,7 @@ public class NavigationUtil {
((KabViewsDisableAble) activity).disableViews();
Intent intent = new Intent(activity, MusicControllerActivity.class);
if (sharedViews != null) {
ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(activity,
@SuppressWarnings("unchecked") ActivityOptionsCompat optionsCompat = ActivityOptionsCompat.makeSceneTransitionAnimation(activity,
sharedViews
);
ActivityCompat.startActivity(activity, intent, optionsCompat.toBundle());
@ -105,10 +105,10 @@ public class NavigationUtil {
}
}
public static void openPlayingQueueDialog(final Activity activity) {
final MaterialDialog materialDialog = PlayingQueueDialogHelper.getDialog(activity);
if (materialDialog != null) {
materialDialog.show();
public static void openPlayingQueueDialog(final ActionBarActivity activity) {
PlayingQueueDialog dialog = PlayingQueueDialog.create();
if (dialog != null) {
dialog.show(activity.getSupportFragmentManager(), "PLAY_QUEUE");
} else {
Toast.makeText(activity, activity.getResources().getString(R.string.nothing_playing), Toast.LENGTH_SHORT).show();
}

View file

@ -19,7 +19,7 @@ import java.util.ArrayList;
import java.util.List;
/**
* Created by karim on 16.03.15.
* @author Karim Abou Zeid (kabouzeid)
*/
public class PlaylistsUtil {
public static final String MUSIC_ONLY_SELECTION = MediaStore.Audio.AudioColumns.IS_MUSIC + "=1"
@ -57,7 +57,7 @@ public class PlaylistsUtil {
context.getContentResolver().delete(uri, null, null);
}
public static void deletePlaylist(final Context context, final int playlistId) {
public static void deletePlaylist(final Context context, final long playlistId) {
final Uri uri = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;
String where = MediaStore.Audio.Playlists._ID + "=?";
String[] whereVal = {String.valueOf(playlistId)};
@ -147,7 +147,6 @@ public class PlaylistsUtil {
Cursor c = context.getContentResolver().query(
MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId),
new String[]{BaseColumns._ID}, MUSIC_ONLY_SELECTION, null, null);
if (c != null) {
int count = 0;
if (c.moveToFirst()) {
@ -156,7 +155,6 @@ public class PlaylistsUtil {
c.close();
return count;
}
return 0;
}
@ -165,7 +163,7 @@ public class PlaylistsUtil {
playlistId, from, to);
}
public static void renamePlaylist(final Context context, final int id, final String newName) {
public static void renamePlaylist(final Context context, final long id, final String newName) {
ContentValues contentValues = new ContentValues();
contentValues.put(MediaStore.Audio.PlaylistsColumns.NAME, newName);
context.getContentResolver().update(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
@ -175,7 +173,7 @@ public class PlaylistsUtil {
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
}
public static String getNameForPlaylist(final Context context, final int id) {
public static String getNameForPlaylist(final Context context, final long id) {
Cursor cursor = context.getContentResolver().query(
MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
new String[]{MediaStore.Audio.PlaylistsColumns.NAME},

View file

@ -1,10 +1,12 @@
package com.kabouzeid.gramophone.util;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.dialogs.ColorChooserDialog;
public final class PreferenceUtils {
@ -19,7 +21,7 @@ public final class PreferenceUtils {
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 DOWNLOAD_MISSING_ARTIST_IMAGES = "auto_download_artist_images";
public static final String COLORED_ALBUM_FOOTERS = "colored_album_footers";
public static final String COLORED_NAVIGATION_BAR_ALBUM = "colored_navigation_bar_album";
public static final String COLORED_NAVIGATION_BAR_ARTIST = "colored_navigation_bar_artist";
@ -31,13 +33,15 @@ public final class PreferenceUtils {
private static PreferenceUtils sInstance;
private final Context mContext;
private final SharedPreferences mPreferences;
public PreferenceUtils(final Context context) {
mContext = context;
mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
}
public static final PreferenceUtils getInstance(final Context context) {
public static PreferenceUtils getInstance(final Context context) {
if (sInstance == null) {
sInstance = new PreferenceUtils(context.getApplicationContext());
}
@ -55,30 +59,52 @@ public final class PreferenceUtils {
return R.style.Theme_MaterialMusic_Light;
}
public void setGeneralTheme(int appTheme) {
int value = -1;
switch (appTheme) {
case R.style.Theme_MaterialMusic_Light:
value = 0;
break;
case R.style.Theme_MaterialMusic:
value = 1;
break;
}
if (value != 0 && value != 1) {
return;
}
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putString(GENERAL_THEME, String.valueOf(value));
editor.apply();
public int getThemeColorPrimary() {
return mPreferences.getInt("primary_color", mContext.getResources().getColor(R.color.indigo_500));
}
public void setDefaultStartPage(final int value) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putString(DEFAULT_START_PAGE, String.valueOf(value));
editor.apply();
public int getThemeColorPrimaryDarker() {
return ColorChooserDialog.shiftColorDown(getThemeColorPrimary());
}
@SuppressLint("CommitPrefEdits")
public void setThemeColorPrimary(int color) {
mPreferences.edit().putInt("primary_color", color).commit();
}
public int getThemeColorAccent() {
return mPreferences.getInt("accent_color", mContext.getResources().getColor(R.color.pink_500));
}
@SuppressLint("CommitPrefEdits")
public void setThemeColorAccent(int color) {
mPreferences.edit().putInt("accent_color", color).commit();
}
// public void setGeneralTheme(int appTheme) {
// int value = -1;
// switch (appTheme) {
// case R.style.Theme_MaterialMusic_Light:
// value = 0;
// break;
// case R.style.Theme_MaterialMusic:
// value = 1;
// break;
// }
// if (value != 0 && value != 1) {
// return;
// }
// final SharedPreferences.Editor editor = mPreferences.edit();
// editor.putString(GENERAL_THEME, String.valueOf(value));
// editor.apply();
// }
//
// public void setDefaultStartPage(final int value) {
// final SharedPreferences.Editor editor = mPreferences.edit();
// editor.putString(DEFAULT_START_PAGE, String.valueOf(value));
// editor.apply();
// }
public final int getDefaultStartPage() {
return Integer.parseInt(mPreferences.getString(DEFAULT_START_PAGE, "-1"));
}
@ -97,81 +123,81 @@ public final class PreferenceUtils {
return mPreferences.getBoolean(ONLY_ON_WIFI, false);
}
public void setAutoDownloadOnlyOnWifi(final boolean value) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putBoolean(ONLY_ON_WIFI, value);
editor.apply();
}
// public void setAutoDownloadOnlyOnWifi(final boolean value) {
// final SharedPreferences.Editor editor = mPreferences.edit();
// editor.putBoolean(ONLY_ON_WIFI, value);
// editor.apply();
// }
public final boolean coloredAlbumFootersEnabled() {
return mPreferences.getBoolean(COLORED_ALBUM_FOOTERS, true);
}
public void setColoredAlbumFootersEnabled(final boolean value) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putBoolean(COLORED_ALBUM_FOOTERS, value);
editor.apply();
}
// public void setColoredAlbumFootersEnabled(final boolean value) {
// final SharedPreferences.Editor editor = mPreferences.edit();
// editor.putBoolean(COLORED_ALBUM_FOOTERS, value);
// editor.apply();
// }
public final boolean coloredNavigationBarAlbumEnabled() {
return mPreferences.getBoolean(COLORED_NAVIGATION_BAR_ALBUM, true);
}
public void setColoredNavigationBarAlbumEnabled(final boolean value) {
/*public void setColoredNavigationBarAlbumEnabled(final boolean value) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putBoolean(COLORED_NAVIGATION_BAR_ALBUM, value);
editor.apply();
}
}*/
public final boolean coloredNavigationBarArtistEnabled() {
return mPreferences.getBoolean(COLORED_NAVIGATION_BAR_ARTIST, true);
}
public void setColoredNavigationBarArtistEnabled(final boolean value) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putBoolean(COLORED_NAVIGATION_BAR_ARTIST, value);
editor.apply();
}
// public void setColoredNavigationBarArtistEnabled(final boolean value) {
// final SharedPreferences.Editor editor = mPreferences.edit();
// editor.putBoolean(COLORED_NAVIGATION_BAR_ARTIST, value);
// editor.apply();
// }
public final boolean coloredNavigationBarCurrentPlayingEnabled() {
return mPreferences.getBoolean(COLORED_NAVIGATION_BAR_CURRENT_PLAYING, true);
}
public void setColoredNavigationBarCurrentPlayingEnabled(final boolean value) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putBoolean(COLORED_NAVIGATION_BAR_CURRENT_PLAYING, value);
editor.apply();
}
// public void setColoredNavigationBarCurrentPlayingEnabled(final boolean value) {
// final SharedPreferences.Editor editor = mPreferences.edit();
// editor.putBoolean(COLORED_NAVIGATION_BAR_CURRENT_PLAYING, value);
// editor.apply();
// }
public final boolean playbackControllerBoxEnabled() {
return mPreferences.getBoolean(PLAYBACK_CONTROLLER_BOX, false);
}
public void setPlaybackControllerBoxEnabled(final boolean value) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putBoolean(PLAYBACK_CONTROLLER_BOX, value);
editor.apply();
}
// public void setPlaybackControllerBoxEnabled(final boolean value) {
// final SharedPreferences.Editor editor = mPreferences.edit();
// editor.putBoolean(PLAYBACK_CONTROLLER_BOX, value);
// editor.apply();
// }
public final boolean transparentToolbar() {
return mPreferences.getBoolean(TRANSPARENT_TOOLBAR, false);
}
public void setTransparentToolbar(final boolean value) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putBoolean(TRANSPARENT_TOOLBAR, value);
editor.apply();
}
// public void setTransparentToolbar(final boolean value) {
// final SharedPreferences.Editor editor = mPreferences.edit();
// editor.putBoolean(TRANSPARENT_TOOLBAR, value);
// editor.apply();
// }
public final boolean downloadMissingArtistImages() {
return mPreferences.getBoolean(DOWNLOAD_MISSING_ARTIST_IMAGES, true);
}
public void setDownloadMissingArtistImages(final boolean value) {
final SharedPreferences.Editor editor = mPreferences.edit();
editor.putBoolean(DOWNLOAD_MISSING_ARTIST_IMAGES, value);
editor.apply();
}
// public final boolean downloadMissingArtistImages() {
// return mPreferences.getBoolean(DOWNLOAD_MISSING_ARTIST_IMAGES, true);
// }
//
// public void setDownloadMissingArtistImages(final boolean value) {
// final SharedPreferences.Editor editor = mPreferences.edit();
// editor.putBoolean(DOWNLOAD_MISSING_ARTIST_IMAGES, value);
// editor.apply();
// }
private void setSortOrder(final String key, final String value) {
final SharedPreferences.Editor editor = mPreferences.edit();
@ -179,52 +205,52 @@ public final class PreferenceUtils {
editor.apply();
}
public void setArtistSortOrder(final String value) {
setSortOrder(ARTIST_SORT_ORDER, value);
}
// 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 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 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_A_Z);
}
public void setAlbumSortOrder(final String value) {
setSortOrder(ALBUM_SORT_ORDER, value);
}
// 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 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 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);

View file

@ -29,127 +29,127 @@ public final class SortOrder {
/**
* Artist sort order entries.
*/
public static interface ArtistSortOrder {
public interface ArtistSortOrder {
/* Artist sort order A-Z */
public final static String ARTIST_A_Z = MediaStore.Audio.Artists.DEFAULT_SORT_ORDER;
String ARTIST_A_Z = MediaStore.Audio.Artists.DEFAULT_SORT_ORDER;
/* Artist sort order Z-A */
public final static String ARTIST_Z_A = ARTIST_A_Z + " DESC";
String ARTIST_Z_A = ARTIST_A_Z + " DESC";
/* Artist sort order number of songs */
public final static String ARTIST_NUMBER_OF_SONGS = MediaStore.Audio.Artists.NUMBER_OF_TRACKS
String ARTIST_NUMBER_OF_SONGS = MediaStore.Audio.Artists.NUMBER_OF_TRACKS
+ " DESC";
/* Artist sort order number of albums */
public final static String ARTIST_NUMBER_OF_ALBUMS = MediaStore.Audio.Artists.NUMBER_OF_ALBUMS
String ARTIST_NUMBER_OF_ALBUMS = MediaStore.Audio.Artists.NUMBER_OF_ALBUMS
+ " DESC";
}
/**
* Album sort order entries.
*/
public static interface AlbumSortOrder {
public interface AlbumSortOrder {
/* Album sort order A-Z */
public final static String ALBUM_A_Z = MediaStore.Audio.Albums.DEFAULT_SORT_ORDER;
String ALBUM_A_Z = MediaStore.Audio.Albums.DEFAULT_SORT_ORDER;
/* Album sort order Z-A */
public final static String ALBUM_Z_A = ALBUM_A_Z + " DESC";
String ALBUM_Z_A = ALBUM_A_Z + " DESC";
/* Album sort order songs */
public final static String ALBUM_NUMBER_OF_SONGS = MediaStore.Audio.Albums.NUMBER_OF_SONGS
String ALBUM_NUMBER_OF_SONGS = MediaStore.Audio.Albums.NUMBER_OF_SONGS
+ " DESC";
/* Album sort order artist */
public final static String ALBUM_ARTIST = MediaStore.Audio.Albums.ARTIST;
String ALBUM_ARTIST = MediaStore.Audio.Albums.ARTIST;
/* Album sort order year */
public final static String ALBUM_YEAR = MediaStore.Audio.Albums.FIRST_YEAR + " DESC";
String ALBUM_YEAR = MediaStore.Audio.Albums.FIRST_YEAR + " DESC";
}
/**
* Song sort order entries.
*/
public static interface SongSortOrder {
public interface SongSortOrder {
/* Song sort order A-Z */
public final static String SONG_A_Z = MediaStore.Audio.Media.DEFAULT_SORT_ORDER;
String SONG_A_Z = MediaStore.Audio.Media.DEFAULT_SORT_ORDER;
/* Song sort order Z-A */
public final static String SONG_Z_A = SONG_A_Z + " DESC";
String SONG_Z_A = SONG_A_Z + " DESC";
/* Song sort order artist */
public final static String SONG_ARTIST = MediaStore.Audio.Media.ARTIST;
String SONG_ARTIST = MediaStore.Audio.Media.ARTIST;
/* Song sort order album */
public final static String SONG_ALBUM = MediaStore.Audio.Media.ALBUM;
String SONG_ALBUM = MediaStore.Audio.Media.ALBUM;
/* Song sort order year */
public final static String SONG_YEAR = MediaStore.Audio.Media.YEAR + " DESC";
String SONG_YEAR = MediaStore.Audio.Media.YEAR + " DESC";
/* Song sort order duration */
public final static String SONG_DURATION = MediaStore.Audio.Media.DURATION + " DESC";
String SONG_DURATION = MediaStore.Audio.Media.DURATION + " DESC";
/* Song sort order date */
public final static String SONG_DATE = MediaStore.Audio.Media.DATE_ADDED + " DESC";
String SONG_DATE = MediaStore.Audio.Media.DATE_ADDED + " DESC";
}
/**
* Album song sort order entries.
*/
public static interface AlbumSongSortOrder {
public interface AlbumSongSortOrder {
/* Album song sort order A-Z */
public final static String SONG_A_Z = MediaStore.Audio.Media.DEFAULT_SORT_ORDER;
String SONG_A_Z = MediaStore.Audio.Media.DEFAULT_SORT_ORDER;
/* Album song sort order Z-A */
public final static String SONG_Z_A = SONG_A_Z + " DESC";
String SONG_Z_A = SONG_A_Z + " DESC";
/* Album song sort order track list */
public final static String SONG_TRACK_LIST = MediaStore.Audio.Media.TRACK + ", "
String SONG_TRACK_LIST = MediaStore.Audio.Media.TRACK + ", "
+ MediaStore.Audio.Media.DEFAULT_SORT_ORDER;
/* Album song sort order duration */
public final static String SONG_DURATION = SongSortOrder.SONG_DURATION;
String SONG_DURATION = SongSortOrder.SONG_DURATION;
}
/**
* Artist song sort order entries.
*/
public static interface ArtistSongSortOrder {
public interface ArtistSongSortOrder {
/* Artist song sort order A-Z */
public final static String SONG_A_Z = MediaStore.Audio.Media.DEFAULT_SORT_ORDER;
String SONG_A_Z = MediaStore.Audio.Media.DEFAULT_SORT_ORDER;
/* Artist song sort order Z-A */
public final static String SONG_Z_A = SONG_A_Z + " DESC";
String SONG_Z_A = SONG_A_Z + " DESC";
/* Artist song sort order album */
public final static String SONG_ALBUM = MediaStore.Audio.Media.ALBUM;
String SONG_ALBUM = MediaStore.Audio.Media.ALBUM;
/* Artist song sort order year */
public final static String SONG_YEAR = MediaStore.Audio.Media.YEAR + " DESC";
String SONG_YEAR = MediaStore.Audio.Media.YEAR + " DESC";
/* Artist song sort order duration */
public final static String SONG_DURATION = MediaStore.Audio.Media.DURATION + " DESC";
String SONG_DURATION = MediaStore.Audio.Media.DURATION + " DESC";
/* Artist song sort order date */
public final static String SONG_DATE = MediaStore.Audio.Media.DATE_ADDED + " DESC";
String SONG_DATE = MediaStore.Audio.Media.DATE_ADDED + " DESC";
}
/**
* Artist album sort order entries.
*/
public static interface ArtistAlbumSortOrder {
public interface ArtistAlbumSortOrder {
/* Artist album sort order A-Z */
public final static String ALBUM_A_Z = MediaStore.Audio.Albums.DEFAULT_SORT_ORDER;
String ALBUM_A_Z = MediaStore.Audio.Albums.DEFAULT_SORT_ORDER;
/* Artist album sort order Z-A */
public final static String ALBUM_Z_A = ALBUM_A_Z + " DESC";
String ALBUM_Z_A = ALBUM_A_Z + " DESC";
/* Artist album sort order songs */
public final static String ALBUM_NUMBER_OF_SONGS = MediaStore.Audio.Artists.Albums.NUMBER_OF_SONGS
String ALBUM_NUMBER_OF_SONGS = MediaStore.Audio.Artists.Albums.NUMBER_OF_SONGS
+ " DESC";
/* Artist album sort order year */
public final static String ALBUM_YEAR = MediaStore.Audio.Artists.Albums.FIRST_YEAR
String ALBUM_YEAR = MediaStore.Audio.Artists.Albums.FIRST_YEAR
+ " DESC";
}

View file

@ -4,18 +4,12 @@ import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.Uri;
import android.os.Build;
import android.provider.MediaStore;
import android.support.annotation.DrawableRes;
import android.support.v4.content.ContextCompat;
import android.util.TypedValue;
import android.view.View;
import android.view.Window;
@ -25,31 +19,30 @@ import android.view.inputmethod.InputMethodManager;
import com.kabouzeid.gramophone.R;
/**
* Created by karim on 12.12.14.
* @author Karim Abou Zeid (kabouzeid)
*/
public class Util {
private static int albumArtSize = 600;
public static int resolveDrawable(Context context, int drawable) {
TypedArray a = context.obtainStyledAttributes(new int[]{drawable});
int resId = a.getResourceId(0, 0);
a.recycle();
return resId;
}
// public static int resolveDrawable(Context context, int drawable) {
// TypedArray a = context.obtainStyledAttributes(new int[]{drawable});
// int resId = a.getResourceId(0, 0);
// a.recycle();
// return resId;
// }
public static int resolveColor(Context context, int color) {
TypedArray a = context.obtainStyledAttributes(new int[]{color});
int resId = a.getColor(0, 0);
a.recycle();
return resId;
}
// public static int resolveColor(Context context, int color) {
// TypedArray a = context.obtainStyledAttributes(new int[]{color});
// int resId = a.getColor(0, 0);
// a.recycle();
// return resId;
// }
public static boolean isWindowTranslucent(Context context) {
TypedArray a = context.obtainStyledAttributes(new int[]{android.R.attr.windowTranslucentStatus});
boolean result = a.getBoolean(0, false);
a.recycle();
return result;
}
// public static boolean isWindowTranslucent(Context context) {
// TypedArray a = context.obtainStyledAttributes(new int[]{android.R.attr.windowTranslucentStatus});
// boolean result = a.getBoolean(0, false);
// a.recycle();
// return result;
// }
public static int getActionBarSize(Context context) {
TypedValue typedValue = new TypedValue();
@ -113,44 +106,43 @@ public class Util {
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
public static final 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 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;
@ -158,22 +150,23 @@ public class Util {
return fileSizeInMB + " MB";
}
public static String getFilePathFromContentProviderUri(Context context, Uri uri) {
String path = "";
String[] projection = {MediaStore.MediaColumns.DATA};
Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
if (cursor == null) return null;
int column_index = cursor.getColumnIndexOrThrow(projection[0]);
if (cursor.moveToFirst()) {
path = cursor.getString(column_index);
}
cursor.close();
return path;
}
private static Bitmap getScaledBitmap(final Bitmap bitmap) {
return Bitmap.createScaledBitmap(bitmap, albumArtSize, albumArtSize, false);
}
// public static String getFilePathFromContentProviderUri(Context context, Uri uri) {
// String path = "";
// String[] projection = {MediaStore.MediaColumns.DATA};
// Cursor cursor = context.getContentResolver().query(uri, projection, null, null, null);
// if (cursor == null) return null;
// int column_index = cursor.getColumnIndexOrThrow(projection[0]);
// if (cursor.moveToFirst()) {
// path = cursor.getString(column_index);
// }
// cursor.close();
// return path;
// }
//
// private static Bitmap getScaledBitmap(final Bitmap bitmap) {
// int albumArtSize = 600;
// return Bitmap.createScaledBitmap(bitmap, albumArtSize, albumArtSize, false);
// }
public static void hideSoftKeyboard(Activity activity) {
if (activity != null) {
@ -201,11 +194,11 @@ public class Util {
return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
}
public static Drawable getTintedDrawable(Resources res, @DrawableRes int drawableResId, int color) {
Drawable drawable = res.getDrawable(drawableResId);
public static Drawable getTintedDrawable(Context context, @DrawableRes int drawableResId, int color) {
Drawable drawable = ContextCompat.getDrawable(context, drawableResId);
if (drawable != null) {
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
}
return drawable;
}
}
}

View file

@ -13,7 +13,7 @@ import android.widget.ListView;
import android.widget.TextView;
/**
* Created by karim on 06.12.14.
* @author Karim Abou Zeid (kabouzeid)
*/
public class ViewUtil {
public final static int DEFAULT_COLOR_ANIMATION_DURATION = 1000;
@ -89,6 +89,7 @@ public class ViewUtil {
@Override
public void onGlobalLayout() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
//noinspection deprecation
view.getViewTreeObserver().removeGlobalOnLayoutListener(this);
} else {
view.getViewTreeObserver().removeOnGlobalLayoutListener(this);