From 7fb1b321885bb5df54803057a79ac820548bdf3b Mon Sep 17 00:00:00 2001 From: Roumen Georgiev Date: Wed, 25 Apr 2018 15:29:20 +0300 Subject: [PATCH] moved show() method to SWItem classes --- .../startupwizard/SWRadioButton.java | 61 +++++++++++ .../androidaps/startupwizard/SWString.java | 55 ++++++++++ .../androidaps/startupwizard/SWUrl.java | 56 ++++++++++ .../startupwizard/SetupWizardActivity.java | 101 ++++-------------- .../main/res/layout/activity_setupwizard.xml | 32 ------ 5 files changed, 193 insertions(+), 112 deletions(-) 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 5dc5c74438..af7a0fdab4 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWRadioButton.java @@ -1,11 +1,25 @@ 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; +import android.widget.RadioGroup; +import android.widget.TextView; + import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; public class SWRadioButton extends SWItem { int labelsArray; int valuesArray; + String groupName = ""; + String[] labels; + String[] values; public SWRadioButton() { super(Type.RADIOBUTTON); @@ -17,6 +31,19 @@ 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); } @@ -25,4 +52,38 @@ public class SWRadioButton extends SWItem { return MainApp.sResources.getStringArray(valuesArray); } + public void show(View view){ + Context context = view.getContext(); +// LinearLayout layout = (LinearLayout) new LinearLayout(context); + LinearLayout layout = (LinearLayout) view.findViewById(view.getId()); + layout.removeAllViews(); + + TextView textlabel = new TextView(context); + textlabel.setText(groupName); + 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(context); + for (int row = 0; row < 1; row++) { + + rg.setOrientation(LinearLayout.VERTICAL); + rg.setVisibility(View.VISIBLE); + + for (int i = 0; i < labels.length; i++) { + RadioButton rdbtn = new RadioButton(context); + rdbtn.setId((row * 2) + i); + rdbtn.setText(labels[i]); + 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 1378ca8e0f..46044c9e18 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWString.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWString.java @@ -1,8 +1,63 @@ package info.nightscout.androidaps.startupwizard; +import android.content.Context; +import android.support.v4.content.ContextCompat; +import android.support.v4.widget.TextViewCompat; +import android.text.InputType; +import android.view.Gravity; +import android.view.View; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.TextView; + +import java.util.List; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; + public class SWString extends SWItem { + private List labels; + private List values; + private String groupName; public SWString() { super(Type.STRING); } + public void setOptions(List labels, List values){ + this.labels = labels; + this.values = values; + } + + public void setName(String name){ + this.groupName = name; + } + public void show(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); + 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); + + 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) { + EditText editText = new EditText(context); + editText.setId((row * 2) + i); + editText.setText(values.get(i)); + editText.setInputType(InputType.TYPE_CLASS_TEXT); + editText.setMaxLines(1); + layout.addView(editText); + } + } + } + } } 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 d9ad6076ca..873cdf3506 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SWUrl.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SWUrl.java @@ -1,8 +1,64 @@ package info.nightscout.androidaps.startupwizard; +import android.content.Context; +import android.support.v4.content.ContextCompat; +import android.support.v4.widget.TextViewCompat; +import android.text.InputType; +import android.view.Gravity; +import android.view.View; +import android.widget.EditText; +import android.widget.LinearLayout; +import android.widget.TextView; + +import java.util.List; + +import info.nightscout.androidaps.MainApp; +import info.nightscout.androidaps.R; + public class SWUrl extends SWItem { + private List labels; + private List values; + private String groupName; public SWUrl() { super(Type.URL); } + + public void setOptions(List labels, List values){ + this.labels = labels; + this.values = values; + } + + public void setName(String name){ + this.groupName = name; + } + + public void show(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); + 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); + + 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) { + EditText editText = new EditText(context); + editText.setId((row * 2) + i); + editText.setText(values.get(i)); + editText.setInputType(InputType.TYPE_CLASS_TEXT); + editText.setMaxLines(1); + layout.addView(editText); + } + } + } + } } 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 14f2f1987a..1696225d05 100644 --- a/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/startupwizard/SetupWizardActivity.java @@ -1,32 +1,24 @@ 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; -import android.widget.EditText; import android.widget.LinearLayout; -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.ArrayList; import java.util.List; -import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.R; import static info.nightscout.androidaps.startupwizard.SWItem.Type.RADIOBUTTON; @@ -60,30 +52,17 @@ public class SetupWizardActivity extends AppCompatActivity { 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 List labels = new ArrayList(); + private List comments = new ArrayList(); + 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; + private int currentWizardPage = 0; public static final String INTENT_MESSAGE = "WIZZARDPAGE"; private final Runnable mHidePart2Runnable = new Runnable() { @SuppressLint("InlinedApi") @@ -181,26 +160,23 @@ 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); - label1.setText(currentItem.getLabel()); - label1.setVisibility(View.VISIBLE); - editText1.setText(currentItem.getComment()); - editText1.setVisibility(View.VISIBLE); - } else if(currentItem.type == STRING){ - label2 = (TextView) findViewById(R.id.textLabel2); - editText2 = (EditText) findViewById(R.id.editText2); - label2.setText(currentItem.getLabel()); - label2.setVisibility(View.VISIBLE); - editText2.setText(currentItem.getComment()); - editText2.setVisibility(View.VISIBLE); + if(currentItem.type == URL || currentItem.type == STRING){ + labels.add(currentItem.getLabel()); + comments.add(currentItem.getComment()); } else if(currentItem.type == RADIOBUTTON){ // generate layout dynamically SWRadioButton radioGroupItems = (SWRadioButton) currentItem; - addRadioButtons(currentScreen.getHeader(), radioGroupItems.labels().length, radioGroupItems.labels(), radioGroupItems.values()); + radioGroupItems.setName(currentScreen.getHeader()); + radioGroupItems.setOptions(radioGroupItems.labels(), radioGroupItems.values()); + radioGroupItems.show(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.show(this.findViewById(R.id.fullscreen_content_fields)); } - } @@ -265,53 +241,18 @@ public class SetupWizardActivity extends AppCompatActivity { mHideHandler.postDelayed(mHideRunnable, delayMillis); } - 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++) { - - 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(labels[i]); - rg.addView(rdbtn); - } - } - layout.addView(textlabel); - layout.addView(rg); - - - - } public void showNextPage(View view) { Intent intent = new Intent(this, SetupWizardActivity.class); - intent.putExtra(INTENT_MESSAGE, currentWizzardPage + 1); + intent.putExtra(INTENT_MESSAGE, currentWizardPage + 1); startActivity(intent); } public void showPreviousPage(View view) { Intent intent = new Intent(this, SetupWizardActivity.class); - if(currentWizzardPage > 0) - intent.putExtra(INTENT_MESSAGE, currentWizzardPage - 1); + if(currentWizardPage > 0) + intent.putExtra(INTENT_MESSAGE, currentWizardPage - 1); else intent.putExtra(INTENT_MESSAGE, 0); startActivity(intent); diff --git a/app/src/main/res/layout/activity_setupwizard.xml b/app/src/main/res/layout/activity_setupwizard.xml index 7f4e89b4a4..8b33b18422 100644 --- a/app/src/main/res/layout/activity_setupwizard.xml +++ b/app/src/main/res/layout/activity_setupwizard.xml @@ -33,38 +33,6 @@ android:layout_height="match_parent" android:orientation="vertical"> - - - - - - - -