From 145b7b985a15f42e56fe8961574b26ce53e7a27a Mon Sep 17 00:00:00 2001
From: Alfred
Date: Tue, 16 May 2017 07:50:01 +0000
Subject: [PATCH 1/4] add the ability to be able to add footer
---
.../questionnaireview/MainActivity.java | 13 ++++++
app/src/main/res/layout/footer.xml | 18 ++++++++
.../QuestionnaireView.java | 44 +++++++++++++++++++
.../src/main/res/layout/check_list_item.xml | 1 -
4 files changed, 75 insertions(+), 1 deletion(-)
create mode 100644 app/src/main/res/layout/footer.xml
diff --git a/app/src/main/java/com/alfredayibonte/questionnaireview/MainActivity.java b/app/src/main/java/com/alfredayibonte/questionnaireview/MainActivity.java
index b41a5b9..d8520b2 100644
--- a/app/src/main/java/com/alfredayibonte/questionnaireview/MainActivity.java
+++ b/app/src/main/java/com/alfredayibonte/questionnaireview/MainActivity.java
@@ -5,6 +5,9 @@
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
+import android.view.View;
+import android.widget.Button;
+
import com.alfredayibonte.questionnaireviewlib.QuestionnaireView;
import com.alfredayibonte.questionnaireviewlib.utils.AnswerType;
@@ -18,6 +21,16 @@ protected void onCreate(Bundle savedInstanceState) {
questionnaireView.setQuestion("What is the name of this library ? ");
questionnaireView.setViewType(AnswerType.EDITTEXT);
questionnaireView.addTextChangedListener(this);
+ View view = View.inflate(this, R.layout.footer, null);
+ Button btn = (Button) view.findViewById(R.id.next);
+ btn.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ Log.e("NEXT::", "Next button clicked");
+ }
+ });
+ questionnaireView.addFooter(view);
+
}
@Override
diff --git a/app/src/main/res/layout/footer.xml b/app/src/main/res/layout/footer.xml
new file mode 100644
index 0000000..c3929d7
--- /dev/null
+++ b/app/src/main/res/layout/footer.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/QuestionnaireView.java b/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/QuestionnaireView.java
index 2b54b5a..3ced7a6 100644
--- a/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/QuestionnaireView.java
+++ b/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/QuestionnaireView.java
@@ -3,9 +3,11 @@
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Color;
+import android.support.v4.content.ContextCompat;
import android.text.InputType;
import android.text.TextWatcher;
import android.util.AttributeSet;
+import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.webkit.WebView;
import android.widget.EditText;
@@ -33,6 +35,7 @@ public class QuestionnaireView extends RelativeLayout {
private List answers;
private RadioListAdapter radioAdapter;
private CheckListAdapter checkAdapter;
+ private View view;
public QuestionnaireView(Context context) {
super(context);
}
@@ -176,6 +179,10 @@ public void setAnswers(CharSequence[] answers){
setAnswers(this.answers);
}
+ /**
+ *
+ * @param answers
+ */
public void setAnswers(ArrayList answers){
this.answers = new ArrayList<>();
for(String item : answers)
@@ -189,11 +196,19 @@ public void addCheckItemListener(CheckListAdapter.OnCheckItemClickListener check
checkAdapter.addListener(checkListener);
}
+ /**
+ *
+ * @param radioListener
+ */
public void addRadioItemListener(RadioListAdapter.OnRadioItemClickListener radioListener) {
if (radioAdapter != null)
radioAdapter.addListener(radioListener);
}
+ /**
+ *
+ * @param editorActionListener
+ */
public void addOnEditorActionListener(EditText.OnEditorActionListener editorActionListener){
editTv.setOnEditorActionListener(editorActionListener);
}
@@ -214,6 +229,35 @@ private void makeListViewVisible(){
editTv.setVisibility(GONE);
}
+ /**
+ *
+ * @param layout layout file (eg. R.layout.footer)
+ */
+ public void addFooter(int layout){
+ View view = View.inflate(getContext(), layout, null);
+ addFooter(view);
+ }
+
+ /**
+ *
+ * @param view adds view to parent bottom
+ */
+ public void addFooter(View view){
+ if( view == null ) return;
+ view.setBackgroundColor(ContextCompat.getColor(getContext(),
+ android.R.color.transparent));
+ view.setLayoutParams(
+ new LayoutBuilder()
+ .addWidth(LayoutParams.MATCH_PARENT)
+ .addHeight(LayoutParams.WRAP_CONTENT)
+ .addRule(ALIGN_PARENT_BOTTOM, getId())
+ .create()
+ );
+ addView(view);
+
+
+ }
+
public Question getQuestion(){
return question != null ? question : new Question("");
}
diff --git a/questionnaireviewlib/src/main/res/layout/check_list_item.xml b/questionnaireviewlib/src/main/res/layout/check_list_item.xml
index a0b77ca..9c2dac7 100644
--- a/questionnaireviewlib/src/main/res/layout/check_list_item.xml
+++ b/questionnaireviewlib/src/main/res/layout/check_list_item.xml
@@ -15,7 +15,6 @@
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:padding="10dp"
- android:text="Exforge"
android:textSize="@dimen/question_normal_text"
/>
\ No newline at end of file
From e36bf69818f7131c45229eb8dbfb311df3150404 Mon Sep 17 00:00:00 2001
From: Alfred
Date: Tue, 16 May 2017 15:37:03 +0000
Subject: [PATCH 2/4] add .travis.yml
---
.travis.yml | 11 +++++++++++
1 file changed, 11 insertions(+)
create mode 100644 .travis.yml
diff --git a/.travis.yml b/.travis.yml
new file mode 100644
index 0000000..eb0a004
--- /dev/null
+++ b/.travis.yml
@@ -0,0 +1,11 @@
+nguage: android
+android:
+ components:
+ - tools # to get the new `repository-11.xml`
+ - tools # see https://github.com/travis-ci/travis-ci/issues/6040#issuecomment-219367943)
+ - platform-tools
+ - build-tools-25.0.0
+ - android-25
+
+script:
+ - ./gradlew build connectedCheck
From 2a3114acbc2b9742f4e3d11565b70ac3e81d4860 Mon Sep 17 00:00:00 2001
From: Alfred
Date: Thu, 18 May 2017 15:19:15 +0000
Subject: [PATCH 3/4] add viewPager example
---
app/build.gradle | 1 +
app/src/main/AndroidManifest.xml | 1 +
app/src/main/assets/question.json | 51 ++++++++
.../questionnaireview/AppController.java | 38 ++++++
.../questionnaireview/MainActivity.java | 52 ++++-----
.../NonSwipeableViewPager.java | 29 +++++
.../questionnaireview/QuestionFragment.java | 110 ++++++++++++++++++
.../QuestionPagerAdapter.java | 58 +++++++++
.../models/ResultObject.java | 87 ++++++++++++++
.../questionnaireview/utils/JsonHelper.java | 34 ++++++
app/src/main/res/layout/activity_main.xml | 15 +--
app/src/main/res/layout/question_fragment.xml | 11 ++
12 files changed, 452 insertions(+), 35 deletions(-)
create mode 100644 app/src/main/assets/question.json
create mode 100644 app/src/main/java/com/alfredayibonte/questionnaireview/AppController.java
create mode 100644 app/src/main/java/com/alfredayibonte/questionnaireview/NonSwipeableViewPager.java
create mode 100644 app/src/main/java/com/alfredayibonte/questionnaireview/QuestionFragment.java
create mode 100644 app/src/main/java/com/alfredayibonte/questionnaireview/QuestionPagerAdapter.java
create mode 100644 app/src/main/java/com/alfredayibonte/questionnaireview/models/ResultObject.java
create mode 100644 app/src/main/java/com/alfredayibonte/questionnaireview/utils/JsonHelper.java
create mode 100644 app/src/main/res/layout/question_fragment.xml
diff --git a/app/build.gradle b/app/build.gradle
index 1d3aa34..b5bc9dc 100644
--- a/app/build.gradle
+++ b/app/build.gradle
@@ -26,6 +26,7 @@ dependencies {
})
compile 'com.android.support:appcompat-v7:25.1.1'
compile 'com.android.support.constraint:constraint-layout:1.0.1'
+ compile 'com.google.code.gson:gson:2.8.0'
testCompile 'junit:junit:4.12'
compile project(path: ':questionnaireviewlib')
}
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 3d8271a..ecc8b34 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -3,6 +3,7 @@
package="com.alfredayibonte.questionnaireview">
Lorem ipsum dolor sit amet, consectetur adipisicing elit. Velit earum saepe iste nesciunt dolor corporis, distinctio repudiandae aliquid consectetur impedit eveniet facilis eius nisi nobis a porro quis consequatur harum?
\n",
+ "answer_type": 1,
+ "difficulty": 1,
+ "created_at": "2016-10-23T11:33:59.544Z",
+ "updated_at": "2017-01-12T21:57:28.970Z"
+ },
+ {
+ "id": 2,
+ "answers": [
+ "John"
+ ],
+ "answer": [
+ "John"
+ ],
+ "content": "What is Abraham's name met, consectetur adipisicing elit. Est nihil pariatur expedita eum ut deserunt error ullam aliquid obcaecati iusto cumque sit, praesentium provident doloribus, rerum doloremque totam reprehenderit inventore.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Est nihil pariatur expedita eum ut deserunt error ullam aliquid obcaecati iusto cumque sit, praesentium provident doloribus, rerum doloremque totam reprehenderit inventore.Lorem ipsum dolor sit amet, consectetur adipisicing elit. Est nihil pariatur expedita eum ut deserunt error ullam aliquid obcaecati iusto cumque sit, praesentium provident doloribus, rerum doloremque totam reprehenderit inventore.
\n",
+ "answer_type": 3,
+ "difficulty": 4,
+ "created_at": "2017-01-20T22:27:51.110Z",
+ "updated_at": "2017-01-20T22:27:51.110Z"
+ },
+ {
+ "id": 3,
+ "answers": [
+ "(A - B)(A + B)",
+ "AB",
+ "A+B*A",
+ "(A + B)(A + B)",
+ "(A + B)(A - B)"
+ ],
+ "answer": [
+ "(A - B)(A + B)",
+ "(A + B)(A - B)"
+ ],
+ "content": "A2 - B2 = ?
\n",
+ "answer_type": 2,
+ "difficulty": 1,
+ "created_at": "2017-01-20T22:30:33.216Z",
+ "updated_at": "2017-01-20T22:30:33.216Z"
+ }
+]
\ No newline at end of file
diff --git a/app/src/main/java/com/alfredayibonte/questionnaireview/AppController.java b/app/src/main/java/com/alfredayibonte/questionnaireview/AppController.java
new file mode 100644
index 0000000..60b684b
--- /dev/null
+++ b/app/src/main/java/com/alfredayibonte/questionnaireview/AppController.java
@@ -0,0 +1,38 @@
+package com.alfredayibonte.questionnaireview;
+
+import android.app.Application;
+
+import com.alfredayibonte.questionnaireview.models.ResultObject;
+import com.alfredayibonte.questionnaireview.utils.JsonHelper;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.List;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+import com.google.gson.reflect.TypeToken;
+
+/**
+ *
+ * Created by Alfredayibonte on 5/18/17.
+ */
+
+public class AppController extends Application {
+ private List questions;
+ public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
+ Gson gson;
+ @Override
+ public void onCreate() {
+ super.onCreate();
+ questions = new ArrayList<>();
+ String result = JsonHelper.loadJSONFromAsset(getApplicationContext());
+ Type type = new TypeToken>() {}.getType();
+ gson = new GsonBuilder()
+ .setDateFormat(DATE_FORMAT)
+ .create();
+ questions = gson.fromJson(result, type);
+ }
+
+ public List getQuestions(){
+ return questions;
+ }
+}
diff --git a/app/src/main/java/com/alfredayibonte/questionnaireview/MainActivity.java b/app/src/main/java/com/alfredayibonte/questionnaireview/MainActivity.java
index d8520b2..c9d74b5 100644
--- a/app/src/main/java/com/alfredayibonte/questionnaireview/MainActivity.java
+++ b/app/src/main/java/com/alfredayibonte/questionnaireview/MainActivity.java
@@ -1,50 +1,46 @@
package com.alfredayibonte.questionnaireview;
+import android.support.v4.view.PagerAdapter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
-import android.text.Editable;
-import android.text.TextWatcher;
-import android.util.Log;
-import android.view.View;
-import android.widget.Button;
+import android.view.MenuItem;
-import com.alfredayibonte.questionnaireviewlib.QuestionnaireView;
-import com.alfredayibonte.questionnaireviewlib.utils.AnswerType;
-
-public class MainActivity extends AppCompatActivity implements TextWatcher {
+public class MainActivity extends AppCompatActivity implements QuestionFragment.OnQuestionItemSelectedListener {
+ private NonSwipeableViewPager mPager;
+ private PagerAdapter mPagerAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
- QuestionnaireView questionnaireView = (QuestionnaireView)findViewById(R.id.questionnaire);
- questionnaireView.setQuestion("What is the name of this library ? ");
- questionnaireView.setViewType(AnswerType.EDITTEXT);
- questionnaireView.addTextChangedListener(this);
- View view = View.inflate(this, R.layout.footer, null);
- Button btn = (Button) view.findViewById(R.id.next);
- btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Log.e("NEXT::", "Next button clicked");
- }
- });
- questionnaireView.addFooter(view);
+ mPager = (NonSwipeableViewPager)findViewById(R.id.pager);
+ AppController app = (AppController) getApplication();
+ mPagerAdapter = new QuestionPagerAdapter(getApplicationContext(),
+ getSupportFragmentManager(), app.getQuestions());
+ mPager.setAdapter(mPagerAdapter);
}
@Override
- public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
-
+ public boolean onOptionsItemSelected(MenuItem item) {
+ switch (item.getItemId()) {
+ case android.R.id.home:
+ onBackPressed();
+ return true;
+ }
+
+ return super.onOptionsItemSelected(item);
}
@Override
- public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
- Log.e(MainActivity.class.getSimpleName(), charSequence.toString());
+ public void onPreviousButtonPressed() {
+ int page = mPager.getCurrentItem();
+ mPager.setCurrentItem( page - 1 );
}
@Override
- public void afterTextChanged(Editable editable) {
-
+ public void onNextButtonPressed() {
+ int page = mPager.getCurrentItem();
+ mPager.setCurrentItem( page + 1 );
}
}
\ No newline at end of file
diff --git a/app/src/main/java/com/alfredayibonte/questionnaireview/NonSwipeableViewPager.java b/app/src/main/java/com/alfredayibonte/questionnaireview/NonSwipeableViewPager.java
new file mode 100644
index 0000000..d541c85
--- /dev/null
+++ b/app/src/main/java/com/alfredayibonte/questionnaireview/NonSwipeableViewPager.java
@@ -0,0 +1,29 @@
+package com.alfredayibonte.questionnaireview;
+
+import android.content.Context;
+import android.support.v4.view.ViewPager;
+import android.util.AttributeSet;
+import android.view.MotionEvent;
+
+public class NonSwipeableViewPager extends ViewPager {
+
+ public NonSwipeableViewPager(Context context) {
+ super(context);
+ }
+
+ public NonSwipeableViewPager(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+
+ @Override
+ public boolean onInterceptTouchEvent(MotionEvent event) {
+ // Never allow swiping to switch between pages
+ return false;
+ }
+
+ @Override
+ public boolean onTouchEvent(MotionEvent event) {
+ // Never allow swiping to switch between pages
+ return false;
+ }
+}
diff --git a/app/src/main/java/com/alfredayibonte/questionnaireview/QuestionFragment.java b/app/src/main/java/com/alfredayibonte/questionnaireview/QuestionFragment.java
new file mode 100644
index 0000000..fa04bc8
--- /dev/null
+++ b/app/src/main/java/com/alfredayibonte/questionnaireview/QuestionFragment.java
@@ -0,0 +1,110 @@
+package com.alfredayibonte.questionnaireview;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.support.v7.app.AppCompatActivity;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.util.Log;
+import android.view.LayoutInflater;
+import android.view.View;
+import android.view.ViewGroup;
+import android.widget.Button;
+import com.alfredayibonte.questionnaireviewlib.QuestionnaireView;
+import com.alfredayibonte.questionnaireviewlib.models.Question;
+import com.alfredayibonte.questionnaireviewlib.utils.AnswerType;
+import java.util.ArrayList;
+import static com.alfredayibonte.questionnaireview.QuestionPagerAdapter.ANSWERS_KEY;
+import static com.alfredayibonte.questionnaireview.QuestionPagerAdapter.ANSWER_TYPE_KEY;
+import static com.alfredayibonte.questionnaireview.QuestionPagerAdapter.POSITION_KEY;
+import static com.alfredayibonte.questionnaireview.QuestionPagerAdapter.QUESTION_KEY;
+
+public class QuestionFragment extends Fragment implements TextWatcher {
+ OnQuestionItemSelectedListener mCallback;
+ Question question;
+ ArrayList answers;
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ question = new Question("");
+ if (getArguments() != null) {
+ question.setId(getArguments().getInt(POSITION_KEY));
+ question.setContent(getArguments().getString(QUESTION_KEY));
+ question.setAnswer_type(getArguments().getInt(ANSWER_TYPE_KEY));
+ answers = getArguments().getStringArrayList(ANSWERS_KEY);
+
+ }
+
+ }
+
+ @Override
+ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+ ViewGroup rootView = (ViewGroup) inflater
+ .inflate(R.layout.question_fragment, container, false);
+ QuestionnaireView questionnaireView = (QuestionnaireView)rootView.findViewById(R.id.questionnaire);
+ questionnaireView.setQuestion(question.getContent());
+ questionnaireView.setViewType(question.getAnswer_type());
+ questionnaireView.setAnswers(answers);
+ questionnaireView.addTextChangedListener(this);
+ View view = View.inflate(getContext(), R.layout.footer, null);
+ Button next = (Button) view.findViewById(R.id.next);
+ Button back = (Button) view.findViewById(R.id.back);
+ next.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ mCallback.onNextButtonPressed();
+ }
+ });
+ questionnaireView.addFooter(view);
+ back.setOnClickListener(new View.OnClickListener() {
+ @Override
+ public void onClick(View view) {
+ mCallback.onPreviousButtonPressed();
+ }
+ });
+
+ return rootView;
+ }
+
+ @Override
+ public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
+
+ }
+
+ @Override
+ public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
+ Log.e(MainActivity.class.getSimpleName(), charSequence.toString());
+ }
+
+ @Override
+ public void afterTextChanged(Editable editable) {
+
+ }
+
+ public interface OnQuestionItemSelectedListener{
+ public void onPreviousButtonPressed();
+ public void onNextButtonPressed();
+ }
+
+ @Override
+ public void onAttach(Context context) {
+ super.onAttach(context);
+
+ AppCompatActivity activity = null;
+
+ if (context instanceof AppCompatActivity){
+ activity = (AppCompatActivity) context;
+ }
+ if(activity != null){
+ try {
+ mCallback = (OnQuestionItemSelectedListener) activity;
+ } catch (ClassCastException e) {
+ throw new ClassCastException(activity.toString()
+ + " must implement OnHeadlineSelectedListener");
+ }
+ }
+
+ }
+}
diff --git a/app/src/main/java/com/alfredayibonte/questionnaireview/QuestionPagerAdapter.java b/app/src/main/java/com/alfredayibonte/questionnaireview/QuestionPagerAdapter.java
new file mode 100644
index 0000000..9eaa0ea
--- /dev/null
+++ b/app/src/main/java/com/alfredayibonte/questionnaireview/QuestionPagerAdapter.java
@@ -0,0 +1,58 @@
+package com.alfredayibonte.questionnaireview;
+
+import android.content.Context;
+import android.os.Bundle;
+import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentManager;
+import android.support.v4.app.FragmentStatePagerAdapter;
+
+import com.alfredayibonte.questionnaireview.models.ResultObject;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class QuestionPagerAdapter extends FragmentStatePagerAdapter {
+ Fragment fragment;
+ Context context;
+ protected static final String POSITION_KEY = "POSITION";
+ protected static final String QUESTION_KEY = "QUESTION";
+ protected static final String ANSWERS_KEY = "ANSWERS";
+ protected static final String ANSWER_TYPE_KEY = "ANSWER_TYPE";
+ List questions;
+ public QuestionPagerAdapter(Context context,
+ FragmentManager fm){
+ super(fm);
+ this.context = context;
+ questions = new ArrayList<>();
+ }
+
+ public QuestionPagerAdapter(Context context, FragmentManager fm, List questions){
+ this(context, fm);
+ this.questions = questions;
+ }
+
+ @Override
+ public Fragment getItem(int position) {
+ fragment = new QuestionFragment();
+ Bundle args = new Bundle();
+ args.putInt(POSITION_KEY, position);
+ if(questions == null || questions.isEmpty())
+ return fragment;
+ else if(questions.get(position) == null ) return fragment;
+ args.putString(QUESTION_KEY, questions.get(position).getContent());
+ args.putStringArrayList(ANSWERS_KEY, questions.get(position).getAnswers());
+ args.putInt(ANSWER_TYPE_KEY, questions.get(position).getAnswer_type());
+ fragment.setArguments(args);
+ return fragment;
+ }
+
+ @Override
+ public int getCount() {
+ return (questions != null && !questions.isEmpty())? questions.size() : 1;
+ }
+
+
+
+}
+
+
diff --git a/app/src/main/java/com/alfredayibonte/questionnaireview/models/ResultObject.java b/app/src/main/java/com/alfredayibonte/questionnaireview/models/ResultObject.java
new file mode 100644
index 0000000..7882d4a
--- /dev/null
+++ b/app/src/main/java/com/alfredayibonte/questionnaireview/models/ResultObject.java
@@ -0,0 +1,87 @@
+package com.alfredayibonte.questionnaireview.models;
+
+import java.util.ArrayList;
+import java.util.Date;
+
+/**
+ *
+ * Created by Alfredayibonte on 5/18/17.
+ */
+
+public class ResultObject {
+
+ public ResultObject(){}
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getContent() {
+ return content;
+ }
+
+ public void setContent(String content) {
+ this.content = content;
+ }
+
+ public ArrayList getAnswers() {
+ return answers;
+ }
+
+ public void setAnswers(ArrayList answers) {
+ this.answers = answers;
+ }
+
+ public ArrayList getAnswer() {
+ return answer;
+ }
+
+ public void setAnswer(ArrayList answer) {
+ this.answer = answer;
+ }
+
+ public int getAnswer_type() {
+ return answer_type;
+ }
+
+ public void setAnswer_type(int answer_type) {
+ this.answer_type = answer_type;
+ }
+
+ public int getDifficulty() {
+ return difficulty;
+ }
+
+ public void setDifficulty(int difficulty) {
+ this.difficulty = difficulty;
+ }
+
+ public Date getCreated_at() {
+ return created_at;
+ }
+
+ public void setCreated_at(Date created_at) {
+ this.created_at = created_at;
+ }
+
+ public Date getUpdated_at() {
+ return updated_at;
+ }
+
+ public void setUpdated_at(Date updated_at) {
+ this.updated_at = updated_at;
+ }
+
+ private int id;
+ private String content;
+ private ArrayList answers;
+ private ArrayList answer;
+ private int answer_type;
+ private int difficulty;
+ private Date created_at;
+ private Date updated_at;
+}
diff --git a/app/src/main/java/com/alfredayibonte/questionnaireview/utils/JsonHelper.java b/app/src/main/java/com/alfredayibonte/questionnaireview/utils/JsonHelper.java
new file mode 100644
index 0000000..916fe40
--- /dev/null
+++ b/app/src/main/java/com/alfredayibonte/questionnaireview/utils/JsonHelper.java
@@ -0,0 +1,34 @@
+package com.alfredayibonte.questionnaireview.utils;
+
+import android.content.Context;
+import java.io.IOException;
+import java.io.InputStream;
+
+
+public class JsonHelper {
+
+ public static String loadJSONFromAsset(Context context) {
+ String json = null;
+ try {
+
+ InputStream is = context.getAssets().open("question.json");
+
+ int size = is.available();
+
+ byte[] buffer = new byte[size];
+
+ is.read(buffer);
+
+ is.close();
+
+ json = new String(buffer, "UTF-8");
+
+
+ } catch (IOException ex) {
+ ex.printStackTrace();
+ return null;
+ }
+ return json;
+ }
+
+}
diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml
index 7d87655..5bc8da2 100644
--- a/app/src/main/res/layout/activity_main.xml
+++ b/app/src/main/res/layout/activity_main.xml
@@ -5,14 +5,15 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.alfredayibonte.questionnaireview.MainActivity">
-
+ app:layout_constraintTop_toTopOf="parent"
+ android:id="@+id/pager"/>
+
diff --git a/app/src/main/res/layout/question_fragment.xml b/app/src/main/res/layout/question_fragment.xml
new file mode 100644
index 0000000..98f441b
--- /dev/null
+++ b/app/src/main/res/layout/question_fragment.xml
@@ -0,0 +1,11 @@
+
+
\ No newline at end of file
From bde426f1a36688e11f52530e4b05f3be8b389265 Mon Sep 17 00:00:00 2001
From: Alfred
Date: Mon, 22 May 2017 06:59:24 +0000
Subject: [PATCH 4/4] * rename AnswerType to ViewType * add customTheme *
change all textbox and checkbox to AppCompat
---
app/src/main/AndroidManifest.xml | 4 +-
.../questionnaireview/AppController.java | 8 +--
.../questionnaireview/MainActivity.java | 18 ++----
.../questionnaireview/QuestionFragment.java | 28 ++++++++--
.../QuestionPagerAdapter.java | 6 +-
...{ResultObject.java => ResponseObject.java} | 4 +-
app/src/main/res/layout/question_fragment.xml | 3 +-
app/src/main/res/values/colors.xml | 1 +
app/src/main/res/values/styles.xml | 9 +++
.../CheckListItemView.java | 12 ++--
.../QuestionnaireView.java | 56 ++++++++++---------
.../RadioListItemView.java | 6 +-
.../adapters/CheckListAdapter.java | 10 ++--
.../adapters/RadioListAdapter.java | 5 +-
.../utils/{AnswerType.java => ViewType.java} | 2 +-
.../src/main/res/layout/check_list_item.xml | 4 +-
.../src/main/res/layout/radio_list_item.xml | 3 +-
.../src/main/res/values/attrs.xml | 8 +++
.../src/main/res/values/colors.xml | 1 +
19 files changed, 110 insertions(+), 78 deletions(-)
rename app/src/main/java/com/alfredayibonte/questionnaireview/models/{ResultObject.java => ResponseObject.java} (96%)
rename questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/utils/{AnswerType.java => ViewType.java} (90%)
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index ecc8b34..280afc3 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -10,7 +10,9 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
-
+
diff --git a/app/src/main/java/com/alfredayibonte/questionnaireview/AppController.java b/app/src/main/java/com/alfredayibonte/questionnaireview/AppController.java
index 60b684b..8c1349b 100644
--- a/app/src/main/java/com/alfredayibonte/questionnaireview/AppController.java
+++ b/app/src/main/java/com/alfredayibonte/questionnaireview/AppController.java
@@ -2,7 +2,7 @@
import android.app.Application;
-import com.alfredayibonte.questionnaireview.models.ResultObject;
+import com.alfredayibonte.questionnaireview.models.ResponseObject;
import com.alfredayibonte.questionnaireview.utils.JsonHelper;
import java.lang.reflect.Type;
import java.util.ArrayList;
@@ -17,7 +17,7 @@
*/
public class AppController extends Application {
- private List questions;
+ private List questions;
public static final String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
Gson gson;
@Override
@@ -25,14 +25,14 @@ public void onCreate() {
super.onCreate();
questions = new ArrayList<>();
String result = JsonHelper.loadJSONFromAsset(getApplicationContext());
- Type type = new TypeToken>() {}.getType();
+ Type type = new TypeToken>() {}.getType();
gson = new GsonBuilder()
.setDateFormat(DATE_FORMAT)
.create();
questions = gson.fromJson(result, type);
}
- public List getQuestions(){
+ public List getQuestions(){
return questions;
}
}
diff --git a/app/src/main/java/com/alfredayibonte/questionnaireview/MainActivity.java b/app/src/main/java/com/alfredayibonte/questionnaireview/MainActivity.java
index c9d74b5..deb930d 100644
--- a/app/src/main/java/com/alfredayibonte/questionnaireview/MainActivity.java
+++ b/app/src/main/java/com/alfredayibonte/questionnaireview/MainActivity.java
@@ -3,7 +3,8 @@
import android.support.v4.view.PagerAdapter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
-import android.view.MenuItem;
+
+import com.alfredayibonte.questionnaireviewlib.models.Question;
public class MainActivity extends AppCompatActivity implements QuestionFragment.OnQuestionItemSelectedListener {
private NonSwipeableViewPager mPager;
@@ -22,24 +23,13 @@ protected void onCreate(Bundle savedInstanceState) {
}
@Override
- public boolean onOptionsItemSelected(MenuItem item) {
- switch (item.getItemId()) {
- case android.R.id.home:
- onBackPressed();
- return true;
- }
-
- return super.onOptionsItemSelected(item);
- }
-
- @Override
- public void onPreviousButtonPressed() {
+ public void onPreviousButtonPressed(Question question) {
int page = mPager.getCurrentItem();
mPager.setCurrentItem( page - 1 );
}
@Override
- public void onNextButtonPressed() {
+ public void onNextButtonPressed(Question question) {
int page = mPager.getCurrentItem();
mPager.setCurrentItem( page + 1 );
}
diff --git a/app/src/main/java/com/alfredayibonte/questionnaireview/QuestionFragment.java b/app/src/main/java/com/alfredayibonte/questionnaireview/QuestionFragment.java
index fa04bc8..68973ab 100644
--- a/app/src/main/java/com/alfredayibonte/questionnaireview/QuestionFragment.java
+++ b/app/src/main/java/com/alfredayibonte/questionnaireview/QuestionFragment.java
@@ -12,15 +12,19 @@
import android.view.ViewGroup;
import android.widget.Button;
import com.alfredayibonte.questionnaireviewlib.QuestionnaireView;
+import com.alfredayibonte.questionnaireviewlib.adapters.CheckListAdapter;
+import com.alfredayibonte.questionnaireviewlib.adapters.RadioListAdapter;
+import com.alfredayibonte.questionnaireviewlib.models.Answer;
import com.alfredayibonte.questionnaireviewlib.models.Question;
-import com.alfredayibonte.questionnaireviewlib.utils.AnswerType;
import java.util.ArrayList;
+import java.util.List;
import static com.alfredayibonte.questionnaireview.QuestionPagerAdapter.ANSWERS_KEY;
import static com.alfredayibonte.questionnaireview.QuestionPagerAdapter.ANSWER_TYPE_KEY;
import static com.alfredayibonte.questionnaireview.QuestionPagerAdapter.POSITION_KEY;
import static com.alfredayibonte.questionnaireview.QuestionPagerAdapter.QUESTION_KEY;
-public class QuestionFragment extends Fragment implements TextWatcher {
+public class QuestionFragment extends Fragment implements TextWatcher,
+ CheckListAdapter.OnCheckItemClickListener, RadioListAdapter.OnRadioItemClickListener {
OnQuestionItemSelectedListener mCallback;
Question question;
ArrayList answers;
@@ -47,6 +51,8 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
questionnaireView.setQuestion(question.getContent());
questionnaireView.setViewType(question.getAnswer_type());
questionnaireView.setAnswers(answers);
+ questionnaireView.addRadioItemListener(this);
+ questionnaireView.addCheckItemListener(this);
questionnaireView.addTextChangedListener(this);
View view = View.inflate(getContext(), R.layout.footer, null);
Button next = (Button) view.findViewById(R.id.next);
@@ -54,14 +60,14 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- mCallback.onNextButtonPressed();
+ mCallback.onNextButtonPressed(question);
}
});
questionnaireView.addFooter(view);
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
- mCallback.onPreviousButtonPressed();
+ mCallback.onPreviousButtonPressed(question);
}
});
@@ -83,9 +89,19 @@ public void afterTextChanged(Editable editable) {
}
+ @Override
+ public void onCheckItemClick(List answers) {
+ //todo: get answers here if check list
+ }
+
+ @Override
+ public void onRadioItemClick(List answers) {
+ //todo: get answers here if radio
+ }
+
public interface OnQuestionItemSelectedListener{
- public void onPreviousButtonPressed();
- public void onNextButtonPressed();
+ public void onPreviousButtonPressed(Question question);
+ public void onNextButtonPressed(Question question);
}
@Override
diff --git a/app/src/main/java/com/alfredayibonte/questionnaireview/QuestionPagerAdapter.java b/app/src/main/java/com/alfredayibonte/questionnaireview/QuestionPagerAdapter.java
index 9eaa0ea..e975649 100644
--- a/app/src/main/java/com/alfredayibonte/questionnaireview/QuestionPagerAdapter.java
+++ b/app/src/main/java/com/alfredayibonte/questionnaireview/QuestionPagerAdapter.java
@@ -6,7 +6,7 @@
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
-import com.alfredayibonte.questionnaireview.models.ResultObject;
+import com.alfredayibonte.questionnaireview.models.ResponseObject;
import java.util.ArrayList;
import java.util.List;
@@ -18,7 +18,7 @@ public class QuestionPagerAdapter extends FragmentStatePagerAdapter {
protected static final String QUESTION_KEY = "QUESTION";
protected static final String ANSWERS_KEY = "ANSWERS";
protected static final String ANSWER_TYPE_KEY = "ANSWER_TYPE";
- List questions;
+ List questions;
public QuestionPagerAdapter(Context context,
FragmentManager fm){
super(fm);
@@ -26,7 +26,7 @@ public QuestionPagerAdapter(Context context,
questions = new ArrayList<>();
}
- public QuestionPagerAdapter(Context context, FragmentManager fm, List questions){
+ public QuestionPagerAdapter(Context context, FragmentManager fm, List questions){
this(context, fm);
this.questions = questions;
}
diff --git a/app/src/main/java/com/alfredayibonte/questionnaireview/models/ResultObject.java b/app/src/main/java/com/alfredayibonte/questionnaireview/models/ResponseObject.java
similarity index 96%
rename from app/src/main/java/com/alfredayibonte/questionnaireview/models/ResultObject.java
rename to app/src/main/java/com/alfredayibonte/questionnaireview/models/ResponseObject.java
index 7882d4a..881d812 100644
--- a/app/src/main/java/com/alfredayibonte/questionnaireview/models/ResultObject.java
+++ b/app/src/main/java/com/alfredayibonte/questionnaireview/models/ResponseObject.java
@@ -8,9 +8,9 @@
* Created by Alfredayibonte on 5/18/17.
*/
-public class ResultObject {
+public class ResponseObject {
- public ResultObject(){}
+ public ResponseObject(){}
public int getId() {
return id;
diff --git a/app/src/main/res/layout/question_fragment.xml b/app/src/main/res/layout/question_fragment.xml
index 98f441b..ebc586a 100644
--- a/app/src/main/res/layout/question_fragment.xml
+++ b/app/src/main/res/layout/question_fragment.xml
@@ -8,4 +8,5 @@
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
- android:background="@color/white" />
\ No newline at end of file
+ android:textColor="@color/colorPrimary"
+ />
\ No newline at end of file
diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml
index 3ab3e9c..2008ed1 100644
--- a/app/src/main/res/values/colors.xml
+++ b/app/src/main/res/values/colors.xml
@@ -3,4 +3,5 @@
#3F51B5
#303F9F
#FF4081
+ #000
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index daa2a5c..1e16f4e 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -8,4 +8,13 @@
- @color/colorAccent
+
+
+
diff --git a/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/CheckListItemView.java b/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/CheckListItemView.java
index ff46f5f..7d3769f 100644
--- a/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/CheckListItemView.java
+++ b/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/CheckListItemView.java
@@ -1,10 +1,10 @@
package com.alfredayibonte.questionnaireviewlib;
import android.content.Context;
+import android.support.v7.widget.AppCompatCheckBox;
+import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
-import android.widget.CheckBox;
import android.widget.LinearLayout;
-import android.widget.TextView;
import com.alfredayibonte.questionnaireviewlib.adapters.CheckListAdapter;
import com.alfredayibonte.questionnaireviewlib.models.Answer;
@@ -14,8 +14,8 @@
* Created by Alfredayibonte on 5/3/17.
*/
public class CheckListItemView extends LinearLayout{
- private CheckBox checkBox;
- private TextView textView;
+ private AppCompatCheckBox checkBox;
+ private AppCompatTextView textView;
private Answer answer;
private Context context;
private CheckListAdapter adapter;
@@ -42,8 +42,8 @@ public CheckListItemView(Context context, AttributeSet attrs) {
@Override
protected void onFinishInflate() {
super.onFinishInflate();
- checkBox = (CheckBox)findViewById(R.id.checkbox);
- textView = (TextView)findViewById(R.id.tv1);
+ checkBox = (AppCompatCheckBox)findViewById(R.id.checkbox);
+ textView = (AppCompatTextView)findViewById(R.id.tv1);
}
diff --git a/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/QuestionnaireView.java b/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/QuestionnaireView.java
index 3ced7a6..c66ec17 100644
--- a/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/QuestionnaireView.java
+++ b/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/QuestionnaireView.java
@@ -4,6 +4,7 @@
import android.content.res.TypedArray;
import android.graphics.Color;
import android.support.v4.content.ContextCompat;
+import android.support.v7.widget.AppCompatEditText;
import android.text.InputType;
import android.text.TextWatcher;
import android.util.AttributeSet;
@@ -17,7 +18,7 @@
import com.alfredayibonte.questionnaireviewlib.adapters.RadioListAdapter;
import com.alfredayibonte.questionnaireviewlib.models.Answer;
import com.alfredayibonte.questionnaireviewlib.models.Question;
-import com.alfredayibonte.questionnaireviewlib.utils.AnswerType;
+import com.alfredayibonte.questionnaireviewlib.utils.ViewType;
import java.util.ArrayList;
import java.util.List;
@@ -27,7 +28,7 @@
*/
public class QuestionnaireView extends RelativeLayout {
- private EditText editTv;
+ private AppCompatEditText editTv;
private WebView webview;
private ListView listView;
private int viewType;
@@ -37,21 +38,29 @@ public class QuestionnaireView extends RelativeLayout {
private CheckListAdapter checkAdapter;
private View view;
public QuestionnaireView(Context context) {
- super(context);
+ this(context, null, 0);
}
public QuestionnaireView(Context context, AttributeSet attrs) {
- super(context, attrs);
- drawInnerViews(context, attrs);
+ this(context, attrs, 0);
+ }
+
+ public QuestionnaireView(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
if (!isInEditMode()) {
- parseAttributes(context, attrs);
+ parseAttributes(context, attrs, defStyleAttr);
}
+
}
private void drawInnerViews(Context context, AttributeSet attrs){
+ float density = context.getResources().getDisplayMetrics().density;
+ int value16 = (int)(16*density);
+ int value10 = (int)(10*density);
+ int value40 = (int)(40*density);
LayoutParams mainLayoutParams = new LayoutParams(
LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
- mainLayoutParams.setMargins(16,16,16,16);
+ mainLayoutParams.setMargins(value16,value16,value16,value16);
setLayoutParams(mainLayoutParams);
//creation & addition of webview
@@ -61,7 +70,7 @@ private void drawInnerViews(Context context, AttributeSet attrs){
new LayoutBuilder()
.addWidth(LayoutParams.MATCH_PARENT)
.addHeight(LayoutParams.WRAP_CONTENT)
- .setMargin(0,40,0,0)
+ .setMargin(value10,value40,0,0)
.create()
);
webview.getSettings();
@@ -75,21 +84,21 @@ private void drawInnerViews(Context context, AttributeSet attrs){
new LayoutBuilder()
.addWidth(LayoutParams.MATCH_PARENT)
.addHeight(LayoutParams.WRAP_CONTENT)
- .setMargin(0,10,0,0)
+ .setMargin(0,value10,0,0)
.addRule(BELOW, webview.getId() )
.create()
);
addView(listView );
//creation & addition of editText
- editTv = new EditText(context, attrs);
+ editTv = new AppCompatEditText(context, attrs);
editTv.setVisibility(GONE);
editTv.setId(android.R.id.text1);
editTv.setLayoutParams(
new LayoutBuilder()
.addWidth(LayoutParams.MATCH_PARENT)
.addHeight(LayoutParams.WRAP_CONTENT)
- .setMargin(0, 10, 0, 0)
+ .setMargin(value10, value10, 0, 0)
.addRule(BELOW, webview.getId())
.create()
);
@@ -99,21 +108,16 @@ private void drawInnerViews(Context context, AttributeSet attrs){
}
- public QuestionnaireView(Context context, AttributeSet attrs, int defStyleAttr) {
- super(context, attrs, defStyleAttr);
- if (!isInEditMode()) {
- parseAttributes(context, attrs);
- }
- }
-
- private void parseAttributes(Context context, AttributeSet attrs) {
+ private void parseAttributes(Context context, AttributeSet attrs, int defStyleAttr) {
+ drawInnerViews(context, attrs);
TypedArray values = context.obtainStyledAttributes(attrs, R.styleable.QuestionBaseView);
- int position = values.getInt(R.styleable.QuestionBaseView_view_type, 1);
- setViewType(position);
+ int viewType = values.getInt(R.styleable.QuestionBaseView_view_type, 1);
+ setViewType(viewType);
String text = values.getString(R.styleable.QuestionBaseView_question);
setQuestion(text);
CharSequence[] answers = values.getTextArray(R.styleable.QuestionBaseView_entries);
if(answers != null) setAnswers(answers);
+
values.recycle();
}
@@ -129,11 +133,11 @@ public void setViewType(int viewType){
if(question != null)
question.setAnswer_type(viewType);
switch (viewType){
- case AnswerType.RADIO:
- case AnswerType.CHECKLIST:
+ case ViewType.RADIO:
+ case ViewType.CHECKLIST:
makeListViewVisible();
break;
- case AnswerType.EDITTEXT:
+ case ViewType.EDITTEXT:
listView.setVisibility(GONE);
editTv.setVisibility(VISIBLE);
break;
@@ -159,11 +163,11 @@ public void setQuestion(String content){
public void setAnswers(List answers){
this.answers = answers;
switch (viewType){
- case AnswerType.CHECKLIST:
+ case ViewType.CHECKLIST:
checkAdapter = new CheckListAdapter(getContext(), this.answers);
listView.setAdapter(checkAdapter);
break;
- case AnswerType.RADIO:
+ case ViewType.RADIO:
radioAdapter = new RadioListAdapter(getContext(), this.answers);
listView.setAdapter(radioAdapter);
break;
diff --git a/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/RadioListItemView.java b/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/RadioListItemView.java
index 75bb010..9594f96 100644
--- a/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/RadioListItemView.java
+++ b/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/RadioListItemView.java
@@ -2,9 +2,9 @@
import android.content.Context;
import android.support.v7.widget.AppCompatRadioButton;
+import android.support.v7.widget.AppCompatTextView;
import android.util.AttributeSet;
import android.widget.LinearLayout;
-import android.widget.TextView;
import com.alfredayibonte.questionnaireviewlib.adapters.RadioListAdapter;
import com.alfredayibonte.questionnaireviewlib.models.Answer;
@@ -15,7 +15,7 @@
*/
public class RadioListItemView extends LinearLayout{
private AppCompatRadioButton radioButton;
- private TextView textView;
+ private AppCompatTextView textView;
private Answer answer;
private Context context;
private RadioListAdapter adapter;
@@ -43,7 +43,7 @@ public RadioListItemView(Context context, AttributeSet attrs) {
protected void onFinishInflate() {
super.onFinishInflate();
radioButton = (AppCompatRadioButton) findViewById(R.id.radio);
- textView = (TextView)findViewById(R.id.tv1);
+ textView = (AppCompatTextView)findViewById(R.id.tv1);
}
diff --git a/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/adapters/CheckListAdapter.java b/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/adapters/CheckListAdapter.java
index e094d76..3b056af 100644
--- a/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/adapters/CheckListAdapter.java
+++ b/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/adapters/CheckListAdapter.java
@@ -20,18 +20,19 @@
public class CheckListAdapter extends BaseAdapter {
private List answers = new ArrayList<>();
private Context context;
- OnCheckItemClickListener listener;
+ private OnCheckItemClickListener listener;
+ private CheckListItemView checkItemView;
public CheckListAdapter(Context context, List answers) {
this.context = context;
this.answers = answers;
}
- public CheckListAdapter(Context context, List answers, OnCheckItemClickListener listener) {
+ protected CheckListAdapter(Context context, List answers, OnCheckItemClickListener listener) {
this(context, answers);
this.listener = listener;
}
- public CheckListAdapter( List answers, OnCheckItemClickListener listener, Context context) {
+ protected CheckListAdapter( List answers, OnCheckItemClickListener listener, Context context) {
this(context, answers);
this.listener = listener;
}
@@ -42,6 +43,8 @@ public interface OnCheckItemClickListener {
void onCheckItemClick(List answers);
}
+
+
public void addListener(OnCheckItemClickListener listener){
this.listener = listener;
}
@@ -67,7 +70,6 @@ public long getItemId(int position) {
public View getView(final int position, View convertView, ViewGroup parent) {
Answer answer = answers.get(position);
- CheckListItemView checkItemView = null;
if (convertView == null){
checkItemView = (CheckListItemView)View.inflate(context, R.layout.check_list_item, null);
}
diff --git a/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/adapters/RadioListAdapter.java b/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/adapters/RadioListAdapter.java
index a487ad4..0b8e133 100644
--- a/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/adapters/RadioListAdapter.java
+++ b/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/adapters/RadioListAdapter.java
@@ -22,7 +22,8 @@
public class RadioListAdapter extends BaseAdapter{
private List answers = new ArrayList<>();
private Context context;
- RadioListAdapter.OnRadioItemClickListener listener;
+ private RadioListAdapter.OnRadioItemClickListener listener;
+ private RadioListItemView radioListItemView = null;
public RadioListAdapter(Context context, List answers) {
this.context = context;
@@ -58,10 +59,8 @@ public interface OnRadioItemClickListener {
public View getView(final int position, View convertView, ViewGroup parent) {
Answer item = (Answer) getItem(position);
- RadioListItemView radioListItemView = null;
if (convertView == null) {
radioListItemView = (RadioListItemView)View.inflate(context, R.layout.radio_list_item, null);
-
} else{
radioListItemView = (RadioListItemView)convertView;
}
diff --git a/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/utils/AnswerType.java b/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/utils/ViewType.java
similarity index 90%
rename from questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/utils/AnswerType.java
rename to questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/utils/ViewType.java
index 91394d1..9f1ce55 100644
--- a/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/utils/AnswerType.java
+++ b/questionnaireviewlib/src/main/java/com/alfredayibonte/questionnaireviewlib/utils/ViewType.java
@@ -4,7 +4,7 @@
*
* Created by Alfredayibonte on 5/3/17.
*/
-public class AnswerType {
+public class ViewType {
public static final int RADIO = 1;
public static final int CHECKLIST = 2;
public static final int EDITTEXT = 3;
diff --git a/questionnaireviewlib/src/main/res/layout/check_list_item.xml b/questionnaireviewlib/src/main/res/layout/check_list_item.xml
index 9c2dac7..2370c91 100644
--- a/questionnaireviewlib/src/main/res/layout/check_list_item.xml
+++ b/questionnaireviewlib/src/main/res/layout/check_list_item.xml
@@ -4,12 +4,12 @@
android:id="@+id/check_list_item"
android:layout_width="match_parent"
android:layout_height="match_parent">
-
-
-
\ No newline at end of file
diff --git a/questionnaireviewlib/src/main/res/values/attrs.xml b/questionnaireviewlib/src/main/res/values/attrs.xml
index 9413aaa..d847522 100644
--- a/questionnaireviewlib/src/main/res/values/attrs.xml
+++ b/questionnaireviewlib/src/main/res/values/attrs.xml
@@ -20,6 +20,14 @@
+
+
+
+
+
+
+
+
diff --git a/questionnaireviewlib/src/main/res/values/colors.xml b/questionnaireviewlib/src/main/res/values/colors.xml
index 7c5c12d..9336aa3 100644
--- a/questionnaireviewlib/src/main/res/values/colors.xml
+++ b/questionnaireviewlib/src/main/res/values/colors.xml
@@ -1,4 +1,5 @@
#FFF
+ #F0F
\ No newline at end of file