Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1 Fix global structure #1

Merged
merged 1 commit into from
Apr 21, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,91 +21,126 @@
import android.text.InputType;
import android.util.Log;
import android.widget.Toast;

import com.heinrichreimersoftware.singleinputform.SingleInputFormActivity;
import com.heinrichreimersoftware.singleinputform.steps.CheckBoxStep;
import com.heinrichreimersoftware.singleinputform.steps.DateStep;
import com.heinrichreimersoftware.singleinputform.steps.OptionStep;
import com.heinrichreimersoftware.singleinputform.steps.SeekBarStep;
import com.heinrichreimersoftware.singleinputform.steps.Step;
import com.heinrichreimersoftware.singleinputform.steps.TextStep;

import java.util.ArrayList;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.List;

public class MainActivity extends SingleInputFormActivity{
public class MainActivity extends SingleInputFormActivity {

private static final String DATA_KEY_HEIGHT = "height";
private static final String DATA_KEY_EULA = "eula";
private static final String DATA_KEY_EMAIL = "email";
private static final String DATA_KEY_PASSWORD = "password";
private static final String DATA_KEY_BIRTHDAY = "birthday";
private static final String DATA_KEY_OPTIONS = "options";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}

@Override
protected List<Step> getSteps(Context context) {
long startTime = System.currentTimeMillis();
List<Step> steps = new ArrayList<Step>();
steps.add(new CheckBoxStep.CheckBoxStepBuilder().setContext(context)
.setDataKey(DATA_KEY_EULA)
.setTextResId(R.string.eula)
.setTitleResId(R.string.eula_title)
.setErrorResId(R.string.eula_error)
.setDetailsResId(R.string.eula_details)
.setChecker(new CheckBoxStep.StepChecker() {
@Override
public boolean check(boolean input) {
return input;
}
})
.createStep());
steps.add(new TextStep.TextInnerStepBuilder().setContext(context)
.setDataKey(DATA_KEY_EMAIL)
.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS)
.setTitleResId(R.string.email)
.setErrorResId(R.string.email_error)
.setDetailsResId(R.string.email_details)
.setChecker(new TextStep.StepChecker() {
@Override
public boolean check(String input) {
return android.util.Patterns.EMAIL_ADDRESS.matcher(input).matches();
}
})
.createStep());
steps.add(new TextStep.TextInnerStepBuilder().setContext(context)
.setDataKey(DATA_KEY_PASSWORD)
.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD)
.setTitleResId(R.string.password)
.setErrorResId(R.string.password_error)
.setDetailsResId(R.string.password_details)
.setChecker(new TextStep.StepChecker() {
@Override
public boolean check(String input) {
return input.length() >= 5;
}
})
.createStep());
steps.add(new DateStep.DateStepBuilder().setContext(context)
.setDataKey(DATA_KEY_BIRTHDAY)
.setTitleResId(R.string.birthday)
.setErrorResId(R.string.birthday_error)
.setDetailsResId(R.string.birthday_details)
.setDateChecker(new DateStep.DateStepChecker() {
@Override
public boolean check(int year, int month, int day) {
Calendar today = new GregorianCalendar();
Calendar birthday = new GregorianCalendar(year, month, day);
today.add(Calendar.YEAR, -14);
return today.after(birthday);
}
})
.createStep());
steps.add(new SeekBarStep.SeekBarStepBuilder().setContext(context)
.setDataKey(DATA_KEY_HEIGHT)
.setMax(180)
.setMin(150)
.setTitleResId(R.string.height)
.setErrorResId(R.string.height_error)
.setDetailsResId(R.string.height_details)
.setChecker(new SeekBarStep.StepChecker() {
@Override
public boolean check(int progress) {
return progress >= 160;
}
})
.createStep());

private static final String DATA_KEY_HEIGHT = "height";
private static final String DATA_KEY_EULA = "eula";
private static final String DATA_KEY_EMAIL = "email";
private static final String DATA_KEY_PASSWORD = "password";
private static final String DATA_KEY_BIRTHDAY = "birthday";
private static final String DATA_KEY_CITY = "city";
steps.add(new OptionStep.OptionStepBuilder(this).setDataKey(DATA_KEY_OPTIONS)
.setTitleResId(R.string.eula_title)
.setDetailsResId(R.string.eula_details)
.setErrorResId(R.string.eula_error)
.setOptions(new String[] { "Option 1", "Option 2", "Option 3" })
.createStep());

@Override
protected List<Step> getSteps(Context context){
List<Step> steps = new ArrayList<Step>();
steps.add(
new CheckBoxStep(context, DATA_KEY_EULA, R.string.eula, R.string.eula_title, R.string.eula_error, R.string.eula_details, new CheckBoxStep.StepChecker() {
@Override
public boolean check(boolean input) {
return input;
}
})
);
steps.add(
new TextStep(context, DATA_KEY_EMAIL, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS, R.string.email, R.string.email_error, R.string.email_details, new TextStep.StepChecker() {
@Override
public boolean check(String input) {
return android.util.Patterns.EMAIL_ADDRESS.matcher(input).matches();
}
})
);
steps.add(
new TextStep(context, DATA_KEY_PASSWORD, InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD, R.string.password, R.string.password_error, R.string.password_details, new TextStep.StepChecker() {
@Override
public boolean check(String input) {
return input.length() >= 5;
}
})
);
steps.add(
new DateStep(context, DATA_KEY_BIRTHDAY, R.string.birthday, R.string.birthday_error, R.string.birthday_details, new DateStep.StepChecker(){
@Override
public boolean check(int year, int month, int day){
Calendar today = new GregorianCalendar();
Calendar birthday = new GregorianCalendar(year, month, day);
today.add(Calendar.YEAR, -14);
return today.after(birthday);
}
})
);
steps.add(
new SeekBarStep(context, DATA_KEY_HEIGHT, 150, 180, R.string.height, R.string.height_error, R.string.height_details, new SeekBarStep.StepChecker() {
@Override
public boolean check(int progress) {
return progress >= 160;
}
})
);
steps.add(
new TextStep(context, DATA_KEY_CITY, InputType.TYPE_CLASS_TEXT, R.string.city, R.string.city_error, R.string.city_details)
);

return steps;
}
Log.d("MPB","TEST: "+(System.currentTimeMillis()-startTime));
return steps;
}

@Override
protected void onFormFinished(Bundle data){
Toast.makeText(this, "Form finished: " +
CheckBoxStep.checked(data, DATA_KEY_EULA) + ", " +
TextStep.text(data, DATA_KEY_EMAIL) + ", " +
TextStep.text(data, DATA_KEY_PASSWORD) + ", " +
DateStep.day(data, DATA_KEY_BIRTHDAY) + "." + DateStep.month(data, DATA_KEY_BIRTHDAY) + "." + DateStep.year(data, DATA_KEY_BIRTHDAY) + ", " +
SeekBarStep.progress(data, DATA_KEY_HEIGHT) + ", " +
TextStep.text(data, DATA_KEY_CITY),
Toast.LENGTH_LONG).show();
Log.d("MainActivity", "data: " + data.toString());
}
@Override
protected void onFormFinished(Bundle data) {
Toast.makeText(this, "Form finished: " +
CheckBoxStep.checked(data, DATA_KEY_EULA) + ", " +
TextStep.text(data, DATA_KEY_EMAIL) + ", " +
TextStep.text(data, DATA_KEY_PASSWORD) + ", " +
DateStep.day(data, DATA_KEY_BIRTHDAY) + "." + DateStep.month(data, DATA_KEY_BIRTHDAY) + "."
+ DateStep.year(data, DATA_KEY_BIRTHDAY) + ", " +
SeekBarStep.progress(data, DATA_KEY_HEIGHT), Toast.LENGTH_LONG).show();
Log.d("MainActivity", "data: " + data.toString());
}
}