Skip to content

Commit

Permalink
scroll added to create config layout (#1960)
Browse files Browse the repository at this point in the history
  • Loading branch information
neel1998 authored and mariobehling committed Aug 28, 2019
1 parent d23f44e commit 8b69f3e
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 76 deletions.
28 changes: 19 additions & 9 deletions app/src/main/java/io/pslab/activity/CreateConfigActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.util.SparseBooleanArray;
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.ListView;
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.Toast;

Expand All @@ -30,20 +31,20 @@ public class CreateConfigActivity extends AppCompatActivity {
private ArrayList<String> instrumentsList;
private ArrayList<String[]> instrumentParamsList;
private ArrayList<String[]> instrumentParamsListTitles;
private ListView paramsListView;
private int selectedItem = 0;
private String intervalUnit = "sec";
private EditText intervalEditText;
private String interval;
private View rootView;
private LinearLayout paramsListContainer;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_create_config);
Toolbar toolbar = findViewById(R.id.toolbar);
rootView = findViewById(R.id.create_config_root_view);
paramsListView = findViewById(R.id.params_list);
paramsListContainer = findViewById(R.id.params_list_container);
Spinner selectInstrumentSpinner = findViewById(R.id.select_instrument_spinner);
Spinner intervalUnitSpinner = findViewById(R.id.interval_unit_spinner);
intervalEditText = findViewById(R.id.interval_edit_text);
Expand Down Expand Up @@ -95,10 +96,10 @@ public void onClick(View v) {
if (interval.length() == 0) {
Toast.makeText(CreateConfigActivity.this, getResources().getString(R.string.no_interval_message), Toast.LENGTH_SHORT).show();
} else {
SparseBooleanArray selectedParams = paramsListView.getCheckedItemPositions();
ArrayList<String> selectedParamsList = new ArrayList<>();
for (int i = 0; i < paramsListView.getCount(); i++) {
if (selectedParams.get(i)) {
for (int i = 0; i < paramsListContainer.getChildCount(); i ++) {
CheckBox checkBox = (CheckBox) paramsListContainer.getChildAt(i);
if (checkBox.isChecked()) {
selectedParamsList.add(instrumentParamsList.get(selectedItem)[i]);
}
}
Expand Down Expand Up @@ -133,8 +134,17 @@ private void createArrayLists() {
}

private void createCheckboxList() {
paramsListView.setAdapter(new ArrayAdapter<String>(CreateConfigActivity.this, android.R.layout.simple_list_item_multiple_choice, instrumentParamsListTitles.get(selectedItem)));
paramsListView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
paramsListContainer.removeAllViews();
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);
}
}

@Override
Expand Down
141 changes: 74 additions & 67 deletions app/src/main/res/layout/activity_create_config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,84 +7,91 @@
android:layout_height="match_parent"
tools:context=".activity.CreateConfigActivity">

<RelativeLayout
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/top_app_bar_layout"
android:padding="@dimen/home_fragment_padding">
android:layout_below="@+id/top_app_bar_layout">

<TextView
android:id="@+id/select_instrument_title"
style="@style/Base.TextAppearance.AppCompat.Title"
android:layout_width="wrap_content"
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/create_config_margin4"
android:text="@string/select_instrument_title" />
android:padding="@dimen/home_fragment_padding">

<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:layout_marginTop="@dimen/create_config_margin4"
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"
android:layout_toEndOf="@id/select_instrument_title" />

<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" />
<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/interval_unit_spinner"
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/interval_edit_text" />
<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" />

<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_marginTop="@dimen/create_config_margin2"
android:text="@string/select_params_title" />
<android.support.v7.widget.AppCompatSpinner
android:id="@+id/interval_unit_spinner"
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/interval_edit_text" />

<ListView
android:id="@+id/params_list"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@+id/create_config_btn"
android:layout_below="@+id/select_params_title"
android:layout_margin="@dimen/create_config_margin1" />
<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_marginTop="@dimen/create_config_margin2"
android:text="@string/select_params_title" />

<Button
android:id="@+id/create_config_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="@color/colorPrimary"
android:padding="@dimen/margin_btn"
android:text="@string/create_config_btn_text"
android:textColor="@color/white" />
</RelativeLayout>
<LinearLayout
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>

<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: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>

</ScrollView>

<android.support.design.widget.AppBarLayout
android:id="@+id/top_app_bar_layout"
Expand Down

0 comments on commit 8b69f3e

Please sign in to comment.