Skip to content

Commit

Permalink
Version 1.0 finalized.
Browse files Browse the repository at this point in the history
- Support for the following question types: Dichotomic choice (e.g. example YES/NO), Single choice, Multiple choose;
- Presentation page;
- Question blocked until response is obtained;
- Bug fixes and improvements.
  • Loading branch information
douglasrafael committed Mar 12, 2019
1 parent db4c026 commit c3e1336
Show file tree
Hide file tree
Showing 20 changed files with 539 additions and 128 deletions.
Binary file removed ..gitignore.swp
Binary file not shown.
41 changes: 39 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,39 @@
# SimpleSurvey
Library for simple survey creation
# Simple Survey
[![license](https://img.shields.io/github/license/mashape/apistatus.svg)](https://opensource.org/licenses/MIT)

Library for simple survey creation.
This library has as main dependency the library [AppIntro](https://github.com/AppIntro/AppIntro) _(An excellent library for you to create introductions to your application)_.

**Simple Survey**, only provides an easy way to create forms with pre-defined question types.

## Features
- Support for the following question types:
- Dichotomic choice (e.g. example YES/NO)
- Single choice
- Multiple choose
- Presentation page
- Question blocked until response is obtained.

## Installation
```
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
```

```
dependencies {
implementation 'com.github.nutes-uepb:simple-survey:v1.0.0'
}
```

## Using

#### [See example of use](https://github.com/nutes-uepb/simple-survey/blob/master/app/src/main/java/br/edu/uepb/nutes/simplesurvey/SimpleSurvey1.java)

`More examples coming soon...`


131 changes: 105 additions & 26 deletions app/src/main/java/br/edu/uepb/nutes/simplesurvey/SimpleSurvey1.java
Original file line number Diff line number Diff line change
@@ -1,76 +1,155 @@
package br.edu.uepb.nutes.simplesurvey;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Color;
import android.support.v4.content.ContextCompat;
import android.util.Log;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import br.edu.uepb.nutes.simplesurvey.base.SimpleSurvey;
import br.edu.uepb.nutes.simplesurvey.pages.DichotomicChoice;
import br.edu.uepb.nutes.simplesurvey.pages.Infor;
import br.edu.uepb.nutes.simplesurvey.pages.MultipleChoice;
import br.edu.uepb.nutes.simplesurvey.pages.SingleChoice;

public class SimpleSurvey1 extends SimpleSurvey implements DichotomicChoice.OnRadioListener,
Infor.OnButtonListener {
public class SimpleSurvey1 extends SimpleSurvey implements Infor.OnInfoListener,
DichotomicChoice.OnDichotomicListener, SingleChoice.OnSingleListener,
MultipleChoice.OnMultipleListener {
private final String LOG_TAG = SimpleSurvey1.class.getSimpleName();

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

private void addPages() {
setMessageBlocked("Ops! responda para poder ir para próxima perguta...");
setMessageBlocked("Oops! answer so i can go to the next question...");
/**
* Available animations:
* - setFadeAnimation()
* - setZoomAnimation()
* - setFlowAnimation()
* - setSlideOverAnimation()
* - setDepthAnimation()
* More details: {https://github.com/AppIntro/AppIntro#animations}
*/
setFadeAnimation();

addQuestion(new Infor.Config()
.layout(R.layout.welcome)
.nextQuestionAuto()
.pageNumber(0)
.build());

// page 1
addQuestion(new DichotomicChoice.Config()
.title("Title of the question")
.description("Lorem Ipsum is simply dummy text of the printing and typesetting industry?")
.title("Title of the question 1", Color.WHITE)
.description("Lorem Ipsum is simply dummy text of the printing and typesetting industry?",
Color.WHITE)
.colorBackground(ContextCompat.getColor(this, R.color.colorGreen))
.radioStyle(R.drawable.radio_sample1_lef, R.drawable.radio_sample1_right, Color.WHITE, Color.WHITE)
.radioLeftText(R.string.masc)
.radioRightText(R.string.femi)
.nextQuestionAuto()
.image(R.drawable.placeholder)
.buttonClose(R.drawable.ic_action_close_dark)
.enableZoomImage()
.pageNumber(1)
.build());

addQuestion(new DichotomicChoice.Config()
.title("Simple Survey 1")
.description("Simple survey from @NUTES")
addQuestion(new SingleChoice.Config()
.title("Title of the question 2", Color.WHITE)
.description("Lorem Ipsum is simply dummy text of the printing and typesetting industry?",
Color.WHITE)
.colorBackground(ContextCompat.getColor(this, R.color.colorCyan))
.colorBackgroundTint(Color.WHITE)
.colorSelectedText(Color.WHITE)
.items(new ArrayList<String>() {{
add("Item 1");
add("Item 2");
add("Item 3");
add("Item 4");
}})
.image(R.drawable.placeholder)
.buttonClose(R.drawable.ic_action_close_dark)
.disableAddNewItem()
.nextQuestionAuto()
.pageNumber(2)
.build());

addQuestion(new DichotomicChoice.Config()
.title("Simple Survey 2")
.description("Simple survey from @NUTES")
.pageNumber(3)
.title("Title of the question 3")
.description("Lorem Ipsum is simply dummy text of the printing and typesetting industry?")
.nextQuestionAuto()
.pageNumber(3)
.build());

addQuestion(new DichotomicChoice.Config()
.title("Simple Survey 3")
.description("Simple survey from @NUTES")
.colorBackground(ContextCompat.getColor(this, R.color.colorBlueGrey))
addQuestion(new MultipleChoice.Config()
.title("Simple Survey 3", Color.WHITE)
.description("Simple survey from @NUTES", Color.WHITE)
.colorBackground(ContextCompat.getColor(this, R.color.colorDeepPurple))
.items(new ArrayList<String>() {{
add("Item 1");
add("Item 2");
add("Item 3");
add("Item 4");
}})
.buttonClose(R.drawable.ic_action_close_dark)
.nextQuestionAuto()
.colorBackgroundTint(Color.WHITE)
.colorSelectedText(Color.WHITE)
.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)
.title("Thank you for the answers :)")
.pageNumber(-1)
.build());
}

@Override
public void onAnswerButton(int page) {

public void onClosePage() {
new AlertDialog
.Builder(this)
.setMessage("Do you want to cancel the survey??")
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.setNegativeButton("No", null)
.show();
}

@Override
public void onAnswerRadio(int page, boolean value) {
public void onAnswerInfo(int page) {
Log.w(LOG_TAG, "onAnswerInfo() | PAGE: " + page);
if (page == 0) { // first page
nextQuestion();
} else if (page == -1) { // end page
finish();
}
}

@Override
public void onAnswerDichotomic(int page, boolean value) {
Log.w(LOG_TAG, "onAnswerDichotomic() | PAGE: " + page + " | ANSWER: " + value);
}

@Override
public void onClosePage() {
public void onAnswerSingle(int page, String value, int indexValue) {
Log.w(LOG_TAG, "onAnswerMultiple() | PAGE: " + page
+ " | ANSWER (value): " + value
+ " | ANSWER (index): " + indexValue);
}

@Override
public void onAnswerMultiple(int page, List<String> values, List<Integer> indexValues) {
Log.w(LOG_TAG, "onAnswerMultiple() | PAGE: " + page
+ " | ANSWER (values): " + Arrays.toString(values.toArray())
+ " | ANSWER (indexes): " + Arrays.toString(indexValues.toArray()));
}
}
10 changes: 10 additions & 0 deletions app/src/main/res/drawable-anydpi/ic_action_close_dark.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24"
android:tint="#FFFFFF">
<path
android:fillColor="#FF000000"
android:pathData="M19,6.41L17.59,5 12,10.59 6.41,5 5,6.41 10.59,12 5,17.59 6.41,19 12,13.41 17.59,19 19,17.59 13.41,12z"/>
</vector>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions app/src/main/res/drawable/radio_sample1_lef.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<shape>
<corners android:bottomLeftRadius="25dp" android:topLeftRadius="60dp" />
<solid android:color="#286572" />
<padding android:bottom="15dp" android:left="40dp" android:right="40dp" android:top="15dp" />
</shape>
</item>

<item android:state_pressed="true">
<shape>
<corners android:bottomLeftRadius="25dp" android:topLeftRadius="60dp" />
<stroke android:width="2dp" android:color="#286572" />
<padding android:bottom="15dp" android:left="40dp" android:right="40dp" android:top="15dp" />
</shape>
</item>

<item>
<shape>
<corners android:bottomLeftRadius="25dp" android:topLeftRadius="60dp" />
<stroke android:width="2dp" android:color="#286572" />
<padding android:bottom="15dp" android:left="40dp" android:right="40dp" android:top="15dp" />
</shape>
</item>
</selector>
26 changes: 26 additions & 0 deletions app/src/main/res/drawable/radio_sample1_right.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<shape>
<corners android:bottomRightRadius="60dp" android:topRightRadius="25dp" />
<solid android:color="#286572" />
<padding android:bottom="15dp" android:left="40dp" android:right="40dp" android:top="15dp" />
</shape>
</item>

<item android:state_pressed="true">
<shape>
<corners android:bottomRightRadius="60dp" android:topRightRadius="25dp" />
<stroke android:width="2dp" android:color="#286572" />
<padding android:bottom="15dp" android:left="40dp" android:right="40dp" android:top="15dp" />
</shape>
</item>

<item>
<shape>
<corners android:bottomRightRadius="60dp" android:topRightRadius="25dp" />
<stroke android:width="2dp" android:color="#286572" />
<padding android:bottom="15dp" android:left="40dp" android:right="40dp" android:top="15dp" />
</shape>
</item>
</selector>
7 changes: 3 additions & 4 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand All @@ -11,13 +10,13 @@
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="vertical"
android:padding="16dp">
android:padding="60dp">

<Button
android:id="@+id/button"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Open Survey" />
android:layout_height="60dp"
android:text="Open Survey Sample 1" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
58 changes: 58 additions & 0 deletions app/src/main/res/layout/welcome.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:layout_marginTop="80dp">

<TextView
android:id="@+id/question_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Welcome to Simple Survey"
android:textSize="50sp" />

<TextView
android:id="@+id/question_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:gravity="center"
android:text="Sample 1"
android:textSize="25sp" />

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="40dp"
android:gravity="center"
android:text=":-)"
android:textSize="50sp" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center|bottom"
android:orientation="vertical"
android:padding="100dp">

<Button
android:id="@+id/answer_button"
style="@style/Widget.AppCompat.Button.Colored"
android:layout_width="match_parent"
android:layout_height="60dp"
android:text="Lets go >>"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>

</android.support.constraint.ConstraintLayout>
4 changes: 2 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<resources>
<string name="app_name">Simple Survey</string>
<string name="masc">Masculino</string>
<string name="femi">Feminino</string>
<string name="masc">Male</string>
<string name="femi">Female</string>
</resources>
Loading

0 comments on commit c3e1336

Please sign in to comment.