Added new cities, changed task rabbit server error reporting, and saving data as a draft

pull/14/head
Andrew Shaw 13 years ago
parent 7973b55993
commit f7b2405e8a

@ -1,5 +1,6 @@
package com.todoroo.astrid.taskrabbit;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@ -28,6 +29,8 @@ import android.support.v4.app.ActionBar;
import android.support.v4.app.FragmentActivity;
import android.support.v4.view.MenuItem;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.util.Log;
import android.util.TypedValue;
import android.view.View;
import android.view.View.OnClickListener;
@ -110,6 +113,7 @@ public class TaskRabbitActivity extends FragmentActivity {
private TextView menuTitle;
private ListView menuList;
private ArrayAdapter<String> adapter;
private TaskRabbitLocationManager locationManager;
private int currentSelectedItem = 0;
@ -122,11 +126,18 @@ public class TaskRabbitActivity extends FragmentActivity {
public static final int REQUEST_CODE_TASK_RABBIT_OAUTH = 5;
public static final int REQUEST_CODE_ENABLE_GPS = 6;
public static final int MESSAGE_CODE_SUCCESS = 1;
public static final int MESSAGE_CODE_FAILURE = -1;
public static final int MESSAGE_CODE_INTERNET_FAILURE = -2;
public static final int MESSAGE_CODE_LOCATION_FAILURE = -3;
/** Act.fm current user name */
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_DIALOG_INTRO_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$
@ -139,9 +150,12 @@ public class TaskRabbitActivity extends FragmentActivity {
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 TASK_RABBIT_URL = "http://www.taskrabbit.com"; //$NON-NLS-1$
public static final String TASK_RABBIT_CLIENT_ID = "RZUDrMuGn9Q3dXeq4nL24bM6LZmMCi1CEGgfP4ND"; //$NON-NLS-1$
public static final String TASK_RABBIT_CLIENT_APPLICATION_ID = "Va7FUIUTprsmyuwAq9eHSZvAgiRj8FVH1zeaM8Zt"; //$NON-NLS-1$
// 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 TASK_RABBIT_ID = "id"; //$NON-NLS-1$
private TaskRabbitTaskContainer taskRabbitTask;
@ -172,27 +186,54 @@ public class TaskRabbitActivity extends FragmentActivity {
}
}
public void showIntroDialog() {
if (!Preferences.getBoolean(TASK_RABBIT_DIALOG_INTRO_PREF, false)) {
if (TaskRabbitLocationManager.supportsCurrentLocation(currentLocation)) {
AlertDialog.Builder adb = new AlertDialog.Builder(TaskRabbitActivity.this);
adb.setMessage(getString(R.string.tr_alert_intro_location));
adb.setPositiveButton(getString(R.string.tr_alert_button_close), new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, final int id) {
showAddListPopover();
}
});
adb.show();
}
else {
final AlertDialog adb = new AlertDialog.Builder(TaskRabbitActivity.this)
.setMessage(R.string.tr_alert_intro_no_location)
.setPositiveButton(getString(R.string.tr_alert_button_close),null)
.show();
((TextView) adb.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
}
Preferences.setBoolean(TASK_RABBIT_DIALOG_INTRO_PREF, true);
}
}
@Override
public void onResume() {
super.onResume();
StatisticsService.sessionStart(this);
populateFields();
showAddListPopover();
showIntroDialog();
}
@Override
public void onPause() {
super.onPause();
StatisticsService.sessionPause();
public void onDestroy() {
super.onDestroy();
try {
taskRabbitTask.setLocalTaskData(serializeToJSON().toString());
TaskRabbitDataService.getInstance().saveTaskAndMetadata(taskRabbitTask);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
protected void populateFields() {
loadItem(getIntent());
taskRabbitTask = TaskRabbitDataService.getInstance().getContainerForTask(model);
@ -527,6 +568,11 @@ public class TaskRabbitActivity extends FragmentActivity {
if(!Preferences.isSet(TASK_RABBIT_TOKEN)){
loginTaskRabbit();
}
else if (!supportsSelectedLocation()){
Message successMessage = new Message();
successMessage.what = MESSAGE_CODE_LOCATION_FAILURE;
handler.sendMessage(successMessage);
}
else {
@ -536,29 +582,39 @@ public class TaskRabbitActivity extends FragmentActivity {
new Thread(new Runnable() {
@Override
public void run() {
boolean success = true;
try {
String urlCall = "tasks/";
if (taskRabbitTask.getTaskID() > 0) urlCall += taskRabbitTask.getTaskID();
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");
boolean success = false;
String response = restClient.post(taskRabbitURL(urlCall), getTaskBody(), contentType, authorization);
String urlCall = "tasks/";
if (taskRabbitTask.getTaskID() > 0) urlCall += taskRabbitTask.getTaskID();
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");
HttpEntity taskBody = getTaskBody();
String response = null;
try {
response = restClient.post(taskRabbitURL(urlCall), taskBody, contentType, authorization);
Log.e("The response", "The post response: " + response);
JSONObject taskResponse = new JSONObject(response);
if(taskResponse.has(TASK_RABBIT_ID)){
taskRabbitTask.setRemoteTaskData(response);
taskRabbitTask.setTaskID(taskResponse.optString(TASK_RABBIT_ID));
Message successMessage = new Message();
successMessage.what = 1;
successMessage.what = MESSAGE_CODE_SUCCESS;
handler.sendMessage(successMessage);
success = true;
}
}
catch (UnknownHostException e) {
Message failureMessage = new Message();
failureMessage.what = MESSAGE_CODE_INTERNET_FAILURE;
handler.sendMessage(failureMessage);
}
catch (Exception e){
Message failureMessage = new Message();
failureMessage.what = -1;
failureMessage.what = MESSAGE_CODE_FAILURE;
handler.sendMessage(failureMessage);
success = false;
}
finally {
StatisticsService.reportEvent(StatisticsConstants.TASK_RABBIT_POST, "success", new Boolean(success).toString());
@ -588,25 +644,45 @@ public class TaskRabbitActivity extends FragmentActivity {
@Override
public void handleMessage(Message msg) {
String alertMessage = null;
switch (msg.what) {
case -1:
AlertDialog.Builder adb = new AlertDialog.Builder(TaskRabbitActivity.this);
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();
case MESSAGE_CODE_FAILURE:
{
alertMessage = getString(R.string.tr_alert_message_fail);
break;
case 0: break;
case 1:
}
case MESSAGE_CODE_INTERNET_FAILURE:
{
alertMessage = getString(R.string.tr_alert_internet_message_fail);
break;
}
case MESSAGE_CODE_LOCATION_FAILURE:
{
final AlertDialog adb = new AlertDialog.Builder(TaskRabbitActivity.this)
.setMessage(R.string.tr_alert_location_not_supported_message)
.setPositiveButton(getString(R.string.tr_alert_button_close),null)
.show();
((TextView) adb.findViewById(android.R.id.message)).setMovementMethod(LinkMovementMethod.getInstance());
return;
}
case MESSAGE_CODE_SUCCESS:
{
TaskRabbitDataService.getInstance().saveTaskAndMetadata(taskRabbitTask);
Intent data = new Intent();
data.putExtra(TaskRabbitControlSet.DATA_RESPONSE, taskRabbitTask.getRemoteTaskData().toString());
TaskRabbitActivity.this.setResult(Activity.RESULT_OK, data);
TaskRabbitActivity.this.finish();
break;
return;
}
}
AlertDialog.Builder adb = new AlertDialog.Builder(TaskRabbitActivity.this);
adb.setTitle(getString(R.string.tr_alert_title_fail));
adb.setMessage(alertMessage);
adb.setPositiveButton(getString(R.string.tr_alert_button_close),null);
adb.show();
}
};
@ -625,30 +701,26 @@ public class TaskRabbitActivity extends FragmentActivity {
}
}
private void loadLocation() {
TaskRabbitLocationManager locationManager = new TaskRabbitLocationManager(this);
if ( !locationManager.isLocationUpdatesEnabled()) {
buildAlertMessageNoGps();
if (locationManager == null) {
locationManager = new TaskRabbitLocationManager(this);
if ( !locationManager.isLocationUpdatesEnabled()) {
buildAlertMessageNoGps();
}
}
else {
currentLocation = locationManager.getLastKnownLocation();
if (currentLocation == null) {
locationManager.getLocation(new LocationResult(){
@Override
public void gotLocation(final Location location){
//Got the location!
currentLocation = location;
updateControlSetLocation(currentLocation);
setupListView();
}
currentLocation = locationManager.getLastKnownLocation();
if (currentLocation == null) {
locationManager.getLocation(new LocationResult(){
@Override
public void gotLocation(final Location location){
//Got the location!
currentLocation = location;
updateControlSetLocation(currentLocation);
}
);
}
else {
updateControlSetLocation(currentLocation);
}
);
}
else {
updateControlSetLocation(currentLocation);
}
}
@ -719,7 +791,6 @@ public class TaskRabbitActivity extends FragmentActivity {
else if (requestCode == REQUEST_CODE_ENABLE_GPS) {
loadLocation();
setupListView();
}
else {
@ -743,6 +814,21 @@ public class TaskRabbitActivity extends FragmentActivity {
}
/* location calls */
private boolean supportsSelectedLocation() {
for (TaskRabbitSetListener controlSet : controls) {
if (TaskRabbitLocationControlSet.class.isAssignableFrom(controlSet.getClass())) {
TaskRabbitLocationControlSet locationControlSet = (TaskRabbitLocationControlSet) controlSet;
if(!TaskRabbitLocationManager.supportsCurrentLocation(locationControlSet.location) && locationControlSet.getDisplayView().getParent() != null) {
return false;
}
}
}
return true;
}
public void updateControlSetLocation (Location location) {
for (TaskRabbitSetListener controlSet : controls) {
if (TaskRabbitLocationControlSet.class.isAssignableFrom(controlSet.getClass())) {
@ -795,34 +881,27 @@ public class TaskRabbitActivity extends FragmentActivity {
private void setupListView() {
String[] keys = getResources().getStringArray(R.array.tr_preset_types);
boolean locationEnabled = getIntent().getBooleanExtra(TaskRabbitControlSet.LOCATION_ENABLED, false);
if (!locationEnabled && !TaskRabbitLocationManager.supportsCurrentLocation(currentLocation)) {
keys = new String[]{ getResources().getString(R.string.tr_type_virtual)};
}
if (adapter == null) {
adapter = new ArrayAdapter<String>(this, R.layout.task_rabbit_menu_row, keys);
menuList = new ListView(this);
menuList.setAdapter(adapter);
menuList.setCacheColorHint(Color.TRANSPARENT);
adapter = new ArrayAdapter<String>(this, R.layout.task_rabbit_menu_row, keys);
menuList = new ListView(this);
menuList.setAdapter(adapter);
menuList.setCacheColorHint(Color.TRANSPARENT);
menuList.setSelection(0);
menuList.setOnItemClickListener(new OnItemClickListener() {
menuList.setSelection(0);
menuList.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
currentSelectedItem = position;
displayViewsForMode(position);
menuPopover.dismiss();
}
});
@Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
currentSelectedItem = position;
displayViewsForMode(position);
menuPopover.dismiss();
}
});
}
else {
adapter = new ArrayAdapter<String>(this, R.layout.task_rabbit_menu_row, keys);
menuList.setAdapter(adapter);
/*adapter.clear();
adapter.addAll(keys);
adapter.notifyDataSetChanged();*/
}
}

@ -27,7 +27,6 @@ import com.todoroo.astrid.actfm.OAuthLoginActivity;
import com.todoroo.astrid.activity.TaskEditFragment;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.helper.TaskEditControlSet;
import com.todoroo.astrid.taskrabbit.TaskRabbitLocationManager.LocationResult;
public class TaskRabbitControlSet extends TaskEditControlSet implements AssignedChangedListener {
@ -83,8 +82,7 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
protected void refreshDisplayView() {
JSONObject remoteData = taskRabbitTask.getRemoteTaskData();
if (remoteData != null)
updateDisplay(remoteData);
updateDisplay(remoteData);
}
@ -136,10 +134,8 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
private void updateTaskRow(TaskRabbitTaskContainer container) {
displayText.setText(fragment.getString(R.string.tr_display_status));
JSONObject remoteData = container.getRemoteTaskData();
if (remoteData != null) {
updateDisplay(remoteData);
updateStatus(remoteData);
}
updateDisplay(remoteData);
updateStatus(remoteData);
}
/* message callbacks */
@ -180,19 +176,24 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
}
public boolean activityResult (int requestCode, int resultCode, Intent data) {
if (requestCode == REQUEST_CODE_TASK_RABBIT_ACTIVITY && resultCode == Activity.RESULT_OK){
String result = data.getStringExtra(OAuthLoginActivity.DATA_RESPONSE);
if (!TextUtils.isEmpty(result)) {
try {
Message successMessage = new Message();
successMessage.what = 1;
handler.sendMessageDelayed(successMessage, 500);
}
catch (Exception e){
e.printStackTrace();
if (requestCode == REQUEST_CODE_TASK_RABBIT_ACTIVITY ){
if (resultCode == Activity.RESULT_OK) {
String result = data.getStringExtra(OAuthLoginActivity.DATA_RESPONSE);
if (!TextUtils.isEmpty(result)) {
try {
Message successMessage = new Message();
successMessage.what = 1;
handler.sendMessageDelayed(successMessage, 500);
return true;
}
catch (Exception e){
e.printStackTrace();
}
}
}
else {
updateDisplay(null);
}
return true;
}
return false;
@ -211,6 +212,11 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
statusText.setText(status);
getDisplayView().setVisibility(View.VISIBLE);
}
else if (taskRabbitTask.getLocalTaskData() != null) {
TextView statusText = (TextView) getDisplayView().findViewById(R.id.display_row_edit);
statusText.setText(fragment.getActivity().getString(R.string.tr_status_draft));
getDisplayView().setVisibility(View.VISIBLE);
}
else {
getDisplayView().setVisibility(View.GONE);
}
@ -219,6 +225,8 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
protected void updateStatus(JSONObject json){
if (json == null) return;
final long taskID = json.optLong(TaskRabbitActivity.TASK_RABBIT_ID);
if (taskID == TaskRabbitTaskContainer.NO_ID) return;
new Thread(new Runnable() {
@ -258,32 +266,13 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
return false;
}
private void loadLocation() {
locationManager = new TaskRabbitLocationManager(fragment.getActivity());
currentLocation = locationManager.getLastKnownLocation();
if (currentLocation == null) {
locationManager.getLocation(new LocationResult(){
@Override
public void gotLocation(final Location location){
//Got the location!
currentLocation = location;
isEnabledForTRLocation = TaskRabbitLocationManager.supportsCurrentLocation(currentLocation);
}
}
);
} else {
isEnabledForTRLocation = TaskRabbitLocationManager.supportsCurrentLocation(currentLocation);
}
isEnabledForTRLocation = TaskRabbitLocationManager.supportsCurrentLocation(currentLocation);
}
@Override
public boolean didPostToTaskRabbit() {
if (taskRabbitTask == null) return false;

@ -55,7 +55,6 @@ public final class TaskRabbitDataService {
*/
public void saveTaskAndMetadata(TaskRabbitTaskContainer task) {
taskDao.save(task.task);
task.metadata.add(task.trTask);
// note we don't include note metadata, since we only receive deltas
metadataService.synchronizeMetadata(task.task.getId(), task.metadata,

@ -27,12 +27,16 @@ public class TaskRabbitLocationManager {
}
private static final GeoPoint[] supportedLocations = {
new GeoPoint(42358430, -71059770), //
new GeoPoint(37739230, -122439880),
new GeoPoint(40714350, -74005970),
new GeoPoint(41878110, -8762980),
new GeoPoint(34052230, -118243680),
new GeoPoint(33717470, -117831140)
new GeoPoint(42358430, -71059770), //BOS
new GeoPoint(37739230, -122439880), //SF
new GeoPoint(40714350, -74005970), //NYC
new GeoPoint(41878110, -87629800), //CHI
new GeoPoint(34052230, -118243680), //LA
new GeoPoint(33717470, -117831140), //OC
new GeoPoint(30267150, -97743060), //AUSTIN
new GeoPoint(45523450, -122676210), //PORTLAND
new GeoPoint(47606210, -122332070), //SEA
new GeoPoint(29424120, -98493630) //SAN ANTONIO
};
public boolean isLocationUpdatesEnabled() {
boolean provider_enabled=false;

@ -3,8 +3,11 @@ import java.io.IOException;
import java.util.List;
import java.util.Locale;
import android.app.Activity;
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;
@ -36,6 +39,9 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
private EditText searchText;
private TaskRabbitMapOverlayItem currentOverlayItem;
private String locationAddress;
private static final int LOCATION_SEARCH_SUCCESS = 1;
private static final int LOCATION_SEARCH_FAIL = -1;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
@ -60,12 +66,12 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
mapController = mapView.getController();
if(lastKnownLocation != null) {
point = new GeoPoint((int)(lastKnownLocation.getLatitude()*1E6),(int)(lastKnownLocation.getLongitude()*1E6));
point = locationToGeoPoint(lastKnownLocation);
OverlayItem overlayitem = createOverlayItem(point);
currentOverlayItem.addOverlay(overlayitem);
mapOverlays.add(currentOverlayItem);
getAddressFromLocation(lastKnownLocation);
locationAddress = getAddressFromLocation(lastKnownLocation);
mapController.animateTo(point);
mapController.setZoom(17);
mapView.invalidate();
@ -87,6 +93,7 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
}
public String getSearchText() {
return searchText.getText().toString();
}
@ -102,13 +109,13 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case 1:
case LOCATION_SEARCH_SUCCESS:
mapView.invalidate();
currentOverlayItem.onTap(0);
// What to do when ready, example:
break;
case -1:
case LOCATION_SEARCH_FAIL:
AlertDialog.Builder adb = new AlertDialog.Builder(TaskRabbitMapActivity.this);
adb.setTitle(getString(R.string.tr_alert_location_fail_title));
@ -157,12 +164,12 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
mapOverlays.add(currentOverlayItem);
Message successMessage = new Message();
successMessage.what = 1;
successMessage.what = LOCATION_SEARCH_SUCCESS;
handler.sendMessage(successMessage);
} else {
Message failureMessage = new Message();
failureMessage.what = -1;
failureMessage.what = LOCATION_SEARCH_FAIL;
handler.sendMessage(failureMessage);
}
@ -180,27 +187,30 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
return overlayitem;
}
private void getAddressFromLocation(Location location){
public String getAddressFromLocation(Location location){
try {
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
// Acquire a reference to the system Location Manager
List<Address> addresses = geocoder.getFromLocation(location.getLatitude(), location.getLongitude(), 1);
if (addresses != null){
for (Address address : addresses){
updateAddress(address);
return updateAddress(address);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return "";
}
private void updateAddress(Address address){
private String updateAddress(Address address){
String addressString = null;
if(address.getLocality() != null && address.getPostalCode() != null){
locationAddress = ""; //$NON-NLS-1$
addressString = ""; //$NON-NLS-1$
for (int i = 0; i < address.getMaxAddressLineIndex(); i++){
locationAddress += address.getAddressLine(i) + ", "; //$NON-NLS-1$
addressString += address.getAddressLine(i) + ", "; //$NON-NLS-1$
}
}
return addressString;
}
@ -220,6 +230,43 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
myItemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(myItemizedOverlay);
}
public void didSelectItem (final OverlayItem selectedItem) {
AlertDialog.Builder dialogPrompt = new AlertDialog.Builder(this);
dialogPrompt.setTitle(getString(R.string.tr_alert_location_clicked_title));
Location location = geoPointToLocation(selectedItem.getPoint());
locationAddress = getAddressFromLocation(location);
setSearchTextForCurrentAddress();
dialogPrompt.setMessage(locationAddress);
dialogPrompt.setIcon(
android.R.drawable.ic_dialog_alert).setPositiveButton(
android.R.string.ok, new DialogInterface.OnClickListener() {
@SuppressWarnings("nls")
public void onClick(DialogInterface dialog, int which) {
Intent data = new Intent();
data.putExtra("lat",selectedItem.getPoint().getLatitudeE6());
data.putExtra("lng",selectedItem.getPoint().getLongitudeE6());
data.putExtra("name", getSearchText());
setResult(Activity.RESULT_OK, data);
finish();
}
}).setNegativeButton(android.R.string.cancel, null);
dialogPrompt.show();
}
private Location geoPointToLocation(GeoPoint geoPoint) {
Location location = new Location("");
location.setLatitude(((long)geoPoint.getLatitudeE6())/1E6);
location.setLongitude(((long)geoPoint.getLongitudeE6())/1E6);
return location;
}
private GeoPoint locationToGeoPoint(Location lastKnownLocation) {
GeoPoint point = new GeoPoint((int)(lastKnownLocation.getLatitude()*1E6),(int)(lastKnownLocation.getLongitude()*1E6));
return point;
}
@Override
public void onLocationChanged(Location location) {
if (location != null) {
@ -232,6 +279,7 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
}
}
@Override
public void onProviderDisabled(String provider) {
//

@ -2,17 +2,12 @@ package com.todoroo.astrid.taskrabbit;
import java.util.ArrayList;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.widget.ImageView;
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>();
@ -58,33 +53,18 @@ public class TaskRabbitMapOverlayItem extends ItemizedOverlay<OverlayItem> {
public int size() {
return mOverlays.size();
}
@Override
protected boolean onTap(int index) {
if (index >= mOverlays.size()) {
return false;
}
selectedItem = mOverlays.get(index);
AlertDialog.Builder dialogPrompt = new AlertDialog.Builder(mActivity);
dialogPrompt.setTitle(mActivity.getString(R.string.tr_alert_location_clicked_title));
dialogPrompt.setMessage(selectedItem.getSnippet());
dialogPrompt.setIcon(
android.R.drawable.ic_dialog_alert).setPositiveButton(
android.R.string.ok, new DialogInterface.OnClickListener() {
@SuppressWarnings("nls")
public void onClick(DialogInterface dialog, int which) {
Intent data = new Intent();
data.putExtra("lat",selectedItem.getPoint().getLatitudeE6());
data.putExtra("lng",selectedItem.getPoint().getLongitudeE6());
data.putExtra("name",mActivity.getSearchText());
mActivity.setResult(Activity.RESULT_OK, data);
mActivity.finish();
}
}).setNegativeButton(android.R.string.cancel, null);
dialogPrompt.show();
mActivity.setSearchTextForCurrentAddress();
mActivity.didSelectItem(selectedItem);
return true;
}
}

@ -403,27 +403,40 @@
<!-- Task Rabbit activity messages -->
<string name="tr_button_already_posted">Already Posted!</string>
<string name="tr_status_draft">draft</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_button_close">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_alert_internet_message_fail">Internet connection could not be found. Please check your connection and try again.</string>
<string name="tr_alert_intro_location">TaskRabbit is an inexpensive way to delegate tasks to trust-worthy people in your area.</string>
<string name="tr_alert_intro_no_location">TaskRabbit is an inexpensive way to delegate tasks to trust-worthy people but it isn\'t yet available in your location. You can use it to assign virtual tasks or tasks in <a href="http://www.taskrabbit.com/pickacity">supported locations</a></string>
<string name="tr_alert_location_not_supported_title">Location not supported</string>
<string name="tr_alert_location_not_supported_message">TaskRabbit isn\'t yet supported in your current location. Please choose a <a href="http://www.taskrabbit.com/pickacity">supported location</a> or set type to virtual before posting this task</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>
<string name="tr_success_toast">Task posted to TaskRabbit successfully!</string>
<string name="tr_display_status">TaskRabbit 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_title">Use this location</string>
<string name="tr_alert_location_clicked_message">Use this location for TaskRabbit</string>
</resources>

@ -316,14 +316,14 @@ public class WebServicesView extends LinearLayout {
int lowestNew = Integer.MAX_VALUE;
try {
lowestNew = attributes.containsKey("lowestNew") ?
Integer.parseInt(attributes.get("lowestNew")) : Integer.MAX_VALUE;
Integer.parseInt(attributes.get("lowestNew")) : Integer.MAX_VALUE;
} catch (NumberFormatException e) {
// text, i.e. "too low to display"
}
int lowestUsed = Integer.MAX_VALUE;
try {
lowestUsed = attributes.containsKey("lowestUsed") ?
Integer.parseInt(attributes.get("lowestUsed")) : Integer.MAX_VALUE;
Integer.parseInt(attributes.get("lowestUsed")) : Integer.MAX_VALUE;
} catch (NumberFormatException e) {
// text, i.e. "too low to display"
}
@ -379,12 +379,12 @@ public class WebServicesView extends LinearLayout {
public void run() {
try {
String url = GOOGLE_SEARCH_URL +
URLEncoder.encode(task.getValue(Task.TITLE), "UTF-8");
URLEncoder.encode(task.getValue(Task.TITLE), "UTF-8");
String result = restClient.get(url);
final JSONObject searchResults = new JSONObject(result);
activity.runOnUiThread(new GoogleSearchResultsProcessor(body,
searchResults.getJSONObject("responseData")));
searchResults.getJSONObject("responseData")));
} catch (Exception e) {
displayError(e, body);
@ -442,31 +442,31 @@ public class WebServicesView extends LinearLayout {
protected void initializeTaskRabbit() {
if(taskRabbitControl != null && taskRabbitControl.isEnabledForTRLocation == true) {
addSectionHeader("Outsource this task to someone");
addSectionHeader("Outsource this task to someone");
final LinearLayout body = new LinearLayout(activity);
body.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
final LinearLayout body = new LinearLayout(activity);
body.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
ROW_HEIGHT));
body.setOrientation(LinearLayout.VERTICAL);
body.setOrientation(LinearLayout.VERTICAL);
ImageView imageView = new ImageView(getContext());
imageView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
ROW_HEIGHT));
imageView.setImageResource(R.drawable.task_rabbit_logo);
imageView.setScaleType(ScaleType.CENTER_INSIDE);
body.addView(imageView);
ImageView imageView = new ImageView(getContext());
imageView.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
ROW_HEIGHT));
imageView.setImageResource(R.drawable.task_rabbit_logo);
imageView.setScaleType(ScaleType.CENTER_INSIDE);
body.addView(imageView);
body.setOnClickListener(new OnClickListener() {
body.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
taskRabbitControl.showTaskRabbitActivity();
@Override
public void onClick(View v) {
taskRabbitControl.showTaskRabbitActivity();
}
});
addView(body);
addSectionDivider();
}
});
addView(body);
addSectionDivider();
}

Loading…
Cancel
Save