Search in sources :

Example 1 with ColorPickerDialogListener

use of com.jaredrummler.android.colorpicker.ColorPickerDialogListener in project Gadgetbridge by Freeyourgadget.

the class GBDeviceAdapterv2 method onBindViewHolder.

@Override
public void onBindViewHolder(@NonNull ViewHolder holder, final int position) {
    final GBDevice device = deviceList.get(position);
    long[] dailyTotals = new long[] { 0, 0 };
    if (deviceActivityMap.containsKey(device.getAddress())) {
        dailyTotals = deviceActivityMap.get(device.getAddress());
    }
    final DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
    holder.container.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (device.isInitialized() || device.isConnected()) {
                showTransientSnackbar(R.string.controlcenter_snackbar_need_longpress);
            } else {
                showTransientSnackbar(R.string.controlcenter_snackbar_connecting);
                GBApplication.deviceService().connect(device);
            }
        }
    });
    holder.container.setOnLongClickListener(new View.OnLongClickListener() {

        @Override
        public boolean onLongClick(View v) {
            if (device.getState() != GBDevice.State.NOT_CONNECTED) {
                showTransientSnackbar(R.string.controlcenter_snackbar_disconnecting);
                GBApplication.deviceService().disconnect();
            }
            return true;
        }
    });
    holder.deviceImageView.setImageResource(device.isInitialized() ? device.getType().getIcon() : device.getType().getDisabledIcon());
    holder.deviceNameLabel.setText(getUniqueDeviceName(device));
    if (device.isBusy()) {
        holder.deviceStatusLabel.setText(device.getBusyTask());
        holder.busyIndicator.setVisibility(View.VISIBLE);
    } else {
        holder.deviceStatusLabel.setText(device.getStateString());
        holder.busyIndicator.setVisibility(View.INVISIBLE);
    }
    // begin of action row
    // battery
    // multiple battery support: at this point we support up to three batteries
    // to support more batteries, the battery UI would need to be extended
    holder.batteryStatusBox0.setVisibility(coordinator.getBatteryCount() > 0 ? View.VISIBLE : View.GONE);
    holder.batteryStatusBox1.setVisibility(coordinator.getBatteryCount() > 1 ? View.VISIBLE : View.GONE);
    holder.batteryStatusBox2.setVisibility(coordinator.getBatteryCount() > 2 ? View.VISIBLE : View.GONE);
    LinearLayout[] batteryStatusBoxes = { holder.batteryStatusBox0, holder.batteryStatusBox1, holder.batteryStatusBox2 };
    TextView[] batteryStatusLabels = { holder.batteryStatusLabel0, holder.batteryStatusLabel1, holder.batteryStatusLabel2 };
    ImageView[] batteryIcons = { holder.batteryIcon0, holder.batteryIcon1, holder.batteryIcon2 };
    for (int batteryIndex = 0; batteryIndex < coordinator.getBatteryCount(); batteryIndex++) {
        int batteryLevel = device.getBatteryLevel(batteryIndex);
        float batteryVoltage = device.getBatteryVoltage(batteryIndex);
        BatteryState batteryState = device.getBatteryState(batteryIndex);
        int batteryIcon = device.getBatteryIcon(batteryIndex);
        // unused for now
        int batteryLabel = device.getBatteryLabel(batteryIndex);
        batteryIcons[batteryIndex].setImageResource(R.drawable.level_list_battery);
        if (batteryIcon != GBDevice.BATTERY_ICON_DEFAULT) {
            batteryIcons[batteryIndex].setImageResource(batteryIcon);
        }
        if (batteryLevel != GBDevice.BATTERY_UNKNOWN) {
            batteryStatusLabels[batteryIndex].setText(device.getBatteryLevel(batteryIndex) + "%");
            if (BatteryState.BATTERY_CHARGING.equals(batteryState) || BatteryState.BATTERY_CHARGING_FULL.equals(batteryState)) {
                batteryIcons[batteryIndex].setImageLevel(device.getBatteryLevel(batteryIndex) + 100);
            } else {
                batteryIcons[batteryIndex].setImageLevel(device.getBatteryLevel(batteryIndex));
            }
        } else if (BatteryState.NO_BATTERY.equals(batteryState) && batteryVoltage != GBDevice.BATTERY_UNKNOWN) {
            batteryStatusLabels[batteryIndex].setText(String.format(Locale.getDefault(), "%.2f", batteryVoltage));
            batteryIcons[batteryIndex].setImageLevel(200);
        } else {
            // should be the "default" status, shown when the device is not connected
            batteryStatusLabels[batteryIndex].setText("");
            batteryIcons[batteryIndex].setImageLevel(50);
        }
        final int finalBatteryIndex = batteryIndex;
        batteryStatusBoxes[batteryIndex].setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent startIntent;
                startIntent = new Intent(context, BatteryInfoActivity.class);
                startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
                startIntent.putExtra(GBDevice.BATTERY_INDEX, finalBatteryIndex);
                context.startActivity(startIntent);
            }
        });
        // Hide the battery status level, if it has no text
        if (TextUtils.isEmpty(batteryStatusLabels[batteryIndex].getText())) {
            batteryStatusLabels[batteryIndex].setVisibility(View.GONE);
        } else {
            batteryStatusLabels[batteryIndex].setVisibility(View.VISIBLE);
        }
    }
    holder.heartRateStatusBox.setVisibility((device.isInitialized() && coordinator.supportsRealtimeData() && coordinator.supportsHeartRateMeasurement(device)) ? View.VISIBLE : View.GONE);
    if (parent.getContext() instanceof ControlCenterv2) {
        ActivitySample sample = ((ControlCenterv2) parent.getContext()).getCurrentHRSample();
        if (sample != null) {
            holder.heartRateStatusLabel.setText(String.valueOf(sample.getHeartRate()));
        } else {
            holder.heartRateStatusLabel.setText("");
        }
        // Hide the level, if it has no text
        if (TextUtils.isEmpty(holder.heartRateStatusLabel.getText())) {
            holder.heartRateStatusLabel.setVisibility(View.GONE);
        } else {
            holder.heartRateStatusLabel.setVisibility(View.VISIBLE);
        }
    }
    holder.heartRateStatusBox.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            GBApplication.deviceService().onHeartRateTest();
            HeartRateDialog dialog = new HeartRateDialog(context);
            dialog.show();
        }
    });
    // device specific settings
    holder.deviceSpecificSettingsView.setVisibility(coordinator.getSupportedDeviceSpecificSettings(device) != null ? View.VISIBLE : View.GONE);
    holder.deviceSpecificSettingsView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent startIntent;
            startIntent = new Intent(context, DeviceSettingsActivity.class);
            startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
            context.startActivity(startIntent);
        }
    });
    // fetch activity data
    holder.fetchActivityDataBox.setVisibility((device.isInitialized() && coordinator.supportsActivityDataFetching()) ? View.VISIBLE : View.GONE);
    holder.fetchActivityData.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showTransientSnackbar(R.string.busy_task_fetch_activity_data);
            GBApplication.deviceService().onFetchRecordedData(RecordedDataTypes.TYPE_ACTIVITY);
        }
    });
    // take screenshot
    holder.takeScreenshotView.setVisibility((device.isInitialized() && coordinator.supportsScreenshots()) ? View.VISIBLE : View.GONE);
    holder.takeScreenshotView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showTransientSnackbar(R.string.controlcenter_snackbar_requested_screenshot);
            GBApplication.deviceService().onScreenshotReq();
        }
    });
    // manage apps
    holder.manageAppsView.setVisibility((device.isInitialized() && coordinator.supportsAppsManagement()) ? View.VISIBLE : View.GONE);
    holder.manageAppsView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
            Class<? extends Activity> appsManagementActivity = coordinator.getAppsManagementActivity();
            if (appsManagementActivity != null) {
                Intent startIntent = new Intent(context, appsManagementActivity);
                startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
                context.startActivity(startIntent);
            }
        }
    });
    // set alarms
    holder.setAlarmsView.setVisibility(coordinator.getAlarmSlotCount() > 0 ? View.VISIBLE : View.GONE);
    holder.setAlarmsView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent startIntent;
            startIntent = new Intent(context, ConfigureAlarms.class);
            startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
            context.startActivity(startIntent);
        }
    });
    // set reminders
    holder.setRemindersView.setVisibility(coordinator.getReminderSlotCount() > 0 ? View.VISIBLE : View.GONE);
    holder.setRemindersView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent startIntent;
            startIntent = new Intent(context, ConfigureReminders.class);
            startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
            context.startActivity(startIntent);
        }
    });
    // show graphs
    holder.showActivityGraphs.setVisibility(coordinator.supportsActivityTracking() ? View.VISIBLE : View.GONE);
    holder.showActivityGraphs.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent startIntent;
            startIntent = new Intent(context, ChartsActivity.class);
            startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
            context.startActivity(startIntent);
        }
    });
    // show activity tracks
    holder.showActivityTracks.setVisibility(coordinator.supportsActivityTracks() ? View.VISIBLE : View.GONE);
    holder.showActivityTracks.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent startIntent;
            startIntent = new Intent(context, ActivitySummariesActivity.class);
            startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
            context.startActivity(startIntent);
        }
    });
    ItemWithDetailsAdapter infoAdapter = new ItemWithDetailsAdapter(context, device.getDeviceInfos());
    infoAdapter.setHorizontalAlignment(true);
    holder.deviceInfoList.setAdapter(infoAdapter);
    justifyListViewHeightBasedOnChildren(holder.deviceInfoList);
    holder.deviceInfoList.setFocusable(false);
    final boolean detailsShown = expandedDeviceAddress.equals(device.getAddress());
    boolean showInfoIcon = device.hasDeviceInfos() && !device.isBusy();
    holder.deviceInfoView.setVisibility(showInfoIcon ? View.VISIBLE : View.GONE);
    holder.deviceInfoBox.setActivated(detailsShown);
    holder.deviceInfoBox.setVisibility(detailsShown ? View.VISIBLE : View.GONE);
    holder.deviceInfoView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            expandedDeviceAddress = detailsShown ? "" : device.getAddress();
            TransitionManager.beginDelayedTransition(parent);
            notifyDataSetChanged();
        }
    });
    holder.findDevice.setVisibility(device.isInitialized() && coordinator.supportsFindDevice() ? View.VISIBLE : View.GONE);
    holder.findDevice.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new AlertDialog.Builder(context).setCancelable(true).setTitle(context.getString(R.string.controlcenter_find_device)).setMessage(context.getString(R.string.find_lost_device_message, device.getName())).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    if (device.getType() == DeviceType.VIBRATISSIMO) {
                        Intent startIntent;
                        startIntent = new Intent(context, VibrationActivity.class);
                        startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
                        context.startActivity(startIntent);
                        return;
                    }
                    GBApplication.deviceService().onFindDevice(true);
                    Snackbar.make(parent, R.string.control_center_find_lost_device, Snackbar.LENGTH_INDEFINITE).setAction(R.string.find_lost_device_you_found_it, new View.OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            GBApplication.deviceService().onFindDevice(false);
                        }
                    }).setCallback(new Snackbar.Callback() {

                        @Override
                        public void onDismissed(Snackbar snackbar, int event) {
                            GBApplication.deviceService().onFindDevice(false);
                            super.onDismissed(snackbar, event);
                        }
                    }).show();
                }
            }).setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                // do nothing
                }
            }).show();
        // ProgressDialog.show(
        // context,
        // context.getString(R.string.control_center_find_lost_device),
        // context.getString(R.string.control_center_cancel_to_stop_vibration),
        // true, true,
        // new DialogInterface.OnCancelListener() {
        // @Override
        // public void onCancel(DialogInterface dialog) {
        // GBApplication.deviceService().onFindDevice(false);
        // }
        // });
        }
    });
    holder.calibrateDevice.setVisibility(device.isInitialized() && (coordinator.getCalibrationActivity() != null) ? View.VISIBLE : View.GONE);
    holder.calibrateDevice.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Intent startIntent = new Intent(context, coordinator.getCalibrationActivity());
            startIntent.putExtra(GBDevice.EXTRA_DEVICE, device);
            context.startActivity(startIntent);
        }
    });
    holder.fmFrequencyBox.setVisibility(View.GONE);
    if (device.isInitialized() && device.getExtraInfo("fm_frequency") != null) {
        holder.fmFrequencyBox.setVisibility(View.VISIBLE);
        holder.fmFrequencyLabel.setText(String.format(Locale.getDefault(), "%.1f", (float) device.getExtraInfo("fm_frequency")));
    }
    final TextView fmFrequencyLabel = holder.fmFrequencyLabel;
    final float FREQ_MIN = 87.5F;
    final float FREQ_MAX = 108.0F;
    final int FREQ_MIN_INT = (int) Math.floor(FREQ_MIN);
    final int FREQ_MAX_INT = (int) Math.round(FREQ_MAX);
    final AlertDialog[] alert = new AlertDialog[1];
    holder.fmFrequencyBox.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            final AlertDialog.Builder builder = new AlertDialog.Builder(context);
            final LayoutInflater inflater = LayoutInflater.from(context);
            final View frequency_picker_view = inflater.inflate(R.layout.dialog_frequency_picker, null);
            builder.setTitle(R.string.preferences_fm_frequency);
            final float[] fm_presets = new float[3];
            fm_presets[0] = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getFloat("fm_preset0", 99);
            fm_presets[1] = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getFloat("fm_preset1", 100);
            fm_presets[2] = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).getFloat("fm_preset2", 101);
            final NumberPicker frequency_decimal_picker = frequency_picker_view.findViewById(R.id.frequency_dec);
            frequency_decimal_picker.setMinValue(FREQ_MIN_INT);
            frequency_decimal_picker.setMaxValue(FREQ_MAX_INT);
            final NumberPicker frequency_fraction_picker = frequency_picker_view.findViewById(R.id.frequency_fraction);
            frequency_fraction_picker.setMinValue(0);
            frequency_fraction_picker.setMaxValue(9);
            final NumberPicker.OnValueChangeListener picker_listener = new NumberPicker.OnValueChangeListener() {

                @Override
                public void onValueChange(NumberPicker numberPicker, int oldVal, int newVal) {
                    int decimal_value = numberPicker.getValue();
                    if (decimal_value == FREQ_MIN_INT) {
                        frequency_fraction_picker.setMinValue(5);
                        frequency_fraction_picker.setMaxValue(9);
                    } else if (decimal_value == FREQ_MAX_INT) {
                        frequency_fraction_picker.setMinValue(0);
                        frequency_fraction_picker.setMaxValue(0);
                    } else {
                        frequency_fraction_picker.setMinValue(0);
                        frequency_fraction_picker.setMaxValue(9);
                    }
                }
            };
            frequency_decimal_picker.setOnValueChangedListener(picker_listener);
            final Button[] button_presets = new Button[] { frequency_picker_view.findViewById(R.id.frequency_preset1), frequency_picker_view.findViewById(R.id.frequency_preset2), frequency_picker_view.findViewById(R.id.frequency_preset3) };
            for (int i = 0; i < button_presets.length; i++) {
                final int index = i;
                button_presets[index].setText(String.valueOf(fm_presets[index]));
                button_presets[index].setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View view) {
                        final float frequency = fm_presets[index];
                        device.setExtraInfo("fm_frequency", fm_presets[index]);
                        fmFrequencyLabel.setText(String.format(Locale.getDefault(), "%.1f", (float) frequency));
                        GBApplication.deviceService().onSetFmFrequency(frequency);
                        alert[0].dismiss();
                    }
                });
                button_presets[index].setOnLongClickListener(new View.OnLongClickListener() {

                    @Override
                    public boolean onLongClick(View view) {
                        final float frequency = (float) (frequency_decimal_picker.getValue() + (0.1 * frequency_fraction_picker.getValue()));
                        fm_presets[index] = frequency;
                        button_presets[index].setText(String.valueOf(frequency));
                        SharedPreferences.Editor editor = GBApplication.getDeviceSpecificSharedPrefs(device.getAddress()).edit();
                        editor.putFloat((String.format("fm_preset%s", index)), frequency);
                        editor.apply();
                        editor.commit();
                        return true;
                    }
                });
            }
            final float frequency = (float) device.getExtraInfo("fm_frequency");
            final int decimal = (int) frequency;
            final int fraction = Math.round((frequency - decimal) * 10);
            frequency_decimal_picker.setValue(decimal);
            picker_listener.onValueChange(frequency_decimal_picker, frequency_decimal_picker.getValue(), decimal);
            frequency_fraction_picker.setValue(fraction);
            builder.setView(frequency_picker_view);
            builder.setPositiveButton(context.getResources().getString(android.R.string.ok), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    float frequency = (float) (frequency_decimal_picker.getValue() + (0.1 * frequency_fraction_picker.getValue()));
                    if (frequency < FREQ_MIN || frequency > FREQ_MAX) {
                        new AlertDialog.Builder(context).setTitle(R.string.pref_invalid_frequency_title).setMessage(R.string.pref_invalid_frequency_message).setNeutralButton(android.R.string.ok, new DialogInterface.OnClickListener() {

                            public void onClick(DialogInterface dialog, int which) {
                            }
                        }).show();
                    } else {
                        device.setExtraInfo("fm_frequency", frequency);
                        fmFrequencyLabel.setText(String.format(Locale.getDefault(), "%.1f", frequency));
                        GBApplication.deviceService().onSetFmFrequency(frequency);
                    }
                }
            });
            builder.setNegativeButton(context.getResources().getString(R.string.Cancel), new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.cancel();
                }
            });
            alert[0] = builder.create();
            alert[0].show();
        }
    });
    holder.ledColor.setVisibility(View.GONE);
    if (device.isInitialized() && device.getExtraInfo("led_color") != null && coordinator.supportsLedColor()) {
        holder.ledColor.setVisibility(View.VISIBLE);
        final GradientDrawable ledColor = (GradientDrawable) holder.ledColor.getDrawable().mutate();
        ledColor.setColor((int) device.getExtraInfo("led_color"));
        holder.ledColor.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                ColorPickerDialog.Builder builder = ColorPickerDialog.newBuilder();
                builder.setDialogTitle(R.string.preferences_led_color);
                int[] presets = coordinator.getColorPresets();
                builder.setColor((int) device.getExtraInfo("led_color"));
                builder.setShowAlphaSlider(false);
                builder.setShowColorShades(false);
                if (coordinator.supportsRgbLedColor()) {
                    builder.setAllowCustom(true);
                    if (presets.length == 0) {
                        builder.setDialogType(ColorPickerDialog.TYPE_CUSTOM);
                    }
                } else {
                    builder.setAllowCustom(false);
                }
                if (presets.length > 0) {
                    builder.setAllowPresets(true);
                    builder.setPresets(presets);
                }
                ColorPickerDialog dialog = builder.create();
                dialog.setColorPickerDialogListener(new ColorPickerDialogListener() {

                    @Override
                    public void onColorSelected(int dialogId, int color) {
                        ledColor.setColor(color);
                        device.setExtraInfo("led_color", color);
                        GBApplication.deviceService().onSetLedColor(color);
                    }

                    @Override
                    public void onDialogDismissed(int dialogId) {
                    // Nothing to do
                    }
                });
                dialog.show(((Activity) context).getFragmentManager(), "color-picker-dialog");
            }
        });
    }
    holder.powerOff.setVisibility(View.GONE);
    if (device.isInitialized() && coordinator.supportsPowerOff()) {
        holder.powerOff.setVisibility(View.VISIBLE);
        holder.powerOff.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                new AlertDialog.Builder(context).setTitle(R.string.controlcenter_power_off_confirm_title).setMessage(R.string.controlcenter_power_off_confirm_description).setIcon(R.drawable.ic_power_settings_new).setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {

                    public void onClick(final DialogInterface dialog, final int whichButton) {
                        GBApplication.deviceService().onPowerOff();
                    }
                }).setNegativeButton(android.R.string.no, null).show();
            }
        });
    }
    // remove device, hidden under details
    holder.removeDevice.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            new AlertDialog.Builder(context).setCancelable(true).setTitle(context.getString(R.string.controlcenter_delete_device_name, device.getName())).setMessage(R.string.controlcenter_delete_device_dialogmessage).setPositiveButton(R.string.Delete, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    try {
                        DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(device);
                        if (coordinator != null) {
                            coordinator.deleteDevice(device);
                        }
                        DeviceHelper.getInstance().removeBond(device);
                    } catch (Exception ex) {
                        GB.toast(context, "Error deleting device: " + ex.getMessage(), Toast.LENGTH_LONG, GB.ERROR, ex);
                    } finally {
                        Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST);
                        LocalBroadcastManager.getInstance(context).sendBroadcast(refreshIntent);
                    }
                }
            }).setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                // do nothing
                }
            }).show();
        }
    });
    // set alias, hidden under details
    holder.setAlias.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final EditText input = new EditText(context);
            input.setInputType(InputType.TYPE_CLASS_TEXT);
            input.setText(device.getAlias());
            FrameLayout container = new FrameLayout(context);
            FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            params.leftMargin = context.getResources().getDimensionPixelSize(R.dimen.dialog_margin);
            params.rightMargin = context.getResources().getDimensionPixelSize(R.dimen.dialog_margin);
            input.setLayoutParams(params);
            container.addView(input);
            // Specify the type of input expected; this, for example, sets the input as a password, and will mask the text
            new AlertDialog.Builder(context).setView(container).setCancelable(true).setTitle(context.getString(R.string.controlcenter_set_alias)).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    try (DBHandler dbHandler = GBApplication.acquireDB()) {
                        DaoSession session = dbHandler.getDaoSession();
                        Device dbDevice = DBHelper.getDevice(device, session);
                        String alias = input.getText().toString();
                        dbDevice.setAlias(alias);
                        dbDevice.update();
                        device.setAlias(alias);
                    } catch (Exception ex) {
                        GB.toast(context, context.getString(R.string.error_setting_alias) + ex.getMessage(), Toast.LENGTH_LONG, GB.ERROR, ex);
                    } finally {
                        Intent refreshIntent = new Intent(DeviceManager.ACTION_REFRESH_DEVICELIST);
                        LocalBroadcastManager.getInstance(context).sendBroadcast(refreshIntent);
                    }
                }
            }).setNegativeButton(R.string.Cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                // do nothing
                }
            }).show();
        }
    });
    holder.cardViewActivityCardLayout.setVisibility(coordinator.supportsActivityTracking() ? View.VISIBLE : View.GONE);
    holder.cardViewActivityCardLayout.setMinimumWidth(coordinator.supportsActivityTracking() ? View.VISIBLE : View.GONE);
    if (coordinator.supportsActivityTracking()) {
        setActivityCard(holder, device, dailyTotals);
    }
}
Also used : AlertDialog(android.app.AlertDialog) ActivitySample(nodomain.freeyourgadget.gadgetbridge.model.ActivitySample) DeviceSettingsActivity(nodomain.freeyourgadget.gadgetbridge.activities.devicesettings.DeviceSettingsActivity) ActivitySummariesActivity(nodomain.freeyourgadget.gadgetbridge.activities.ActivitySummariesActivity) ChartsActivity(nodomain.freeyourgadget.gadgetbridge.activities.charts.ChartsActivity) SettingsActivity(nodomain.freeyourgadget.gadgetbridge.activities.SettingsActivity) BatteryInfoActivity(nodomain.freeyourgadget.gadgetbridge.activities.BatteryInfoActivity) VibrationActivity(nodomain.freeyourgadget.gadgetbridge.activities.VibrationActivity) Activity(android.app.Activity) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) ControlCenterv2(nodomain.freeyourgadget.gadgetbridge.activities.ControlCenterv2) TextView(android.widget.TextView) ImageView(android.widget.ImageView) EditText(android.widget.EditText) NumberPicker(android.widget.NumberPicker) Device(nodomain.freeyourgadget.gadgetbridge.entities.Device) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice) GradientDrawable(android.graphics.drawable.GradientDrawable) ColorPickerDialog(com.jaredrummler.android.colorpicker.ColorPickerDialog) LayoutInflater(android.view.LayoutInflater) Snackbar(com.google.android.material.snackbar.Snackbar) DialogInterface(android.content.DialogInterface) ColorPickerDialogListener(com.jaredrummler.android.colorpicker.ColorPickerDialogListener) DBHandler(nodomain.freeyourgadget.gadgetbridge.database.DBHandler) DeviceCoordinator(nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator) VibrationActivity(nodomain.freeyourgadget.gadgetbridge.activities.VibrationActivity) DaoSession(nodomain.freeyourgadget.gadgetbridge.entities.DaoSession) SharedPreferences(android.content.SharedPreferences) HeartRateDialog(nodomain.freeyourgadget.gadgetbridge.activities.HeartRateDialog) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) CardView(androidx.cardview.widget.CardView) TextView(android.widget.TextView) ListView(android.widget.ListView) FrameLayout(android.widget.FrameLayout) BatteryState(nodomain.freeyourgadget.gadgetbridge.model.BatteryState) LinearLayout(android.widget.LinearLayout)

Aggregations

Activity (android.app.Activity)1 AlertDialog (android.app.AlertDialog)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 GradientDrawable (android.graphics.drawable.GradientDrawable)1 LayoutInflater (android.view.LayoutInflater)1 View (android.view.View)1 EditText (android.widget.EditText)1 FrameLayout (android.widget.FrameLayout)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 ListView (android.widget.ListView)1 NumberPicker (android.widget.NumberPicker)1 TextView (android.widget.TextView)1 CardView (androidx.cardview.widget.CardView)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 Snackbar (com.google.android.material.snackbar.Snackbar)1 ColorPickerDialog (com.jaredrummler.android.colorpicker.ColorPickerDialog)1 ColorPickerDialogListener (com.jaredrummler.android.colorpicker.ColorPickerDialogListener)1