DT @24.11.2015: Modified Report Layout, corrected spellchecker and added more detail to position (has to be continued..)
This commit is contained in:
@@ -9,7 +9,6 @@ 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;
|
||||||
@@ -67,7 +66,6 @@ public class ReportActivity extends BaseActivity {
|
|||||||
private int year, month, day;
|
private int year, month, day;
|
||||||
private int hour, minute;
|
private int hour, minute;
|
||||||
|
|
||||||
|
|
||||||
public HashMap<String, String[]> categories;
|
public HashMap<String, String[]> categories;
|
||||||
public ArrayList<String> incidentCategoryList;
|
public ArrayList<String> incidentCategoryList;
|
||||||
|
|
||||||
@@ -76,6 +74,8 @@ public class ReportActivity extends BaseActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
userHasToBeLoggedIn();
|
userHasToBeLoggedIn();
|
||||||
|
|
||||||
|
Intent intent = getIntent();
|
||||||
|
String pos = intent.getStringExtra(EXTRA_MESSAGE);
|
||||||
getCategories();
|
getCategories();
|
||||||
|
|
||||||
final Calendar c = Calendar.getInstance();
|
final Calendar c = Calendar.getInstance();
|
||||||
@@ -93,8 +93,6 @@ public class ReportActivity extends BaseActivity {
|
|||||||
txtPosition = (EditText) findViewById(R.id.input_report_position);
|
txtPosition = (EditText) findViewById(R.id.input_report_position);
|
||||||
txtPositionDetail = (TextView) findViewById(R.id.lbl_report_position_detail);
|
txtPositionDetail = (TextView) findViewById(R.id.lbl_report_position_detail);
|
||||||
|
|
||||||
restoreSharedPreferences();
|
|
||||||
|
|
||||||
if(txtDay.getText().toString().equals("")) {
|
if(txtDay.getText().toString().equals("")) {
|
||||||
txtDay.setText(new StringBuilder()
|
txtDay.setText(new StringBuilder()
|
||||||
.append(year).append("-").append(month + 1).append("-")
|
.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) {
|
if(pos != null) {
|
||||||
txtPosition.setText(pos);
|
txtPosition.setText(pos);
|
||||||
@@ -122,9 +118,26 @@ public class ReportActivity extends BaseActivity {
|
|||||||
|
|
||||||
Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
|
Geocoder geocoder = new Geocoder(getApplicationContext(), Locale.getDefault());
|
||||||
try {
|
try {
|
||||||
List<Address> addresses = geocoder.getFromLocation(Double.parseDouble(position[0]), Double.parseDouble(position[1]), 1);
|
List<Address> addressList = geocoder.getFromLocation(Double.parseDouble(position[0]), Double.parseDouble(position[1]), 1);
|
||||||
txtPosition.setText(addresses.get(0).getLocality());
|
|
||||||
txtPositionDetail.setText(addresses.get(0).getAddressLine(0));
|
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];
|
latitude = position[0];
|
||||||
longitude = position[1];
|
longitude = position[1];
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
@@ -147,6 +160,7 @@ public class ReportActivity extends BaseActivity {
|
|||||||
showDialog(DATE_DIALOG_ID);
|
showDialog(DATE_DIALOG_ID);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
txtPosition.setEnabled(false);
|
txtPosition.setEnabled(false);
|
||||||
txtTime.setOnClickListener(new View.OnClickListener() {
|
txtTime.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -155,11 +169,13 @@ public class ReportActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
restoreSharedPreferences();
|
||||||
|
|
||||||
txtTitle.addTextChangedListener(new TextValidator(txtTitle) {
|
txtTitle.addTextChangedListener(new TextValidator(txtTitle) {
|
||||||
@Override
|
@Override
|
||||||
public void validate(TextView textView, String text) {
|
public void validate(TextView textView, String text) {
|
||||||
if (text.length() < 5) {
|
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.");
|
"5 characters in length.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,37 +185,13 @@ public class ReportActivity extends BaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void validate(TextView textView, String text) {
|
public void validate(TextView textView, String text) {
|
||||||
if (text.length() < 5) {
|
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.");
|
"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) {
|
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>() {
|
return new StringRequest(Request.Method.POST, AppConfig.URL_REGISTER, new Response.Listener<String>() {
|
||||||
|
|
||||||
@@ -214,8 +206,19 @@ public class ReportActivity extends BaseActivity {
|
|||||||
if (!error) {
|
if (!error) {
|
||||||
showMessage("Report added!");
|
showMessage("Report added!");
|
||||||
SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
|
SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
|
||||||
editor.clear();
|
editor.clear().commit();
|
||||||
editor.apply();
|
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);
|
gotoMapActivity(latitude+":"+longitude);
|
||||||
} else {
|
} else {
|
||||||
String errorMsg = jObj.getString("error_msg");
|
String errorMsg = jObj.getString("error_msg");
|
||||||
@@ -253,7 +256,6 @@ public class ReportActivity extends BaseActivity {
|
|||||||
params.put("radius",Integer.toString(radius));
|
params.put("radius",Integer.toString(radius));
|
||||||
params.put("happened_at",year+"-"+month+"-"+day+" "+hour+":"+minute+":00");
|
params.put("happened_at",year+"-"+month+"-"+day+" "+hour+":"+minute+":00");
|
||||||
|
|
||||||
|
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,11 +266,9 @@ public class ReportActivity extends BaseActivity {
|
|||||||
protected Dialog onCreateDialog(int id) {
|
protected Dialog onCreateDialog(int id) {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case DATE_DIALOG_ID:
|
case DATE_DIALOG_ID:
|
||||||
// set date picker as current date
|
|
||||||
return new DatePickerDialog(this, datePickerListener,
|
return new DatePickerDialog(this, datePickerListener,
|
||||||
year, month,day);
|
year, month,day);
|
||||||
case TIME_DIALOG_ID:
|
case TIME_DIALOG_ID:
|
||||||
// set date picker as current date
|
|
||||||
return new TimePickerDialog(this, timePickerListener,
|
return new TimePickerDialog(this, timePickerListener,
|
||||||
hour,minute,true);
|
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
|
@Override
|
||||||
protected void onStop() {
|
protected void onStop() {
|
||||||
@@ -331,6 +323,32 @@ public class ReportActivity extends BaseActivity {
|
|||||||
editor.apply();
|
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(){
|
public void getCategories(){
|
||||||
String tag_string_req = "getincidentcategories";
|
String tag_string_req = "getincidentcategories";
|
||||||
StringRequest strReq = getStringRequestGetIncidentCategories();
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ public abstract class TextValidator implements TextWatcher {
|
|||||||
|
|
||||||
public TextValidator(TextView textView) {
|
public TextValidator(TextView textView) {
|
||||||
this.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);
|
public abstract void validate(TextView textView, String text);
|
||||||
|
|||||||
@@ -141,35 +141,36 @@
|
|||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
android:id="@+id/input_report_position"
|
android:id="@+id/input_report_position"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:text="City"
|
android:text="City"
|
||||||
android:ems="10"
|
android:editable="false"
|
||||||
android:layout_below="@+id/lbl_report_position"
|
android:layout_below="@+id/lbl_report_position"
|
||||||
android:layout_alignLeft="@+id/lbl_report_position"
|
android:layout_toRightOf="@+id/lbl_report_category"
|
||||||
android:layout_alignStart="@+id/lbl_report_position"
|
android:layout_toEndOf="@+id/lbl_report_category"/>
|
||||||
android:editable="false"/>
|
|
||||||
|
|
||||||
<com.beardedhen.androidbootstrap.BootstrapButton
|
<com.beardedhen.androidbootstrap.BootstrapButton
|
||||||
android:id="@+id/btn_report_position"
|
android:id="@+id/btn_report_position"
|
||||||
|
android:layout_marginTop="3dp"
|
||||||
bootstrap:bootstrapText="@string/btn_report_position"
|
bootstrap:bootstrapText="@string/btn_report_position"
|
||||||
|
android:layout_below="@+id/lbl_report_position"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
bootstrap:bootstrapBrand="primary"
|
bootstrap:bootstrapBrand="primary"
|
||||||
bootstrap:roundedCorners="true"
|
bootstrap:roundedCorners="true"
|
||||||
android:layout_marginTop="7dp"
|
bootstrap:bootstrapSize="lg"
|
||||||
android:layout_alignTop="@+id/lbl_report_position"
|
android:layout_alignParentLeft="true"
|
||||||
android:layout_alignRight="@+id/input_report_time"
|
android:layout_alignParentStart="true" />
|
||||||
android:layout_alignEnd="@+id/input_report_time" />
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
android:id="@+id/lbl_report_position_detail"
|
android:id="@+id/lbl_report_position_detail"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
android:layout_below="@+id/input_report_position"
|
android:layout_below="@+id/input_report_position"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignLeft="@+id/input_report_position"
|
||||||
android:layout_alignParentStart="true" />
|
android:layout_alignStart="@+id/input_report_position" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|||||||
Reference in New Issue
Block a user