DT @22.11.2015: Implemented some text checks

This commit is contained in:
Dennis Thießen
2015-11-22 13:35:57 +01:00
parent ae9d0350db
commit f2cb138975
8 changed files with 68 additions and 37 deletions

View File

@@ -66,12 +66,10 @@
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/androidTest/jni" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" /> <sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/assets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/bundles" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/coverage-instrumented-classes" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/debug" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dependency-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/dex-cache" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.0/jars" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/appcompat-v7/22.2.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/mediarouter-v7/22.0.0/jars" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/mediarouter-v7/22.0.0/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.2.0/jars" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.android.support/support-v4/22.2.0/jars" />
@@ -102,17 +100,12 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.twitter.sdk.android/twitter-core/1.4.1/jars" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/com.twitter.sdk.android/twitter-core/1.4.1/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/io.fabric.sdk.android/fabric/1.3.4/jars" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/exploded-aar/io.fabric.sdk.android/fabric/1.3.4/jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jacoco" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaResources" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/lint" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/ndk" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" /> <excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/tmp" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" /> <excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" /> <excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content> </content>

View File

@@ -9,6 +9,7 @@ import android.location.Address;
import android.location.Geocoder; import android.location.Geocoder;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.util.Patterns;
import android.view.View; import android.view.View;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.DatePicker; import android.widget.DatePicker;
@@ -26,6 +27,7 @@ import com.android.volley.toolbox.StringRequest;
import org.deke.risk.riskahead.helper.AppConfig; import org.deke.risk.riskahead.helper.AppConfig;
import org.deke.risk.riskahead.helper.AppController; import org.deke.risk.riskahead.helper.AppController;
import org.deke.risk.riskahead.helper.BaseActivity; import org.deke.risk.riskahead.helper.BaseActivity;
import org.deke.risk.riskahead.helper.TextValidator;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@@ -152,6 +154,26 @@ public class ReportActivity extends BaseActivity {
showDialog(TIME_DIALOG_ID); showDialog(TIME_DIALOG_ID);
} }
}); });
txtTitle.addTextChangedListener(new TextValidator(txtTitle) {
@Override
public void validate(TextView textView, String text) {
if (text.length() < 5) {
textView.setError("Your password must be at least\n" +
"5 characters in length.");
}
}
});
txtDescription.addTextChangedListener(new TextValidator(txtDescription) {
@Override
public void validate(TextView textView, String text) {
if (text.length() < 5) {
textView.setError("Your password must be at least\n" +
"5 characters in length.");
}
}
});
} }
private void restoreSharedPreferences() { private void restoreSharedPreferences() {
@@ -194,7 +216,7 @@ public class ReportActivity extends BaseActivity {
SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit(); SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
editor.clear(); editor.clear();
editor.apply(); editor.apply();
gotoMapActivity(); gotoMapActivity(latitude+":"+longitude);
} else { } else {
String errorMsg = jObj.getString("error_msg"); String errorMsg = jObj.getString("error_msg");
Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_LONG).show(); Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_LONG).show();

View File

@@ -4,8 +4,8 @@ import android.app.AlertDialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.Bundle; import android.os.Bundle;
import android.util.Log; import android.util.Log;
import android.util.Patterns;
import android.view.View; import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
@@ -17,6 +17,7 @@ import com.android.volley.toolbox.StringRequest;
import org.deke.risk.riskahead.helper.AppConfig; import org.deke.risk.riskahead.helper.AppConfig;
import org.deke.risk.riskahead.helper.AppController; import org.deke.risk.riskahead.helper.AppController;
import org.deke.risk.riskahead.helper.BaseActivity; import org.deke.risk.riskahead.helper.BaseActivity;
import org.deke.risk.riskahead.helper.TextValidator;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@@ -45,7 +46,25 @@ public class SettingsActivity extends BaseActivity {
txtEmail = (TextView) findViewById(R.id.txt_settings_email); txtEmail = (TextView) findViewById(R.id.txt_settings_email);
txtPassword = (TextView) findViewById(R.id.txt_settings_password); txtPassword = (TextView) findViewById(R.id.txt_settings_password);
txtUsername.addTextChangedListener(new TextValidator(txtUsername) {
@Override
public void validate(TextView textView, String text) {
if (text.length() < 5) {
textView.setError("Your username must be at least\n" +
"5 characters in length.");
}
}
});
txtEmail.addTextChangedListener(new TextValidator(txtEmail) {
@Override
public void validate(TextView textView, String text) {
if (!Patterns.EMAIL_ADDRESS.matcher(text).matches()) {
textView.setError("Please enter a valid email address\n" +
"e.g.: text@abc.de");
}
}
});
findViewById(R.id.btn_settings_req_password).setOnClickListener(new View.OnClickListener() { findViewById(R.id.btn_settings_req_password).setOnClickListener(new View.OnClickListener() {
@Override @Override
@@ -80,23 +99,29 @@ public class SettingsActivity extends BaseActivity {
return; return;
} }
new AlertDialog.Builder(SettingsActivity.this) if (txtUsername.getError() != null || txtEmail.getError() != null) {
.setTitle("Confirm changes") showMessage("Entered fields not valid\n" +
.setMessage("Do you really want to confirm changes? ") "Please check errors first.");
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { } else {
public void onClick(DialogInterface dialog, int which) {
String tag_string_req = "updateuser"; new AlertDialog.Builder(SettingsActivity.this)
StringRequest strReq = getStringChangeUserSettings(); .setTitle("Confirm changes")
AppController.getInstance().addToRequestQueue(strReq, tag_string_req); .setMessage("Do you really want to confirm changes? ")
} .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
}) public void onClick(DialogInterface dialog, int which) {
.setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() { String tag_string_req = "updateuser";
public void onClick(DialogInterface dialog, int which) { StringRequest strReq = getStringChangeUserSettings();
// do nothing AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
} }
}) })
.setIcon(android.R.drawable.ic_dialog_alert) .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
.show(); public void onClick(DialogInterface dialog, int which) {
// do nothing
}
})
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
}
} }
}); });

View File

@@ -290,12 +290,10 @@ public class ViewReportActivity extends BaseActivity {
JSONObject jObj = new JSONObject(response); JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error"); boolean error = jObj.getBoolean("error");
// Check for error node in json
if (!error) { if (!error) {
BootstrapLabel scorelabel = (BootstrapLabel) findViewById(R.id.txt_viewreport_points); BootstrapLabel scorelabel = (BootstrapLabel) findViewById(R.id.txt_viewreport_points);
scorelabel.setText(jObj.getString("points")); scorelabel.setText(jObj.getString("points"));
} else { } else {
// Error in login. Get the error message
String errorMsg = jObj.getString("error_msg"); String errorMsg = jObj.getString("error_msg");
Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_LONG).show(); Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_LONG).show();
} }
@@ -316,17 +314,14 @@ public class ViewReportActivity extends BaseActivity {
@Override @Override
protected Map<String, String> getParams() { protected Map<String, String> getParams() {
// Posting parameters to login url
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
params.put("tag", "getincidentvotescore"); params.put("tag", "getincidentvotescore");
params.put("uid", user.get("uid")); params.put("uid", user.get("uid"));
params.put("token", user.get("token")); params.put("token", user.get("token"));
params.put("incidentid", incidentid); params.put("incidentid", incidentid);
return params; return params;
} }
}; };
} }
@@ -380,7 +375,6 @@ public class ViewReportActivity extends BaseActivity {
@Override @Override
protected Map<String, String> getParams() { protected Map<String, String> getParams() {
// Posting parameters to login url
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
params.put("tag", "addvote"); params.put("tag", "addvote");
params.put("uid", user.get("uid")); params.put("uid", user.get("uid"));
@@ -388,10 +382,8 @@ public class ViewReportActivity extends BaseActivity {
params.put("incidentid", incidentid); params.put("incidentid", incidentid);
params.put("votetype", votetype); params.put("votetype", votetype);
return params; return params;
} }
}; };
} }

View File

@@ -18,7 +18,6 @@ public abstract class TextValidator implements TextWatcher {
@Override @Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) { public void beforeTextChanged(CharSequence s, int start, int count, int after) {
} }
@Override @Override

Binary file not shown.

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 102 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 46 KiB