time picker dialog added. TODO

This commit is contained in:
aFedasenka 2012-06-23 01:43:49 +02:00
parent 268116a3c9
commit 481f488d57
4 changed files with 76 additions and 15 deletions

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TimePicker
android:id="@+id/parkingTimePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>

View file

@ -981,7 +981,9 @@ public class OsmandSettings {
*/
public final static String PARKING_POINT_LAT = "parking_point_lat"; //$NON-NLS-1$
public final static String PARKING_POINT_LON = "parking_point_lon"; //$NON-NLS-1$
public final static String PARKING_LIMIT_TIME = "parking_limit_time"; //$NON-NLS-1$
public final static String PARKING_TYPE = "parking_limit_time"; //$NON-NLS-1$
public final static String PARKING_TIME_HOUR = "parking_limit_hour"; //$//$NON-NLS-1$
public final static String PARKING_TIME_MINUTE = "parking_limit_minute"; //$//$NON-NLS-1$
public LatLon getParkingPosition() {
float lat = globalPreferences.getFloat(PARKING_POINT_LAT, 0);
@ -992,20 +994,36 @@ public class OsmandSettings {
return new LatLon(lat, lon);
}
public int getParkingTimeLimit() {
return globalPreferences.getInt(PARKING_LIMIT_TIME, -1);
public boolean getParkingType() {
return globalPreferences.getBoolean(PARKING_TYPE, false);
}
public int getParkingHour() {
return globalPreferences.getInt(PARKING_TIME_HOUR, -1);
}
public int getParkingMinute() {
return globalPreferences.getInt(PARKING_TIME_MINUTE, -1);
}
public boolean clearParkingPosition() {
return globalPreferences.edit().remove(PARKING_POINT_LAT).remove(PARKING_POINT_LON).remove(PARKING_LIMIT_TIME).commit();
return globalPreferences.edit().remove(PARKING_POINT_LAT).remove(PARKING_POINT_LON).remove(PARKING_TYPE).remove(PARKING_TIME_HOUR).remove(PARKING_TIME_MINUTE).commit();
}
public boolean setParkingPosition(double latitude, double longitude) {
return globalPreferences.edit().putFloat(PARKING_POINT_LAT, (float) latitude).putFloat(PARKING_POINT_LON, (float) longitude).commit();
}
public boolean setParkingTimeLimit(int limit) {
return globalPreferences.edit().putInt(PARKING_LIMIT_TIME, limit).commit();
public boolean setParkingType(boolean limited) {
return globalPreferences.edit().putBoolean(PARKING_TYPE, limited).commit();
}
public boolean setParkingHour(int hour) {
return globalPreferences.edit().putInt(PARKING_TIME_HOUR, hour).commit();
}
public boolean setParkingMinute(int minute) {
return globalPreferences.edit().putInt(PARKING_TIME_MINUTE, minute).commit();
}
public static final String LAST_SEARCHED_REGION = "last_searched_region"; //$NON-NLS-1$

View file

@ -63,7 +63,7 @@ public class ParkingPositionLayer extends OsmandMapLayer implements ContextMenuL
private TextInfoControl parkingPlaceControl;
private int timeLimit;
private boolean timeLimit;
public ParkingPositionLayer(MapActivity map) {
this.map = map;
@ -106,10 +106,11 @@ public class ParkingPositionLayer extends OsmandMapLayer implements ContextMenuL
@Override
public void onDraw(Canvas canvas, RectF latLonBounds, RectF tilesRect, DrawSettings nightMode) {
// settings.clearParkingPosition();
parkingPoint = settings.getParkingPosition();
timeLimit = settings.getParkingTimeLimit();
timeLimit = settings.getParkingType();
Bitmap parkingIcon;
if (timeLimit == -1) {
if (timeLimit) {
parkingIcon = parkingNoLimitIcon;
} else {
parkingIcon = parkingLimitIcon;

View file

@ -13,6 +13,7 @@ import android.app.AlertDialog.Builder;
import android.content.DialogInterface;
import android.view.View;
import android.widget.ImageButton;
import android.widget.TimePicker;
/**
*
@ -44,7 +45,14 @@ public class ParkingPositionPlugin extends OsmandPlugin {
@Override
public String getDescription() {
return app.getString(R.string.osmand_parking_plugin_description);
// TODO
StringBuilder res = new StringBuilder();
res.append(app.getString(R.string.osmand_parking_plugin_description));
if (settings.getParkingType())
res.append(settings.getParkingHour());
res.append(" ");
res.append(settings.getParkingMinute());
return res.toString();
}
@Override
@ -96,15 +104,36 @@ public class ParkingPositionPlugin extends OsmandPlugin {
Builder choose = new AlertDialog.Builder(mapActivity);
choose.setView(addParking);
choose.setTitle("Choose the type of parking");
ImageButton limitButton= (ImageButton) addParking.findViewById(R.id.parking_lim_button);
final AlertDialog create = choose.create();
ImageButton limitButton = (ImageButton) addParking.findViewById(R.id.parking_lim_button);
limitButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
create.dismiss();
settings.setParkingPosition(latitude, longitude);
settings.setParkingTimeLimit(1);
settings.setParkingType(true);
if (mapActivity.getMapView().getLayers().contains(parkingLayer))
parkingLayer.setParkingPoint(settings.getParkingPosition());
final View setTimeParking = mapActivity.getLayoutInflater().inflate(R.layout.set_time_of_parking, null);
Builder setTime = new AlertDialog.Builder(mapActivity);
setTime.setView(setTimeParking);
setTime.setTitle("Set the time limit of parking");
setTime.setNegativeButton(R.string.default_buttons_cancel, null);
setTime.setPositiveButton(R.string.default_buttons_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
create.dismiss();
TimePicker timePicker = (TimePicker)setTimeParking.findViewById(R.id.parkingTimePicker);
settings.setParkingHour(timePicker.getCurrentHour());
settings.setParkingMinute(timePicker.getCurrentMinute());
}
});
setTime.create();
setTime.show();
}
});
@ -113,13 +142,14 @@ public class ParkingPositionPlugin extends OsmandPlugin {
@Override
public void onClick(View v) {
create.dismiss();
settings.setParkingPosition(latitude, longitude);
settings.setParkingTimeLimit(-1);
settings.setParkingType(false);
if (mapActivity.getMapView().getLayers().contains(parkingLayer))
parkingLayer.setParkingPoint(settings.getParkingPosition());
}
});
choose.create();
choose.show();
}