Search in sources :

Example 11 with Version

use of nodomain.freeyourgadget.gadgetbridge.util.Version 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

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