Skip to content

Commit

Permalink
Page class names changed to Question.
Browse files Browse the repository at this point in the history
  • Loading branch information
douglasrafael committed Mar 12, 2019
1 parent 6407230 commit db4c026
Show file tree
Hide file tree
Showing 13 changed files with 310 additions and 290 deletions.
40 changes: 28 additions & 12 deletions app/src/main/java/br/edu/uepb/nutes/simplesurvey/SimpleSurvey1.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,43 +3,59 @@
import android.support.v4.content.ContextCompat;

import br.edu.uepb.nutes.simplesurvey.base.SimpleSurvey;
import br.edu.uepb.nutes.simplesurvey.pages.InforPage;
import br.edu.uepb.nutes.simplesurvey.pages.RadioQuestion;
import br.edu.uepb.nutes.simplesurvey.pages.DichotomicChoice;
import br.edu.uepb.nutes.simplesurvey.pages.Infor;

public class SimpleSurvey1 extends SimpleSurvey implements RadioQuestion.OnRadioListener,
InforPage.OnButtonListener {
public class SimpleSurvey1 extends SimpleSurvey implements DichotomicChoice.OnRadioListener,
Infor.OnButtonListener {

@Override
protected void initView() {
addPages();
}

private void addPages() {
setMessageBlocked("Ops! responda para poder ir para próxima perguta...");

// page 1
addQuestion(new RadioQuestion.Config()
addQuestion(new DichotomicChoice.Config()
.title("Title of the question")
.description("Lorem Ipsum is simply dummy text of the printing and typesetting industry?")
.radioLeftText(R.string.masc)
.radioRightText(R.string.femi)
.enableNextQuestionAuto()
.nextQuestionAuto()
.image(R.drawable.placeholder)
.answerRequired()
.enableZoomImage()
.pageNumber(1)
.build());

addQuestion(new RadioQuestion.Config()
.title("Simple Survey")
addQuestion(new DichotomicChoice.Config()
.title("Simple Survey 1")
.description("Simple survey from @NUTES")
.colorBackground(ContextCompat.getColor(this, R.color.colorCyan))
.answerRequired()
.pageNumber(1)
.pageNumber(2)
.build());

addQuestion(new DichotomicChoice.Config()
.title("Simple Survey 2")
.description("Simple survey from @NUTES")
.pageNumber(3)
.nextQuestionAuto()
.build());

addQuestion(new InforPage.Config()
addQuestion(new DichotomicChoice.Config()
.title("Simple Survey 3")
.description("Simple survey from @NUTES")
.colorBackground(ContextCompat.getColor(this, R.color.colorBlueGrey))
.pageNumber(4)
.build());


addQuestion(new Infor.Config()
.title("Lorem Ipsum")
.description("Lorem Ipsum is simply dummy text of the printing and typesetting industry." +
" Lorem Ipsum has been the industry's standard dummy text ever since the 1500s,")
.pageNumber(4)
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
import br.edu.uepb.nutes.simplesurvey.R;

/**
* BaseConfigPage implementation.
* BaseConfigQuestion implementation.
*
* @param <T>
*/
public abstract class BaseConfigPage<T> {
public abstract class BaseConfigQuestion<T> {
private String titleStr,
descriptionStr;

Expand All @@ -51,10 +51,9 @@ public abstract class BaseConfigPage<T> {
drawableClose;

private boolean zoomDisabled,
isAnswerRequired,
nextQuestionAuto;

protected BaseConfigPage() {
protected BaseConfigQuestion() {
this.layout = 0;
this.title = 0;
this.description = 0;
Expand All @@ -64,7 +63,6 @@ protected BaseConfigPage() {
this.descriptionColor = Color.BLACK;
this.drawableClose = R.drawable.ic_action_close_light;
this.zoomDisabled = true;
this.isAnswerRequired = false;
this.nextQuestionAuto = false;
}

Expand Down Expand Up @@ -116,10 +114,6 @@ public boolean isZoomDisabled() {
return zoomDisabled;
}

public boolean isAnswerRequired() {
return isAnswerRequired;
}

public boolean isNextQuestionAuto() {
return nextQuestionAuto;
}
Expand Down Expand Up @@ -307,22 +301,12 @@ public T enableZoomImage() {
return (T) this;
}

/**
* Enable question required.
*
* @return Config
*/
public T answerRequired() {
this.isAnswerRequired = true;
return (T) this;
}

/**
* Activate next page/question automatically after a valid response.
*
* @return Config
*/
public T enableNextQuestionAuto() {
public T nextQuestionAuto() {
this.nextQuestionAuto = true;
return (T) this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
Expand All @@ -45,17 +44,17 @@
import br.edu.uepb.nutes.simplesurvey.R;

/**
* BasePage implementation.
* BaseQuestion implementation.
*
* @param <T>
*/
public abstract class BasePage<T extends BaseConfigPage> extends Fragment implements IBasePage<T> {
protected boolean isBlocked;
protected int pageNumber;
protected OnPageListener mPageListener;

public abstract class BaseQuestion<T extends BaseConfigQuestion> extends Fragment implements IBaseQuestion<T> {
private final String SEPARATOR_ITEMS = "#";

private boolean isBlocked;
private int pageNumber;
private OnQuestionListener mPageListener;

public TextView titleTextView;
public TextView descTextView;
public PhotoView questionImageView;
Expand All @@ -65,6 +64,10 @@ public abstract class BasePage<T extends BaseConfigPage> extends Fragment implem
public LinearLayout boxImage;
public LinearLayout boxInput;

public BaseQuestion() {

}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater,
Expand All @@ -82,37 +85,37 @@ public View onCreateView(@NonNull LayoutInflater inflater,
this.boxInput = view.findViewById(R.id.box_input);

if (boxTitle != null && titleTextView != null) {
if (getConfigsPage().getTitle() != 0) {
titleTextView.setText(getConfigsPage().getTitle());
} else if (getConfigsPage().getTitleStr() != null && !getConfigsPage().getTitleStr().isEmpty()) {
titleTextView.setText(getConfigsPage().getTitleStr());
if (getConfigsQuestion().getTitle() != 0) {
titleTextView.setText(getConfigsQuestion().getTitle());
} else if (getConfigsQuestion().getTitleStr() != null && !getConfigsQuestion().getTitleStr().isEmpty()) {
titleTextView.setText(getConfigsQuestion().getTitleStr());
} else {
boxTitle.setVisibility(View.GONE);
}

if (getConfigsPage().getTitleColor() != 0) {
titleTextView.setTextColor(getConfigsPage().getTitleColor());
if (getConfigsQuestion().getTitleColor() != 0) {
titleTextView.setTextColor(getConfigsQuestion().getTitleColor());
}
}

if (boxDescription != null && descTextView != null) {
if (getConfigsPage().getDescription() != 0) {
descTextView.setText(getConfigsPage().getDescription());
} else if (getConfigsPage().getDescriptionStr() != null
&& !getConfigsPage().getDescriptionStr().isEmpty()) {
descTextView.setText(getConfigsPage().getDescriptionStr());
if (getConfigsQuestion().getDescription() != 0) {
descTextView.setText(getConfigsQuestion().getDescription());
} else if (getConfigsQuestion().getDescriptionStr() != null
&& !getConfigsQuestion().getDescriptionStr().isEmpty()) {
descTextView.setText(getConfigsQuestion().getDescriptionStr());
} else {
boxDescription.setVisibility(View.GONE);
}

if (getConfigsPage().getDescriptionColor() != 0) {
descTextView.setTextColor(getConfigsPage().getDescriptionColor());
if (getConfigsQuestion().getDescriptionColor() != 0) {
descTextView.setTextColor(getConfigsQuestion().getDescriptionColor());
}
}

if (closeImageButton != null) {
if (getConfigsPage().getDrawableClose() != 0) {
closeImageButton.setImageResource(getConfigsPage().getDrawableClose());
if (getConfigsQuestion().getDrawableClose() != 0) {
closeImageButton.setImageResource(getConfigsQuestion().getDrawableClose());
closeImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand All @@ -125,11 +128,11 @@ public void onClick(View v) {
}

if (boxImage != null && questionImageView != null) {
if (getConfigsPage().getImage() != 0) {
questionImageView.setImageResource(getConfigsPage().getImage());
if (getConfigsQuestion().getImage() != 0) {
questionImageView.setImageResource(getConfigsQuestion().getImage());

// enable/disable zoom
questionImageView.setZoomable(!getConfigsPage().isZoomDisabled());
questionImageView.setZoomable(!getConfigsQuestion().isZoomDisabled());
} else boxImage.setVisibility(View.GONE);
}

Expand Down Expand Up @@ -157,27 +160,28 @@ private AppIntroViewPager getPageInstance() {
}

@Override
public void blockPage() {
public void blockQuestion() {
this.isBlocked = true;
getAppIntroInstance().setNextPageSwipeLock(this.isBlocked);
}

@Override
public void unlockPage() {
public void unlockQuestion() {
this.isBlocked = false;
getAppIntroInstance().setNextPageSwipeLock(this.isBlocked);

// To hide unnecessary buttons, mysteriously,
// the buttons are activated when a page is unlocked.
getAppIntroInstance().showDoneButton(false);
getAppIntroInstance().setProgressButtonEnabled(false);
getAppIntroInstance().showSkipButton(false);
}

/**
* Next page.
*/
@Override
public void nextPage() {
unlockPage();
public void nextQuestion() {
unlockQuestion();
new Handler().post(new Runnable() {
@Override
public void run() {
Expand All @@ -202,10 +206,18 @@ public boolean isBlocked() {
* @return int
*/
@Override
public int getPageNumber() {
public int getQuestionNumber() {
return pageNumber;
}

public void setPageNumber(int pageNumber) {
this.pageNumber = pageNumber;
}

public void setListener(OnQuestionListener mPageListener) {
this.mPageListener = mPageListener;
}

/**
* Retrieve extra items saved in sharedPreferences.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,26 +24,26 @@

import android.view.View;

public interface IBasePage<T> {
public interface IBaseQuestion<T> {
View getView();

void nextPage();
void nextQuestion();

int getPageNumber();
int getQuestionNumber();

boolean isBlocked();

void clearAnswer();

void initView(View v);

void blockPage();
void blockQuestion();

void unlockPage();
void unlockQuestion();

int getLayout();

T getConfigsPage();
T getConfigsQuestion();

View getComponentAnswer();
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
package br.edu.uepb.nutes.simplesurvey.base;

/**
* Interface OnPageListener.
* Interface OnQuestionListener.
*/
public interface OnPageListener {
public interface OnQuestionListener {
void onClosePage();
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@
import android.view.View;

/**
* OnSwipePageTouchListener implementation.
* OnSwipeQuestionTouchListener implementation.
*/
public class OnSwipePageTouchListener implements View.OnTouchListener {
public class OnSwipeQuestionTouchListener implements View.OnTouchListener {
private final GestureDetector gestureDetector;

public OnSwipePageTouchListener(Context context) {
public OnSwipeQuestionTouchListener(Context context) {
gestureDetector = new GestureDetector(context, new GestureListener());
}

Expand Down
Loading

0 comments on commit db4c026

Please sign in to comment.