added SWCheckbox item
This commit is contained in:
parent
d5a3177c35
commit
1f2f2f54fc
|
@ -0,0 +1,59 @@
|
||||||
|
package info.nightscout.androidaps.startupwizard;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.CompoundButton;
|
||||||
|
import android.widget.LinearLayout;
|
||||||
|
import android.widget.CheckBox;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import info.nightscout.utils.SP;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Rumen Georgiev on 5/9/2018.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class SWCheckbox extends SWItem {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(SWCheckbox.class);
|
||||||
|
|
||||||
|
int labelsArray;
|
||||||
|
int valuesArray;
|
||||||
|
String label = "";
|
||||||
|
int preferenceID;
|
||||||
|
private CheckBox checkBox;
|
||||||
|
|
||||||
|
public SWCheckbox() {
|
||||||
|
super(Type.CHECKBOX);
|
||||||
|
}
|
||||||
|
|
||||||
|
public SWCheckbox option(String label, int preferenceID) {
|
||||||
|
this.label = label;
|
||||||
|
this.preferenceID = preferenceID;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void generateDialog(View view, LinearLayout layout) {
|
||||||
|
Context context = view.getContext();
|
||||||
|
// Get if there is already value in SP
|
||||||
|
Boolean previousValue;
|
||||||
|
previousValue = SP.getBoolean(preferenceId, false);
|
||||||
|
checkBox = new CheckBox(context);
|
||||||
|
checkBox.setText(label);
|
||||||
|
checkBox.setChecked(previousValue);
|
||||||
|
checkBox.setVisibility(View.VISIBLE);
|
||||||
|
checkBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
|
||||||
|
@Override
|
||||||
|
public void onCheckedChanged(CompoundButton compoundButton, boolean b) {
|
||||||
|
save(checkBox.isChecked());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
layout.addView(checkBox);
|
||||||
|
super.generateDialog(view, layout);
|
||||||
|
}
|
||||||
|
public void save(boolean value){
|
||||||
|
SP.putBoolean(preferenceID, value);
|
||||||
|
}
|
||||||
|
}
|
|
@ -113,9 +113,8 @@ public class SWDefinition {
|
||||||
)
|
)
|
||||||
// Virtual pump
|
// Virtual pump
|
||||||
.add(VirtualPumpPlugin.getPlugin().isEnabled(PluginType.PUMP)?
|
.add(VirtualPumpPlugin.getPlugin().isEnabled(PluginType.PUMP)?
|
||||||
// TODO: Replace with checkbox
|
new SWCheckbox()
|
||||||
new SWRadioButton()
|
.option(MainApp.instance().getApplicationContext().getResources().getString(R.string.virtualpump_uploadstatus_title), R.string.key_virtualpump_uploadstatus)
|
||||||
.option(MainApp.instance().getApplicationContext().getResources().getString(R.string.virtualpump_uploadstatus_title), R.array.trueFalseArray, R.array.trueFalseValues)
|
|
||||||
.preferenceId(R.string.key_virtualpump_uploadstatus)
|
.preferenceId(R.string.key_virtualpump_uploadstatus)
|
||||||
.label(R.string.virtualpump_uploadstatus_title)
|
.label(R.string.virtualpump_uploadstatus_title)
|
||||||
.comment(R.string.virtualpump_uploadstatus_title): new SWItem(SWItem.Type.STRING)
|
.comment(R.string.virtualpump_uploadstatus_title): new SWItem(SWItem.Type.STRING)
|
||||||
|
|
|
@ -81,10 +81,6 @@ public class SWRadioButton extends SWItem {
|
||||||
p.setPluginEnabled(PluginType.PUMP, false);
|
p.setPluginEnabled(PluginType.PUMP, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log.debug("Pump selected: DanaR:"+DanaRPlugin.getPlugin().isEnabled(PluginType.PUMP));
|
|
||||||
log.debug("Pump selected: Virtual:"+VirtualPumpPlugin.getPlugin().isEnabled(PluginType.PUMP));
|
|
||||||
log.debug("Pump selected: Combo:"+ ComboPlugin.getPlugin().isEnabled(PluginType.PUMP));
|
|
||||||
log.debug("Pump selected: "+ found.getNameShort());
|
|
||||||
for (int i = 0; i < labels().length; i++) {
|
for (int i = 0; i < labels().length; i++) {
|
||||||
RadioButton rdbtn = new RadioButton(context);
|
RadioButton rdbtn = new RadioButton(context);
|
||||||
rdbtn.setId(View.generateViewId());
|
rdbtn.setId(View.generateViewId());
|
||||||
|
|
Loading…
Reference in a new issue