New Drawables and widget alpha

This commit is contained in:
Karim Abou Zeid 2015-03-10 17:22:35 +01:00
commit f3c629e1c6
27 changed files with 222 additions and 11 deletions

View file

@ -9,13 +9,13 @@
<uses-permission android:name="android.permission.INTERNET" />
<application
android:name="com.kabouzeid.gramophone.App"
android:name=".App"
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/Theme.MaterialMusic" >
<activity
android:name="com.kabouzeid.gramophone.ui.activities.MainActivity"
android:name=".ui.activities.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@ -23,21 +23,21 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.kabouzeid.gramophone.ui.activities.AlbumDetailActivity" >
<activity android:name=".ui.activities.AlbumDetailActivity" >
</activity>
<activity android:name="com.kabouzeid.gramophone.ui.activities.ArtistDetailActivity" >
<activity android:name=".ui.activities.ArtistDetailActivity" >
</activity>
<activity
android:name="com.kabouzeid.gramophone.ui.activities.MusicControllerActivity"
android:parentActivityName="com.kabouzeid.gramophone.ui.activities.MainActivity" >
android:name=".ui.activities.MusicControllerActivity"
android:parentActivityName=".ui.activities.MainActivity" >
</activity>
<service
android:name="com.kabouzeid.gramophone.service.MusicService"
android:name=".service.MusicService"
android:enabled="true" >
</service>
<receiver android:name="com.kabouzeid.gramophone.service.MediaButtonIntentReceiver" >
<receiver android:name=".service.MediaButtonIntentReceiver" >
<intent-filter>
<action android:name="android.intent.action.MEDIA_BUTTON" />
</intent-filter>
@ -48,18 +48,28 @@
android:value="b23725bd3d266aa65c5a3dd1816b2f801524a189" />
<activity
android:name="com.kabouzeid.gramophone.ui.activities.tageditor.SongTagEditorActivity"
android:name=".ui.activities.tageditor.SongTagEditorActivity"
android:label="@string/title_activity_tag_editor"
android:windowSoftInputMode="adjustResize" >
</activity>
<activity
android:name="com.kabouzeid.gramophone.ui.activities.tageditor.AlbumTagEditorActivity"
android:name=".ui.activities.tageditor.AlbumTagEditorActivity"
android:label="@string/title_activity_album_tag_editor" >
</activity>
<activity
android:name="com.kabouzeid.gramophone.ui.activities.SearchActivity"
android:name=".ui.activities.SearchActivity"
android:label="@string/title_activity_search" >
</activity>
<receiver android:name=".widget.MusicPlayerWidget" >
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data
android:name="android.appwidget.provider"
android:resource="@xml/music_player_widget_info" />
</receiver>
</application>
</manifest>

View file

@ -0,0 +1,104 @@
package com.kabouzeid.gramophone.widget;
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.graphics.Bitmap;
import android.net.Uri;
import android.widget.RemoteViews;
import com.kabouzeid.gramophone.App;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.model.Song;
import com.kabouzeid.gramophone.service.MusicService;
import com.kabouzeid.gramophone.ui.activities.MusicControllerActivity;
import com.kabouzeid.gramophone.util.MusicUtil;
import com.nostra13.universalimageloader.core.ImageLoader;
/**
* Implementation of App Widget functionality.
*/
public class MusicPlayerWidget extends AppWidgetProvider {
private static MusicPlayerWidget instance;
public static synchronized MusicPlayerWidget getInstance() {
if (instance == null) {
instance = new MusicPlayerWidget();
}
return instance;
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.music_player_widget);
appWidgetManager.updateAppWidget(appWidgetIds, views);
}
@Override
public void onEnabled(Context context) {
// Enter relevant functionality for when the first widget is created
}
@Override
public void onDisabled(Context context) {
// Enter relevant functionality for when the last widget is disabled
}
private void linkButtons(final Context context, final RemoteViews views) {
views.setOnClickPendingIntent(R.id.album_art, retrievePlaybackActions(context, 0));
views.setOnClickPendingIntent(R.id.button_toggle_play_pause, retrievePlaybackActions(context, 1));
views.setOnClickPendingIntent(R.id.button_next, retrievePlaybackActions(context, 2));
views.setOnClickPendingIntent(R.id.button_prev, retrievePlaybackActions(context, 3));
}
private PendingIntent retrievePlaybackActions(final Context context, final int which) {
Intent action;
PendingIntent pendingIntent;
final ComponentName serviceName = new ComponentName(context, MusicService.class);
switch (which) {
case 0:
action = new Intent(context, MusicControllerActivity.class);
pendingIntent = PendingIntent.getActivity(context, 0, action, 0);
return pendingIntent;
case 1:
action = new Intent(MusicService.ACTION_TOGGLE_PLAYBACK);
action.setComponent(serviceName);
pendingIntent = PendingIntent.getService(context, 1, action, 0);
return pendingIntent;
case 2:
action = new Intent(MusicService.ACTION_SKIP);
action.setComponent(serviceName);
pendingIntent = PendingIntent.getService(context, 2, action, 0);
return pendingIntent;
case 3:
action = new Intent(MusicService.ACTION_REWIND);
action.setComponent(serviceName);
pendingIntent = PendingIntent.getService(context, 3, action, 0);
return pendingIntent;
}
return null;
}
public void performUpdate(final MusicService service, final Song song){
final RemoteViews views = new RemoteViews(service.getPackageName(), R.layout.music_player_widget);
linkButtons(service, views);
loadAlbumArt(views, MusicUtil.getAlbumArtUri(song.albumId).toString());
views.setTextViewText(R.id.song_title, song.title);
}
private static void loadAlbumArt(RemoteViews widgetView, String albumArtUri) {
Bitmap albumArtBitmap = ImageLoader.getInstance().loadImageSync(albumArtUri);
if (albumArtBitmap == null) {
widgetView.setImageViewResource(R.id.album_art, R.drawable.default_album_art);
} else {
widgetView.setImageViewBitmap(R.id.album_art, albumArtBitmap);
}
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 336 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 363 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 195 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 278 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 265 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 277 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 207 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 373 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 375 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 404 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 257 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 497 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 477 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 509 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 298 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 594 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 592 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 591 B

View file

@ -0,0 +1,69 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="@dimen/app_widget_small_artwork_height"
android:background="#FFFFFF">
<ImageView
android:src="@drawable/default_album_art"
android:id="@+id/album_art"
android:layout_width="@dimen/app_widget_small_artwork_height"
android:layout_height="@dimen/app_widget_small_artwork_height"
android:scaleType="centerCrop"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:gravity="center"
android:id="@+id/song_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:singleLine="true"
android:textAppearance="@style/Theme.MaterialMusic.Notification.Title"
android:layout_margin="4dp"
android:text="@string/nothing_playing"/>
<LinearLayout
android:id="@+id/media_actions"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:orientation="horizontal"
>
<ImageButton
android:layout_weight="1"
android:background="@drawable/notification_selector"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/button_prev"
android:src="@drawable/ic_skip_previous_black_36dp"
/>
<ImageButton
android:layout_weight="1"
android:background="@drawable/notification_selector"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/button_toggle_play_pause"
android:src="@drawable/ic_play_arrow_black_36dp"
/>
<ImageButton
android:layout_weight="1"
android:background="@drawable/notification_selector"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/button_next"
android:src="@drawable/ic_skip_next_black_36dp"
/>
</LinearLayout>
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!--
Refer to App Widget Documentation for margin information
http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout
-->
<dimen name="widget_margin">0dp</dimen>
</resources>

View file

@ -36,4 +36,11 @@
<dimen name="tab_height">48dp</dimen>
<dimen name="tagEditorHeaderVariableSpace">100dp</dimen>
<!--
Refer to App Widget Documentation for margin information
http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout
-->
<dimen name="widget_margin">8dp</dimen>
<dimen name="app_widget_small_artwork_height">64dp</dimen>
</resources>

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
android:minWidth="180dp"
android:minHeight="40dp"
android:updatePeriodMillis="86400000"
android:previewImage="@drawable/example_appwidget_preview"
android:initialLayout="@layout/music_player_widget"
android:resizeMode="horizontal|vertical"
android:widgetCategory="home_screen|keyguard"
android:initialKeyguardLayout="@layout/music_player_widget">
</appwidget-provider>