mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Improve DefaultTimeBar color customization
Add attributes for the scrubber handle color and unplayed color. If attributes are missing, derive defaults from the played color. Issue: #2740 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=154825736
This commit is contained in:
parent
d33a6b49f0
commit
c3158d3e68
@ -61,22 +61,21 @@ public class DefaultTimeBar extends View implements TimeBar {
|
|||||||
private static final int DEFAULT_INCREMENT_COUNT = 20;
|
private static final int DEFAULT_INCREMENT_COUNT = 20;
|
||||||
private static final int DEFAULT_BAR_HEIGHT = 4;
|
private static final int DEFAULT_BAR_HEIGHT = 4;
|
||||||
private static final int DEFAULT_TOUCH_TARGET_HEIGHT = 26;
|
private static final int DEFAULT_TOUCH_TARGET_HEIGHT = 26;
|
||||||
private static final int DEFAULT_PLAYED_COLOR = 0x33FFFFFF;
|
private static final int DEFAULT_PLAYED_COLOR = 0xFFFFFFFF;
|
||||||
private static final int DEFAULT_BUFFERED_COLOR = 0xCCFFFFFF;
|
|
||||||
private static final int DEFAULT_AD_MARKER_COLOR = 0xB2FFFF00;
|
private static final int DEFAULT_AD_MARKER_COLOR = 0xB2FFFF00;
|
||||||
private static final int DEFAULT_AD_MARKER_WIDTH = 4;
|
private static final int DEFAULT_AD_MARKER_WIDTH = 4;
|
||||||
private static final int DEFAULT_SCRUBBER_ENABLED_SIZE = 12;
|
private static final int DEFAULT_SCRUBBER_ENABLED_SIZE = 12;
|
||||||
private static final int DEFAULT_SCRUBBER_DISABLED_SIZE = 0;
|
private static final int DEFAULT_SCRUBBER_DISABLED_SIZE = 0;
|
||||||
private static final int DEFAULT_SCRUBBER_DRAGGED_SIZE = 16;
|
private static final int DEFAULT_SCRUBBER_DRAGGED_SIZE = 16;
|
||||||
private static final int OPAQUE_COLOR = 0xFF000000;
|
|
||||||
|
|
||||||
private final Rect seekBounds;
|
private final Rect seekBounds;
|
||||||
private final Rect progressBar;
|
private final Rect progressBar;
|
||||||
private final Rect bufferedBar;
|
private final Rect bufferedBar;
|
||||||
private final Rect scrubberBar;
|
private final Rect scrubberBar;
|
||||||
private final Paint progressPaint;
|
private final Paint playedPaint;
|
||||||
private final Paint bufferedPaint;
|
|
||||||
private final Paint scrubberPaint;
|
private final Paint scrubberPaint;
|
||||||
|
private final Paint bufferedPaint;
|
||||||
|
private final Paint unplayedPaint;
|
||||||
private final Paint adMarkerPaint;
|
private final Paint adMarkerPaint;
|
||||||
private final int barHeight;
|
private final int barHeight;
|
||||||
private final int touchTargetHeight;
|
private final int touchTargetHeight;
|
||||||
@ -115,9 +114,10 @@ public class DefaultTimeBar extends View implements TimeBar {
|
|||||||
progressBar = new Rect();
|
progressBar = new Rect();
|
||||||
bufferedBar = new Rect();
|
bufferedBar = new Rect();
|
||||||
scrubberBar = new Rect();
|
scrubberBar = new Rect();
|
||||||
progressPaint = new Paint();
|
playedPaint = new Paint();
|
||||||
bufferedPaint = new Paint();
|
|
||||||
scrubberPaint = new Paint();
|
scrubberPaint = new Paint();
|
||||||
|
bufferedPaint = new Paint();
|
||||||
|
unplayedPaint = new Paint();
|
||||||
adMarkerPaint = new Paint();
|
adMarkerPaint = new Paint();
|
||||||
|
|
||||||
// Calculate the dimensions and paints for drawn elements.
|
// Calculate the dimensions and paints for drawn elements.
|
||||||
@ -147,13 +147,18 @@ public class DefaultTimeBar extends View implements TimeBar {
|
|||||||
scrubberDraggedSize = a.getDimensionPixelSize(
|
scrubberDraggedSize = a.getDimensionPixelSize(
|
||||||
R.styleable.DefaultTimeBar_scrubber_dragged_size, defaultScrubberDraggedSize);
|
R.styleable.DefaultTimeBar_scrubber_dragged_size, defaultScrubberDraggedSize);
|
||||||
int playedColor = a.getInt(R.styleable.DefaultTimeBar_played_color, DEFAULT_PLAYED_COLOR);
|
int playedColor = a.getInt(R.styleable.DefaultTimeBar_played_color, DEFAULT_PLAYED_COLOR);
|
||||||
|
int scrubberColor = a.getInt(R.styleable.DefaultTimeBar_scrubber_color,
|
||||||
|
getDefaultScrubberColor(playedColor));
|
||||||
int bufferedColor = a.getInt(R.styleable.DefaultTimeBar_buffered_color,
|
int bufferedColor = a.getInt(R.styleable.DefaultTimeBar_buffered_color,
|
||||||
DEFAULT_BUFFERED_COLOR);
|
getDefaultBufferedColor(playedColor));
|
||||||
|
int unplayedColor = a.getInt(R.styleable.DefaultTimeBar_unplayed_color,
|
||||||
|
getDefaultUnplayedColor(playedColor));
|
||||||
int adMarkerColor = a.getInt(R.styleable.DefaultTimeBar_ad_marker_color,
|
int adMarkerColor = a.getInt(R.styleable.DefaultTimeBar_ad_marker_color,
|
||||||
DEFAULT_AD_MARKER_COLOR);
|
DEFAULT_AD_MARKER_COLOR);
|
||||||
progressPaint.setColor(playedColor);
|
playedPaint.setColor(playedColor);
|
||||||
scrubberPaint.setColor(OPAQUE_COLOR | playedColor);
|
scrubberPaint.setColor(scrubberColor);
|
||||||
bufferedPaint.setColor(bufferedColor);
|
bufferedPaint.setColor(bufferedColor);
|
||||||
|
unplayedPaint.setColor(unplayedColor);
|
||||||
adMarkerPaint.setColor(adMarkerColor);
|
adMarkerPaint.setColor(adMarkerColor);
|
||||||
} finally {
|
} finally {
|
||||||
a.recycle();
|
a.recycle();
|
||||||
@ -165,9 +170,10 @@ public class DefaultTimeBar extends View implements TimeBar {
|
|||||||
scrubberEnabledSize = defaultScrubberEnabledSize;
|
scrubberEnabledSize = defaultScrubberEnabledSize;
|
||||||
scrubberDisabledSize = defaultScrubberDisabledSize;
|
scrubberDisabledSize = defaultScrubberDisabledSize;
|
||||||
scrubberDraggedSize = defaultScrubberDraggedSize;
|
scrubberDraggedSize = defaultScrubberDraggedSize;
|
||||||
scrubberPaint.setColor(OPAQUE_COLOR | DEFAULT_PLAYED_COLOR);
|
playedPaint.setColor(DEFAULT_PLAYED_COLOR);
|
||||||
progressPaint.setColor(DEFAULT_PLAYED_COLOR);
|
scrubberPaint.setColor(getDefaultScrubberColor(DEFAULT_PLAYED_COLOR));
|
||||||
bufferedPaint.setColor(DEFAULT_BUFFERED_COLOR);
|
bufferedPaint.setColor(getDefaultBufferedColor(DEFAULT_PLAYED_COLOR));
|
||||||
|
unplayedPaint.setColor(getDefaultUnplayedColor(DEFAULT_PLAYED_COLOR));
|
||||||
adMarkerPaint.setColor(DEFAULT_AD_MARKER_COLOR);
|
adMarkerPaint.setColor(DEFAULT_AD_MARKER_COLOR);
|
||||||
}
|
}
|
||||||
formatBuilder = new StringBuilder();
|
formatBuilder = new StringBuilder();
|
||||||
@ -502,21 +508,21 @@ public class DefaultTimeBar extends View implements TimeBar {
|
|||||||
int barTop = progressBar.centerY() - progressBarHeight / 2;
|
int barTop = progressBar.centerY() - progressBarHeight / 2;
|
||||||
int barBottom = barTop + progressBarHeight;
|
int barBottom = barTop + progressBarHeight;
|
||||||
if (duration <= 0) {
|
if (duration <= 0) {
|
||||||
canvas.drawRect(progressBar.left, barTop, progressBar.right, barBottom, progressPaint);
|
canvas.drawRect(progressBar.left, barTop, progressBar.right, barBottom, unplayedPaint);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
int bufferedLeft = bufferedBar.left;
|
int bufferedLeft = bufferedBar.left;
|
||||||
int bufferedRight = bufferedBar.right;
|
int bufferedRight = bufferedBar.right;
|
||||||
int progressLeft = Math.max(Math.max(progressBar.left, bufferedRight), scrubberBar.right);
|
int progressLeft = Math.max(Math.max(progressBar.left, bufferedRight), scrubberBar.right);
|
||||||
if (progressLeft < progressBar.right) {
|
if (progressLeft < progressBar.right) {
|
||||||
canvas.drawRect(progressLeft, barTop, progressBar.right, barBottom, progressPaint);
|
canvas.drawRect(progressLeft, barTop, progressBar.right, barBottom, unplayedPaint);
|
||||||
}
|
}
|
||||||
bufferedLeft = Math.max(bufferedLeft, scrubberBar.right);
|
bufferedLeft = Math.max(bufferedLeft, scrubberBar.right);
|
||||||
if (bufferedRight > bufferedLeft) {
|
if (bufferedRight > bufferedLeft) {
|
||||||
canvas.drawRect(bufferedLeft, barTop, bufferedRight, barBottom, bufferedPaint);
|
canvas.drawRect(bufferedLeft, barTop, bufferedRight, barBottom, bufferedPaint);
|
||||||
}
|
}
|
||||||
if (scrubberBar.width() > 0) {
|
if (scrubberBar.width() > 0) {
|
||||||
canvas.drawRect(scrubberBar.left, barTop, scrubberBar.right, barBottom, scrubberPaint);
|
canvas.drawRect(scrubberBar.left, barTop, scrubberBar.right, barBottom, playedPaint);
|
||||||
}
|
}
|
||||||
int adMarkerOffset = adMarkerWidth / 2;
|
int adMarkerOffset = adMarkerWidth / 2;
|
||||||
for (int i = 0; i < adBreakCount; i++) {
|
for (int i = 0; i < adBreakCount; i++) {
|
||||||
@ -577,4 +583,16 @@ public class DefaultTimeBar extends View implements TimeBar {
|
|||||||
return (int) (dps * displayMetrics.density + 0.5f);
|
return (int) (dps * displayMetrics.density + 0.5f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static int getDefaultScrubberColor(int playedColor) {
|
||||||
|
return 0xFF000000 | playedColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getDefaultUnplayedColor(int playedColor) {
|
||||||
|
return 0x33000000 | (playedColor & 0x00FFFFFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getDefaultBufferedColor(int playedColor) {
|
||||||
|
return 0xCC000000 | (playedColor & 0x00FFFFFF);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -68,7 +68,9 @@
|
|||||||
<attr name="scrubber_disabled_size" format="dimension"/>
|
<attr name="scrubber_disabled_size" format="dimension"/>
|
||||||
<attr name="scrubber_dragged_size" format="dimension"/>
|
<attr name="scrubber_dragged_size" format="dimension"/>
|
||||||
<attr name="played_color" format="color"/>
|
<attr name="played_color" format="color"/>
|
||||||
|
<attr name="scrubber_color" format="color"/>
|
||||||
<attr name="buffered_color" format="color"/>
|
<attr name="buffered_color" format="color"/>
|
||||||
|
<attr name="unplayed_color" format="color"/>
|
||||||
<attr name="ad_marker_color" format="color"/>
|
<attr name="ad_marker_color" format="color"/>
|
||||||
</declare-styleable>
|
</declare-styleable>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user