DT @27.11.2015: Fehler-handling verbessert und implementiert, Adds eingebaut
This commit is contained in:
@@ -29,6 +29,8 @@
|
|||||||
android:protectionLevel="signature" />
|
android:protectionLevel="signature" />
|
||||||
|
|
||||||
<!-- Google Maps Fragment API Key Data -->
|
<!-- Google Maps Fragment API Key Data -->
|
||||||
|
<meta-data android:name="com.google.android.gms.version"
|
||||||
|
android:value="@integer/google_play_services_version" />
|
||||||
<meta-data
|
<meta-data
|
||||||
android:name="com.google.android.maps.v2.API_KEY"
|
android:name="com.google.android.maps.v2.API_KEY"
|
||||||
android:value="AIzaSyALm-1lEf5xualfyHdmNEdAsXlbwOQhbI8" />
|
android:value="AIzaSyALm-1lEf5xualfyHdmNEdAsXlbwOQhbI8" />
|
||||||
@@ -39,6 +41,10 @@
|
|||||||
android:name="com.facebook.sdk.ApplicationId"
|
android:name="com.facebook.sdk.ApplicationId"
|
||||||
android:value="@string/facebook_app_id" />
|
android:value="@string/facebook_app_id" />
|
||||||
|
|
||||||
|
<activity android:name="com.google.android.gms.ads.AdActivity"
|
||||||
|
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
|
||||||
|
android:theme="@android:style/Theme.Translucent" />
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".StartActivity"
|
android:name=".StartActivity"
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
|
|||||||
@@ -34,8 +34,7 @@ public class MainActivity extends BaseActivity{
|
|||||||
|
|
||||||
Handler mHandler = new Handler();
|
Handler mHandler = new Handler();
|
||||||
|
|
||||||
private final static int INTERVAL = 1000 * 10; //10 seconds
|
private final static int INTERVAL = 1000 * 20; //20 seconds
|
||||||
private TextView incidentCount;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -46,7 +45,6 @@ public class MainActivity extends BaseActivity{
|
|||||||
msg_input = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
|
msg_input = intent.getStringExtra(MainActivity.EXTRA_MESSAGE);
|
||||||
|
|
||||||
fragmentManager = getSupportFragmentManager();
|
fragmentManager = getSupportFragmentManager();
|
||||||
incidentCount = (TextView) findViewById(R.id.txt_main_incidents);
|
|
||||||
|
|
||||||
findViewById(R.id.btn_main_report).setOnClickListener(new View.OnClickListener() {
|
findViewById(R.id.btn_main_report).setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@@ -63,6 +61,18 @@ public class MainActivity extends BaseActivity{
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected int getLayoutResourceId() {
|
||||||
|
return R.layout.activity_main;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected String getActivityName() {
|
||||||
|
return mActivityTitle;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause(){
|
protected void onPause(){
|
||||||
super.onPause();
|
super.onPause();
|
||||||
@@ -75,16 +85,6 @@ public class MainActivity extends BaseActivity{
|
|||||||
startRepeatingTask();
|
startRepeatingTask();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected int getLayoutResourceId() {
|
|
||||||
return R.layout.activity_main;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getActivityName() {
|
|
||||||
return mActivityTitle;
|
|
||||||
}
|
|
||||||
|
|
||||||
Runnable mHandlerTask = new Runnable()
|
Runnable mHandlerTask = new Runnable()
|
||||||
{
|
{
|
||||||
@Override
|
@Override
|
||||||
@@ -121,8 +121,8 @@ public class MainActivity extends BaseActivity{
|
|||||||
count.setText(jObj.getString("msg"));
|
count.setText(jObj.getString("msg"));
|
||||||
} else {
|
} else {
|
||||||
String errorMsg = jObj.getString("error_msg");
|
String errorMsg = jObj.getString("error_msg");
|
||||||
Toast.makeText(getApplicationContext(),
|
Log.e(TAG, "Error getting incident count (server returned error): " + errorMsg);
|
||||||
errorMsg, Toast.LENGTH_LONG).show();
|
showMessage(errorMsg);
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -134,15 +134,13 @@ public class MainActivity extends BaseActivity{
|
|||||||
@Override
|
@Override
|
||||||
public void onErrorResponse(VolleyError error) {
|
public void onErrorResponse(VolleyError error) {
|
||||||
Log.e(TAG, "Error getting incident count: " + error.getMessage());
|
Log.e(TAG, "Error getting incident count: " + error.getMessage());
|
||||||
Toast.makeText(getApplicationContext(),
|
showMessage(getString(R.string.errormsg_couldnotretrieve));
|
||||||
error.getMessage(), Toast.LENGTH_LONG).show();
|
|
||||||
stopRepeatingTask();
|
stopRepeatingTask();
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Map<String, String> getParams() {
|
protected Map<String, String> getParams() {
|
||||||
// Posting params to register url
|
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
params.put("tag", "getincidentcount");
|
params.put("tag", "getincidentcount");
|
||||||
params.put("uid", user.get("uid"));
|
params.put("uid", user.get("uid"));
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import android.app.SearchableInfo;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
import android.graphics.Color;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.LoaderManager;
|
import android.support.v4.app.LoaderManager;
|
||||||
import android.support.v4.content.CursorLoader;
|
import android.support.v4.content.CursorLoader;
|
||||||
@@ -13,6 +14,8 @@ import android.support.v7.widget.SearchView;
|
|||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
import android.widget.EditText;
|
||||||
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import com.android.volley.Request;
|
import com.android.volley.Request;
|
||||||
@@ -67,7 +70,7 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
|||||||
ClusterManager<AppClusterItem> mClusterManager;
|
ClusterManager<AppClusterItem> mClusterManager;
|
||||||
|
|
||||||
private static final int DEFAULT_ZOOM_LEVEL = 14;
|
private static final int DEFAULT_ZOOM_LEVEL = 14;
|
||||||
private static final int THRESHOLD_ZOOM_LEVEL = 6;
|
private static final int THRESHOLD_ZOOM_LEVEL = 7;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -251,6 +254,11 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
|||||||
SearchableInfo searchInfo = searchManager.getSearchableInfo(getComponentName());
|
SearchableInfo searchInfo = searchManager.getSearchableInfo(getComponentName());
|
||||||
searchView.setSearchableInfo(searchInfo);
|
searchView.setSearchableInfo(searchInfo);
|
||||||
|
|
||||||
|
EditText txtSearch = ((EditText)searchView.findViewById(android.support.v7.appcompat.R.id.search_src_text));
|
||||||
|
txtSearch.setHint(getResources().getString(R.string.search_hint));
|
||||||
|
txtSearch.setHintTextColor(Color.LTGRAY);
|
||||||
|
txtSearch.setTextColor(Color.WHITE);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,6 +283,7 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestGetAllIncidentsWithPosition() {
|
private StringRequest getStringRequestGetAllIncidentsWithPosition() {
|
||||||
|
showDialog();
|
||||||
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>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -310,12 +319,12 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
|||||||
Circle circle = mMap.addCircle(circleOptions);
|
Circle circle = mMap.addCircle(circleOptions);
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
addHeatMap();
|
addHeatMap();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
String errorMsg = jObj.getString("error_msg");
|
String errorMsg = jObj.getString("error_msg");
|
||||||
Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_LONG).show();
|
Log.e(TAG, "Error getting map positions (server returned error): " + errorMsg);
|
||||||
|
showMessage(errorMsg);
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -323,32 +332,25 @@ public class MapsActivity extends BaseActivity implements LoaderManager.LoaderCa
|
|||||||
|
|
||||||
}
|
}
|
||||||
}, new Response.ErrorListener() {
|
}, new Response.ErrorListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onErrorResponse(VolleyError error) {
|
public void onErrorResponse(VolleyError error) {
|
||||||
Log.e(TAG, "Report Error: " + error.getMessage());
|
Log.e(TAG, "Error getting map positions: " + error.getMessage());
|
||||||
Toast.makeText(getApplicationContext(),
|
showMessage(getString(R.string.errormsg_couldnotretrieve));
|
||||||
error.getMessage(), Toast.LENGTH_LONG).show();
|
|
||||||
hideDialog();
|
hideDialog();
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@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", "getincidentswithposition");
|
params.put("tag", "getincidentswithposition");
|
||||||
params.put("uid", user.get("uid"));
|
params.put("uid", user.get("uid"));
|
||||||
params.put("token", user.get("token"));
|
params.put("token", user.get("token"));
|
||||||
|
|
||||||
|
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onClusterItemInfoWindowClick(AppClusterItem appClusterItem) {
|
public void onClusterItemInfoWindowClick(AppClusterItem appClusterItem) {
|
||||||
gotoViewReportActivity(appClusterItem.getID());
|
gotoViewReportActivity(appClusterItem.getID());
|
||||||
|
|||||||
@@ -100,21 +100,19 @@ public class ProfileActivity extends BaseActivity {
|
|||||||
posts.setText(jObj.getString("posts"));
|
posts.setText(jObj.getString("posts"));
|
||||||
} else {
|
} else {
|
||||||
String errorMsg = jObj.getString("error_msg");
|
String errorMsg = jObj.getString("error_msg");
|
||||||
Toast.makeText(getApplicationContext(),
|
Log.e(TAG, "Error getting user stats (server returned error): " + errorMsg);
|
||||||
errorMsg, Toast.LENGTH_LONG).show();
|
showMessage(errorMsg);
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}, new Response.ErrorListener() {
|
}, new Response.ErrorListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onErrorResponse(VolleyError error) {
|
public void onErrorResponse(VolleyError error) {
|
||||||
Log.e(TAG, "Error getting user stats: " + error.getMessage());
|
Log.e(TAG, "Error getting user stats: " + error.getMessage());
|
||||||
Toast.makeText(getApplicationContext(),
|
showMessage(getString(R.string.errormsg_couldnotretrieve));
|
||||||
error.getMessage(), Toast.LENGTH_LONG).show();
|
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@@ -132,12 +130,13 @@ public class ProfileActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestTop10() {
|
private StringRequest getStringRequestTop10() {
|
||||||
|
showDialog();
|
||||||
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>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(String response) {
|
public void onResponse(String response) {
|
||||||
Log.d(TAG, "Top 10 stats: " + response);
|
Log.d(TAG, "Top 10 stats: " + response);
|
||||||
|
hideDialog();
|
||||||
try {
|
try {
|
||||||
JSONObject jObj = new JSONObject(response);
|
JSONObject jObj = new JSONObject(response);
|
||||||
boolean error = jObj.getBoolean("error");
|
boolean error = jObj.getBoolean("error");
|
||||||
@@ -170,12 +169,10 @@ public class ProfileActivity extends BaseActivity {
|
|||||||
|
|
||||||
tbltop10.addView(row,i+1);
|
tbltop10.addView(row,i+1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
String errorMsg = jObj.getString("error_msg");
|
String errorMsg = jObj.getString("error_msg");
|
||||||
Toast.makeText(getApplicationContext(),
|
Log.e(TAG, "Error getting top 10 stats (Server returned error): " + errorMsg);
|
||||||
errorMsg, Toast.LENGTH_LONG).show();
|
showMessage(errorMsg);
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -187,14 +184,13 @@ public class ProfileActivity extends BaseActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void onErrorResponse(VolleyError error) {
|
public void onErrorResponse(VolleyError error) {
|
||||||
Log.e(TAG, "Error getting top 10 stats: " + error.getMessage());
|
Log.e(TAG, "Error getting top 10 stats: " + error.getMessage());
|
||||||
Toast.makeText(getApplicationContext(),
|
showMessage(getString(R.string.errormsg_couldnotretrieve));
|
||||||
error.getMessage(), Toast.LENGTH_LONG).show();
|
hideDialog();
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Map<String, String> getParams() {
|
protected Map<String, String> getParams() {
|
||||||
// Posting params to register url
|
|
||||||
Map<String, String> params = new HashMap<>();
|
Map<String, String> params = new HashMap<>();
|
||||||
params.put("tag", "gettop10");
|
params.put("tag", "gettop10");
|
||||||
params.put("uid", user.get("uid"));
|
params.put("uid", user.get("uid"));
|
||||||
|
|||||||
@@ -191,75 +191,6 @@ public class ReportActivity extends BaseActivity {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
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>() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onResponse(String response) {
|
|
||||||
Log.d(TAG, "Report response: " + response);
|
|
||||||
|
|
||||||
try {
|
|
||||||
JSONObject jObj = new JSONObject(response);
|
|
||||||
boolean error = jObj.getBoolean("error");
|
|
||||||
|
|
||||||
if (!error) {
|
|
||||||
showMessage("Report added!");
|
|
||||||
SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
|
|
||||||
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");
|
|
||||||
Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_LONG).show();
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, new Response.ErrorListener() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onErrorResponse(VolleyError error) {
|
|
||||||
Log.e(TAG, "Report Error: " + error.getMessage());
|
|
||||||
Toast.makeText(getApplicationContext(),
|
|
||||||
error.getMessage(), Toast.LENGTH_LONG).show();
|
|
||||||
hideDialog();
|
|
||||||
}
|
|
||||||
}) {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected Map<String, String> getParams() {
|
|
||||||
// Posting parameters to login url
|
|
||||||
Map<String, String> params = new HashMap<>();
|
|
||||||
params.put("tag", "addincidentwithposition");
|
|
||||||
params.put("uid", user.get("uid"));
|
|
||||||
params.put("token", user.get("token"));
|
|
||||||
params.put("textshort",textshort);
|
|
||||||
params.put("textlong",textlong);
|
|
||||||
params.put("fiduser",user.get("uid"));
|
|
||||||
params.put("fidcategory", Integer.toString(crimecategory));
|
|
||||||
params.put("latitude",latitude);
|
|
||||||
params.put("longitude",longitude);
|
|
||||||
params.put("status",Integer.toString(status));
|
|
||||||
params.put("radius",Integer.toString(radius));
|
|
||||||
params.put("happened_at",year+"-"+month+"-"+day+" "+hour+":"+minute+":00");
|
|
||||||
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Dialog onCreateDialog(int id) {
|
protected Dialog onCreateDialog(int id) {
|
||||||
switch (id) {
|
switch (id) {
|
||||||
@@ -354,13 +285,82 @@ public class ReportActivity extends BaseActivity {
|
|||||||
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
|
AppController.getInstance().addToRequestQueue(strReq, tag_string_req);
|
||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestGetIncidentCategories() {
|
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) {
|
||||||
|
showDialog();
|
||||||
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>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(String response) {
|
public void onResponse(String response) {
|
||||||
Log.d(TAG, "Incident categories response: " + response);
|
Log.d(TAG, "Report response: " + response);
|
||||||
|
hideDialog();
|
||||||
|
try {
|
||||||
|
JSONObject jObj = new JSONObject(response);
|
||||||
|
boolean error = jObj.getBoolean("error");
|
||||||
|
|
||||||
|
if (!error) {
|
||||||
|
showMessage("Report added!");
|
||||||
|
SharedPreferences.Editor editor = getPreferences(MODE_PRIVATE).edit();
|
||||||
|
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");
|
||||||
|
Log.e(TAG, "Error adding incident (Server returned error): " + errorMsg);
|
||||||
|
showMessage(errorMsg);
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, new Response.ErrorListener() {
|
||||||
|
@Override
|
||||||
|
public void onErrorResponse(VolleyError error) {
|
||||||
|
Log.e(TAG, "Error adding incident: " + error.getMessage());
|
||||||
|
showMessage(getString(R.string.errormsg_couldnotretrieve));
|
||||||
|
hideDialog();
|
||||||
|
}
|
||||||
|
}) {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Map<String, String> getParams() {
|
||||||
|
Map<String, String> params = new HashMap<>();
|
||||||
|
params.put("tag", "addincidentwithposition");
|
||||||
|
params.put("uid", user.get("uid"));
|
||||||
|
params.put("token", user.get("token"));
|
||||||
|
params.put("textshort",textshort);
|
||||||
|
params.put("textlong",textlong);
|
||||||
|
params.put("fiduser",user.get("uid"));
|
||||||
|
params.put("fidcategory", Integer.toString(crimecategory));
|
||||||
|
params.put("latitude",latitude);
|
||||||
|
params.put("longitude",longitude);
|
||||||
|
params.put("status",Integer.toString(status));
|
||||||
|
params.put("radius",Integer.toString(radius));
|
||||||
|
params.put("happened_at",year+"-"+month+"-"+day+" "+hour+":"+minute+":00");
|
||||||
|
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private StringRequest getStringRequestGetIncidentCategories() {
|
||||||
|
showDialog();
|
||||||
|
return new StringRequest(Request.Method.POST, AppConfig.URL_REGISTER, new Response.Listener<String>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(String response) {
|
||||||
|
Log.d(TAG, "Incident categories response: " + response);
|
||||||
|
hideDialog();
|
||||||
try {
|
try {
|
||||||
JSONObject jObj = new JSONObject(response);
|
JSONObject jObj = new JSONObject(response);
|
||||||
boolean error = jObj.getBoolean("error");
|
boolean error = jObj.getBoolean("error");
|
||||||
@@ -386,7 +386,8 @@ public class ReportActivity extends BaseActivity {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
String errorMsg = jObj.getString("error_msg");
|
String errorMsg = jObj.getString("error_msg");
|
||||||
Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_LONG).show();
|
Log.e(TAG, "Error getting incident categories (Server returned error): " + errorMsg);
|
||||||
|
showMessage(errorMsg);
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -397,9 +398,9 @@ public class ReportActivity extends BaseActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onErrorResponse(VolleyError error) {
|
public void onErrorResponse(VolleyError error) {
|
||||||
Log.e(TAG, "Report Error: " + error.getMessage());
|
Log.e(TAG, "Error getting incident categories: " + error.getMessage());
|
||||||
Toast.makeText(getApplicationContext(),
|
showMessage(getString(R.string.errormsg_couldnotretrieve));
|
||||||
error.getMessage(), Toast.LENGTH_LONG).show();
|
hideDialog();
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ public class ReportlistActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestGetIncidentsWithPositionFromUserID() {
|
private StringRequest getStringRequestGetIncidentsWithPositionFromUserID() {
|
||||||
|
showDialog();
|
||||||
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>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -87,7 +88,6 @@ public class ReportlistActivity 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) {
|
||||||
JSONArray incidents = jObj.getJSONArray("message");
|
JSONArray incidents = jObj.getJSONArray("message");
|
||||||
resultList = new ArrayList<>();
|
resultList = new ArrayList<>();
|
||||||
@@ -104,12 +104,11 @@ public class ReportlistActivity extends BaseActivity {
|
|||||||
myListView.setAdapter(myListAdapter);
|
myListView.setAdapter(myListAdapter);
|
||||||
|
|
||||||
} 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();
|
Log.e(TAG, "Error getting incident list (Server returned error): " + errorMsg);
|
||||||
|
showMessage(errorMsg);
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
// JSON error
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,25 +117,21 @@ public class ReportlistActivity extends BaseActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onErrorResponse(VolleyError error) {
|
public void onErrorResponse(VolleyError error) {
|
||||||
Log.e(TAG, "Report Error: " + error.getMessage());
|
Log.e(TAG, "Error getting incident list: " + error.getMessage());
|
||||||
Toast.makeText(getApplicationContext(),
|
showMessage(getString(R.string.errormsg_couldnotretrieve));
|
||||||
error.getMessage(), Toast.LENGTH_LONG).show();
|
|
||||||
hideDialog();
|
hideDialog();
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@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", "getincidentsfromuserid");
|
params.put("tag", "getincidentsfromuserid");
|
||||||
params.put("uid", user.get("uid"));
|
params.put("uid", user.get("uid"));
|
||||||
params.put("token", user.get("token"));
|
params.put("token", user.get("token"));
|
||||||
|
|
||||||
|
|
||||||
return params;
|
return params;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -146,11 +146,13 @@ public class SettingsActivity extends BaseActivity {
|
|||||||
protected String getActivityName() { return mActivityTitle; }
|
protected String getActivityName() { return mActivityTitle; }
|
||||||
|
|
||||||
private StringRequest getStringChangeUserSettings() {
|
private StringRequest getStringChangeUserSettings() {
|
||||||
|
showDialog();
|
||||||
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>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(String response) {
|
public void onResponse(String response) {
|
||||||
Log.d(TAG, "Change user settings: " + response);
|
Log.d(TAG, "Change user settings: " + response);
|
||||||
|
hideDialog();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSONObject jObj = new JSONObject(response);
|
JSONObject jObj = new JSONObject(response);
|
||||||
@@ -162,10 +164,9 @@ public class SettingsActivity extends BaseActivity {
|
|||||||
finish();
|
finish();
|
||||||
startActivity(getIntent());
|
startActivity(getIntent());
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
String errorMsg = jObj.getString("error_msg");
|
String errorMsg = jObj.getString("error_msg");
|
||||||
Toast.makeText(getApplicationContext(),
|
Log.e(TAG, "Error getting user settings (Server returned error): " + errorMsg);
|
||||||
errorMsg, Toast.LENGTH_LONG).show();
|
showMessage(errorMsg);
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -176,9 +177,9 @@ public class SettingsActivity extends BaseActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onErrorResponse(VolleyError error) {
|
public void onErrorResponse(VolleyError error) {
|
||||||
Log.e(TAG, "Change user settings Error: " + error.getMessage());
|
Log.e(TAG, "Error getting user settings: " + error.getMessage());
|
||||||
Toast.makeText(getApplicationContext(),
|
showMessage(getString(R.string.errormsg_couldnotretrieve));
|
||||||
error.getMessage(), Toast.LENGTH_LONG).show();
|
hideDialog();
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
@@ -202,20 +203,23 @@ public class SettingsActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestResetPW(final String email) {
|
private StringRequest getStringRequestResetPW(final String email) {
|
||||||
|
showDialog();
|
||||||
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>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(String response) {
|
public void onResponse(String response) {
|
||||||
Log.d(TAG, "Resend E-Mail Response: " + response);
|
Log.d(TAG, "Resend E-Mail Response: " + response);
|
||||||
|
hideDialog();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
JSONObject jObj = new JSONObject(response);
|
JSONObject jObj = new JSONObject(response);
|
||||||
boolean error = jObj.getBoolean("error");
|
boolean error = jObj.getBoolean("error");
|
||||||
if (!error) {
|
if (!error) {
|
||||||
|
//do nothing
|
||||||
} else {
|
} else {
|
||||||
String errorMsg = jObj.getString("error_msg");
|
String errorMsg = jObj.getString("error_msg");
|
||||||
Toast.makeText(getApplicationContext(),
|
Log.e(TAG, "Error request email reset (Server returned error): " + errorMsg);
|
||||||
errorMsg, Toast.LENGTH_LONG).show();
|
showMessage(errorMsg);
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -226,9 +230,9 @@ public class SettingsActivity extends BaseActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onErrorResponse(VolleyError error) {
|
public void onErrorResponse(VolleyError error) {
|
||||||
Log.e(TAG, "E-Mail pw resend Error: " + error.getMessage());
|
Log.e(TAG, "Error request email reset: " + error.getMessage());
|
||||||
Toast.makeText(getApplicationContext(),
|
showMessage(getString(R.string.errormsg_couldnotretrieve));
|
||||||
error.getMessage(), Toast.LENGTH_LONG).show();
|
hideDialog();
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
|
|
||||||
|
|||||||
@@ -128,6 +128,7 @@ public class ViewReportActivity extends BaseActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private StringRequest getStringRequestDeleteIncident(final String incidentid) {
|
private StringRequest getStringRequestDeleteIncident(final String incidentid) {
|
||||||
|
showDialog();
|
||||||
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>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -139,14 +140,13 @@ 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) {
|
||||||
showMessage("Incident deleted");
|
showMessage("Incident deleted");
|
||||||
gotoProfileActivity();
|
gotoProfileActivity();
|
||||||
} 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();
|
Log.e(TAG, "Error deleting incident (Server returned error): " + errorMsg);
|
||||||
|
showMessage(errorMsg);
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -156,9 +156,8 @@ public class ViewReportActivity extends BaseActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onErrorResponse(VolleyError error) {
|
public void onErrorResponse(VolleyError error) {
|
||||||
Log.e(TAG, "Report Error: " + error.getMessage());
|
Log.e(TAG, "Error deleting incident: " + error.getMessage());
|
||||||
Toast.makeText(getApplicationContext(),
|
showMessage(getString(R.string.errormsg_couldnotretrieve));
|
||||||
error.getMessage(), Toast.LENGTH_LONG).show();
|
|
||||||
hideDialog();
|
hideDialog();
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
@@ -180,7 +179,7 @@ public class ViewReportActivity extends BaseActivity {
|
|||||||
|
|
||||||
|
|
||||||
private StringRequest getStringRequestGetIncidentWithPositionFromID(final String incidentid) {
|
private StringRequest getStringRequestGetIncidentWithPositionFromID(final String incidentid) {
|
||||||
|
showDialog();
|
||||||
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>() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -192,7 +191,6 @@ 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) {
|
||||||
JSONObject incident = jObj.getJSONArray("message").getJSONObject(0);
|
JSONObject incident = jObj.getJSONArray("message").getJSONObject(0);
|
||||||
|
|
||||||
@@ -244,9 +242,9 @@ public class ViewReportActivity extends BaseActivity {
|
|||||||
|
|
||||||
|
|
||||||
} 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();
|
Log.e(TAG, "Error get incident (Server returned error): " + errorMsg);
|
||||||
|
showMessage(errorMsg);
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -256,9 +254,8 @@ public class ViewReportActivity extends BaseActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onErrorResponse(VolleyError error) {
|
public void onErrorResponse(VolleyError error) {
|
||||||
Log.e(TAG, "Report Error: " + error.getMessage());
|
Log.e(TAG, "Error get incident: " + error.getMessage());
|
||||||
Toast.makeText(getApplicationContext(),
|
showMessage(getString(R.string.errormsg_couldnotretrieve));
|
||||||
error.getMessage(), Toast.LENGTH_LONG).show();
|
|
||||||
hideDialog();
|
hideDialog();
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
@@ -302,7 +299,8 @@ public class ViewReportActivity extends BaseActivity {
|
|||||||
scorelabel.setText(jObj.getString("points"));
|
scorelabel.setText(jObj.getString("points"));
|
||||||
} else {
|
} else {
|
||||||
String errorMsg = jObj.getString("error_msg");
|
String errorMsg = jObj.getString("error_msg");
|
||||||
Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_LONG).show();
|
Log.e(TAG, "Error get incident vote score (Server returned error): " + errorMsg);
|
||||||
|
showMessage(errorMsg);
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -312,9 +310,8 @@ public class ViewReportActivity extends BaseActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onErrorResponse(VolleyError error) {
|
public void onErrorResponse(VolleyError error) {
|
||||||
Log.e(TAG, "Report Error: " + error.getMessage());
|
Log.e(TAG, "Error get incident vote score: " + error.getMessage());
|
||||||
Toast.makeText(getApplicationContext(),
|
showMessage(getString(R.string.errormsg_couldnotretrieve));
|
||||||
error.getMessage(), Toast.LENGTH_LONG).show();
|
|
||||||
hideDialog();
|
hideDialog();
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
@@ -363,7 +360,8 @@ public class ViewReportActivity extends BaseActivity {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
String errorMsg = jObj.getString("error_msg");
|
String errorMsg = jObj.getString("error_msg");
|
||||||
Toast.makeText(getApplicationContext(), errorMsg, Toast.LENGTH_LONG).show();
|
Log.e(TAG, "Error voting incident (Server returned error): " + errorMsg);
|
||||||
|
showMessage(errorMsg);
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -373,9 +371,8 @@ public class ViewReportActivity extends BaseActivity {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onErrorResponse(VolleyError error) {
|
public void onErrorResponse(VolleyError error) {
|
||||||
Log.e(TAG, "Report Error: " + error.getMessage());
|
Log.e(TAG, "Error voting incident: " + error.getMessage());
|
||||||
Toast.makeText(getApplicationContext(),
|
showMessage(getString(R.string.errormsg_couldnotretrieve));
|
||||||
error.getMessage(), Toast.LENGTH_LONG).show();
|
|
||||||
hideDialog();
|
hideDialog();
|
||||||
}
|
}
|
||||||
}) {
|
}) {
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package org.deke.risk.riskahead.helper;
|
|||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
|
import com.android.volley.DefaultRetryPolicy;
|
||||||
import com.android.volley.Request;
|
import com.android.volley.Request;
|
||||||
import com.android.volley.RequestQueue;
|
import com.android.volley.RequestQueue;
|
||||||
import com.android.volley.toolbox.Volley;
|
import com.android.volley.toolbox.Volley;
|
||||||
@@ -12,6 +12,8 @@ import com.beardedhen.androidbootstrap.TypefaceProvider;
|
|||||||
public class AppController extends Application {
|
public class AppController extends Application {
|
||||||
|
|
||||||
public static final String TAG = AppController.class.getSimpleName();
|
public static final String TAG = AppController.class.getSimpleName();
|
||||||
|
private static final int MY_SOCKET_TIMEOUT_MS = 10000;
|
||||||
|
private static final int MY_SOCKET_RETRIES_MS = 3;
|
||||||
|
|
||||||
private RequestQueue mRequestQueue;
|
private RequestQueue mRequestQueue;
|
||||||
private static AppController mInstance;
|
private static AppController mInstance;
|
||||||
@@ -38,6 +40,9 @@ public class AppController extends Application {
|
|||||||
|
|
||||||
public <T> void addToRequestQueue(Request<T> req, String tag) {
|
public <T> void addToRequestQueue(Request<T> req, String tag) {
|
||||||
req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
|
req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
|
||||||
|
req.setRetryPolicy(new DefaultRetryPolicy(MY_SOCKET_TIMEOUT_MS,
|
||||||
|
MY_SOCKET_RETRIES_MS,
|
||||||
|
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
|
||||||
getRequestQueue().add(req);
|
getRequestQueue().add(req);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,15 @@
|
|||||||
package org.deke.risk.riskahead.helper;
|
package org.deke.risk.riskahead.helper;
|
||||||
|
|
||||||
|
import android.app.AlertDialog;
|
||||||
import android.app.ProgressDialog;
|
import android.app.ProgressDialog;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
import android.net.ConnectivityManager;
|
||||||
|
import android.net.NetworkInfo;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Handler;
|
||||||
import android.support.v4.widget.DrawerLayout;
|
import android.support.v4.widget.DrawerLayout;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.app.ActionBarDrawerToggle;
|
import android.support.v7.app.ActionBarDrawerToggle;
|
||||||
@@ -17,6 +23,11 @@ import android.widget.AdapterView;
|
|||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.android.volley.toolbox.StringRequest;
|
||||||
|
import com.google.android.gms.ads.AdListener;
|
||||||
|
import com.google.android.gms.ads.AdRequest;
|
||||||
|
import com.google.android.gms.ads.InterstitialAd;
|
||||||
|
|
||||||
import org.deke.risk.riskahead.LoginActivity;
|
import org.deke.risk.riskahead.LoginActivity;
|
||||||
import org.deke.risk.riskahead.MainActivity;
|
import org.deke.risk.riskahead.MainActivity;
|
||||||
import org.deke.risk.riskahead.MapsActivity;
|
import org.deke.risk.riskahead.MapsActivity;
|
||||||
@@ -25,7 +36,6 @@ import org.deke.risk.riskahead.ReportActivity;
|
|||||||
import org.deke.risk.riskahead.ProfileActivity;
|
import org.deke.risk.riskahead.ProfileActivity;
|
||||||
import org.deke.risk.riskahead.ReportlistActivity;
|
import org.deke.risk.riskahead.ReportlistActivity;
|
||||||
import org.deke.risk.riskahead.SettingsActivity;
|
import org.deke.risk.riskahead.SettingsActivity;
|
||||||
import org.deke.risk.riskahead.StartActivity;
|
|
||||||
import org.deke.risk.riskahead.SubscriptionsActivity;
|
import org.deke.risk.riskahead.SubscriptionsActivity;
|
||||||
import org.deke.risk.riskahead.ViewReportActivity;
|
import org.deke.risk.riskahead.ViewReportActivity;
|
||||||
|
|
||||||
@@ -46,10 +56,15 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||||||
public HashMap<String, String> user;
|
public HashMap<String, String> user;
|
||||||
public ProgressDialog pDialog;
|
public ProgressDialog pDialog;
|
||||||
|
|
||||||
|
Handler mHandler = new Handler();
|
||||||
|
private final static int INTERVAL = 1000 * 300; //300 seconds
|
||||||
|
InterstitialAd mInterstitialAd;
|
||||||
|
|
||||||
public void userHasToBeLoggedIn(){
|
public void userHasToBeLoggedIn(){
|
||||||
if (!session.isLoggedIn()) {
|
if (!session.isLoggedIn()) {
|
||||||
logout();
|
logout();
|
||||||
}
|
}
|
||||||
|
isNetworkAvailable();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -57,10 +72,26 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(getLayoutResourceId());
|
setContentView(getLayoutResourceId());
|
||||||
|
|
||||||
|
mInterstitialAd = new InterstitialAd(getApplicationContext());
|
||||||
|
mInterstitialAd.setAdUnitId(getString(R.string.banner_ad_unit_id));
|
||||||
|
|
||||||
|
mInterstitialAd.setAdListener(new AdListener() {
|
||||||
|
@Override
|
||||||
|
public void onAdClosed() {
|
||||||
|
requestNewInterstitial();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
requestNewInterstitial();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
overridePendingTransition(R.anim.fade_in_anim, R.anim.fade_out_anim);
|
overridePendingTransition(R.anim.fade_in_anim, R.anim.fade_out_anim);
|
||||||
|
|
||||||
pDialog = new ProgressDialog(this);
|
pDialog = new ProgressDialog(this);
|
||||||
pDialog.setCancelable(false);
|
pDialog.setCancelable(false);
|
||||||
|
pDialog.setTitle(getString(R.string.progress_getdata_title));
|
||||||
|
pDialog.setMessage(getString(R.string.progress_getdata_text));
|
||||||
|
|
||||||
session = new SessionManager(getApplicationContext());
|
session = new SessionManager(getApplicationContext());
|
||||||
user = session.getUserDetails();
|
user = session.getUserDetails();
|
||||||
@@ -86,6 +117,64 @@ public abstract class BaseActivity extends AppCompatActivity {
|
|||||||
getSupportActionBar().setHomeButtonEnabled(true);
|
getSupportActionBar().setHomeButtonEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void requestNewInterstitial() {
|
||||||
|
AdRequest adRequest = new AdRequest.Builder()
|
||||||
|
.addTestDevice("1C182703CED1D65AE86F9E51E94ECDE7")
|
||||||
|
.build();
|
||||||
|
|
||||||
|
mInterstitialAd.loadAd(adRequest);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPause(){
|
||||||
|
super.onPause();
|
||||||
|
stopRepeatingTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onResume(){
|
||||||
|
super.onResume();
|
||||||
|
startRepeatingTask();
|
||||||
|
}
|
||||||
|
|
||||||
|
Runnable mHandlerTask = new Runnable()
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (mInterstitialAd.isLoaded()) {
|
||||||
|
mInterstitialAd.show();
|
||||||
|
}
|
||||||
|
mHandler.postDelayed(mHandlerTask, INTERVAL);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
void startRepeatingTask()
|
||||||
|
{
|
||||||
|
mHandlerTask.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
void stopRepeatingTask()
|
||||||
|
{
|
||||||
|
mHandler.removeCallbacks(mHandlerTask);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void isNetworkAvailable() {
|
||||||
|
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
|
||||||
|
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
|
||||||
|
if(activeNetworkInfo == null){
|
||||||
|
new AlertDialog.Builder(this)
|
||||||
|
.setTitle(getString(R.string.alert_internetconnection_title))
|
||||||
|
.setMessage(getString(R.string.alert_internetconnection_text))
|
||||||
|
.setNeutralButton(android.R.string.yes, new DialogInterface.OnClickListener() {
|
||||||
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
|
logoutUser();
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||||
|
.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void logoutUser() {
|
public void logoutUser() {
|
||||||
session.removeUser();
|
session.removeUser();
|
||||||
logout();
|
logout();
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
<resources>
|
<resources>
|
||||||
<string name="app_name">RiskAhead</string>
|
<string name="app_name">RiskAhead</string>
|
||||||
<string name="facebook_app_id">658657714234846</string>
|
<string name="facebook_app_id">658657714234846</string>
|
||||||
|
<string name="banner_ad_unit_id">ca-app-pub-3940256099942544/6300978111</string>
|
||||||
|
|
||||||
<string name="btn_start_login">Login</string>
|
<string name="btn_start_login">Login</string>
|
||||||
<string name="btn_start_register">Register</string>
|
<string name="btn_start_register">Register</string>
|
||||||
@@ -109,5 +110,10 @@
|
|||||||
<string name="alert_accactivation_confirmation">E-Mail was sent to your e-mail address</string>
|
<string name="alert_accactivation_confirmation">E-Mail was sent to your e-mail address</string>
|
||||||
<string name="alert_accregistration_title">Activation E-Mail</string>
|
<string name="alert_accregistration_title">Activation E-Mail</string>
|
||||||
<string name="alert_accregistration_text">An activation link was send to your e-mail address. Please follow the instructions to activate your account. Thank you!</string>
|
<string name="alert_accregistration_text">An activation link was send to your e-mail address. Please follow the instructions to activate your account. Thank you!</string>
|
||||||
|
<string name="alert_internetconnection_title">No Internet Connection</string>
|
||||||
|
<string name="alert_internetconnection_text">You need an active internet connection to use this app. Please turn on your internet connection and login again.</string>
|
||||||
|
<string name="errormsg_couldnotretrieve">Could not retrieve data from server. Please check internet connection.</string>
|
||||||
|
<string name="progress_getdata_text">Please wait...</string>
|
||||||
|
<string name="progress_getdata_title">Retrieve data from server</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user