Time-limit description fixed. Refresh map after parking point deletion fixed. Choose Type of Parking dialog relayouted. Time picker control now works in both 24- and 12-hour mode (it is taken from the device settings). Bugfixes.
This commit is contained in:
parent
844c57f2bd
commit
a9d0507f56
6 changed files with 156 additions and 435 deletions
|
@ -1,27 +1,53 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal" >
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal" >
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/parking_no_lim_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentLeft="true"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_marginLeft="50dp"
|
||||
android:contentDescription="@string/osmand_parking_time_no_limit"
|
||||
android:background="@drawable/parking_no_limit_button" />
|
||||
<TableRow
|
||||
android:id="@+id/tableRow1"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/parking_lim_button"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_marginLeft="40dp"
|
||||
android:contentDescription="@string/osmand_parking_time_limit"
|
||||
android:layout_toRightOf="@+id/parking_no_lim_button"
|
||||
android:background="@drawable/parking_limit_button" />
|
||||
<ImageButton
|
||||
android:id="@+id/parking_no_lim_button"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:layout_marginRight="16dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:background="@drawable/poi_parking_pos_no_limit_menu"
|
||||
android:contentDescription="@string/osmand_parking_time_no_limit" />
|
||||
|
||||
</RelativeLayout>
|
||||
<ImageButton
|
||||
android:id="@+id/parking_lim_button"
|
||||
android:layout_column="1"
|
||||
android:layout_marginRight="16dp"
|
||||
android:layout_marginLeft="16dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:background="@drawable/poi_parking_pos_limit_menu"
|
||||
android:contentDescription="@string/osmand_parking_time_limit" />
|
||||
|
||||
</TableRow>
|
||||
|
||||
<TableRow
|
||||
android:id="@+id/tableRow2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" >
|
||||
|
||||
<TextView
|
||||
android:id="@+id/parking_lim_text"
|
||||
android:layout_column="0"
|
||||
android:layout_marginRight="4dp"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="@string/osmand_parking_no_lim_text" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/parking_no_lim_text"
|
||||
android:layout_column="1"
|
||||
android:layout_marginRight="4dp"
|
||||
android:layout_marginLeft="4dp"
|
||||
android:gravity="center_horizontal"
|
||||
android:text="@string/osmand_parking_lim_text" />
|
||||
</TableRow>
|
||||
|
||||
</TableLayout>
|
|
@ -9,10 +9,22 @@
|
|||
1. All your modified/created strings are in the top of the file (to make easier find what's translated).
|
||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||
-->
|
||||
<string name="osmand_parking_event">Pick up the car from parking</string>
|
||||
<string name="osmand_parking_warning">Warning</string>
|
||||
<string name="osmand_parking_warning_text">Notification to pick up your car was previously added to your Calendar. It will remain there until you will delete it manually.</string>
|
||||
<string name="osmand_parking_time_limit_title">Set the time limit of parking</string>
|
||||
<string name="osmand_parking_delete_confirm">Do you want to remove the location of the parked car?</string>
|
||||
<string name="osmand_parking_delete">Delete a parking marker</string>
|
||||
<string name="osmand_parking_choose_type">Choose the type of parking</string>
|
||||
<string name="osmand_parking_lim_text">Time-limited</string>
|
||||
<string name="osmand_parking_no_lim_text">Time-unlimited</string>
|
||||
<string name="osmand_parking_add_event">Add a notification to Calendar application</string>
|
||||
<string name="osmand_parking_time_limit">Time-limited parking</string>
|
||||
<string name="osmand_parking_time_no_limit">Time-unlimited parking</string>
|
||||
<string name="osmand_parking_position_description">The position of your parked car. %1$s</string>
|
||||
<string name="osmand_parking_position_description_add">To pick up the car at:</string>
|
||||
<string name="osmand_parking_pm">PM</string>
|
||||
<string name="osmand_parking_am">AM</string>
|
||||
<string name="osmand_parking_position_name">Parking point</string>
|
||||
<string name="osmand_parking_plugin_description">This plugin allows to store the location of your parked car.</string>
|
||||
<string name="osmand_parking_plugin_name">Parking Position Plugin</string>
|
||||
|
|
|
@ -983,6 +983,7 @@ public class OsmandSettings {
|
|||
public final static String PARKING_POINT_LON = "parking_point_lon"; //$NON-NLS-1$
|
||||
public final static String PARKING_TYPE = "parking_type"; //$NON-NLS-1$
|
||||
public final static String PARKING_TIME = "parking_limit_time"; //$//$NON-NLS-1$
|
||||
public final static String PARKING_EVENT_ADDED = "parking_event_added"; //$//$NON-NLS-1$
|
||||
|
||||
public LatLon getParkingPosition() {
|
||||
float lat = globalPreferences.getFloat(PARKING_POINT_LAT, 0);
|
||||
|
@ -997,12 +998,21 @@ public class OsmandSettings {
|
|||
return globalPreferences.getBoolean(PARKING_TYPE, false);
|
||||
}
|
||||
|
||||
public boolean isParkingEventAdded() {
|
||||
return globalPreferences.getBoolean(PARKING_EVENT_ADDED, false);
|
||||
}
|
||||
|
||||
public boolean addParkingEvent(boolean added) {
|
||||
return globalPreferences.edit().putBoolean(PARKING_EVENT_ADDED, added).commit();
|
||||
}
|
||||
|
||||
public long getParkingTime() {
|
||||
return globalPreferences.getLong(PARKING_TIME, -1);
|
||||
}
|
||||
|
||||
public boolean clearParkingPosition() {
|
||||
return globalPreferences.edit().remove(PARKING_POINT_LAT).remove(PARKING_POINT_LON).remove(PARKING_TYPE).remove(PARKING_TIME).commit();
|
||||
return globalPreferences.edit().remove(PARKING_POINT_LAT).remove(PARKING_POINT_LON).remove(PARKING_TYPE)
|
||||
.remove(PARKING_TIME).remove(PARKING_EVENT_ADDED).commit();
|
||||
}
|
||||
|
||||
public boolean setParkingPosition(double latitude, double longitude) {
|
||||
|
|
|
@ -1,369 +0,0 @@
|
|||
package net.osmand.plus.parkingpoint;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.util.Log;
|
||||
|
||||
public class CalendarEvent
|
||||
{
|
||||
private int calendarID = -1;
|
||||
static String contentProvider;
|
||||
static Uri remindersUri;
|
||||
static Uri eventsUri;
|
||||
static Uri calendars;
|
||||
static String eventsTable;
|
||||
static long EVENT_DURATION = 3600000;
|
||||
static long REMINDER_TIME = 0;
|
||||
|
||||
public Context context = null;
|
||||
|
||||
/**
|
||||
* @param a
|
||||
* Constructor
|
||||
*/
|
||||
public CalendarEvent(Context c)
|
||||
{
|
||||
int sdk;
|
||||
|
||||
try
|
||||
{
|
||||
sdk = new Integer(Build.VERSION.SDK_INT).intValue();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
sdk = 9;
|
||||
}
|
||||
|
||||
this.context = c;
|
||||
if(sdk >= 8)
|
||||
{
|
||||
//2.2 or higher
|
||||
eventsTable = "view_events";
|
||||
contentProvider = "com.android.calendar";
|
||||
}
|
||||
else
|
||||
{
|
||||
//anything older
|
||||
eventsTable = "Events";
|
||||
contentProvider = "calendar";
|
||||
}
|
||||
|
||||
remindersUri = Uri.parse(String.format("content://%s/reminders",contentProvider));
|
||||
eventsUri = Uri.parse(String.format("content://%s/events",contentProvider));
|
||||
calendars = Uri.parse(String.format("content://%s/calendars",contentProvider));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param strTitle
|
||||
* as the Title of the event
|
||||
* @param strDescription
|
||||
* as the description of the event
|
||||
* @param startTime
|
||||
* as the time in millis the event begins
|
||||
*/
|
||||
public long insertEvent(String strTitle, String strDescription, long startTime, long endTime) throws Exception
|
||||
{
|
||||
if (calendarID != -1)
|
||||
{
|
||||
// Source: http://sgap.springnote.com/pages/5150959
|
||||
|
||||
ContentValues event = new ContentValues();
|
||||
event.put(EventColumns.ID, calendarID);
|
||||
event.put(EventColumns.TITLE, strTitle);
|
||||
event.put(EventColumns.DESC, strDescription);
|
||||
event.put(EventColumns.START, startTime);
|
||||
event.put(EventColumns.END, endTime);
|
||||
event.put(EventColumns.ALLDAY, "0");
|
||||
event.put(EventColumns.STATUS, "1");
|
||||
event.put(EventColumns.VIS, "0");
|
||||
event.put(EventColumns.TRANS, "0");
|
||||
event.put(EventColumns.ALARM, "1");
|
||||
return Long.parseLong(context.getContentResolver().insert(eventsUri, event).getLastPathSegment());
|
||||
|
||||
}
|
||||
return -1;
|
||||
//throw exception
|
||||
|
||||
}
|
||||
|
||||
public long insertEvent(HashMap<String, String> args)
|
||||
{
|
||||
//Convert to use ContentValues?
|
||||
if (calendarID != -1)
|
||||
{ // Source: http://sgap.springnote.com/pages/5150959
|
||||
ContentValues event = new ContentValues();
|
||||
event.put(EventColumns.ID, calendarID);
|
||||
|
||||
event.putAll(HashMapToContentValues(args));
|
||||
event.put(EventColumns.ALLDAY, "0");
|
||||
event.put(EventColumns.STATUS, "1");
|
||||
event.put(EventColumns.VIS, "0");
|
||||
event.put(EventColumns.TRANS, "0");
|
||||
event.put(EventColumns.ALARM, "1");
|
||||
|
||||
return Long.parseLong(context.getContentResolver().insert(eventsUri, event).getLastPathSegment());
|
||||
}
|
||||
//throw exception
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
public void addReminder(long eventID)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (contains(eventID))
|
||||
{
|
||||
ContentValues values = new ContentValues();
|
||||
|
||||
values.put("event_id", eventID);
|
||||
values.put("method", 1);
|
||||
values.put("minutes", REMINDER_TIME);
|
||||
context.getContentResolver().insert(remindersUri, values);
|
||||
|
||||
Log.d("Calendar Event", "Reminder Added for event " + eventID);
|
||||
|
||||
}
|
||||
else
|
||||
Log.d("Calendar Event", "Reminder Not Added");
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void updateReminder(long eventID, int minutes)
|
||||
{
|
||||
|
||||
Uri updateReminderUri = Uri.withAppendedPath(remindersUri, String.valueOf(eventID));
|
||||
ContentValues values = new ContentValues();
|
||||
values.put(ReminderColumns.ID, eventID);
|
||||
values.put(ReminderColumns.METHOD, 1);
|
||||
values.put(ReminderColumns.TIME, minutes);
|
||||
|
||||
context.getContentResolver().update(updateReminderUri, values, null, null);
|
||||
Log.d("Calendar Event", "Alarm Updated");
|
||||
}
|
||||
|
||||
public void deleteReminder(long eventID)
|
||||
{
|
||||
|
||||
Uri reminderUri = Uri.withAppendedPath(remindersUri, String.valueOf(eventID));
|
||||
context.getContentResolver().delete(reminderUri, null, null);
|
||||
Log.d("Calendar Event", "Reminder deleted");
|
||||
}
|
||||
|
||||
public boolean containsAlarm(long eventID)
|
||||
{
|
||||
String selection = ReminderColumns.ID + "=" + eventID;
|
||||
String[] projection = new String[] { ReminderColumns.METHOD };
|
||||
Cursor cursor = context.getContentResolver().query(remindersUri, projection, selection, null, null);
|
||||
|
||||
if (cursor.getCount() > 0)
|
||||
{
|
||||
cursor.close();
|
||||
Log.d("Calendar Event", "Contains Reminder");
|
||||
return true;
|
||||
}
|
||||
if(cursor != null)
|
||||
cursor.close();
|
||||
Log.d("Calendar Event", "Does not contain a reminder for " + eventID);
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes the eventID passed Returns the number of rows removed
|
||||
*
|
||||
* @param iEventID
|
||||
* as the eventID to remove
|
||||
*/
|
||||
public int removeEvent(long iEventID)
|
||||
{
|
||||
Log.d("studentspet", "removing event.. " + iEventID);
|
||||
if (calendarID != -1 && iEventID != -1)
|
||||
{
|
||||
if (this.contains(iEventID))
|
||||
{
|
||||
Uri deleteEventUri = Uri.withAppendedPath(eventsUri, String.valueOf(iEventID));
|
||||
return context.getContentResolver().delete(deleteEventUri, null, null);
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns boolean specifying if the passed EventID is in the Calendar
|
||||
*
|
||||
* @param iEventID
|
||||
*/
|
||||
public boolean contains(long iEventID)
|
||||
{
|
||||
if (calendarID != -1)
|
||||
{
|
||||
//Wrong table name for android 2.2
|
||||
String[] projection = new String[] { EventColumns.TITLE, CalendarColumns.ID };
|
||||
Cursor managedCursor = context.getContentResolver().query(eventsUri, projection, eventsTable+"._id=" + iEventID, null, null);
|
||||
while (managedCursor.moveToNext())
|
||||
{
|
||||
managedCursor.close();
|
||||
return true;
|
||||
}
|
||||
if(managedCursor != null)
|
||||
managedCursor.close();
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of rows updated
|
||||
*
|
||||
* @param iEventID
|
||||
* as the eventID to update
|
||||
* @param whereArgs
|
||||
* as the Set arguments see Where class
|
||||
*/
|
||||
public int updateEvent(long iEventID, HashMap<String, String> args)
|
||||
{
|
||||
if (calendarID != -1)
|
||||
{
|
||||
if (contains(iEventID))
|
||||
{
|
||||
Uri updateEventUri = Uri.withAppendedPath(eventsUri, String.valueOf(iEventID));
|
||||
return context.getContentResolver().update(updateEventUri, HashMapToContentValues(args), null, null);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return -1;
|
||||
|
||||
}
|
||||
|
||||
private ContentValues HashMapToContentValues(HashMap<String,String> hm)
|
||||
{
|
||||
ContentValues cv = new ContentValues();
|
||||
for (Entry<String, String> kvp : hm.entrySet())
|
||||
{
|
||||
cv.put(kvp.getKey(), kvp.getValue());
|
||||
}
|
||||
|
||||
return cv;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return ArrayList as list of calendars available
|
||||
*/
|
||||
//needs rewritten
|
||||
public ArrayList<CalendarListItem> getCalendars()
|
||||
{
|
||||
ArrayList<CalendarListItem> calendarList = new ArrayList<CalendarListItem>();
|
||||
String[] projection = new String[] { CalendarColumns.ID, CalendarColumns.NAME, CalendarColumns.DISPLAYNAME};
|
||||
Cursor managedCursor = context.getContentResolver().query(calendars, projection, null, null, null);
|
||||
|
||||
if (managedCursor.getCount() > 0)
|
||||
{
|
||||
int nameColumn = managedCursor.getColumnIndex(CalendarColumns.NAME);
|
||||
int displayNameColumn = managedCursor.getColumnIndex(CalendarColumns.DISPLAYNAME);
|
||||
int idColumn = managedCursor.getColumnIndex(CalendarColumns.ID);
|
||||
while (managedCursor.moveToNext())
|
||||
{
|
||||
if (!managedCursor.isNull(nameColumn))
|
||||
calendarList.add(new CalendarListItem(managedCursor.getString(nameColumn), managedCursor.getLong(idColumn)));
|
||||
else
|
||||
calendarList.add(new CalendarListItem(managedCursor.getString(displayNameColumn), managedCursor.getLong(idColumn)));
|
||||
}
|
||||
}
|
||||
if(managedCursor != null)
|
||||
managedCursor.close();
|
||||
|
||||
return calendarList;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @return calendarID as selected calendar's id
|
||||
*/
|
||||
public long getSelectedCalendar()
|
||||
{
|
||||
return calendarID;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param newCalendarID
|
||||
* as new calendar
|
||||
*/
|
||||
public void setSelectedCalendar(int newCalendarID)
|
||||
{
|
||||
calendarID = newCalendarID;
|
||||
}
|
||||
|
||||
class CalendarException extends Exception
|
||||
{
|
||||
private static final long serialVersionUID = 0;
|
||||
|
||||
public CalendarException(String desc)
|
||||
{
|
||||
super(desc);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public static class CalendarListItem
|
||||
{
|
||||
|
||||
String name;
|
||||
long id;
|
||||
|
||||
public CalendarListItem(String calendarName, long calendarID)
|
||||
{
|
||||
this.name = calendarName;
|
||||
this.id = calendarID;
|
||||
}
|
||||
}
|
||||
|
||||
public static class EventColumns
|
||||
{
|
||||
public static final String ID = "calendar_id";
|
||||
public static final String TITLE = "title";
|
||||
public static final String DESC = "description";
|
||||
public static final String START = "dtstart";
|
||||
public static final String END = "dtend";
|
||||
public static final String ALLDAY = "allDay";
|
||||
public static final String STATUS = "eventStatus";
|
||||
public static final String VIS = "visibility";
|
||||
public static final String TRANS = "transparency";
|
||||
public static final String ALARM = "hasAlarm";
|
||||
}
|
||||
|
||||
public static class ReminderColumns
|
||||
{
|
||||
public static final String ID = "event_id";
|
||||
public static final String METHOD = "method";
|
||||
public static final String TIME = "minutes";
|
||||
}
|
||||
|
||||
public static class CalendarColumns
|
||||
{
|
||||
public static final String ID = "_id";
|
||||
public static final String TITLE = "title";
|
||||
public static final String NAME = "name";
|
||||
public static final String DISPLAYNAME = "displayName";
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -26,6 +26,7 @@ import android.graphics.Paint.Style;
|
|||
import android.graphics.PointF;
|
||||
import android.graphics.RectF;
|
||||
import android.location.Location;
|
||||
import android.text.format.DateFormat;
|
||||
import android.text.format.Time;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
|
@ -106,6 +107,8 @@ public class ParkingPositionLayer extends OsmandMapLayer implements ContextMenuL
|
|||
public void onDraw(Canvas canvas, RectF latLonBounds, RectF tilesRect, DrawSettings nightMode) {
|
||||
// settings.clearParkingPosition();
|
||||
parkingPoint = settings.getParkingPosition();
|
||||
if (parkingPoint == null)
|
||||
return;
|
||||
timeLimit = settings.getParkingType();
|
||||
Bitmap parkingIcon;
|
||||
if (!timeLimit) {
|
||||
|
@ -113,8 +116,6 @@ public class ParkingPositionLayer extends OsmandMapLayer implements ContextMenuL
|
|||
} else {
|
||||
parkingIcon = parkingLimitIcon;
|
||||
}
|
||||
if (parkingPoint == null)
|
||||
return;
|
||||
double latitude = parkingPoint.getLatitude();
|
||||
double longitude = parkingPoint.getLongitude();
|
||||
if (isLocationVisible(latitude, longitude)) {
|
||||
|
@ -167,14 +168,13 @@ public class ParkingPositionLayer extends OsmandMapLayer implements ContextMenuL
|
|||
long parkingTime = settings.getParkingTime();
|
||||
Time time = new Time();
|
||||
time.set(parkingTime);
|
||||
timeLimitDesc.append("To pick up the car at: ");
|
||||
timeLimitDesc.append(map.getString(R.string.osmand_parking_position_description_add));
|
||||
timeLimitDesc.append(time.hour);
|
||||
timeLimitDesc.append(":");
|
||||
timeLimitDesc.append(time.minute);
|
||||
if (time.hour>12)
|
||||
timeLimitDesc.append(" p.m.");
|
||||
else
|
||||
timeLimitDesc.append(" a.m.");
|
||||
timeLimitDesc.append(time.minute);
|
||||
if (!DateFormat.is24HourFormat(map.getApplicationContext())) {
|
||||
timeLimitDesc.append(time.hour >= 12 ? map.getString(R.string.osmand_parking_pm) : map.getString(R.string.osmand_parking_am));
|
||||
}
|
||||
}
|
||||
return map.getString(R.string.osmand_parking_position_description, timeLimitDesc.toString());
|
||||
}
|
||||
|
|
|
@ -12,8 +12,10 @@ import net.osmand.plus.activities.MapActivity;
|
|||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
import android.app.AlertDialog;
|
||||
import android.app.AlertDialog.Builder;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.text.format.DateFormat;
|
||||
import android.view.View;
|
||||
import android.widget.CheckBox;
|
||||
import android.widget.ImageButton;
|
||||
|
@ -21,7 +23,7 @@ import android.widget.TimePicker;
|
|||
|
||||
/**
|
||||
*
|
||||
* The plugin facilitates a storage of the location of a parked car
|
||||
* The plugin facilitates a storage of the location of a parked car.
|
||||
*
|
||||
* @author Alena Fedasenka
|
||||
*/
|
||||
|
@ -99,20 +101,26 @@ public class ParkingPositionPlugin extends OsmandPlugin {
|
|||
}
|
||||
|
||||
/**
|
||||
* Method dialog for adding of a parking location
|
||||
* Method dialog for adding of a parking location.
|
||||
* It allows user to choose a type of parking (time-limited or time-unlimited).
|
||||
*/
|
||||
private void showAddParkingDialog(final MapActivity mapActivity, final double latitude, final double longitude) {
|
||||
final boolean wasEventPreviouslyAdded = settings.isParkingEventAdded();
|
||||
final View addParking = mapActivity.getLayoutInflater().inflate(R.layout.parking_set_type, null);
|
||||
Builder choose = new AlertDialog.Builder(mapActivity);
|
||||
choose.setView(addParking);
|
||||
choose.setTitle("Choose the type of parking");
|
||||
final Dialog choose = new Dialog(mapActivity);
|
||||
choose.setContentView(addParking);
|
||||
choose.setCancelable(true);
|
||||
choose.setTitle(mapActivity.getString(R.string.osmand_parking_choose_type));
|
||||
|
||||
ImageButton limitButton = (ImageButton) addParking.findViewById(R.id.parking_lim_button);
|
||||
limitButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (wasEventPreviouslyAdded) {
|
||||
showDeleteEventWarning(mapActivity);
|
||||
}
|
||||
setParkingPosition(mapActivity, latitude, longitude, true);
|
||||
showChooseParkingTypeDialog(mapActivity);
|
||||
showSetTimeLimitDialog(mapActivity, choose);
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -120,6 +128,11 @@ public class ParkingPositionPlugin extends OsmandPlugin {
|
|||
noLimitButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
choose.dismiss();
|
||||
if (wasEventPreviouslyAdded) {
|
||||
showDeleteEventWarning(mapActivity);
|
||||
}
|
||||
settings.addParkingEvent(false);
|
||||
setParkingPosition(mapActivity, latitude, longitude, false);
|
||||
}
|
||||
});
|
||||
|
@ -127,38 +140,50 @@ public class ParkingPositionPlugin extends OsmandPlugin {
|
|||
choose.show();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Method creates confirmation dialog for deletion of a parking location
|
||||
* Method creates confirmation dialog for deletion of a parking location.
|
||||
*/
|
||||
private void showDeleteDialog(final MapActivity mapActivity) {
|
||||
Builder confirm = new AlertDialog.Builder(mapActivity);
|
||||
confirm.setTitle("Delete parking location");
|
||||
confirm.setMessage("Do you want to remove the location of the parked car?");
|
||||
confirm.setTitle(mapActivity.getString(R.string.osmand_parking_delete));
|
||||
confirm.setMessage(mapActivity.getString(R.string.osmand_parking_delete_confirm));
|
||||
confirm.setCancelable(true);
|
||||
confirm.setPositiveButton(R.string.default_buttons_yes,
|
||||
new DialogInterface.OnClickListener() {
|
||||
confirm.setPositiveButton(R.string.default_buttons_yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
showDeleteEventWarning(mapActivity);
|
||||
settings.clearParkingPosition();
|
||||
deleteCalendarEvent();
|
||||
mapActivity.getMapView().refreshMap();
|
||||
}
|
||||
});
|
||||
confirm.setNegativeButton(R.string.default_buttons_cancel, null);
|
||||
confirm.show();
|
||||
}
|
||||
|
||||
private void showChooseParkingTypeDialog(final MapActivity mapActivity) {
|
||||
|
||||
/**
|
||||
* Opens the dialog to set a time limit for time-limited parking.
|
||||
* The dialog has option to add a notification to Calendar app.
|
||||
* Anyway the time-limit can be seen from parking point description.
|
||||
* @param mapActivity
|
||||
* @param choose
|
||||
*/
|
||||
private void showSetTimeLimitDialog(final MapActivity mapActivity, final Dialog choose) {
|
||||
final View setTimeParking = mapActivity.getLayoutInflater().inflate(R.layout.parking_set_time_limit, null);
|
||||
Builder setTime = new AlertDialog.Builder(mapActivity);
|
||||
setTime.setView(setTimeParking);
|
||||
setTime.setTitle("Set the time limit of parking");
|
||||
setTime.setTitle(mapActivity.getString(R.string.osmand_parking_time_limit_title));
|
||||
setTime.setNegativeButton(R.string.default_buttons_cancel, null);
|
||||
final TimePicker timePicker = (TimePicker) setTimeParking.findViewById(R.id.parking_time_picker);
|
||||
|
||||
//to set the same 24-hour or 12-hour mode as it is set in the device
|
||||
timePicker.setIs24HourView(DateFormat.is24HourFormat(app));
|
||||
timePicker.setCurrentHour(Calendar.getInstance().get(Calendar.HOUR_OF_DAY));
|
||||
|
||||
setTime.setPositiveButton(R.string.default_buttons_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
TimePicker timePicker = (TimePicker) setTimeParking.findViewById(R.id.parking_time_picker);
|
||||
choose.dismiss();
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.set(Calendar.HOUR, timePicker.getCurrentHour());
|
||||
cal.set(Calendar.MINUTE, timePicker.getCurrentMinute());
|
||||
|
@ -166,41 +191,58 @@ public class ParkingPositionPlugin extends OsmandPlugin {
|
|||
CheckBox addCalendarEvent = (CheckBox)setTimeParking.findViewById(R.id.check_event_in_calendar);
|
||||
if (addCalendarEvent.isChecked())
|
||||
addCalendarEvent(setTimeParking);
|
||||
settings.addParkingEvent(true);
|
||||
}
|
||||
});
|
||||
setTime.create();
|
||||
setTime.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Opens a Calendar app with added notification to pick up the car from time-limited parking.
|
||||
* @param view
|
||||
*/
|
||||
private void addCalendarEvent(View view) {
|
||||
Intent intent = new Intent(Intent.ACTION_EDIT);
|
||||
intent.setType("vnd.android.cursor.item/event");
|
||||
intent.putExtra("calendar_id", 1);
|
||||
intent.putExtra("beginTime", settings.getParkingTime());
|
||||
intent.putExtra("allDay", false);
|
||||
intent.putExtra("endTime", settings.getParkingTime()+60*60*1000);
|
||||
intent.putExtra("title", "Pickup the car from parking");
|
||||
intent.putExtra("name", "parkingEvent");
|
||||
intent.setType("vnd.android.cursor.item/event"); //$NON-NLS-1$
|
||||
intent.putExtra("calendar_id", 1); //$NON-NLS-1$
|
||||
intent.putExtra("title", view.getContext().getString(R.string.osmand_parking_event)); //$NON-NLS-1$
|
||||
intent.putExtra("beginTime", settings.getParkingTime()); //$NON-NLS-1$
|
||||
intent.putExtra("endTime", settings.getParkingTime()+60*60*1000); //$NON-NLS-1$
|
||||
view.getContext().startActivity(intent);
|
||||
}
|
||||
|
||||
private void deleteCalendarEvent() {
|
||||
// TODO delete calendar event
|
||||
// Uri calendars = Uri.parse(String.format("content://%s/calendars", "com.android.calendar"));
|
||||
// String[] projection = new String[] { CalendarColumns.ID, CalendarColumns.NAME, CalendarColumns.DISPLAYNAME};
|
||||
// TODO next line throws SecurityException
|
||||
// Cursor managedCursor = view.getContext().getContentResolver().query(calendars, projection, null, null, null);
|
||||
|
||||
/**
|
||||
* Method shows warning, if previously the event for time-limited parking was added to Calendar app.
|
||||
* @param mapActivity
|
||||
*/
|
||||
private void showDeleteEventWarning(final MapActivity mapActivity) {
|
||||
if (settings.isParkingEventAdded()) {
|
||||
Builder deleteEventWarning = new AlertDialog.Builder(mapActivity);
|
||||
deleteEventWarning.setTitle(mapActivity.getString(R.string.osmand_parking_warning));
|
||||
deleteEventWarning.setMessage(mapActivity.getString(R.string.osmand_parking_warning_text));
|
||||
deleteEventWarning.setNeutralButton(R.string.default_buttons_ok, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
}
|
||||
});
|
||||
deleteEventWarning.create();
|
||||
deleteEventWarning.show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Method sets a parking point on a ParkingLayer.
|
||||
* @param mapActivity
|
||||
* @param latitude
|
||||
* @param longitude
|
||||
* @param isLimited
|
||||
*/
|
||||
private void setParkingPosition(final MapActivity mapActivity, final double latitude, final double longitude, boolean isLimited) {
|
||||
// to set a new parking position first the event for old parking (in case of a time-limit parking) should be deleted!
|
||||
deleteCalendarEvent();
|
||||
settings.setParkingPosition(latitude, longitude);
|
||||
settings.setParkingType(isLimited);
|
||||
if (mapActivity.getMapView().getLayers().contains(parkingLayer)) {
|
||||
parkingLayer.setParkingPointOnLayer(settings.getParkingPosition());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue