Search in sources :

Example 1 with ButtonConfiguration

use of nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.buttons.ButtonConfiguration 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);
    }
}
Also used : ButtonConfigurationPutRequest(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.buttons.ButtonConfigurationPutRequest) SharedPreferences(android.content.SharedPreferences) CommuteConfigPutRequest(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.commute.CommuteConfigPutRequest) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) ButtonConfiguration(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.buttons.ButtonConfiguration) JSONException(org.json.JSONException) Paint(android.graphics.Paint) Version(nodomain.freeyourgadget.gadgetbridge.util.Version) ApplicationInformation(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.application.ApplicationInformation)

Aggregations

SharedPreferences (android.content.SharedPreferences)1 Paint (android.graphics.Paint)1 ArrayList (java.util.ArrayList)1 ApplicationInformation (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.application.ApplicationInformation)1 ButtonConfiguration (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.buttons.ButtonConfiguration)1 ButtonConfigurationPutRequest (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.buttons.ButtonConfigurationPutRequest)1 CommuteConfigPutRequest (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.commute.CommuteConfigPutRequest)1 Version (nodomain.freeyourgadget.gadgetbridge.util.Version)1 JSONArray (org.json.JSONArray)1 JSONException (org.json.JSONException)1