Minor formatting/refactoring

This commit is contained in:
Eugene Cheung 2017-06-12 23:23:30 -04:00
commit 487748258a
147 changed files with 351 additions and 341 deletions

View file

@ -25,7 +25,7 @@ public class App extends Application {
.build();
Fabric.with(this, crashlyticsKit);
//Set up dynamic shortcuts
// Set up dynamic shortcuts
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
new DynamicShortcutManager(this).initDynamicShortcuts();
}

View file

@ -18,7 +18,6 @@ import com.kabouzeid.gramophone.util.Util;
/**
* @author Adrian Campos
*/
@RequiresApi(Build.VERSION_CODES.N_MR1)
public final class AppShortcutIconGenerator {
public static Icon generateThemedIcon(Context context, int iconId) {
@ -30,7 +29,7 @@ public final class AppShortcutIconGenerator {
}
private static Icon generateDefaultThemedIcon(Context context, int iconId) {
//Return an Icon of iconId with default colors
// Return an Icon of iconId with default colors
return generateThemedIcon(context, iconId,
context.getColor(R.color.app_shortcut_default_foreground),
context.getColor(R.color.app_shortcut_default_background)
@ -38,11 +37,11 @@ public final class AppShortcutIconGenerator {
}
private static Icon generateUserThemedIcon(Context context, int iconId) {
//Get background color from context's theme
// Get background color from context's theme
final TypedValue typedColorBackground = new TypedValue();
context.getTheme().resolveAttribute(android.R.attr.colorBackground, typedColorBackground, true);
//Return an Icon of iconId with those colors
// Return an Icon of iconId with those colors
return generateThemedIcon(context, iconId,
ThemeStore.primaryColor(context),
typedColorBackground.data
@ -50,14 +49,14 @@ public final class AppShortcutIconGenerator {
}
private static Icon generateThemedIcon(Context context, int iconId, int foregroundColor, int backgroundColor) {
//Get and tint foreground and background drawables
// Get and tint foreground and background drawables
Drawable vectorDrawable = Util.getTintedVectorDrawable(context, iconId, foregroundColor);
Drawable backgroundDrawable = Util.getTintedVectorDrawable(context, R.drawable.ic_app_shortcut_background, backgroundColor);
//Squash the two drawables together
// Squash the two drawables together
LayerDrawable layerDrawable = new LayerDrawable(new Drawable[]{backgroundDrawable, vectorDrawable});
//Return as an Icon
// Return as an Icon
return Icon.createWithBitmap(drawableToBitmap(layerDrawable));
}

View file

@ -31,7 +31,7 @@ public class AppShortcutLauncherActivity extends Activity {
int shortcutType = SHORTCUT_TYPE_NONE;
//Set shortcutType from the intent extras
// Set shortcutType from the intent extras
Bundle extras = getIntent().getExtras();
if (extras != null) {
//noinspection WrongConstant

View file

@ -4,6 +4,7 @@ import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ShortcutInfo;
import android.os.Build;
import android.os.Bundle;
import com.kabouzeid.gramophone.appshortcuts.AppShortcutLauncherActivity;
@ -11,8 +12,7 @@ import com.kabouzeid.gramophone.appshortcuts.AppShortcutLauncherActivity;
/**
* @author Adrian Campos
*/
@TargetApi(25)
@TargetApi(Build.VERSION_CODES.N_MR1)
public abstract class BaseShortcutType {
static final String ID_PREFIX = "com.kabouzeid.gramophone.appshortcuts.id.";
@ -23,13 +23,11 @@ public abstract class BaseShortcutType {
this.context = context;
}
abstract ShortcutInfo getShortcutInfo();
static public String getId() {
return ID_PREFIX + "invalid";
}
abstract ShortcutInfo getShortcutInfo();
/**
* Creates an Intent that will launch MainActivtiy and immediately play {@param songs} in either shuffle or normal mode

View file

@ -3,6 +3,7 @@ package com.kabouzeid.gramophone.appshortcuts.shortcuttype;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.pm.ShortcutInfo;
import android.os.Build;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.appshortcuts.AppShortcutIconGenerator;
@ -11,13 +12,16 @@ import com.kabouzeid.gramophone.appshortcuts.AppShortcutLauncherActivity;
/**
* @author Adrian Campos
*/
@TargetApi(25)
@TargetApi(Build.VERSION_CODES.N_MR1)
public final class LastAddedShortcutType extends BaseShortcutType {
public LastAddedShortcutType(Context context) {
super(context);
}
public static String getId() {
return ID_PREFIX + "last_added";
}
public ShortcutInfo getShortcutInfo() {
return new ShortcutInfo.Builder(context, getId())
.setShortLabel(context.getString(R.string.app_shortcut_last_added_short))
@ -26,8 +30,4 @@ public final class LastAddedShortcutType extends BaseShortcutType {
.setIntent(getPlaySongsIntent(AppShortcutLauncherActivity.SHORTCUT_TYPE_LAST_ADDED))
.build();
}
public static String getId(){
return ID_PREFIX + "last_added";
}
}

View file

@ -3,6 +3,7 @@ package com.kabouzeid.gramophone.appshortcuts.shortcuttype;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.pm.ShortcutInfo;
import android.os.Build;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.appshortcuts.AppShortcutIconGenerator;
@ -11,13 +12,16 @@ import com.kabouzeid.gramophone.appshortcuts.AppShortcutLauncherActivity;
/**
* @author Adrian Campos
*/
@TargetApi(25)
@TargetApi(Build.VERSION_CODES.N_MR1)
public final class ShuffleAllShortcutType extends BaseShortcutType {
public ShuffleAllShortcutType(Context context) {
super(context);
}
public static String getId() {
return ID_PREFIX + "shuffle_all";
}
public ShortcutInfo getShortcutInfo() {
return new ShortcutInfo.Builder(context, getId())
.setShortLabel(context.getString(R.string.app_shortcut_shuffle_all_short))
@ -26,8 +30,4 @@ public final class ShuffleAllShortcutType extends BaseShortcutType {
.setIntent(getPlaySongsIntent(AppShortcutLauncherActivity.SHORTCUT_TYPE_SHUFFLE_ALL))
.build();
}
public static String getId() {
return ID_PREFIX + "shuffle_all";
}
}

View file

@ -3,6 +3,7 @@ package com.kabouzeid.gramophone.appshortcuts.shortcuttype;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.pm.ShortcutInfo;
import android.os.Build;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.appshortcuts.AppShortcutIconGenerator;
@ -11,13 +12,16 @@ import com.kabouzeid.gramophone.appshortcuts.AppShortcutLauncherActivity;
/**
* @author Adrian Campos
*/
@TargetApi(25)
@TargetApi(Build.VERSION_CODES.N_MR1)
public final class TopTracksShortcutType extends BaseShortcutType {
public TopTracksShortcutType(Context context) {
super(context);
}
public static String getId() {
return ID_PREFIX + "top_tracks";
}
public ShortcutInfo getShortcutInfo() {
return new ShortcutInfo.Builder(context, getId())
.setShortLabel(context.getString(R.string.app_shortcut_top_tracks_short))
@ -26,8 +30,4 @@ public final class TopTracksShortcutType extends BaseShortcutType {
.setIntent(getPlaySongsIntent(AppShortcutLauncherActivity.SHORTCUT_TYPE_TOP_TRACKS))
.build();
}
public static String getId() {
return ID_PREFIX + "top_tracks";
}
}

View file

@ -32,6 +32,7 @@ public class AppWidgetBig extends BaseAppWidget {
public static final String NAME = "app_widget_big";
private static AppWidgetBig mInstance;
private Target<Bitmap> target; // for cancellation
public static synchronized AppWidgetBig getInstance() {
if (mInstance == null) {
@ -125,14 +126,14 @@ public class AppWidgetBig extends BaseAppWidget {
int playPauseRes = isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, createBitmap(Util.getTintedVectorDrawable(service, playPauseRes, MaterialValueHelper.getPrimaryTextColor(service, false)), 1f));
// set prev/next button drawables
// Set prev/next button drawables
appWidgetView.setImageViewBitmap(R.id.button_next, createBitmap(Util.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getPrimaryTextColor(service, false)), 1f));
appWidgetView.setImageViewBitmap(R.id.button_prev, createBitmap(Util.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getPrimaryTextColor(service, false)), 1f));
// Link actions buttons to intents
linkButtons(service, appWidgetView);
// load the album cover async and push the update on completion
// Load the album cover async and push the update on completion
Point p = Util.getScreenSize(service);
final int widgetImageSize = Math.min(p.x, p.y);
final Context appContext = service.getApplicationContext();
@ -171,8 +172,6 @@ public class AppWidgetBig extends BaseAppWidget {
});
}
private Target<Bitmap> target; // for cancellation
/**
* Link up various button actions using {@link PendingIntent}.
*/

View file

@ -31,6 +31,7 @@ public class AppWidgetClassic extends BaseAppWidget {
public static final String NAME = "app_widget_classic";
private static AppWidgetClassic mInstance;
private Target<Bitmap> target; // for cancellation
public static synchronized AppWidgetClassic getInstance() {
if (mInstance == null) {
@ -124,14 +125,14 @@ public class AppWidgetClassic extends BaseAppWidget {
int playPauseRes = isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, createBitmap(Util.getTintedVectorDrawable(service, playPauseRes, MaterialValueHelper.getSecondaryTextColor(service, false)), 1f));
// set prev/next button drawables
// Set prev/next button drawables
appWidgetView.setImageViewBitmap(R.id.button_next, createBitmap(Util.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getSecondaryTextColor(service, false)), 1f));
appWidgetView.setImageViewBitmap(R.id.button_prev, createBitmap(Util.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(service, false)), 1f));
// Link actions buttons to intents
linkButtons(service, appWidgetView);
// load the album cover async and push the update on completion
// Load the album cover async and push the update on completion
final Context appContext = service.getApplicationContext();
final int widgetImageSize = service.getResources().getDimensionPixelSize(R.dimen.app_widget_classic_image_size);
service.runOnUiThread(new Runnable() {
@ -169,8 +170,6 @@ public class AppWidgetClassic extends BaseAppWidget {
});
}
private Target<Bitmap> target; // for cancellation
/**
* Link up various button actions using {@link PendingIntent}.
*/

View file

@ -31,6 +31,7 @@ public class AppWidgetSmall extends BaseAppWidget {
public static final String NAME = "app_widget_small";
private static AppWidgetSmall mInstance;
private Target<Bitmap> target; // for cancellation
public static synchronized AppWidgetSmall getInstance() {
if (mInstance == null) {
@ -130,14 +131,14 @@ public class AppWidgetSmall extends BaseAppWidget {
int playPauseRes = isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, createBitmap(Util.getTintedVectorDrawable(service, playPauseRes, MaterialValueHelper.getSecondaryTextColor(service, false)), 1f));
// set prev/next button drawables
// Set prev/next button drawables
appWidgetView.setImageViewBitmap(R.id.button_next, createBitmap(Util.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getSecondaryTextColor(service, false)), 1f));
appWidgetView.setImageViewBitmap(R.id.button_prev, createBitmap(Util.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(service, false)), 1f));
// Link actions buttons to intents
linkButtons(service, appWidgetView);
// load the album cover async and push the update on completion
// Load the album cover async and push the update on completion
final Context appContext = service.getApplicationContext();
final int widgetImageSize = service.getResources().getDimensionPixelSize(R.dimen.app_widget_small_image_size);
service.runOnUiThread(new Runnable() {
@ -175,8 +176,6 @@ public class AppWidgetSmall extends BaseAppWidget {
});
}
private Target<Bitmap> target; // for cancellation
/**
* Link up various button actions using {@link PendingIntent}.
*/

View file

@ -14,12 +14,6 @@ import android.graphics.drawable.Drawable;
*/
public class BaseAppWidget extends AppWidgetProvider {
protected PendingIntent buildPendingIntent(Context context, final String action, final ComponentName serviceName) {
Intent intent = new Intent(action);
intent.setComponent(serviceName);
return PendingIntent.getService(context, 0, intent, 0);
}
protected static Bitmap createBitmap(Drawable drawable, float sizeMultiplier) {
Bitmap bitmap = Bitmap.createBitmap((int) (drawable.getIntrinsicWidth() * sizeMultiplier), (int) (drawable.getIntrinsicHeight() * sizeMultiplier), Bitmap.Config.ARGB_8888);
Canvas c = new Canvas(bitmap);
@ -27,4 +21,10 @@ public class BaseAppWidget extends AppWidgetProvider {
drawable.draw(c);
return bitmap;
}
protected PendingIntent buildPendingIntent(Context context, final String action, final ComponentName serviceName) {
Intent intent = new Intent(action);
intent.setComponent(serviceName);
return PendingIntent.getService(context, 0, intent, 0);
}
}

View file

@ -1,35 +1,31 @@
package com.kabouzeid.gramophone.misc;
import android.annotation.TargetApi;
import android.os.Build;
import android.transition.Transition;
/**
* @author Karim Abou Zeid (kabouzeid)
*/
@TargetApi(21)
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public abstract class SimpleTransitionListener implements Transition.TransitionListener {
@Override
public void onTransitionStart(Transition transition) {
}
@Override
public void onTransitionEnd(Transition transition) {
}
@Override
public void onTransitionCancel(Transition transition) {
}
@Override
public void onTransitionPause(Transition transition) {
}
@Override
public void onTransitionResume(Transition transition) {
}
}

View file

@ -7,7 +7,6 @@ import android.support.annotation.NonNull;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.loader.LastAddedLoader;
import com.kabouzeid.gramophone.model.Song;
import com.kabouzeid.gramophone.util.PreferenceUtil;
import java.util.ArrayList;

View file

@ -69,7 +69,7 @@ public class AboutActivity extends AbsBaseActivity implements View.OnClickListen
LinearLayout addToGooglePlusCircles;
@BindView(R.id.follow_on_twitter)
LinearLayout followOnTwitter;
@BindView(R.id.fork_on_git_hub)
@BindView(R.id.fork_on_github)
LinearLayout forkOnGitHub;
@BindView(R.id.visit_website)
LinearLayout visitWebsite;

View file

@ -9,8 +9,8 @@ import android.support.v7.widget.GridLayoutManager;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.adapter.album.AlbumAdapter;
import com.kabouzeid.gramophone.loader.AlbumLoader;
import com.kabouzeid.gramophone.interfaces.LoaderIds;
import com.kabouzeid.gramophone.loader.AlbumLoader;
import com.kabouzeid.gramophone.misc.WrappedAsyncTaskLoader;
import com.kabouzeid.gramophone.model.Album;
import com.kabouzeid.gramophone.util.PreferenceUtil;

View file

@ -9,8 +9,8 @@ import android.support.v7.widget.GridLayoutManager;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.adapter.artist.ArtistAdapter;
import com.kabouzeid.gramophone.loader.ArtistLoader;
import com.kabouzeid.gramophone.interfaces.LoaderIds;
import com.kabouzeid.gramophone.loader.ArtistLoader;
import com.kabouzeid.gramophone.misc.WrappedAsyncTaskLoader;
import com.kabouzeid.gramophone.model.Artist;
import com.kabouzeid.gramophone.util.PreferenceUtil;

View file

@ -9,8 +9,8 @@ import android.support.v7.widget.LinearLayoutManager;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.adapter.PlaylistAdapter;
import com.kabouzeid.gramophone.loader.PlaylistLoader;
import com.kabouzeid.gramophone.interfaces.LoaderIds;
import com.kabouzeid.gramophone.loader.PlaylistLoader;
import com.kabouzeid.gramophone.misc.WrappedAsyncTaskLoader;
import com.kabouzeid.gramophone.model.Playlist;
import com.kabouzeid.gramophone.model.smartplaylist.HistoryPlaylist;

View file

@ -10,8 +10,8 @@ import android.support.v7.widget.GridLayoutManager;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.adapter.song.ShuffleButtonSongAdapter;
import com.kabouzeid.gramophone.adapter.song.SongAdapter;
import com.kabouzeid.gramophone.loader.SongLoader;
import com.kabouzeid.gramophone.interfaces.LoaderIds;
import com.kabouzeid.gramophone.loader.SongLoader;
import com.kabouzeid.gramophone.misc.WrappedAsyncTaskLoader;
import com.kabouzeid.gramophone.model.Song;
import com.kabouzeid.gramophone.util.PreferenceUtil;

View file

@ -4,7 +4,7 @@ import java.util.Calendar;
import java.util.GregorianCalendar;
/**
* @author Karim Abou Zeid (kabouzeid)
* @author Eugene Cheung (arkon)
*/
public class CalendarUtil {
private static final long MS_PER_MINUTE = 60 * 1000;

View file

@ -49,7 +49,7 @@ public class Util {
return size;
}
@TargetApi(19)
@TargetApi(Build.VERSION_CODES.KITKAT)
public static void setStatusBarTranslucent(@NonNull Window window) {
window.setFlags(
WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS,