Added POI info fields to the context menu

This commit is contained in:
Alexey Kulish 2015-09-08 17:53:57 +03:00
parent 73c1664ff8
commit 748337ada6
4 changed files with 51 additions and 80 deletions

View file

@ -177,7 +177,7 @@
android:id="@+id/context_menu_bottom_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
android:orientation="vertical">
<View
android:layout_width="match_parent"

View file

@ -1,7 +1,6 @@
package net.osmand.plus.mapcontextmenu;
import android.content.res.Resources;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
@ -16,7 +15,6 @@ import net.osmand.osm.MapPoiTypes;
import net.osmand.osm.PoiType;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.util.Algorithms;
import java.util.Map;
@ -33,63 +31,11 @@ public class InfoSectionBuilder extends BottomSectionBuilder {
private void buildRow(View view, int iconId, String text) {
/*
<LinearLayout
android:id="@+id/context_menu_top_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:id="@+id/context_menu_icon_layout"
android:orientation="horizontal"
android:layout_width="42dp"
android:layout_height="match_parent">
<ImageView
android:id="@+id/context_menu_icon_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:scaleType="center"
android:layout_marginStart="12dp"
android:layout_marginLeft="12dp"
android:src="@drawable/ic_action_building_number"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
android:orientation="vertical">
<TextView
android:id="@+id/context_menu_line1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:text="@string/search_address_building"
android:textSize="@dimen/default_list_text_size_large"
android:textColor="?android:textColorPrimary"
android:textStyle="bold"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:background="#c9c9c9"/>
*/
LinearLayout ll = new LinearLayout(view.getContext());
ll.setOrientation(LinearLayout.HORIZONTAL);
ll.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT) ;
llParams.setMargins(0, dpToPx(10f), 0, dpToPx(10f));
ll.setLayoutParams(llParams);
// Icon
LinearLayout llIcon = new LinearLayout(view.getContext());
@ -98,9 +44,9 @@ public class InfoSectionBuilder extends BottomSectionBuilder {
ll.addView(llIcon);
ImageView icon = new ImageView(view.getContext());
ViewGroup.MarginLayoutParams llIconParams = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
LinearLayout.LayoutParams llIconParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT) ;
llIconParams.setMargins(dpToPx(12f), 0, 0, 0);
//llIconParams.setGravity(Gravity.CENTER_VERTICAL);
llIconParams.gravity = Gravity.CENTER_VERTICAL;
icon.setLayoutParams(llIconParams);
icon.setScaleType(ImageView.ScaleType.CENTER);
icon.setImageDrawable(getRowIcon(iconId));
@ -109,15 +55,33 @@ public class InfoSectionBuilder extends BottomSectionBuilder {
// Text
LinearLayout llText = new LinearLayout(view.getContext());
llText.setOrientation(LinearLayout.VERTICAL);
ViewGroup.MarginLayoutParams llTextParams = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
llTextParams.setMargins(0, dpToPx(4f), 0, dpToPx(4f));
llText.setLayoutParams(llTextParams);
ll.addView(llText);
TextView textView = new TextView(view.getContext());
ViewGroup.MarginLayoutParams llTextViewParams = new ViewGroup.MarginLayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
LinearLayout.LayoutParams llTextViewParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
llTextViewParams.setMargins(dpToPx(10f), 0, dpToPx(10f), 0);
llText.setLayoutParams(llTextViewParams);
textView.setText(text);
//textView.setText("sdf dsaf fsdasdfg adsf asdsfd asdf sdf adsfg asdf sdfa sdf dsf agsfdgd fgsfd sdf asdf adg adf sdf asdf dfgdfsg sdfg adsf asdf asdf sdf SDF ASDF ADSF ASDF ASDF DAF SDAF dfg dsfg dfg sdfg rg rth sfghs dfgs dfgsdfg adfg dfg sdfg dfs ");
llText.addView(textView);
((LinearLayout)view).addView(ll);
View horizontalLine = new View(view.getContext());
LinearLayout.LayoutParams llHorLineParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dpToPx(1f));
llHorLineParams.gravity = Gravity.BOTTOM;
horizontalLine.setLayoutParams(llHorLineParams);
TypedValue typedValue = new TypedValue();
Resources.Theme theme = view.getContext().getTheme();
theme.resolveAttribute(R.attr.dashboard_divider, typedValue, true);
int color = typedValue.data;
horizontalLine.setBackgroundColor(color);
((LinearLayout)view).addView(horizontalLine);
}
public int dpToPx(float dp) {

View file

@ -10,7 +10,6 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.DecelerateInterpolator;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
@ -21,12 +20,9 @@ import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.search.SearchActivity;
import org.apache.commons.logging.Log;
import java.util.Map;
public class MapContextMenuFragment extends Fragment {
@ -206,6 +202,12 @@ public class MapContextMenuFragment extends Fragment {
BottomSectionBuilder bottomSectionBuilder = MapContextMenu.getInstance().getBottomSectionBuilder();
if (bottomSectionBuilder != null) {
View bottomView = view.findViewById(R.id.context_menu_bottom_view);
bottomView.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return true;
}
});
bottomSectionBuilder.buildSection(bottomView);
}

View file

@ -30,7 +30,6 @@ import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;
public class ContextMenuLayer extends OsmandMapLayer {
@ -65,6 +64,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
private String description;
private Map<Object, IContextMenuProvider> selectedObjects = new ConcurrentHashMap<Object, IContextMenuProvider>();
private Object selectedObj;
private IContextMenuProvider contextObject;
private TextView textView;
private ImageView closeButton;
@ -274,7 +274,8 @@ public class ContextMenuLayer extends OsmandMapLayer {
if (selectedObjects.size() == 1) {
setLocation(null, "");
selectedObj = selectedObjects.keySet().iterator().next();
showMapContextMenu(selectedObj, latLon);
contextObject = selectedObjects.get(selectedObj);
showMapContextMenu(latLon);
} else if (selectedObjects.size() > 1) {
showContextMenuForSelectedObjects(latLon);
}
@ -282,7 +283,9 @@ public class ContextMenuLayer extends OsmandMapLayer {
setLocation(null, "");
final double lat = tileBox.getLatFromPixel((int) point.x, (int) point.y);
final double lon = tileBox.getLonFromPixel((int) point.x, (int) point.y);
showMapContextMenu(null, new LatLon(lat, lon));
selectedObj = null;
contextObject = null;
showMapContextMenu(new LatLon(lat, lon));
//setLocation(new LatLon(lat, lon), null);
}
view.refreshMap();
@ -424,7 +427,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
@Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
if (pressedContextMarker(tileBox, point.x, point.y)) {
showMapContextMenu(selectedObj, latLon);
showMapContextMenu(latLon);
return true;
}
@ -455,7 +458,8 @@ public class ContextMenuLayer extends OsmandMapLayer {
if (selectedObjects.size() == 1) {
setLocation(null, "");
selectedObj = selectedObjects.keySet().iterator().next();
showMapContextMenu(selectedObj, latLon);
contextObject = selectedObjects.get(selectedObj);
showMapContextMenu(latLon);
} else if (selectedObjects.size() > 1) {
showContextMenuForSelectedObjects(latLon);
return true;
@ -482,22 +486,23 @@ public class ContextMenuLayer extends OsmandMapLayer {
@Override
public void onClick(DialogInterface dialog, int which) {
selectedObj = s.get(which);
showMapContextMenu(selectedObj, l);
contextObject = selectedObjects.get(selectedObj);
showMapContextMenu(l);
}
});
builder.show();
} else {
selectedObj = selectedObjects.keySet().iterator().next();
showMapContextMenu(selectedObj, l);
contextObject = selectedObjects.get(selectedObj);
showMapContextMenu(l);
}
}
private void showMapContextMenu(Object obj, LatLon latLon) {
private void showMapContextMenu(LatLon latLon) {
PointDescription pointDescription;
if (obj != null) {
IContextMenuProvider typedObj = selectedObjects.get(obj);
pointDescription = typedObj.getObjectName(obj);
LatLon objLocation = typedObj.getObjectLocation(obj);
if (selectedObj != null && contextObject != null) {
pointDescription = contextObject.getObjectName(selectedObj);
LatLon objLocation = contextObject.getObjectLocation(selectedObj);
pointDescription.setLat(objLocation.getLatitude());
pointDescription.setLon(objLocation.getLongitude());
} else {
@ -506,7 +511,7 @@ public class ContextMenuLayer extends OsmandMapLayer {
this.latLon = new LatLon(pointDescription.getLat(), pointDescription.getLon());
showMapContextMenuMarker();
MapContextMenu.getInstance().show(pointDescription, obj);
MapContextMenu.getInstance().show(pointDescription, selectedObj);
}