get radiobutton values from arrays.xml & no header

This commit is contained in:
Roumen Georgiev 2018-04-25 16:45:15 +03:00
parent ddf3c44928
commit 8333fe8975
7 changed files with 25 additions and 35 deletions

View file

@ -42,6 +42,11 @@ public class SWDefinition {
.add(new SWRadioButton().option(R.array.ageArray, R.array.ageValues).preferenceId(R.string.key_age).label(R.string.patientage).comment(R.string.patientage_summary))
.validator(() -> SP.contains(R.string.key_age))
)
.add(new SWScreen(R.string.language)
.skippable(false)
.add(new SWRadioButton().option(R.array.languagesArray, R.array.languagesValues).preferenceId(R.string.language).label(R.string.language).comment(R.string.setupwizard_language_prompt))
.validator(() -> SP.contains(R.string.language))
)
;
}

View file

@ -1,5 +1,7 @@
package info.nightscout.androidaps.startupwizard;
import android.view.View;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.utils.SP;
@ -59,4 +61,8 @@ public class SWItem {
SP.putString(preferenceId, value);
MainApp.bus().post(new EventPreferenceChange(preferenceId));
}
public void generateDialog(View view){
}
}

View file

@ -1,9 +1,6 @@
package info.nightscout.androidaps.startupwizard;
import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.support.v4.widget.TextViewCompat;
import android.view.Gravity;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RadioButton;
@ -17,9 +14,7 @@ public class SWRadioButton extends SWItem {
int labelsArray;
int valuesArray;
String groupName = "";
String[] labels;
String[] values;
public SWRadioButton() {
super(Type.RADIOBUTTON);
@ -31,19 +26,6 @@ public class SWRadioButton extends SWItem {
return this;
}
public void setName(String name){
this.groupName = name;
}
public String getGroupName(){
return this.groupName;
}
public void setOptions(String[] labels, String[] values){
this.labels = labels.clone();
this.values = values.clone();
}
public String[] labels() {
return MainApp.sResources.getStringArray(labelsArray);
}
@ -52,20 +34,20 @@ public class SWRadioButton extends SWItem {
return MainApp.sResources.getStringArray(valuesArray);
}
@Override
public void generateDialog(View view){
Context context = view.getContext();
// LinearLayout layout = (LinearLayout) new LinearLayout(context);
LinearLayout layout = (LinearLayout) view.findViewById(view.getId());
layout.removeAllViews();
String[] labels = context.getResources().getStringArray(labelsArray);
String[] values = context.getResources().getStringArray(valuesArray);
TextView textlabel = new TextView(context);
textlabel.setText(groupName);
textlabel.setGravity(Gravity.START);
/* textlabel.setGravity(Gravity.START);
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
llp.setMargins(10, 0, 0, 0); // llp.setMargins(left, top, right, bottom);
textlabel.setLayoutParams(llp);
textlabel.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.linearBlockBackground));
TextViewCompat.setTextAppearance(textlabel, android.R.style.TextAppearance_Medium);
TextViewCompat.setTextAppearance(textlabel, android.R.style.TextAppearance_Medium);*/
RadioGroup rg = new RadioGroup(context);
for (int row = 0; row < 1; row++) {
@ -80,7 +62,6 @@ public class SWRadioButton extends SWItem {
rg.addView(rdbtn);
}
}
layout.addView(textlabel);
layout.addView(rg);
}

View file

@ -31,6 +31,8 @@ public class SWString extends SWItem {
public void setName(String name){
this.groupName = name;
}
@Override
public void generateDialog(View view) {
Context context = view.getContext();
LinearLayout layout = (LinearLayout) view.findViewById(view.getId());
@ -38,12 +40,12 @@ public class SWString extends SWItem {
TextView textlabel = new TextView(context);
textlabel.setText(groupName);
textlabel.setGravity(Gravity.START);
/* textlabel.setGravity(Gravity.START);
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
llp.setMargins(10, 0, 0, 0); // llp.setMargins(left, top, right, bottom);
textlabel.setLayoutParams(llp);
textlabel.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.linearBlockBackground));
TextViewCompat.setTextAppearance(textlabel, android.R.style.TextAppearance_Medium);
TextViewCompat.setTextAppearance(textlabel, android.R.style.TextAppearance_Medium);*/
layout.addView(textlabel);

View file

@ -33,21 +33,19 @@ public class SWUrl extends SWItem {
this.groupName = name;
}
@Override
public void generateDialog(View view) {
Context context = view.getContext();
LinearLayout layout = (LinearLayout) view.findViewById(view.getId());
layout.removeAllViews();
TextView textlabel = new TextView(context);
textlabel.setText(groupName);
textlabel.setGravity(Gravity.START);
/*textlabel.setGravity(Gravity.START);
LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
llp.setMargins(10, 0, 0, 0); // llp.setMargins(left, top, right, bottom);
textlabel.setLayoutParams(llp);
textlabel.setBackgroundColor(ContextCompat.getColor(MainApp.instance(), R.color.linearBlockBackground));
TextViewCompat.setTextAppearance(textlabel, android.R.style.TextAppearance_Medium);
TextViewCompat.setTextAppearance(textlabel, android.R.style.TextAppearance_Medium);*/
layout.addView(textlabel);
for (int row = 0; row < 1; row++) {
for (int i = 0; i < labels.size(); i++) {
if(values.get(i) != "" && values.get(i) != null) {

View file

@ -166,14 +166,11 @@ public class SetupWizardActivity extends AppCompatActivity {
} else if(currentItem.type == RADIOBUTTON){
// generate layout dynamically
SWRadioButton radioGroupItems = (SWRadioButton) currentItem;
radioGroupItems.setName(currentScreen.getHeader());
radioGroupItems.setOptions(radioGroupItems.labels(), radioGroupItems.values());
radioGroupItems.generateDialog(this.findViewById(R.id.fullscreen_content_fields));
}
if(labels.size() > 0){
// we have some labels lets display them
SWUrl swUrl = new SWUrl();
swUrl.setName(currentScreen.getHeader());
swUrl.setOptions(labels, comments);
swUrl.generateDialog(this.findViewById(R.id.fullscreen_content_fields));
}

View file

@ -1011,4 +1011,5 @@
<string name="setupwizard_previous">Prev</string>
<string name="setupwizard_skip">Skip</string>
<string name="setupwizard_finish">FINISH</string>
<string name="setupwizard_language_prompt">Select your language</string>
</resources>