use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone in project Gadgetbridge by Freeyourgadget.
the class CasioGBX100DeviceSupport method onReverseFindDevice.
private void onReverseFindDevice(boolean start) {
if (start) {
SharedPreferences sharedPreferences = GBApplication.getDeviceSpecificSharedPrefs(getDevice().getAddress());
String findPhone = sharedPreferences.getString(PREF_FIND_PHONE_ENABLED, getContext().getString(R.string.p_off));
if (findPhone.equals(getContext().getString(R.string.p_off)))
return;
GBDeviceEventFindPhone findPhoneEvent = new GBDeviceEventFindPhone();
findPhoneEvent.event = GBDeviceEventFindPhone.Event.START;
evaluateGBDeviceEvent(findPhoneEvent);
if (!findPhone.equals(getContext().getString(R.string.p_on))) {
String duration = sharedPreferences.getString(MakibesHR3Constants.PREF_FIND_PHONE_DURATION, "0");
try {
int iDuration;
try {
iDuration = Integer.parseInt(duration);
} catch (Exception ex) {
LOG.warn(ex.getMessage());
iDuration = 60;
}
if (iDuration > 0) {
this.mFindPhoneHandler.postDelayed(new Runnable() {
@Override
public void run() {
onReverseFindDevice(false);
}
}, iDuration * 1000);
}
} catch (Exception e) {
LOG.error("Unexpected exception in MiBand2Coordinator.getTime: " + e.getMessage());
}
}
} else {
// Always send stop, ignore preferences.
GBDeviceEventFindPhone findPhoneEvent = new GBDeviceEventFindPhone();
findPhoneEvent.event = GBDeviceEventFindPhone.Event.STOP;
evaluateGBDeviceEvent(findPhoneEvent);
}
}
use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone in project Gadgetbridge by Freeyourgadget.
the class AppMessageHandlerGBPebble method handleMessage.
@Override
public GBDeviceEvent[] handleMessage(ArrayList<Pair<Integer, Object>> pairs) {
GBDeviceEventFindPhone gbDeviceEventFindPhone = null;
for (Pair<Integer, Object> pair : pairs) {
switch(pair.first) {
case KEY_FIND_PHONE_START:
LOG.info("find phone start");
gbDeviceEventFindPhone = new GBDeviceEventFindPhone();
gbDeviceEventFindPhone.event = GBDeviceEventFindPhone.Event.START;
break;
case KEY_FIND_PHONE_STOP:
LOG.info("find phone stop");
gbDeviceEventFindPhone = new GBDeviceEventFindPhone();
gbDeviceEventFindPhone.event = GBDeviceEventFindPhone.Event.STOP;
break;
default:
LOG.info("unhandled key: " + pair.first);
break;
}
}
// always ack
GBDeviceEventSendBytes sendBytesAck = new GBDeviceEventSendBytes();
sendBytesAck.encodedBytes = mPebbleProtocol.encodeApplicationMessageAck(mUUID, mPebbleProtocol.last_id);
return new GBDeviceEvent[] { sendBytesAck, gbDeviceEventFindPhone };
}
use of nodomain.freeyourgadget.gadgetbridge.deviceevents.GBDeviceEventFindPhone in project Gadgetbridge by Freeyourgadget.
the class MakibesHR3DeviceSupport method onReverseFindDevice.
private void onReverseFindDevice(boolean start) {
if (start) {
SharedPreferences sharedPreferences = GBApplication.getDeviceSpecificSharedPrefs(this.getDevice().getAddress());
int findPhone = MakibesHR3Coordinator.getFindPhone(sharedPreferences);
if (findPhone != MakibesHR3Coordinator.FindPhone_OFF) {
GBDeviceEventFindPhone findPhoneEvent = new GBDeviceEventFindPhone();
findPhoneEvent.event = GBDeviceEventFindPhone.Event.START;
evaluateGBDeviceEvent(findPhoneEvent);
if (findPhone > 0) {
this.mFindPhoneHandler.postDelayed(new Runnable() {
@Override
public void run() {
onReverseFindDevice(false);
}
}, findPhone * 1000);
}
}
} else {
// Always send stop, ignore preferences.
GBDeviceEventFindPhone findPhoneEvent = new GBDeviceEventFindPhone();
findPhoneEvent.event = GBDeviceEventFindPhone.Event.STOP;
evaluateGBDeviceEvent(findPhoneEvent);
}
}
Aggregations