mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-25 16:15:55 +01:00
Bangle.js: some minor code cleanup
Also improves performance when scanning for emoji (if one has been found stop scanning for more)
This commit is contained in:
parent
abec54fb1a
commit
7985f8c703
@ -23,7 +23,6 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
@ -51,7 +50,6 @@ import org.xml.sax.InputSource;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
@ -64,7 +62,6 @@ import java.util.GregorianCalendar;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.SimpleTimeZone;
|
||||
@ -77,8 +74,6 @@ import io.wax911.emojify.EmojiUtils;
|
||||
import de.greenrobot.dao.query.QueryBuilder;
|
||||
import nodomain.freeyourgadget.gadgetbridge.BuildConfig;
|
||||
import nodomain.freeyourgadget.gadgetbridge.GBApplication;
|
||||
import nodomain.freeyourgadget.gadgetbridge.R;
|
||||
import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHandler;
|
||||
import nodomain.freeyourgadget.gadgetbridge.database.DBHelper;
|
||||
import nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventBatteryInfo;
|
||||
@ -94,7 +89,6 @@ import nodomain.freeyourgadget.gadgetbridge.entities.CalendarSyncState;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.CalendarSyncStateDao;
|
||||
import nodomain.freeyourgadget.gadgetbridge.entities.DaoSession;
|
||||
import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.ActivityKind;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.Alarm;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.BatteryState;
|
||||
import nodomain.freeyourgadget.gadgetbridge.model.CalendarEventSpec;
|
||||
@ -644,9 +638,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
// clone the data from super.getHeaders() so we can write to it
|
||||
Map<String, String> h = new HashMap<>(super.getHeaders());
|
||||
if (headers != null) {
|
||||
Iterator<String> iter = headers.keySet().iterator();
|
||||
while (iter.hasNext()) {
|
||||
String key = iter.next();
|
||||
for (String key : headers.keySet()) {
|
||||
String value = headers.get(key);
|
||||
h.put(key, value);
|
||||
}
|
||||
@ -847,7 +839,10 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
if (EmojiUtils.getAllEmojis()==null)
|
||||
EmojiManager.initEmojiData(GBApplication.getContext());
|
||||
for(Emoji emoji : EmojiUtils.getAllEmojis())
|
||||
if (word.contains(emoji.getEmoji())) hasEmoji = true;
|
||||
if (word.contains(emoji.getEmoji())) {
|
||||
hasEmoji = true;
|
||||
break;
|
||||
}
|
||||
// if we had emoji, ensure we create 3 bit color (not 1 bit B&W)
|
||||
return "\0"+bitmapToEspruinoString(textToBitmap(word), hasEmoji ? BangleJSBitmapStyle.RGB_3BPP_TRANSPARENT : BangleJSBitmapStyle.MONOCHROME_TRANSPARENT);
|
||||
}
|
||||
@ -895,7 +890,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
for (int i=0;i<notificationSpec.attachedActions.size();i++) {
|
||||
NotificationSpec.Action action = notificationSpec.attachedActions.get(i);
|
||||
if (action.type==NotificationSpec.Action.TYPE_WEARABLE_REPLY)
|
||||
mNotificationReplyAction.add(notificationSpec.getId(), new Long(((long)notificationSpec.getId()<<4) + i + 1)); // wow. This should be easier!
|
||||
mNotificationReplyAction.add(notificationSpec.getId(), ((long) notificationSpec.getId() << 4) + i + 1);
|
||||
}
|
||||
try {
|
||||
JSONObject o = new JSONObject();
|
||||
@ -972,7 +967,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
o.put("t", "call");
|
||||
String cmdName = "";
|
||||
try {
|
||||
Field fields[] = callSpec.getClass().getDeclaredFields();
|
||||
Field[] fields = callSpec.getClass().getDeclaredFields();
|
||||
for (Field field : fields)
|
||||
if (field.getName().startsWith("CALL_") && field.getInt(callSpec) == callSpec.command)
|
||||
cmdName = field.getName().substring(5).toLowerCase();
|
||||
@ -1098,7 +1093,6 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
GB.toast(getContext(), "Log written to "+filename, Toast.LENGTH_LONG, GB.INFO);
|
||||
} catch (IOException e) {
|
||||
LOG.warn("Could not write to file", e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1281,9 +1275,9 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
int height = bitmap.getHeight();
|
||||
int bpp = (style==BangleJSBitmapStyle.RGB_3BPP ||
|
||||
style==BangleJSBitmapStyle.RGB_3BPP_TRANSPARENT) ? 3 : 1;
|
||||
byte pixels[] = new byte[width * height];
|
||||
byte[] pixels = new byte[width * height];
|
||||
final byte PIXELCOL_TRANSPARENT = -1;
|
||||
final int ditherMatrix[] = {1*16,5*16,7*16,3*16}; // for bayer dithering
|
||||
final int[] ditherMatrix = {1*16,5*16,7*16,3*16}; // for bayer dithering
|
||||
// if doing RGB_3BPP_TRANSPARENT, check image to see if it's transparent
|
||||
// MONOCHROME_TRANSPARENT is handled later on...
|
||||
boolean allowTransparency = (style == BangleJSBitmapStyle.RGB_3BPP_TRANSPARENT);
|
||||
@ -1291,7 +1285,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
byte transparentColorIndex = 0;
|
||||
/* Work out what colour index each pixel should be and write to pixels.
|
||||
Also figure out if we're transparent at all, and how often each color is used */
|
||||
int colUsage[] = new int[8];
|
||||
int[] colUsage = new int[8];
|
||||
int n = 0;
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
@ -1342,7 +1336,7 @@ public class BangleJSDeviceSupport extends AbstractBTLEDeviceSupport {
|
||||
}
|
||||
// Write the header
|
||||
int headerLen = isTransparent ? 4 : 3;
|
||||
byte bmp[] = new byte[(((height * width * bpp) + 7) >> 3) + headerLen];
|
||||
byte[] bmp = new byte[(((height * width * bpp) + 7) >> 3) + headerLen];
|
||||
bmp[0] = (byte)width;
|
||||
bmp[1] = (byte)height;
|
||||
bmp[2] = (byte)(bpp + (isTransparent?128:0));
|
||||
|
Loading…
Reference in New Issue
Block a user