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));
}
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();
}
}
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);
}
}
Aggregations