Search in sources :

Example 6 with CustomWidget

use of nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.CustomWidget in project Gadgetbridge by Freeyourgadget.

the class FossilHRWatchAdapter method uploadWidgets.

private void uploadWidgets() {
    ArrayList<Widget> systemWidgets = new ArrayList<>(widgets.size());
    for (Widget widget : widgets) {
        if (!(widget instanceof CustomWidget) && !widget.getWidgetType().isCustom())
            systemWidgets.add(widget);
    }
    queueWrite(new WidgetsPutRequest(systemWidgets.toArray(new Widget[0]), this));
}
Also used : CustomWidget(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.CustomWidget) Widget(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.Widget) ArrayList(java.util.ArrayList) WidgetsPutRequest(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.WidgetsPutRequest) CustomWidget(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.CustomWidget)

Example 7 with CustomWidget

use of nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.CustomWidget in project Gadgetbridge by Freeyourgadget.

the class HRConfigActivity method saveCustomWidgetList.

private void saveCustomWidgetList() {
    try {
        JSONArray widgetArray = new JSONArray();
        for (CustomWidget widget : customWidgets) {
            JSONArray elementArray = new JSONArray();
            for (CustomWidgetElement element : widget.getElements()) {
                JSONObject elementObject = new JSONObject();
                elementObject.put("type", element.getWidgetElementType().getJsonIdentifier()).put("id", element.getId()).put("value", element.getValue()).put("x", element.getX()).put("y", element.getY());
                elementArray.put(elementObject);
            }
            JSONObject widgetObject = new JSONObject();
            widgetObject.put("name", widget.getName()).put("elements", elementArray);
            widgetArray.put(widgetObject);
        }
        sharedPreferences.edit().putString("QHYBRID_CUSTOM_WIDGETS", widgetArray.toString()).apply();
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
Also used : CustomWidgetElement(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.CustomWidgetElement) JSONObject(org.json.JSONObject) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) CustomWidget(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.CustomWidget)

Example 8 with CustomWidget

use of nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.CustomWidget in project Gadgetbridge by Freeyourgadget.

the class HRConfigActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_qhybrid_hr_settings);
    sharedPreferences = GBApplication.getPrefs().getPreferences();
    initMappings();
    loadWidgetConfigs();
    final ListView widgetListView = findViewById(R.id.qhybrid_widget_list);
    widgetListAdapter = new WidgetListAdapter(customWidgets);
    widgetListView.setAdapter(widgetListAdapter);
    widgetListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            Widget widget = widgetListAdapter.getItem(position);
            Intent startIntent = new Intent(HRConfigActivity.this, WidgetSettingsActivity.class);
            startIntent.putExtra("EXTRA_WIDGET", widget);
            startIntent.putExtra("EXTRA_WIDGET_IDNEX", position);
            startIntent.putExtra("EXTRA_WIDGET_INITIAL_NAME", ((CustomWidget) widget).getName());
            startActivityForResult(startIntent, REQUEST_CODE_WIDGET_EDIT);
        }
    });
    loadCustomWidgetList();
    findViewById(R.id.qhybrid_widget_add).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent startIntent = new Intent(HRConfigActivity.this, WidgetSettingsActivity.class);
            startActivityForResult(startIntent, REQUEST_CODE_WIDGET_EDIT);
        }
    });
    findViewById(R.id.qhybrid_set_background).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            new AlertDialog.Builder(HRConfigActivity.this).setTitle("whoop whoop").setMessage("background has to be pushed every time a custom widget changes, causing traffic and battery drain. Consider that when using custom widgets.").setPositiveButton("ok", new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialogInterface, int i) {
                    Intent pickIntent = new Intent(Intent.ACTION_PICK);
                    pickIntent.setType("image/*");
                    startActivityForResult(pickIntent, REQUEST_CODE_IMAGE_PICK);
                }
            }).setNegativeButton("nah", null).show();
        }
    });
    findViewById(R.id.qhybrid_unset_background).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            Intent intent = new Intent(QHybridSupport.QHYBRID_COMMAND_SET_BACKGROUND_IMAGE);
            intent.putIntegerArrayListExtra("EXTRA_PIXELS", null);
            LocalBroadcastManager.getInstance(HRConfigActivity.this).sendBroadcast(intent);
        }
    });
    for (int i = 0; i < widgetButtonsMapping.size(); i++) {
        final int widgetButtonId = widgetButtonsMapping.keyAt(i);
        findViewById(widgetButtonId).setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Widget.WidgetType[] types = Widget.WidgetType.values();
                final ArrayList<String> names = new ArrayList<>(types.length);
                for (Widget.WidgetType type : types) {
                    names.add(getResources().getString(type.getStringResource()));
                }
                for (CustomWidget customWidget : customWidgets) {
                    names.add(customWidget.getName());
                }
                final String[] nameStrings = names.toArray(new String[0]);
                new AlertDialog.Builder(HRConfigActivity.this).setItems(nameStrings, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        saveWidgetSetting(widgetButtonId, which, nameStrings);
                    }
                }).show();
            }
        });
    }
    // Disable some functions on watches with too new firmware (from official app 4.6.0 and higher)
    String fwVersion_str = GBApplication.app().getDeviceManager().getSelectedDevice().getFirmwareVersion();
    fwVersion_str = fwVersion_str.replaceFirst("^DN", "").replaceFirst("r\\.v.*", "");
    Version fwVersion = new Version(fwVersion_str);
    if (fwVersion.compareTo(new Version("1.0.2.20")) >= 0) {
        findViewById(R.id.qhybrid_widget_add).setEnabled(false);
        for (int i = 0; i < widgetButtonsMapping.size(); i++) {
            final int widgetButtonId = widgetButtonsMapping.keyAt(i);
            findViewById(widgetButtonId).setEnabled(false);
        }
        findViewById(R.id.qhybrid_set_background).setEnabled(false);
        findViewById(R.id.qhybrid_unset_background).setEnabled(false);
        GB.toast(getString(R.string.fossil_hr_warning_firmware_too_new), Toast.LENGTH_LONG, GB.INFO);
    }
}
Also used : AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Widget(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.Widget) CustomWidget(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.CustomWidget) ArrayList(java.util.ArrayList) ListView(android.widget.ListView) Version(nodomain.freeyourgadget.gadgetbridge.util.Version) Intent(android.content.Intent) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) CustomWidget(nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.CustomWidget) AdapterView(android.widget.AdapterView)

Aggregations

CustomWidget (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.CustomWidget)8 Widget (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.Widget)4 Intent (android.content.Intent)3 ArrayList (java.util.ArrayList)3 CustomWidgetElement (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.CustomWidgetElement)3 Version (nodomain.freeyourgadget.gadgetbridge.util.Version)3 JSONArray (org.json.JSONArray)3 JSONException (org.json.JSONException)3 JSONObject (org.json.JSONObject)3 Paint (android.graphics.Paint)2 View (android.view.View)2 AdapterView (android.widget.AdapterView)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 CustomBackgroundWidgetElement (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.CustomBackgroundWidgetElement)2 CustomTextWidgetElement (nodomain.freeyourgadget.gadgetbridge.service.devices.qhybrid.requests.fossil_hr.widget.CustomTextWidgetElement)2 Prefs (nodomain.freeyourgadget.gadgetbridge.util.Prefs)2 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 Bitmap (android.graphics.Bitmap)1