diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lenovo/DataType.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lenovo/DataType.java index ce4d4cc73..9b4f26696 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lenovo/DataType.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lenovo/DataType.java @@ -9,7 +9,7 @@ public enum DataType { ENVIRONMENT_TEMPERATURE(new byte[]{0x00, 0x09}), AIR_PRESSURE(new byte[]{0x00, 0x0A}); - private byte[] value; + private final byte[] value; DataType(byte[] value) { this.value = value; diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lenovo/LenovoWatchCalibrationActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lenovo/LenovoWatchCalibrationActivity.java index 508bb6a01..a3d75bcc0 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lenovo/LenovoWatchCalibrationActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lenovo/LenovoWatchCalibrationActivity.java @@ -23,6 +23,7 @@ import android.view.View; import android.widget.Button; import android.widget.NumberPicker; +import androidx.annotation.NonNull; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.activities.AbstractGBActivity; @@ -31,12 +32,12 @@ import nodomain.freeyourgadget.gadgetbridge.impl.GBDevice; public class LenovoWatchCalibrationActivity extends AbstractGBActivity { private static final String STATE_DEVICE = "stateDevice"; - GBDevice device; + private GBDevice device; - NumberPicker pickerHour, pickerMinute, pickerSecond; + private NumberPicker pickerHour, pickerMinute, pickerSecond; - Handler handler; - Runnable holdCalibration; + private Handler handler; + private Runnable holdCalibration; @Override protected void onCreate(Bundle savedInstanceState) { @@ -92,7 +93,7 @@ public class LenovoWatchCalibrationActivity extends AbstractGBActivity { } @Override - protected void onSaveInstanceState(Bundle outState) { + protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); outState.putParcelable(STATE_DEVICE, device); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lenovo/LenovoWatchPairingActivity.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lenovo/LenovoWatchPairingActivity.java index 2b6f795ae..06b301699 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lenovo/LenovoWatchPairingActivity.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lenovo/LenovoWatchPairingActivity.java @@ -27,6 +27,7 @@ import android.widget.Toast; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import androidx.annotation.NonNull; import androidx.localbroadcastmanager.content.LocalBroadcastManager; import nodomain.freeyourgadget.gadgetbridge.GBApplication; import nodomain.freeyourgadget.gadgetbridge.R; @@ -86,7 +87,7 @@ public class LenovoWatchPairingActivity extends AbstractGBActivity { } @Override - protected void onSaveInstanceState(Bundle outState) { + protected void onSaveInstanceState(@NonNull Bundle outState) { super.onSaveInstanceState(outState); outState.putParcelable(STATE_DEVICE_CANDIDATE, deviceCandidate); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lenovo/watchxplus/WatchXPlusDeviceCoordinator.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lenovo/watchxplus/WatchXPlusDeviceCoordinator.java index aff51c4bc..9c4a1bf83 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lenovo/watchxplus/WatchXPlusDeviceCoordinator.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/devices/lenovo/watchxplus/WatchXPlusDeviceCoordinator.java @@ -22,7 +22,6 @@ import java.util.Collection; import java.util.Collections; import nodomain.freeyourgadget.gadgetbridge.GBApplication; -import nodomain.freeyourgadget.gadgetbridge.GBException; import nodomain.freeyourgadget.gadgetbridge.R; import nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsPreferenceConst; import nodomain.freeyourgadget.gadgetbridge.devices.AbstractDeviceCoordinator; @@ -47,7 +46,7 @@ public class WatchXPlusDeviceCoordinator extends AbstractDeviceCoordinator { public static final int FindPhone_OFF = 0; public static boolean isBPCalibrated = false; - private static Prefs prefs = GBApplication.getPrefs(); + private static final Prefs prefs = GBApplication.getPrefs(); @NonNull @Override @@ -194,7 +193,7 @@ Prefs from device settings on main page } // return watch language pref - public static byte getLanguage(SharedPreferences sharedPrefs) { + public static byte getLanguage() { int settingRead = prefs.getInt(WatchXPlusConstants.PREF_WXP_LANGUAGE, 1); return (byte) settingRead; } @@ -308,38 +307,38 @@ Prefs from device settings on main page Values from device specific settings page */ // read altitude from preferences - public static int getAltitude(String address) { + public static int getAltitude() { return prefs.getInt(WatchXPlusConstants.PREF_ALTITUDE, 200); } // read repeat call notification - public static int getRepeatOnCall(String address) { + public static int getRepeatOnCall() { return prefs.getInt(WatchXPlusConstants.PREF_REPEAT, 1); } //read continious call notification - public static boolean getContiniousVibrationOnCall(String address) { + public static boolean getContiniousVibrationOnCall() { return prefs.getBoolean(WatchXPlusConstants.PREF_CONTINIOUS, false); } //read missed call notification - public static boolean getMissedCallReminder(String address) { + public static boolean getMissedCallReminder() { return prefs.getBoolean(WatchXPlusConstants.PREF_MISSED_CALL, false); } //read missed call notification - public static int getMissedCallRepeat(String address) { + public static int getMissedCallRepeat() { return prefs.getInt(WatchXPlusConstants.PREF_MISSED_CALL_REPEAT, 0); } //read button reject call settings - public static boolean getButtonReject(String address) { + public static boolean getButtonReject() { return prefs.getBoolean(WatchXPlusConstants.PREF_BUTTON_REJECT, false); } //read shake wrist reject call settings - public static boolean getShakeReject(String address) { + public static boolean getShakeReject() { return prefs.getBoolean(WatchXPlusConstants.PREF_SHAKE_REJECT, false); } diff --git a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/lenovo/watchxplus/WatchXPlusDeviceSupport.java b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/lenovo/watchxplus/WatchXPlusDeviceSupport.java index 33d882e9c..23f92b21d 100644 --- a/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/lenovo/watchxplus/WatchXPlusDeviceSupport.java +++ b/app/src/main/java/nodomain/freeyourgadget/gadgetbridge/service/devices/lenovo/watchxplus/WatchXPlusDeviceSupport.java @@ -92,7 +92,7 @@ import nodomain.freeyourgadget.gadgetbridge.util.StringUtils; public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { - private static Prefs prefs = GBApplication.getPrefs(); + private static final Prefs prefs = GBApplication.getPrefs(); private boolean needsAuth; private int sequenceNumber = 0; @@ -489,11 +489,11 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { final int repeatDelay = 5000; // repeat delay of 5 sec (watch show call notifications for about 5 sec.) final int repeatMissedDelay = 60000; // repeat missed call delay of 60 sec // get settings for continuous vibration while phone rings - final boolean continuousRing = WatchXPlusDeviceCoordinator.getContiniousVibrationOnCall(getDevice().getAddress()); + final boolean continuousRing = WatchXPlusDeviceCoordinator.getContiniousVibrationOnCall(); // set settings for missed call - boolean missedCall = WatchXPlusDeviceCoordinator.getMissedCallReminder(getDevice().getAddress()); - int repeatCount = WatchXPlusDeviceCoordinator.getRepeatOnCall(getDevice().getAddress()); - int repeatCountMissed = WatchXPlusDeviceCoordinator.getMissedCallRepeat(getDevice().getAddress()); + boolean missedCall = WatchXPlusDeviceCoordinator.getMissedCallReminder(); + int repeatCount = WatchXPlusDeviceCoordinator.getRepeatOnCall(); + int repeatCountMissed = WatchXPlusDeviceCoordinator.getMissedCallRepeat(); // check if repeatCount is in boundaries min=0, max=10 if (repeatCount < 0) repeatCount = 0; if (repeatCount > 10) repeatCount = 10; // limit repeats to 10 @@ -610,13 +610,11 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { } /** handle button press while ringing - * @param value - reply from watch - * while phone rings choose what to do when watch button is pressed */ - private void handleButtonWhenRing(byte[] value) { + private void handleButtonWhenRing() { GBDeviceEventCallControl callCmd = new GBDeviceEventCallControl(); // get saved settings if true - reject call, otherwise ignore call - boolean buttonReject = WatchXPlusDeviceCoordinator.getButtonReject(getDevice().getAddress()); + boolean buttonReject = WatchXPlusDeviceCoordinator.getButtonReject(); if (buttonReject) { LOG.info(" call rejected "); isRinging = false; @@ -873,9 +871,8 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { * @param minuteStart - begin minute * @param hourEnd - end hour * @param minuteEnd - end minute - * set long sit reminder (inactivity reminder) on watch */ - private WatchXPlusDeviceSupport setLongSitHours(TransactionBuilder builder, boolean enable, int hourStart, int minuteStart, int hourEnd, int minuteEnd, int period) { + private void setLongSitHours(TransactionBuilder builder, boolean enable, int hourStart, int minuteStart, int hourEnd, int minuteEnd, int period) { LOG.warn(" Setting Long sit reminder... Enabled:"+enable+" Period:"+period); LOG.warn(" Setting Long sit time... Hs:"+hourEnd+" Ms:"+minuteEnd+" He:"+hourStart+" Me:"+minuteStart); LOG.warn(" Setting Long sit DND time... Hs:"+hourStart+" Ms:"+minuteStart+" He:"+hourEnd+" Me:"+minuteEnd); @@ -898,7 +895,6 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { buildCommand(command, WatchXPlusConstants.WRITE_VALUE, bArr)); // set long sit reminder state (enabled, disabled) setLongSitSwitch(builder, enable); - return this; } /** get Long sit settings from app, and send it to watch @@ -925,15 +921,13 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { /** set long sit reminder switch * @param tbuilder - transaction builder * @param enable - true or false - * enabled or disables long sit reminder (inactivity reminder) on watch */ - private WatchXPlusDeviceSupport setLongSitSwitch(TransactionBuilder tbuilder, boolean enable) { + private void setLongSitSwitch(TransactionBuilder tbuilder, boolean enable) { LOG.warn("Setting Long sit reminder switch to" + enable); tbuilder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), buildCommand(WatchXPlusConstants.CMD_INACTIVITY_REMINDER_SWITCH, WatchXPlusConstants.WRITE_VALUE, new byte[]{(byte) (enable ? 0x01 : 0x00)})); - return this; } @@ -945,9 +939,8 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { * @param minuteStart - begin minute * @param hourEnd - end hour * @param minuteEnd - end minute - * set do not disturb on watch */ - private WatchXPlusDeviceSupport setQuiteHours(TransactionBuilder builder, boolean enable, int hourStart, int minuteStart, int hourEnd, int minuteEnd) { + private void setQuiteHours(TransactionBuilder builder, boolean enable, int hourStart, int minuteStart, int hourEnd, int minuteEnd) { LOG.warn(" Setting DND time... Hs:"+hourStart+" Ms:"+minuteStart+" He:"+hourEnd+" Me:"+minuteEnd); // set DND time byte[] command = WatchXPlusConstants.CMD_SET_QUITE_HOURS_TIME; @@ -961,21 +954,18 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { buildCommand(command, WatchXPlusConstants.WRITE_VALUE, bArr)); // set DND state (enabled, disabled) setQuiteHoursSwitch(builder, enable); - return this; } /** set do not disturb switch * @param tbuilder - transaction builder * @param enable - true or false - * enabled or disables DND on watch */ - private WatchXPlusDeviceSupport setQuiteHoursSwitch(TransactionBuilder tbuilder, boolean enable) { + private void setQuiteHoursSwitch(TransactionBuilder tbuilder, boolean enable) { LOG.warn("Setting DND switch to" + enable); tbuilder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), buildCommand(WatchXPlusConstants.CMD_SET_QUITE_HOURS_SWITCH, WatchXPlusConstants.WRITE_VALUE, new byte[]{(byte) (enable ? 0x01 : 0x00)})); - return this; } /** get DND settings from app, and send it to watch @@ -1360,7 +1350,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { } else if (ArrayUtils.equals(value, WatchXPlusConstants.RESP_SET_PERSONAL_INFO, 5)) { handlePersonalInfo(value); } else if (ArrayUtils.equals(value, WatchXPlusConstants.RESP_BUTTON_WHILE_RING, 5)) { - handleButtonWhenRing(value); + handleButtonWhenRing(); } else if (ArrayUtils.equals(value, WatchXPlusConstants.RESP_DISCONNECT_REMIND, 5)) { handleDisconnectReminderState(value); } else if (ArrayUtils.equals(value, WatchXPlusConstants.RESP_BATTERY_INFO, 5)) { @@ -1855,7 +1845,6 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { * for test purposes only */ private void handleShakeState(byte[] value) { - boolean z = true; String light = "lightScreen"; if ((value[11] & 1) == 1) { light = light + " on"; @@ -1939,8 +1928,8 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { } // Command to toggle Lift Wrist to Light Screen, and shake to ignore/reject call - private WatchXPlusDeviceSupport setHeadsUpScreen(TransactionBuilder transactionBuilder, boolean enable) { - boolean shakeReject = WatchXPlusDeviceCoordinator.getShakeReject(getDevice().getAddress()); + private void setHeadsUpScreen(TransactionBuilder transactionBuilder, boolean enable) { + boolean shakeReject = WatchXPlusDeviceCoordinator.getShakeReject(); byte refuseCall = 0x00; // force shake wrist to ignore/reject call to OFF // returned characteristic is equal with button press while ringing if (shakeReject) refuseCall = 0x01; @@ -1958,7 +1947,6 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { buildCommand(WatchXPlusConstants.CMD_SHAKE_SWITCH, WatchXPlusConstants.WRITE_VALUE, liftScreen)); - return this; } private void setDisconnectReminder(TransactionBuilder transactionBuilder, SharedPreferences sharedPreferences) { @@ -1966,12 +1954,11 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { WatchXPlusDeviceCoordinator.shouldEnableDisconnectReminder(sharedPreferences)); } - private WatchXPlusDeviceSupport setDisconnectReminder(TransactionBuilder transactionBuilder, boolean enable) { + private void setDisconnectReminder(TransactionBuilder transactionBuilder, boolean enable) { transactionBuilder.write(getCharacteristic(WatchXPlusConstants.UUID_CHARACTERISTIC_WRITE), buildCommand(WatchXPlusConstants.CMD_DISCONNECT_REMIND, WatchXPlusConstants.WRITE_VALUE, new byte[]{(byte) (enable ? 0x01 : 0x00)})); - return this; } // Request status of Disconnect reminder @@ -1989,7 +1976,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { // calibrate altitude private void setAltitude(TransactionBuilder transactionBuilder) { - int mAltitude = WatchXPlusDeviceCoordinator.getAltitude(getDevice().getAddress()); + int mAltitude = WatchXPlusDeviceCoordinator.getAltitude(); if (mAltitude < 0) { mAltitude = (Math.abs(mAltitude) ^ 65535) + 1; } @@ -2007,7 +1994,7 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { } // set time format - private WatchXPlusDeviceSupport setLanguageAndTimeFormat(TransactionBuilder transactionBuilder, byte timeMode, byte language) { + private void setLanguageAndTimeFormat(TransactionBuilder transactionBuilder, byte timeMode, byte language) { byte[] bArr = new byte[2]; bArr[0] = language; //byte[08] language bArr[1] = timeMode; //byte[09] time @@ -2015,13 +2002,12 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { buildCommand(WatchXPlusConstants.CMD_TIME_LANGUAGE, WatchXPlusConstants.WRITE_VALUE, bArr)); - return this; } private void setLanguageAndTimeFormat(TransactionBuilder transactionBuilder, SharedPreferences sharedPreferences) { this.setLanguageAndTimeFormat(transactionBuilder, WatchXPlusDeviceCoordinator.getTimeMode(sharedPreferences), - WatchXPlusDeviceCoordinator.getLanguage(sharedPreferences)); + WatchXPlusDeviceCoordinator.getLanguage()); } @Override @@ -2084,14 +2070,16 @@ public class WatchXPlusDeviceSupport extends AbstractBTLEDeviceSupport { (byte) value}; } - static int calculateLow(byte... bArr) { - int i = 0; - int i2 = 0; - while (i < bArr.length) { - i2 += (bArr[i] & 255) << (i * 8); - i++; - } - return i2; - } +// --Commented out by Inspection START (13.12.2019 г. 23:38): +// static int calculateLow(byte... bArr) { +// int i = 0; +// int i2 = 0; +// while (i < bArr.length) { +// i2 += (bArr[i] & 255) << (i * 8); +// i++; +// } +// return i2; +// } +// --Commented out by Inspection STOP (13.12.2019 г. 23:38) } }