moved show() method to SWItem classes
This commit is contained in:
parent
dda7ca3f95
commit
7fb1b32188
|
@ -1,11 +1,25 @@
|
||||||
package info.nightscout.androidaps.startupwizard;
|
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.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
|
||||||
public class SWRadioButton extends SWItem {
|
public class SWRadioButton extends SWItem {
|
||||||
|
|
||||||
int labelsArray;
|
int labelsArray;
|
||||||
int valuesArray;
|
int valuesArray;
|
||||||
|
String groupName = "";
|
||||||
|
String[] labels;
|
||||||
|
String[] values;
|
||||||
|
|
||||||
public SWRadioButton() {
|
public SWRadioButton() {
|
||||||
super(Type.RADIOBUTTON);
|
super(Type.RADIOBUTTON);
|
||||||
|
@ -17,6 +31,19 @@ public class SWRadioButton extends SWItem {
|
||||||
return this;
|
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() {
|
public String[] labels() {
|
||||||
return MainApp.sResources.getStringArray(labelsArray);
|
return MainApp.sResources.getStringArray(labelsArray);
|
||||||
}
|
}
|
||||||
|
@ -25,4 +52,38 @@ public class SWRadioButton extends SWItem {
|
||||||
return MainApp.sResources.getStringArray(valuesArray);
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,63 @@
|
||||||
package info.nightscout.androidaps.startupwizard;
|
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 {
|
public class SWString extends SWItem {
|
||||||
|
private List<String> labels;
|
||||||
|
private List<String> values;
|
||||||
|
private String groupName;
|
||||||
|
|
||||||
public SWString() {
|
public SWString() {
|
||||||
super(Type.STRING);
|
super(Type.STRING);
|
||||||
}
|
}
|
||||||
|
public void setOptions(List<String> labels, List<String> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,8 +1,64 @@
|
||||||
package info.nightscout.androidaps.startupwizard;
|
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 {
|
public class SWUrl extends SWItem {
|
||||||
|
|
||||||
|
private List<String> labels;
|
||||||
|
private List<String> values;
|
||||||
|
private String groupName;
|
||||||
public SWUrl() {
|
public SWUrl() {
|
||||||
super(Type.URL);
|
super(Type.URL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setOptions(List<String> labels, List<String> 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,32 +1,24 @@
|
||||||
package info.nightscout.androidaps.startupwizard;
|
package info.nightscout.androidaps.startupwizard;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
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.ActionBar;
|
||||||
import android.support.v7.app.AppCompatActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.view.Gravity;
|
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
|
||||||
import android.widget.LinearLayout;
|
import android.widget.LinearLayout;
|
||||||
import android.widget.RadioButton;
|
|
||||||
import android.widget.RadioGroup;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.text.NumberFormat;
|
import java.text.NumberFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
|
||||||
import static info.nightscout.androidaps.startupwizard.SWItem.Type.RADIOBUTTON;
|
import static info.nightscout.androidaps.startupwizard.SWItem.Type.RADIOBUTTON;
|
||||||
|
@ -60,30 +52,17 @@ public class SetupWizardActivity extends AppCompatActivity {
|
||||||
private LinearLayout linearLayout;
|
private LinearLayout linearLayout;
|
||||||
private TextView radioLabel;
|
private TextView radioLabel;
|
||||||
private int numberOfButtons = 0;
|
private int numberOfButtons = 0;
|
||||||
private String[] labels;
|
private List<String> labels = new ArrayList<String>();
|
||||||
private Context context;
|
private List<String> comments = new ArrayList<String>();
|
||||||
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 LinearLayout layout;
|
||||||
private TextView textlabel;
|
private TextView textlabel;
|
||||||
private TextView screenName;
|
private TextView screenName;
|
||||||
private TextView label1;
|
|
||||||
private EditText editText1;
|
|
||||||
private TextView label2;
|
|
||||||
private EditText editText2;
|
|
||||||
private Button skipButton;
|
private Button skipButton;
|
||||||
//logiing
|
//logiing
|
||||||
private static Logger log = LoggerFactory.getLogger(SetupWizardActivity.class);
|
private static Logger log = LoggerFactory.getLogger(SetupWizardActivity.class);
|
||||||
|
|
||||||
private int currentWizzardPage = 0;
|
private int currentWizardPage = 0;
|
||||||
public static final String INTENT_MESSAGE = "WIZZARDPAGE";
|
public static final String INTENT_MESSAGE = "WIZZARDPAGE";
|
||||||
private final Runnable mHidePart2Runnable = new Runnable() {
|
private final Runnable mHidePart2Runnable = new Runnable() {
|
||||||
@SuppressLint("InlinedApi")
|
@SuppressLint("InlinedApi")
|
||||||
|
@ -181,26 +160,23 @@ public class SetupWizardActivity extends AppCompatActivity {
|
||||||
}
|
}
|
||||||
for(int i = 0; i < currentScreen.items.size(); i++){
|
for(int i = 0; i < currentScreen.items.size(); i++){
|
||||||
SWItem currentItem = currentScreen.items.get(i);
|
SWItem currentItem = currentScreen.items.get(i);
|
||||||
if(currentItem.type == URL){
|
if(currentItem.type == URL || currentItem.type == STRING){
|
||||||
label1 = (TextView) findViewById(R.id.textLabel1);
|
labels.add(currentItem.getLabel());
|
||||||
editText1 = (EditText) findViewById(R.id.editText1);
|
comments.add(currentItem.getComment());
|
||||||
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);
|
|
||||||
} else if(currentItem.type == RADIOBUTTON){
|
} else if(currentItem.type == RADIOBUTTON){
|
||||||
// generate layout dynamically
|
// generate layout dynamically
|
||||||
SWRadioButton radioGroupItems = (SWRadioButton) currentItem;
|
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);
|
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) {
|
public void showNextPage(View view) {
|
||||||
Intent intent = new Intent(this, SetupWizardActivity.class);
|
Intent intent = new Intent(this, SetupWizardActivity.class);
|
||||||
intent.putExtra(INTENT_MESSAGE, currentWizzardPage + 1);
|
intent.putExtra(INTENT_MESSAGE, currentWizardPage + 1);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void showPreviousPage(View view) {
|
public void showPreviousPage(View view) {
|
||||||
Intent intent = new Intent(this, SetupWizardActivity.class);
|
Intent intent = new Intent(this, SetupWizardActivity.class);
|
||||||
if(currentWizzardPage > 0)
|
if(currentWizardPage > 0)
|
||||||
intent.putExtra(INTENT_MESSAGE, currentWizzardPage - 1);
|
intent.putExtra(INTENT_MESSAGE, currentWizardPage - 1);
|
||||||
else
|
else
|
||||||
intent.putExtra(INTENT_MESSAGE, 0);
|
intent.putExtra(INTENT_MESSAGE, 0);
|
||||||
startActivity(intent);
|
startActivity(intent);
|
||||||
|
|
|
@ -33,38 +33,6 @@
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:orientation="vertical">
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/textLabel1"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="TextLabel"
|
|
||||||
android:visibility="gone"/>
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/editText1"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:ems="10"
|
|
||||||
android:inputType="text|text"
|
|
||||||
android:text="Enter your setting here"
|
|
||||||
android:visibility="gone"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/textLabel2"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:text="TextLabel2"
|
|
||||||
android:visibility="gone"/>
|
|
||||||
|
|
||||||
<EditText
|
|
||||||
android:id="@+id/editText2"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:ems="10"
|
|
||||||
android:inputType="text|text"
|
|
||||||
android:text="Enter your setting here"
|
|
||||||
android:visibility="gone"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|
Loading…
Reference in a new issue