Commit f20b943c by Kunj Gupta

UOFLMA-27: Dynamic form page is created.

parent 0161f043
......@@ -139,6 +139,7 @@ public class CatalogueItemScreen extends AppCompatActivity {
Intent intent = new Intent(CatalogueItemScreen.this, CatalogueVariableScreen.class);
intent.putExtra(Constants.DATA_KEY_SYS_ID, mCatalogueItemList.get(position).getSysId());
intent.putExtra(Constants.DATA_KEY_CATALOGUE_ITEM_DESCRIPTION, mCatalogueItemList.get(position).getDescription());
intent.putExtra(Constants.DATA_KEY_CATALOGUE_TITLE, mCatalogueItemList.get(position).getName());
startActivity(intent);
}
});
......
......@@ -6,20 +6,21 @@ import android.app.TimePickerDialog;
import android.content.DialogInterface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.Html;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.FrameLayout;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.TimePicker;
......@@ -50,21 +51,37 @@ import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
/**
* Created by Kunj on 11/8/16.
*/
public class CatalogueVariableScreen extends FragmentActivity {
public class CatalogueVariableScreen extends AppCompatActivity {
@BindView(R.id.tool_bar_view) Toolbar mToolbar;
@BindView(R.id.variable_screen_back_text_view) TextView mBackTextView;
@BindView(R.id.variable_screen_submit_text_view) TextView mSubmitTextView;
@BindView(R.id.variable_screen_empty_text_view) TextView mEmptyTextView;
@BindView(R.id.variable_screen_container_layout) LinearLayout mContainerLayout;
@BindView(R.id.variable_screen_main_layout) LinearLayout mMainLayout;
@BindView(R.id.variable_screen_bottom_layout) RelativeLayout mBottomLayout;
private List<CatalogueVariable> mCatalogueVariableList;
private LinearLayout mMainLayout;
private JSONArray mJsonArray;
private CatalogueApplication mApplication;
private String mCatalogueItemSysId, mCatalogueItemDescription;
private String mCatalogueItemSysId, mCatalogueItemDescription, mCatalogueItemTitle;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.catalogue_variable_screen);
ButterKnife.bind(this);
mApplication = (CatalogueApplication) getApplication();
Bundle extras = getIntent().getExtras();
......@@ -72,9 +89,20 @@ public class CatalogueVariableScreen extends FragmentActivity {
if (extras != null) {
mCatalogueItemSysId = extras.getString(Constants.DATA_KEY_SYS_ID);
mCatalogueItemDescription = extras.getString(Constants.DATA_KEY_CATALOGUE_ITEM_DESCRIPTION);
mCatalogueItemTitle = extras.getString(Constants.DATA_KEY_CATALOGUE_TITLE);
//The key argument here must match that used in the other activity
}
setSupportActionBar(mToolbar);
ActionBar actionBar = getSupportActionBar();
if(actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setElevation(0);
actionBar.setTitle(mCatalogueItemTitle);
actionBar.setDisplayShowHomeEnabled(false);
actionBar.setDisplayShowTitleEnabled(true);
}
if(mApplication.isNetConnected()) {
new FetchCatalogueVariable().execute();
} else {
......@@ -137,36 +165,17 @@ public class CatalogueVariableScreen extends FragmentActivity {
}
private void createView() {
mMainLayout = new LinearLayout(CatalogueVariableScreen.this);
mMainLayout.setOrientation(LinearLayout.VERTICAL);
mMainLayout.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
FrameLayout.LayoutParams.MATCH_PARENT));
getCustomLayout();
mMainLayout.addView(getCustomLayout());
if(!mCatalogueVariableList.isEmpty()) {
mMainLayout.addView(getVerticalSeparator());
mMainLayout.addView(getBottomLayout());
mBottomLayout.setVisibility(View.VISIBLE);
} else {
mBottomLayout.setVisibility(View.GONE);
}
setContentView(mMainLayout);
}
private View getCustomLayout() {
ScrollView scrollView = new ScrollView(CatalogueVariableScreen.this);
scrollView.setFillViewport(true);
scrollView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, .9f));
private void getCustomLayout() {
/*Child view of scroll view*/
LinearLayout linearLayout = new LinearLayout(CatalogueVariableScreen.this);
ScrollView.LayoutParams params = new ScrollView.LayoutParams(ScrollView.LayoutParams.MATCH_PARENT, ScrollView.LayoutParams.WRAP_CONTENT);
linearLayout.setLayoutParams(params);
linearLayout.setOrientation(LinearLayout.VERTICAL);
linearLayout.setPadding((int)getResources().getDimension(R.dimen.normal_margin),
(int)getResources().getDimension(R.dimen.normal_margin),
(int)getResources().getDimension(R.dimen.normal_margin),
(int)getResources().getDimension(R.dimen.normal_margin));
scrollView.addView(linearLayout, params);
LinearLayout.LayoutParams childControlViewLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.WRAP_CONTENT);
LinearLayout.LayoutParams childLabelViewLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
......@@ -181,16 +190,16 @@ public class CatalogueVariableScreen extends FragmentActivity {
descriptionView.setText(Html.fromHtml(mCatalogueItemDescription));
}
linearLayout.addView(descriptionView, childControlViewLayoutParams);
mContainerLayout.addView(descriptionView, childControlViewLayoutParams);
}
if(mCatalogueVariableList.isEmpty()) {
TextView noVariableView = new TextView(CatalogueVariableScreen.this);
noVariableView.setText(R.string.no_variables_string);
noVariableView.setGravity(Gravity.CENTER);
linearLayout.addView(noVariableView, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT));
mEmptyTextView.setVisibility(View.VISIBLE);
mMainLayout.setVisibility(View.GONE);
} else {
mEmptyTextView.setVisibility(View.GONE);
mMainLayout.setVisibility(View.VISIBLE);
for (int i = 0; i < mCatalogueVariableList.size(); i++) {
CatalogueVariable catalogueVariable = mCatalogueVariableList.get(i);
ViewType viewType = catalogueVariable.getType();
......@@ -204,7 +213,7 @@ public class CatalogueVariableScreen extends FragmentActivity {
(int) getResources().getDimension(R.dimen.small_margin),
(int) getResources().getDimension(R.dimen.small_margin),
(int) getResources().getDimension(R.dimen.small_margin));
linearLayout.addView(nameNullView, childLabelViewLayoutParams);
mContainerLayout.addView(nameNullView, childLabelViewLayoutParams);
} else {
if (viewType != ViewType.LABEL && viewType != ViewType.CHECK_BOX && viewType != ViewType.BREAK) {
/*Create label for every type*/
......@@ -212,7 +221,7 @@ public class CatalogueVariableScreen extends FragmentActivity {
TextView label = new TextView(CatalogueVariableScreen.this);
label.setText(catalogueVariable.getQuestionText());
childLabelViewLayoutParams.topMargin = (int) getResources().getDimension(R.dimen.small_margin);
linearLayout.addView(label, childLabelViewLayoutParams);
mContainerLayout.addView(label, childLabelViewLayoutParams);
} else {
/*Create label with mandatory value*/
LinearLayout labelLayout = new LinearLayout(CatalogueVariableScreen.this);
......@@ -228,7 +237,7 @@ public class CatalogueVariableScreen extends FragmentActivity {
mandatory.setTextColor(ContextCompat.getColor(CatalogueVariableScreen.this, R.color.error_color));
labelLayout.addView(mandatory);
linearLayout.addView(labelLayout);
mContainerLayout.addView(labelLayout);
}
}
......@@ -246,70 +255,27 @@ public class CatalogueVariableScreen extends FragmentActivity {
/*Set bottom margin for custom view*/
if (viewType != ViewType.BREAK) {
linearLayout.addView(controlView, childControlViewLayoutParams);
mContainerLayout.addView(controlView, childControlViewLayoutParams);
} else
linearLayout.addView(controlView);
mContainerLayout.addView(controlView);
/*Mandatory variable contain error view*/
if (catalogueVariable.isMandatory()) {
/*Add error view for validation*/
View errorView = getErrorView();
errorView.setTag("error_" + i);
linearLayout.addView(errorView);
mContainerLayout.addView(errorView);
}
} else {
TextView viewNotImplemented = new TextView(CatalogueVariableScreen.this);
viewNotImplemented.setText(String.format(getString(R.string.view_not_implemented_string), viewType.getDisplayString()));
viewNotImplemented.setBackgroundColor(ContextCompat.getColor(CatalogueVariableScreen.this, R.color.view_not_implemented_color));
childLabelViewLayoutParams.topMargin = (int) getResources().getDimension(R.dimen.small_margin);
linearLayout.addView(viewNotImplemented, childLabelViewLayoutParams);
mContainerLayout.addView(viewNotImplemented, childLabelViewLayoutParams);
}
}
}
}
return scrollView;
}
private View getBottomLayout() {
LinearLayout bottomLayout = new LinearLayout(CatalogueVariableScreen.this);
bottomLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 0, .1f));
bottomLayout.setOrientation(LinearLayout.HORIZONTAL);
bottomLayout.setBackgroundColor(ContextCompat.getColor(CatalogueVariableScreen.this, android.R.color.white));
LinearLayout.LayoutParams bottomChildViewParams = new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1.0f);
TextView cancelTextView = new TextView(CatalogueVariableScreen.this);
cancelTextView.setText(android.R.string.cancel);
cancelTextView.setLayoutParams(bottomChildViewParams);
cancelTextView.setGravity(Gravity.CENTER);
cancelTextView.setId(R.id.create_form_cancel_text_view);
cancelTextView.setOnClickListener(listener);
bottomLayout.addView(cancelTextView);
bottomLayout.addView(getHorizontalSeparator());
TextView saveTextView = new TextView(CatalogueVariableScreen.this);
saveTextView.setText(R.string.save_string);
saveTextView.setLayoutParams(bottomChildViewParams);
saveTextView.setGravity(Gravity.CENTER);
saveTextView.setId(R.id.create_form_save_text_view);
saveTextView.setOnClickListener(listener);
bottomLayout.addView(saveTextView);
return bottomLayout;
}
private View getVerticalSeparator() {
View view = new View(CatalogueVariableScreen.this);
view.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, (int)getResources().getDimension(R.dimen.separator_value)));
view.setBackgroundColor(ContextCompat.getColor(CatalogueVariableScreen.this, android.R.color.black));
return view;
}
private View getHorizontalSeparator() {
View view = new View(CatalogueVariableScreen.this);
view.setLayoutParams(new LinearLayout.LayoutParams((int)getResources().getDimension(R.dimen.separator_value), LinearLayout.LayoutParams.MATCH_PARENT));
view.setBackgroundColor(ContextCompat.getColor(CatalogueVariableScreen.this, android.R.color.black));
return view;
}
private View getErrorView() {
......@@ -320,19 +286,15 @@ public class CatalogueVariableScreen extends FragmentActivity {
return textView;
}
View.OnClickListener listener = new View.OnClickListener() {
@Override
public void onClick(final View v) {
switch (v.getId()) {
case R.id.create_form_cancel_text_view:
finish();
break;
case R.id.create_form_save_text_view:
saveFormData();
break;
}
}
};
@OnClick(R.id.variable_screen_submit_text_view)
void submitOnClicked() {
saveFormData();
}
@OnClick(R.id.variable_screen_back_text_view)
void backOnClicked() {
finish();
}
private void saveFormData() {
/*For Local DB column and value*/
......@@ -349,10 +311,10 @@ public class CatalogueVariableScreen extends FragmentActivity {
ViewType viewType = catalogueVariable.getType();
if(viewType != ViewType.LABEL && viewType != ViewType.BREAK) {
View view = mMainLayout.findViewWithTag(tempTagObj);
View view = mContainerLayout.findViewWithTag(tempTagObj);
if (view != null) {
String value = Util.getVariableViewValue(view, viewType);
View errorView = mMainLayout.findViewWithTag("error_"+i);
View errorView = mContainerLayout.findViewWithTag("error_"+i);
columnList.add(catalogueVariable.getName());
JSONObject jsonObject = new JSONObject();
......@@ -527,4 +489,12 @@ public class CatalogueVariableScreen extends FragmentActivity {
public String getMonth(int month) {
return Constants.month[month];
}
@Override
public boolean onOptionsItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() == android.R.id.home) {
finish();
}
return super.onOptionsItemSelected(menuItem);
}
}
\ No newline at end of file
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="5dp" />
<solid
android:color="@color/back_button_bg_color"/>
</shape>
\ No newline at end of file
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners
android:radius="5dp" />
<solid
android:color="@color/submit_button_bg_color"/>
</shape>
\ No newline at end of file
......@@ -5,7 +5,7 @@
android:weightSum="10"
android:paddingLeft="@dimen/small_margin"
android:paddingRight="@dimen/small_margin"
android:background="@drawable/background_with_border">
android:background="@drawable/list_view_item_bg_with_border">
<ImageView
android:layout_width="0dp"
......
......@@ -5,7 +5,7 @@
android:weightSum="10"
android:paddingLeft="@dimen/small_margin"
android:paddingRight="@dimen/small_margin"
android:background="@drawable/background_with_border">
android:background="@drawable/list_view_item_bg_with_border">
<ImageView
android:layout_width="0dp"
......
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="match_parent"
android:orientation="vertical"
android:weightSum="10">
<android.support.v7.widget.Toolbar
android:id="@+id/tool_bar_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="0dp"
android:background="@android:color/white"
android:contentInsetEnd="0dp"
android:contentInsetRight="0dp"
android:contentInsetStart="0dp"
android:minHeight="?attr/actionBarSize"
android:padding="0dp"
app:contentInsetEnd="0dp"
app:contentInsetLeft="0dp"
app:contentInsetRight="0dp"
app:contentInsetStart="0dp" />
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/variable_screen_empty_text_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="@string/no_variables_string"
android:textSize="@dimen/extra_normal_text_size" />
<LinearLayout
android:id="@+id/variable_screen_main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/screen_bg_color"
android:orientation="vertical"
android:padding="@dimen/normal_margin"
android:visibility="gone">
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="9"
android:background="@android:color/white"
android:requiresFadingEdge="vertical">
<LinearLayout
android:id="@+id/variable_screen_container_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="vertical"
android:padding="@dimen/normal_margin" />
</ScrollView>
<RelativeLayout
android:id="@+id/variable_screen_bottom_layout"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:background="@android:color/white"
android:gravity="center_vertical">
<TextView
android:id="@+id/variable_screen_submit_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="@dimen/normal_margin"
android:background="@drawable/submit_button_bg_with_border"
android:paddingBottom="@dimen/normal_margin"
android:paddingLeft="@dimen/extra_large_margin"
android:paddingRight="@dimen/extra_large_margin"
android:paddingTop="@dimen/normal_margin"
android:text="@string/submit_string"
android:textColor="@android:color/white" />
<TextView
android:id="@+id/variable_screen_back_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/normal_margin"
android:layout_toLeftOf="@id/variable_screen_submit_text_view"
android:background="@drawable/back_button_bg_with_border"
android:paddingBottom="@dimen/normal_margin"
android:paddingLeft="@dimen/extra_large_margin"
android:paddingRight="@dimen/extra_large_margin"
android:paddingTop="@dimen/normal_margin"
android:text="@string/back_string"
android:textColor="@android:color/white" />
</RelativeLayout>
</LinearLayout>
</FrameLayout>
</LinearLayout>
\ No newline at end of file
......@@ -14,4 +14,7 @@
<color name="screen_bg_color">#c0cfd1</color>
<color name="bg_border_color">#d6d6d6</color>
<color name="back_button_bg_color">#4f0307</color>
<color name="submit_button_bg_color">#e31b22</color>
</resources>
......@@ -12,10 +12,8 @@
<dimen name="extra_normal_text_size">18sp</dimen>
<dimen name="large_text_size">20sp</dimen>
<dimen name="separator_value">1dp</dimen>
<dimen name="list_view_divider_height">5dp</dimen>
<!--Home Screen-->
<dimen name="home_screen_item_height">120dp</dimen>
......
<?xml version="1.0" encoding="utf-8"?>
<resources>
<item name="create_form_save_text_view" type="id"/>
<item name="create_form_cancel_text_view" type="id"/>
</resources>
\ No newline at end of file
......@@ -2,7 +2,8 @@
<string name="app_name">UofL Catalogue</string>
<string name="set_string">Set</string>
<string name="save_string">Save</string>
<string name="submit_string">Submit</string>
<string name="back_string">Back</string>
<string name="error_string">* Required</string>
<string name="none_string">-None-</string>
<string name="search_for_reference_string">Reference</string>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment