Skip to content

Commit

Permalink
Merge pull request #5 from alfredayibonte/feat/add-footer
Browse files Browse the repository at this point in the history
Feat/add footer
  • Loading branch information
alfredayibonte authored May 29, 2017
2 parents 0f135ec + bde426f commit ce8d8ca
Show file tree
Hide file tree
Showing 26 changed files with 608 additions and 74 deletions.
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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')
}
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
package="com.alfredayibonte.questionnaireview">

<application
android:name=".AppController"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity
android:theme="@style/customTheme"
android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
51 changes: 51 additions & 0 deletions app/src/main/assets/question.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
[
{
"id": 1,
"answers": [
"a",
"b",
"c"
],
"answer": [
"a"
],
"content": "<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. <strong>Velit</strong> earum saepe iste nesciunt dolor corporis, distinctio <em>repudiandae</em> aliquid consectetur impedit eveniet facilis eius nisi nobis a porro quis consequatur harum?</p>\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": "<p>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.</p>\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": "<p><span style=\"font-size:48px;\">A<sup>2&nbsp;</sup>- B<sup>2 </sup>= ?</span></p>\n",
"answer_type": 2,
"difficulty": 1,
"created_at": "2017-01-20T22:30:33.216Z",
"updated_at": "2017-01-20T22:30:33.216Z"
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.alfredayibonte.questionnaireview;

import android.app.Application;

import com.alfredayibonte.questionnaireview.models.ResponseObject;
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<ResponseObject> 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<List<ResponseObject>>() {}.getType();
gson = new GsonBuilder()
.setDateFormat(DATE_FORMAT)
.create();
questions = gson.fromJson(result, type);
}

public List<ResponseObject> getQuestions(){
return questions;
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
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 com.alfredayibonte.questionnaireviewlib.QuestionnaireView;
import com.alfredayibonte.questionnaireviewlib.utils.AnswerType;

public class MainActivity extends AppCompatActivity implements TextWatcher {
import com.alfredayibonte.questionnaireviewlib.models.Question;

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("<h1 style='color: red;'>What is the name of this library ?</h1>");
questionnaireView.setViewType(AnswerType.EDITTEXT);
questionnaireView.addTextChangedListener(this);
}

@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
mPager = (NonSwipeableViewPager)findViewById(R.id.pager);
AppController app = (AppController) getApplication();
mPagerAdapter = new QuestionPagerAdapter(getApplicationContext(),
getSupportFragmentManager(), app.getQuestions());
mPager.setAdapter(mPagerAdapter);

}

@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
Log.e(MainActivity.class.getSimpleName(), charSequence.toString());
public void onPreviousButtonPressed(Question question) {
int page = mPager.getCurrentItem();
mPager.setCurrentItem( page - 1 );
}

@Override
public void afterTextChanged(Editable editable) {

public void onNextButtonPressed(Question question) {
int page = mPager.getCurrentItem();
mPager.setCurrentItem( page + 1 );
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
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.adapters.CheckListAdapter;
import com.alfredayibonte.questionnaireviewlib.adapters.RadioListAdapter;
import com.alfredayibonte.questionnaireviewlib.models.Answer;
import com.alfredayibonte.questionnaireviewlib.models.Question;
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,
CheckListAdapter.OnCheckItemClickListener, RadioListAdapter.OnRadioItemClickListener {
OnQuestionItemSelectedListener mCallback;
Question question;
ArrayList<String> 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.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);
Button back = (Button) view.findViewById(R.id.back);
next.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mCallback.onNextButtonPressed(question);
}
});
questionnaireView.addFooter(view);
back.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mCallback.onPreviousButtonPressed(question);
}
});

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) {

}

@Override
public void onCheckItemClick(List<Answer> answers) {
//todo: get answers here if check list
}

@Override
public void onRadioItemClick(List<Answer> answers) {
//todo: get answers here if radio
}

public interface OnQuestionItemSelectedListener{
public void onPreviousButtonPressed(Question question);
public void onNextButtonPressed(Question question);
}

@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");
}
}

}
}
Loading

0 comments on commit ce8d8ca

Please sign in to comment.