Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved UI Of Config Activity #1977

Merged
merged 1 commit into from
Oct 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions app/src/main/java/io/pslab/CheckBoxGetter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.pslab;

import java.io.Serializable;

public class CheckBoxGetter implements Serializable {

private String name;
private boolean isSelected;

public CheckBoxGetter(String name, boolean isSelected) {
this.name = name;
this.isSelected = isSelected;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public boolean isSelected() {
return isSelected;
}

public void setSelected(boolean selected) {
isSelected = selected;
}
}
35 changes: 19 additions & 16 deletions app/src/main/java/io/pslab/activity/CreateConfigActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@
import android.os.Environment;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.Toolbar;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.Toast;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import io.pslab.CheckBoxGetter;
import io.pslab.R;
import io.pslab.adapters.CheckBoxAdapter;
import io.pslab.others.CSVLogger;
import io.pslab.others.CustomSnackBar;

Expand All @@ -36,7 +38,8 @@ public class CreateConfigActivity extends AppCompatActivity {
private EditText intervalEditText;
private String interval;
private View rootView;
private LinearLayout paramsListContainer;
private RecyclerView paramsListContainer;
private List<CheckBoxGetter> list;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -58,6 +61,8 @@ protected void onCreate(Bundle savedInstanceState) {
instrumentsList = new ArrayList<>();
instrumentParamsList = new ArrayList<>();
instrumentParamsListTitles = new ArrayList<>();
paramsListContainer.setLayoutManager(new LinearLayoutManager(this));
list = new ArrayList<>();
createArrayLists();
selectInstrumentSpinner.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, instrumentsList));
selectInstrumentSpinner.setSelection(0, true);
Expand Down Expand Up @@ -97,9 +102,9 @@ public void onClick(View v) {
Toast.makeText(CreateConfigActivity.this, getResources().getString(R.string.no_interval_message), Toast.LENGTH_SHORT).show();
} else {
ArrayList<String> selectedParamsList = new ArrayList<>();
for (int i = 0; i < paramsListContainer.getChildCount(); i ++) {
CheckBox checkBox = (CheckBox) paramsListContainer.getChildAt(i);
if (checkBox.isChecked()) {
for (int i = 0; i < paramsListContainer.getChildCount(); i++) {
boolean checkBox = list.get(i).isSelected();
if (checkBox) {
selectedParamsList.add(instrumentParamsList.get(selectedItem)[i]);
}
}
Expand Down Expand Up @@ -134,17 +139,15 @@ private void createArrayLists() {
}

private void createCheckboxList() {
paramsListContainer.removeAllViews();
list.clear();
String[] params = instrumentParamsListTitles.get(selectedItem);
for (int i = 0; i < params.length; i++){
CheckBox checkBox = new CheckBox(CreateConfigActivity.this);
checkBox.setText(params[i]);
LinearLayout.LayoutParams checkBoxParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,LinearLayout.LayoutParams.WRAP_CONTENT);
checkBoxParams.gravity = Gravity.CENTER_HORIZONTAL;
checkBoxParams.setMargins(0,(int)getResources().getDimension(R.dimen.create_config_margin1),0,0);
checkBox.setLayoutParams(checkBoxParams);
paramsListContainer.addView(checkBox, i);
for (int i = 0; i < params.length; i++) {
CheckBoxGetter check = new CheckBoxGetter(params[i], false);
list.add(check);
}
CheckBoxAdapter box;
box = new CheckBoxAdapter(CreateConfigActivity.this, list);
paramsListContainer.setAdapter(box);
}

@Override
Expand Down
75 changes: 75 additions & 0 deletions app/src/main/java/io/pslab/adapters/CheckBoxAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package io.pslab.adapters;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import io.pslab.CheckBoxGetter;
import io.pslab.R;


public class CheckBoxAdapter extends RecyclerView.Adapter<CheckBoxAdapter.CheckBoxHolder> {

private Context boxcontext;
private List<CheckBoxGetter> list = new ArrayList<>();

public CheckBoxAdapter(Context boxcontext, List<CheckBoxGetter> list) {
this.boxcontext = boxcontext;
this.list = list;
}

@Override
public CheckBoxHolder onCreateViewHolder(ViewGroup parent, int viewType) {

View view = LayoutInflater.from(boxcontext).inflate(R.layout.item_checkbox, parent, false);
return new CheckBoxHolder(view);
}

@Override
public void onBindViewHolder(final CheckBoxHolder holder, final int position) {

final CheckBoxGetter check = list.get(position);

holder.tv_name.setText(check.getName());

holder.checkBox.setChecked(check.isSelected());
holder.checkBox.setTag(list.get(position));

holder.checkBox.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
CheckBoxGetter check1 = (CheckBoxGetter) holder.checkBox.getTag();
check1.setSelected(holder.checkBox.isChecked());
list.get(position).setSelected(holder.checkBox.isChecked());
}
});
}

@Override
public int getItemCount() {
return list.size();
}

public List<CheckBoxGetter> getCheckList() {
return list;
}

public static class CheckBoxHolder extends RecyclerView.ViewHolder {

private TextView tv_name;
private CheckBox checkBox;

public CheckBoxHolder(View itemView) {
super(itemView);
tv_name = itemView.findViewById(R.id.tv_checkbox);
checkBox = itemView.findViewById(R.id.checkBox_select);
}
}
}
98 changes: 50 additions & 48 deletions app/src/main/res/layout/activity_create_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,84 +12,86 @@
android:layout_height="wrap_content"
android:layout_below="@+id/top_app_bar_layout">

<RelativeLayout
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/home_fragment_padding">
android:orientation="vertical"
android:padding="@dimen/config_activity_padding">

<TextView
android:id="@+id/select_instrument_title"
style="@style/Base.TextAppearance.AppCompat.Title"
android:layout_width="wrap_content"
<LinearLayout
android:id="@+id/select_instrument"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/create_config_margin4"
android:text="@string/select_instrument_title" />
android:orientation="horizontal">

<android.support.v7.widget.AppCompatSpinner
android:id="@+id/select_instrument_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/select_instrument_title" />
<TextView
android:id="@+id/select_instrument_title"
style="@style/Base.TextAppearance.AppCompat.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/select_instrument_title" />

<TextView
android:id="@+id/time_interval_title"
style="@style/Base.TextAppearance.AppCompat.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/select_instrument_title"
android:layout_marginTop="@dimen/create_config_margin3"
android:text="@string/time_interval_title" />
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/select_instrument_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<EditText
android:id="@+id/interval_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/select_instrument_title"
android:layout_marginStart="@dimen/margin_btn"
android:layout_marginTop="@dimen/create_config_margin1"
android:layout_toEndOf="@id/time_interval_title"
android:hint="@string/time_interval_hint"
android:inputType="number" />
</LinearLayout>

<android.support.v7.widget.AppCompatSpinner
android:id="@+id/interval_unit_spinner"
android:layout_width="wrap_content"
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/select_instrument_title"
android:layout_marginStart="@dimen/margin_btn"
android:layout_marginTop="@dimen/create_config_margin1"
android:layout_toEndOf="@+id/interval_edit_text" />
android:orientation="horizontal">

<TextView
android:id="@+id/time_interval_title"
style="@style/Base.TextAppearance.AppCompat.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/time_interval_title" />

<EditText
android:id="@+id/interval_edit_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="@string/time_interval_hint"
android:imeOptions="actionDone"
android:inputType="number"
android:textAlignment="center" />

<android.support.v7.widget.AppCompatSpinner
android:id="@+id/interval_unit_spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

<TextView
android:id="@+id/select_params_title"
style="@style/Base.TextAppearance.AppCompat.Title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/time_interval_title"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:layout_marginTop="@dimen/create_config_margin2"
android:text="@string/select_params_title" />

<LinearLayout
<android.support.v7.widget.RecyclerView
android:id="@+id/params_list_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/select_params_title"
android:orientation="vertical">
</LinearLayout>
android:layout_height="@dimen/create_config_recycler_view"
android:layout_marginTop="@dimen/create_config_margin1" />

<Button
android:id="@+id/create_config_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/params_list_container"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:layout_marginTop="@dimen/create_config_margin2"
android:background="@drawable/btn_back_rounded"
android:padding="@dimen/margin_btn"
android:layout_marginTop="@dimen/create_config_margin2"
android:text="@string/create_config_btn_text"
android:textColor="@color/white" />
</RelativeLayout>
</LinearLayout>

</ScrollView>

Expand Down
29 changes: 29 additions & 0 deletions app/src/main/res/layout/item_checkbox.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/check_box_magin"
android:layout_marginBottom="@dimen/check_box_magin"
app:cardCornerRadius="@dimen/check_box_corner">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<TextView
android:id="@+id/tv_checkbox"
android:layout_width="@dimen/check_box_width"
android:layout_height="wrap_content"
android:layout_weight="1"
android:padding="@dimen/create_config_margin2" />

<CheckBox
android:id="@+id/checkBox_select"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>

</android.support.v7.widget.CardView>
5 changes: 5 additions & 0 deletions app/src/main/res/values/dimens.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<dimen name="device_status_width">80dp</dimen>
<dimen name="device_status_height">80dp</dimen>
<dimen name="device_status_textsize">20sp</dimen>
<dimen name="config_activity_padding">9dp</dimen>

<dimen name="multimeter_layout_margin">20dp</dimen>
<dimen name="multimeter_line_width">1dp</dimen>
Expand Down Expand Up @@ -356,6 +357,10 @@
<dimen name="create_config_margin2">20dp</dimen>
<dimen name="create_config_margin3">22dp</dimen>
<dimen name="create_config_margin4">12dp</dimen>
<dimen name="create_config_recycler_view">280dp</dimen>
<dimen name="check_box_width">0dp</dimen>
<dimen name="check_box_magin">4dp</dimen>
<dimen name="check_box_corner">5dp</dimen>
<dimen name="sensor_sht21_margin">5dp</dimen>
<dimen name="sht21_height">40dp</dimen>
<dimen name="card_sht21_height">180dp</dimen>
Expand Down