From dda7ca3f95ef77f4471eb4b73c9a2445745e767e Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Wed, 25 Apr 2018 11:03:33 +0300 Subject: [PATCH] radio group is generated dynamically --- .../startupwizard/SetupWizardActivity.java | 67 +++++++++++++++---- .../main/res/layout/activity_setupwizard.xml | 21 ------ 2 files changed, 55 insertions(+), 33 deletions(-) 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 b1a978936f..14f2f1987a 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java @@ -1,11 +1,15 @@ package info.nightscout.androidaps.startupwizard; import android.annotation.SuppressLint; +import android.content.Context; import android.content.Intent; +import android.support.v4.content.ContextCompat; +import android.support.v4.widget.TextViewCompat; import android.support.v7.app.ActionBar; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.os.Handler; +import android.view.Gravity; import android.view.MotionEvent; import android.view.View; import android.widget.Button; @@ -15,8 +19,14 @@ import android.widget.RadioButton; import android.widget.RadioGroup; import android.widget.TextView; +import org.json.JSONArray; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.text.NumberFormat; import java.util.List; +import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import static info.nightscout.androidaps.startupwizard.SWItem.Type.RADIOBUTTON; @@ -49,12 +59,30 @@ public class SetupWizardActivity extends AppCompatActivity { private View mContentView; private LinearLayout linearLayout; private TextView radioLabel; + private int numberOfButtons = 0; + private String[] labels; + private Context context; + private View view; + private int resLayoutId; + private String label; + private JSONArray data1; + private JSONArray data2; + private double step; + private double min; + private double max; + private NumberFormat formatter; + private Runnable save; + private LinearLayout layout; + private TextView textlabel; private TextView screenName; private TextView label1; private EditText editText1; private TextView label2; private EditText editText2; private Button skipButton; + //logiing + private static Logger log = LoggerFactory.getLogger(SetupWizardActivity.class); + private int currentWizzardPage = 0; public static final String INTENT_MESSAGE = "WIZZARDPAGE"; private final Runnable mHidePart2Runnable = new Runnable() { @@ -153,7 +181,6 @@ public class SetupWizardActivity extends AppCompatActivity { } for(int i = 0; i < currentScreen.items.size(); i++){ SWItem currentItem = currentScreen.items.get(i); - if(currentItem.type == URL){ label1 = (TextView) findViewById(R.id.textLabel1); editText1 = (EditText) findViewById(R.id.editText1); @@ -169,11 +196,9 @@ public class SetupWizardActivity extends AppCompatActivity { editText2.setText(currentItem.getComment()); editText2.setVisibility(View.VISIBLE); } else if(currentItem.type == RADIOBUTTON){ - ((LinearLayout) findViewById(R.id.radio_group_layout)).setVisibility(View.VISIBLE); - radioLabel = (TextView) findViewById(R.id.radio_group_label); - radioLabel.setText(currentScreen.getHeader()); + // generate layout dynamically SWRadioButton radioGroupItems = (SWRadioButton) currentItem; - addRadioButtons(radioGroupItems.labels().length, radioGroupItems.labels(), radioGroupItems.values()); + addRadioButtons(currentScreen.getHeader(), radioGroupItems.labels().length, radioGroupItems.labels(), radioGroupItems.values()); } } @@ -240,22 +265,40 @@ public class SetupWizardActivity extends AppCompatActivity { mHideHandler.postDelayed(mHideRunnable, delayMillis); } - public void addRadioButtons(int number, String[] labels, String[] values) { + private int itemsCount() { + return data1.length(); + } + public void addRadioButtons(String label, int number, String[] labels, String[] values) { + layout = (LinearLayout) findViewById(R.id.fullscreen_content_fields); + layout.removeAllViews(); + + textlabel = new TextView(this); + textlabel.setText(label); + 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); + + RadioGroup rg = new RadioGroup(this); for (int row = 0; row < 1; row++) { - RadioGroup ll = new RadioGroup(this); - ll.setOrientation(LinearLayout.VERTICAL); + + rg.setOrientation(LinearLayout.VERTICAL); + rg.setVisibility(View.VISIBLE); for (int i = 0; i < number; i++) { RadioButton rdbtn = new RadioButton(this); rdbtn.setId((row * 2) + i); -// rdbtn.setText("Radio " + rdbtn.getId()); rdbtn.setText(labels[i]); - ll.addView(rdbtn); + rg.addView(rdbtn); } - ((RadioGroup) findViewById(R.id.radiogroup)).addView(ll); - ((RadioGroup) findViewById(R.id.radiogroup)).setVisibility(View.VISIBLE); } + layout.addView(textlabel); + layout.addView(rg); + + } diff --git a/app/src/main/res/layout/activity_setupwizard.xml b/app/src/main/res/layout/activity_setupwizard.xml index 45d1ed1b44..7f4e89b4a4 100644 --- a/app/src/main/res/layout/activity_setupwizard.xml +++ b/app/src/main/res/layout/activity_setupwizard.xml @@ -65,27 +65,6 @@ android:text="Enter your setting here" android:visibility="gone"/> - - - - - - - -