-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from alfredayibonte/feat/add-footer
Feat/add footer
- Loading branch information
Showing
26 changed files
with
608 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 </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" | ||
} | ||
] |
38 changes: 38 additions & 0 deletions
38
app/src/main/java/com/alfredayibonte/questionnaireview/AppController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
35 changes: 17 additions & 18 deletions
35
app/src/main/java/com/alfredayibonte/questionnaireview/MainActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/alfredayibonte/questionnaireview/NonSwipeableViewPager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
126 changes: 126 additions & 0 deletions
126
app/src/main/java/com/alfredayibonte/questionnaireview/QuestionFragment.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
|
||
} | ||
} |
Oops, something went wrong.