Added Nullity Annotations

This commit is contained in:
Karim Abou Zeid 2015-07-10 02:37:10 +02:00
commit 5317c51400
102 changed files with 772 additions and 404 deletions

View file

@ -4,6 +4,7 @@ import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Point;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.view.Display;
import android.view.WindowManager;
@ -24,7 +25,7 @@ import java.io.IOException;
public class ImageUtil {
@Nullable
public static Bitmap getEmbeddedSongArt(File songFile, Context context) {
public static Bitmap getEmbeddedSongArt(File songFile, @NonNull Context context) {
try {
AudioFile audioFile = AudioFileIO.read(songFile);
byte[] data = audioFile.getTag().getFirstArtwork().getBinaryData();
@ -39,13 +40,13 @@ public class ImageUtil {
options.inJustDecodeBounds = false;
return BitmapFactory.decodeByteArray(data, 0, data.length, options);
}
} catch (CannotReadException | TagException | IOException | ReadOnlyFileException | InvalidAudioFrameException e) {
} catch (@NonNull CannotReadException | TagException | IOException | ReadOnlyFileException | InvalidAudioFrameException e) {
e.printStackTrace();
}
return null;
}
public static int calculateInSampleSize(BitmapFactory.Options options, Context context) {
public static int calculateInSampleSize(@NonNull BitmapFactory.Options options, @NonNull Context context) {
// Raw height and width of image
final int height = options.outHeight;
@ -76,7 +77,7 @@ public class ImageUtil {
return inSampleSize;
}
private static int getSmallerScreenSize(Context c) {
private static int getSmallerScreenSize(@NonNull Context c) {
Display display = ((WindowManager) c.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
Point size = new Point();
display.getSize(size);

View file

@ -1,6 +1,7 @@
package com.kabouzeid.gramophone.util;
import android.content.Context;
import android.support.annotation.NonNull;
import java.io.File;
import java.io.FileInputStream;
@ -22,7 +23,7 @@ public final class InternalStorageUtil {
* @param key the filename
* @param object any {@link java.io.Serializable} object which will be written to the internal storage
*/
public static synchronized void writeObject(final Context context, final String key, final Object object) throws IOException {
public static synchronized void writeObject(@NonNull final Context context, @NonNull final String key, final Object object) throws IOException {
// First write the object to a file with ".tmp" postfix,
// so when an error occurs, we do not overwrite the original
// file (if exists) with a corrupted file.
@ -43,7 +44,7 @@ public final class InternalStorageUtil {
* @param originalFileName the original filename
* @param newFileName the new filename
*/
public static synchronized void renameAppFile(final Context context, String originalFileName, String newFileName) {
public static synchronized void renameAppFile(@NonNull final Context context, String originalFileName, @NonNull String newFileName) {
File originalFile = context.getFileStreamPath(originalFileName);
File newFile = new File(originalFile.getParent(), newFileName);
if (newFile.exists()) {
@ -57,7 +58,7 @@ public final class InternalStorageUtil {
* @param context a valid {@link Context}
* @param key the filename
*/
public static synchronized Object readObject(final Context context, String key) throws IOException,
public static synchronized Object readObject(@NonNull final Context context, String key) throws IOException,
ClassNotFoundException {
FileInputStream fis = context.openFileInput(key);
ObjectInputStream ois = new ObjectInputStream(fis);

View file

@ -12,6 +12,7 @@ import android.provider.BaseColumns;
import android.provider.MediaStore;
import android.provider.Settings;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Log;
import android.widget.Toast;
@ -37,11 +38,13 @@ import java.util.List;
public class MusicUtil {
public static final String TAG = MusicUtil.class.getSimpleName();
public static String getAlbumImageLoaderString(Album album) {
@NonNull
public static String getAlbumImageLoaderString(@NonNull Album album) {
return PhonographImageDownloader.SCHEME_ALBUM + album.id;
}
public static String getSongImageLoaderString(Song song) {
@NonNull
public static String getSongImageLoaderString(@NonNull Song song) {
return PhonographImageDownloader.SCHEME_SONG + song.albumId + "#" + song.data;
}
@ -57,14 +60,14 @@ public class MusicUtil {
}
@NonNull
public static Intent createShareSongFileIntent(final Song song) {
public static Intent createShareSongFileIntent(@NonNull final Song song) {
return new Intent()
.setAction(Intent.ACTION_SEND)
.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + song.data))
.setType("audio/*");
}
public static void setRingtone(final Context context, final int id) {
public static void setRingtone(@NonNull final Context context, final int id) {
final ContentResolver resolver = context.getContentResolver();
final Uri uri = getSongUri(id);
try {
@ -72,7 +75,7 @@ public class MusicUtil {
values.put(MediaStore.Audio.AudioColumns.IS_RINGTONE, "1");
values.put(MediaStore.Audio.AudioColumns.IS_ALARM, "1");
resolver.update(uri, values, null, null);
} catch (final UnsupportedOperationException ignored) {
} catch (@NonNull final UnsupportedOperationException ignored) {
return;
}
@ -95,7 +98,8 @@ public class MusicUtil {
}
}
public static String getArtistInfoString(Context context, Artist artist) {
@NonNull
public static String getArtistInfoString(@NonNull Context context, @NonNull Artist artist) {
return artist.songCount + " " + context.getResources().getString(R.string.songs) + " | " + artist.albumCount + " " + context.getResources().getString(R.string.albums);
}
@ -111,7 +115,7 @@ public class MusicUtil {
return trackNumberToFix % 1000;
}
public static void insertAlbumArt(Context context, int albumId, String path) {
public static void insertAlbumArt(@NonNull Context context, int albumId, String path) {
ContentResolver contentResolver = context.getContentResolver();
Uri artworkUri = Uri.parse("content://media/external/audio/albumart");
@ -124,16 +128,18 @@ public class MusicUtil {
contentResolver.insert(artworkUri, values);
}
public static void deleteAlbumArt(Context context, int albumId) {
public static void deleteAlbumArt(@NonNull Context context, int albumId) {
ContentResolver contentResolver = context.getContentResolver();
Uri localUri = Uri.parse("content://media/external/audio/albumart");
contentResolver.delete(ContentUris.withAppendedId(localUri, albumId), null, null);
}
@NonNull
public static File createAlbumArtFile(String name) {
return new File(createAlbumArtDir(), name + System.currentTimeMillis());
}
@NonNull
@SuppressWarnings("ResultOfMethodCallIgnored")
public static File createAlbumArtDir() {
File albumArtDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "/.albumart/");
@ -148,7 +154,7 @@ public class MusicUtil {
return albumArtDir;
}
public static void deleteTracks(final Context context, final List<Song> songs) {
public static void deleteTracks(@NonNull final Context context, @NonNull final List<Song> songs) {
final String[] projection = new String[]{
BaseColumns._ID, MediaStore.MediaColumns.DATA
};
@ -191,7 +197,7 @@ public class MusicUtil {
Log.e("MusicUtils", "Failed to delete file " + name);
}
cursor.moveToNext();
} catch (final SecurityException ex) {
} catch (@NonNull final SecurityException ex) {
cursor.moveToNext();
} catch (NullPointerException e) {
Log.e("MusicUtils", "Failed to find file " + name);
@ -204,19 +210,19 @@ public class MusicUtil {
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.DATABASE_CHANGED));
}
private static Playlist getFavoritesPlaylist(final Context context) {
private static Playlist getFavoritesPlaylist(@NonNull final Context context) {
return PlaylistLoader.getPlaylist(context, context.getString(R.string.favorites));
}
private static Playlist getOrCreateFavoritesPlaylist(final Context context) {
private static Playlist getOrCreateFavoritesPlaylist(@NonNull final Context context) {
return PlaylistLoader.getPlaylist(context, PlaylistsUtil.createPlaylist(context, context.getString(R.string.favorites)));
}
public static boolean isFavorite(final Context context, final Song song) {
public static boolean isFavorite(@NonNull final Context context, @NonNull final Song song) {
return PlaylistsUtil.doPlaylistContains(context, getFavoritesPlaylist(context).id, song.id);
}
public static void toggleFavorite(final Context context, final Song song) {
public static void toggleFavorite(@NonNull final Context context, @NonNull final Song song) {
if (isFavorite(context, song)) {
PlaylistsUtil.removeFromPlaylist(context, song, getFavoritesPlaylist(context).id);
} else {
@ -224,7 +230,7 @@ public class MusicUtil {
}
}
public static boolean isArtistNameUnknown(final String artistName) {
public static boolean isArtistNameUnknown(@Nullable final String artistName) {
return artistName != null && (artistName.trim().toLowerCase().equals("unknown") || artistName.trim().toLowerCase().equals("<unknown>"));
}
}

View file

@ -4,6 +4,8 @@ import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.media.audiofx.AudioEffect;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v4.util.Pair;
@ -25,7 +27,7 @@ import com.kabouzeid.gramophone.ui.activities.PlaylistDetailActivity;
*/
public class NavigationUtil {
public static void goToArtist(final Activity activity, final int artistId, final Pair[] sharedViews) {
public static void goToArtist(final Activity activity, final int artistId, @Nullable final Pair[] sharedViews) {
if (activity instanceof ArtistDetailActivity)
return;
if ((activity instanceof KabViewsDisableAble && ((KabViewsDisableAble) activity).areViewsEnabled()) || !(activity instanceof KabViewsDisableAble)) {
@ -44,7 +46,7 @@ public class NavigationUtil {
}
}
public static void goToAlbum(final Activity activity, final int albumId, final Pair[] sharedViews) {
public static void goToAlbum(final Activity activity, final int albumId, @Nullable final Pair[] sharedViews) {
if (activity instanceof AlbumDetailActivity)
return;
if ((activity instanceof KabViewsDisableAble && ((KabViewsDisableAble) activity).areViewsEnabled()) || !(activity instanceof KabViewsDisableAble)) {
@ -63,7 +65,7 @@ public class NavigationUtil {
}
}
public static void goToPlaylist(final Activity activity, final Playlist playlist, final Pair[] sharedViews) {
public static void goToPlaylist(final Activity activity, final Playlist playlist, @Nullable final Pair[] sharedViews) {
if ((activity instanceof KabViewsDisableAble && ((KabViewsDisableAble) activity).areViewsEnabled()) || !(activity instanceof KabViewsDisableAble)) {
if (activity instanceof KabViewsDisableAble)
((KabViewsDisableAble) activity).disableViews();
@ -83,7 +85,7 @@ public class NavigationUtil {
}
}
public static void openCurrentPlayingIfPossible(final Activity activity, final Pair[] sharedViews) {
public static void openCurrentPlayingIfPossible(final Activity activity, @Nullable final Pair[] sharedViews) {
if (activity instanceof MusicControllerActivity) {
activity.onBackPressed();
return;
@ -107,7 +109,7 @@ public class NavigationUtil {
}
}
public static void openPlayingQueueDialog(final AppCompatActivity activity) {
public static void openPlayingQueueDialog(@NonNull final AppCompatActivity activity) {
PlayingQueueDialog dialog = PlayingQueueDialog.create();
if (dialog != null) {
dialog.show(activity.getSupportFragmentManager(), "PLAY_QUEUE");
@ -116,7 +118,7 @@ public class NavigationUtil {
}
}
public static void openEqualizer(final Activity activity) {
public static void openEqualizer(@NonNull final Activity activity) {
final int sessionId = MusicPlayerRemote.getAudioSessionId();
if (sessionId == AudioEffect.ERROR_BAD_VALUE) {
Toast.makeText(activity, activity.getResources().getString(R.string.no_audio_ID), Toast.LENGTH_LONG).show();
@ -126,7 +128,7 @@ public class NavigationUtil {
effects.putExtra(AudioEffect.EXTRA_AUDIO_SESSION, sessionId);
effects.putExtra(AudioEffect.EXTRA_CONTENT_TYPE, AudioEffect.CONTENT_TYPE_MUSIC);
activity.startActivityForResult(effects, 0);
} catch (final ActivityNotFoundException notFound) {
} catch (@NonNull final ActivityNotFoundException notFound) {
Toast.makeText(activity, activity.getResources().getString(R.string.no_equalizer), Toast.LENGTH_SHORT).show();
}
}

View file

@ -7,6 +7,8 @@ import android.database.Cursor;
import android.net.Uri;
import android.provider.BaseColumns;
import android.provider.MediaStore;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.widget.Toast;
import com.kabouzeid.gramophone.App;
@ -24,7 +26,7 @@ import java.util.List;
*/
public class PlaylistsUtil {
public static int createPlaylist(final Context context, final String name) {
public static int createPlaylist(@NonNull final Context context, @Nullable final String name) {
int id = -1;
if (name != null && name.length() > 0) {
Cursor cursor = context.getContentResolver().query(MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI,
@ -70,7 +72,7 @@ public class PlaylistsUtil {
// App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
// }
public static void deletePlaylists(final Context context, final ArrayList<Playlist> playlists) {
public static void deletePlaylists(@NonNull final Context context, @NonNull final ArrayList<Playlist> playlists) {
final Uri uri = MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI;
final StringBuilder selection = new StringBuilder();
selection.append(MediaStore.Audio.Playlists._ID + " IN (");
@ -85,13 +87,13 @@ public class PlaylistsUtil {
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
}
public static void addToPlaylist(final Context context, final Song song, final int playlistId, final boolean showToastOnFinish) {
public static void addToPlaylist(@NonNull final Context context, final Song song, final int playlistId, final boolean showToastOnFinish) {
List<Song> helperList = new ArrayList<>();
helperList.add(song);
addToPlaylist(context, helperList, playlistId, showToastOnFinish);
}
public static void addToPlaylist(final Context context, final List<Song> songs, final int playlistId, final boolean showToastOnFinish) {
public static void addToPlaylist(@NonNull final Context context, @NonNull final List<Song> songs, final int playlistId, final boolean showToastOnFinish) {
final int size = songs.size();
final ContentResolver resolver = context.getContentResolver();
final String[] projection = new String[]{
@ -124,7 +126,8 @@ public class PlaylistsUtil {
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
}
public static ContentValues[] makeInsertItems(final List<Song> songs, final int offset, int len, final int base) {
@NonNull
public static ContentValues[] makeInsertItems(@NonNull final List<Song> songs, final int offset, int len, final int base) {
if (offset + len > songs.size()) {
len = songs.size() - offset;
}
@ -139,7 +142,7 @@ public class PlaylistsUtil {
return contentValues;
}
public static void removeFromPlaylist(final Context context, final Song song, int playlistId) {
public static void removeFromPlaylist(@NonNull final Context context, @NonNull final Song song, int playlistId) {
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri(
"external", playlistId);
String selection = MediaStore.Audio.Playlists.Members.AUDIO_ID + " =?";
@ -149,7 +152,7 @@ public class PlaylistsUtil {
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
}
public static void removeFromPlaylist(final Context context, final List<PlaylistSong> songs) {
public static void removeFromPlaylist(@NonNull final Context context, @NonNull final List<PlaylistSong> songs) {
final int playlistId = songs.get(0).playlistId;
Uri uri = MediaStore.Audio.Playlists.Members.getContentUri(
"external", playlistId);
@ -165,7 +168,7 @@ public class PlaylistsUtil {
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
}
public static boolean doPlaylistContains(final Context context, final long playlistId, final int songId) {
public static boolean doPlaylistContains(@NonNull final Context context, final long playlistId, final int songId) {
if (playlistId != -1) {
Cursor c = context.getContentResolver().query(
MediaStore.Audio.Playlists.Members.getContentUri("external", playlistId),
@ -195,12 +198,12 @@ public class PlaylistsUtil {
// return 0;
// }
public static boolean moveItem(final Context context, int playlistId, int from, int to) {
public static boolean moveItem(@NonNull final Context context, int playlistId, int from, int to) {
return MediaStore.Audio.Playlists.Members.moveItem(context.getContentResolver(),
playlistId, from, to);
}
public static void renamePlaylist(final Context context, final long id, final String newName) {
public static void renamePlaylist(@NonNull 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,
@ -210,7 +213,7 @@ public class PlaylistsUtil {
App.bus.post(new DataBaseChangedEvent(DataBaseChangedEvent.PLAYLISTS_CHANGED));
}
public static String getNameForPlaylist(final Context context, final long id) {
public static String getNameForPlaylist(@NonNull 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

@ -4,6 +4,8 @@ import android.annotation.SuppressLint;
import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import com.kabouzeid.gramophone.R;
@ -49,15 +51,16 @@ public final class PreferenceUtils {
private static PreferenceUtils sInstance;
@NonNull
private final Context mContext;
private final SharedPreferences mPreferences;
public PreferenceUtils(final Context context) {
public PreferenceUtils(@NonNull final Context context) {
mContext = context;
mPreferences = PreferenceManager.getDefaultSharedPreferences(context);
}
public static PreferenceUtils getInstance(final Context context) {
public static PreferenceUtils getInstance(@NonNull final Context context) {
if (sInstance == null) {
sInstance = new PreferenceUtils(context.getApplicationContext());
}
@ -204,29 +207,35 @@ public final class PreferenceUtils {
return mPreferences.getBoolean(IGNORE_MEDIA_STORE_ARTWORK, false);
}
@Nullable
public final String getArtistSortOrder() {
return mPreferences.getString(ARTIST_SORT_ORDER, SortOrder.ArtistSortOrder.ARTIST_A_Z);
}
@Nullable
public final String getArtistSongSortOrder() {
return mPreferences.getString(ARTIST_SONG_SORT_ORDER,
SortOrder.ArtistSongSortOrder.SONG_A_Z);
}
@Nullable
public final String getArtistAlbumSortOrder() {
return mPreferences.getString(ARTIST_ALBUM_SORT_ORDER,
SortOrder.ArtistAlbumSortOrder.ALBUM_YEAR_ASC);
}
@Nullable
public final String getAlbumSortOrder() {
return mPreferences.getString(ALBUM_SORT_ORDER, SortOrder.AlbumSortOrder.ALBUM_A_Z);
}
@Nullable
public final String getAlbumSongSortOrder() {
return mPreferences.getString(ALBUM_SONG_SORT_ORDER,
SortOrder.AlbumSongSortOrder.SONG_TRACK_LIST);
}
@Nullable
public final String getSongSortOrder() {
return mPreferences.getString(SONG_SORT_ORDER, SortOrder.SongSortOrder.SONG_A_Z);
}

View file

@ -15,6 +15,8 @@ import android.os.Build;
import android.support.annotation.AttrRes;
import android.support.annotation.ColorInt;
import android.support.annotation.DrawableRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.util.TypedValue;
import android.view.View;
@ -36,7 +38,7 @@ public class Util {
// return resId;
// }
public static int resolveColor(Context context, @AttrRes int colorAttr) {
public static int resolveColor(@NonNull Context context, @AttrRes int colorAttr) {
TypedArray a = context.obtainStyledAttributes(new int[]{colorAttr});
int resId = a.getColor(0, 0);
a.recycle();
@ -50,7 +52,7 @@ public class Util {
// return result;
// }
public static int getActionBarSize(Context context) {
public static int getActionBarSize(@NonNull Context context) {
TypedValue typedValue = new TypedValue();
int[] textSizeAttr = new int[]{R.attr.actionBarSize};
int indexOfAttrTextSize = 0;
@ -60,7 +62,7 @@ public class Util {
return actionBarSize;
}
public static int getStatusBarHeight(Context context) {
public static int getStatusBarHeight(@NonNull Context context) {
int result = 0;
int resourceId = context.getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
@ -69,7 +71,7 @@ public class Util {
return result;
}
public static int getNavigationBarHeight(Context context) {
public static int getNavigationBarHeight(@NonNull Context context) {
int result = 0;
int resourceId = context.getResources().getIdentifier("navigation_bar_height", "dimen", "android");
if (resourceId > 0) {
@ -96,7 +98,7 @@ public class Util {
// }
@TargetApi(19)
public static void setStatusBarTranslucent(Window window, boolean translucent) {
public static void setStatusBarTranslucent(@NonNull Window window, boolean translucent) {
if (translucent) {
window.setFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,
@ -112,12 +114,13 @@ public class Util {
WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
public static void setAllowDrawUnderStatusBar(Window window) {
public static void setAllowDrawUnderStatusBar(@NonNull Window window) {
window.getDecorView().setSystemUiVisibility(
View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
@NonNull
public static String getFileSizeString(long sizeInBytes) {
long fileSizeInKB = sizeInBytes / 1024;
long fileSizeInMB = fileSizeInKB / 1024;
@ -142,7 +145,7 @@ public class Util {
// return Bitmap.createScaledBitmap(bitmap, albumArtSize, albumArtSize, false);
// }
public static void hideSoftKeyboard(Activity activity) {
public static void hideSoftKeyboard(@Nullable Activity activity) {
if (activity != null) {
View currentFocus = activity.getCurrentFocus();
if (currentFocus != null) {
@ -160,15 +163,15 @@ public class Util {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
}
public static boolean isTablet(final Context context) {
public static boolean isTablet(@NonNull final Context context) {
return context.getResources().getConfiguration().smallestScreenWidthDp >= 600;
}
public static boolean isInPortraitMode(final Context context) {
public static boolean isInPortraitMode(@NonNull final Context context) {
return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
}
public static Drawable getTintedDrawable(Context context, @DrawableRes int drawableResId, int color) {
public static Drawable getTintedDrawable(@NonNull Context context, @DrawableRes int drawableResId, int color) {
Drawable drawable = ContextCompat.getDrawable(context, drawableResId);
if (drawable != null) {
drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
@ -195,6 +198,7 @@ public class Util {
return (alpha << 24) + (0x00ffffff & Color.HSVToColor(hsv));
}
@NonNull
public static ColorStateList getEmptyColorStateList(int color) {
return new ColorStateList(
new int[][]{
@ -205,14 +209,14 @@ public class Util {
}
@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
public static boolean isRTL(Context context) {
public static boolean isRTL(@NonNull Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
Configuration config = context.getResources().getConfiguration();
return config.getLayoutDirection() == View.LAYOUT_DIRECTION_RTL;
} else return false;
}
public static Bitmap getResizedBitmap(Bitmap bm, int newHeight, int newWidth, boolean recycleOld) {
public static Bitmap getResizedBitmap(@NonNull Bitmap bm, int newHeight, int newWidth, boolean recycleOld) {
int width = bm.getWidth();
int height = bm.getHeight();
float scaleWidth = ((float) newWidth) / width;

View file

@ -3,6 +3,8 @@ package com.kabouzeid.gramophone.util;
import android.animation.ArgbEvaluator;
import android.animation.ObjectAnimator;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.internal.view.menu.ListMenuItemView;
import android.support.v7.internal.view.menu.MenuPopupHelper;
import android.view.View;
@ -26,7 +28,7 @@ import java.lang.reflect.Field;
public class ViewUtil {
public final static int DEFAULT_COLOR_ANIMATION_DURATION = 500;
public static void disableViews(ViewGroup layout) {
public static void disableViews(@NonNull ViewGroup layout) {
for (int i = 0; i < layout.getChildCount(); i++) {
View child = layout.getChildAt(i);
if (child instanceof ViewGroup) {
@ -37,7 +39,7 @@ public class ViewUtil {
}
}
public static void enableViews(ViewGroup layout) {
public static void enableViews(@NonNull ViewGroup layout) {
for (int i = 0; i < layout.getChildCount(); i++) {
View child = layout.getChildAt(i);
if (child instanceof ViewGroup) {
@ -48,7 +50,7 @@ public class ViewUtil {
}
}
public static void setListViewHeightBasedOnChildren(ListView listView) {
public static void setListViewHeightBasedOnChildren(@NonNull ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null)
return;
@ -100,13 +102,13 @@ public class ViewUtil {
animator.start();
}
public static void setBackgroundAlpha(View view, float alpha, int baseColor) {
public static void setBackgroundAlpha(@NonNull View view, float alpha, int baseColor) {
int a = Math.min(255, Math.max(0, (int) (alpha * 255))) << 24;
int rgb = 0x00ffffff & baseColor;
view.setBackgroundColor(a + rgb);
}
public static void addOnGlobalLayoutListener(final View view, final Runnable runnable) {
public static void addOnGlobalLayoutListener(@NonNull final View view, @NonNull final Runnable runnable) {
ViewTreeObserver vto = view.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
@ -134,7 +136,7 @@ public class ViewUtil {
// }
// }
public static void setCheckBoxTintForMenu(MenuPopupHelper menuPopupHelper) {
public static void setCheckBoxTintForMenu(@Nullable MenuPopupHelper menuPopupHelper) {
if (menuPopupHelper != null) {
final ListView listView = menuPopupHelper.getPopup().getListView();
listView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {