DT @21.12.2015: Last changes commited

This commit is contained in:
Dennis Thießen
2015-12-21 13:38:58 +01:00
parent 24ec175a43
commit acf1eaa8b0
5 changed files with 40 additions and 84 deletions

View File

@@ -41,6 +41,7 @@ public class MainActivity extends BaseActivity{
Handler mHandler = new Handler(); Handler mHandler = new Handler();
private final static int INTERVAL = 1000 * 20; //20 seconds private final static int INTERVAL = 1000 * 20; //20 seconds
private TextView count;
private Button report; private Button report;
private Button map; private Button map;
@@ -50,6 +51,8 @@ public class MainActivity extends BaseActivity{
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
userHasToBeLoggedIn(); userHasToBeLoggedIn();
count = (TextView) findViewById(R.id.txt_main_incidents);
Intent intent = getIntent(); Intent intent = getIntent();
msg_input = intent.getStringExtra(MainActivity.EXTRA_MESSAGE); msg_input = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
@@ -145,8 +148,9 @@ public class MainActivity extends BaseActivity{
boolean error = jObj.getBoolean("error"); boolean error = jObj.getBoolean("error");
if (!error) { if (!error) {
TextView count = (TextView) findViewById(R.id.txt_main_incidents); JSONObject jCount = jObj.getJSONObject("msg");
count.setText(jObj.getString("total"));
count.setText(jCount.getString("total"));
} else { } else {
String errorMsg = jObj.getString("error_msg"); String errorMsg = jObj.getString("error_msg");
Log.e(TAG, "Error getting incident count (server returned error): " + errorMsg); Log.e(TAG, "Error getting incident count (server returned error): " + errorMsg);

View File

@@ -147,10 +147,10 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
private void addMarkersToMap(){ private void addMarkersToMap(){
LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds; LatLngBounds bounds = mMap.getProjection().getVisibleRegion().latLngBounds;
mHeatMapPositionList.clear(); mHeatMapPositionList.clear();
//Loop through all the items that are available to be placed on the map Log.d("Zoom", "Bounds: NE:" + bounds.northeast +" SW: " + bounds.southwest);
for(IncidentReport item : myMarkers) for(IncidentReport item : myMarkers)
{ {
//If the item is within the the bounds of the screen
if(bounds.contains(item.getPosition())) if(bounds.contains(item.getPosition()))
{ {
mHeatMapPositionList.add(item.getPosition()); mHeatMapPositionList.add(item.getPosition());
@@ -259,10 +259,11 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
tvSuspect.setText(clickedClusterItem.getSuspectString(getApplicationContext())); tvSuspect.setText(clickedClusterItem.getSuspectString(getApplicationContext()));
tvUsername.setText(getString(R.string.lbl_mapsinfowindow_author) + ": " + clickedClusterItem.getFromUsername()); tvUsername.setText(getString(R.string.lbl_mapsinfowindow_author) + ": " + clickedClusterItem.getFromUsername());
tvScore.setText(getString(R.string.lbl_mapsinfowindow_score) + ": " + clickedClusterItem.getVotedScore()); //TODO
tvVictim.setText(clickedClusterItem.getFidVictimCategory()); //tvScore.setText(clickedClusterItem.getVotedScore());
tvTime.setText(clickedClusterItem.getTimeString(getApplicationContext())); //tvVictim.setText(clickedClusterItem.getFidVictimCategory());
rbScore.setRating(clickedClusterItem.getScoreStars()); //tvTime.setText(clickedClusterItem.getTimeString(getApplicationContext()));
//rbScore.setRating(clickedClusterItem.getScoreStars());
} }
return myContentsView; return myContentsView;
} }
@@ -417,7 +418,6 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
@Override @Override
public void onResponse(String response) { public void onResponse(String response) {
Log.d(TAG, "Map positions response: " + response); Log.d(TAG, "Map positions response: " + response);
hideDialog();
try { try {
JSONObject jObj = new JSONObject(response); JSONObject jObj = new JSONObject(response);
@@ -428,19 +428,18 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
for(int i=0;i<incidents.length();i++){ for(int i=0;i<incidents.length();i++){
JSONObject incident = incidents.getJSONObject(i); JSONObject incident = incidents.getJSONObject(i);
LatLng pos = new LatLng(Double.parseDouble(incident.getString("latitude")),Double.parseDouble(incident.getString("longitude"))); myMarkers.add(new IncidentReport(incident,new LatLng(incident.getDouble("latitude"),incident.getDouble("longitude"))));
myMarkers.add(new IncidentReport(incident,pos));
} }
addHeatMap(); addHeatMap();
} else { } else {
String errorMsg = jObj.getString("error_msg"); String errorMsg = jObj.getString("error_msg");
Log.e(TAG, "Error getting map positions (server returned error): " + errorMsg); Log.e(TAG, "Error getting map positions (server returned error): " + errorMsg);
showMessage(errorMsg); showMessage(errorMsg);
} }
hideDialog();
} catch (JSONException e) { } catch (JSONException e) {
e.printStackTrace(); e.printStackTrace();
hideDialog();
} }
} }
@@ -455,7 +454,7 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
@Override @Override
protected Map<String, String> getParams() { protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>(); Map<String, String> params = new HashMap<>();
params.put("tag", "getincidentswithpositionandscorev2"); params.put("tag", "getincidentswithpositionandscore");
params.put("uid", user.get(SessionManager.KEY_UID)); params.put("uid", user.get(SessionManager.KEY_UID));
params.put("token", user.get(SessionManager.TOKEN)); params.put("token", user.get(SessionManager.TOKEN));

View File

@@ -42,7 +42,7 @@ public class ViewReportActivity extends BaseActivity {
private EditText txtDate; private EditText txtDate;
private EditText txtTime; private EditText txtTime;
private TextView txtPositionDetail; private TextView txtPositionDetail;
private BootstrapLabel scorelabel;
@Override @Override
protected void onCreate(Bundle savedInstanceState) { protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@@ -58,9 +58,9 @@ public class ViewReportActivity extends BaseActivity {
txtTime = (EditText) findViewById(R.id.input_viewreport_time); txtTime = (EditText) findViewById(R.id.input_viewreport_time);
txtPosition = (EditText) findViewById(R.id.input_viewreport_position); txtPosition = (EditText) findViewById(R.id.input_viewreport_position);
txtPositionDetail = (TextView) findViewById(R.id.lbl_viewreport_position_detail); txtPositionDetail = (TextView) findViewById(R.id.lbl_viewreport_position_detail);
scorelabel = (BootstrapLabel) findViewById(R.id.txt_viewreport_points);
getIncident(uid); getIncident(uid);
getIncidentVoteScore(uid);
findViewById(R.id.btn_viewreport_upvote).setOnClickListener(new View.OnClickListener() { findViewById(R.id.btn_viewreport_upvote).setOnClickListener(new View.OnClickListener() {
@Override @Override
@@ -196,6 +196,8 @@ public class ViewReportActivity extends BaseActivity {
txtDescription.setText(incident.getString("text_long")); txtDescription.setText(incident.getString("text_long"));
txtCrimeCategory.setText(incident.getString("cat_name")); txtCrimeCategory.setText(incident.getString("cat_name"));
scorelabel.setText(jObj.getString("score"));
String[] happened_at = incident.getString("happened_at").split(" "); String[] happened_at = incident.getString("happened_at").split(" ");
txtDate.setText(happened_at[0]); txtDate.setText(happened_at[0]);
txtTime.setText(happened_at[1].substring(0, 5)); txtTime.setText(happened_at[1].substring(0, 5));
@@ -272,59 +274,6 @@ public class ViewReportActivity extends BaseActivity {
}; };
} }
public void getIncidentVoteScore(Integer uid) {
String tag_string_req = "getincidentvotescore";
StringRequest strReq = getStringRequestGetIncidentVoteScore(uid);
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
}
private StringRequest getStringRequestGetIncidentVoteScore(final Integer incidentid) {
return new StringRequest(Request.Method.POST, AppConfig.URL_REGISTER, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, "IncidentScore with ID response: " + response);
hideDialog();
try {
JSONObject jObj = new JSONObject(response);
boolean error = jObj.getBoolean("error");
if (!error) {
BootstrapLabel scorelabel = (BootstrapLabel) findViewById(R.id.txt_viewreport_points);
scorelabel.setText(jObj.getString("points"));
} else {
String errorMsg = jObj.getString("error_msg");
Log.e(TAG, "Error get incident vote score (Server returned error): " + errorMsg);
showMessage(errorMsg);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "Error get incident vote score: " + error.getMessage());
showMessage(getString(R.string.errormsg_couldnotretrieve));
hideDialog();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<>();
params.put("tag", "getincidentvotescore");
params.put("uid", user.get(SessionManager.KEY_UID));
params.put("token", user.get(SessionManager.TOKEN));
params.put("incidentid", incidentid.toString());
return params;
}
};
}
public void makeUpvote(Integer uid) { public void makeUpvote(Integer uid) {
String tag_string_req = "addvote"; String tag_string_req = "addvote";
StringRequest strReq = getStringRequestAddVote(uid, "1"); StringRequest strReq = getStringRequestAddVote(uid, "1");

View File

@@ -90,7 +90,7 @@ public class IncidentReport implements ClusterItem {
this.incidentPosition = new LatLng(mIncident.getDouble("latitude"),mIncident.getDouble("longitude")); this.incidentPosition = new LatLng(mIncident.getDouble("latitude"),mIncident.getDouble("longitude"));
} }
this.votedScore = mIncident.getInt("id"); this.votedScore = mIncident.getInt("score");
this.createdAt = mIncident.getString("created_at"); this.createdAt = mIncident.getString("created_at");
this.updatedAt = mIncident.getString("updated_at"); this.updatedAt = mIncident.getString("updated_at");
this.fromUsername = mIncident.getString("username"); this.fromUsername = mIncident.getString("username");
@@ -257,29 +257,29 @@ public class IncidentReport implements ClusterItem {
} }
public String getIncidentCategoryName(Context context){ public String getIncidentCategoryName(Context context){
return context.getResources().getStringArray(R.array.cat_situation_main)[this.fidIncidentCategory]; return context.getResources().getStringArray(R.array.cat_situation_main)[this.fidIncidentCategory-1];
} }
public String getIncidentSubCategoryName(Context context){ public String getIncidentSubCategoryName(Context context){
String returnName = ""; String returnName = "";
switch(this.fidIncidentCategory){ switch(this.fidIncidentCategory){
case 1: case 1:
returnName = context.getResources().getStringArray(R.array.cat_situation_sub_general)[this.fidIncidentSubCategory]; returnName = context.getResources().getStringArray(R.array.cat_situation_sub_general)[this.fidIncidentSubCategory-1];
break; break;
case 2: case 2:
returnName = context.getResources().getStringArray(R.array.cat_situation_sub_verbal)[this.fidIncidentSubCategory]; returnName = context.getResources().getStringArray(R.array.cat_situation_sub_verbal)[this.fidIncidentSubCategory-1];
break; break;
case 3: case 3:
returnName = context.getResources().getStringArray(R.array.cat_situation_sub_force)[this.fidIncidentSubCategory]; returnName = context.getResources().getStringArray(R.array.cat_situation_sub_force)[this.fidIncidentSubCategory-1];
break; break;
case 4: case 4:
returnName = context.getResources().getStringArray(R.array.cat_situation_sub_force_serious)[this.fidIncidentSubCategory]; returnName = context.getResources().getStringArray(R.array.cat_situation_sub_force_serious)[this.fidIncidentSubCategory-1];
break; break;
case 5: case 5:
returnName = context.getResources().getStringArray(R.array.cat_situation_sub_nature)[this.fidIncidentSubCategory]; returnName = context.getResources().getStringArray(R.array.cat_situation_sub_nature)[this.fidIncidentSubCategory-1];
break; break;
case 6: case 6:
returnName = context.getResources().getStringArray(R.array.cat_situation_sub_infrastructure)[this.fidIncidentSubCategory]; returnName = context.getResources().getStringArray(R.array.cat_situation_sub_infrastructure)[this.fidIncidentSubCategory-1];
break; break;
} }
return returnName; return returnName;
@@ -289,10 +289,10 @@ public class IncidentReport implements ClusterItem {
String returnString = ""; String returnString = "";
switch (this.fidTimeCategory){ switch (this.fidTimeCategory){
case 1: case 1:
returnString = context.getResources().getStringArray(R.array.cat_time_main)[this.fidTimeCategory]; returnString = context.getResources().getStringArray(R.array.cat_time_main)[this.fidTimeCategory-1];
break; break;
case 2: case 2:
returnString = context.getResources().getStringArray(R.array.cat_time_sub_periodical)[this.fidTimeSubCategory]; returnString = context.getResources().getStringArray(R.array.cat_time_sub_periodical)[this.fidTimeSubCategory-1];
break; break;
case 3: case 3:
if((this.fromTime != null) && !(this.fromTime.equals("00:00:00"))){ if((this.fromTime != null) && !(this.fromTime.equals("00:00:00"))){
@@ -309,14 +309,14 @@ public class IncidentReport implements ClusterItem {
} }
break; break;
case 5: case 5:
returnString = context.getResources().getStringArray(R.array.cat_time_main)[this.fidTimeCategory]; returnString = context.getResources().getStringArray(R.array.cat_time_main)[this.fidTimeCategory-1];
break; break;
} }
return returnString; return returnString;
} }
public String getSuspectString(Context context){ public String getSuspectString(Context context){
return context.getResources().getStringArray(R.array.cat_suspect_main)[this.fidSuspectCategory]; return context.getResources().getStringArray(R.array.cat_suspect_main)[this.fidSuspectCategory-1];
} }
public int getCategoryColor(){ public int getCategoryColor(){

View File

@@ -6,19 +6,23 @@
android:orientation="vertical" android:orientation="vertical"
android:paddingLeft="6dp" android:paddingLeft="6dp"
android:paddingRight="7dp" android:paddingRight="7dp"
android:paddingTop="8dp" android:paddingTop="7dp"
android:paddingBottom="8dp" android:paddingBottom="8dp"
android:background="@drawable/infowindow"> android:background="@drawable/infowindow">
<TextView <TextView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginRight="10dp"
android:textColor="#a6000000" android:textColor="#a6000000"
android:id="@+id/txt_infowindow_category" android:id="@+id/txt_infowindow_category"
android:text="Header" android:text="Headerfffffffffffffffffffffffffffffffff"
android:textSize="18dp" android:textSize="18dp"
android:paddingLeft="30dp" android:paddingLeft="30dp"
android:typeface="serif" /> android:typeface="serif"
android:singleLine="true"
android:ellipsize="marquee"
android:marqueeRepeatLimit="marquee_forever"/>
<LinearLayout <LinearLayout
android:orientation="horizontal" android:orientation="horizontal"