Create an alternate dialog if user isn't on a Google Maps enabled device

pull/14/head
Tim Su 13 years ago
parent 410ebab943
commit 572296e023

@ -631,10 +631,8 @@
android:windowSoftInputMode="stateHidden"
android:screenOrientation="portrait"></activity>
<!-- Uses Library -->
<uses-library android:name="com.google.android.maps" />
<!-- Uses Library -->
<uses-library android:name="com.google.android.maps" android:required="false" />
</application>

@ -77,8 +77,8 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
public interface TaskRabbitSetListener {
public void readFromModel(JSONObject json, String key, int mode);
public void saveToJSON(JSONObject json, String key) throws JSONException;
public void writeToJSON(JSONObject json, String key) throws JSONException;
public void saveToDatabase(JSONObject json, String key) throws JSONException;
public void postToTaskRabbit(JSONObject json, String key) throws JSONException;
}
public interface ActivityResultSetListener {
@ -430,7 +430,7 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
return;
}
if(taskRabbitTask.getTaskID() > 0) {
if(taskRabbitTask.getTaskID() != TaskRabbitTaskContainer.NO_ID) {
taskButton.setText("Already Posted!");
taskButton.setEnabled(false);
}
@ -472,7 +472,7 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
for (int i = 0; i < controls.size(); i++) {
if (presetValues[i] == -1) continue;
TaskRabbitSetListener set = controls.get(i);
set.writeToJSON(parameters, keys[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));
@ -498,7 +498,7 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
String[] keys = getResources().getStringArray(R.array.tr_default_set_key);
for (int i = 0; i < controls.size(); i++) {
TaskRabbitSetListener set = controls.get(i);
set.saveToJSON(parameters, keys[i]);
set.saveToDatabase(parameters, keys[i]);
}
parameters.put(getString(R.string.tr_set_key_type), currentSelectedItem);
parameters.put(getString(R.string.tr_set_key_name), taskTitle.getText().toString());
@ -636,7 +636,8 @@ public class TaskRabbitActivity extends FragmentActivity implements LocationList
private void loadLocation() {
LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
if ( !locationManager.isProviderEnabled( LocationManager.GPS_PROVIDER ) || !locationManager.isProviderEnabled( LocationManager.NETWORK_PROVIDER )) {
if ( !locationManager.isProviderEnabled( LocationManager.GPS_PROVIDER ) &&
!locationManager.isProviderEnabled( LocationManager.NETWORK_PROVIDER )) {
buildAlertMessageNoGps();
}

@ -291,7 +291,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();
@ -320,7 +319,7 @@ public class TaskRabbitControlSet extends TaskEditControlSet implements Assigned
@Override
public boolean didPostToTaskRabbit() {
if (taskRabbitTask == null) return false;
return taskRabbitTask.getTaskID() > 0;
return taskRabbitTask.getTaskID() != TaskRabbitTaskContainer.NO_ID;
}

@ -85,13 +85,13 @@ public class TaskRabbitDeadlineControlSet extends PopupControlSet implements Tas
@Override
public void saveToJSON(JSONObject json, String key) throws JSONException {
public void saveToDatabase(JSONObject json, String key) throws JSONException {
json.put(key, dateAndTimePicker.constructDueDate());
}
@Override
public void writeToJSON(JSONObject json, String key) throws JSONException {
public void postToTaskRabbit(JSONObject json, String key) throws JSONException {
long dueDate = dateAndTimePicker.constructDueDate();
json.put(key, dueDate);
}

@ -1,5 +1,6 @@
package com.todoroo.astrid.taskrabbit;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
@ -8,6 +9,7 @@ import org.json.JSONException;
import org.json.JSONObject;
import android.app.Activity;
import android.content.DialogInterface;
import android.content.Intent;
import android.location.Address;
import android.location.Geocoder;
@ -16,9 +18,13 @@ import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup.LayoutParams;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.timsu.astrid.R;
import com.todoroo.andlib.utility.DialogUtilities;
import com.todoroo.astrid.data.Task;
import com.todoroo.astrid.helper.TaskEditControlSet;
import com.todoroo.astrid.taskrabbit.TaskRabbitActivity.ActivityResultSetListener;
@ -30,8 +36,9 @@ public class TaskRabbitLocationControlSet extends TaskEditControlSet implements
private final TextView displayText;
private final TextView displayEdit;
private final Activity activity;
public Location location;
private String locationName;
public Location location;
public JSONObject manualEntry = null;
public int REQUEST_CODE_TASK_RABBIT_LOCATION = 6;
@ -50,14 +57,48 @@ public class TaskRabbitLocationControlSet extends TaskEditControlSet implements
@Override
public void onClick(View v) {
Intent mapIntent = new Intent(activity, TaskRabbitMapActivity.class);
activity.startActivityForResult(mapIntent, REQUEST_CODE_TASK_RABBIT_LOCATION);
try {
Class.forName("com.google.android.maps.MapView");
Intent mapIntent = new Intent(activity, TaskRabbitMapActivity.class);
activity.startActivityForResult(mapIntent, REQUEST_CODE_TASK_RABBIT_LOCATION);
} catch (Exception e) {
manualLocationEntry();
}
}
});
}
protected void manualLocationEntry() {
LinearLayout layout = new LinearLayout(activity);
layout.setOrientation(LinearLayout.VERTICAL);
LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT);
final String[] fields = new String[] { "Address", "City", "State", "Zip" };
final HashMap<String, EditText> views = new HashMap<String, EditText>();
for(String field : fields) {
EditText et = new EditText(activity);
et.setHint(field);
et.setLayoutParams(lp);
views.put(field, et);
layout.addView(et);
}
DialogUtilities.viewDialog(activity, "Enter Location", layout, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
displayEdit.setText(views.get("Address").getText());
manualEntry = new JSONObject();
for(String field : fields)
try {
manualEntry.put(field.toLowerCase(), views.get(field).getText());
} catch (JSONException e) {
// fail
}
}
}, null);
}
private void parseTaskLocation(JSONObject json) {
if (json == null) return;
@ -85,6 +126,7 @@ public class TaskRabbitLocationControlSet extends TaskEditControlSet implements
location.setLatitude(locationToDouble(lat));
location.setLongitude(locationToDouble(lng));
displayEdit.setText(getLocationText());
manualEntry = null;
getAddressFromLocation(location);
@ -136,12 +178,12 @@ public class TaskRabbitLocationControlSet extends TaskEditControlSet implements
}
@Override
public void saveToJSON(JSONObject json, String key) throws JSONException {
public void saveToDatabase(JSONObject json, String key) throws JSONException {
json.put(key, getTaskLocation());
}
@Override
public void writeToJSON(JSONObject json, String key) throws JSONException {
public void postToTaskRabbit(JSONObject json, String key) throws JSONException {
JSONArray locations = json.optJSONArray("other_locations_attributes");
if (locations == null) {
locations = new JSONArray();
@ -152,6 +194,8 @@ public class TaskRabbitLocationControlSet extends TaskEditControlSet implements
}
private JSONObject getTaskLocation() {
if(manualEntry != null)
return manualEntry;
try {
JSONObject locationObject = new JSONObject();

@ -57,7 +57,7 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
List<Overlay> mapOverlays = mapView.getOverlays();
Drawable drawable = this.getResources().getDrawable(R.drawable.icon_locale);
Drawable drawable = this.getResources().getDrawable(android.R.drawable.star_big_on);
currentOverlayItem = new TaskRabbitMapOverlayItem(drawable, this);
GeoPoint point = null;
@ -65,7 +65,7 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
if(lastKnownLocation != null) {
point = new GeoPoint((int)(lastKnownLocation.getLatitude()*1E6),(int)(lastKnownLocation.getLongitude()*1E6));
OverlayItem overlayitem = new OverlayItem(point, "Set this location", "Send this location to Task Rabbit!");
OverlayItem overlayitem = createOverlayItem(point);
currentOverlayItem.addOverlay(overlayitem);
mapOverlays.add(currentOverlayItem);
@ -86,11 +86,8 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
ImageButton searchButton=(ImageButton)findViewById(R.id.search_button);
searchButton.setImageResource(android.R.drawable.ic_menu_search);
searchButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
searchLocation();
}
});
@ -112,12 +109,12 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
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(@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();
}
});
@ -150,59 +147,64 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
private void searchLocation() {
Thread thread = new Thread(){
@Override
public void run (){
Thread thread = new Thread() {
@Override
public void run() {
List<Address> addresses = null;
try {
List<Address> addresses = null;
try {
Geocoder geoCoder = new Geocoder(TaskRabbitMapActivity.this, Locale.getDefault());
addresses = geoCoder.getFromLocationName(searchText.getText().toString(),5);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Geocoder geoCoder = new Geocoder(
TaskRabbitMapActivity.this, Locale.getDefault());
addresses = geoCoder.getFromLocationName(
searchText.getText().toString(), 5);
} catch (IOException e) {
e.printStackTrace();
}
if(addresses != null && addresses.size() > 0)
{
updateAddress(addresses.get(0));
GeoPoint q = new GeoPoint( (int) (addresses.get(0).getLatitude() * 1E6),
(int) (addresses.get(0).getLongitude() * 1E6));
if (addresses != null && addresses.size() > 0) {
updateAddress(addresses.get(0));
GeoPoint q = new GeoPoint(
(int) (addresses.get(0).getLatitude() * 1E6),
(int) (addresses.get(0).getLongitude() * 1E6));
Drawable drawable = TaskRabbitMapActivity.this.getResources().getDrawable(R.drawable.icon_locale);
currentOverlayItem = new TaskRabbitMapOverlayItem(drawable, TaskRabbitMapActivity.this);
mapController.animateTo(q);
mapController.setZoom(12);
Drawable drawable = TaskRabbitMapActivity.this.getResources().getDrawable(
R.drawable.icon_locale);
currentOverlayItem = new TaskRabbitMapOverlayItem(drawable,
TaskRabbitMapActivity.this);
mapController.animateTo(q);
mapController.setZoom(12);
OverlayItem overlayitem = new OverlayItem(q, "Set this location", "For the rabbits!");
OverlayItem overlayitem = createOverlayItem(q);
currentOverlayItem.addOverlay(overlayitem);
List<Overlay> mapOverlays = mapView.getOverlays();
mapOverlays.clear();
mapOverlays.add(currentOverlayItem);
currentOverlayItem.addOverlay(overlayitem);
List<Overlay> mapOverlays = mapView.getOverlays();
mapOverlays.clear();
mapOverlays.add(currentOverlayItem);
Message successMessage = new Message();
successMessage.what = 1;
handler.sendMessage(successMessage);
// searchText.setText("");
}
else
{
Message successMessage = new Message();
successMessage.what = 1;
handler.sendMessage(successMessage);
} else {
Message failureMessage = new Message();
failureMessage.what = -1;
handler.sendMessage(failureMessage);
Message failureMessage = new Message();
failureMessage.what = -1;
handler.sendMessage(failureMessage);
}
}
};
}
}
thread.start();
};
}
thread.start();
}
protected OverlayItem createOverlayItem(GeoPoint q) {
OverlayItem overlayitem = new OverlayItem(q, "Set this location",
"Use this location for TaskRabbit");
return overlayitem;
}
private void getAddressFromLocation(Location location){
try {
@ -220,7 +222,6 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
}
private void updateAddress(Address address){
if(address.getLocality() != null && address.getPostalCode() != null){
// locationAddress = (address.getLocality() + ", " + address.getPostalCode());
locationAddress = "";
for (int i = 0; i < address.getMaxAddressLineIndex(); i++){
locationAddress += address.getAddressLine(i) + ", ";
@ -241,13 +242,12 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
TaskRabbitMapOverlayItem myItemizedOverlay = new TaskRabbitMapOverlayItem(drawable);
GeoPoint point = new GeoPoint((int)(location.getLatitude() * 1E6), (int)(location.getLongitude() * 1E6));
OverlayItem overlayitem = new OverlayItem(point, "Set this location", "For the rabbits!");
OverlayItem overlayitem = createOverlayItem(point);
myItemizedOverlay.addOverlay(overlayitem);
mapOverlays.add(myItemizedOverlay);
}
@Override
public void onLocationChanged(Location location) {
// TODO Auto-generated method stub
if (location != null) {
double lat = location.getLatitude();
double lng = location.getLongitude();
@ -260,17 +260,17 @@ public class TaskRabbitMapActivity extends MapActivity implements LocationListen
}
@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
//
}

@ -6,36 +6,26 @@ import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Point;
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 {
public class TaskRabbitMapOverlayItem extends ItemizedOverlay<OverlayItem> {
private final ArrayList<OverlayItem> mOverlays = new ArrayList<OverlayItem>();
private Drawable defaultMarker;
private TaskRabbitMapActivity mActivity;
private OverlayItem inDrag;
private int xDragImageOffset=0;
private int yDragImageOffset=0;
private final int xDragTouchOffset=0;
private final int yDragTouchOffset=0;
private ImageView dragImage=null;
private OverlayItem selectedItem=null;
private final int didTap = -1;
private final Point tapPoint = null;
private ImageView dragImage = null;
private OverlayItem selectedItem = null;
public TaskRabbitMapOverlayItem(Drawable defaultMarker) {
super(boundCenterBottom(defaultMarker));
}
public TaskRabbitMapOverlayItem(Drawable defaultMarker, TaskRabbitMapActivity activity) {
super(boundCenterBottom(defaultMarker));
this.defaultMarker = defaultMarker;
mActivity = activity;
getDragImage();
@ -46,13 +36,9 @@ public class TaskRabbitMapOverlayItem extends ItemizedOverlay {
dragImage= new ImageView(mActivity);
dragImage.setImageDrawable(mActivity.getResources().getDrawable(R.drawable.icon_locale));
//dragImage.setImageDrawable(R.drawable.gl_alarm);
dragImage.setImageDrawable(mActivity.getResources().getDrawable(
android.R.drawable.star_big_on));
dragImage.setLayoutParams(new RelativeLayout.LayoutParams(50, 50));
xDragImageOffset=dragImage.getDrawable().getIntrinsicWidth()/2;
yDragImageOffset=dragImage.getDrawable().getIntrinsicHeight();
}
return dragImage;
}
@ -83,8 +69,8 @@ public class TaskRabbitMapOverlayItem extends ItemizedOverlay {
dialog.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());

@ -78,12 +78,12 @@ public class TaskRabbitNameControlSet extends PopupControlSet implements TaskRab
}
@Override
public void saveToJSON(JSONObject json, String key) throws JSONException {
public void saveToDatabase(JSONObject json, String key) throws JSONException {
json.put(key, editText.getText().toString());
}
@Override
public void writeToJSON(JSONObject json, String key) throws JSONException {
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)) {
json.put(nameKey, json.optString(nameKey, "") + "\nRestaurant Name: " + editText.getText().toString());

@ -160,7 +160,7 @@ public class TaskRabbitSpinnerControlSet extends TaskEditControlSet implements T
}
}
@Override
public void saveToJSON(JSONObject json, String key) throws JSONException {
public void saveToDatabase(JSONObject json, String key) throws JSONException {
json.put(key, spinner.getSelectedItemPosition());
}
@ -174,7 +174,7 @@ public class TaskRabbitSpinnerControlSet extends TaskEditControlSet implements T
}
@Override
public void writeToJSON(JSONObject json, String key) throws JSONException {
public void postToTaskRabbit(JSONObject json, String key) throws JSONException {
if(spinner.getSelectedItem() != null){
String spinnerString = spinner.getSelectedItem().toString();

@ -20,6 +20,8 @@ import com.todoroo.astrid.sync.SyncContainer;
*/
public class TaskRabbitTaskContainer extends SyncContainer {
public static final int NO_ID = 0;
public Metadata trTask;
public TaskRabbitTaskContainer(Task task, Metadata trTask) {
@ -42,18 +44,16 @@ public class TaskRabbitTaskContainer extends SyncContainer {
return getJSONData(TaskRabbitMetadata.DATA_REMOTE);
}
public int getTaskID() {
public long getTaskID() {
if(TextUtils.isEmpty(trTask.getValue(TaskRabbitMetadata.ID)))
return NO_ID;
try {
int taskID = Integer.parseInt(trTask.getValue(TaskRabbitMetadata.ID));
if(taskID > 0)
return taskID;
return Long.parseLong(trTask.getValue(TaskRabbitMetadata.ID));
} catch (Exception e) {
return NO_ID;
}
catch (Exception e) {
e.printStackTrace();
}
return 0;
}
private JSONObject getJSONData(StringProperty key) {
if(trTask.containsNonNullValue(key)) {
String jsonString = trTask.getValue(key);

Loading…
Cancel
Save