Skip to content

Commit f23ea4b

Browse files
committed
Improved UI Of Config Activity
1 parent 1308834 commit f23ea4b

File tree

6 files changed

+219
-63
lines changed

6 files changed

+219
-63
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package io.pslab;
2+
3+
import java.io.Serializable;
4+
5+
public class CheckBoxGetter implements Serializable {
6+
7+
private String name;
8+
private boolean isSelected;
9+
10+
public CheckBoxGetter(String name, boolean isSelected) {
11+
this.name = name;
12+
this.isSelected = isSelected;
13+
}
14+
15+
public String getName() {
16+
return name;
17+
}
18+
19+
public void setName(String name) {
20+
this.name = name;
21+
}
22+
23+
public boolean isSelected() {
24+
return isSelected;
25+
}
26+
27+
public void setSelected(boolean selected) {
28+
isSelected = selected;
29+
}
30+
}

app/src/main/java/io/pslab/activity/CreateConfigActivity.java

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,27 @@
44
import android.os.Environment;
55
import android.support.design.widget.Snackbar;
66
import android.support.v7.app.AppCompatActivity;
7+
import android.support.v7.widget.LinearLayoutManager;
8+
import android.support.v7.widget.RecyclerView;
79
import android.support.v7.widget.Toolbar;
8-
import android.view.Gravity;
910
import android.view.MenuItem;
1011
import android.view.View;
1112
import android.widget.AdapterView;
1213
import android.widget.ArrayAdapter;
1314
import android.widget.Button;
14-
import android.widget.CheckBox;
1515
import android.widget.EditText;
16-
import android.widget.LinearLayout;
1716
import android.widget.Spinner;
1817
import android.widget.Toast;
1918

2019
import java.io.File;
2120
import java.io.FileWriter;
2221
import java.io.IOException;
2322
import java.util.ArrayList;
23+
import java.util.List;
2424

25+
import io.pslab.CheckBoxGetter;
2526
import io.pslab.R;
27+
import io.pslab.adapters.CheckBoxAdapter;
2628
import io.pslab.others.CSVLogger;
2729
import io.pslab.others.CustomSnackBar;
2830

@@ -36,7 +38,8 @@ public class CreateConfigActivity extends AppCompatActivity {
3638
private EditText intervalEditText;
3739
private String interval;
3840
private View rootView;
39-
private LinearLayout paramsListContainer;
41+
private RecyclerView paramsListContainer;
42+
private List<CheckBoxGetter> list;
4043

4144
@Override
4245
protected void onCreate(Bundle savedInstanceState) {
@@ -58,6 +61,8 @@ protected void onCreate(Bundle savedInstanceState) {
5861
instrumentsList = new ArrayList<>();
5962
instrumentParamsList = new ArrayList<>();
6063
instrumentParamsListTitles = new ArrayList<>();
64+
paramsListContainer.setLayoutManager(new LinearLayoutManager(this));
65+
list = new ArrayList<>();
6166
createArrayLists();
6267
selectInstrumentSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, instrumentsList));
6368
selectInstrumentSpinner.setSelection(0, true);
@@ -97,9 +102,9 @@ public void onClick(View v) {
97102
Toast.makeText(CreateConfigActivity.this, getResources().getString(R.string.no_interval_message), Toast.LENGTH_SHORT).show();
98103
} else {
99104
ArrayList<String> selectedParamsList = new ArrayList<>();
100-
for (int i = 0; i < paramsListContainer.getChildCount(); i ++) {
101-
CheckBox checkBox = (CheckBox) paramsListContainer.getChildAt(i);
102-
if (checkBox.isChecked()) {
105+
for (int i = 0; i < paramsListContainer.getChildCount(); i++) {
106+
boolean checkBox = paramsListContainer.getChildAt(i).isSelected();
107+
if (checkBox) {
103108
selectedParamsList.add(instrumentParamsList.get(selectedItem)[i]);
104109
}
105110
}
@@ -134,17 +139,17 @@ private void createArrayLists() {
134139
}
135140

136141
private void createCheckboxList() {
137-
paramsListContainer.removeAllViews();
142+
list.clear();
138143
String[] params = instrumentParamsListTitles.get(selectedItem);
139-
for (int i = 0; i < params.length; i++){
140-
CheckBox checkBox = new CheckBox(CreateConfigActivity.this);
141-
checkBox.setText(params[i]);
142-
LinearLayout.LayoutParams checkBoxParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
143-
checkBoxParams.gravity = Gravity.CENTER_HORIZONTAL;
144-
checkBoxParams.setMargins(0,(int)getResources().getDimension(R.dimen.create_config_margin1),0,0);
145-
checkBox.setLayoutParams(checkBoxParams);
146-
paramsListContainer.addView(checkBox, i);
144+
for (int i = 0; i < params.length; i++) {
145+
146+
CheckBoxGetter check = new CheckBoxGetter(params[i], false);
147+
list.add(check);
147148
}
149+
CheckBoxAdapter box;
150+
box = new CheckBoxAdapter(CreateConfigActivity.this, list);
151+
paramsListContainer.setAdapter(box);
152+
148153
}
149154

150155
@Override
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package io.pslab.adapters;
2+
3+
import android.content.Context;
4+
import android.support.v7.widget.RecyclerView;
5+
import android.view.LayoutInflater;
6+
import android.view.View;
7+
import android.view.ViewGroup;
8+
import android.widget.CheckBox;
9+
import android.widget.TextView;
10+
11+
import java.util.ArrayList;
12+
import java.util.List;
13+
14+
import io.pslab.CheckBoxGetter;
15+
import io.pslab.R;
16+
17+
18+
public class CheckBoxAdapter extends RecyclerView.Adapter<CheckBoxAdapter.CheckBoxHolder> {
19+
20+
private Context boxcontext;
21+
private List<CheckBoxGetter> list = new ArrayList<>();
22+
23+
public CheckBoxAdapter(Context boxcontext, List<CheckBoxGetter> list) {
24+
this.boxcontext = boxcontext;
25+
this.list = list;
26+
}
27+
28+
@Override
29+
public CheckBoxHolder onCreateViewHolder(ViewGroup parent, int viewType) {
30+
31+
View view = LayoutInflater.from(boxcontext).inflate(R.layout.item_checkbox, parent, false);
32+
33+
return new CheckBoxHolder(view);
34+
}
35+
36+
@Override
37+
public void onBindViewHolder(final CheckBoxHolder holder, final int position) {
38+
39+
final CheckBoxGetter check = list.get(position);
40+
41+
holder.tv_name.setText(check.getName());
42+
43+
holder.checkBox.setChecked(check.isSelected());
44+
holder.checkBox.setTag(list.get(position));
45+
46+
holder.checkBox.setOnClickListener(new View.OnClickListener() {
47+
@Override
48+
public void onClick(View view) {
49+
String data = "";
50+
CheckBoxGetter fruits1 = (CheckBoxGetter) holder.checkBox.getTag();
51+
52+
fruits1.setSelected(holder.checkBox.isChecked());
53+
54+
list.get(position).setSelected(holder.checkBox.isChecked());
55+
56+
for (int j = 0; j < list.size(); j++) {
57+
58+
if (list.get(j).isSelected()) {
59+
data = data + "\n" + list.get(j).getName();
60+
}
61+
}
62+
}
63+
});
64+
}
65+
66+
@Override
67+
public int getItemCount() {
68+
return list.size();
69+
}
70+
71+
public List<CheckBoxGetter> getFruitsList() {
72+
return list;
73+
}
74+
75+
public static class CheckBoxHolder extends RecyclerView.ViewHolder {
76+
77+
private TextView tv_name;
78+
private CheckBox checkBox;
79+
80+
public CheckBoxHolder(View itemView) {
81+
super(itemView);
82+
83+
tv_name = itemView.findViewById(R.id.tv_checkbox);
84+
checkBox = itemView.findViewById(R.id.checkBox_select);
85+
}
86+
}
87+
}

app/src/main/res/layout/activity_create_config.xml

Lines changed: 49 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -12,84 +12,86 @@
1212
android:layout_height="wrap_content"
1313
android:layout_below="@+id/top_app_bar_layout">
1414

15-
<RelativeLayout
15+
<LinearLayout
1616
android:layout_width="match_parent"
1717
android:layout_height="wrap_content"
18+
android:orientation="vertical"
1819
android:padding="@dimen/home_fragment_padding">
1920

20-
<TextView
21-
android:id="@+id/select_instrument_title"
22-
style="@style/Base.TextAppearance.AppCompat.Title"
23-
android:layout_width="wrap_content"
21+
<LinearLayout
22+
android:id="@+id/select_instrument"
23+
android:layout_width="match_parent"
2424
android:layout_height="wrap_content"
25-
android:layout_marginTop="@dimen/create_config_margin4"
26-
android:text="@string/select_instrument_title" />
25+
android:orientation="horizontal">
2726

28-
<android.support.v7.widget.AppCompatSpinner
29-
android:id="@+id/select_instrument_spinner"
30-
android:layout_width="wrap_content"
31-
android:layout_height="wrap_content"
32-
android:layout_toEndOf="@id/select_instrument_title" />
27+
<TextView
28+
android:id="@+id/select_instrument_title"
29+
style="@style/Base.TextAppearance.AppCompat.Title"
30+
android:layout_width="wrap_content"
31+
android:layout_height="wrap_content"
32+
android:text="@string/select_instrument_title" />
3333

34-
<TextView
35-
android:id="@+id/time_interval_title"
36-
style="@style/Base.TextAppearance.AppCompat.Title"
37-
android:layout_width="wrap_content"
38-
android:layout_height="wrap_content"
39-
android:layout_below="@+id/select_instrument_title"
40-
android:layout_marginTop="@dimen/create_config_margin3"
41-
android:text="@string/time_interval_title" />
34+
<android.support.v7.widget.AppCompatSpinner
35+
android:id="@+id/select_instrument_spinner"
36+
android:layout_width="wrap_content"
37+
android:layout_height="wrap_content" />
4238

43-
<EditText
44-
android:id="@+id/interval_edit_text"
45-
android:layout_width="wrap_content"
46-
android:layout_height="wrap_content"
47-
android:layout_below="@id/select_instrument_title"
48-
android:layout_marginStart="@dimen/margin_btn"
49-
android:layout_marginTop="@dimen/create_config_margin1"
50-
android:layout_toEndOf="@id/time_interval_title"
51-
android:hint="@string/time_interval_hint"
52-
android:inputType="number" />
39+
</LinearLayout>
5340

54-
<android.support.v7.widget.AppCompatSpinner
55-
android:id="@+id/interval_unit_spinner"
56-
android:layout_width="wrap_content"
41+
<LinearLayout
42+
android:layout_width="match_parent"
5743
android:layout_height="wrap_content"
58-
android:layout_below="@+id/select_instrument_title"
59-
android:layout_marginStart="@dimen/margin_btn"
6044
android:layout_marginTop="@dimen/create_config_margin1"
61-
android:layout_toEndOf="@+id/interval_edit_text" />
45+
android:orientation="horizontal">
46+
47+
<TextView
48+
android:id="@+id/time_interval_title"
49+
style="@style/Base.TextAppearance.AppCompat.Title"
50+
android:layout_width="wrap_content"
51+
android:layout_height="wrap_content"
52+
android:text="@string/time_interval_title" />
53+
54+
<EditText
55+
android:id="@+id/interval_edit_text"
56+
android:layout_width="wrap_content"
57+
android:layout_height="wrap_content"
58+
android:hint="@string/time_interval_hint"
59+
android:imeOptions="actionDone"
60+
android:inputType="number"
61+
android:textAlignment="center" />
62+
63+
<android.support.v7.widget.AppCompatSpinner
64+
android:id="@+id/interval_unit_spinner"
65+
android:layout_width="wrap_content"
66+
android:layout_height="wrap_content" />
67+
</LinearLayout>
6268

6369
<TextView
6470
android:id="@+id/select_params_title"
6571
style="@style/Base.TextAppearance.AppCompat.Title"
6672
android:layout_width="wrap_content"
6773
android:layout_height="wrap_content"
68-
android:layout_below="@id/time_interval_title"
69-
android:layout_centerHorizontal="true"
74+
android:layout_gravity="center"
7075
android:layout_marginTop="@dimen/create_config_margin2"
7176
android:text="@string/select_params_title" />
7277

73-
<LinearLayout
78+
<android.support.v7.widget.RecyclerView
7479
android:id="@+id/params_list_container"
7580
android:layout_width="match_parent"
76-
android:layout_height="wrap_content"
77-
android:layout_below="@+id/select_params_title"
78-
android:orientation="vertical">
79-
</LinearLayout>
81+
android:layout_height="@dimen/create_config_recycler_view"
82+
android:layout_marginTop="@dimen/create_config_margin1" />
8083

8184
<Button
8285
android:id="@+id/create_config_btn"
8386
android:layout_width="wrap_content"
8487
android:layout_height="wrap_content"
85-
android:layout_below="@+id/params_list_container"
86-
android:layout_centerHorizontal="true"
88+
android:layout_gravity="center"
89+
android:layout_marginTop="@dimen/create_config_margin2"
8790
android:background="@drawable/btn_back_rounded"
8891
android:padding="@dimen/margin_btn"
89-
android:layout_marginTop="@dimen/create_config_margin2"
9092
android:text="@string/create_config_btn_text"
9193
android:textColor="@color/white" />
92-
</RelativeLayout>
94+
</LinearLayout>
9395

9496
</ScrollView>
9597

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content"
6+
android:layout_margin="@dimen/check_box_magin"
7+
app:cardCornerRadius="@dimen/check_box_corner">
8+
9+
<LinearLayout
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content"
12+
android:orientation="horizontal">
13+
14+
<TextView
15+
android:id="@+id/tv_checkbox"
16+
android:layout_width="@dimen/check_box_width"
17+
android:layout_height="wrap_content"
18+
android:layout_weight="1"
19+
android:padding="@dimen/create_config_margin2" />
20+
21+
<CheckBox
22+
android:id="@+id/checkBox_select"
23+
android:layout_width="wrap_content"
24+
android:layout_height="wrap_content" />
25+
26+
</LinearLayout>
27+
28+
</android.support.v7.widget.CardView>

app/src/main/res/values/dimens.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,10 @@
356356
<dimen name="create_config_margin2">20dp</dimen>
357357
<dimen name="create_config_margin3">22dp</dimen>
358358
<dimen name="create_config_margin4">12dp</dimen>
359+
<dimen name="create_config_recycler_view">250dp</dimen>
360+
<dimen name="check_box_width">0dp</dimen>
361+
<dimen name="check_box_magin">10dp</dimen>
362+
<dimen name="check_box_corner">5dp</dimen>
359363
<dimen name="sensor_sht21_margin">5dp</dimen>
360364
<dimen name="sht21_height">40dp</dimen>
361365
<dimen name="card_sht21_height">180dp</dimen>

0 commit comments

Comments
 (0)