Search in sources :

Example 1 with BatteryConfig

use of nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig in project Gadgetbridge by Freeyourgadget.

the class BatteryInfoActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    final Context appContext = this.getApplicationContext();
    if (appContext instanceof GBApplication) {
        setContentView(R.layout.activity_battery_info);
    }
    Intent intent = getIntent();
    Bundle bundle = intent.getExtras();
    if (bundle != null) {
        gbDevice = bundle.getParcelable(GBDevice.EXTRA_DEVICE);
        batteryIndex = bundle.getInt(GBDevice.BATTERY_INDEX, 0);
    } else {
        throw new IllegalArgumentException("Must provide a device when invoking this activity");
    }
    final BatteryInfoChartFragment batteryInfoChartFragment = new BatteryInfoChartFragment();
    getSupportFragmentManager().beginTransaction().replace(R.id.batteryChartFragmentHolder, batteryInfoChartFragment).commit();
    timeTo = (int) (System.currentTimeMillis() / 1000);
    batteryInfoChartFragment.setDateAndGetData(gbDevice, batteryIndex, timeFrom, timeTo);
    TextView battery_status_device_name_text = (TextView) findViewById(R.id.battery_status_device_name);
    TextView battery_status_battery_voltage = (TextView) findViewById(R.id.battery_status_battery_voltage);
    TextView battery_status_extra_name = (TextView) findViewById(R.id.battery_status_extra_name);
    final TextView battery_status_date_from_text = (TextView) findViewById(R.id.battery_status_date_from_text);
    final TextView battery_status_date_to_text = (TextView) findViewById(R.id.battery_status_date_to_text);
    final SeekBar battery_status_time_span_seekbar = (SeekBar) findViewById(R.id.battery_status_time_span_seekbar);
    final TextView battery_status_time_span_text = (TextView) findViewById(R.id.battery_status_time_span_text);
    LinearLayout battery_status_date_to_layout = (LinearLayout) findViewById(R.id.battery_status_date_to_layout);
    battery_status_time_span_seekbar.setMax(5);
    battery_status_time_span_seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {

        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            String text;
            switch(i) {
                case 0:
                    text = getString(R.string.calendar_day);
                    timeFrom = DateTimeUtils.shiftDays(timeTo, -1);
                    break;
                case 1:
                    text = getString(R.string.calendar_week);
                    timeFrom = DateTimeUtils.shiftDays(timeTo, -7);
                    break;
                case 2:
                    text = getString(R.string.calendar_two_weeks);
                    timeFrom = DateTimeUtils.shiftDays(timeTo, -14);
                    break;
                case 3:
                    text = getString(R.string.calendar_month);
                    timeFrom = DateTimeUtils.shiftMonths(timeTo, -1);
                    break;
                case 4:
                    text = getString(R.string.calendar_six_months);
                    timeFrom = DateTimeUtils.shiftMonths(timeTo, -6);
                    break;
                case 5:
                    text = getString(R.string.calendar_year);
                    timeFrom = DateTimeUtils.shiftMonths(timeTo, -12);
                    break;
                default:
                    text = getString(R.string.calendar_two_weeks);
                    timeFrom = DateTimeUtils.shiftDays(timeTo, -14);
            }
            battery_status_time_span_text.setText(text);
            battery_status_date_from_text.setText(DateTimeUtils.formatDate(new Date(timeFrom * 1000L)));
            battery_status_date_to_text.setText(DateTimeUtils.formatDate(new Date(timeTo * 1000L)));
            batteryInfoChartFragment.setDateAndGetData(gbDevice, batteryIndex, timeFrom, timeTo);
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {
        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
        }
    });
    // Button battery_status_calendar_button = findViewById(R.id.battery_status_calendar_button);
    battery_status_date_to_layout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            final Calendar currentDate = Calendar.getInstance();
            currentDate.setTimeInMillis(timeTo * 1000L);
            Context context = getApplicationContext();
            if (context instanceof GBApplication) {
                new DatePickerDialog(BatteryInfoActivity.this, new DatePickerDialog.OnDateSetListener() {

                    @Override
                    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                        Calendar date = Calendar.getInstance();
                        date.set(year, monthOfYear, dayOfMonth);
                        timeTo = (int) (date.getTimeInMillis() / 1000);
                        battery_status_date_to_text.setText(DateTimeUtils.formatDate(new Date(timeTo * 1000L)));
                        battery_status_time_span_seekbar.setProgress(0);
                        battery_status_time_span_seekbar.setProgress(1);
                        batteryInfoChartFragment.setDateAndGetData(gbDevice, batteryIndex, timeFrom, timeTo);
                    }
                }, currentDate.get(Calendar.YEAR), currentDate.get(Calendar.MONTH), currentDate.get(Calendar.DATE)).show();
            }
        }
    });
    battery_status_time_span_seekbar.setProgress(2);
    ImageView battery_status_device_icon = findViewById(R.id.battery_status_device_icon);
    battery_status_device_icon.setImageResource(gbDevice.isInitialized() ? gbDevice.getType().getIcon() : gbDevice.getType().getDisabledIcon());
    TextView battery_status_battery_level_text = (TextView) findViewById(R.id.battery_status_battery_level);
    String level = gbDevice.getBatteryLevel(batteryIndex) > 0 ? String.format("%1s%%", gbDevice.getBatteryLevel(batteryIndex)) : "";
    String voltage = gbDevice.getBatteryVoltage(batteryIndex) > 0 ? String.format("%1sV", gbDevice.getBatteryVoltage(batteryIndex)) : "";
    battery_status_device_name_text.setText(gbDevice.getName());
    battery_status_battery_level_text.setText(level);
    battery_status_battery_voltage.setText(voltage);
    DeviceCoordinator coordinator = DeviceHelper.getInstance().getCoordinator(gbDevice);
    for (BatteryConfig batteryConfig : coordinator.getBatteryConfig()) {
        if (batteryConfig.getBatteryIndex() == batteryIndex) {
            battery_status_extra_name.setText(batteryConfig.getBatteryLabel());
            battery_status_device_icon.setImageResource(batteryConfig.getBatteryIcon());
            if (gbDevice.isInitialized()) {
                battery_status_device_icon.setColorFilter(this.getResources().getColor(R.color.accent));
            }
        }
    }
}
Also used : Context(android.content.Context) GBApplication(nodomain.freeyourgadget.gadgetbridge.GBApplication) SeekBar(android.widget.SeekBar) DatePickerDialog(android.app.DatePickerDialog) Bundle(android.os.Bundle) Calendar(java.util.Calendar) Intent(android.content.Intent) ImageView(android.widget.ImageView) TextView(android.widget.TextView) View(android.view.View) Date(java.util.Date) BatteryConfig(nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig) TextView(android.widget.TextView) DatePicker(android.widget.DatePicker) ImageView(android.widget.ImageView) LinearLayout(android.widget.LinearLayout) DeviceCoordinator(nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator)

Example 2 with BatteryConfig

use of nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig in project Gadgetbridge by Freeyourgadget.

the class AbstractDeviceCoordinator method createDevice.

@Override
public GBDevice createDevice(GBDeviceCandidate candidate) {
    GBDevice gbDevice = new GBDevice(candidate.getDevice().getAddress(), candidate.getName(), null, getDeviceType());
    for (BatteryConfig batteryConfig : getBatteryConfig()) {
        gbDevice.setBatteryIcon(batteryConfig.getBatteryIcon(), batteryConfig.getBatteryIndex());
        gbDevice.setBatteryLabel(batteryConfig.getBatteryLabel(), batteryConfig.getBatteryIndex());
    }
    return gbDevice;
}
Also used : BatteryConfig(nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)

Example 3 with BatteryConfig

use of nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig in project Gadgetbridge by Freeyourgadget.

the class GalaxyBudsLiveDeviceCoordinator method getBatteryConfig.

@Override
public BatteryConfig[] getBatteryConfig() {
    BatteryConfig battery1 = new BatteryConfig(0, R.drawable.ic_tws_case, R.string.battery_case);
    BatteryConfig battery2 = new BatteryConfig(1, R.drawable.ic_galaxy_buds_live_l, R.string.left_earbud);
    BatteryConfig battery3 = new BatteryConfig(2, R.drawable.ic_galaxy_buds_live_r, R.string.right_earbud);
    return new BatteryConfig[] { battery1, battery2, battery3 };
}
Also used : BatteryConfig(nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig)

Example 4 with BatteryConfig

use of nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig in project Gadgetbridge by Freeyourgadget.

the class DeviceHelper method toGBDevice.

/**
 * Converts a known device from the database to a GBDevice.
 * Note: The device might not be supported anymore, so callers should verify that.
 * @param dbDevice
 * @return
 */
public GBDevice toGBDevice(Device dbDevice) {
    DeviceType deviceType = DeviceType.fromKey(dbDevice.getType());
    GBDevice gbDevice = new GBDevice(dbDevice.getIdentifier(), dbDevice.getName(), dbDevice.getAlias(), deviceType);
    DeviceCoordinator coordinator = getCoordinator(gbDevice);
    for (BatteryConfig batteryConfig : coordinator.getBatteryConfig()) {
        gbDevice.setBatteryIcon(batteryConfig.getBatteryIcon(), batteryConfig.getBatteryIndex());
        gbDevice.setBatteryLabel(batteryConfig.getBatteryLabel(), batteryConfig.getBatteryIndex());
    }
    List<DeviceAttributes> deviceAttributesList = dbDevice.getDeviceAttributesList();
    if (deviceAttributesList.size() > 0) {
        gbDevice.setModel(dbDevice.getModel());
        DeviceAttributes attrs = deviceAttributesList.get(0);
        gbDevice.setFirmwareVersion(attrs.getFirmwareVersion1());
        gbDevice.setFirmwareVersion2(attrs.getFirmwareVersion2());
        gbDevice.setVolatileAddress(attrs.getVolatileIdentifier());
    }
    return gbDevice;
}
Also used : DeviceType(nodomain.freeyourgadget.gadgetbridge.model.DeviceType) BatteryConfig(nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig) DeviceAttributes(nodomain.freeyourgadget.gadgetbridge.entities.DeviceAttributes) MiScale2DeviceCoordinator(nodomain.freeyourgadget.gadgetbridge.devices.miscale2.MiScale2DeviceCoordinator) WatchXPlusDeviceCoordinator(nodomain.freeyourgadget.gadgetbridge.devices.lenovo.watchxplus.WatchXPlusDeviceCoordinator) UnknownDeviceCoordinator(nodomain.freeyourgadget.gadgetbridge.devices.UnknownDeviceCoordinator) FitProDeviceCoordinator(nodomain.freeyourgadget.gadgetbridge.devices.fitpro.FitProDeviceCoordinator) LefunDeviceCoordinator(nodomain.freeyourgadget.gadgetbridge.devices.lefun.LefunDeviceCoordinator) BFH16DeviceCoordinator(nodomain.freeyourgadget.gadgetbridge.devices.jyou.BFH16DeviceCoordinator) SonySWR12DeviceCoordinator(nodomain.freeyourgadget.gadgetbridge.devices.sonyswr12.SonySWR12DeviceCoordinator) GalaxyBudsLiveDeviceCoordinator(nodomain.freeyourgadget.gadgetbridge.devices.galaxy_buds.GalaxyBudsLiveDeviceCoordinator) CasioGBX100DeviceCoordinator(nodomain.freeyourgadget.gadgetbridge.devices.casio.gbx100.CasioGBX100DeviceCoordinator) Watch9DeviceCoordinator(nodomain.freeyourgadget.gadgetbridge.devices.watch9.Watch9DeviceCoordinator) GalaxyBudsDeviceCoordinator(nodomain.freeyourgadget.gadgetbridge.devices.galaxy_buds.GalaxyBudsDeviceCoordinator) DeviceCoordinator(nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator) CasioGB6900DeviceCoordinator(nodomain.freeyourgadget.gadgetbridge.devices.casio.gb6900.CasioGB6900DeviceCoordinator) GBDevice(nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)

Example 5 with BatteryConfig

use of nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig in project Gadgetbridge by Freeyourgadget.

the class SonyWFSP800NCoordinator method getBatteryConfig.

@Override
public BatteryConfig[] getBatteryConfig() {
    final BatteryConfig battery1 = new BatteryConfig(0, R.drawable.ic_tws_case, R.string.battery_case);
    final BatteryConfig battery2 = new BatteryConfig(1, R.drawable.ic_galaxy_buds_l, R.string.left_earbud);
    final BatteryConfig battery3 = new BatteryConfig(2, R.drawable.ic_galaxy_buds_r, R.string.right_earbud);
    return new BatteryConfig[] { battery1, battery2, battery3 };
}
Also used : BatteryConfig(nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig)

Aggregations

BatteryConfig (nodomain.freeyourgadget.gadgetbridge.model.BatteryConfig)7 DeviceCoordinator (nodomain.freeyourgadget.gadgetbridge.devices.DeviceCoordinator)2 GBDevice (nodomain.freeyourgadget.gadgetbridge.impl.GBDevice)2 DatePickerDialog (android.app.DatePickerDialog)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Bundle (android.os.Bundle)1 View (android.view.View)1 DatePicker (android.widget.DatePicker)1 ImageView (android.widget.ImageView)1 LinearLayout (android.widget.LinearLayout)1 SeekBar (android.widget.SeekBar)1 TextView (android.widget.TextView)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 GBApplication (nodomain.freeyourgadget.gadgetbridge.GBApplication)1 UnknownDeviceCoordinator (nodomain.freeyourgadget.gadgetbridge.devices.UnknownDeviceCoordinator)1 CasioGB6900DeviceCoordinator (nodomain.freeyourgadget.gadgetbridge.devices.casio.gb6900.CasioGB6900DeviceCoordinator)1 CasioGBX100DeviceCoordinator (nodomain.freeyourgadget.gadgetbridge.devices.casio.gbx100.CasioGBX100DeviceCoordinator)1 FitProDeviceCoordinator (nodomain.freeyourgadget.gadgetbridge.devices.fitpro.FitProDeviceCoordinator)1