Fix - Context menu (android 2.3 support). Added custom icons to POI info

This commit is contained in:
Alexey Kulish 2015-09-15 15:30:01 +03:00
parent d1f532b3c3
commit 705f29cd54
5 changed files with 126 additions and 72 deletions

View file

@ -2,27 +2,26 @@
<FrameLayout
android:id="@+id/context_menu_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/transparent"
android:orientation="vertical">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent">
<LinearLayout
android:id="@+id/context_menu_shadow_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"/>
<LinearLayout
android:id="@+id/context_menu_main"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="@+id/context_menu_top_shadow"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="20dp"
android:orientation="horizontal">
@ -30,14 +29,14 @@
<LinearLayout
android:id="@+id/context_menu_top_shadow_all"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_map_context_menu"
android:orientation="vertical">
<LinearLayout
android:id="@+id/context_menu_top_view"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:baselineAligned="false"
android:orientation="horizontal">
@ -124,7 +123,7 @@
<ImageButton
android:id="@+id/context_menu_route_button"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
@ -139,7 +138,7 @@
<ImageButton
android:id="@+id/context_menu_fav_button"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
@ -154,7 +153,7 @@
<ImageButton
android:id="@+id/context_menu_share_button"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
@ -169,7 +168,7 @@
<ImageButton
android:id="@+id/context_menu_more_button"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_vertical"
android:layout_weight="1"
@ -183,14 +182,14 @@
<ScrollView
android:id="@+id/context_menu_bottom_scroll"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/ctx_menu_info_view_bg"
android:fillViewport="true">
<LinearLayout
android:id="@+id/context_menu_bottom_view"
android:layout_width="fill_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">

View file

@ -184,7 +184,7 @@ public class MapContextMenuFragment extends Fragment {
lastTouchDown = System.currentTimeMillis();
dy = event.getY();
dyMain = mainView.getY();
dyMain = getViewY();
velocity = VelocityTracker.obtain();
velocityX = 0;
velocityY = 0;
@ -194,14 +194,16 @@ public class MapContextMenuFragment extends Fragment {
case MotionEvent.ACTION_MOVE:
float y = event.getY();
float newY = mainView.getY() + (y - dy);
mainView.setY((int)newY);
float newY = getViewY() + (y - dy);
setViewY((int) newY);
menuFullHeight = view.getHeight() - (int) newY + 10;
ViewGroup.LayoutParams lp = mainView.getLayoutParams();
lp.height = Math.max(menuFullHeight, menuTitleHeight);
mainView.setLayoutParams(lp);
mainView.requestLayout();
if (!oldAndroid()) {
ViewGroup.LayoutParams lp = mainView.getLayoutParams();
lp.height = Math.max(menuFullHeight, menuTitleHeight);
mainView.setLayoutParams(lp);
mainView.requestLayout();
}
velocity.addMovement(event);
velocity.computeCurrentVelocity(1000);
@ -217,8 +219,10 @@ public class MapContextMenuFragment extends Fragment {
float endX = event.getX();
float endY = event.getY();
slidingUp = Math.abs(maxVelocityY) > 500 && (mainView.getY() - dyMain) < -50;
slidingDown = Math.abs(maxVelocityY) > 500 && (mainView.getY() - dyMain) > 50;
int currentY = getViewY();
slidingUp = Math.abs(maxVelocityY) > 500 && (currentY - dyMain) < -50;
slidingDown = Math.abs(maxVelocityY) > 500 && (currentY - dyMain) > 50;
velocity.recycle();
@ -232,27 +236,32 @@ public class MapContextMenuFragment extends Fragment {
final int posY = getPosY();
if (mainView.getY() != posY) {
if (currentY != posY) {
if (posY < mainView.getY()) {
if (posY < getViewY()) {
updateMainViewLayout(posY);
}
mainView.animate().y(posY)
.setDuration(200)
.setInterpolator(new DecelerateInterpolator())
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationCancel(Animator animation) {
updateMainViewLayout(posY);
}
if (!oldAndroid()) {
mainView.animate().y(posY)
.setDuration(200)
.setInterpolator(new DecelerateInterpolator())
.setListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationCancel(Animator animation) {
updateMainViewLayout(posY);
}
@Override
public void onAnimationEnd(Animator animation) {
updateMainViewLayout(posY);
}
})
.start();
@Override
public void onAnimationEnd(Animator animation) {
updateMainViewLayout(posY);
}
})
.start();
} else {
setViewY(posY);
updateMainViewLayout(posY);
}
}
// OnClick event
@ -409,17 +418,38 @@ public class MapContextMenuFragment extends Fragment {
}
private void updateMainViewLayout(int posY) {
ViewGroup.LayoutParams lp;
menuFullHeight = view.getHeight() - posY;
lp = mainView.getLayoutParams();
lp.height = Math.max(menuFullHeight, menuTitleHeight);
mainView.setLayoutParams(lp);
mainView.requestLayout();
if (!oldAndroid()) {
ViewGroup.LayoutParams lp = mainView.getLayoutParams();
lp.height = Math.max(menuFullHeight, menuTitleHeight);
mainView.setLayoutParams(lp);
mainView.requestLayout();
}
}
private int getViewY() {
if (!oldAndroid()) {
return (int)mainView.getY();
} else {
return mainView.getPaddingTop();
}
}
private void setViewY(int y) {
if (!oldAndroid()) {
mainView.setY(y);
} else {
mainView.setPadding(0, y, 0, 0);
}
}
private boolean oldAndroid() {
return (Build.VERSION.SDK_INT < Build.VERSION_CODES.ICE_CREAM_SANDWICH);
}
private void doLayoutMenu() {
final int posY = getPosY();
mainView.setY(posY);
setViewY(posY);
updateMainViewLayout(posY);
}

View file

@ -1,6 +1,7 @@
package net.osmand.plus.mapcontextmenu.sections;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.text.util.Linkify;
import android.util.TypedValue;
import android.view.Gravity;
@ -32,11 +33,15 @@ public class AmenityInfoMenuBuilder extends MenuBuilder {
}
private void buildRow(View view, int iconId, String text, boolean firstRow) {
buildRow(view, getRowIcon(iconId), text, firstRow);
}
private void buildRow(View view, Drawable icon, String text, boolean firstRow) {
boolean light = app.getSettings().isLightContent();
LinearLayout ll = new LinearLayout(view.getContext());
ll.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams llParams = 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(14f), 0, dpToPx(14f));
ll.setLayoutParams(llParams);
@ -47,21 +52,21 @@ public class AmenityInfoMenuBuilder extends MenuBuilder {
llIcon.setGravity(Gravity.CENTER_VERTICAL);
ll.addView(llIcon);
ImageView icon = new ImageView(view.getContext());
LinearLayout.LayoutParams llIconParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT) ;
ImageView iconView = new ImageView(view.getContext());
LinearLayout.LayoutParams llIconParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
llIconParams.setMargins(dpToPx(16f), firstRow ? dpToPx(12f) - dpToPx(SHADOW_HEIGHT_BOTTOM_DP / 2f) : dpToPx(12f), dpToPx(32f), dpToPx(12f));
llIconParams.gravity = Gravity.CENTER_VERTICAL;
icon.setLayoutParams(llIconParams);
icon.setScaleType(ImageView.ScaleType.CENTER);
icon.setImageDrawable(getRowIcon(iconId));
llIcon.addView(icon);
iconView.setLayoutParams(llIconParams);
iconView.setScaleType(ImageView.ScaleType.CENTER);
iconView.setImageDrawable(icon);
llIcon.addView(iconView);
// Text
LinearLayout llText = new LinearLayout(view.getContext());
llText.setOrientation(LinearLayout.VERTICAL);
ll.addView(llText);
TextView textView = new TextView(view.getContext());
TextView textView = new TextView(view.getContext());
LinearLayout.LayoutParams llTextParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
llTextParams.setMargins(0, firstRow ? dpToPx(8f) - dpToPx(SHADOW_HEIGHT_BOTTOM_DP) : dpToPx(8f), 0, dpToPx(8f));
textView.setLayoutParams(llTextParams);
@ -87,7 +92,7 @@ public class AmenityInfoMenuBuilder extends MenuBuilder {
llText.setLayoutParams(llTextViewParams);
llText.addView(textView);
((LinearLayout)view).addView(ll);
((LinearLayout) view).addView(ll);
View horizontalLine = new View(view.getContext());
LinearLayout.LayoutParams llHorLineParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, dpToPx(1f));
@ -96,7 +101,7 @@ public class AmenityInfoMenuBuilder extends MenuBuilder {
horizontalLine.setBackgroundColor(app.getResources().getColor(light ? R.color.ctx_menu_info_divider_light : R.color.ctx_menu_info_divider_dark));
((LinearLayout)view).addView(horizontalLine);
((LinearLayout) view).addView(horizontalLine);
}
public int dpToPx(float dp) {
@ -114,17 +119,18 @@ public class AmenityInfoMenuBuilder extends MenuBuilder {
boolean firstRow = true;
MapPoiTypes poiTypes = app.getPoiTypes();
for(Map.Entry<String, String> e : amenity.getAdditionalInfo().entrySet()) {
int iconId;
for (Map.Entry<String, String> e : amenity.getAdditionalInfo().entrySet()) {
int iconId = 0;
Drawable icon = null;
String key = e.getKey();
String vl = e.getValue();
if(key.startsWith("name:")) {
if (key.startsWith("name:")) {
continue;
} else if(Amenity.OPENING_HOURS.equals(key)) {
} else if (Amenity.OPENING_HOURS.equals(key)) {
iconId = R.drawable.ic_action_time;
} else if(Amenity.PHONE.equals(key)) {
} else if (Amenity.PHONE.equals(key)) {
iconId = R.drawable.ic_action_call_dark;
} else if(Amenity.WEBSITE.equals(key)) {
} else if (Amenity.WEBSITE.equals(key)) {
iconId = R.drawable.ic_world_globe_dark;
} else {
if (Amenity.DESCRIPTION.equals(key)) {
@ -132,9 +138,13 @@ public class AmenityInfoMenuBuilder extends MenuBuilder {
} else {
iconId = R.drawable.ic_action_info_dark;
}
AbstractPoiType pt = poiTypes.getAnyPoiAdditionalTypeByKey(e.getKey());
AbstractPoiType pt = poiTypes.getAnyPoiAdditionalTypeByKey(key);
if (pt != null) {
if(pt instanceof PoiType && !((PoiType) pt).isText()) {
PoiType pType = (PoiType) pt;
if (pType.getParentType() != null && pType.getParentType() instanceof PoiType) {
icon = getRowIcon(view.getContext(), ((PoiType) pType.getParentType()).getOsmTag() + "_" + pType.getOsmTag().replace(':', '_') + "_" + pType.getOsmValue());
}
if (pt instanceof PoiType && !((PoiType) pt).isText()) {
vl = pt.getTranslation();
} else {
vl = pt.getTranslation() + ": " + amenity.unzipContent(e.getValue());
@ -145,7 +155,12 @@ public class AmenityInfoMenuBuilder extends MenuBuilder {
}
}
buildRow(view, iconId, vl, firstRow);
if (icon != null) {
buildRow(view, icon, vl, firstRow);
} else {
buildRow(view, iconId, vl, firstRow);
}
firstRow = false;
}
}

View file

@ -1,11 +1,15 @@
package net.osmand.plus.mapcontextmenu.sections;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.view.View;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.render.RenderingIcons;
public abstract class MenuBuilder {
@ -27,4 +31,12 @@ public abstract class MenuBuilder {
light ? R.color.icon_color : R.color.icon_color_light);
}
public Drawable getRowIcon(Context ctx, String fileName) {
Bitmap iconBitmap = RenderingIcons.getIcon(ctx, fileName, false);
if (iconBitmap != null) {
return new BitmapDrawable(ctx.getResources(), iconBitmap);
} else {
return null;
}
}
}

View file

@ -200,10 +200,8 @@ public class ContextMenuLayer extends OsmandMapLayer {
}
public void showMapContextMenuMarker() {
if (!showContextMarker) {
showContextMarker = true;
view.refreshMap();
}
showContextMarker = true;
view.refreshMap();
}
public void hideMapContextMenuMarker() {