mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 01:53:31 +00:00
fix(widget): refine layouts and progress UX across sizes
Compact (4×1)
- Reduce root vertical padding so the 4×1 cell yields ~56dp of content height.
- Make album art a true square (50×50dp) and center vertically; keeps edges
clear of rounded corners.
- Tighten timing block: 2dp progress bar; 10sp labels with no extra font
padding; prevents elapsed/total text from slipping below the background.
- Wrap album art in a 50×50dp FrameLayout with a new 6dp-radius background
drawable; soft corners while remaining visually smaller than the widget body.
- Mirror the same structure in the preview layout so Studio preview matches
on-device rendering.
(app/src/main/res/layout/widget_layout_compact.xml,
app/src/main/res/drawable/widget_album_art_bg.xml)
Large Short (4×2)
- Wrap album art in a fixed 90dp square container and enforce a true square
crop via centerCrop.
- Tighten vertical spacing: thinner progress bar, closer timing row, controls
shifted down for better balance.
- Keep album/timing text to the left of the controls but retune spacing so the
stack stays fully inside the widget bounds.
Large (4×3 and up)
- Restructure to a vertical stack: header row (album art + text), full-width
progress bar, timing row, primary controls, then secondary controls.
- Lock album art to a 150dp square; progress bar spans the widget beneath the
header to match the new visual hierarchy.
Based-on: cd28ee0764
Co-authored-by: The Firehawk <firehawk@opayq.net>
Co-Authored-By: Mücahit Kaya <kaya-mucahit@outlook.com>
Co-Authored-By: Firehawk <firehawk@opayq.net>
This commit is contained in:
parent
b79cfa4af0
commit
35af1f9038
17 changed files with 964 additions and 149 deletions
|
|
@ -24,20 +24,24 @@ public final class WidgetUpdateManager {
|
|||
public static void updateFromState(Context ctx,
|
||||
String title,
|
||||
String artist,
|
||||
String album,
|
||||
Bitmap art,
|
||||
boolean playing,
|
||||
boolean shuffleEnabled,
|
||||
int repeatMode,
|
||||
long positionMs,
|
||||
long durationMs) {
|
||||
if (TextUtils.isEmpty(title)) title = ctx.getString(R.string.widget_not_playing);
|
||||
if (TextUtils.isEmpty(artist)) artist = ctx.getString(R.string.widget_placeholder_subtitle);
|
||||
if (TextUtils.isEmpty(album)) album = "";
|
||||
|
||||
final TimingInfo timing = createTimingInfo(positionMs, durationMs);
|
||||
|
||||
AppWidgetManager mgr = AppWidgetManager.getInstance(ctx);
|
||||
int[] ids = mgr.getAppWidgetIds(new ComponentName(ctx, WidgetProvider4x1.class));
|
||||
for (int id : ids) {
|
||||
android.widget.RemoteViews rv = choosePopulate(ctx, title, artist, art, playing,
|
||||
timing.elapsedText, timing.totalText, timing.progress, id);
|
||||
android.widget.RemoteViews rv = choosePopulate(ctx, title, artist, album, art, playing,
|
||||
timing.elapsedText, timing.totalText, timing.progress, shuffleEnabled, repeatMode, id);
|
||||
WidgetProvider.attachIntents(ctx, rv, id);
|
||||
mgr.updateAppWidget(id, rv);
|
||||
}
|
||||
|
|
@ -56,14 +60,20 @@ public final class WidgetUpdateManager {
|
|||
public static void updateFromState(Context ctx,
|
||||
String title,
|
||||
String artist,
|
||||
String album,
|
||||
String coverArtId,
|
||||
boolean playing,
|
||||
boolean shuffleEnabled,
|
||||
int repeatMode,
|
||||
long positionMs,
|
||||
long durationMs) {
|
||||
final Context appCtx = ctx.getApplicationContext();
|
||||
final String t = TextUtils.isEmpty(title) ? appCtx.getString(R.string.widget_not_playing) : title;
|
||||
final String a = TextUtils.isEmpty(artist) ? appCtx.getString(R.string.widget_placeholder_subtitle) : artist;
|
||||
final String alb = !TextUtils.isEmpty(album) ? album : "";
|
||||
final boolean p = playing;
|
||||
final boolean sh = shuffleEnabled;
|
||||
final int rep = repeatMode;
|
||||
final TimingInfo timing = createTimingInfo(positionMs, durationMs);
|
||||
|
||||
if (!TextUtils.isEmpty(coverArtId)) {
|
||||
|
|
@ -76,8 +86,8 @@ public final class WidgetUpdateManager {
|
|||
AppWidgetManager mgr = AppWidgetManager.getInstance(appCtx);
|
||||
int[] ids = mgr.getAppWidgetIds(new ComponentName(appCtx, WidgetProvider4x1.class));
|
||||
for (int id : ids) {
|
||||
android.widget.RemoteViews rv = choosePopulate(appCtx, t, a, resource, p,
|
||||
timing.elapsedText, timing.totalText, timing.progress, id);
|
||||
android.widget.RemoteViews rv = choosePopulate(appCtx, t, a, alb, resource, p,
|
||||
timing.elapsedText, timing.totalText, timing.progress, sh, rep, id);
|
||||
WidgetProvider.attachIntents(appCtx, rv, id);
|
||||
mgr.updateAppWidget(id, rv);
|
||||
}
|
||||
|
|
@ -87,8 +97,8 @@ public final class WidgetUpdateManager {
|
|||
AppWidgetManager mgr = AppWidgetManager.getInstance(appCtx);
|
||||
int[] ids = mgr.getAppWidgetIds(new ComponentName(appCtx, WidgetProvider4x1.class));
|
||||
for (int id : ids) {
|
||||
android.widget.RemoteViews rv = choosePopulate(appCtx, t, a, null, p,
|
||||
timing.elapsedText, timing.totalText, timing.progress, id);
|
||||
android.widget.RemoteViews rv = choosePopulate(appCtx, t, a, alb, null, p,
|
||||
timing.elapsedText, timing.totalText, timing.progress, sh, rep, id);
|
||||
WidgetProvider.attachIntents(appCtx, rv, id);
|
||||
mgr.updateAppWidget(id, rv);
|
||||
}
|
||||
|
|
@ -99,8 +109,8 @@ public final class WidgetUpdateManager {
|
|||
AppWidgetManager mgr = AppWidgetManager.getInstance(appCtx);
|
||||
int[] ids = mgr.getAppWidgetIds(new ComponentName(appCtx, WidgetProvider4x1.class));
|
||||
for (int id : ids) {
|
||||
android.widget.RemoteViews rv = choosePopulate(appCtx, t, a, null, p,
|
||||
timing.elapsedText, timing.totalText, timing.progress, id);
|
||||
android.widget.RemoteViews rv = choosePopulate(appCtx, t, a, alb, null, p,
|
||||
timing.elapsedText, timing.totalText, timing.progress, sh, rep, id);
|
||||
WidgetProvider.attachIntents(appCtx, rv, id);
|
||||
mgr.updateAppWidget(id, rv);
|
||||
}
|
||||
|
|
@ -116,13 +126,15 @@ public final class WidgetUpdateManager {
|
|||
if (!future.isDone()) return;
|
||||
MediaController c = future.get();
|
||||
androidx.media3.common.MediaItem mi = c.getCurrentMediaItem();
|
||||
String title = null, artist = null, coverId = null;
|
||||
String title = null, artist = null, album = null, coverId = null;
|
||||
if (mi != null && mi.mediaMetadata != null) {
|
||||
if (mi.mediaMetadata.title != null) title = mi.mediaMetadata.title.toString();
|
||||
if (mi.mediaMetadata.artist != null) artist = mi.mediaMetadata.artist.toString();
|
||||
if (mi.mediaMetadata.albumTitle != null) album = mi.mediaMetadata.albumTitle.toString();
|
||||
if (mi.mediaMetadata.extras != null) {
|
||||
if (title == null) title = mi.mediaMetadata.extras.getString("title");
|
||||
if (artist == null) artist = mi.mediaMetadata.extras.getString("artist");
|
||||
if (album == null) album = mi.mediaMetadata.extras.getString("album");
|
||||
coverId = mi.mediaMetadata.extras.getString("coverArtId");
|
||||
}
|
||||
}
|
||||
|
|
@ -133,8 +145,11 @@ public final class WidgetUpdateManager {
|
|||
updateFromState(appCtx,
|
||||
title != null ? title : appCtx.getString(R.string.widget_not_playing),
|
||||
artist != null ? artist : appCtx.getString(R.string.widget_placeholder_subtitle),
|
||||
album,
|
||||
coverId,
|
||||
c.isPlaying(),
|
||||
c.getShuffleModeEnabled(),
|
||||
c.getRepeatMode(),
|
||||
position,
|
||||
duration);
|
||||
c.release();
|
||||
|
|
@ -174,31 +189,68 @@ public final class WidgetUpdateManager {
|
|||
}
|
||||
|
||||
public static android.widget.RemoteViews chooseBuild(Context ctx, int appWidgetId) {
|
||||
if (isLarge(ctx, appWidgetId)) return WidgetViewsFactory.buildLarge(ctx);
|
||||
return WidgetViewsFactory.buildCompact(ctx);
|
||||
LayoutSize size = resolveLayoutSize(ctx, appWidgetId);
|
||||
switch (size) {
|
||||
case MEDIUM:
|
||||
return WidgetViewsFactory.buildMedium(ctx);
|
||||
case LARGE:
|
||||
return WidgetViewsFactory.buildLarge(ctx);
|
||||
case EXPANDED:
|
||||
return WidgetViewsFactory.buildExpanded(ctx);
|
||||
case COMPACT:
|
||||
default:
|
||||
return WidgetViewsFactory.buildCompact(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
private static android.widget.RemoteViews choosePopulate(Context ctx,
|
||||
String title,
|
||||
String artist,
|
||||
String album,
|
||||
Bitmap art,
|
||||
boolean playing,
|
||||
String elapsedText,
|
||||
String totalText,
|
||||
int progress,
|
||||
boolean shuffleEnabled,
|
||||
int repeatMode,
|
||||
int appWidgetId) {
|
||||
if (isLarge(ctx, appWidgetId)) {
|
||||
return WidgetViewsFactory.populateLarge(ctx, title, artist, art, playing, elapsedText, totalText, progress);
|
||||
LayoutSize size = resolveLayoutSize(ctx, appWidgetId);
|
||||
switch (size) {
|
||||
case MEDIUM:
|
||||
return WidgetViewsFactory.populateMedium(ctx, title, artist, album, art, playing,
|
||||
elapsedText, totalText, progress, shuffleEnabled, repeatMode);
|
||||
case LARGE:
|
||||
return WidgetViewsFactory.populateLarge(ctx, title, artist, album, art, playing,
|
||||
elapsedText, totalText, progress, shuffleEnabled, repeatMode);
|
||||
case EXPANDED:
|
||||
return WidgetViewsFactory.populateExpanded(ctx, title, artist, album, art, playing,
|
||||
elapsedText, totalText, progress, shuffleEnabled, repeatMode);
|
||||
case COMPACT:
|
||||
default:
|
||||
return WidgetViewsFactory.populateCompact(ctx, title, artist, album, art, playing,
|
||||
elapsedText, totalText, progress, shuffleEnabled, repeatMode);
|
||||
}
|
||||
return WidgetViewsFactory.populate(ctx, title, artist, art, playing, elapsedText, totalText, progress);
|
||||
}
|
||||
|
||||
private static boolean isLarge(Context ctx, int appWidgetId) {
|
||||
private static LayoutSize resolveLayoutSize(Context ctx, int appWidgetId) {
|
||||
AppWidgetManager mgr = AppWidgetManager.getInstance(ctx);
|
||||
android.os.Bundle opts = mgr.getAppWidgetOptions(appWidgetId);
|
||||
int minH = opts != null ? opts.getInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT) : 0;
|
||||
int threshold = ctx.getResources().getInteger(com.cappielloantonio.tempo.R.integer.widget_large_min_height_dp);
|
||||
return minH >= threshold; // dp threshold for 2-row height
|
||||
int expandedThreshold = ctx.getResources().getInteger(R.integer.widget_expanded_min_height_dp);
|
||||
int largeThreshold = ctx.getResources().getInteger(R.integer.widget_large_min_height_dp);
|
||||
int mediumThreshold = ctx.getResources().getInteger(R.integer.widget_medium_min_height_dp);
|
||||
if (minH >= expandedThreshold) return LayoutSize.EXPANDED;
|
||||
if (minH >= largeThreshold) return LayoutSize.LARGE;
|
||||
if (minH >= mediumThreshold) return LayoutSize.MEDIUM;
|
||||
return LayoutSize.COMPACT;
|
||||
}
|
||||
|
||||
private enum LayoutSize {
|
||||
COMPACT,
|
||||
MEDIUM,
|
||||
LARGE,
|
||||
EXPANDED
|
||||
}
|
||||
|
||||
private static final class TimingInfo {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue