TaskRabbit code warnings and comments cleanup

pull/14/head
Tim Su 13 years ago
parent 65ccfbe127
commit 410ebab943

@ -183,13 +183,11 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
super.onPause();
StatisticsService.sessionPause();
// if (shouldSaveState)
try {
taskRabbitTask.setLocalTaskData(serializeToJSON().toString());
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
taskRabbitTask.setLocalTaskData(serializeToJSON().toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
protected void populateFields() {
@ -294,7 +292,6 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
try {
descriptionControlSet.readFromModel(new JSONObject().put("description", model.getValue(Task.NOTES)), "description", currentSelectedItem);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
controls.add(descriptionControlSet);
@ -483,9 +480,7 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
}
parameters.put(getString(R.string.tr_set_key_name), taskTitle.getText().toString());
parameters.put(getString(R.string.tr_set_key_name), taskTitle.getText().toString());
// parameters.put(activity.getString(R.string.tr_set_key_type), menuList.getSelectedItem().toString());
Log.d("THE TAK JSON IS", parameters.toString());
return new JSONObject().put("task", parameters);
}

@ -6,9 +6,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Location;
import android.location.LocationListener;
@ -16,18 +14,16 @@ import android.location.LocationManager;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.provider.Settings;
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.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.maps.GeoPoint;
import com.timsu.astrid.R;
import com.timsu.astrid.data.location.GeoPoint;
import com.todoroo.andlib.service.Autowired;
import com.todoroo.andlib.service.DependencyInjectionService;
import com.todoroo.andlib.service.RestClient;
@ -38,9 +34,12 @@ 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 {
private static final int RADIUS_250_MILES = 400000;
public interface TaskRabbitSetListener {
public void readFromModel(JSONObject json, String key);
public void saveToJSON(JSONObject json, String key) throws JSONException;
@ -52,33 +51,27 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
}
/** task model */
Task model = null;
private Task model = null;
@Autowired
private RestClient restClient;
/** true if editing started with a new task */
private final boolean isNewTask = false;
private Location currentLocation;
public boolean isEnabledForTRLocation = false;
public static final String LOCATION_ENABLED = "location_enabled"; //$NON-NLS-1$
GeoPoint[] supportedLocations =
{
private 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(33717470, -117831140)
};
private final Fragment fragment;
private LinearLayout row;
protected final TextView displayText;
LocationManager locationManager;
private LocationManager locationManager;
public static final int REQUEST_CODE_TASK_RABBIT_ACTIVITY = 5;
public static final String DATA_RESPONSE = "response"; //$NON-NLS-1$
@ -104,11 +97,6 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
loadLocation();
}
protected void refreshDisplayView() {
JSONObject remoteData = taskRabbitTask.getRemoteTaskData();
if (remoteData != null)
@ -141,7 +129,6 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
@Override
public String writeToModel(Task task) {
// TaskRabbitDataService.getInstance().saveTaskAndMetadata(taskRabbitTask);
return null;
}
@ -155,8 +142,6 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
}
}
/* message callbacks */
/**
* Show toast for task edit canceling
@ -180,26 +165,6 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
}
};
private void buildAlertMessageNoGps() {
final AlertDialog.Builder builder = new AlertDialog.Builder(fragment.getActivity());
builder.setMessage("Yout GPS seems to be disabled, do you want to enable it?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(@SuppressWarnings("unused") final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
fragment.getActivity().startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(final DialogInterface dialog, @SuppressWarnings("unused") final int id) {
dialog.cancel();
}
});
final AlertDialog alert = builder.create();
alert.show();
}
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);
}
@ -207,7 +172,6 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
/** Fire task rabbit if assigned **/
@Override
public boolean showTaskRabbitForUser(String name, JSONObject json) {
// TODO Auto-generated method stub
if (name.equals(fragment.getActivity().getString(R.string.actfm_EPA_task_rabbit))) {
showTaskRabbitActivity();
return true;
@ -261,9 +225,7 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
public void run() {
try {
Log.d("Tasks url:", taskRabbitURL("tasks/" + taskID + "?client_id=" + TaskRabbitActivity.TASK_RABBIT_CLIENT_ID));
String response = restClient.get(taskRabbitURL("tasks/" + taskID));
Log.d("Task rabbit response", response);
JSONObject taskResponse = new JSONObject(response);
if(taskResponse.has("id")){
taskRabbitTask.setRemoteTaskData(response);
@ -298,12 +260,11 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
private void loadLocation() {
Log.d("TRControlSet", "gJgHFDSJKGFHSJKFGHDSJKFGSJDGFSDJKFGDSJKFGSHJDFHS:LDFHS:FJKSDJFL:");
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);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
}
else {
Log.d("TRControlSet", "loading location and checking if we suppor it");
@ -312,16 +273,13 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
}
public boolean supportsCurrentLocation() {
//TODO test this
if (currentLocation == null) return false;
for (GeoPoint point : supportedLocations){
Log.d("TRControlSet", "Searching if we support current location");
Location city = new Location(""); //$NON-NLS-1$
Location city = new Location("");
city.setLatitude(point.getLatitudeE6()/1E6);
city.setLongitude(point.getLongitudeE6()/1E6);
float distance = currentLocation.distanceTo(city);
if (distance < 400000) { //250 mi radius
if (distance < RADIUS_250_MILES) {
return true;
}
}
@ -341,26 +299,24 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
locationManager = null;
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
//
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
//
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
//
}
@Override
public boolean didPostToTaskRabbit() {
if (taskRabbitTask == null) return false;

@ -24,9 +24,9 @@ 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 int setID;
private final TextView displayText;
private final TextView displayEdit;
private final Activity activity;
@ -37,9 +37,7 @@ public class TaskRabbitLocationControlSet extends TaskEditControlSet implements
public TaskRabbitLocationControlSet(final Activity activity , int viewLayout, int title, int setID) {
super(activity, viewLayout);
this.setID = setID;
this.activity = activity;
// DependencyInjectionService.getInstance().inject(this);
REQUEST_CODE_TASK_RABBIT_LOCATION += setID;
displayText = (TextView) getDisplayView().findViewById(R.id.display_row_title);
@ -103,13 +101,12 @@ public class TaskRabbitLocationControlSet extends TaskEditControlSet implements
return (int)(location * 1e6);
}
private void getAddressFromLocation(Location location){
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(location.getLatitude(), location.getLongitude(), 1);
List<Address> addresses = geocoder.getFromLocation(newLocation.getLatitude(),
newLocation.getLongitude(), 1);
if (addresses != null){
for (Address address : addresses){
updateAddress(address);
@ -154,7 +151,6 @@ public class TaskRabbitLocationControlSet extends TaskEditControlSet implements
}
private JSONObject getTaskLocation() {
try {
@ -177,13 +173,12 @@ public class TaskRabbitLocationControlSet extends TaskEditControlSet implements
return null;
}
//don't need these
//don't need these
@Override
public void readFromTask(Task task) {
//
}
@Override
public String writeToModel(Task task) {
return null;

@ -99,88 +99,5 @@ public class TaskRabbitMapOverlayItem extends ItemizedOverlay {
return true;
}
/*
@Override
public boolean onTouchEvent(MotionEvent event, MapView mapView) {
final int action=event.getAction();
final int x=(int)event.getX();
final int y=(int)event.getY();
boolean result=false;
if (action==MotionEvent.ACTION_DOWN) {
for (int i = 0; i < mOverlays.size(); i++) {
OverlayItem item = mOverlays.get(i);
Point p= new Point(0,0);
mapView.getProjection().toPixels(item.getPoint(), p);
if (hitTest(item, defaultMarker, x-p.x, y-p.y)) {
didTap = i;
tapPoint = new Point((int) event.getX(), (int) event.getY());
result=true;
inDrag=item;
mOverlays.remove(inDrag);
populate();
xDragTouchOffset=0;
yDragTouchOffset=0;
setDragImagePosition(p.x, p.y);
// dragImage.setVisibility(View.VISIBLE);
xDragTouchOffset=x-p.x;
yDragTouchOffset=y-p.y;
break;
}
}
}
else if (action==MotionEvent.ACTION_MOVE && inDrag!=null) {
setDragImagePosition(x, y);
if (tapPoint != null && Math.abs(tapPoint.x - event.getX()) > 10 && Math.abs(tapPoint.x - event.getX()) > 10) {
didTap = -1;
}
result=true;
}
else if (action==MotionEvent.ACTION_UP && inDrag!=null) {
// dragImage.setVisibility(View.GONE);
if (didTap != -1) {
this.onTap(didTap);
didTap = -1;
return true;
}
GeoPoint pt=mapView.getProjection().fromPixels(x-xDragTouchOffset,
y-yDragTouchOffset);
OverlayItem toDrop=new OverlayItem(pt, inDrag.getTitle(),
inDrag.getSnippet());
mOverlays.add(toDrop);
populate();
inDrag=null;
result=true;
}
return(result || super.onTouchEvent(event, mapView));
}
private void setDragImagePosition(int x, int y) {
getDragImage();
RelativeLayout.LayoutParams lp=
(RelativeLayout.LayoutParams)dragImage.getLayoutParams();
if (lp != null) {
lp.setMargins(x-xDragImageOffset-xDragTouchOffset,
y-yDragImageOffset-yDragTouchOffset, 0, 0);
}
dragImage.setLayoutParams(lp);
}
*/
}

Loading…
Cancel
Save