forked from Blendman974/faceclaw
UI changes, system status icons
This commit is contained in:
1 parent
6e442e7faa
commit
b5273715ae
14 files changed
+830
-236
No files matched your search
+103
-10
@@ -35,12 +35,12 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
private static final int DESCRIPTOR_TIMEOUT_MS = 5_000;
|
||||
private static final int WRITE_TIMEOUT_MS = 2_000;
|
||||
private static final int PRELUDE_TIMEOUT_MS = 2_000;
|
||||
private static final int ACK_TIMEOUT_MS = 2_000;
|
||||
private static final int ACK_TIMEOUT_MS = 3_500;
|
||||
private static final int HEARTBEAT_INTERVAL_MS = 5_000;
|
||||
private static final int BATTERY_REFRESH_INTERVAL_MS = 5 * 60_000;
|
||||
private static final int BATTERY_INPUT_QUIET_MS = 5_000;
|
||||
private static final int WINDOW_SIZE = 1;
|
||||
private static final int IMAGE_FRAGMENT_SIZE = 4000;
|
||||
private static final int WINDOW_SIZE = 3;
|
||||
private static final int IMAGE_FRAGMENT_SIZE = 1000;
|
||||
private static final int IMAGE_RETRY_DELAY_MS = 10_000;
|
||||
private static final boolean IMAGE_FRAGMENT_NO_ACK = false;
|
||||
private static final int WARMUP_FRAGMENT_TIMEOUT_MS = 3_000;
|
||||
@@ -103,10 +103,13 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
|
||||
private String displayedFingerprint = "";
|
||||
private byte[][] displayedTileBmps = emptyTileSet();
|
||||
private final Map<Integer, ImageUpdateStats> imageUpdateStats = new HashMap<>();
|
||||
|
||||
private final Object desiredTilesLock = new Object();
|
||||
private String desiredFingerprint = "";
|
||||
private byte[][] desiredTileBmps = emptyTileSet();
|
||||
private boolean desiredForceTiledCommit;
|
||||
private int desiredPaintMs;
|
||||
|
||||
private final ArrayDeque<OutboundMessage> pendingMessages = new ArrayDeque<>();
|
||||
private final ArrayDeque<OutboundMessage> inFlightMessages = new ArrayDeque<>();
|
||||
@@ -178,6 +181,14 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
|
||||
|
||||
public void submitDashboardImage(List<byte[]> tileBmps, String fingerprint) {
|
||||
submitDashboardImage(tileBmps, fingerprint, false, -1);
|
||||
}
|
||||
|
||||
public void submitDashboardImage(List<byte[]> tileBmps, String fingerprint, boolean forceTiledCommit) {
|
||||
submitDashboardImage(tileBmps, fingerprint, forceTiledCommit, -1);
|
||||
}
|
||||
|
||||
public void submitDashboardImage(List<byte[]> tileBmps, String fingerprint, boolean forceTiledCommit, int paintMs) {
|
||||
if (tileBmps == null || tileBmps.size() != DASHBOARD_TILES.length) {
|
||||
throw new IllegalArgumentException("exactly 4 tile bitmaps are required");
|
||||
}
|
||||
@@ -188,6 +199,8 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
desiredTileBmps[i] = bmp == null ? new byte[0] : Arrays.copyOf(bmp, bmp.length);
|
||||
}
|
||||
desiredFingerprint = fingerprint == null ? "" : fingerprint;
|
||||
desiredForceTiledCommit = forceTiledCommit;
|
||||
desiredPaintMs = paintMs;
|
||||
}
|
||||
interruptibleSleep.interrupt();
|
||||
}
|
||||
@@ -198,6 +211,29 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
byte[] tile2Bmp,
|
||||
byte[] tile3Bmp,
|
||||
String fingerprint
|
||||
) {
|
||||
submitDashboardImage4(tile0Bmp, tile1Bmp, tile2Bmp, tile3Bmp, fingerprint, false, -1);
|
||||
}
|
||||
|
||||
public void submitDashboardImage4(
|
||||
byte[] tile0Bmp,
|
||||
byte[] tile1Bmp,
|
||||
byte[] tile2Bmp,
|
||||
byte[] tile3Bmp,
|
||||
String fingerprint,
|
||||
boolean forceTiledCommit
|
||||
) {
|
||||
submitDashboardImage4(tile0Bmp, tile1Bmp, tile2Bmp, tile3Bmp, fingerprint, forceTiledCommit, -1);
|
||||
}
|
||||
|
||||
public void submitDashboardImage4(
|
||||
byte[] tile0Bmp,
|
||||
byte[] tile1Bmp,
|
||||
byte[] tile2Bmp,
|
||||
byte[] tile3Bmp,
|
||||
String fingerprint,
|
||||
boolean forceTiledCommit,
|
||||
int paintMs
|
||||
) {
|
||||
synchronized (desiredTilesLock) {
|
||||
desiredTileBmps = emptyTileSet();
|
||||
@@ -206,6 +242,8 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
desiredTileBmps[2] = tile2Bmp == null ? new byte[0] : Arrays.copyOf(tile2Bmp, tile2Bmp.length);
|
||||
desiredTileBmps[3] = tile3Bmp == null ? new byte[0] : Arrays.copyOf(tile3Bmp, tile3Bmp.length);
|
||||
desiredFingerprint = fingerprint == null ? "" : fingerprint;
|
||||
desiredForceTiledCommit = forceTiledCommit;
|
||||
desiredPaintMs = paintMs;
|
||||
}
|
||||
interruptibleSleep.interrupt();
|
||||
}
|
||||
@@ -542,6 +580,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
}
|
||||
|
||||
private boolean writeMessageLocked(OutboundMessage message) {
|
||||
long writeStartedAtMs = SystemClock.elapsedRealtime();
|
||||
if (!bleManager.writeFrames(
|
||||
rightAddress,
|
||||
BleProtocol.WRITE_CHAR_UUID,
|
||||
@@ -551,6 +590,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
)) {
|
||||
return false;
|
||||
}
|
||||
message.writeStartedAtMs = writeStartedAtMs;
|
||||
message.sentAtMs = SystemClock.elapsedRealtime();
|
||||
message.ackDeadlineAtMs = message.sentAtMs + message.ackTimeoutMs;
|
||||
if (message.magic != 0) {
|
||||
@@ -657,6 +697,10 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
return;
|
||||
}
|
||||
if (message.imageMessageNumber == 1) {
|
||||
ImageUpdateStats stats = imageUpdateStats.get(message.imageUpdateId);
|
||||
if (stats != null && stats.firstWriteStartedAtMs <= 0) {
|
||||
stats.firstWriteStartedAtMs = message.writeStartedAtMs > 0 ? message.writeStartedAtMs : message.sentAtMs;
|
||||
}
|
||||
logImageUpdateLandmarkLocked("first bluetooth message sent", message, message.sentAtMs);
|
||||
}
|
||||
if (message.imageMessageNumber == message.imageMessageCount) {
|
||||
@@ -668,7 +712,12 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
if (message.imageUpdateId <= 0 || message.imageMessageNumber != message.imageMessageCount) {
|
||||
return;
|
||||
}
|
||||
logImageUpdateLandmarkLocked("last bluetooth message acked", message, SystemClock.elapsedRealtime());
|
||||
long ackedAtMs = SystemClock.elapsedRealtime();
|
||||
ImageUpdateStats stats = imageUpdateStats.remove(message.imageUpdateId);
|
||||
if (stats != null && stats.firstWriteStartedAtMs > 0) {
|
||||
emitFrameMetrics(stats.paintMs, (int) Math.max(0, ackedAtMs - stats.firstWriteStartedAtMs), stats.tileCount);
|
||||
}
|
||||
logImageUpdateLandmarkLocked("last bluetooth message acked", message, ackedAtMs);
|
||||
}
|
||||
|
||||
private void logImageUpdateLandmarkLocked(String event, OutboundMessage message, long elapsedMs) {
|
||||
@@ -759,8 +808,13 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
String fingerprint = getDesiredFingerprint();
|
||||
List<TileImagePlan> changedTiles = new ArrayList<>();
|
||||
byte[][] tileBmps;
|
||||
boolean forceTiledCommit;
|
||||
int paintMs;
|
||||
synchronized (desiredTilesLock) {
|
||||
tileBmps = desiredTileBmps;
|
||||
forceTiledCommit = desiredForceTiledCommit;
|
||||
desiredForceTiledCommit = false;
|
||||
paintMs = desiredPaintMs;
|
||||
}
|
||||
for (int i = 0; i < DASHBOARD_TILES.length; i++) {
|
||||
BleProtocol.ImageTileOptions tile = DASHBOARD_TILES[i];
|
||||
@@ -779,22 +833,27 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean synchronizeCommits = changedTiles.size() > 1;
|
||||
boolean synchronizedCommits = changedTiles.size() > 1;
|
||||
if (forceTiledCommit) {
|
||||
synchronizedCommits = false;
|
||||
}
|
||||
boolean reserveLastByte = false;
|
||||
for (TileImagePlan plan : changedTiles) {
|
||||
plan.fragments = BleImageOptimizer.planImageFragments(plan.bmp, IMAGE_FRAGMENT_SIZE, reserveLastByte);
|
||||
}
|
||||
|
||||
int updateId = nextImageUpdateId++;
|
||||
imageUpdateStats.put(updateId, new ImageUpdateStats(paintMs, changedTiles.size()));
|
||||
int messageCount = 0;
|
||||
for (TileImagePlan plan : changedTiles) {
|
||||
messageCount += plan.fragments.size();
|
||||
}
|
||||
int messageNumber = 1;
|
||||
if (!synchronizeCommits) {
|
||||
TileImagePlan plan = changedTiles.get(0);
|
||||
for (BleProtocol.ImageFragment fragment : plan.fragments) {
|
||||
enqueueImageFragmentLocked(plan, fragment, fingerprint, updateId, messageNumber++, messageCount, nextTransportSeq++, true, true);
|
||||
if (!synchronizedCommits) {
|
||||
for (TileImagePlan plan : changedTiles) {
|
||||
for (BleProtocol.ImageFragment fragment : plan.fragments) {
|
||||
enqueueImageFragmentLocked(plan, fragment, fingerprint, updateId, messageNumber++, messageCount, nextTransportSeq++, true, true);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (TileImagePlan plan : changedTiles) {
|
||||
@@ -808,7 +867,8 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
}
|
||||
|
||||
logLine("queue image update#" + updateId + " fingerprint=" + fingerprint
|
||||
+ " changedTiles=" + changedTiles.size() + " messages=" + messageCount);
|
||||
+ " changedTiles=" + changedTiles.size() + " messages=" + messageCount
|
||||
+ " synchronizedCommits=" + synchronizedCommits);
|
||||
}
|
||||
|
||||
private void enqueueImageFragmentLocked(
|
||||
@@ -958,6 +1018,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
displayedFingerprint = "";
|
||||
displayedTileBmps = emptyTileSet();
|
||||
} else if ("image".equals(message.kind)) {
|
||||
imageUpdateStats.remove(message.imageUpdateId);
|
||||
clearMessagesOfKindLocked("image");
|
||||
displayedFingerprint = "";
|
||||
displayedTileBmps = emptyTileSet();
|
||||
@@ -975,6 +1036,9 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
OutboundMessage message = pendingIterator.next();
|
||||
if (kind.equals(message.kind)) {
|
||||
pendingIterator.remove();
|
||||
if ("image".equals(kind)) {
|
||||
imageUpdateStats.remove(message.imageUpdateId);
|
||||
}
|
||||
releaseMagicLocked(message, "cleared pending " + kind);
|
||||
}
|
||||
}
|
||||
@@ -983,6 +1047,9 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
OutboundMessage message = inFlightIterator.next();
|
||||
if (kind.equals(message.kind)) {
|
||||
inFlightIterator.remove();
|
||||
if ("image".equals(kind)) {
|
||||
imageUpdateStats.remove(message.imageUpdateId);
|
||||
}
|
||||
releaseMagicLocked(message, "cleared inflight " + kind);
|
||||
}
|
||||
}
|
||||
@@ -1179,6 +1246,20 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
});
|
||||
}
|
||||
|
||||
private void emitFrameMetrics(int paintMs, int transmitMs, int tileCount) {
|
||||
final FaceclawBleCommunicatorListener current = listener;
|
||||
if (current == null) {
|
||||
return;
|
||||
}
|
||||
mainHandler.post(() -> {
|
||||
try {
|
||||
current.onFrameMetrics(paintMs, transmitMs, tileCount);
|
||||
} catch (Throwable t) {
|
||||
Log.w(TAG, "listener onFrameMetrics failed", t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void maybeEmitEvenAppConflictLocked(String reason) {
|
||||
if (!"write failed".equals(reason)) {
|
||||
return;
|
||||
@@ -1379,6 +1460,17 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
}
|
||||
}
|
||||
|
||||
private static final class ImageUpdateStats {
|
||||
final int paintMs;
|
||||
final int tileCount;
|
||||
long firstWriteStartedAtMs;
|
||||
|
||||
ImageUpdateStats(int paintMs, int tileCount) {
|
||||
this.paintMs = Math.max(0, paintMs);
|
||||
this.tileCount = tileCount;
|
||||
}
|
||||
}
|
||||
|
||||
private static final class OutboundMessage {
|
||||
final String kind;
|
||||
final String label;
|
||||
@@ -1394,6 +1486,7 @@ public class FaceclawBleCommunicator implements FaceclawBleListener, Runnable {
|
||||
int imageMessageNumber;
|
||||
int imageMessageCount;
|
||||
long sentAtMs;
|
||||
long writeStartedAtMs;
|
||||
long ackDeadlineAtMs;
|
||||
byte[] ackPayload = new byte[0];
|
||||
|
||||
|
||||
+1
@@ -6,4 +6,5 @@ public interface FaceclawBleCommunicatorListener {
|
||||
void onRingEvent(String kind, String containerName, int eventType, int eventSource, int systemExitReasonCode);
|
||||
void onBatteryState(int headsetBattery, int headsetCharging);
|
||||
void onEvenAppConflict(String message);
|
||||
void onFrameMetrics(int paintMs, int transmitMs, int tileCount);
|
||||
}
|
||||
+1
-1
@@ -75,7 +75,7 @@ public class FaceclawMediaNotificationListenerService extends NotificationListen
|
||||
continue;
|
||||
}
|
||||
CharSequence title = extras.getCharSequence(Notification.EXTRA_TITLE);
|
||||
if (expectedTitle.contentEquals(title)) {
|
||||
if (title != null && expectedTitle.contentEquals(title)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+193
@@ -0,0 +1,193 @@
|
||||
package com.faceclaw.app;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.ConnectivityManager;
|
||||
import android.net.Network;
|
||||
import android.net.NetworkCapabilities;
|
||||
import android.net.wifi.WifiInfo;
|
||||
import android.net.wifi.WifiManager;
|
||||
import android.os.Build;
|
||||
import android.telephony.SignalStrength;
|
||||
import android.telephony.TelephonyManager;
|
||||
import android.util.Log;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public final class FaceclawSystemStatusIconProvider {
|
||||
private static final String TAG = "FaceclawStatusIcons";
|
||||
private static final int ICON_SIZE = 24;
|
||||
|
||||
private FaceclawSystemStatusIconProvider() {
|
||||
}
|
||||
|
||||
public static byte[] getSystemStatusIconGrays(Context context, int iconSize) {
|
||||
if (context == null) {
|
||||
return new byte[0];
|
||||
}
|
||||
Context appContext = context.getApplicationContext();
|
||||
int size = Math.max(1, Math.min(96, iconSize));
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream(size * size * 3);
|
||||
|
||||
int wifiLevel = getWifiLevel(appContext);
|
||||
if (wifiLevel >= 0) {
|
||||
append(out, scaleIcon(drawWifiIcon(wifiLevel), size));
|
||||
}
|
||||
|
||||
int cellLevel = getCellLevel(appContext);
|
||||
if (cellLevel >= 0) {
|
||||
append(out, scaleIcon(drawCellIcon(cellLevel), size));
|
||||
}
|
||||
|
||||
if (isHotspotEnabled(appContext)) {
|
||||
append(out, scaleIcon(drawHotspotIcon(), size));
|
||||
}
|
||||
|
||||
return out.toByteArray();
|
||||
}
|
||||
|
||||
private static int getWifiLevel(Context context) {
|
||||
try {
|
||||
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||
Network activeNetwork = connectivityManager == null ? null : connectivityManager.getActiveNetwork();
|
||||
NetworkCapabilities capabilities = activeNetwork == null ? null : connectivityManager.getNetworkCapabilities(activeNetwork);
|
||||
if (capabilities == null || !capabilities.hasTransport(NetworkCapabilities.TRANSPORT_WIFI)) {
|
||||
return -1;
|
||||
}
|
||||
WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
||||
WifiInfo info = wifiManager == null ? null : wifiManager.getConnectionInfo();
|
||||
if (info == null || !isValidRssi(info.getRssi())) {
|
||||
return -1;
|
||||
}
|
||||
return Math.max(0, Math.min(4, WifiManager.calculateSignalLevel(info.getRssi(), 5)));
|
||||
} catch (Throwable t) {
|
||||
Log.w(TAG, "failed to read Wi-Fi status", t);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private static int getCellLevel(Context context) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P) {
|
||||
return -1;
|
||||
}
|
||||
try {
|
||||
TelephonyManager telephonyManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
|
||||
SignalStrength signalStrength = telephonyManager == null ? null : telephonyManager.getSignalStrength();
|
||||
if (signalStrength == null) {
|
||||
return -1;
|
||||
}
|
||||
return Math.max(0, Math.min(4, signalStrength.getLevel()));
|
||||
} catch (SecurityException e) {
|
||||
// Most Android versions require READ_PHONE_STATE for this. We skip it
|
||||
// rather than prompting for a broad phone permission just for an icon.
|
||||
return -1;
|
||||
} catch (Throwable t) {
|
||||
Log.w(TAG, "failed to read cellular status", t);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isHotspotEnabled(Context context) {
|
||||
try {
|
||||
WifiManager wifiManager = (WifiManager) context.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
|
||||
if (wifiManager == null) {
|
||||
return false;
|
||||
}
|
||||
Method method = wifiManager.getClass().getDeclaredMethod("getWifiApState");
|
||||
method.setAccessible(true);
|
||||
Object result = method.invoke(wifiManager);
|
||||
int state = result instanceof Integer ? (Integer) result : -1;
|
||||
return state == 13 || state == 12; // WIFI_AP_STATE_ENABLED / ENABLING
|
||||
} catch (Throwable ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isValidRssi(int rssi) {
|
||||
return rssi > -127 && rssi < 0;
|
||||
}
|
||||
|
||||
private static byte[] drawWifiIcon(int level) {
|
||||
byte[] icon = new byte[ICON_SIZE * ICON_SIZE];
|
||||
int cx = 12;
|
||||
int cy = 18;
|
||||
fillRect(icon, cx - 1, cy - 1, 3, 3, 230);
|
||||
int[] radii = new int[] {5, 9, 13, 17};
|
||||
for (int index = 0; index < radii.length; index++) {
|
||||
if (level <= index) {
|
||||
continue;
|
||||
}
|
||||
drawWifiArc(icon, cx, cy, radii[index], 210);
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
private static void drawWifiArc(byte[] icon, int cx, int cy, int radius, int value) {
|
||||
int inner = (radius - 1) * (radius - 1);
|
||||
int outer = (radius + 1) * (radius + 1);
|
||||
for (int y = 0; y < ICON_SIZE; y++) {
|
||||
for (int x = 0; x < ICON_SIZE; x++) {
|
||||
int dx = x - cx;
|
||||
int dy = y - cy;
|
||||
int dist = dx * dx + dy * dy;
|
||||
if (dy <= 0 && dist >= inner && dist <= outer && Math.abs(dx) <= radius) {
|
||||
setPixel(icon, x, y, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static byte[] drawCellIcon(int level) {
|
||||
byte[] icon = new byte[ICON_SIZE * ICON_SIZE];
|
||||
for (int bar = 0; bar < 4; bar++) {
|
||||
int x = 5 + bar * 4;
|
||||
int height = 5 + bar * 4;
|
||||
int value = level > bar ? 220 : 55;
|
||||
fillRect(icon, x, 20 - height, 3, height, value);
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
private static byte[] drawHotspotIcon() {
|
||||
byte[] icon = new byte[ICON_SIZE * ICON_SIZE];
|
||||
fillRect(icon, 11, 17, 3, 3, 230);
|
||||
drawWifiArc(icon, 12, 19, 7, 210);
|
||||
drawWifiArc(icon, 12, 19, 12, 210);
|
||||
fillRect(icon, 6, 5, 12, 2, 170);
|
||||
return icon;
|
||||
}
|
||||
|
||||
private static byte[] scaleIcon(byte[] source, int size) {
|
||||
if (size == ICON_SIZE) {
|
||||
return source;
|
||||
}
|
||||
byte[] scaled = new byte[size * size];
|
||||
for (int y = 0; y < size; y++) {
|
||||
int sy = Math.min(ICON_SIZE - 1, (y * ICON_SIZE) / size);
|
||||
for (int x = 0; x < size; x++) {
|
||||
int sx = Math.min(ICON_SIZE - 1, (x * ICON_SIZE) / size);
|
||||
scaled[y * size + x] = source[sy * ICON_SIZE + sx];
|
||||
}
|
||||
}
|
||||
return scaled;
|
||||
}
|
||||
|
||||
private static void fillRect(byte[] icon, int x, int y, int width, int height, int value) {
|
||||
for (int row = y; row < y + height; row++) {
|
||||
for (int col = x; col < x + width; col++) {
|
||||
setPixel(icon, col, row, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void setPixel(byte[] icon, int x, int y, int value) {
|
||||
if (x < 0 || y < 0 || x >= ICON_SIZE || y >= ICON_SIZE) {
|
||||
return;
|
||||
}
|
||||
icon[y * ICON_SIZE + x] = (byte) Math.max(0, Math.min(255, value));
|
||||
}
|
||||
|
||||
private static void append(ByteArrayOutputStream out, byte[] bytes) {
|
||||
out.write(bytes, 0, bytes.length);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user