mirror of
https://codeberg.org/Freeyourgadget/Gadgetbridge.git
synced 2025-01-10 17:11:56 +01:00
Allow DeviceService to target a specific device
This commit is contained in:
parent
226d75d366
commit
005276248f
@ -330,6 +330,16 @@ public class GBApplication extends Application {
|
|||||||
return deviceService;
|
return deviceService;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the facade for talking to a specific device. Devices are managed by
|
||||||
|
* an Android Service and this facade provides access to its functionality.
|
||||||
|
*
|
||||||
|
* @return the facade for talking to the service/device.
|
||||||
|
*/
|
||||||
|
public static DeviceService deviceService(GBDevice device) {
|
||||||
|
return deviceService.forDevice(device);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the DBHandler instance for reading/writing or throws GBException
|
* Returns the DBHandler instance for reading/writing or throws GBException
|
||||||
* when that was not successful
|
* when that was not successful
|
||||||
|
@ -129,7 +129,7 @@ public class SleepAlarmWidget extends AppWidgetProvider {
|
|||||||
Alarm alarm = AlarmUtils.createSingleShot(0, true, false, calendar);
|
Alarm alarm = AlarmUtils.createSingleShot(0, true, false, calendar);
|
||||||
ArrayList<Alarm> alarms = new ArrayList<>(1);
|
ArrayList<Alarm> alarms = new ArrayList<>(1);
|
||||||
alarms.add(alarm);
|
alarms.add(alarm);
|
||||||
GBApplication.deviceService().onSetAlarms(alarms);
|
GBApplication.deviceService(deviceForWidget).onSetAlarms(alarms);
|
||||||
|
|
||||||
// if (GBApplication.isRunningLollipopOrLater()) {
|
// if (GBApplication.isRunningLollipopOrLater()) {
|
||||||
// setAlarmViaAlarmManager(context, calendar.getTimeInMillis());
|
// setAlarmViaAlarmManager(context, calendar.getTimeInMillis());
|
||||||
|
@ -181,7 +181,7 @@ public class Widget extends AppWidgetProvider {
|
|||||||
GB.toast(context,
|
GB.toast(context,
|
||||||
context.getString(R.string.device_not_connected),
|
context.getString(R.string.device_not_connected),
|
||||||
Toast.LENGTH_SHORT, GB.ERROR);
|
Toast.LENGTH_SHORT, GB.ERROR);
|
||||||
GBApplication.deviceService().connect();
|
GBApplication.deviceService(deviceForWidget).connect();
|
||||||
GB.toast(context,
|
GB.toast(context,
|
||||||
context.getString(R.string.connecting),
|
context.getString(R.string.connecting),
|
||||||
Toast.LENGTH_SHORT, GB.INFO);
|
Toast.LENGTH_SHORT, GB.INFO);
|
||||||
@ -192,7 +192,7 @@ public class Widget extends AppWidgetProvider {
|
|||||||
context.getString(R.string.busy_task_fetch_activity_data),
|
context.getString(R.string.busy_task_fetch_activity_data),
|
||||||
Toast.LENGTH_SHORT, GB.INFO);
|
Toast.LENGTH_SHORT, GB.INFO);
|
||||||
|
|
||||||
GBApplication.deviceService().onFetchRecordedData(RecordedDataTypes.TYPE_ACTIVITY);
|
GBApplication.deviceService(deviceForWidget).onFetchRecordedData(RecordedDataTypes.TYPE_ACTIVITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateWidget() {
|
public void updateWidget() {
|
||||||
|
@ -369,7 +369,7 @@ public class ActivitySummariesActivity extends AbstractListActivity<BaseActivity
|
|||||||
|
|
||||||
private void fetchTrackData() {
|
private void fetchTrackData() {
|
||||||
if (mGBDevice.isInitialized() && !mGBDevice.isBusy()) {
|
if (mGBDevice.isInitialized() && !mGBDevice.isBusy()) {
|
||||||
GBApplication.deviceService().onFetchRecordedData(RecordedDataTypes.TYPE_GPS_TRACKS);
|
GBApplication.deviceService(mGBDevice).onFetchRecordedData(RecordedDataTypes.TYPE_GPS_TRACKS);
|
||||||
} else {
|
} else {
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
if (!mGBDevice.isInitialized()) {
|
if (!mGBDevice.isInitialized()) {
|
||||||
|
@ -173,7 +173,7 @@ public class ConfigureAlarms extends AbstractGBActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void sendAlarmsToDevice() {
|
private void sendAlarmsToDevice() {
|
||||||
GBApplication.deviceService().onSetAlarms(mGBAlarmListAdapter.getAlarmList());
|
GBApplication.deviceService(gbDevice).onSetAlarms(mGBAlarmListAdapter.getAlarmList());
|
||||||
}
|
}
|
||||||
|
|
||||||
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
private final BroadcastReceiver mReceiver = new BroadcastReceiver() {
|
||||||
|
@ -176,7 +176,7 @@ public class ConfigureReminders extends AbstractGBActivity {
|
|||||||
|
|
||||||
private void sendRemindersToDevice() {
|
private void sendRemindersToDevice() {
|
||||||
if (gbDevice.isInitialized()) {
|
if (gbDevice.isInitialized()) {
|
||||||
GBApplication.deviceService().onSetReminders(mGBReminderListAdapter.getReminderList());
|
GBApplication.deviceService(gbDevice).onSetReminders(mGBReminderListAdapter.getReminderList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -212,7 +212,7 @@ public class ConfigureWorldClocks extends AbstractGBActivity {
|
|||||||
|
|
||||||
private void sendWorldClocksToDevice() {
|
private void sendWorldClocksToDevice() {
|
||||||
if (gbDevice.isInitialized()) {
|
if (gbDevice.isInitialized()) {
|
||||||
GBApplication.deviceService().onSetWorldClocks(mGBWorldClockListAdapter.getWorldClockList());
|
GBApplication.deviceService(gbDevice).onSetWorldClocks(mGBWorldClockListAdapter.getWorldClockList());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -148,7 +148,7 @@ public class FwAppInstallerActivity extends AbstractGBActivity implements Instal
|
|||||||
|
|
||||||
private void connect() {
|
private void connect() {
|
||||||
mayConnect = false; // only do that once per #onCreate
|
mayConnect = false; // only do that once per #onCreate
|
||||||
GBApplication.deviceService().connect(device);
|
GBApplication.deviceService(device).connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void validateInstallation() {
|
private void validateInstallation() {
|
||||||
@ -200,7 +200,7 @@ public class FwAppInstallerActivity extends AbstractGBActivity implements Instal
|
|||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
setInstallEnabled(false);
|
setInstallEnabled(false);
|
||||||
installHandler.onStartInstall(device);
|
installHandler.onStartInstall(device);
|
||||||
GBApplication.deviceService().onInstallApp(uri);
|
GBApplication.deviceService(device).onInstallApp(uri);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -231,7 +231,7 @@ public class FwAppInstallerActivity extends AbstractGBActivity implements Instal
|
|||||||
if (device == null || !device.isConnected()) {
|
if (device == null || !device.isConnected()) {
|
||||||
connect();
|
connect();
|
||||||
} else {
|
} else {
|
||||||
GBApplication.deviceService().requestDeviceInfo();
|
GBApplication.deviceService(device).requestDeviceInfo();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ public class WidgetAlarmsActivity extends Activity implements View.OnClickListen
|
|||||||
Alarm alarm = AlarmUtils.createSingleShot(0, true, true, calendar);
|
Alarm alarm = AlarmUtils.createSingleShot(0, true, true, calendar);
|
||||||
ArrayList<Alarm> alarms = new ArrayList<>(1);
|
ArrayList<Alarm> alarms = new ArrayList<>(1);
|
||||||
alarms.add(alarm);
|
alarms.add(alarm);
|
||||||
GBApplication.deviceService().onSetAlarms(alarms);
|
GBApplication.deviceService(deviceForWidget).onSetAlarms(alarms);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -304,7 +304,7 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
|||||||
LocalBroadcastManager.getInstance(getContext()).registerReceiver(mReceiver, filter);
|
LocalBroadcastManager.getInstance(getContext()).registerReceiver(mReceiver, filter);
|
||||||
|
|
||||||
if (mCoordinator.supportsAppListFetching()) {
|
if (mCoordinator.supportsAppListFetching()) {
|
||||||
GBApplication.deviceService().onAppInfoReq();
|
GBApplication.deviceService(mGBDevice).onAppInfoReq();
|
||||||
if (isCacheManager()) {
|
if (isCacheManager()) {
|
||||||
refreshList();
|
refreshList();
|
||||||
}
|
}
|
||||||
@ -391,7 +391,7 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
|||||||
ArrayList<UUID> concatUuids = AppManagerActivity.getUuidsFromFile(concatFilename);
|
ArrayList<UUID> concatUuids = AppManagerActivity.getUuidsFromFile(concatFilename);
|
||||||
uuids.addAll(concatUuids);
|
uuids.addAll(concatUuids);
|
||||||
}
|
}
|
||||||
GBApplication.deviceService().onAppReorder(uuids.toArray(new UUID[uuids.size()]));
|
GBApplication.deviceService(mGBDevice).onAppReorder(uuids.toArray(new UUID[uuids.size()]));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onItemClick(View view, GBDeviceApp deviceApp) {
|
public void onItemClick(View view, GBDeviceApp deviceApp) {
|
||||||
@ -399,7 +399,7 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
|||||||
openPopupMenu(view, deviceApp);
|
openPopupMenu(view, deviceApp);
|
||||||
} else {
|
} else {
|
||||||
UUID uuid = deviceApp.getUUID();
|
UUID uuid = deviceApp.getUUID();
|
||||||
GBApplication.deviceService().onAppStart(uuid, true);
|
GBApplication.deviceService(mGBDevice).onAppStart(uuid, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -506,11 +506,11 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
|||||||
refreshIntent = new Intent(AbstractAppManagerFragment.ACTION_REFRESH_APPLIST);
|
refreshIntent = new Intent(AbstractAppManagerFragment.ACTION_REFRESH_APPLIST);
|
||||||
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(refreshIntent);
|
LocalBroadcastManager.getInstance(getContext()).sendBroadcast(refreshIntent);
|
||||||
}
|
}
|
||||||
GBApplication.deviceService().onAppDelete(selectedApp.getUUID());
|
GBApplication.deviceService(mGBDevice).onAppDelete(selectedApp.getUUID());
|
||||||
return true;
|
return true;
|
||||||
case R.id.appmanager_app_reinstall:
|
case R.id.appmanager_app_reinstall:
|
||||||
File cachePath = new File(appCacheDir, selectedApp.getUUID() + mCoordinator.getAppFileExtension());
|
File cachePath = new File(appCacheDir, selectedApp.getUUID() + mCoordinator.getAppFileExtension());
|
||||||
GBApplication.deviceService().onInstallApp(Uri.fromFile(cachePath));
|
GBApplication.deviceService(mGBDevice).onInstallApp(Uri.fromFile(cachePath));
|
||||||
return true;
|
return true;
|
||||||
case R.id.appmanager_app_share:
|
case R.id.appmanager_app_share:
|
||||||
File origFilePath = new File(appCacheDir, selectedApp.getUUID() + mCoordinator.getAppFileExtension());
|
File origFilePath = new File(appCacheDir, selectedApp.getUUID() + mCoordinator.getAppFileExtension());
|
||||||
@ -533,24 +533,24 @@ public abstract class AbstractAppManagerFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case R.id.appmanager_health_activate:
|
case R.id.appmanager_health_activate:
|
||||||
GBApplication.deviceService().onInstallApp(Uri.parse("fake://health"));
|
GBApplication.deviceService(mGBDevice).onInstallApp(Uri.parse("fake://health"));
|
||||||
return true;
|
return true;
|
||||||
case R.id.appmanager_hrm_activate:
|
case R.id.appmanager_hrm_activate:
|
||||||
GBApplication.deviceService().onInstallApp(Uri.parse("fake://hrm"));
|
GBApplication.deviceService(mGBDevice).onInstallApp(Uri.parse("fake://hrm"));
|
||||||
return true;
|
return true;
|
||||||
case R.id.appmanager_weather_activate:
|
case R.id.appmanager_weather_activate:
|
||||||
GBApplication.deviceService().onInstallApp(Uri.parse("fake://weather"));
|
GBApplication.deviceService(mGBDevice).onInstallApp(Uri.parse("fake://weather"));
|
||||||
return true;
|
return true;
|
||||||
case R.id.appmanager_health_deactivate:
|
case R.id.appmanager_health_deactivate:
|
||||||
case R.id.appmanager_hrm_deactivate:
|
case R.id.appmanager_hrm_deactivate:
|
||||||
case R.id.appmanager_weather_deactivate:
|
case R.id.appmanager_weather_deactivate:
|
||||||
GBApplication.deviceService().onAppDelete(selectedApp.getUUID());
|
GBApplication.deviceService(mGBDevice).onAppDelete(selectedApp.getUUID());
|
||||||
return true;
|
return true;
|
||||||
case R.id.appmanager_weather_install_provider:
|
case R.id.appmanager_weather_install_provider:
|
||||||
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://f-droid.org/app/ru.gelin.android.weather.notification")));
|
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://f-droid.org/app/ru.gelin.android.weather.notification")));
|
||||||
return true;
|
return true;
|
||||||
case R.id.appmanager_app_configure:
|
case R.id.appmanager_app_configure:
|
||||||
GBApplication.deviceService().onAppStart(selectedApp.getUUID(), true);
|
GBApplication.deviceService(mGBDevice).onAppStart(selectedApp.getUUID(), true);
|
||||||
|
|
||||||
Intent startIntent = new Intent(getContext().getApplicationContext(), ExternalPebbleJSActivity.class);
|
Intent startIntent = new Intent(getContext().getApplicationContext(), ExternalPebbleJSActivity.class);
|
||||||
startIntent.putExtra(DeviceService.EXTRA_APP_UUID, selectedApp.getUUID());
|
startIntent.putExtra(DeviceService.EXTRA_APP_UUID, selectedApp.getUUID());
|
||||||
|
@ -359,7 +359,7 @@ public class ChartsActivity extends AbstractGBFragmentActivity implements Charts
|
|||||||
|
|
||||||
private void fetchActivityData() {
|
private void fetchActivityData() {
|
||||||
if (getDevice().isInitialized()) {
|
if (getDevice().isInitialized()) {
|
||||||
GBApplication.deviceService().onFetchRecordedData(RecordedDataTypes.TYPE_ACTIVITY);
|
GBApplication.deviceService(getDevice()).onFetchRecordedData(RecordedDataTypes.TYPE_ACTIVITY);
|
||||||
} else {
|
} else {
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
GB.toast(this, getString(R.string.device_not_connected), Toast.LENGTH_SHORT, GB.ERROR);
|
GB.toast(this, getString(R.string.device_not_connected), Toast.LENGTH_SHORT, GB.ERROR);
|
||||||
|
@ -210,7 +210,7 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat imp
|
|||||||
invokeLater(new Runnable() {
|
invokeLater(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
GBApplication.deviceService().onSendConfiguration(preferenceKey);
|
GBApplication.deviceService(device).onSendConfiguration(preferenceKey);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -355,7 +355,7 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat imp
|
|||||||
enableHeartrateSleepSupport.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
enableHeartrateSleepSupport.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
public boolean onPreferenceChange(Preference preference, Object newVal) {
|
||||||
GBApplication.deviceService().onEnableHeartRateSleepSupport(Boolean.TRUE.equals(newVal));
|
GBApplication.deviceService(device).onEnableHeartRateSleepSupport(Boolean.TRUE.equals(newVal));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -369,7 +369,7 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat imp
|
|||||||
|
|
||||||
heartrateMeasurementInterval.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
heartrateMeasurementInterval.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
|
||||||
public boolean onPreferenceChange(final Preference preference, final Object newVal) {
|
public boolean onPreferenceChange(final Preference preference, final Object newVal) {
|
||||||
GBApplication.deviceService().onSetHeartRateMeasurementInterval(Integer.parseInt((String) newVal));
|
GBApplication.deviceService(device).onSetHeartRateMeasurementInterval(Integer.parseInt((String) newVal));
|
||||||
|
|
||||||
final boolean isMeasurementIntervalEnabled = !newVal.equals("0");
|
final boolean isMeasurementIntervalEnabled = !newVal.equals("0");
|
||||||
|
|
||||||
@ -720,7 +720,7 @@ public class DeviceSpecificSettingsFragment extends PreferenceFragmentCompat imp
|
|||||||
CannedMessagesSpec cannedMessagesSpec = new CannedMessagesSpec();
|
CannedMessagesSpec cannedMessagesSpec = new CannedMessagesSpec();
|
||||||
cannedMessagesSpec.type = CannedMessagesSpec.TYPE_REJECTEDCALLS;
|
cannedMessagesSpec.type = CannedMessagesSpec.TYPE_REJECTEDCALLS;
|
||||||
cannedMessagesSpec.cannedMessages = messages.toArray(new String[0]);
|
cannedMessagesSpec.cannedMessages = messages.toArray(new String[0]);
|
||||||
GBApplication.deviceService().onSetCannedMessages(cannedMessagesSpec);
|
GBApplication.deviceService(device).onSetCannedMessages(cannedMessagesSpec);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -285,7 +285,7 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
|
|||||||
showTransientSnackbar(R.string.controlcenter_snackbar_need_longpress);
|
showTransientSnackbar(R.string.controlcenter_snackbar_need_longpress);
|
||||||
} else {
|
} else {
|
||||||
showTransientSnackbar(R.string.controlcenter_snackbar_connecting);
|
showTransientSnackbar(R.string.controlcenter_snackbar_connecting);
|
||||||
GBApplication.deviceService().connect(device);
|
GBApplication.deviceService(device).connect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -391,7 +391,7 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
|
|||||||
holder.heartRateStatusBox.setOnClickListener(new View.OnClickListener() {
|
holder.heartRateStatusBox.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
GBApplication.deviceService().onHeartRateTest();
|
GBApplication.deviceService(device).onHeartRateTest();
|
||||||
HeartRateDialog dialog = new HeartRateDialog(context);
|
HeartRateDialog dialog = new HeartRateDialog(context);
|
||||||
dialog.show();
|
dialog.show();
|
||||||
}
|
}
|
||||||
@ -422,7 +422,7 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
showTransientSnackbar(R.string.busy_task_fetch_activity_data);
|
showTransientSnackbar(R.string.busy_task_fetch_activity_data);
|
||||||
GBApplication.deviceService().onFetchRecordedData(RecordedDataTypes.TYPE_ACTIVITY);
|
GBApplication.deviceService(device).onFetchRecordedData(RecordedDataTypes.TYPE_ACTIVITY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -436,7 +436,7 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
showTransientSnackbar(R.string.controlcenter_snackbar_requested_screenshot);
|
showTransientSnackbar(R.string.controlcenter_snackbar_requested_screenshot);
|
||||||
GBApplication.deviceService().onScreenshotReq();
|
GBApplication.deviceService(device).onScreenshotReq();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -556,16 +556,16 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
|
|||||||
context.startActivity(startIntent);
|
context.startActivity(startIntent);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
GBApplication.deviceService().onFindDevice(true);
|
GBApplication.deviceService(device).onFindDevice(true);
|
||||||
Snackbar.make(parent, R.string.control_center_find_lost_device, Snackbar.LENGTH_INDEFINITE).setAction(R.string.find_lost_device_you_found_it, new View.OnClickListener() {
|
Snackbar.make(parent, R.string.control_center_find_lost_device, Snackbar.LENGTH_INDEFINITE).setAction(R.string.find_lost_device_you_found_it, new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
GBApplication.deviceService().onFindDevice(false);
|
GBApplication.deviceService(device).onFindDevice(false);
|
||||||
}
|
}
|
||||||
}).setCallback(new Snackbar.Callback() {
|
}).setCallback(new Snackbar.Callback() {
|
||||||
@Override
|
@Override
|
||||||
public void onDismissed(Snackbar snackbar, int event) {
|
public void onDismissed(Snackbar snackbar, int event) {
|
||||||
GBApplication.deviceService().onFindDevice(false);
|
GBApplication.deviceService(device).onFindDevice(false);
|
||||||
super.onDismissed(snackbar, event);
|
super.onDismissed(snackbar, event);
|
||||||
}
|
}
|
||||||
}).show();
|
}).show();
|
||||||
@ -673,7 +673,7 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
|
|||||||
final float frequency = fm_presets[index];
|
final float frequency = fm_presets[index];
|
||||||
device.setExtraInfo("fm_frequency", fm_presets[index]);
|
device.setExtraInfo("fm_frequency", fm_presets[index]);
|
||||||
fmFrequencyLabel.setText(String.format(Locale.getDefault(), "%.1f", (float) frequency));
|
fmFrequencyLabel.setText(String.format(Locale.getDefault(), "%.1f", (float) frequency));
|
||||||
GBApplication.deviceService().onSetFmFrequency(frequency);
|
GBApplication.deviceService(device).onSetFmFrequency(frequency);
|
||||||
alert[0].dismiss();
|
alert[0].dismiss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -719,7 +719,7 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
|
|||||||
} else {
|
} else {
|
||||||
device.setExtraInfo("fm_frequency", frequency);
|
device.setExtraInfo("fm_frequency", frequency);
|
||||||
fmFrequencyLabel.setText(String.format(Locale.getDefault(), "%.1f", frequency));
|
fmFrequencyLabel.setText(String.format(Locale.getDefault(), "%.1f", frequency));
|
||||||
GBApplication.deviceService().onSetFmFrequency(frequency);
|
GBApplication.deviceService(device).onSetFmFrequency(frequency);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -771,7 +771,7 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
|
|||||||
public void onColorSelected(int dialogId, int color) {
|
public void onColorSelected(int dialogId, int color) {
|
||||||
ledColor.setColor(color);
|
ledColor.setColor(color);
|
||||||
device.setExtraInfo("led_color", color);
|
device.setExtraInfo("led_color", color);
|
||||||
GBApplication.deviceService().onSetLedColor(color);
|
GBApplication.deviceService(device).onSetLedColor(color);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -796,7 +796,7 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
|
|||||||
.setIcon(R.drawable.ic_power_settings_new)
|
.setIcon(R.drawable.ic_power_settings_new)
|
||||||
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
||||||
public void onClick(final DialogInterface dialog, final int whichButton) {
|
public void onClick(final DialogInterface dialog, final int whichButton) {
|
||||||
GBApplication.deviceService().onPowerOff();
|
GBApplication.deviceService(device).onPowerOff();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.setNegativeButton(android.R.string.no, null)
|
.setNegativeButton(android.R.string.no, null)
|
||||||
@ -840,13 +840,13 @@ public class GBDeviceAdapterv2 extends ListAdapter<GBDevice, GBDeviceAdapterv2.V
|
|||||||
case R.id.controlcenter_device_submenu_connect:
|
case R.id.controlcenter_device_submenu_connect:
|
||||||
if (device.getState() != GBDevice.State.CONNECTED) {
|
if (device.getState() != GBDevice.State.CONNECTED) {
|
||||||
showTransientSnackbar(R.string.controlcenter_snackbar_connecting);
|
showTransientSnackbar(R.string.controlcenter_snackbar_connecting);
|
||||||
GBApplication.deviceService().connect(device);
|
GBApplication.deviceService(device).connect();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case R.id.controlcenter_device_submenu_disconnect:
|
case R.id.controlcenter_device_submenu_disconnect:
|
||||||
if (device.getState() != GBDevice.State.NOT_CONNECTED) {
|
if (device.getState() != GBDevice.State.NOT_CONNECTED) {
|
||||||
showTransientSnackbar(R.string.controlcenter_snackbar_disconnecting);
|
showTransientSnackbar(R.string.controlcenter_snackbar_disconnecting);
|
||||||
GBApplication.deviceService().disconnect(device);
|
GBApplication.deviceService(device).disconnect();
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
case R.id.controlcenter_device_submenu_set_alias:
|
case R.id.controlcenter_device_submenu_set_alias:
|
||||||
|
@ -94,7 +94,7 @@ public abstract class AbstractDeviceCoordinator implements DeviceCoordinator {
|
|||||||
public void deleteDevice(final GBDevice gbDevice) throws GBException {
|
public void deleteDevice(final GBDevice gbDevice) throws GBException {
|
||||||
LOG.info("will try to delete device: " + gbDevice.getName());
|
LOG.info("will try to delete device: " + gbDevice.getName());
|
||||||
if (gbDevice.isConnected() || gbDevice.isConnecting()) {
|
if (gbDevice.isConnected() || gbDevice.isConnecting()) {
|
||||||
GBApplication.deviceService().disconnect(gbDevice);
|
GBApplication.deviceService(gbDevice).disconnect();
|
||||||
}
|
}
|
||||||
Prefs prefs = getPrefs();
|
Prefs prefs = getPrefs();
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ public class HuamiSettingsCustomizer implements DeviceSpecificSettingsCustomizer
|
|||||||
tryPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
tryPref.setOnPreferenceClickListener(new Preference.OnPreferenceClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onPreferenceClick(final Preference preference) {
|
public boolean onPreferenceClick(final Preference preference) {
|
||||||
GBApplication.deviceService().onSendConfiguration(tryPrefKey);
|
GBApplication.deviceService(device).onSendConfiguration(tryPrefKey);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -588,11 +588,11 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
|
|||||||
final Uri tempAppFileUri = Uri.fromFile(tempFile);
|
final Uri tempAppFileUri = Uri.fromFile(tempFile);
|
||||||
if (preview) {
|
if (preview) {
|
||||||
findViewById(R.id.watchface_upload_progress_bar).setVisibility(View.VISIBLE);
|
findViewById(R.id.watchface_upload_progress_bar).setVisibility(View.VISIBLE);
|
||||||
GBApplication.deviceService().onInstallApp(tempAppFileUri);
|
GBApplication.deviceService(mGBDevice).onInstallApp(tempAppFileUri);
|
||||||
new Handler().postDelayed(new Runnable() {
|
new Handler().postDelayed(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
GBApplication.deviceService().onAppDelete(UUID.nameUUIDFromBytes("previewWatchface".getBytes(StandardCharsets.UTF_8)));
|
GBApplication.deviceService(mGBDevice).onAppDelete(UUID.nameUUIDFromBytes("previewWatchface".getBytes(StandardCharsets.UTF_8)));
|
||||||
}
|
}
|
||||||
}, 15000);
|
}, 15000);
|
||||||
} else {
|
} else {
|
||||||
@ -609,14 +609,14 @@ public class HybridHRWatchfaceDesignerActivity extends AbstractGBActivity implem
|
|||||||
@Override
|
@Override
|
||||||
public void onClick(DialogInterface dialog, int which) {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
findViewById(R.id.watchface_upload_progress_bar).setVisibility(View.VISIBLE);
|
findViewById(R.id.watchface_upload_progress_bar).setVisibility(View.VISIBLE);
|
||||||
GBApplication.deviceService().onInstallApp(tempAppFileUri);
|
GBApplication.deviceService(mGBDevice).onInstallApp(tempAppFileUri);
|
||||||
FossilHRInstallHandler.saveAppInCache(fossilFile, selectedBackgroundImage, wfFactory.getPreviewImage(mContext), mCoordinator, HybridHRWatchfaceDesignerActivity.this);
|
FossilHRInstallHandler.saveAppInCache(fossilFile, selectedBackgroundImage, wfFactory.getPreviewImage(mContext), mCoordinator, HybridHRWatchfaceDesignerActivity.this);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.show();
|
.show();
|
||||||
} else {
|
} else {
|
||||||
findViewById(R.id.watchface_upload_progress_bar).setVisibility(View.VISIBLE);
|
findViewById(R.id.watchface_upload_progress_bar).setVisibility(View.VISIBLE);
|
||||||
GBApplication.deviceService().onInstallApp(tempAppFileUri);
|
GBApplication.deviceService(mGBDevice).onInstallApp(tempAppFileUri);
|
||||||
FossilHRInstallHandler.saveAppInCache(fossilFile, selectedBackgroundImage, wfFactory.getPreviewImage(mContext), mCoordinator, HybridHRWatchfaceDesignerActivity.this);
|
FossilHRInstallHandler.saveAppInCache(fossilFile, selectedBackgroundImage, wfFactory.getPreviewImage(mContext), mCoordinator, HybridHRWatchfaceDesignerActivity.this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,7 +64,7 @@ public class BluetoothConnectReceiver extends BroadcastReceiver {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
LOG.info("Will re-connect to " + gbDevice.getAddress() + "(" + gbDevice.getName() + ")");
|
LOG.info("Will re-connect to " + gbDevice.getAddress() + "(" + gbDevice.getName() + ")");
|
||||||
GBApplication.deviceService().connect(gbDevice);
|
GBApplication.deviceService(gbDevice).connect();
|
||||||
}
|
}
|
||||||
|
|
||||||
private GBDevice getKnownDeviceByAddressOrNull(String deviceAddress){
|
private GBDevice getKnownDeviceByAddressOrNull(String deviceAddress){
|
||||||
|
@ -200,15 +200,15 @@ public class CalendarReceiver extends BroadcastReceiver {
|
|||||||
calendarEventSpec.location = calendarEvent.getLocation();
|
calendarEventSpec.location = calendarEvent.getLocation();
|
||||||
calendarEventSpec.type = CalendarEventSpec.TYPE_UNKNOWN;
|
calendarEventSpec.type = CalendarEventSpec.TYPE_UNKNOWN;
|
||||||
if (syncState == EventState.NEEDS_UPDATE) {
|
if (syncState == EventState.NEEDS_UPDATE) {
|
||||||
GBApplication.deviceService().onDeleteCalendarEvent(CalendarEventSpec.TYPE_UNKNOWN, i);
|
GBApplication.deviceService(mGBDevice).onDeleteCalendarEvent(CalendarEventSpec.TYPE_UNKNOWN, i);
|
||||||
}
|
}
|
||||||
GBApplication.deviceService().onAddCalendarEvent(calendarEventSpec);
|
GBApplication.deviceService(mGBDevice).onAddCalendarEvent(calendarEventSpec);
|
||||||
es.setState(EventState.SYNCED);
|
es.setState(EventState.SYNCED);
|
||||||
eventState.put(i, es);
|
eventState.put(i, es);
|
||||||
// update db
|
// update db
|
||||||
session.insertOrReplace(new CalendarSyncState(null, deviceId, i, es.event.hashCode()));
|
session.insertOrReplace(new CalendarSyncState(null, deviceId, i, es.event.hashCode()));
|
||||||
} else if (syncState == EventState.NEEDS_DELETE) {
|
} else if (syncState == EventState.NEEDS_DELETE) {
|
||||||
GBApplication.deviceService().onDeleteCalendarEvent(CalendarEventSpec.TYPE_UNKNOWN, i);
|
GBApplication.deviceService(mGBDevice).onDeleteCalendarEvent(CalendarEventSpec.TYPE_UNKNOWN, i);
|
||||||
eventState.remove(i);
|
eventState.remove(i);
|
||||||
// delete from db for current device only
|
// delete from db for current device only
|
||||||
QueryBuilder<CalendarSyncState> qb = session.getCalendarSyncStateDao().queryBuilder();
|
QueryBuilder<CalendarSyncState> qb = session.getCalendarSyncStateDao().queryBuilder();
|
||||||
|
@ -53,6 +53,7 @@ import static nodomain.freeyourgadget.gadgetbridge.util.JavaExtensions.coalesce;
|
|||||||
|
|
||||||
public class GBDeviceService implements DeviceService {
|
public class GBDeviceService implements DeviceService {
|
||||||
protected final Context mContext;
|
protected final Context mContext;
|
||||||
|
private final GBDevice mDevice;
|
||||||
private final Class<? extends Service> mServiceClass;
|
private final Class<? extends Service> mServiceClass;
|
||||||
public static final String[] transliterationExtras = new String[]{
|
public static final String[] transliterationExtras = new String[]{
|
||||||
EXTRA_NOTIFICATION_SENDER,
|
EXTRA_NOTIFICATION_SENDER,
|
||||||
@ -69,10 +70,20 @@ public class GBDeviceService implements DeviceService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
public GBDeviceService(Context context) {
|
public GBDeviceService(Context context) {
|
||||||
|
this(context, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GBDeviceService(Context context, GBDevice device) {
|
||||||
mContext = context;
|
mContext = context;
|
||||||
|
mDevice = device;
|
||||||
mServiceClass = DeviceCommunicationService.class;
|
mServiceClass = DeviceCommunicationService.class;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public DeviceService forDevice(final GBDevice device) {
|
||||||
|
return new GBDeviceService(mContext, device);
|
||||||
|
}
|
||||||
|
|
||||||
protected Intent createIntent() {
|
protected Intent createIntent() {
|
||||||
return new Intent(mContext, mServiceClass);
|
return new Intent(mContext, mServiceClass);
|
||||||
}
|
}
|
||||||
@ -87,6 +98,10 @@ public class GBDeviceService implements DeviceService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mDevice != null) {
|
||||||
|
intent.putExtra(GBDevice.EXTRA_DEVICE, mDevice);
|
||||||
|
}
|
||||||
|
|
||||||
mContext.startService(intent);
|
mContext.startService(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -102,29 +117,16 @@ public class GBDeviceService implements DeviceService {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connect() {
|
public void connect() {
|
||||||
connect(null, false);
|
connect(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void connect(@Nullable GBDevice device) {
|
public void connect(boolean firstTime) {
|
||||||
connect(device, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void connect(@Nullable GBDevice device, boolean firstTime) {
|
|
||||||
Intent intent = createIntent().setAction(ACTION_CONNECT)
|
Intent intent = createIntent().setAction(ACTION_CONNECT)
|
||||||
.putExtra(GBDevice.EXTRA_DEVICE, device)
|
|
||||||
.putExtra(EXTRA_CONNECT_FIRST_TIME, firstTime);
|
.putExtra(EXTRA_CONNECT_FIRST_TIME, firstTime);
|
||||||
invokeService(intent);
|
invokeService(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void disconnect(@Nullable GBDevice device) {
|
|
||||||
Intent intent = createIntent().setAction(ACTION_DISCONNECT)
|
|
||||||
.putExtra(GBDevice.EXTRA_DEVICE, device);
|
|
||||||
invokeService(intent);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void disconnect() {
|
public void disconnect() {
|
||||||
Intent intent = createIntent().setAction(ACTION_DISCONNECT);
|
Intent intent = createIntent().setAction(ACTION_DISCONNECT);
|
||||||
|
@ -150,16 +150,14 @@ public interface DeviceService extends EventHandler {
|
|||||||
|
|
||||||
void connect();
|
void connect();
|
||||||
|
|
||||||
void connect(@Nullable GBDevice device);
|
void connect(boolean firstTime);
|
||||||
|
|
||||||
void connect(@Nullable GBDevice device, boolean firstTime);
|
|
||||||
|
|
||||||
void disconnect(@Nullable GBDevice device);
|
|
||||||
|
|
||||||
void disconnect();
|
void disconnect();
|
||||||
|
|
||||||
void quit();
|
void quit();
|
||||||
|
|
||||||
|
DeviceService forDevice(GBDevice device);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Requests information from the {@link DeviceCommunicationService} about the connection state,
|
* Requests information from the {@link DeviceCommunicationService} about the connection state,
|
||||||
* firmware info, etc.
|
* firmware info, etc.
|
||||||
|
@ -82,7 +82,7 @@ public class AutoConnectIntervalReceiver extends BroadcastReceiver {
|
|||||||
for(GBDevice device : devices){
|
for(GBDevice device : devices){
|
||||||
if(device.getState() == GBDevice.State.WAITING_FOR_RECONNECT) {
|
if(device.getState() == GBDevice.State.WAITING_FOR_RECONNECT) {
|
||||||
LOG.info("Will re-connect to " + device.getAddress() + "(" + device.getName() + ")");
|
LOG.info("Will re-connect to " + device.getAddress() + "(" + device.getName() + ")");
|
||||||
GBApplication.deviceService().connect(device);
|
GBApplication.deviceService(device).connect();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -147,7 +147,7 @@ public class BondingUtil {
|
|||||||
*/
|
*/
|
||||||
private static void connectToGBDevice(GBDevice device) {
|
private static void connectToGBDevice(GBDevice device) {
|
||||||
if (device != null) {
|
if (device != null) {
|
||||||
GBApplication.deviceService().connect(device, true);
|
GBApplication.deviceService(device).connect(true);
|
||||||
} else {
|
} else {
|
||||||
GB.toast("Unable to connect, can't recognize the device type", Toast.LENGTH_LONG, GB.ERROR);
|
GB.toast("Unable to connect, can't recognize the device type", Toast.LENGTH_LONG, GB.ERROR);
|
||||||
}
|
}
|
||||||
@ -180,8 +180,8 @@ public class BondingUtil {
|
|||||||
public static void connectThenComplete(BondingInterface bondingInterface, GBDevice device) {
|
public static void connectThenComplete(BondingInterface bondingInterface, GBDevice device) {
|
||||||
toast(bondingInterface.getContext(), bondingInterface.getContext().getString(R.string.discovery_trying_to_connect_to, device.getName()), Toast.LENGTH_SHORT, GB.INFO);
|
toast(bondingInterface.getContext(), bondingInterface.getContext().getString(R.string.discovery_trying_to_connect_to, device.getName()), Toast.LENGTH_SHORT, GB.INFO);
|
||||||
// Disconnect when LE Pebble so that the user can manually initiate a connection
|
// Disconnect when LE Pebble so that the user can manually initiate a connection
|
||||||
GBApplication.deviceService().disconnect(device);
|
GBApplication.deviceService(device).disconnect();
|
||||||
GBApplication.deviceService().connect(device, true);
|
GBApplication.deviceService(device).connect(true);
|
||||||
bondingInterface.onBondingComplete(true);
|
bondingInterface.onBondingComplete(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user