use of nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.buttons.ButtonConfigurationPutRequest in project Gadgetbridge by Freeyourgadget.
the class FossilHRWatchAdapter method overwriteButtons.
@Override
public void overwriteButtons(String jsonConfigString) {
try {
SharedPreferences prefs = getDeviceSpecificPreferences();
String singlePressEvent = "short_press_release";
Version firmwareVersion = getCleanFWVersion();
if (firmwareVersion != null && firmwareVersion.compareTo(new Version("1.0.2.19")) < 0) {
singlePressEvent = "single_click";
}
ArrayList<ButtonConfiguration> configs = new ArrayList<>(5);
configs.add(new ButtonConfiguration("top_" + singlePressEvent, prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_1_FUNCTION_SHORT, "weatherApp")));
configs.add(new ButtonConfiguration("top_hold", prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_1_FUNCTION_LONG, "weatherApp")));
// configs.add(new ButtonConfiguration("top_double_click", prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_1_FUNCTION_DOUBLE, "weatherApp")));
configs.add(new ButtonConfiguration("middle_" + singlePressEvent, prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_2_FUNCTION_SHORT, "commuteApp")));
// configs.add(new ButtonConfiguration("middle_hold", prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_2_FUNCTION_LONG, "commuteApp")));
// configs.add(new ButtonConfiguration("middle_double_click", prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_2_FUNCTION_DOUBLE, "commuteApp")));
configs.add(new ButtonConfiguration("bottom_" + singlePressEvent, prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_3_FUNCTION_SHORT, "musicApp")));
configs.add(new ButtonConfiguration("bottom_hold", prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_3_FUNCTION_LONG, "musicApp")));
// configs.add(new ButtonConfiguration("bottom_double_click", prefs.getString(DeviceSettingsPreferenceConst.PREF_BUTTON_3_FUNCTION_DOUBLE, "musicApp")));
// filter out all apps not installed on watch
ArrayList<ButtonConfiguration> availableConfigs = new ArrayList<>();
outerLoop: for (ButtonConfiguration config : configs) {
for (ApplicationInformation installedApp : installedApplications) {
if (installedApp.getAppName().equals(config.getAction())) {
availableConfigs.add(config);
continue outerLoop;
}
}
}
queueWrite(new ButtonConfigurationPutRequest(availableConfigs.toArray(new ButtonConfiguration[0]), this));
for (ApplicationInformation info : installedApplications) {
if (info.getAppName().equals("commuteApp")) {
JSONArray jsonArray = new JSONArray(GBApplication.getPrefs().getString(CommuteActionsActivity.CONFIG_KEY_Q_ACTIONS, "[]"));
String[] menuItems = new String[jsonArray.length()];
for (int i = 0; i < jsonArray.length(); i++) menuItems[i] = jsonArray.getString(i);
queueWrite(new CommuteConfigPutRequest(menuItems, this));
break;
}
}
} catch (JSONException e) {
LOG.error("Error while configuring buttons", e);
}
}
Aggregations