draft version editing hours activity

git-svn-id: https://osmand.googlecode.com/svn/trunk@286 e29c36b1-1cfa-d876-8d93-3434fc2bb7b8
This commit is contained in:
Victor Shcherb 2010-07-05 18:19:03 +00:00
parent 22353589b5
commit e372693c2e
8 changed files with 406 additions and 6 deletions

View file

@ -37,12 +37,18 @@ public class ToDoConstants {
// 40. Support simple vector road rendering (require new index file) (?) // 40. Support simple vector road rendering (require new index file) (?)
// 63. Support simple offline routing(require new index file) (?) // 63. Support simple offline routing(require new index file) (?)
// FIXME BUGS Android // FIXME BUGS Android
// FIXME !!!! Check agains ID is not unique ! (for relation/node/way - it could be the same) - checked for data extraction & index creator // FIXME !!!! Check agains ID is not unique ! (for relation/node/way - it could be the same) - checked for data extraction & index creator
// REFACTOR Settings activity ( for check box properties!) // REFACTOR Settings activity ( for check box properties!)
// Fix bugs with test data (bug with follow turn / left time / add turn) // Fix bugs with test data (bug with follow turn / left time / add turn)
// Fix description on android // show POI choose near by or last map selection.
// Show poi direction (using sensor)
// double tap to zoom
// hide center point (enable only when trackball using)
// forbid rotate map to landscape
// Improvement : Show stops in the transport route // Improvement : Show stops in the transport route
// BUG : loshitsa delete POI
// TODO swing // TODO swing
// 9. Fix issues with big files (such as netherlands) - save memory (!) - very slow due to transport index ! // 9. Fix issues with big files (such as netherlands) - save memory (!) - very slow due to transport index !

View file

@ -0,0 +1,174 @@
package com.osmand.osm;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
public class OpeningHoursParser {
private static final String[] daysStr = new String[] {"Mo", "Tu", "We", "Th", "Fr", "Sa", "Su"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
public static boolean parseRule(String r, int[][] hours, boolean[] days){
Arrays.fill(days, false);
int startDay = -1;
int previousDay = -1;
int k = 0;
for (; k < r.length(); k++) {
char ch = r.charAt(k);
if (Character.isDigit(ch)) {
// time starts
break;
}
if(Character.isWhitespace(ch) || ch == ','){
continue;
} else if(ch == '-'){
if(previousDay != -1){
startDay = previousDay;
} else {
return false;
}
} else if(k < r.length() - 1){
int i = 0;
for(String s : daysStr){
if(s.charAt(0) == ch && s.charAt(1) == r.charAt(k+1)){
break;
}
i++;
}
if(i < daysStr.length){
if(startDay != -1){
for (int j = startDay; j <= i; j++) {
days[j] = true;
}
startDay = -1;
} else {
days[i] = true;
}
previousDay = i;
}
} else {
return false;
}
}
if(previousDay == -1){
return false;
}
String time = r.substring(k);
String[] stEnd = time.split("-"); //$NON-NLS-1$
if(stEnd.length != 2){
return false;
}
int st;
int end;
try {
int i1 = stEnd[0].indexOf(':');
int i2 = stEnd[1].indexOf(':');
st = Integer.parseInt(stEnd[0].substring(0, i1).trim())* 60 + Integer.parseInt(stEnd[0].substring(i1 + 1).trim());
end = Integer.parseInt(stEnd[1].substring(0, i2).trim())* 60 + Integer.parseInt(stEnd[1].substring(i2 + 1).trim());
} catch (NumberFormatException e) {
return false;
}
for(int i=0; i<7; i++){
if(days[i]){
hours[i][0] = st;
hours[i][1] = end;
}
}
return true;
}
public static int[][] parseOpenedHours(String format){
int[][] hours = new int[7][2];
for(int k = 0; k<7;k++){
hours[k][0] = hours[k][1] = -1;
}
boolean days[] = new boolean[7];
String[] rules = format.split(";"); //$NON-NLS-1$
for(String r : rules){
r = r.trim();
if(r.length() == 0){
continue;
}
// check if valid
if(!parseRule(r, hours, days)){
return null;
}
}
return hours;
}
public static String toStringOpenedHours(int[][] hours){
Map<Integer, List<Integer>> groups = new LinkedHashMap<Integer, List<Integer>>();
for (int k = 0; k < 7; k++) {
if (hours[k][0] >= 0 && hours[k][1] >= 0) {
int uniqueInt = hours[k][1] * 60 * 24 + hours[k][0];
if (!groups.containsKey(uniqueInt)) {
groups.put(uniqueInt, new ArrayList<Integer>());
}
groups.get(uniqueInt).add(k);
}
}
StringBuilder b = new StringBuilder(100);
boolean first = true;
for(Integer time : groups.keySet()){
if(first){
first = false;
} else {
b.append("; "); //$NON-NLS-1$
}
int end = time / (60 * 24);
int st = time - end * (60 * 24);
int stHour = st / 60;
int stTime = st - stHour * 60;
int endHour = end / 60;
int endTime = end - endHour * 60;
List<Integer> list = groups.get(time);
boolean dash = false;
for(int k = 0; k < list.size(); k++){
Integer val = list.get(k);
if(k > 0){
if(k < list.size() - 1 && list.get(k + 1) == val + 1 && list.get(k - 1) == val - 1){
if(!dash){
b.append("-"); //$NON-NLS-1$
dash = true;
}
} else if(dash){
b.append(daysStr[val]);
dash = false;
} else {
b.append(", ").append(daysStr[val]); //$NON-NLS-1$
}
} else {
b.append(daysStr[val]);
}
}
b.append(" "); //$NON-NLS-1$
formatTime(stHour, stTime, b);
b.append("-"); //$NON-NLS-1$
formatTime(endHour, endTime, b);
}
return b.toString();
}
private static void formatTime(int h, int t, StringBuilder b){
if(h < 10){
b.append("0"); //$NON-NLS-1$
}
b.append(h).append(":"); //$NON-NLS-1$
if(t < 10){
b.append("0"); //$NON-NLS-1$
}
b.append(t);
}
public static void main(String[] args) {
int[][] hours = parseOpenedHours("Mo-Fr 08:30-14:40; Sa 08:00 - 14:00"); //$NON-NLS-1$
System.out.println(Arrays.deepToString(hours));
System.out.println(toStringOpenedHours(hours));
hours = parseOpenedHours("Mo, We-Fr 08:30-14:40; Sa 08:00 - 14:00"); //$NON-NLS-1$
System.out.println(Arrays.deepToString(hours));
System.out.println(toStringOpenedHours(hours));
}
}

View file

@ -15,7 +15,7 @@
<!-- <EditText android:text="" android:id="@+id/Type" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_height="wrap_content" android:layout_width = "fill_parent" /> --> <!-- <EditText android:text="" android:id="@+id/Type" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_height="wrap_content" android:layout_width = "fill_parent" /> -->
</TableRow> </TableRow>
<TableRow> <TableRow>
<TextView android:text="@string/poi_dialog_opening_hours" android:id="@+id/TextView" android:layout_marginLeft="5dp" android:layout_width="wrap_content" android:layout_height="wrap_content"/> <Button android:text="@string/poi_dialog_opening_hours" android:id="@+id/OpenHoursButton" android:layout_width="wrap_content" android:layout_height="wrap_content"/>
<EditText android:text="" android:hint="Mo-Su 08:00-20:00" android:id="@+id/OpeningHours" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_width ="100dp" android:layout_height="wrap_content"></EditText> <EditText android:text="" android:hint="Mo-Su 08:00-20:00" android:id="@+id/OpeningHours" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_width ="100dp" android:layout_height="wrap_content"></EditText>
</TableRow> </TableRow>
<TableRow> <TableRow>

View file

@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent">
<LinearLayout android:layout_width="wrap_content" android:layout_height="fill_parent" android:orientation="vertical">
<CheckBox android:text="" android:id="@+id/Day1" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox>
<CheckBox android:text="" android:id="@+id/Day2" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox>
<CheckBox android:text="" android:id="@+id/Day3" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox>
<CheckBox android:text="" android:id="@+id/Day4" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox>
<CheckBox android:text="" android:id="@+id/Day5" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox>
<CheckBox android:text="" android:id="@+id/Day6" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox>
<CheckBox android:text="" android:id="@+id/Day7" android:layout_width="wrap_content" android:layout_height="wrap_content"></CheckBox>
</LinearLayout>
<LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:gravity="center" android:layout_marginLeft="5dp">
<TextView android:text="" android:id="@+id/TimeText" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
<TimePicker android:id="@+id/TimePickerStart" android:layout_width="wrap_content" android:layout_height="wrap_content"></TimePicker>
<TimePicker android:id="@+id/TimePickerEnd" android:layout_width="wrap_content" android:layout_height="wrap_content"></TimePicker>
</LinearLayout>
</LinearLayout>
</ScrollView>

View file

@ -271,7 +271,7 @@ See osmand.googlecode.com.</string>
<string name="poi_error_info_not_loaded">Info about node was not loaded</string> <string name="poi_error_info_not_loaded">Info about node was not loaded</string>
<string name="poi_dialog_name">Name</string> <string name="poi_dialog_name">Name</string>
<string name="poi_dialog_opening_hours">Opening hours</string> <string name="poi_dialog_opening_hours">Opened</string>
<string name="poi_dialog_comment">Comment</string> <string name="poi_dialog_comment">Comment</string>
<string name="poi_dialog_comment_default">POI changing</string> <string name="poi_dialog_comment_default">POI changing</string>
<string name="poi_dialog_other_tags_message">All other tags are preserved</string> <string name="poi_dialog_other_tags_message">All other tags are preserved</string>

View file

@ -13,6 +13,8 @@ import java.net.HttpURLConnection;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.text.MessageFormat; import java.text.MessageFormat;
import java.util.Arrays;
import java.util.Calendar;
import java.util.List; import java.util.List;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
@ -38,13 +40,20 @@ import android.app.AlertDialog.Builder;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.res.Resources; import android.content.res.Resources;
import android.text.format.DateFormat;
import android.util.Xml; import android.util.Xml;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView; import android.widget.AutoCompleteTextView;
import android.widget.Button; import android.widget.Button;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.EditText; import android.widget.EditText;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast; import android.widget.Toast;
import android.widget.TimePicker.OnTimeChangedListener;
import com.osmand.AmenityIndexRepository; import com.osmand.AmenityIndexRepository;
import com.osmand.Base64; import com.osmand.Base64;
@ -58,6 +67,7 @@ import com.osmand.data.AmenityType;
import com.osmand.osm.Entity; import com.osmand.osm.Entity;
import com.osmand.osm.EntityInfo; import com.osmand.osm.EntityInfo;
import com.osmand.osm.Node; import com.osmand.osm.Node;
import com.osmand.osm.OpeningHoursParser;
import com.osmand.osm.Entity.EntityId; import com.osmand.osm.Entity.EntityId;
import com.osmand.osm.Entity.EntityType; import com.osmand.osm.Entity.EntityType;
import com.osmand.osm.OSMSettings.OSMTagKey; import com.osmand.osm.OSMSettings.OSMTagKey;
@ -79,9 +89,11 @@ public class EditingPOIActivity {
private AutoCompleteTextView typeText; private AutoCompleteTextView typeText;
private EditText nameText; private EditText nameText;
private Button typeButton; private Button typeButton;
private Button openHoursButton;
private EditText openingHours; private EditText openingHours;
private EntityInfo entityInfo; private EntityInfo entityInfo;
private EditText commentText; private EditText commentText;
private final static Log log = LogUtil.getLog(EditingPOIActivity.class); private final static Log log = LogUtil.getLog(EditingPOIActivity.class);
@ -118,7 +130,7 @@ public class EditingPOIActivity {
} }
Builder builder = new AlertDialog.Builder(ctx); Builder builder = new AlertDialog.Builder(ctx);
builder.setTitle(MessageFormat.format(this.view.getResources().getString(R.string.poi_remove_confirm_template), n.getTag(OSMTagKey.NAME))); builder.setTitle(MessageFormat.format(this.view.getResources().getString(R.string.poi_remove_confirm_template), a.getSimpleFormat(OsmandSettings.usingEnglishNames(ctx))));
final EditText comment = new EditText(ctx); final EditText comment = new EditText(ctx);
comment.setText(R.string.poi_remove_title); comment.setText(R.string.poi_remove_title);
builder.setView(comment); builder.setView(comment);
@ -148,6 +160,7 @@ public class EditingPOIActivity {
nameText.setText(a.getName()); nameText.setText(a.getName());
typeText = ((AutoCompleteTextView)dlg.findViewById(R.id.Type)); typeText = ((AutoCompleteTextView)dlg.findViewById(R.id.Type));
typeButton = ((Button)dlg.findViewById(R.id.TypeButton)); typeButton = ((Button)dlg.findViewById(R.id.TypeButton));
openHoursButton = ((Button)dlg.findViewById(R.id.OpenHoursButton));
openingHours = ((EditText)dlg.findViewById(R.id.OpeningHours)); openingHours = ((EditText)dlg.findViewById(R.id.OpeningHours));
openingHours.setText(a.getOpeningHours()); openingHours.setText(a.getOpeningHours());
typeText = ((AutoCompleteTextView)dlg.findViewById(R.id.Type)); typeText = ((AutoCompleteTextView)dlg.findViewById(R.id.Type));
@ -156,6 +169,15 @@ public class EditingPOIActivity {
updateType(a); updateType(a);
openHoursButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
editOpenHoursDlg();
}
});
typeButton.setOnClickListener(new View.OnClickListener(){ typeButton.setOnClickListener(new View.OnClickListener(){
@Override @Override
public void onClick(View v) { public void onClick(View v) {
@ -240,6 +262,29 @@ public class EditingPOIActivity {
private void editOpenHoursDlg(){
final int[][] time = OpeningHoursParser.parseOpenedHours(openingHours.getText().toString());
if(time == null){
Toast.makeText(ctx, "Opening hours format is not supported for editing", Toast.LENGTH_LONG).show();
return;
}
Builder builder = new AlertDialog.Builder(ctx);
final OpeningHoursView v = new OpeningHoursView(ctx);
builder.setView(v.createOpeningHoursEditView(time));
builder.setPositiveButton(ctx.getString(R.string.default_buttons_apply), new DialogInterface.OnClickListener(){
@Override
public void onClick(DialogInterface dialog, int which) {
openingHours.setText(OpeningHoursParser.toStringOpenedHours(v.getTime()));
}
});
builder.setNegativeButton(ctx.getString(R.string.default_buttons_cancel), null);
builder.show();
}
protected String sendRequsetThroughHttpClient(String url, String requestMethod, String requestBody, String userOperation, boolean doAuthenticate) { protected String sendRequsetThroughHttpClient(String url, String requestMethod, String requestBody, String userOperation, boolean doAuthenticate) {
StringBuilder responseBody = new StringBuilder(); StringBuilder responseBody = new StringBuilder();
try { try {

View file

@ -0,0 +1,148 @@
package com.osmand.activities;
import java.util.Calendar;
import android.content.Context;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;
import android.widget.TimePicker;
import android.widget.Toast;
import android.widget.TimePicker.OnTimeChangedListener;
import com.osmand.R;
import com.osmand.osm.OpeningHoursParser;
public class OpeningHoursView {
private final Context ctx;
private int selectedDay = -1;
private int[][] time;
private TimePicker timePickerStart;
private TimePicker timePickerEnd;
private boolean firstTime = true;
private boolean notifyingTime = true;
public OpeningHoursView(Context ctx){
this.ctx = ctx;
}
public View createOpeningHoursEditView(int[][] t){
this.time = t;
LayoutInflater inflater = (LayoutInflater)ctx.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View view = inflater.inflate(R.layout.open_hours_edit, null);
timePickerStart = (TimePicker)view.findViewById(R.id.TimePickerStart);
timePickerEnd = (TimePicker)view.findViewById(R.id.TimePickerEnd);
final TextView timeText =(TextView)view.findViewById(R.id.TimeText);
OnTimeChangedListener onTimeChangedListener = new TimePicker.OnTimeChangedListener(){
@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
if(selectedDay == -1 || !notifyingTime){
return;
}
if(view == timePickerStart ){
time[selectedDay][0] = hourOfDay * 60 + minute;
} else {
time[selectedDay][1] = hourOfDay * 60 + minute;
}
timeText.setText(OpeningHoursParser.toStringOpenedHours(time));
}
};
Calendar inst = Calendar.getInstance();
int first = inst.getFirstDayOfWeek();
int[] ids = new int[]{R.id.Day1, R.id.Day2, R.id.Day3, R.id.Day4, R.id.Day5, R.id.Day6, R.id.Day7};
for (int i = 0; i < 7; i++) {
int d = (first + i - 1) % 7 + 1;
final CheckBox day = (CheckBox) view.findViewById(ids[i]);
inst.set(Calendar.DAY_OF_WEEK, d);
day.setText(DateFormat.format("E", inst)); //$NON-NLS-1$
final int pos = (d + 5) % 7;
if(time[pos][0] >= 0 && time[pos][1] >= 0){
day.setChecked(true);
} else {
day.setChecked(false);
}
day.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
// try to unselect not current day
if(selectedDay != pos && !isChecked){
selectedDay = pos;
if(firstTime){
Toast.makeText(ctx, "Press once to select day, twice to unselect it", Toast.LENGTH_LONG).show();
firstTime = false;
}
// select it again
day.setChecked(true);
} else {
// uncheck
if(!isChecked){
time[pos][0] = -1;
time[pos][1] = -1;
selectedDay = -1;
} else {
// check again
if (selectedDay > -1 && pos != selectedDay) {
time[pos][0] = time[selectedDay][0];
time[pos][1] = time[selectedDay][1];
}
if (time[pos][0] < 0) {
time[pos][0] = 8 * 60;
}
if (time[pos][1] < 0) {
time[pos][1] = 20 * 60;
}
selectedDay = pos;
}
}
timeText.setText(OpeningHoursParser.toStringOpenedHours(time));
updateTimePickers();
}
});
}
// init
timePickerEnd.setIs24HourView(true);
timePickerStart.setIs24HourView(true);
timePickerStart.setCurrentHour(8);
timePickerStart.setCurrentMinute(0);
timePickerEnd.setCurrentHour(20);
timePickerEnd.setCurrentMinute(0);
timeText.setText(OpeningHoursParser.toStringOpenedHours(time));
timePickerEnd.setOnTimeChangedListener(onTimeChangedListener);
timePickerStart.setOnTimeChangedListener(onTimeChangedListener);
return view;
}
public void updateTimePickers(){
if(selectedDay > -1){
notifyingTime = false;
timePickerStart.setCurrentHour(time[selectedDay][0] / 60);
timePickerStart.setCurrentMinute(time[selectedDay][0] % 60);
timePickerEnd.setCurrentHour(time[selectedDay][1] / 60);
timePickerEnd.setCurrentMinute(time[selectedDay][1] % 60);
notifyingTime = true;
}
}
public int[][] getTime() {
return time;
}
}

View file

@ -37,7 +37,7 @@ public class TransportStopsLayer implements OsmandMapLayer {
pointAltUI = new Paint(); pointAltUI = new Paint();
pointAltUI.setColor(Color.rgb(0, 0, 255)); pointAltUI.setColor(Color.rgb(0, 0, 255));
pointAltUI.setAlpha(200); pointAltUI.setAlpha(150);
pointAltUI.setAntiAlias(true); pointAltUI.setAntiAlias(true);
resourceManager = ResourceManager.getResourceManager(); resourceManager = ResourceManager.getResourceManager();
pixRect.set(0, 0, view.getWidth(), view.getHeight()); pixRect.set(0, 0, view.getWidth(), view.getHeight());