DT @24.11.2015: Modified Report Layout, corrected spellchecker and added more detail to position (has to be continued..)

This commit is contained in:
Dennis Thießen
2015-11-24 22:37:06 +01:00
parent d2bdacb3f8
commit 666fa60512
3 changed files with 89 additions and 59 deletions

View File

@@ -9,7 +9,6 @@ import android.location.Address;
import android.location.Geocoder;
import android.os.Bundle;
import android.util.Log;
import android.util.Patterns;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.DatePicker;
@@ -67,7 +66,6 @@ public class ReportActivity extends BaseActivity {
private int year, month, day;
private int hour, minute;
public HashMap<String, String[]> categories;
public ArrayList<String> incidentCategoryList;
@@ -76,6 +74,8 @@ public class ReportActivity extends BaseActivity {
super.onCreate(savedInstanceState);
userHasToBeLoggedIn();
Intent intent = getIntent();
String pos = intent.getStringExtra(EXTRA_MESSAGE);
getCategories();
final Calendar c = Calendar.getInstance();
@@ -93,8 +93,6 @@ public class ReportActivity extends BaseActivity {
txtPosition = (EditText) findViewById(R.id.input_report_position);
txtPositionDetail = (TextView) findViewById(R.id.lbl_report_position_detail);
restoreSharedPreferences();
if(txtDay.getText().toString().equals("")) {
txtDay.setText(new StringBuilder()
.append(year).append("-").append(month + 1).append("-")
@@ -113,8 +111,6 @@ public class ReportActivity extends BaseActivity {
}
});
Intent intent = getIntent();
String pos = intent.getStringExtra(EXTRA_MESSAGE);
if(pos != null) {
txtPosition.setText(pos);
@@ -122,9 +118,26 @@ public class ReportActivity extends BaseActivity {
Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
try {
List<Address> addresses = geocoder.getFromLocation(Double.parseDouble(position[0]), Double.parseDouble(position[1]), 1);
txtPosition.setText(addresses.get(0).getLocality());
txtPositionDetail.setText(addresses.get(0).getAddressLine(0));
List<Address> addressList = geocoder.getFromLocation(Double.parseDouble(position[0]), Double.parseDouble(position[1]), 1);
if (addressList != null && addressList.size() > 0) {
Address address = addressList.get(0);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < address.getMaxAddressLineIndex(); i++) {
if(txtPosition.getText().equals("") && address.getAddressLine(i) != null) txtPosition.setText(address.getAddressLine(i));
if(address.getAddressLine(i) != null) sb.append(address.getAddressLine(i)).append("\n");
}
//if(address.getLocality() != null) sb.append(address.getLocality()).append("\n");
//if(address.getPostalCode() != null) sb.append(address.getPostalCode()).append("\n");
if(address.getCountryName() != null) sb.append(address.getCountryName());
txtPositionDetail.setText(sb.toString());
}
latitude = position[0];
longitude = position[1];
} catch (IOException e) {
@@ -147,6 +160,7 @@ public class ReportActivity extends BaseActivity {
showDialog(DATE_DIALOG_ID);
}
});
txtPosition.setEnabled(false);
txtTime.setOnClickListener(new View.OnClickListener() {
@Override
@@ -155,11 +169,13 @@ public class ReportActivity extends BaseActivity {
}
});
restoreSharedPreferences();
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" +
textView.setError("Title must be at least\n" +
"5 characters in length.");
}
}
@@ -169,37 +185,13 @@ public class ReportActivity extends BaseActivity {
@Override
public void validate(TextView textView, String text) {
if (text.length() < 5) {
textView.setError("Your password must be at least\n" +
textView.setError("Description must be at least\n" +
"5 characters in length.");
}
}
});
}
private void restoreSharedPreferences() {
SharedPreferences prefs = getPreferences(MODE_PRIVATE);
String title = prefs.getString(SAVED_TITLE, null);
if (title != null) txtTitle.setText(title);
String descr = prefs.getString(SAVED_DESCRIPTION_LONG, null);
if (descr != null) txtDescription.setText(descr);
int crimec = prefs.getInt(SAVED_CRIME_CATEGORY, 0);
txtCrimeCategory.setSelection(crimec);
String day = prefs.getString(SAVED_DATE_INCIDENT, null);
if (day != null) txtDay.setText(day);
String time = prefs.getString(SAVED_DATE_TIME, null);
if (time != null) txtTime.setText(time);
String posi = prefs.getString(SAVED_POSITION, null);
if (posi != null) txtPosition.setText(posi);
latitude = prefs.getString("latitude",null);
longitude = prefs.getString("longitude",null);
}
private StringRequest getStringRequestAddIncidentWithPosition(final String textshort, final String textlong, final int crimecategory, final String latitude, final String longitude, final int status, final int radius, final String day, final String time) {
return new StringRequest(Request.Method.POST, AppConfig.URL_REGISTER, new Response.Listener<String>() {
@@ -214,8 +206,19 @@ public class ReportActivity extends BaseActivity {
if (!error) {
showMessage("Report added!");
SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
editor.clear();
editor.apply();
editor.clear().commit();
txtTitle.setText("");
txtDescription.setText("");
txtCrimeCategory.setSelection(0);
txtDay.setText("");
txtTime.setText("");
txtPosition.setText("");
findViewById(R.id.btn_report_position).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
gotoMapActivity();
}
});
gotoMapActivity(latitude+":"+longitude);
} else {
String errorMsg = jObj.getString("error_msg");
@@ -253,7 +256,6 @@ public class ReportActivity extends BaseActivity {
params.put("radius",Integer.toString(radius));
params.put("happened_at",year+"-"+month+"-"+day+" "+hour+":"+minute+":00");
return params;
}
@@ -264,11 +266,9 @@ public class ReportActivity extends BaseActivity {
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
// set date picker as current date
return new DatePickerDialog(this, datePickerListener,
year, month,day);
case TIME_DIALOG_ID:
// set date picker as current date
return new TimePickerDialog(this, timePickerListener,
hour,minute,true);
}
@@ -305,15 +305,7 @@ public class ReportActivity extends BaseActivity {
}
};
@Override
protected int getLayoutResourceId() {
return R.layout.activity_report;
}
@Override
protected String getActivityName() {
return mActivityTitle;
}
@Override
protected void onStop() {
@@ -331,6 +323,32 @@ public class ReportActivity extends BaseActivity {
editor.apply();
}
private void restoreSharedPreferences() {
SharedPreferences prefs = getPreferences(MODE_PRIVATE);
txtTitle.setText(prefs.getString(SAVED_TITLE, ""));
txtDescription.setText(prefs.getString(SAVED_DESCRIPTION_LONG, ""));
txtCrimeCategory.setSelection(prefs.getInt(SAVED_CRIME_CATEGORY, 0));
txtDay.setText(prefs.getString(SAVED_DATE_INCIDENT, new StringBuilder()
.append(year).append("-").append(month + 1).append("-")
.append(day).append(" ").toString()));
txtTime.setText(prefs.getString(SAVED_DATE_TIME, new StringBuilder().append(hour)
.append(":").append(minute).append(" ").toString()));
txtPosition.setText(prefs.getString(SAVED_POSITION, "0:0"));
latitude = prefs.getString("latitude","0");
longitude = prefs.getString("longitude","0");
findViewById(R.id.btn_report_position).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
gotoMapActivity(latitude + ":" + longitude);
}
});
}
public void getCategories(){
String tag_string_req = "getincidentcategories";
StringRequest strReq = getStringRequestGetIncidentCategories();
@@ -397,4 +415,14 @@ public class ReportActivity extends BaseActivity {
}
};
}
@Override
protected int getLayoutResourceId() {
return R.layout.activity_report;
}
@Override
protected String getActivityName() {
return mActivityTitle;
}
}

View File

@@ -12,6 +12,7 @@ public abstract class TextValidator implements TextWatcher {
public TextValidator(TextView textView) {
this.textView = textView;
if(this.textView.getText().equals("")) this.textView.setError("Please enter a value");
}
public abstract void validate(TextView textView, String text);

View File

@@ -141,35 +141,36 @@
<EditText
android:id="@+id/input_report_position"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="City"
android:ems="10"
android:editable="false"
android:layout_below="@+id/lbl_report_position"
android:layout_alignLeft="@+id/lbl_report_position"
android:layout_alignStart="@+id/lbl_report_position"
android:editable="false"/>
android:layout_toRightOf="@+id/lbl_report_category"
android:layout_toEndOf="@+id/lbl_report_category"/>
<com.beardedhen.androidbootstrap.BootstrapButton
android:id="@+id/btn_report_position"
android:layout_marginTop="3dp"
bootstrap:bootstrapText="@string/btn_report_position"
android:layout_below="@+id/lbl_report_position"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
bootstrap:bootstrapBrand="primary"
bootstrap:roundedCorners="true"
android:layout_marginTop="7dp"
android:layout_alignTop="@+id/lbl_report_position"
android:layout_alignRight="@+id/input_report_time"
android:layout_alignEnd="@+id/input_report_time" />
bootstrap:bootstrapSize="lg"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:id="@+id/lbl_report_position_detail"
android:layout_alignParentRight="true"
android:layout_below="@+id/input_report_position"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
android:layout_alignLeft="@+id/input_report_position"
android:layout_alignStart="@+id/input_report_position" />
</RelativeLayout>
<LinearLayout