1
0
mirror of https://codeberg.org/Freeyourgadget/Gadgetbridge synced 2024-11-28 12:56:49 +01:00

Fixed a bunch of warnings

This commit is contained in:
TaaviE 2020-08-26 05:28:03 +03:00 committed by Gitea
parent 66f684bbd3
commit 7db3b68047
19 changed files with 72 additions and 69 deletions

View File

@ -189,7 +189,7 @@ public abstract class AbstractSettingsActivity extends AppCompatPreferenceActivi
*/
private static void bindPreferenceSummaryToValue(Preference preference) {
// Set the listener to watch for value changes.
SimpleSetSummaryOnChangeListener listener = null;
SimpleSetSummaryOnChangeListener listener;
Preference.OnPreferenceChangeListener existingListener = preference.getOnPreferenceChangeListener();
if (existingListener != null) {
listener = new ExtraSetSummaryOnChangeListener(existingListener);

View File

@ -186,7 +186,7 @@ public class AlarmDetails extends AbstractGBActivity {
private void updateAlarm() {
alarm.setSmartWakeup(supportsSmartWakeup() && cbSmartWakeup.isChecked());
alarm.setSnooze(supportsSnoozing() && cbSnooze.isChecked());
int repetitionMask = AlarmUtils.createRepetitionMassk(cbMonday.isChecked(), cbTuesday.isChecked(), cbWednesday.isChecked(), cbThursday.isChecked(), cbFriday.isChecked(), cbSaturday.isChecked(), cbSunday.isChecked());
int repetitionMask = AlarmUtils.createRepetitionMask(cbMonday.isChecked(), cbTuesday.isChecked(), cbWednesday.isChecked(), cbThursday.isChecked(), cbFriday.isChecked(), cbSaturday.isChecked(), cbSunday.isChecked());
alarm.setRepetition(repetitionMask);
alarm.setHour(timePicker.getCurrentHour());
alarm.setMinute(timePicker.getCurrentMinute());

View File

@ -188,6 +188,7 @@ public class ExternalPebbleJSActivity extends AbstractGBActivity {
myWebView.setWebViewClient(new GBWebClient());
myWebView.setWebChromeClient(new GBChromeClient());
WebSettings webSettings = myWebView.getSettings();
//noinspection SetJavaScriptEnabled
webSettings.setJavaScriptEnabled(true);
//needed to access the DOM
webSettings.setDomStorageEnabled(true);

View File

@ -60,7 +60,7 @@ public class WidgetAlarmsActivity extends Activity implements View.OnClickListen
textView = findViewById(R.id.alarm5);
if (userSleepDuration > 0) {
Resources res = getResources();
textView.setText(String.format(res.getQuantityString(R.plurals.widget_alarm_target_hours, userSleepDuration, userSleepDuration)));
textView.setText(res.getQuantityString(R.plurals.widget_alarm_target_hours, userSleepDuration, userSleepDuration));
} else {
textView.setVisibility(View.GONE);
}

View File

@ -78,16 +78,19 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator {
GBApplication.deviceService().disconnect();
}
Prefs prefs = getPrefs();
String lastDevice = prefs.getPreferences().getString("last_device_address","");
if (gbDevice.getAddress() == lastDevice){
if (gbDevice.getAddress().equals(lastDevice)) {
LOG.debug("#1605 removing last device");
prefs.getPreferences().edit().remove("last_device_address").apply();
}
String macAddress = prefs.getPreferences().getString(MiBandConst.PREF_MIBAND_ADDRESS,"");
if (gbDevice.getAddress() == macAddress){
if (gbDevice.getAddress().equals(macAddress)) {
LOG.debug("#1605 removing devel miband");
prefs.getPreferences().edit().remove(MiBandConst.PREF_MIBAND_ADDRESS).apply();
}
try (DBHandler dbHandler = GBApplication.acquireDB()) {
DaoSession session = dbHandler.getDaoSession();
Device device = DBHelper.findDevice(gbDevice, session);

View File

@ -111,14 +111,16 @@ public class GenericItem implements ItemWithDetails {
@Override
public int compareTo(ItemWithDetails another) {
if (getName() == another.getName()) {
if (getName().equals(another.getName())) {
return 0;
}
if (getName() == null) {
return +1;
} else if (another.getName() == null) {
return -1;
}
return Collator.getInstance().compare(getName(), another.getName());
}
}

View File

@ -383,9 +383,7 @@ public final class BtLEQueue {
if (!transaction.isEmpty()) {
List<AbstractTransaction> tail = new ArrayList<>(mTransactions.size() + 2);
//mTransactions.drainTo(tail);
for( AbstractTransaction t : mTransactions) {
tail.add(t);
}
tail.addAll(mTransactions);
mTransactions.clear();
mTransactions.add(transaction);
mTransactions.addAll(tail);

View File

@ -60,7 +60,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.StringUtils;
public class CasioGB6900DeviceSupport extends AbstractBTLEDeviceSupport {
private static final Logger LOG = LoggerFactory.getLogger(CasioGB6900DeviceSupport.class);
private ArrayList<BluetoothGattCharacteristic> mCasioCharacteristics = new ArrayList<BluetoothGattCharacteristic>();
private final ArrayList<BluetoothGattCharacteristic> mCasioCharacteristics = new ArrayList<BluetoothGattCharacteristic>();
private CasioHandlerThread mHandlerThread = null;
private MusicSpec mBufferMusicSpec = null;
private MusicStateSpec mBufferMusicStateSpec = null;
@ -190,7 +190,7 @@ public class CasioGB6900DeviceSupport extends AbstractBTLEDeviceSupport {
return;
}
byte value[] = new byte[]{GattCharacteristic.MILD_ALERT};
byte[] value = new byte[]{GattCharacteristic.MILD_ALERT};
BluetoothGattService llService = mBtGatt.getService(CasioGB6900Constants.LINK_LOSS_SERVICE);
BluetoothGattCharacteristic charact = llService.getCharacteristic(CasioGB6900Constants.ALERT_LEVEL_CHARACTERISTIC_UUID);
@ -287,8 +287,7 @@ public class CasioGB6900DeviceSupport extends AbstractBTLEDeviceSupport {
private boolean handleInitResponse(byte data) {
boolean handled = false;
switch(data)
{
switch (data) {
case (byte) 1:
LOG.info("Initialization done, setting state to INITIALIZED");
if (mHandlerThread != null) {
@ -393,11 +392,11 @@ public class CasioGB6900DeviceSupport extends AbstractBTLEDeviceSupport {
return true;
if(characteristicUUID.equals(CasioGB6900Constants.TX_POWER_LEVEL_CHARACTERISTIC_UUID)) {
String str = "onCharacteristicRead: Received power level: ";
StringBuilder str = new StringBuilder("onCharacteristicRead: Received power level: ");
for(int i=0; i<data.length; i++) {
str += String.format("0x%1x ", data[i]);
str.append(String.format("0x%1x ", data[i]));
}
LOG.info(str);
LOG.info(str.toString());
}
else {
return super.onCharacteristicRead(gatt, characteristic, status);
@ -465,10 +464,7 @@ public class CasioGB6900DeviceSupport extends AbstractBTLEDeviceSupport {
byte[] msg = new byte[2 + len];
msg[0] = icon;
msg[1] = 1;
for(int i=0; i<len; i++)
{
msg[i + 2] = titleBytes[i];
}
System.arraycopy(titleBytes, 0, msg, 2, len);
builder.write(getCharacteristic(CasioGB6900Constants.ALERT_CHARACTERISTIC_UUID), msg);
LOG.info("Showing notification, title: " + title + " message (not sent): " + message);
@ -605,10 +601,7 @@ public class CasioGB6900DeviceSupport extends AbstractBTLEDeviceSupport {
arr[0] = 0;
arr[1] = 10;
arr[2] = 1;
for(int i=0; i<len; i++)
{
arr[i+3] = bInfo[i];
}
System.arraycopy(bInfo, 0, arr, 3, len);
builder.write(getCharacteristic(CasioGB6900Constants.MORE_ALERT_FOR_LONG_UUID), arr);
builder.queue(getQueue());
} catch (IOException e) {
@ -692,7 +685,7 @@ public class CasioGB6900DeviceSupport extends AbstractBTLEDeviceSupport {
if (start) {
try {
TransactionBuilder builder = performInitialized("findDevice");
byte value[] = new byte[]{GattCharacteristic.HIGH_ALERT};
byte[] value = new byte[]{GattCharacteristic.HIGH_ALERT};
BluetoothGattService service = mBtGatt.getService(CasioGB6900Constants.IMMEDIATE_ALERT_SERVICE_UUID);
BluetoothGattCharacteristic charact = service.getCharacteristic(CasioGB6900Constants.ALERT_LEVEL_CHARACTERISTIC_UUID);

View File

@ -104,9 +104,9 @@ public class InitOperation extends AbstractBTLEOperation<CasioGB6900DeviceSuppor
if(characteristicUUID.equals(CasioGB6900Constants.CASIO_SETTING_FOR_BLE_CHARACTERISTIC_UUID)) {
mBleSettings = data;
String str = "Read Casio Setting for BLE: ";
for(int i=0; i<data.length; i++) {
str += String.format("0x%1x ", data[i]);
StringBuilder str = new StringBuilder("Read Casio Setting for BLE: ");
for (byte datum : data) {
str.append(String.format("0x%1x ", datum));
}
/* Definition of parameters - for future reference */

View File

@ -30,8 +30,8 @@ import nodomain.freeyourgadget.gadgetbridge.service.devices.miband.operations.Op
import nodomain.freeyourgadget.gadgetbridge.util.GB;
public abstract class AbstractID115Operation extends AbstractBTLEOperation<ID115Support> {
protected BluetoothGattCharacteristic controlCharacteristic = null;
protected BluetoothGattCharacteristic notifyCharacteristic = null;
protected BluetoothGattCharacteristic controlCharacteristic;
protected BluetoothGattCharacteristic notifyCharacteristic;
protected AbstractID115Operation(ID115Support support) {
super(support);

View File

@ -88,7 +88,7 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement
// The delay must be at least as long as it takes the watch to respond.
// Reordering the requests could maybe reduce the delay, but this works fine too.
private CountDownTimer mFetchCountDown = new CountDownTimer(2000, 2000) {
private final CountDownTimer mFetchCountDown = new CountDownTimer(2000, 2000) {
@Override
public void onTick(long millisUntilFinished) {
@ -101,7 +101,7 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement
}
};
private Handler mFindPhoneHandler = new Handler();
private final Handler mFindPhoneHandler = new Handler();
private BluetoothGattCharacteristic mControlCharacteristic = null;
private BluetoothGattCharacteristic mReportCharacteristic = null;
@ -776,8 +776,8 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement
byte[] value = characteristic.getValue();
byte[] arguments = new byte[value.length - 6];
for (int i = 0; i < arguments.length; ++i) {
arguments[i] = value[i + 6];
if (arguments.length >= 0) {
System.arraycopy(value, 6, arguments, 0, arguments.length);
}
byte[] report = new byte[]{value[4], value[5]};
@ -837,9 +837,7 @@ public class MakibesHR3DeviceSupport extends AbstractBTLEDeviceSupport implement
result[MakibesHR3Constants.DATA_ARGUMENT_COUNT_INDEX] = (byte) (data.length + 3);
for (int i = 0; i < command.length; ++i) {
result[MakibesHR3Constants.DATA_COMMAND_INDEX + i] = command[i];
}
System.arraycopy(command, 0, result, 4, command.length);
System.arraycopy(data, 0, result, 6, data.length);

View File

@ -217,8 +217,8 @@ class PebbleGATTClient extends BluetoothGattCallback {
private void connectToPebble(BluetoothDevice btDevice) {
if (removeBond) {
try {
Method m = btDevice.getClass()
.getMethod("removeBond", (Class[]) null);
// TODO: Use BondingUtil
Method m = btDevice.getClass().getMethod("removeBond", (Class[]) null);
m.invoke(btDevice, (Object[]) null);
} catch (Exception e) {
LOG.warn(e.getMessage());

View File

@ -27,8 +27,9 @@ public class Alarm {
public final int WEEKDAY_FRIDAY = 5;
public final int WEEKDAY_SATURDAY = 6;
private byte days = 0;
private byte minute, hour;
private boolean repeat;
private final byte minute;
private final byte hour;
private final boolean repeat;
private String title, message;
public Alarm(byte minute, byte hour, String title, String message){
@ -108,13 +109,13 @@ public class Alarm {
String[] dayNames = new String[]{"sunday", "monday", "tuesday", "thursday", "wednesday", "friday", "saturday"};
for(int i = WEEKDAY_SUNDAY; i <= WEEKDAY_SATURDAY; i++){
if((days & 1 << i) != 0){
description += dayNames[i] + " ";
description.append(dayNames[i]).append(" ");
}
}
}else{
description += "not repeating";
description.append("not repeating");
}
return description;
return description.toString();
}
}

View File

@ -81,7 +81,7 @@ public class AlarmUtils {
* @param sun whether the alarm shall repeat every Sunday
* @return the created repetition mask
*/
public static int createRepetitionMassk(boolean mon, boolean tue, boolean wed, boolean thu, boolean fri, boolean sat, boolean sun) {
public static int createRepetitionMask(boolean mon, boolean tue, boolean wed, boolean thu, boolean fri, boolean sat, boolean sun) {
int repetitionMask = (mon ? Alarm.ALARM_MON : 0) |
(tue ? Alarm.ALARM_TUE : 0) |
(wed ? Alarm.ALARM_WED : 0) |

View File

@ -217,8 +217,7 @@ public class AndroidUtils {
String[] projection = {
MediaStore.Images.Media.DATA
};
Cursor cursor = null;
cursor = context.getContentResolver()
Cursor cursor = context.getContentResolver()
.query(uri, projection, selection, selectionArgs, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
if (cursor.moveToFirst()) {

View File

@ -144,20 +144,17 @@ public class DeviceHelper {
public Set<GBDevice> getAvailableDevices(Context context) {
BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter();
Set<GBDevice> availableDevices = new LinkedHashSet<GBDevice>();
if (btAdapter == null) {
GB.toast(context, context.getString(R.string.bluetooth_is_not_supported_), Toast.LENGTH_SHORT, GB.WARN);
} else if (!btAdapter.isEnabled()) {
GB.toast(context, context.getString(R.string.bluetooth_is_disabled_), Toast.LENGTH_SHORT, GB.WARN);
}
List<GBDevice> dbDevices = getDatabaseDevices();
availableDevices.addAll(dbDevices);
Set<GBDevice> availableDevices = new LinkedHashSet<>(getDatabaseDevices());
Prefs prefs = GBApplication.getPrefs();
String miAddr = prefs.getString(MiBandConst.PREF_MIBAND_ADDRESS, "");
if (miAddr.length() > 0) {
GBDevice miDevice = new GBDevice(miAddr, "MI", null, DeviceType.MIBAND);
String miAddress = prefs.getString(MiBandConst.PREF_MIBAND_ADDRESS, "");
if (miAddress.length() > 0) {
GBDevice miDevice = new GBDevice(miAddress, "MI", null, DeviceType.MIBAND);
availableDevices.add(miDevice);
}

View File

@ -28,10 +28,11 @@ import nodomain.freeyourgadget.gadgetbridge.GBApplication;
public class LanguageUtils {
//transliteration map with english equivalent for unsupported chars
private static Map<Character, String> transliterateMap = new HashMap<Character, String>(){
// Transliteration map with english equivalent for unsupported chars
@SuppressWarnings("OverwrittenKey")
private static final Map<Character, String> transliterateMap = new HashMap<Character, String>() {
{
//extended ASCII characters
// Extended ASCII characters
put('œ', "oe"); put('ª', "a"); put('º', "o"); put('«',"\""); put('»',"\"");
// Scandinavian characters
@ -39,25 +40,25 @@ public class LanguageUtils {
put('Ø',"Oe"); put('ø',"oe");
put('Å',"Aa"); put('å',"aa");
//german characters
// German characters
put('ä',"ae"); put('ö',"oe"); put('ü',"ue");
put('Ä',"Ae"); put('Ö',"Oe"); put('Ü',"Üe");
put('ß',"ss"); put('ẞ',"SS");
//russian chars
// Russian chars
put('а', "a"); put('б', "b"); put('в', "v"); put('г', "g"); put('д', "d"); put('е', "e"); put('ё', "jo"); put('ж', "zh");
put('з', "z"); put('и', "i"); put('й', "jj"); put('к', "k"); put('л', "l"); put('м', "m"); put('н', "n"); put('о', "o");
put('п', "p"); put('р', "r"); put('с', "s"); put('т', "t"); put('у', "u"); put('ф', "f"); put('х', "kh"); put('ц', "c");
put('ч', "ch");put('ш', "sh");put('щ', "shh");put('ъ', "\"");put('ы', "y"); put('ь', "'"); put('э', "eh"); put('ю', "ju");
put('я', "ja");
//hebrew chars
// Hebrew chars
put('א', "a"); put('ב', "b"); put('ג', "g"); put('ד', "d"); put('ה', "h"); put('ו', "u"); put('ז', "z"); put('ח', "kh");
put('ט', "t"); put('י', "y"); put('כ', "c"); put('ל', "l"); put('מ', "m"); put('נ', "n"); put('ס', "s"); put('ע', "'");
put('פ', "p"); put('צ', "ts"); put('ק', "k"); put('ר', "r"); put('ש', "sh"); put('ת', "th"); put('ף', "f"); put('ץ', "ts");
put('ך', "ch");put('ם', "m");put('ן', "n");
// greek chars
// Greek chars
put('α',"a");put('ά',"a");put('β',"v");put('γ',"g");put('δ',"d");put('ε',"e");put('έ',"e");put('ζ',"z");put('η',"i");
put('ή',"i");put('θ',"th");put('ι',"i");put('ί',"i");put('ϊ',"i");put('ΐ',"i");put('κ',"k");put('λ',"l");put('μ',"m");
put('ν',"n");put('ξ',"ks");put('ο',"o");put('ό',"o");put('π',"p");put('ρ',"r");put('σ',"s");put('ς',"s");put('τ',"t");
@ -67,7 +68,7 @@ public class LanguageUtils {
put('Ξ',"KS");put('Ο',"O");put('Ό',"O");put('Π',"P");put('Ρ',"R");put('Σ',"S");put('Τ',"T");put('Υ',"Y");put('Ύ',"Y");
put('Ϋ',"Y");put('Φ',"F");put('Χ',"CH");put('Ψ',"PS");put('Ω',"O");put('Ώ',"O");
//ukrainian characters
// Ukrainian characters
put('ґ', "gh"); put('є', "je"); put('і', "i"); put('ї', "ji"); put('Ґ', "GH"); put('Є', "JE"); put('І', "I"); put('Ї', "JI");
// Arabic
@ -92,6 +93,13 @@ public class LanguageUtils {
//Lithuanian
put('ą', "a"); put('č', "c"); put('ę', "e"); put('ė', "e"); put('į', "i"); put('š', "s"); put('ų', "u"); put('ū', "u"); put('ž', "z");
// Estonian
put('ä', "a"); put('Ä', "A");
put('ö', "o"); put('õ', "o");
put('Ö', "O"); put('Õ', "O");
put('ü', "u"); put('Ü', "U");
//TODO: these must be configurable. If someone wants to transliterate cyrillic it does not mean his device has no German umlauts
// all or nothing is really bad here
}

View File

@ -56,9 +56,11 @@ public class StringUtils {
}
public static String pad(String s, int length, char padChar) {
while(s.length() < length) {
s += padChar;
StringBuilder sBuilder = new StringBuilder(s);
while (sBuilder.length() < length) {
sBuilder.append(padChar);
}
s = sBuilder.toString();
return s;
}

View File

@ -82,6 +82,7 @@ public class WebViewSingleton {
instance.webView.setWebViewClient(new GBWebClient());
instance.webView.setWebChromeClient(new GBChromeClient());
WebSettings webSettings = instance.webView.getSettings();
//noinspection SetJavaScriptEnabled
webSettings.setJavaScriptEnabled(true);
//needed to access the DOM
webSettings.setDomStorageEnabled(true);