From 8333fe8975d4e73b9f58bdaae08e1f6aab531c37 Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Wed, 25 Apr 2018 16:45:15 +0300 Subject: [PATCH] get radiobutton values from arrays.xml & no header --- .../startupwizard/SWDefinition.java | 5 +++ .../androidaps/startupwizard/SWItem.java | 6 ++++ .../startupwizard/SWRadioButton.java | 31 ++++--------------- .../androidaps/startupwizard/SWString.java | 6 ++-- .../androidaps/startupwizard/SWUrl.java | 8 ++--- .../startupwizard/SetupWizardActivity.java | 3 -- app/src/main/res/values/strings.xml | 1 + 7 files changed, 25 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java index 289c200431..9f2ae113a7 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWDefinition.java @@ -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)) + ) ; } diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWItem.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWItem.java index 4e41b4c0c7..43ea2c153b 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWItem.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWItem.java @@ -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){ + + } } diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java index a4c58edbc6..e5ba590387 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java @@ -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); } diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWString.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWString.java index afdb4581d2..214955c743 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWString.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWString.java @@ -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); diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWUrl.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWUrl.java index fe47957a2a..be9c32807b 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWUrl.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWUrl.java @@ -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) { diff --git a/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java b/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java index 8832931441..2d6dfaa14b 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java @@ -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)); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a44d438151..fc277a8ccb 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -1011,4 +1011,5 @@ Prev Skip FINISH + Select your language