Merge pull request #1576 from GaidamakUA/fix_osm

Fix osm
This commit is contained in:
Yurii Mazurevich 2015-08-21 18:09:15 +03:00
commit 918eeef059
29 changed files with 1252 additions and 323 deletions

View file

@ -1,5 +1,9 @@
package net.osmand.data;
import net.osmand.Location;
import net.osmand.osm.PoiCategory;
import net.osmand.util.Algorithms;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.IOException;
@ -13,10 +17,6 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.zip.GZIPInputStream;
import net.osmand.Location;
import net.osmand.osm.PoiCategory;
import net.osmand.util.Algorithms;
public class Amenity extends MapObject {
@ -28,7 +28,7 @@ public class Amenity extends MapObject {
private static final long serialVersionUID = 132083949926339552L;
private String subType;
private PoiCategory type;
private transient PoiCategory type;
// duplicate for fast access
private String openingHours;
private Map<String, String> additionalInfo;

View file

@ -2,6 +2,7 @@ package net.osmand.util;
/* Can be commented out in order to run the main function separately */
import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
@ -199,7 +200,7 @@ public class OpeningHoursParser {
* This implementation only supports month, day of weeks and numeral times, or the value "off"
*
*/
public static class BasicOpeningHourRule implements OpeningHoursRule {
public static class BasicOpeningHourRule implements OpeningHoursRule, Serializable {
/**
* represents the list on which days it is open.
* Day number 0 is MONDAY

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

View file

@ -1,12 +1,19 @@
<android.support.design.widget.CoordinatorLayout
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dashboard_background"
android:orientation="vertical"
tools:context="net.osmand.plus.osmedit.EditPoiFragment">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
@ -34,10 +41,11 @@
android:layout_marginTop="16dp">
<EditText
android:id="@+id/poiNameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"
android:text="@string/lorem_ipsum"/>
tools:text="@string/lorem_ipsum"/>
</android.support.design.widget.TextInputLayout>
</LinearLayout>
@ -46,21 +54,32 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="72dp"
app:layout_scrollFlags="scroll">
<!--android:layout_marginLeft="72dp"-->
<ImageButton
android:id="@+id/poiTypeButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="bottom"
android:background="@null"
android:src="@drawable/ic_action_label"/>
<android.support.design.widget.TextInputLayout
android:id="@+id/poiTypeTextInputLayout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginLeft="24dp"
android:layout_weight="1">
<EditText
<AutoCompleteTextView
android:id="@+id/poiTypeEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableRight="@drawable/ic_action_arrow_drop_down"
android:hint="POI Type"
android:text="@string/lorem_ipsum"/>
android:completionThreshold="1"
tools:text="@string/lorem_ipsum"/>
</android.support.design.widget.TextInputLayout>
@ -83,9 +102,41 @@
app:tabTextColor="@android:color/darker_gray"/>
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>
</android.support.design.widget.CoordinatorLayout>
<View
android:id="@+id/buttonDivider"
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/divider_color"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:gravity="right">
<Button
android:id="@+id/cancelButton"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/shared_string_cancel"
android:textColor="@color/dashboard_general_button_text_light"/>
<Button
android:id="@+id/saveButton"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/dashboard_general_button_text_light"
tools:text="Save"/>
</LinearLayout>
</LinearLayout>

View file

@ -3,13 +3,71 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dashboard_background">
xmlns:card_view="http://schemas.android.com/apk/res-auto">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/color_white"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginTop="16dp"
card_view:cardCornerRadius="2dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="name"
android:layout_margin="16dp"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/divider_color"/>
<TextView
android:id="@+id/nameTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/divider_color"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
<TextView
android:id="@+id/amenityTagTextView"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:text="amenity"
android:layout_margin="16dp"/>
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="@color/divider_color"/>
<TextView
android:id="@+id/amenityTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"/>
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
<LinearLayout
android:id="@+id/editTagsList"
@ -26,24 +84,5 @@
android:layout_height="wrap_content"
android:text="Add tag"/>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Added tags"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/added_tags_recycler_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</android.support.v4.widget.NestedScrollView>

View file

@ -3,26 +3,16 @@
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/dashboard_background">
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/openHoursTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:text="Open hours"
android:textColor="@color/color_black"/>
<TextView
android:id="@+id/contactInfoTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/openHoursTextView"
android:layout_marginLeft="16dp"
android:text="Contact info"
android:textColor="@color/color_black"/>
@ -93,32 +83,28 @@
android:hint="Description"
android:inputType="textMultiLine"/>
<View
android:id="@+id/buttonDivider"
android:layout_width="match_parent"
android:layout_height="1dp"
<TextView
android:id="@+id/openHoursTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/descriptionEditText"
android:background="@color/divider_color"/>
android:layout_marginLeft="16dp"
android:text="Open hours"
android:textColor="@color/color_black"/>
<Button
android:id="@+id/saveButton"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@id/buttonDivider"
tools:text="Save"
android:textColor="@color/dashboard_general_button_text_light"/>
<ImageView
android:id="@+id/openHoursImageView"
style="@style/edit_poi_imageview_style"
android:layout_below="@id/openHoursTextView"
tools:src="@drawable/ic_action_time"/>
<Button
android:id="@+id/cancelButton"
style="?android:attr/borderlessButtonStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/buttonDivider"
android:layout_toLeftOf="@id/saveButton"
android:text="Cancel"
android:textColor="@color/dashboard_general_button_text_light"/>
<EditText
android:id="@+id/openHoursEditText"
style="@style/create_poi_text_field"
android:layout_width="match_parent"
android:layout_below="@id/openHoursTextView"
android:hint="Mo-Su 08:00-20:00"
android:inputType="textMultiLine"/>
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>

View file

@ -11,7 +11,7 @@
android:text="@string/osb_comment_dialog_message" />
<EditText
android:id="@+id/BugMessage"
android:id="@+id/messageEditText"
android:minLines="1"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
@ -27,7 +27,7 @@
android:text="@string/osb_comment_dialog_author" />
<EditText
android:id="@+id/AuthorName"
android:id="@+id/userNameEditText"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_height="wrap_content"
@ -42,12 +42,10 @@
android:text="@string/osb_author_dialog_password" />
<EditText
android:id="@+id/Password"
android:id="@+id/passwordEditText"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:inputType="textPassword" />
</LinearLayout>

View file

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageButton
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="bottom"
android:src="@drawable/ic_action_time"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="24dp"
android:orientation="vertical"
android:layout_weight="1">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="Mo-We"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/divider_color"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="08:00"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/divider_color"/>
</LinearLayout>
<View
android:layout_width="16dp"
android:layout_height="1dp"
android:background="@color/divider_color"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:text="20:00"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/divider_color"/>
</LinearLayout>
<ImageButton
android:id="@+id/deleteItemImageButton"
style="@style/Widget.AppCompat.Button.Borderless"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_gravity="bottom"
android:src="@drawable/ic_action_close_dark"/>
</LinearLayout>

View file

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_marginLeft="5dp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/osb_comment_dialog_message" />
<EditText
android:id="@+id/messageEditText"
android:minLines="1"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:inputType="textMultiLine" />
<TextView
android:layout_marginLeft="5dp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/user_name" />
<EditText
android:id="@+id/userNameEditText"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
<TextView
android:layout_marginLeft="5dp"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="@string/user_password" />
<EditText
android:id="@+id/passwordEditText"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:inputType="textPassword" />
</LinearLayout>

View file

@ -2236,4 +2236,5 @@ Afghanistan, Albania, Algeria, Andorra, Angola, Anguilla, Antigua and Barbuda, A
<string name="shared_string_skip">Skip</string>
<string name="app_name_osmand">OsmAnd</string>
<string name="offline_maps_and_navigation"><![CDATA[Offline Maps\n& Navigation]]></string>
<string name="commit_poi">Commit POI</string>
</resources>

View file

@ -3,9 +3,9 @@ package net.osmand.plus.osmedit;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.text.Editable;
import android.text.TextUtils;
import android.util.Log;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@ -13,14 +13,24 @@ import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import net.osmand.osm.PoiType;
import net.osmand.osm.edit.OSMSettings;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.osmedit.EditPoiFragment.Tag;
import net.osmand.plus.osmedit.data.EditPoiData;
import net.osmand.plus.osmedit.data.Tag;
import java.util.Iterator;
import java.util.Map;
public class AdvancedDataFragment extends Fragment {
private static final String TAG = "AdvancedDataFragment";
private TagAdapterLinearLayoutHack mAdapter;
private EditPoiData.TagsChangedListener mTagsChangedListener;
private boolean mIsUserInput = true;
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
@ -46,11 +56,14 @@ public class AdvancedDataFragment extends Fragment {
valueEditText.clearFocus();
}
});
TextView nameTextView = (TextView) view.findViewById(R.id.nameTextView);
TextView amenityTagTextView = (TextView) view.findViewById(R.id.amenityTagTextView);
TextView amenityTextView = (TextView) view.findViewById(R.id.amenityTextView);
LinearLayout editTagsLineaLayout =
(LinearLayout) view.findViewById(R.id.editTagsList);
Log.v(TAG, "arguments=" + savedInstanceState + "; ll=" + editTagsLineaLayout);
Log.v(TAG, "not restored");
mAdapter = new TagAdapterLinearLayoutHack(editTagsLineaLayout, getData());
mAdapter = new TagAdapterLinearLayoutHack(editTagsLineaLayout, getData(),
nameTextView, amenityTagTextView, amenityTextView,
((OsmandApplication) getActivity().getApplication()).getPoiTypes().getAllTranslatedNames());
// setListViewHeightBasedOnChildren(editTagsLineaLayout);
Button addTagButton = (Button) view.findViewById(R.id.addTagButton);
addTagButton.setOnClickListener(new View.OnClickListener() {
@ -76,76 +89,136 @@ public class AdvancedDataFragment extends Fragment {
super.onResume();
// TODO read more about lifecycle
mAdapter.updateViews();
getEditPoiFragment().addOnPageChangeListener(new ViewPager.OnPageChangeListener() {
mTagsChangedListener = new EditPoiData.TagsChangedListener() {
@Override
public void onPageScrolled(int i, float v, int i1) {
public void onTagsChanged() {
mIsUserInput = false;
mAdapter.updateViews();
mIsUserInput = true;
}
};
getData().addListener(mTagsChangedListener);
}
@Override
public void onPageSelected(int i) {
if (i == 1) mAdapter.updateViews();
}
@Override
public void onPageScrollStateChanged(int i) {
}
});
public void onPause() {
super.onPause();
getData().deleteListener(mTagsChangedListener);
}
@Override
public void onSaveInstanceState(Bundle outState) {
Log.v(TAG, "onSaveInstanceState(" + "outState=" + outState + ")");
super.onSaveInstanceState(outState);
}
public static class TagAdapterLinearLayoutHack {
public class TagAdapterLinearLayoutHack {
private final LinearLayout linearLayout;
private final EditPoiFragment.EditPoiData editPoiData;
private final EditPoiData editPoiData;
private final TextView nameTextView;
private final TextView amenityTagTextView;
private final TextView amenityTextView;
private final Map<String, PoiType> allTranslatedSubTypes;
public TagAdapterLinearLayoutHack(LinearLayout linearLayout,
EditPoiFragment.EditPoiData editPoiData) {
EditPoiData editPoiData,
TextView nameTextView,
TextView amenityTagTextView,
TextView amenityTextView,
Map<String, PoiType> allTranslatedSubTypes) {
this.linearLayout = linearLayout;
this.editPoiData = editPoiData;
this.nameTextView = nameTextView;
this.amenityTagTextView = amenityTagTextView;
this.amenityTextView = amenityTextView;
this.allTranslatedSubTypes = allTranslatedSubTypes;
}
public void addTag(Tag tag) {
View view = getView(tag);
editPoiData.tags.add(tag);
EditText valueEditText = (EditText) view.findViewById(R.id.valueEditText);
Log.v(TAG, "valueEditText text=" + valueEditText.getText());
if (mIsUserInput)
editPoiData.notifyDatasetChanged(mTagsChangedListener);
linearLayout.addView(view);
}
public void updateViews() {
linearLayout.removeAllViews();
Log.v(TAG, "editPoiData.tags=" + editPoiData.tags);
Iterator<Tag> iterator = editPoiData.tags.iterator();
for (Tag tag : editPoiData.tags) {
Log.v(TAG, "tag=" + tag);
if (tag.tag.equals(OSMSettings.OSMTagKey.NAME.getValue())) {
nameTextView.setText(tag.value);
} else if (tag.tag.equals(EditPoiFragment.POI_TYPE_TAG)) {
String subType = tag.value.trim().toLowerCase();
if (allTranslatedSubTypes.get(subType) != null) {
PoiType pt = allTranslatedSubTypes.get(subType);
amenityTagTextView.setText(pt.getOsmTag());
amenityTextView.setText(pt.getOsmValue());
} else {
amenityTagTextView.setText(editPoiData.amenity.getType().getDefaultTag());
amenityTextView.setText(subType);
}
} else {
View view = getView(tag);
EditText valueEditText = (EditText) view.findViewById(R.id.valueEditText);
Log.v(TAG, "valueEditText text=" + valueEditText.getText());
linearLayout.addView(view);
}
}
}
private View getView(final Tag tag) {
Log.v(TAG, "getView(" + "tag=" + tag + ")");
final View convertView = LayoutInflater.from(linearLayout.getContext())
.inflate(R.layout.poi_tag_list_item, null, false);
EditText tagEditText = (EditText) convertView.findViewById(R.id.tagEditText);
EditText valueEditText = (EditText) convertView.findViewById(R.id.valueEditText);
final EditText tagEditText = (EditText) convertView.findViewById(R.id.tagEditText);
tagEditText.setText(tag.tag);
final EditText valueEditText = (EditText) convertView.findViewById(R.id.valueEditText);
ImageButton deleteItemImageButton =
(ImageButton) convertView.findViewById(R.id.deleteItemImageButton);
tagEditText.setText(tag.tag);
valueEditText.setText(tag.value);
deleteItemImageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
linearLayout.removeView((View) v.getParent());
editPoiData.tags.remove(tag);
if (mIsUserInput)
editPoiData.notifyDatasetChanged(mTagsChangedListener);
}
});
tagEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
editPoiData.tags.remove(tag);
tag.tag = tagEditText.getText().toString();
editPoiData.tags.add(tag);
if (mIsUserInput)
editPoiData.notifyDatasetChanged(mTagsChangedListener);
}
});
valueEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
editPoiData.tags.remove(tag);
tag.value = valueEditText.getText().toString();
editPoiData.tags.add(tag);
if (mIsUserInput)
editPoiData.notifyDatasetChanged(mTagsChangedListener);
}
});
Log.v(TAG, "convertView=" + convertView);
return convertView;
}
}
@ -154,7 +227,7 @@ public class AdvancedDataFragment extends Fragment {
return (EditPoiFragment) getParentFragment();
}
private EditPoiFragment.EditPoiData getData() {
private EditPoiData getData() {
return getEditPoiFragment().getEditPoiData();
}
}

View file

@ -1,19 +1,24 @@
package net.osmand.plus.osmedit;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.TextView;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.ProgressImplementation;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
@ -90,8 +95,13 @@ public class DashOsmEditsFragment extends DashBaseFragment {
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (point.getGroup() == OsmPoint.Group.POI) {
SendPoiDialogFragment.createInstance((OpenstreetmapPoint) point)
.show(getChildFragmentManager(), "SendPoiDialogFragment");
} else {
uploadItem(point);
}
}
});
view.findViewById(R.id.options).setVisibility(View.GONE);
view.findViewById(R.id.divider).setVisibility(View.VISIBLE);
@ -188,4 +198,44 @@ public class DashOsmEditsFragment extends DashBaseFragment {
}
}
}
public static class SendPoiDialogFragment extends DialogFragment {
public static final String OPENSTREETMAP_POINT = "openstreetmap_point";
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final OpenstreetmapPoint poi = (OpenstreetmapPoint) getArguments().getSerializable(OPENSTREETMAP_POINT);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
View view = getActivity().getLayoutInflater().inflate(R.layout.send_poi_dialog, null);
final EditText messageEditText = (EditText) view.findViewById(R.id.messageEditText);
final EditText userNameEditText = (EditText) view.findViewById(R.id.userNameEditText);
final EditText passwordEditText = (EditText) view.findViewById(R.id.passwordEditText);
final OsmandSettings settings = ((MapActivity) getActivity()).getMyApplication().getSettings();
userNameEditText.setText(settings.USER_NAME.get());
passwordEditText.setText(settings.USER_PASSWORD.get());
builder.setTitle(R.string.commit_poi)
.setView(view)
.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
settings.USER_NAME.set(userNameEditText.getText().toString());
settings.USER_PASSWORD.set(passwordEditText.getText().toString());
poi.setComment(messageEditText.getText().toString());
((DashOsmEditsFragment) getParentFragment()).showProgressDialog(poi);
}
})
.setNegativeButton(R.string.shared_string_cancel, null);
return builder.create();
}
public static SendPoiDialogFragment createInstance(OpenstreetmapPoint poi) {
SendPoiDialogFragment fragment = new SendPoiDialogFragment();
Bundle bundle = new Bundle();
bundle.putSerializable(OPENSTREETMAP_POINT, poi);
fragment.setArguments(bundle);
return fragment;
}
}
}

View file

@ -2,28 +2,56 @@ package net.osmand.plus.osmedit;
import android.annotation.TargetApi;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.design.widget.TextInputLayout;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.widget.Toolbar;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.Toast;
import net.osmand.access.AccessibleToast;
import net.osmand.data.Amenity;
import net.osmand.osm.PoiType;
import net.osmand.osm.edit.EntityInfo;
import net.osmand.osm.edit.Node;
import net.osmand.osm.edit.OSMSettings;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.osmedit.data.EditPoiData;
import net.osmand.plus.osmedit.data.Tag;
import net.osmand.plus.osmedit.dialogs.PoiSubTypeDialogFragment;
import net.osmand.plus.osmedit.dialogs.PoiTypeDialogFragment;
import net.osmand.util.Algorithms;
import java.io.Serializable;
import java.text.MessageFormat;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
public class EditPoiFragment extends Fragment {
public static final String TAG = "EditPoiFragment";
@ -34,27 +62,42 @@ public class EditPoiFragment extends Fragment {
private final EditPoiData editPoiData = new EditPoiData();
private ViewPager viewPager;
private boolean isLocalEdit;
private boolean mIsUserInput = true;
private EditText poiNameEditText;
private EditPoiData.TagsChangedListener mTagsChangedListener;
private AutoCompleteTextView poiTypeEditText;
private Node node;
private Map<String, PoiType> allTranslatedSubTypes;
public static final String POI_TYPE_TAG = "poi_type_tag";
private OpenstreetmapUtil openstreetmapUtil;
private TextInputLayout poiTypeTextInputLayout;
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
// poiTypes = ((OsmandApplication) activity.getApplication()).getPoiTypes();
// allTranslatedSubTypes = poiTypes.getAllTranslatedNames();
// OsmandSettings settings = ((OsmandApplication) activity.getApplication()).getSettings();
OsmandSettings settings = ((OsmandApplication) activity.getApplication()).getSettings();
// editPoiData.isLocalEdit = true;
// if (settings.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) {
// openstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity);
OsmEditingPlugin plugin = (OsmEditingPlugin) OsmandPlugin.getPlugin(OsmEditingPlugin.class);
if (settings.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) {
openstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity);
// openstreetmapUtilToLoad = openstreetmapUtil;
// } else if(!settings.isInternetConnectionAvailable(true)) {
// openstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity);
} else if (!settings.isInternetConnectionAvailable(true)) {
openstreetmapUtil = new OpenstreetmapLocalUtil(plugin, activity);
// openstreetmapUtilToLoad = new OpenstreetmapRemoteUtil(activity);
// } else {
// editPoiData.isLocalEdit = false;
// openstreetmapUtil = new OpenstreetmapRemoteUtil(activity);
} else {
isLocalEdit = false;
openstreetmapUtil = new OpenstreetmapRemoteUtil(activity);
// openstreetmapUtilToLoad = openstreetmapUtil;
// }
}
// editPoiData.node = (Node) getArguments().getSerializable(KEY_AMENITY_NODE);
node = (Node) getArguments().getSerializable(KEY_AMENITY_NODE);
allTranslatedSubTypes = ((OsmandApplication) activity.getApplication()).getPoiTypes()
.getAllTranslatedNames();
// TODO implement normal name
editPoiData.amenity = (Amenity) getArguments().getSerializable(KEY_AMENITY);
// editPoiData.tags = new LinkedHashSet<>();
}
@ -114,6 +157,144 @@ public class EditPoiFragment extends Fragment {
Uri.parse("https://wiki.openstreetmap.org/wiki/Map_Features")));
}
});
ImageButton poiTypeButton = (ImageButton) view.findViewById(R.id.poiTypeButton);
poiTypeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DialogFragment fragment = PoiTypeDialogFragment.createInstance(editPoiData.amenity);
fragment.show(getChildFragmentManager(), "PoiTypeDialogFragment");
}
});
poiNameEditText = (EditText) view.findViewById(R.id.poiNameEditText);
poiNameEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
final Tag tag = new Tag(OSMSettings.OSMTagKey.NAME.getValue(), s.toString());
if (mIsUserInput) {
getEditPoiData().tags.remove(tag);
getEditPoiData().tags.add(tag);
getEditPoiData().notifyDatasetChanged(mTagsChangedListener);
}
}
});
poiTypeTextInputLayout = (TextInputLayout) view.findViewById(R.id.poiTypeTextInputLayout);
poiTypeEditText = (AutoCompleteTextView) view.findViewById(R.id.poiTypeEditText);
poiTypeEditText.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
final Tag tag = new Tag(POI_TYPE_TAG, s.toString());
if (mIsUserInput) {
getEditPoiData().tags.remove(tag);
getEditPoiData().tags.add(tag);
getEditPoiData().notifyDatasetChanged(mTagsChangedListener);
}
}
});
poiTypeEditText.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(poiTypeEditText.getText().length() == 0 && editPoiData.amenity.getType() != null){
DialogFragment dialogFragment =
PoiSubTypeDialogFragment.createInstance(editPoiData.amenity);
dialogFragment.show(getChildFragmentManager(), "PoiSubTypeDialogFragment");
}
}
});
Button saveButton = (Button) view.findViewById(R.id.saveButton);
int saveButtonTextId = isLocalEdit ? R.string.shared_string_save :
R.string.default_buttons_commit;
saveButton.setText(saveButtonTextId);
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO implement saving
OsmPoint.Action action = node.getId() == -1 ? OsmPoint.Action.CREATE : OsmPoint.Action.MODIFY;
String description = "";
Log.v(TAG, "tags=" + editPoiData.tags);
for (Tag tag : editPoiData.tags) {
if (tag.tag.equals(POI_TYPE_TAG)) {
if (allTranslatedSubTypes.get(tag.value) != null) {
PoiType pt = allTranslatedSubTypes.get(tag.value);
node.putTag(pt.getOsmTag(), pt.getOsmValue());
if (pt.getOsmTag2() != null) {
node.putTag(pt.getOsmTag2(), pt.getOsmValue2());
}
} else {
node.putTag(editPoiData.amenity.getType().getDefaultTag(), tag.value);
}
// } else if (tag.tag.equals(OSMSettings.OSMTagKey.DESCRIPTION.getValue())) {
// description = tag.value;
} else {
if (tag.value.length() > 0) {
node.putTag(tag.tag, tag.value);
} else {
node.removeTag(tag.tag);
}
}
}
commitNode(action, node, openstreetmapUtil.getEntityInfo(),
"",
false,//closeChange.isSelected(),
new Runnable() {
@Override
public void run() {
if (isLocalEdit) {
AccessibleToast.makeText(
getActivity(),
R.string.osm_changes_added_to_local_edits,
Toast.LENGTH_LONG).show();
} else {
final String message = node.getId() == -1 ?
getResources().getString(R.string.poi_action_add)
: getResources().getString(R.string.poi_action_change);
AccessibleToast.makeText(
getActivity(),
MessageFormat.format(
getResources().getString(
R.string.poi_action_succeded_template), message),
Toast.LENGTH_LONG).show();
}
if (getActivity() instanceof MapActivity) {
((MapActivity) getActivity()).getMapView().refreshMap(true);
}
FragmentManager fragmentManager =
getActivity().getSupportFragmentManager();
fragmentManager.beginTransaction().remove(EditPoiFragment.this)
.commit();
fragmentManager.popBackStack();
}
}, getActivity());
}
});
Button cancelButton = (Button) view.findViewById(R.id.cancelButton);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
fragmentManager.beginTransaction().remove(EditPoiFragment.this).commit();
fragmentManager.popBackStack();
}
});
return view;
}
@ -124,11 +305,18 @@ public class EditPoiFragment extends Fragment {
super.onSaveInstanceState(outState);
}
public void addOnPageChangeListener(ViewPager.OnPageChangeListener listener) {
viewPager.addOnPageChangeListener(listener);
public static EditPoiFragment createAddPoiInstance(double latitude, double longitude,
OsmandApplication application) {
Node node = new Node(latitude, longitude, -1);
Amenity amenity;
amenity = new Amenity();
amenity.setType(application.getPoiTypes().getOtherPoiCategory());
amenity.setSubType("");
amenity.setAdditionalInfo(OSMSettings.OSMTagKey.OPENING_HOURS.getValue(), "");
return createInstance(node, amenity);
}
public EditPoiFragment createInstance(Node node, Amenity amenity) {
public static EditPoiFragment createInstance(Node node, Amenity amenity) {
EditPoiFragment editPoiFragment = new EditPoiFragment();
Bundle args = new Bundle();
args.putSerializable(KEY_AMENITY_NODE, node);
@ -141,8 +329,115 @@ public class EditPoiFragment extends Fragment {
return editPoiData;
}
public void send() {
// TODO implement saving
public void setSubCategory(String subCategory) {
poiTypeEditText.setText(subCategory);
}
public void commitNode(final OsmPoint.Action action,
final Node n,
final EntityInfo info,
final String comment,
final boolean closeChangeSet,
final Runnable successAction,
final Activity activity) {
if (info == null && OsmPoint.Action.CREATE != action) {
AccessibleToast.makeText(activity, activity.getResources().getString(R.string.poi_error_info_not_loaded), Toast.LENGTH_LONG).show();
return;
}
new AsyncTask<Void, Void, Node>() {
ProgressDialog progress;
@Override
protected void onPreExecute() {
progress = ProgressDialog.show(activity, activity.getString(R.string.uploading), activity.getString(R.string.uploading_data));
super.onPreExecute();
}
@Override
protected Node doInBackground(Void... params) {
Node node = openstreetmapUtil.commitNodeImpl(action, n, info, comment, closeChangeSet);
return node;
}
@Override
protected void onPostExecute(Node result) {
progress.dismiss();
if (result != null) {
successAction.run();
}
}
;
}.execute();
}
public void updateType(Amenity amenity) {
// TODO implement
Log.v(TAG, "updateType(" + "amenity=" + amenity + ")");
mIsUserInput = false;
poiTypeEditText.setText(amenity.getSubType());
mIsUserInput = true;
poiTypeTextInputLayout.setHint(amenity.getType().getTranslation());
final Map<String, PoiType> subCategories = new LinkedHashMap<>();
for (Map.Entry<String, PoiType> s : allTranslatedSubTypes.entrySet()) {
if (!subCategories.containsKey(s.getKey())) {
subCategories.put(Algorithms.capitalizeFirstLetterAndLowercase(s.getKey()), s.getValue());
}
}
final ArrayAdapter<Object> adapter = new ArrayAdapter<>(getActivity(),
R.layout.list_textview, subCategories.keySet().toArray());
poiTypeEditText.setAdapter(adapter);
poiTypeEditText.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Object item = parent.getAdapter().getItem(position);
if (subCategories.containsKey(item)) {
String keyName = subCategories.get(item).getKeyName();
poiTypeEditText.setText(keyName);
}
}
@Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
public static void showEditInstance(final Amenity amenity, OsmandSettings settings,
final MapActivity mapActivity) {
final OpenstreetmapUtil openstreetmapUtilToLoad;
if (settings.OFFLINE_EDITION.get() || !settings.isInternetConnectionAvailable(true)) {
OsmEditingPlugin plugin = OsmandPlugin.getPlugin(OsmEditingPlugin.class);
openstreetmapUtilToLoad = new OpenstreetmapLocalUtil(plugin, mapActivity);
} else if(!settings.isInternetConnectionAvailable(true)) {
openstreetmapUtilToLoad = new OpenstreetmapRemoteUtil(mapActivity);
} else {
openstreetmapUtilToLoad = new OpenstreetmapRemoteUtil(mapActivity);
}
new AsyncTask<Void, Void, Node>() {
@Override
protected Node doInBackground(Void... params) {
return openstreetmapUtilToLoad.loadNode((Amenity) amenity);
}
protected void onPostExecute(Node n) {
if(n != null){
EditPoiFragment fragment =
EditPoiFragment.createInstance(n, (Amenity) amenity);
mapActivity.getSupportFragmentManager().beginTransaction()
.add(fragment, "EditPoiFragment").commit();
} else {
AccessibleToast.makeText(mapActivity,
mapActivity.getString(R.string.poi_error_poi_not_found),
Toast.LENGTH_SHORT).show();
}
};
}.execute(new Void[0]);
}
public static class MyAdapter extends FragmentPagerAdapter {
@ -178,44 +473,4 @@ public class EditPoiFragment extends Fragment {
throw new IllegalArgumentException("Unexpected position");
}
}
public static class EditPoiData {
// public boolean isLocalEdit;
// public Node node;
public LinkedHashSet<Tag> tags;
}
public static class Tag implements Serializable {
public String tag;
public String value;
public Tag(String tag, String value) {
this.tag = tag;
this.value = value;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Tag tag1 = (Tag) o;
return tag.equals(tag1.tag);
}
@Override
public int hashCode() {
return tag.hashCode();
}
@Override
public String toString() {
return "Tag{" +
"tag='" + tag + '\'' +
", value='" + value + '\'' +
'}';
}
}
}

View file

@ -3,22 +3,36 @@ package net.osmand.plus.osmedit;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.osm.edit.OSMSettings;
import net.osmand.plus.IconsCache;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.osmedit.EditPoiFragment.Tag;
import net.osmand.plus.osmedit.data.EditPoiData;
import net.osmand.plus.osmedit.data.Tag;
import java.util.HashMap;
import java.util.Map;
public class NormalDataFragment extends Fragment {
private static final String TAG = "NormalDataFragment";
private EditText streetEditText;
private EditText houseNumberEditText;
private EditText phoneEditText;
private EditText webSiteEditText;
private EditText descriptionEditText;
private EditPoiData.TagsChangedListener mTagsChangedListener;
private boolean mIsUserInput = true;
private EditText openHoursEditText;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
@ -35,66 +49,126 @@ public class NormalDataFragment extends Fragment {
webSiteImageView.setImageDrawable(iconsCache.getContentIcon(R.drawable.ic_world_globe_dark));
ImageView descriptionImageView = (ImageView) view.findViewById(R.id.descriptionImageView);
descriptionImageView.setImageDrawable(iconsCache.getContentIcon(R.drawable.ic_action_description));
ImageView openHoursImageView = (ImageView) view.findViewById(R.id.openHoursImageView);
openHoursImageView.setImageDrawable(iconsCache.getContentIcon(R.drawable.ic_action_time));
// TODO replace with constants
final TextView streetEditText = (TextView) view.findViewById(R.id.streetEditText);
streetEditText.setOnFocusChangeListener(new MyOnFocusChangeListener(getData(), "addr:street"));
final TextView houseNumberEditText = (TextView) view.findViewById(R.id.houseNumberEditText);
houseNumberEditText.setOnFocusChangeListener(new MyOnFocusChangeListener(getData(), "addr:housenumber"));
final TextView phoneEditText = (TextView) view.findViewById(R.id.phoneEditText);
phoneEditText.setOnFocusChangeListener(new MyOnFocusChangeListener(getData(), "phone"));
final TextView webSiteEditText = (TextView) view.findViewById(R.id.webSiteEditText);
webSiteEditText.setOnFocusChangeListener(new MyOnFocusChangeListener(getData(), "website"));
final TextView descriptionEditText = (TextView) view.findViewById(R.id.descriptionEditText);
descriptionEditText.setOnFocusChangeListener(new MyOnFocusChangeListener(getData(), "description"));
streetEditText = (EditText) view.findViewById(R.id.streetEditText);
streetEditText.addTextChangedListener(new MyOnFocusChangeListener(getData(),
OSMSettings.OSMTagKey.ADDR_STREET.getValue()));
houseNumberEditText = (EditText) view.findViewById(R.id.houseNumberEditText);
houseNumberEditText.addTextChangedListener(new MyOnFocusChangeListener(getData(),
OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER.getValue()));
phoneEditText = (EditText) view.findViewById(R.id.phoneEditText);
phoneEditText.addTextChangedListener(new MyOnFocusChangeListener(getData(),
OSMSettings.OSMTagKey.PHONE.getValue()));
webSiteEditText = (EditText) view.findViewById(R.id.webSiteEditText);
webSiteEditText.addTextChangedListener(new MyOnFocusChangeListener(getData(),
OSMSettings.OSMTagKey.WEBSITE.getValue()));
descriptionEditText = (EditText) view.findViewById(R.id.descriptionEditText);
descriptionEditText.addTextChangedListener(new MyOnFocusChangeListener(getData(),
OSMSettings.OSMTagKey.DESCRIPTION.getValue()));
openHoursEditText = (EditText) view.findViewById(R.id.openHoursEditText);
openHoursEditText.addTextChangedListener(new MyOnFocusChangeListener(getData(),
OSMSettings.OSMTagKey.OPENING_HOURS.getValue()));
Button saveButton = (Button) view.findViewById(R.id.saveButton);
int saveButtonTextId = //getData().isLocalEdit ? R.string.shared_string_save :
R.string.default_buttons_commit;
saveButton.setText(saveButtonTextId);
saveButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
getEditPoiFragment().send();
}
});
Button cancelButton = (Button) view.findViewById(R.id.cancelButton);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
Fragment editPoiFragment = getParentFragment();
fragmentManager.beginTransaction().remove(editPoiFragment).commit();
fragmentManager.popBackStack();
}
});
return view;
}
@Override
public void onResume() {
super.onResume();
mTagsChangedListener = new EditPoiData.TagsChangedListener() {
@Override
public void onTagsChanged() {
TagMapProcessor tagMapProcessor = new TagMapProcessor();
tagMapProcessor.addFilter(OSMSettings.OSMTagKey.ADDR_STREET.getValue(),
streetEditText);
tagMapProcessor.addFilter(OSMSettings.OSMTagKey.ADDR_HOUSE_NUMBER.getValue(),
houseNumberEditText);
tagMapProcessor.addFilter(OSMSettings.OSMTagKey.PHONE.getValue(),
phoneEditText);
tagMapProcessor.addFilter(OSMSettings.OSMTagKey.WEBSITE.getValue(),
webSiteEditText);
tagMapProcessor.addFilter(OSMSettings.OSMTagKey.DESCRIPTION.getValue(),
descriptionEditText);
tagMapProcessor.addFilter(OSMSettings.OSMTagKey.OPENING_HOURS.getValue(),
openHoursEditText);
mIsUserInput = false;
for (Tag tag : getData().tags) {
tagMapProcessor.process(tag);
}
tagMapProcessor.clearEmptyFields();
mIsUserInput = true;
}
};
getData().addListener(mTagsChangedListener);
}
@Override
public void onPause() {
super.onPause();
getData().deleteListener(mTagsChangedListener);
}
private static class TagMapProcessor {
private final Map<String, EditText> mFilters = new HashMap<>();
public void addFilter(String tag, EditText editText) {
mFilters.put(tag, editText);
}
public void process(Tag tag) {
if (mFilters.containsKey(tag.tag)) {
final EditText editText = mFilters.get(tag.tag);
editText.setText(tag.value);
mFilters.remove(tag.tag);
}
}
public void clearEmptyFields() {
for (String tag : mFilters.keySet()) {
mFilters.get(tag).setText(null);
}
}
}
private EditPoiFragment getEditPoiFragment() {
return (EditPoiFragment) getParentFragment();
}
private EditPoiFragment.EditPoiData getData() {
private EditPoiData getData() {
return getEditPoiFragment().getEditPoiData();
}
private static class MyOnFocusChangeListener implements View.OnFocusChangeListener {
private EditPoiFragment.EditPoiData data;
private String tagName;
private class MyOnFocusChangeListener implements TextWatcher {
private final EditPoiData data;
private final String tagName;
public MyOnFocusChangeListener(EditPoiFragment.EditPoiData data, String tagName) {
public MyOnFocusChangeListener(EditPoiData data,
String tagName) {
this.data = data;
this.tagName = tagName;
}
@Override
public void onFocusChange(View v, boolean hasFocus) {
String string = ((EditText) v).getText().toString();
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
}
@Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
}
@Override
public void afterTextChanged(Editable s) {
if (mIsUserInput) {
String string = s.toString();
if (!TextUtils.isEmpty(string)) {
Tag tag = new Tag(tagName, string);
data.tags.remove(tag);
data.tags.add(tag);
data.notifyDatasetChanged(mTagsChangedListener);
}
}
}
}

View file

@ -22,7 +22,6 @@ import net.osmand.plus.Version;
import net.osmand.util.MapUtils;
import org.apache.commons.logging.Log;
import org.xml.sax.SAXException;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlSerializer;

View file

@ -1,13 +1,20 @@
package net.osmand.plus.osmedit;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Serializable;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Xml;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Toast;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
@ -33,20 +40,13 @@ import org.apache.commons.logging.Log;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.content.DialogInterface;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PointF;
import android.os.AsyncTask;
import android.os.Bundle;
import android.util.Xml;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.Toast;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.Serializable;
import java.net.URLConnection;
import java.util.ArrayList;
import java.util.List;
public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider, DialogProvider {
@ -333,8 +333,8 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
}
private void prepareOpenBugDialog(Dialog dlg, Bundle args) {
((EditText)dlg.findViewById(R.id.BugMessage)).setText(args.getString(KEY_MESSAGE));
((EditText)dlg.findViewById(R.id.AuthorName)).setText(args.getString(KEY_AUTHOR));
((EditText)dlg.findViewById(R.id.messageEditText)).setText(args.getString(KEY_MESSAGE));
((EditText)dlg.findViewById(R.id.userNameEditText)).setText(args.getString(KEY_AUTHOR));
}
private Dialog createOpenBugDialog(final Bundle args) {
@ -343,9 +343,9 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
builder.setTitle(R.string.osb_add_dialog_title);
builder.setView(openBug);
builder.setNegativeButton(R.string.shared_string_cancel, null);
((EditText)openBug.findViewById(R.id.Password)).setText(((OsmandApplication) activity.getApplication()).getSettings().USER_PASSWORD.get());
((EditText)openBug.findViewById(R.id.AuthorName)).setText(getUserName());
AndroidUtils.softKeyboardDelayed((EditText)openBug.findViewById(R.id.BugMessage));
((EditText)openBug.findViewById(R.id.passwordEditText)).setText(((OsmandApplication) activity.getApplication()).getSettings().USER_PASSWORD.get());
((EditText)openBug.findViewById(R.id.userNameEditText)).setText(getUserName());
AndroidUtils.softKeyboardDelayed((EditText)openBug.findViewById(R.id.messageEditText));
builder.setPositiveButton(R.string.shared_string_add, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
@ -426,9 +426,9 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
builder.setTitle(R.string.osb_comment_dialog_title);
final View view = activity.getLayoutInflater().inflate(R.layout.open_bug, null);
builder.setView(view);
((EditText)view.findViewById(R.id.AuthorName)).setText(getUserName());
((EditText)view.findViewById(R.id.Password)).setText(((OsmandApplication) activity.getApplication()).getSettings().USER_PASSWORD.get());
AndroidUtils.softKeyboardDelayed((EditText)view.findViewById(R.id.BugMessage));
((EditText)view.findViewById(R.id.userNameEditText)).setText(getUserName());
((EditText)view.findViewById(R.id.passwordEditText)).setText(((OsmandApplication) activity.getApplication()).getSettings().USER_PASSWORD.get());
AndroidUtils.softKeyboardDelayed((EditText)view.findViewById(R.id.messageEditText));
builder.setNegativeButton(R.string.shared_string_cancel, null);
builder.setPositiveButton(R.string.osb_comment_dialog_add_button, new DialogInterface.OnClickListener() {
@Override
@ -446,9 +446,9 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
}
private String getTextAndUpdateUserPwd(final View view) {
String text = ((EditText)view.findViewById(R.id.BugMessage)).getText().toString();
String author = ((EditText)view.findViewById(R.id.AuthorName)).getText().toString();
String pwd = ((EditText)view.findViewById(R.id.Password)).getText().toString();
String text = ((EditText)view.findViewById(R.id.messageEditText)).getText().toString();
String author = ((EditText)view.findViewById(R.id.userNameEditText)).getText().toString();
String pwd = ((EditText)view.findViewById(R.id.passwordEditText)).getText().toString();
((OsmandApplication) OsmBugsLayer.this.activity.getApplication()).getSettings().USER_NAME.set(author);
((OsmandApplication) OsmBugsLayer.this.activity.getApplication()).getSettings().USER_PASSWORD.set(pwd);
return text;
@ -583,7 +583,7 @@ public class OsmBugsLayer extends OsmandMapLayer implements IContextMenuProvider
public void onPrepareDialog(int id, Dialog dialog) {
switch (id) {
case DIALOG_COMMENT_BUG:
((EditText)dialog.findViewById(R.id.BugMessage)).setText("");
((EditText)dialog.findViewById(R.id.messageEditText)).setText("");
break;
}
}

View file

@ -139,7 +139,10 @@ public class OsmEditingPlugin extends OsmandPlugin {
}
@Override
public void registerMapContextMenuActions(final MapActivity mapActivity, final double latitude, final double longitude, ContextMenuAdapter adapter,
public void registerMapContextMenuActions(final MapActivity mapActivity,
final double latitude,
final double longitude,
ContextMenuAdapter adapter,
final Object selectedObj) {
OnContextMenuClick listener = new OnContextMenuClick() {
@Override

View file

@ -0,0 +1,31 @@
package net.osmand.plus.osmedit.data;
import net.osmand.data.Amenity;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;
public class EditPoiData {
private Set<TagsChangedListener> mListeners = new HashSet<>();
public LinkedHashSet<Tag> tags;
public Amenity amenity;
public void notifyDatasetChanged(TagsChangedListener listenerToSkip) {
for (TagsChangedListener listener : mListeners) {
if (listener != listenerToSkip) listener.onTagsChanged();
}
}
public void addListener(TagsChangedListener listener) {
mListeners.add(listener);
}
public void deleteListener(TagsChangedListener listener) {
mListeners.remove(listener);
}
public interface TagsChangedListener {
void onTagsChanged();
}
}

View file

@ -0,0 +1,34 @@
package net.osmand.plus.osmedit.data;
import java.io.Serializable;
public class Tag implements Serializable {
public String tag;
public String value;
public Tag(String tag, String value) {
this.tag = tag;
this.value = value;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Tag tag1 = (Tag) o;
return tag.equals(tag1.tag);
}
@Override
public int hashCode() {
return tag.hashCode();
}
@Override
public String toString() {
return "Tag{" +
"tag='" + tag + '\'' +
", value='" + value + '\'' +
'}';
}
}

View file

@ -0,0 +1,47 @@
package net.osmand.plus.osmedit.dialogs;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import net.osmand.data.Amenity;
import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.PoiType;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.osmedit.EditPoiFragment;
import java.util.Map;
public class PoiSubTypeDialogFragment extends DialogFragment {
private static final String KEY_AMENITY = "amenity";
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
MapPoiTypes poiTypes = ((OsmandApplication) getActivity().getApplication()).getPoiTypes();
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
final Amenity a = (Amenity) getArguments().getSerializable(KEY_AMENITY);
final Map<String, PoiType> allTranslatedNames = poiTypes.getAllTranslatedNames(a.getType(), true);
// (=^.^=)
final String[] subCats = allTranslatedNames.keySet().toArray(new String[0]);
builder.setItems(subCats, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
((EditPoiFragment) getParentFragment()).setSubCategory(subCats[which]);
dismiss();
}
});
return builder.create();
}
public static PoiSubTypeDialogFragment createInstance(Amenity amenity) {
PoiSubTypeDialogFragment fragment = new PoiSubTypeDialogFragment();
Bundle args = new Bundle();
args.putSerializable(KEY_AMENITY, amenity);
fragment.setArguments(args);
return fragment;
}
}

View file

@ -0,0 +1,54 @@
package net.osmand.plus.osmedit.dialogs;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.DialogFragment;
import net.osmand.data.Amenity;
import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.PoiCategory;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.osmedit.EditPoiFragment;
import java.util.List;
public class PoiTypeDialogFragment extends DialogFragment {
private static final String KEY_AMENITY = "amenity";
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
MapPoiTypes poiTypes = ((OsmandApplication) getActivity().getApplication()).getPoiTypes();
final Amenity amenity = (Amenity) getArguments().getSerializable(KEY_AMENITY);
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
final List<PoiCategory> categories = poiTypes.getCategories(false);
String[] vals = new String[categories.size()];
for (int i = 0; i < vals.length; i++) {
vals[i] = categories.get(i).getTranslation();
}
builder.setItems(vals, new Dialog.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
PoiCategory aType = categories.get(which);
if (aType != amenity.getType()) {
amenity.setType(aType);
amenity.setSubType(""); //$NON-NLS-1$
((EditPoiFragment) getParentFragment()).updateType(amenity);
}
dismiss();
}
});
return builder.create();
}
public static PoiTypeDialogFragment createInstance(Amenity amenity) {
PoiTypeDialogFragment poiTypeDialogFragment = new PoiTypeDialogFragment();
Bundle args = new Bundle();
args.putSerializable(KEY_AMENITY, amenity);
poiTypeDialogFragment.setArguments(args);
return poiTypeDialogFragment;
}
}

Binary file not shown.

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2013 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="android.support.v7.recyclerview">
<uses-sdk android:minSdkVersion="7"/>
</manifest>

View file

@ -0,0 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2015 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources>
<declare-styleable name="RecyclerView">
<!-- Class name of the Layout Manager to be used.
<p/>
The class must extend android.support.v7.widget.RecyclerView$LayoutManager
and have either a default constructor or constructor with the signature
(android.content.Context, android.util.AttributeSet, int, int).
<p/>
If the name starts with a '.', application package is prefixed.
Else, if the name contains a '.', the classname is assumed to be a full class name.
Else, the recycler view package name (android.support.v7.widget) is prefixed. -->
<attr name="layoutManager" format="string" />
<!-- ============================= -->
<!-- Attributes for Layout Manager -->
<!-- ============================= -->
<eat-comment />
<attr name="android:orientation" />
<attr name="spanCount" format="integer"/>
<attr name="reverseLayout" format="boolean" />
<attr name="stackFromEnd" format="boolean" />
</declare-styleable>
</resources>

View file

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2015 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->
<resources>
<!-- The max amount of scroll ItemTouchHelper will trigger if dragged view is out of
RecyclerView's bounds.-->
<dimen name="item_touch_helper_max_drag_scroll_per_frame">20dp</dimen>
</resources>

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2015 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<resources>
<!-- ItemTouchHelper uses this id to save a View's original elevation. -->
<item type="id" name="item_touch_helper_previous_elevation"/>
</resources>