Killing nls warnings and logging

pull/14/head
Andrew Shaw 13 years ago
parent 572296e023
commit 9b4374688e

@ -47,7 +47,6 @@ import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.PopupWindow.OnDismissListener;
import android.widget.TextView;
import android.widget.Toast;
import com.timsu.astrid.R;
import com.todoroo.andlib.service.Autowired;
@ -132,12 +131,22 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
public static final String TASK_RABBIT_TOKEN = "task_rabbit_token"; //$NON-NLS-1$
private static final String TASK_RABBIT_POPOVER_PREF = "task_rabbit_popover"; //$NON-NLS-1$
private static final String TASK_RABBIT_PREF_CITY_NAME = "task_rabbit_city_name"; //$NON-NLS-1$
private static final String TASK_RABBIT_PREF_CITY_ID = "task_rabbit_city_id"; //$NON-NLS-1$
private static final String TASK_RABBIT_PREF_CITY_LAT = "task_rabbit_city_lat"; //$NON-NLS-1$
private static final String TASK_RABBIT_PREF_CITY_LNG = "task_rabbit_city_lng"; //$NON-NLS-1$
public static final String CITY_NAME = "name"; //$NON-NLS-1$
public static final String CITY_LAT = "lat"; //$NON-NLS-1$
public static final String CITY_LNG = "lng"; //$NON-NLS-1$
public static final String LOCATION_CONTAINER = "other_locations_attributes"; //$NON-NLS-1$
// Non-production values
public static final String TASK_RABBIT_URL = "http://rs-astrid-api.taskrabbit.com"; //$NON-NLS-1$
public static final String TASK_RABBIT_CLIENT_ID = "fDTmGeR0uNCvoxopNyqsRWae8xOvbOBqC7jmHaxv"; //$NON-NLS-1$
public static final String TASK_RABBIT_CLIENT_APPLICATION_ID = "XBpKshU8utH5eaNmhky9N8aAId5rSLTh04Hi60Co"; //$NON-NLS-1$
public static final String CITY_NAME = "task_rabbit_city_name"; //$NON-NLS-1$
public static final String TASK_RABBIT_ID = "id"; //$NON-NLS-1$
private TaskRabbitTaskContainer taskRabbitTask;
/* From tag settings */
@ -290,7 +299,7 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
TaskRabbitNameControlSet descriptionControlSet = new TaskRabbitNameControlSet(this,
R.layout.control_set_notes, R.layout.task_rabbit_row_description, titleID, i);
try {
descriptionControlSet.readFromModel(new JSONObject().put("description", model.getValue(Task.NOTES)), "description", currentSelectedItem);
descriptionControlSet.readFromModel(new JSONObject().put(getString(arrayID), model.getValue(Task.NOTES)), getString(arrayID), currentSelectedItem);
} catch (JSONException e) {
e.printStackTrace();
}
@ -301,11 +310,6 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
controls.add(set);
}
}
/*
if(TextUtils.isEmpty(taskDescription.getText())){
taskDescription.setText(model.getValue(Task.NOTES));
}*/
if(TextUtils.isEmpty(taskTitle.getText())) {
taskTitle.setText(model.getValue(Task.TITLE));
}
@ -431,7 +435,7 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
}
if(taskRabbitTask.getTaskID() != TaskRabbitTaskContainer.NO_ID) {
taskButton.setText("Already Posted!");
taskButton.setText(getString(R.string.tr_button_already_posted));
taskButton.setEnabled(false);
}
else {
@ -467,21 +471,21 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
String descriptionKey = getString(R.string.tr_set_key_description);
String category = "Category: " + menuTitle.getText().toString() + "\n";
String category = String.format("Category: %S\n", menuTitle.getText().toString()); //$NON-NLS-1$
parameters.put(descriptionKey, category);
for (int i = 0; i < controls.size(); i++) {
if (presetValues[i] == -1) continue;
TaskRabbitSetListener set = controls.get(i);
set.postToTaskRabbit(parameters, keys[i]);
}
if (parameters.optJSONArray("other_locations_attributes") == null) {
parameters.put(getString(R.string.tr_attr_city_id), Preferences.getInt("task_rabbit_city_id", 1));
if (parameters.optJSONArray(LOCATION_CONTAINER) == null) {
parameters.put(getString(R.string.tr_attr_city_id), Preferences.getInt(TASK_RABBIT_PREF_CITY_ID, 1));
parameters.put(getString(R.string.tr_attr_city_lat), true);
}
parameters.put(getString(R.string.tr_set_key_name), taskTitle.getText().toString());
parameters.put(getString(R.string.tr_set_key_name), taskTitle.getText().toString());
return new JSONObject().put("task", parameters);
return new JSONObject().put("task", parameters); //$NON-NLS-1$
}
@ -516,7 +520,10 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
return null;
}
private ProgressDialog progressDialog;
@SuppressWarnings("nls")
protected void submitTaskRabbit(){
if(!Preferences.isSet(TASK_RABBIT_TOKEN)){
@ -535,18 +542,16 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
try {
String urlCall = "tasks/";
if (taskRabbitTask.getTaskID() > 0) urlCall += taskRabbitTask.getTaskID();
urlCall +="?client_id=" + TASK_RABBIT_CLIENT_ID;
Log.d("Tasks url:", taskRabbitURL(urlCall));
Header authorization = new BasicHeader("Authorization", "OAuth " + Preferences.getStringValue(TASK_RABBIT_TOKEN)); //$NON-NLS-1$
Header contentType = new BasicHeader("Content-Type", //$NON-NLS-1$
"application/json"); //$NON-NLS-1$
urlCall += String.format("?client_id=%S&client_application=%S", TASK_RABBIT_CLIENT_ID, TASK_RABBIT_CLIENT_APPLICATION_ID);
Header authorization = new BasicHeader("Authorization", "OAuth" + Preferences.getStringValue(TASK_RABBIT_TOKEN));
Header contentType = new BasicHeader("Content-Type", "application/json");
String response = restClient.post(taskRabbitURL(urlCall), getTaskBody(), contentType, authorization);
Log.d("Task rabbit response", response);
JSONObject taskResponse = new JSONObject(response);
if(taskResponse.has("id")){
if(taskResponse.has(TASK_RABBIT_ID)){
taskRabbitTask.setRemoteTaskData(response);
taskRabbitTask.setTaskID(taskResponse.optString("id"));
taskRabbitTask.setTaskID(taskResponse.optString(TASK_RABBIT_ID));
Message successMessage = new Message();
successMessage.what = 1;
handler.sendMessage(successMessage);
@ -575,7 +580,6 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
try {
taskRabbitTask.setLocalTaskData(serializeToJSON().toString());
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
@ -583,15 +587,6 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
}
/* message callbacks */
/**
* Show toast for task edit canceling
*/
private void showSuccessToast() {
Toast.makeText(this, "Task posted to Task Rabbit successfully!",
Toast.LENGTH_SHORT).show();
}
private final Handler handler = new Handler() {
@Override
@ -600,9 +595,9 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
case -1:
AlertDialog.Builder adb = new AlertDialog.Builder(TaskRabbitActivity.this);
adb.setTitle("Error posting task");
adb.setMessage("Please try again");
adb.setPositiveButton("Close",null);
adb.setTitle(getString(R.string.tr_alert_title_fail));
adb.setMessage(getString(R.string.tr_alert_message_fail));
adb.setPositiveButton(getString(R.string.tr_alert_button_fail),null);
adb.show();
break;
case 0: break;
@ -624,12 +619,11 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
Intent intent = new Intent(this,
OAuthLoginActivity.class);
try {
String url = TASK_RABBIT_URL + "/api/authorize?client_id=" + TASK_RABBIT_CLIENT_ID;
String url = TASK_RABBIT_URL + "/api/authorize?client_id=" + TASK_RABBIT_CLIENT_ID; //$NON-NLS-1$
intent.putExtra(OAuthLoginActivity.URL_TOKEN, url);
this.startActivityForResult(intent, REQUEST_CODE_TASK_RABBIT_OAUTH);
StatisticsService.reportEvent(StatisticsConstants.ACTFM_LOGIN_GL_START);
} catch (Exception e) {
// handleError(e);
e.printStackTrace();
}
}
@ -648,17 +642,18 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
}
@SuppressWarnings("nls")
private void buildAlertMessageNoGps() {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("GPS needs to be enabled in order to add location based tasks. Do you want to enable it?")
builder.setMessage(getString(R.string.tr_alert_gps_title))
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
public void onClick(final DialogInterface dialog, final int id) {
startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
public void onClick(final DialogInterface dialog, final int id) {
dialog.cancel();
}
});
@ -669,40 +664,39 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
protected void saveUserInfo(String response) throws Exception {
JSONObject userObject = new JSONObject(response);
JSONObject cityObject = userObject.getJSONObject("city");
if (cityObject.has("name")){
Preferences.setString("task_rabbit_city_name", cityObject.getString("name"));
JSONObject cityObject = userObject.getJSONObject("city"); //$NON-NLS-1$
if (cityObject.has(CITY_NAME)){
Preferences.setString(TASK_RABBIT_PREF_CITY_NAME, cityObject.getString(CITY_NAME));
}
if (cityObject.has("id")){
Preferences.setInt("task_rabbit_city_id", cityObject.getInt("id"));
if (cityObject.has(TASK_RABBIT_ID)){
Preferences.setInt(TASK_RABBIT_PREF_CITY_ID, cityObject.getInt(TASK_RABBIT_ID));
}
if (cityObject.has("lat")){
// currentLocation.setLatitude(cityObject.getDouble("lat"));
Preferences.setString("task_rabbit_city_lat", String.valueOf(cityObject.getDouble("lat")));
if (cityObject.has(CITY_LAT)){
Preferences.setString(TASK_RABBIT_PREF_CITY_LAT, String.valueOf(cityObject.getDouble(CITY_LAT)));
}
if (cityObject.has("lng")){
// currentLocation.setLongitude(cityObject.getDouble("lng"));
Preferences.setString("task_rabbit_city_lng", String.valueOf(cityObject.getDouble("lng")));
if (cityObject.has(CITY_LNG)){
Preferences.setString(TASK_RABBIT_PREF_CITY_LNG, String.valueOf(cityObject.getDouble(CITY_LNG)));
}
}
private String taskRabbitURL(String method) {
return TASK_RABBIT_URL + "/api/v1/"+ method;
return TASK_RABBIT_URL + "/api/v1/"+ method; //$NON-NLS-1$
}
@Override
public void onActivityResult (int requestCode, int resultCode, Intent data) {
Log.d("The actiivty result request code", "Rerjwklrw" + requestCode);
if (requestCode == REQUEST_CODE_TASK_RABBIT_OAUTH && resultCode == Activity.RESULT_OK){
String result = data.getStringExtra(OAuthLoginActivity.DATA_RESPONSE);
if(result.contains("access_token=")) {
String key = "access_token"; //$NON-NLS-1$
if(result.contains(key)) {
try {
result = result.substring(result.indexOf("access_token=")+"access_token=".length());
result = result.substring(result.indexOf(key)+key.length());
Preferences.setString(TASK_RABBIT_TOKEN, result);
String response = restClient.get(taskRabbitURL("account"));
Log.d("Task rabbit response", response);
String response = restClient.get(taskRabbitURL("account")); //$NON-NLS-1$
saveUserInfo(response);
}
catch (Exception e){

@ -16,7 +16,6 @@ import android.os.Handler;
import android.os.Message;
import android.support.v4.app.Fragment;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
@ -34,7 +33,6 @@ import com.todoroo.astrid.activity.TaskEditFragment;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.helper.TaskEditControlSet;
@SuppressWarnings("nls")
public class TaskRabbitControlSet extends TaskEditControlSet implements AssignedChangedListener, LocationListener {
@ -134,7 +132,7 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
private void updateTaskRow(TaskRabbitTaskContainer container) {
displayText.setText("Task Rabbit Status");
displayText.setText(fragment.getActivity().getString(R.string.tr_display_status));
JSONObject remoteData = container.getRemoteTaskData();
if (remoteData != null) {
updateDisplay(remoteData);
@ -147,7 +145,7 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
* Show toast for task edit canceling
*/
private void showSuccessToast() {
Toast.makeText(fragment.getActivity(), "Task posted to Task Rabbit successfully!",
Toast.makeText(fragment.getActivity(), fragment.getActivity().getString(R.string.tr_success_toast),
Toast.LENGTH_SHORT).show();
}
@ -166,7 +164,7 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
};
private String taskRabbitURL(String method) {
return String.format("%S/api/v1/%S?client_id=%S&client_application=%S", TaskRabbitActivity.TASK_RABBIT_URL, method, TaskRabbitActivity.TASK_RABBIT_CLIENT_ID, TaskRabbitActivity.TASK_RABBIT_CLIENT_APPLICATION_ID);
return String.format("%S/api/v1/%S?client_id=%S&client_application=%S", TaskRabbitActivity.TASK_RABBIT_URL, method, TaskRabbitActivity.TASK_RABBIT_CLIENT_ID, TaskRabbitActivity.TASK_RABBIT_CLIENT_APPLICATION_ID); //$NON-NLS-1$
}
/** Fire task rabbit if assigned **/
@ -219,17 +217,17 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
protected void updateStatus(JSONObject json){
final int taskID = json.optInt("id"); //$NON-NLS-1$
final int taskID = json.optInt(TaskRabbitActivity.TASK_RABBIT_ID);
new Thread(new Runnable() {
@Override
public void run() {
try {
String response = restClient.get(taskRabbitURL("tasks/" + taskID));
String response = restClient.get(taskRabbitURL("tasks/" + taskID)); //$NON-NLS-1$
JSONObject taskResponse = new JSONObject(response);
if(taskResponse.has("id")){
if(taskResponse.has(TaskRabbitActivity.TASK_RABBIT_ID)){
taskRabbitTask.setRemoteTaskData(response);
taskRabbitTask.setTaskID(taskResponse.optString("id"));
taskRabbitTask.setTaskID(taskResponse.optString(TaskRabbitActivity.TASK_RABBIT_ID));
Message successMessage = new Message();
successMessage.what = 2;
handler.sendMessage(successMessage);
@ -263,11 +261,9 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
locationManager = (LocationManager) fragment.getActivity().getSystemService(Context.LOCATION_SERVICE);
currentLocation = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (currentLocation == null) {
Log.d("TRControlSet", "Fail current location is null");
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}
else {
Log.d("TRControlSet", "loading location and checking if we suppor it");
isEnabledForTRLocation = supportsCurrentLocation();
}
}
@ -275,7 +271,7 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
public boolean supportsCurrentLocation() {
if (currentLocation == null) return false;
for (GeoPoint point : supportedLocations){
Location city = new Location("");
Location city = new Location(""); //$NON-NLS-1$
city.setLatitude(point.getLatitudeE6()/1E6);
city.setLongitude(point.getLongitudeE6()/1E6);
float distance = currentLocation.distanceTo(city);
@ -291,7 +287,6 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
@Override
public void onLocationChanged(Location location) {
Log.d("TRControlSet", "Location changed and found");
currentLocation = location;
isEnabledForTRLocation = supportsCurrentLocation();
locationManager.removeUpdates(this);

@ -1,8 +1,6 @@
package com.todoroo.astrid.taskrabbit;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import org.json.JSONArray;
import org.json.JSONException;
@ -11,11 +9,8 @@ import org.json.JSONObject;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Address;
import android.location.Geocoder;
import android.location.Location;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
@ -30,7 +25,6 @@ import com.todoroo.astrid.helper.TaskEditControlSet;
import com.todoroo.astrid.taskrabbit.TaskRabbitActivity.ActivityResultSetListener;
import com.todoroo.astrid.taskrabbit.TaskRabbitActivity.TaskRabbitSetListener;
@SuppressWarnings("nls")
public class TaskRabbitLocationControlSet extends TaskEditControlSet implements TaskRabbitSetListener, ActivityResultSetListener {
private final TextView displayText;
@ -58,7 +52,7 @@ public class TaskRabbitLocationControlSet extends TaskEditControlSet implements
@Override
public void onClick(View v) {
try {
Class.forName("com.google.android.maps.MapView");
Class.forName("com.google.android.maps.MapView"); //$NON-NLS-1$
Intent mapIntent = new Intent(activity, TaskRabbitMapActivity.class);
activity.startActivityForResult(mapIntent, REQUEST_CODE_TASK_RABBIT_LOCATION);
} catch (Exception e) {
@ -69,6 +63,7 @@ public class TaskRabbitLocationControlSet extends TaskEditControlSet implements
}
@SuppressWarnings("nls")
protected void manualLocationEntry() {
LinearLayout layout = new LinearLayout(activity);
layout.setOrientation(LinearLayout.VERTICAL);
@ -102,12 +97,12 @@ public class TaskRabbitLocationControlSet extends TaskEditControlSet implements
private void parseTaskLocation(JSONObject json) {
if (json == null) return;
if (json.has("name"))
locationName = json.optString("name");
if(json.has("lng")) {
location = new Location("");
location.setLatitude(json.optInt("lng"));
location.setLatitude(json.optInt("lat"));
if (json.has(TaskRabbitActivity.CITY_NAME))
locationName = json.optString(TaskRabbitActivity.CITY_NAME);
if(json.has(TaskRabbitActivity.CITY_LNG)) {
location = new Location(""); //$NON-NLS-1$
location.setLongitude(json.optInt(TaskRabbitActivity.CITY_LNG));
location.setLatitude(json.optInt(TaskRabbitActivity.CITY_LAT));
}
}
@ -115,20 +110,19 @@ public class TaskRabbitLocationControlSet extends TaskEditControlSet implements
if (!TextUtils.isEmpty(locationName))
return locationName;
return "Location is set";
return activity.getString(R.string.tr_default_location_name);
}
public boolean activityResult (int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_TASK_RABBIT_LOCATION && resultCode == Activity.RESULT_OK) {
int lng = data.getIntExtra("lng", 0);
int lat = data.getIntExtra("lat", 0);
locationName = data.getStringExtra("name");
location = new Location("");
int lng = data.getIntExtra(TaskRabbitActivity.CITY_LNG, 0);
int lat = data.getIntExtra(TaskRabbitActivity.CITY_LAT, 0);
locationName = data.getStringExtra(TaskRabbitActivity.CITY_NAME);
location = new Location(""); //$NON-NLS-1$
location.setLatitude(locationToDouble(lat));
location.setLongitude(locationToDouble(lng));
displayEdit.setText(getLocationText());
manualEntry = null;
getAddressFromLocation(location);
return true;
}
@ -143,27 +137,6 @@ public class TaskRabbitLocationControlSet extends TaskEditControlSet implements
return (int)(location * 1e6);
}
private void getAddressFromLocation(Location newLocation){
try {
Geocoder geocoder = new Geocoder(activity, Locale.getDefault());
// Acquire a reference to the system Location Manager
List<Address> addresses = geocoder.getFromLocation(newLocation.getLatitude(),
newLocation.getLongitude(), 1);
if (addresses != null){
for (Address address : addresses){
updateAddress(address);
}
}
} catch (Exception e) {
Log.d("Location error", e.toString());
}
}
private void updateAddress(Address address){
if(address.getLocality() != null && address.getPostalCode() != null){
locationName += "\n"+ (address.getLocality() + ", " + address.getPostalCode());
// currentAddress = address;
}
}
@Override
public void readFromModel(JSONObject json, String key, int mode) {
@ -184,12 +157,12 @@ public class TaskRabbitLocationControlSet extends TaskEditControlSet implements
@Override
public void postToTaskRabbit(JSONObject json, String key) throws JSONException {
JSONArray locations = json.optJSONArray("other_locations_attributes");
JSONArray locations = json.optJSONArray(TaskRabbitActivity.LOCATION_CONTAINER);
if (locations == null) {
locations = new JSONArray();
}
locations.put(getTaskLocation());
json.put("other_locations_attributes", locations);
json.put(TaskRabbitActivity.LOCATION_CONTAINER, locations);
}
@ -200,14 +173,14 @@ public class TaskRabbitLocationControlSet extends TaskEditControlSet implements
try {
JSONObject locationObject = new JSONObject();
if(!TextUtils.isEmpty(locationName)){
locationObject.put("name", locationName);
locationObject.put(TaskRabbitActivity.CITY_NAME, locationName);
}
else {
locationObject.put("name", displayText.getText().toString());
locationObject.put(TaskRabbitActivity.CITY_NAME, displayText.getText().toString());
}
if(location != null) {
locationObject.put("lng", location.getLongitude());
locationObject.put("lat", location.getLatitude());
locationObject.put(TaskRabbitActivity.CITY_LNG, location.getLongitude());
locationObject.put(TaskRabbitActivity.CITY_LAT, location.getLatitude());
}
return locationObject;
}

@ -5,8 +5,6 @@ import java.util.Locale;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.location.Address;
import android.location.Geocoder;
@ -16,9 +14,7 @@ import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
@ -36,7 +32,7 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
private MapView mapView;
private MapController mapController;
public Location location;
public Location currentLocation;
private EditText searchText;
private TaskRabbitMapOverlayItem currentOverlayItem;
private String locationAddress;
@ -76,10 +72,6 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
}
if ( !locationManager.isProviderEnabled( LocationManager.GPS_PROVIDER ) || !locationManager.isProviderEnabled( LocationManager.NETWORK_PROVIDER )) {
buildAlertMessageNoGps();
}
searchText=(EditText)findViewById(R.id.search_text);
@ -104,24 +96,6 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
}
}
private void buildAlertMessageNoGps() {
final AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("GPS needs to be enabled in order to add location based tasks. Do you want to enable it?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int id) {
startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int id) {
dialog.cancel();
}
});
final AlertDialog alert = builder.create();
alert.show();
}
private final Handler handler = new Handler() {
@ -137,8 +111,8 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
case -1:
AlertDialog.Builder adb = new AlertDialog.Builder(TaskRabbitMapActivity.this);
adb.setTitle("Google Map");
adb.setMessage("Please Provide the Proper Place");
adb.setTitle(getString(R.string.tr_alert_location_fail_title));
adb.setMessage(getString(R.string.tr_alert_location_fail_message));
adb.setPositiveButton("Close",null);
adb.show();
}
@ -201,8 +175,8 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
}
protected OverlayItem createOverlayItem(GeoPoint q) {
OverlayItem overlayitem = new OverlayItem(q, "Set this location",
"Use this location for TaskRabbit");
OverlayItem overlayitem = new OverlayItem(q, getString(R.string.tr_alert_location_clicked_title),
getString(R.string.tr_alert_location_clicked_message));
return overlayitem;
}
@ -217,14 +191,14 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
}
}
} catch (Exception e) {
Log.d("Location error", e.toString());
e.printStackTrace();
}
}
private void updateAddress(Address address){
if(address.getLocality() != null && address.getPostalCode() != null){
locationAddress = "";
locationAddress = ""; //$NON-NLS-1$
for (int i = 0; i < address.getMaxAddressLineIndex(); i++){
locationAddress += address.getAddressLine(i) + ", ";
locationAddress += address.getAddressLine(i) + ", "; //$NON-NLS-1$
}
}
}
@ -236,11 +210,11 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
}
private void updateLocationOverlay() {
if (location == null) { return; };
if (currentLocation == null) { return; };
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.icon_locale);
TaskRabbitMapOverlayItem myItemizedOverlay = new TaskRabbitMapOverlayItem(drawable);
GeoPoint point = new GeoPoint((int)(location.getLatitude() * 1E6), (int)(location.getLongitude() * 1E6));
GeoPoint point = new GeoPoint((int)(currentLocation.getLatitude() * 1E6), (int)(currentLocation.getLongitude() * 1E6));
OverlayItem overlayitem = createOverlayItem(point);
myItemizedOverlay.addOverlay(overlayitem);
@ -251,7 +225,7 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
if (location != null) {
double lat = location.getLatitude();
double lng = location.getLongitude();
this.location = location;
this.currentLocation = location;
GeoPoint p = new GeoPoint((int) lat * 1000000, (int) lng * 1000000);
updateLocationOverlay();
mapController.animateTo(p);

@ -12,6 +12,7 @@ import android.widget.RelativeLayout;
import com.google.android.maps.ItemizedOverlay;
import com.google.android.maps.OverlayItem;
import com.timsu.astrid.R;
public class TaskRabbitMapOverlayItem extends ItemizedOverlay<OverlayItem> {
private final ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
@ -64,7 +65,7 @@ public class TaskRabbitMapOverlayItem extends ItemizedOverlay<OverlayItem> {
}
selectedItem = mOverlays.get(index);
AlertDialog.Builder dialog = new AlertDialog.Builder(mActivity);
dialog.setTitle("Set this as your location?");
dialog.setTitle(mActivity.getString(R.string.tr_alert_location_clicked_title));
dialog.setMessage(selectedItem.getSnippet());
dialog.setIcon(
android.R.drawable.ic_dialog_alert).setPositiveButton(

@ -11,7 +11,6 @@ import android.content.Intent;
import android.graphics.Bitmap;
import android.text.TextUtils;
import android.util.Base64;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.view.inputmethod.InputMethodManager;
@ -38,7 +37,6 @@ public class TaskRabbitNameControlSet extends PopupControlSet implements TaskRab
private final ImageButton pictureButton;
private Bitmap pendingCommentPicture = null;
private int cameraButton;
public TaskRabbitNameControlSet(Activity activity, int viewLayout,
@ -82,7 +80,9 @@ public class TaskRabbitNameControlSet extends PopupControlSet implements TaskRab
json.put(key, editText.getText().toString());
}
@Override
@SuppressWarnings("nls")
public void postToTaskRabbit(JSONObject json, String key) throws JSONException {
String nameKey = activity.getString(R.string.tr_set_key_description);
if (key.equals(activity.getString(R.string.tr_set_key_name)) && json.has(nameKey)) {
@ -97,7 +97,6 @@ public class TaskRabbitNameControlSet extends PopupControlSet implements TaskRab
JSONObject pictureArray = new JSONObject();
pictureArray.put("image", picture);
json.put("uploaded_photos_attributes", new JSONObject().put("1", pictureArray));
Log.d("The task json", json.toString());
}
}
@ -119,7 +118,7 @@ public class TaskRabbitNameControlSet extends PopupControlSet implements TaskRab
editText.setHint(displayText.getText().toString());
return;
}
String value = json.optString(key, "");
String value = json.optString(key, ""); //$NON-NLS-1$
if (!TextUtils.isEmpty(value)) {
editText.setTextKeepState(value);
notesPreview.setText(value);
@ -134,7 +133,6 @@ public class TaskRabbitNameControlSet extends PopupControlSet implements TaskRab
CameraResultCallback callback = new CameraResultCallback() {
@Override
public void handleCameraResult(Bitmap bitmap) {
Log.d("CAMERA CLALLBACK", "PICTURE SHOULD BE SET");
pendingCommentPicture = bitmap;
pictureButton.setImageBitmap(pendingCommentPicture);
}
@ -154,6 +152,7 @@ public class TaskRabbitNameControlSet extends PopupControlSet implements TaskRab
@Override
public void readFromTask(Task task) {
//
}
@Override

@ -6,7 +6,6 @@ import org.json.JSONObject;
import android.app.Activity;
import android.content.res.TypedArray;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
@ -23,16 +22,14 @@ import com.todoroo.astrid.taskrabbit.TaskRabbitActivity.TaskRabbitSetListener;
public class TaskRabbitSpinnerControlSet extends TaskEditControlSet implements TaskRabbitSetListener{
private final Spinner spinner;
private final int setID;
private final int titleID;
private final TextView displayText;
private final TextView displayEdit;
private ArrayAdapter adapter;
private ArrayAdapter<String> adapter;
private final Activity activity;
public TaskRabbitSpinnerControlSet(final Activity activity, int viewLayout, int title, int setID) {
super(activity, viewLayout);
this.setID = setID;
this.titleID = title;
this.activity = activity;
// DependencyInjectionService.getInstance().inject(this);
@ -67,17 +64,15 @@ public class TaskRabbitSpinnerControlSet extends TaskEditControlSet implements T
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
Log.d("SELECTED ITEM", "SLECTED :" + arg2 + " ACTUAL: " + spinner.getSelectedItemPosition() + " STRING: " + spinner.getSelectedItem().toString());
displayEdit.setText(getDisplayEditText());
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
//
}
});
Log.d("SELECTED ITEM", " ACTUAL: " + spinner.getSelectedItemPosition());
getView().setOnClickListener(getDisplayClickListener());
}
@ -114,14 +109,12 @@ public class TaskRabbitSpinnerControlSet extends TaskEditControlSet implements T
@Override
public void onItemSelected(AdapterView<?> arg0, View arg1,
int arg2, long arg3) {
Log.d("SELECTED ITEM", "SLECTED :" + arg2 + " ACTUAL: " + spinner.getSelectedItemPosition() + " STRING: " + spinner.getSelectedItem().toString());
displayEdit.setText(getDisplayEditText());
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
//
}
});
}
@ -143,12 +136,10 @@ public class TaskRabbitSpinnerControlSet extends TaskEditControlSet implements T
}
int intValue = json.optInt(key, 0);
Log.d("iii", "" + spinner.getCount());
if (intValue < spinner.getCount()) {
spinner.setSelection(intValue);
displayEdit.setText(getDisplayEditText());
}
Log.d("dfhjskhfds", ""+intValue);
}
private String getDisplayEditText() {
@ -169,11 +160,12 @@ public class TaskRabbitSpinnerControlSet extends TaskEditControlSet implements T
int index = conversion.lastIndexOf('$');
String cents = conversion.substring(index+1);
if(TextUtils.isEmpty(cents)) return 0;
Log.d("PARSING TO CHANGE", cents);
return Integer.parseInt(cents);
}
@Override
@SuppressWarnings("nls")
public void postToTaskRabbit(JSONObject json, String key) throws JSONException {
if(spinner.getSelectedItem() != null){
@ -187,7 +179,7 @@ public class TaskRabbitSpinnerControlSet extends TaskEditControlSet implements T
}
else if (key.contains("description")) {
String description = json.optString("description", "");
description += String.format("\n%S %S", key, spinner.getSelectedItem().toString()); //$NON-NLS-1$
description += String.format("\n%S %S", key, spinner.getSelectedItem().toString());
}
else {
json.put(key, spinnerString);

@ -392,5 +392,38 @@
<item>$95</item>
</string-array>
<string name="tr_default_cost_in_cents_25_display">&lt; $25</string>
<string name="tr_default_cost_in_cents_50_display">&lt; $50</string>
<string name="tr_default_cost_in_cents_100_display">&lt; $100</string>
<string name="tr_default_cost_in_cents_101_display">&gt; $100</string>
<!-- Task Rabbit activity messages -->
<string name="tr_button_already_posted">Already Posted!</string>
<string name="tr_alert_title_fail">Error posting task</string>
<string name="tr_alert_message_fail">Please try again</string>
<string name="tr_alert_button_fail">Close</string>
<string name="tr_alert_gps_title">GPS needs to be enabled in order to add location based tasks. Do you want to enable it?</string>
<string name="tr_alert_gps_yes">Yes</string>
<string name="tr_alert_gps_no">No</string>
<string name="tr_default_location_name">Current Location</string>
<!-- Task Rabbit control set toast -->
<string name="tr_success_toast">Task posted to Task Rabbit successfully!</string>
<string name="tr_display_status">Task Rabbit Status</string>
<!-- Task Rabbit Map Activity -->
<string name="tr_alert_location_fail_title">No Location Found</string>
<string name="tr_alert_location_fail_message">Sorry, could not find the location for the address you entered</string>
<string name="tr_alert_location_clicked_title">Set this location</string>
<string name="tr_alert_location_clicked_message">Use this location for TaskRabbit</string>
</resources>
Loading…
Cancel
Save