Skip to content

Commit

Permalink
Added notification controller
Browse files Browse the repository at this point in the history
  • Loading branch information
architjn committed Dec 16, 2015
1 parent ce7c52f commit 45c0036
Show file tree
Hide file tree
Showing 33 changed files with 860 additions and 294 deletions.
14 changes: 9 additions & 5 deletions app/app.iml
Expand Up @@ -74,7 +74,9 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/palette-v7/23.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/recyclerview-v7/23.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/23.1.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.github.afollestad.material-dialogs/core/0.8.5.2/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.sothree.slidinguppanel/library/3.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/me.zhanghai.android.materialprogressbar/library/1.1.4/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
Expand All @@ -88,16 +90,18 @@
</content>
<orderEntry type="jdk" jdkName="Android API 23 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" exported="" name="recyclerview-v7-23.1.1" level="project" />
<orderEntry type="library" exported="" name="support-annotations-23.1.1" level="project" />
<orderEntry type="library" exported="" name="palette-v7-23.1.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.1.1" level="project" />
<orderEntry type="library" exported="" name="library-3.2.0" level="project" />
<orderEntry type="library" exported="" name="org.jbundle.util.osgi.wrapped.org.apache.http.client-4.1.2" level="project" />
<orderEntry type="library" exported="" name="design-23.1.1" level="project" />
<orderEntry type="library" exported="" name="core-0.8.5.2" level="project" />
<orderEntry type="library" exported="" name="recyclerview-v7-23.1.1" level="project" />
<orderEntry type="library" exported="" name="support-v4-23.1.1" level="project" />
<orderEntry type="library" exported="" name="palette-v7-23.1.1" level="project" />
<orderEntry type="library" exported="" name="appcompat-v7-23.1.1" level="project" />
<orderEntry type="library" exported="" name="org.jbundle.util.osgi.wrapped.org.apache.http.client-4.1.2" level="project" />
<orderEntry type="library" exported="" name="picasso-2.5.3-SNAPSHOT" level="project" />
<orderEntry type="library" exported="" name="cardview-v7-23.1.1" level="project" />
<orderEntry type="library" exported="" name="library-1.1.4" level="project" />
<orderEntry type="library" exported="" name="library-2.4.0" level="project" />
<orderEntry type="library" exported="" name="cardview-v7-23.1.1" level="project" />
</component>
</module>
7 changes: 5 additions & 2 deletions app/build.gradle
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "com.architjn.acjmusicplayer"
minSdkVersion 21
targetSdkVersion 23
versionCode 2
versionName "0.5beta"
versionCode 5
versionName "0.5.5beta"
}
buildTypes {
release {
Expand All @@ -33,4 +33,7 @@ dependencies {
compile 'com.squareup.picasso:picasso:+'
compile 'com.sothree.slidinguppanel:library:3.2.0'
compile 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
compile('com.github.afollestad.material-dialogs:core:0.8.5.2@aar') {
transitive = true
}
}
Expand Up @@ -12,6 +12,7 @@

import com.architjn.acjmusicplayer.R;
import com.architjn.acjmusicplayer.ui.layouts.activity.PlayerActivity;
import com.architjn.acjmusicplayer.utils.NotificationHandler;
import com.architjn.acjmusicplayer.utils.PlayerHandler;

import java.io.IOException;
Expand Down Expand Up @@ -43,17 +44,21 @@ public void onReceive(Context context, Intent intent) {
public static final String ACTION_PLAY_PLAYLIST = "ACTION_PLAY_PLAYLIST";
public static final String ACTION_PLAY_ARTIST = "ACTION_PLAY_ARTIST";
public static final String ACTION_GET_SONG = "ACTION_GET_SONG";
public static final String ACTION_NOTI_CLICK = "ACTION_NOTI_CLICK";
public static final String ACTION_NOTI_REMOVE = "ACTION_NOTI_REMOVE";
public static final String ACTION_CHANGE_SONG = "ACTION_CHANGE_SONG";
public static final String ACTION_SEEK_SONG = "ACTION_SEEK_SONG";
public static final String ACTION_NEXT_SONG = "ACTION_NEXT_SONG";
public static final String ACTION_PREV_SONG = "ACTION_PREV_SONG";
public static final String ACTION_PAUSE_SONG = "ACTION_PAUSE_SONG";

private NotificationHandler notificationHandler;

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
context = this;
musicPlayerHandler = new PlayerHandler(context, this);
if (musicPlayerHandler == null)
musicPlayerHandler = new PlayerHandler(context, this);
IntentFilter filter = new IntentFilter();
filter.addAction(ACTION_PLAY_SINGLE);
filter.addAction(ACTION_PLAY_ALL_SONGS);
Expand All @@ -66,11 +71,14 @@ public int onStartCommand(Intent intent, int flags, int startId) {
filter.addAction(ACTION_CHANGE_SONG);
filter.addAction(ACTION_PLAY_PLAYLIST);
filter.addAction(ACTION_PLAY_ARTIST);
filter.addAction(ACTION_NOTI_CLICK);
filter.addAction(ACTION_NOTI_REMOVE);
registerReceiver(playerServiceBroadcastReceiver, filter);
return START_STICKY;
notificationHandler = new NotificationHandler(context, this);
return START_NOT_STICKY;
}

private void handleBroadcastReceived(Context context, Intent intent) throws IOException {
private void handleBroadcastReceived(Context context, final Intent intent) throws IOException {
switch (intent.getAction()) {
case ACTION_PLAY_SINGLE:
musicPlayerHandler.playSingleSong(intent.getLongExtra("songId", 0));
Expand All @@ -86,7 +94,11 @@ private void handleBroadcastReceived(Context context, Intent intent) throws IOEx
updatePlayer();
break;
case ACTION_GET_SONG:
updatePlayer();
try {
updatePlayer();
} catch (ArrayIndexOutOfBoundsException e) {
e.printStackTrace();
}
break;
case ACTION_NEXT_SONG:
musicPlayerHandler.playNextSong(musicPlayerHandler.getCurrentPlayingPos() + 1);
Expand All @@ -96,7 +108,7 @@ private void handleBroadcastReceived(Context context, Intent intent) throws IOEx
updatePlayer();
break;
case ACTION_PAUSE_SONG:
musicPlayerHandler.playOrStop();
musicPlayerHandler.playOrStop(notificationHandler);
break;
case ACTION_SEEK_SONG:
musicPlayerHandler.seek(intent.getIntExtra("seek", 0));
Expand All @@ -114,6 +126,14 @@ private void handleBroadcastReceived(Context context, Intent intent) throws IOEx
intent.getIntExtra("pos", 0));
updatePlayer();
break;
case ACTION_NOTI_CLICK:
Intent i = new Intent(context, PlayerActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(i);
break;
case ACTION_NOTI_REMOVE:
notificationHandler.setNotificationActive(false);
break;
}
}

Expand All @@ -126,6 +146,17 @@ public void updatePlayer() {
i.putExtra("seek", musicPlayerHandler.getMediaPlayer().getCurrentPosition());
i.putExtra("pos", musicPlayerHandler.getCurrentPlayingPos());
sendBroadcast(i);
updateNotificationPlayer();
}

private void updateNotificationPlayer() {
if (!notificationHandler.isNotificationActive())
notificationHandler.setNotificationPlayer(false);
notificationHandler.changeNotificationDetails(musicPlayerHandler
.getCurrentPlayingSong().getName(), musicPlayerHandler
.getCurrentPlayingSong().getArtist(), musicPlayerHandler
.getCurrentPlayingSong().getAlbumId(), musicPlayerHandler
.getMediaPlayer().isPlaying());
}

@Nullable
Expand Down
Expand Up @@ -5,9 +5,10 @@
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.os.AsyncTask;
import android.support.v7.graphics.Palette;
import android.view.View;
import android.widget.TextView;

import com.architjn.acjmusicplayer.R;
import com.architjn.acjmusicplayer.utils.adapters.AlbumListAdapter;
Expand All @@ -19,14 +20,31 @@ public class AlbumItemLoad extends AsyncTask<Void, Void, Void> {

private Context context;
private String artPath;
private AlbumListAdapter.SimpleItemViewHolder holder;
private TextView name, artist;
private View bgView;
private ValueAnimator colorAnimation;
private Bitmap bmp;
private long duration = 800;

public AlbumItemLoad(Context context, String artPath, View header) {
this.context = context;
this.artPath = artPath;
name = (TextView) header.findViewById(R.id.album_list_long_name);
artist = (TextView) header.findViewById(R.id.album_list_long_artist);
bgView = header.findViewById(R.id.album_grid_header_bg);
}

public AlbumItemLoad(Context context, String artPath, AlbumListAdapter.SimpleItemViewHolder holder) {
this.context = context;
this.artPath = artPath;
this.holder = holder;
this.name = holder.name;
this.artist = holder.artist;
this.bgView = holder.bottomBg;
}

@Override
protected void onPreExecute() {
super.onPreExecute();
}

@Override
Expand All @@ -36,47 +54,47 @@ protected Void doInBackground(Void... voids) {
new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(final Palette palette) {
Integer colorFrom = context.getResources().getColor(R.color.colorPrimary);
Integer colorTo = palette.getVibrantColor(palette.getDarkVibrantColor(
palette.getDarkMutedColor(palette.getMutedColor(
context.getResources().getColor(R.color.colorPrimary)))));
colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
colorAnimation.setDuration(800);
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
try {
Integer colorFrom = context.getResources().getColor(android.R.color.white);
Integer colorTo = palette.getVibrantColor(palette.getDarkVibrantColor(
palette.getDarkMutedColor(palette.getMutedColor(
context.getResources().getColor(R.color.colorPrimary)))));
colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
colorAnimation.setDuration(duration);
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

@Override
public void onAnimationUpdate(ValueAnimator animator) {
holder.bottomBg.setBackgroundColor((Integer) animator.getAnimatedValue());
}
@Override
public void onAnimationUpdate(ValueAnimator animator) {
bgView.setBackgroundColor((Integer) animator.getAnimatedValue());
}

});
colorAnimation.start();
try {
Integer colorFrom1 = Color.parseColor("#ffffff");
});
colorAnimation.start();
Integer colorFrom1 = context.getResources().getColor(R.color.album_grid_name_default);
Integer colorTo1 = palette.getVibrantSwatch().getBodyTextColor();
colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom1, colorTo1);
colorAnimation.setDuration(800);
colorAnimation.setDuration(duration);
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
holder.name.setTextColor((Integer) animator.getAnimatedValue());
name.setTextColor((Integer) animator.getAnimatedValue());
}
});
colorAnimation.start();
Integer colorFrom2 = Color.parseColor("#E5E5E5");
Integer colorFrom2 = context.getResources().getColor(R.color.album_grid_artist_default);
Integer colorTo2 = palette.getVibrantSwatch().getTitleTextColor();
colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom2, colorTo2);
colorAnimation.setDuration(800);
colorAnimation.setDuration(duration);
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
@Override
public void onAnimationUpdate(ValueAnimator animator) {
holder.artist.setTextColor((Integer) animator.getAnimatedValue());
artist.setTextColor((Integer) animator.getAnimatedValue());
}
});
colorAnimation.start();
} catch (NullPointerException e) {
e.printStackTrace();
holder.bottomBg.setBackgroundColor(context.getResources()
bgView.setBackgroundColor(context.getResources()
.getColor(R.color.colorPrimary));
}
}
Expand Down
Expand Up @@ -32,29 +32,33 @@ public ColorChangeAnimation(Context context, LinearLayout detailHolder, String a

@Override
protected Void doInBackground(Void... params) {
Bitmap bmp = BitmapFactory.decodeFile(artPath);
Palette.generateAsync(bmp,
new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(final Palette palette) {
Integer colorTo = palette.getVibrantColor(palette.getDarkVibrantColor(
palette.getDarkMutedColor(palette.getMutedColor(
context.getResources().getColor(R.color.colorPrimary)))));
onColorFetched(colorTo);
colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
colorAnimation.setDuration(2000);
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
try {
Bitmap bmp = BitmapFactory.decodeFile(artPath);
Palette.generateAsync(bmp,
new Palette.PaletteAsyncListener() {
@Override
public void onGenerated(final Palette palette) {
Integer colorTo = palette.getVibrantColor(palette.getDarkVibrantColor(
palette.getDarkMutedColor(palette.getMutedColor(
context.getResources().getColor(R.color.colorPrimary)))));
onColorFetched(colorTo);
colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo);
colorAnimation.setDuration(2000);
colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {

@Override
public void onAnimationUpdate(ValueAnimator animator) {
detailHolder.setBackgroundColor((Integer) animator.getAnimatedValue());
}
@Override
public void onAnimationUpdate(ValueAnimator animator) {
detailHolder.setBackgroundColor((Integer) animator.getAnimatedValue());
}

});
colorAnimation.start();
});
colorAnimation.start();
}
}
}
);
);
} catch (IllegalArgumentException e) {
e.printStackTrace();
}
return null;
}

Expand Down
Expand Up @@ -30,6 +30,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.List;
Expand All @@ -51,9 +53,15 @@ public FetchArtistArtWork(Context context, String name, int random) {
this.context = context;
this.name = name;
this.random = random;
if (name.matches("<unknown>"))
this.cancel(true);
StringBuilder builder = new StringBuilder();
builder.append(context.getResources().getString(R.string.artist_fetch_url));
builder.append("&artist=" + name.replace(" ", "+"));
try {
builder.append("&artist=" + URLEncoder.encode(name, "UTF-8"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
builder.append("&api_key=" + context.getResources().getString(R.string.api));
builder.append("&format=json");
this.url = builder.toString();
Expand Down
Expand Up @@ -35,6 +35,8 @@ protected Void doInBackground(Long... ids) {

public Bitmap getAlbumart(Long album_id) {
Bitmap bm = null;
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = Math.max(options.outWidth/img.getWidth(), options.outHeight/img.getHeight());
try {
final Uri sArtworkUri = Uri
.parse("content://media/external/audio/albumart");
Expand All @@ -46,7 +48,7 @@ public Bitmap getAlbumart(Long album_id) {

if (pfd != null) {
FileDescriptor fd = pfd.getFileDescriptor();
bm = BitmapFactory.decodeFileDescriptor(fd);
bm = BitmapFactory.decodeFileDescriptor(fd,null,options);
}
} catch (Exception e) {
}
Expand All @@ -59,8 +61,10 @@ protected void onPostExecute(Void aVoid) {
img.setImageBitmap(bmp);
return;
}
ImageBlurAnimator animator = new ImageBlurAnimator(context, img, 20, bmp);
animator.animate();
if (bmp != null) {
ImageBlurAnimator animator = new ImageBlurAnimator(context, img, 20, bmp);
animator.animate();
}
super.onPostExecute(aVoid);
}
}

0 comments on commit 45c0036

Please sign in to comment.