Buttons are 42dp wide, full-height album art with rounded corners
This commit is contained in:
parent
e111d4f113
commit
26bba697cb
5 changed files with 62 additions and 13 deletions
|
|
@ -6,6 +6,7 @@ import android.content.ComponentName;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.graphics.Palette;
|
||||
|
|
@ -177,11 +178,18 @@ public class AppWidgetCard extends BaseAppWidget {
|
|||
appWidgetView.setImageViewBitmap(R.id.button_next, createBitmap(Util.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, color), 1f));
|
||||
appWidgetView.setImageViewBitmap(R.id.button_prev, createBitmap(Util.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, color), 1f));
|
||||
|
||||
Drawable image;
|
||||
|
||||
if (bitmap == null) {
|
||||
appWidgetView.setImageViewResource(R.id.image, R.drawable.default_album_art);
|
||||
image = appContext.getResources().getDrawable(R.drawable.default_album_art);
|
||||
} else {
|
||||
appWidgetView.setImageViewBitmap(R.id.image, bitmap);
|
||||
image = new BitmapDrawable(bitmap);
|
||||
}
|
||||
|
||||
float radius = appContext.getResources().getDimension(R.dimen.app_widget_card_radius);
|
||||
int size = appContext.getResources().getDimensionPixelSize(R.dimen.app_widget_card_image_size);
|
||||
appWidgetView.setImageViewBitmap(R.id.image, createRoundedBitmap(image, size, size, radius, 0, radius, 0));
|
||||
|
||||
pushUpdate(appContext, appWidgetIds, appWidgetView);
|
||||
}
|
||||
});
|
||||
|
|
|
|||
|
|
@ -6,7 +6,11 @@ import android.content.ComponentName;
|
|||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapShader;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
/**
|
||||
|
|
@ -22,6 +26,46 @@ public class BaseAppWidget extends AppWidgetProvider {
|
|||
return bitmap;
|
||||
}
|
||||
|
||||
protected static Bitmap createRoundedBitmap(Drawable drawable, int width, int height, float tl, float tr, float bl, float br) {
|
||||
if (drawable == null) return null;
|
||||
|
||||
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
Canvas c = new Canvas(bitmap);
|
||||
drawable.setBounds(0, 0, width, height);
|
||||
drawable.draw(c);
|
||||
|
||||
Bitmap rounded = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
||||
|
||||
Canvas canvas = new Canvas(rounded);
|
||||
Paint paint = new Paint();
|
||||
paint.setShader(new BitmapShader(bitmap, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));
|
||||
paint.setAntiAlias(true);
|
||||
canvas.drawPath(composeRoundedRectPath(new RectF(0, 0, width, height), tl, tr, bl, br), paint);
|
||||
|
||||
return rounded;
|
||||
}
|
||||
|
||||
protected static Path composeRoundedRectPath(RectF rect, float tl, float tr, float bl, float br) {
|
||||
Path path = new Path();
|
||||
tl = tl < 0 ? 0 : tl;
|
||||
tr = tr < 0 ? 0 : tr;
|
||||
bl = bl < 0 ? 0 : bl;
|
||||
br = br < 0 ? 0 : br;
|
||||
|
||||
path.moveTo(rect.left + tl, rect.top);
|
||||
path.lineTo(rect.right - tr, rect.top);
|
||||
path.quadTo(rect.right, rect.top, rect.right, rect.top + tr);
|
||||
path.lineTo(rect.right, rect.bottom - br);
|
||||
path.quadTo(rect.right, rect.bottom, rect.right - br, rect.bottom);
|
||||
path.lineTo(rect.left + bl, rect.bottom);
|
||||
path.quadTo(rect.left, rect.bottom, rect.left, rect.bottom - bl);
|
||||
path.lineTo(rect.left, rect.top + tl);
|
||||
path.quadTo(rect.left, rect.top, rect.left + tl, rect.top);
|
||||
path.close();
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
protected PendingIntent buildPendingIntent(Context context, final String action, final ComponentName serviceName) {
|
||||
Intent intent = new Intent(action);
|
||||
intent.setComponent(serviceName);
|
||||
|
|
|
|||
|
|
@ -19,8 +19,8 @@
|
|||
android:right="0dp"
|
||||
android:bottom="1dp"
|
||||
android:left="0dp"/>
|
||||
<solid android:color="#d4d4d4"/>
|
||||
<corners android:radius="2dp"/>
|
||||
<solid android:color="#55d4d4d4"/>
|
||||
<corners android:radius="@dimen/app_widget_card_radius"/>
|
||||
</shape>
|
||||
</item>
|
||||
<item>
|
||||
|
|
@ -30,15 +30,15 @@
|
|||
android:right="0dp"
|
||||
android:bottom="1dp"
|
||||
android:left="0dp"/>
|
||||
<solid android:color="#dddddd"/>
|
||||
<corners android:radius="2dp"/>
|
||||
<solid android:color="#55dddddd"/>
|
||||
<corners android:radius="@dimen/app_widget_card_radius"/>
|
||||
</shape>
|
||||
</item>
|
||||
<!-- Background -->
|
||||
|
||||
<item>
|
||||
<shape>
|
||||
<solid android:color="@android:color/white"/>
|
||||
<corners android:radius="2dp"/>
|
||||
<corners android:radius="@dimen/app_widget_card_radius"/>
|
||||
</shape>
|
||||
</item>
|
||||
|
||||
|
|
|
|||
|
|
@ -15,10 +15,6 @@
|
|||
android:id="@+id/image"
|
||||
android:layout_width="@dimen/app_widget_card_image_size"
|
||||
android:layout_height="@dimen/app_widget_card_image_size"
|
||||
android:layout_marginTop="2dp"
|
||||
android:layout_marginLeft="2dp"
|
||||
android:layout_marginRight="2dp"
|
||||
android:layout_marginBottom="1dp"
|
||||
android:scaleType="centerInside"
|
||||
tools:src="@drawable/default_album_art"
|
||||
tools:ignore="ContentDescription"/>
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ http://developer.android.com/guide/topics/appwidgets/index.html#CreatingLayout
|
|||
<dimen name="app_widget_card_image_size">48dp</dimen>
|
||||
<dimen name="app_widget_card_min_width">250dp</dimen>
|
||||
<dimen name="app_widget_card_min_height">56dp</dimen>
|
||||
<dimen name="app_widget_card_buttons_width">96dp</dimen>
|
||||
<dimen name="app_widget_card_buttons_width">128dp</dimen>
|
||||
<dimen name="app_widget_card_radius">2dp</dimen>
|
||||
|
||||
</resources>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue