-
Notifications
You must be signed in to change notification settings - Fork 88
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
356 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright (C) 2010 Christopher Eby <kreed@kreed.org> | ||
This file is part of Vanilla Music Player. | ||
Vanilla Music Player is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU Library General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or (at your | ||
option) any later version. | ||
Vanilla Music Player is distributed in the hope that it will be useful, but | ||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
or FITNESS FOR A PARTICULAR PURPOSE. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
--> | ||
<selector xmlns:android="http://schemas.android.com/apk/res/android"> | ||
<item | ||
android:state_pressed="true" | ||
android:drawable="@drawable/button_background_focused" /> | ||
<item | ||
android:state_focused="true" | ||
android:drawable="@drawable/button_background_focused" /> | ||
<item android:drawable="@android:color/transparent" /> | ||
</selector> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright (C) 2010 Christopher Eby <kreed@kreed.org> | ||
This file is part of Vanilla Music Player. | ||
Vanilla Music Player is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU Library General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or (at your | ||
option) any later version. | ||
Vanilla Music Player is distributed in the hope that it will be useful, but | ||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
or FITNESS FOR A PARTICULAR PURPOSE. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
--> | ||
<shape xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:shape="rectangle"> | ||
<gradient | ||
android:endColor="#A9D2E2" | ||
android:startColor="#274162" | ||
android:angle="90" /> | ||
</shape> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright (C) 2010 Christopher Eby <kreed@kreed.org> | ||
This file is part of Vanilla Music Player. | ||
Vanilla Music Player is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU Library General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or (at your | ||
option) any later version. | ||
Vanilla Music Player is distributed in the hope that it will be useful, but | ||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
or FITNESS FOR A PARTICULAR PURPOSE. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
--> | ||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/layout" | ||
android:layout_width="fill_parent" | ||
android:layout_height="fill_parent" | ||
android:orientation="horizontal" | ||
android:clickable="true" | ||
android:background="@drawable/appwidget_bg"> | ||
<ImageView | ||
android:id="@+id/cover" | ||
android:visibility="gone" | ||
android:layout_width="wrap_content" | ||
android:layout_height="fill_parent" | ||
android:adjustViewBounds="true" | ||
android:padding="4dip" | ||
android:scaleType="fitCenter" /> | ||
<LinearLayout | ||
android:orientation="vertical" | ||
android:layout_width="0dip" | ||
android:layout_height="fill_parent" | ||
android:layout_weight="1"> | ||
<LinearLayout | ||
android:layout_width="fill_parent" | ||
android:layout_height="0dip" | ||
android:layout_weight="1" | ||
android:layout_gravity="center" | ||
android:orientation="vertical" | ||
android:paddingLeft="8dip" | ||
android:paddingRight="8dip"> | ||
<TextView | ||
android:id="@+id/title" | ||
android:layout_width="fill_parent" | ||
android:layout_height="wrap_content" | ||
android:textColor="#fff" | ||
android:textStyle="bold" | ||
android:textSize="13dip" | ||
android:singleLine="true" | ||
android:fadingEdge="horizontal" | ||
android:fadingEdgeLength="10dip" | ||
android:ellipsize="none" /> | ||
<TextView | ||
android:id="@+id/artist" | ||
android:layout_width="fill_parent" | ||
android:layout_height="wrap_content" | ||
android:textColor="#fff" | ||
android:textSize="13dip" | ||
android:singleLine="true" | ||
android:fadingEdge="horizontal" | ||
android:fadingEdgeLength="10dip" | ||
android:ellipsize="none" /> | ||
</LinearLayout> | ||
<ImageView | ||
android:layout_height="1dip" | ||
android:layout_width="fill_parent" | ||
android:background="@drawable/appwidget_divider" /> | ||
<LinearLayout | ||
android:orientation="horizontal" | ||
android:layout_width="fill_parent" | ||
android:layout_height="0dip" | ||
android:layout_weight="1"> | ||
<ImageButton | ||
android:id="@+id/previous" | ||
android:background="@drawable/button_background" | ||
android:layout_width="0dip" | ||
android:layout_weight="1" | ||
android:layout_height="fill_parent" | ||
android:src="@drawable/previous" | ||
android:scaleType="fitCenter" /> | ||
<ImageView | ||
android:layout_width="1dip" | ||
android:layout_height="fill_parent" | ||
android:background="@drawable/appwidget_divider" /> | ||
<ImageButton | ||
android:id="@+id/play" | ||
android:background="@drawable/button_background" | ||
android:layout_width="0dip" | ||
android:layout_weight="1" | ||
android:layout_height="fill_parent" | ||
android:src="@drawable/play" | ||
android:scaleType="fitCenter" /> | ||
<ImageView | ||
android:layout_width="1dip" | ||
android:layout_height="fill_parent" | ||
android:background="@drawable/appwidget_divider" /> | ||
<ImageButton | ||
android:id="@+id/next" | ||
android:background="@drawable/button_background" | ||
android:layout_width="0dip" | ||
android:layout_weight="1" | ||
android:layout_height="fill_parent" | ||
android:src="@drawable/next" | ||
android:scaleType="fitCenter" /> | ||
</LinearLayout> | ||
</LinearLayout> | ||
</LinearLayout> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
Copyright (C) 2010 Christopher Eby <kreed@kreed.org> | ||
This file is part of Vanilla Music Player. | ||
Vanilla Music Player is free software; you can redistribute it and/or modify | ||
it under the terms of the GNU Library General Public License as published by | ||
the Free Software Foundation, either version 3 of the License, or (at your | ||
option) any later version. | ||
Vanilla Music Player is distributed in the hope that it will be useful, but | ||
WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
or FITNESS FOR A PARTICULAR PURPOSE. | ||
You should have received a copy of the GNU General Public License | ||
along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
--> | ||
<appwidget-provider | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:minWidth="294dip" | ||
android:minHeight="72dip" | ||
android:initialLayout="@layout/four_long_widget" | ||
/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
/* | ||
* Copyright (C) 2010 Christopher Eby <kreed@kreed.org> | ||
* | ||
* This file is part of Vanilla Music Player. | ||
* | ||
* Vanilla Music Player is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU Library General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or (at your | ||
* option) any later version. | ||
* | ||
* Vanilla Music Player is distributed in the hope that it will be useful, but | ||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY | ||
* or FITNESS FOR A PARTICULAR PURPOSE. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package org.kreed.vanilla; | ||
|
||
import android.app.PendingIntent; | ||
import android.appwidget.AppWidgetManager; | ||
import android.appwidget.AppWidgetProvider; | ||
import android.content.ComponentName; | ||
import android.content.Context; | ||
import android.content.Intent; | ||
import android.content.res.Resources; | ||
import android.graphics.Bitmap; | ||
import android.view.View; | ||
import android.widget.RemoteViews; | ||
|
||
/** | ||
* Simple 1x4 widget to show currently playing song, album art, and play/pause, | ||
* next, and previous buttons. Uses artwork from the default Android music | ||
* widget. | ||
*/ | ||
public class FourLongWidget extends AppWidgetProvider { | ||
@Override | ||
public void onUpdate(Context context, AppWidgetManager manager, int[] ids) | ||
{ | ||
Song song; | ||
int state; | ||
|
||
if (ContextApplication.hasService()) { | ||
PlaybackService service = ContextApplication.getService(); | ||
song = service.getSong(0); | ||
state = service.getState(); | ||
} else { | ||
SongTimeline timeline = new SongTimeline(); | ||
timeline.loadState(context); | ||
song = timeline.getSong(0); | ||
state = 0; | ||
|
||
// If we generated a new current song (because the PlaybackService has | ||
// never been started), then we need to save the state. | ||
timeline.saveState(context, 0); | ||
} | ||
|
||
updateWidget(context, manager, ids, song, state); | ||
} | ||
|
||
/** | ||
* Receive a broadcast sent by the PlaybackService and update the widget | ||
* accordingly. | ||
* | ||
* @param intent The intent that was broadcast. | ||
*/ | ||
public static void receive(Intent intent) | ||
{ | ||
String action = intent.getAction(); | ||
if (PlaybackService.EVENT_CHANGED.equals(action) || PlaybackService.EVENT_REPLACE_SONG.equals(action)) { | ||
Context context = ContextApplication.getContext(); | ||
Song song = intent.getParcelableExtra("song"); | ||
int state = intent.getIntExtra("state", -1); | ||
|
||
AppWidgetManager manager = AppWidgetManager.getInstance(context); | ||
int[] ids = manager.getAppWidgetIds(new ComponentName(context, FourLongWidget.class)); | ||
updateWidget(context, manager, ids, song, state); | ||
} | ||
} | ||
|
||
/** | ||
* Populate the widgets with the given ids with the given info. | ||
* | ||
* @param context A Context to use. | ||
* @param manager The AppWidgetManager that will be used to update the | ||
* widget. | ||
* @param ids An array containing the ids of all the widgets to update. | ||
* @param song The current Song in PlaybackService. | ||
* @param state The current PlaybackService state. | ||
*/ | ||
public static void updateWidget(Context context, AppWidgetManager manager, int[] ids, Song song, int state) | ||
{ | ||
if (ids == null || ids.length == 0) | ||
return; | ||
|
||
Resources res = context.getResources(); | ||
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.four_long_widget); | ||
|
||
Bitmap cover = null; | ||
|
||
if (song == null) { | ||
views.setViewVisibility(R.id.title, View.GONE); | ||
views.setTextViewText(R.id.artist, res.getText(R.string.no_songs)); | ||
} else { | ||
views.setViewVisibility(R.id.title, View.VISIBLE); | ||
views.setTextViewText(R.id.title, song.title); | ||
views.setTextViewText(R.id.artist, song.artist); | ||
cover = song.getCover(); | ||
} | ||
|
||
if (cover == null) { | ||
views.setViewVisibility(R.id.cover, View.GONE); | ||
} else { | ||
views.setViewVisibility(R.id.cover, View.VISIBLE); | ||
views.setImageViewBitmap(R.id.cover, cover); | ||
} | ||
|
||
if (state != -1) { | ||
boolean playing = (state & PlaybackService.FLAG_PLAYING) != 0; | ||
views.setImageViewResource(R.id.play, playing ? R.drawable.pause : R.drawable.play); | ||
} | ||
|
||
Intent intent; | ||
PendingIntent pendingIntent; | ||
|
||
ComponentName service = new ComponentName(context, PlaybackService.class); | ||
|
||
intent = new Intent(context, LaunchActivity.class); | ||
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); | ||
views.setOnClickPendingIntent(R.id.layout, pendingIntent); | ||
|
||
intent = new Intent(PlaybackService.ACTION_PREVIOUS_SONG).setComponent(service); | ||
pendingIntent = PendingIntent.getService(context, 0, intent, 0); | ||
views.setOnClickPendingIntent(R.id.previous, pendingIntent); | ||
|
||
intent = new Intent(PlaybackService.ACTION_TOGGLE_PLAYBACK).setComponent(service); | ||
pendingIntent = PendingIntent.getService(context, 0, intent, 0); | ||
views.setOnClickPendingIntent(R.id.play, pendingIntent); | ||
|
||
intent = new Intent(PlaybackService.ACTION_NEXT_SONG).setComponent(service); | ||
pendingIntent = PendingIntent.getService(context, 0, intent, 0); | ||
views.setOnClickPendingIntent(R.id.next, pendingIntent); | ||
|
||
manager.updateAppWidget(ids, views); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters