Add some info from AMapPoint to the Context Menu

This commit is contained in:
Alex Sytnyk 2018-08-01 15:56:27 +03:00
parent 1d878e1923
commit 918ada71c9
6 changed files with 126 additions and 35 deletions

View file

@ -173,6 +173,17 @@
android:layout_marginRight="@dimen/context_menu_padding_margin_small"
tools:text="Closed till 10:00"/>
<TextView
android:id="@+id/info_compass_separator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/context_menu_padding_margin_small"
android:layout_marginRight="@dimen/context_menu_padding_margin_small"
android:text="•"
android:textColor="@color/icon_color"
android:visibility="gone"
tools:visibility="visible"/>
<LinearLayout
android:id="@+id/compass_layout"
android:layout_width="wrap_content"

View file

@ -12,6 +12,8 @@ import java.util.Map;
public class AMapPoint implements Parcelable {
public static final String POINT_IMAGE_URI_PARAM = "point_image_uri_param";
public static final String POINT_SPEED_PARAM = "point_speed_param";
public static final String POINT_TYPE_ICON_NAME_PARAM = "point_type_icon_name_param";
private String id;
private String shortName;

View file

@ -1279,6 +1279,13 @@ public class MapContextMenu extends MenuTitleController implements StateChangedL
return 0;
}
public boolean isShowInfoCompassSeparator() {
if (menuController != null) {
return menuController.isShowInfoCompassSeparator();
}
return false;
}
public boolean isMapDownloaded() {
return menuController != null && menuController.isMapDownloaded();
}

View file

@ -1,36 +1,5 @@
package net.osmand.plus.mapcontextmenu;
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
import static net.osmand.plus.mapcontextmenu.MenuBuilder.SHADOW_HEIGHT_TOP_DP;
import java.util.List;
import net.osmand.AndroidUtils;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadPoint;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.LockableScrollView;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities.UpdateLocationViewCache;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.mapcontextmenu.MenuController.MenuState;
import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController;
import net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController;
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController;
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu;
import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.TransportStopsLayer;
import net.osmand.plus.views.controls.HorizontalSwipeConfirm;
import net.osmand.plus.views.controls.SingleTapConfirm;
import net.osmand.util.Algorithms;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.annotation.TargetApi;
@ -66,6 +35,38 @@ import android.widget.OverScroller;
import android.widget.ProgressBar;
import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.data.QuadPoint;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.LockableScrollView;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities.UpdateLocationViewCache;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.download.DownloadIndexesThread.DownloadEvents;
import net.osmand.plus.mapcontextmenu.MenuController.MenuState;
import net.osmand.plus.mapcontextmenu.MenuController.TitleButtonController;
import net.osmand.plus.mapcontextmenu.MenuController.TitleProgressController;
import net.osmand.plus.mapcontextmenu.controllers.TransportStopController;
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu;
import net.osmand.plus.transport.TransportStopRoute;
import net.osmand.plus.views.AnimateDraggingMapThread;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.TransportStopsLayer;
import net.osmand.plus.views.controls.HorizontalSwipeConfirm;
import net.osmand.plus.views.controls.SingleTapConfirm;
import net.osmand.util.Algorithms;
import java.util.List;
import static android.util.TypedValue.COMPLEX_UNIT_DIP;
import static net.osmand.plus.mapcontextmenu.MenuBuilder.SHADOW_HEIGHT_TOP_DP;
public class MapContextMenuFragment extends BaseOsmAndFragment implements DownloadEvents {
public static final String TAG = "MapContextMenuFragment";
@ -1495,6 +1496,9 @@ public class MapContextMenuFragment extends BaseOsmAndFragment implements Downlo
additionalInfoTextView.setVisibility(View.GONE);
}
additionalInfoImageView.setVisibility(showAdditionalImage ? View.VISIBLE : View.GONE);
view.findViewById(R.id.info_compass_separator)
.setVisibility(menu.isShowInfoCompassSeparator() ? View.VISIBLE : View.GONE);
}
updateCompassVisibility();
updateAdditionalInfoVisibility();

View file

@ -528,6 +528,10 @@ public abstract class MenuController extends BaseMenuController implements Colla
return 0;
}
public boolean isShowInfoCompassSeparator() {
return false;
}
private boolean shouldShowMapSize() {
return indexItem != null && !downloaded;
}

View file

@ -12,6 +12,8 @@ import android.text.TextUtils;
import net.osmand.aidl.maplayer.point.AMapPoint;
import net.osmand.data.LatLon;
import net.osmand.data.PointDescription;
import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.mapcontextmenu.MenuBuilder;
@ -24,6 +26,9 @@ import java.io.InputStream;
public class AMapPointMenuController extends MenuController {
private static final float NO_SPEED = -1;
private static final int NO_ICON = 0;
private AMapPoint point;
private Drawable pointDrawable;
@ -74,11 +79,11 @@ public class AMapPointMenuController extends MenuController {
@Override
public Drawable getSecondLineTypeIcon() {
if (!Algorithms.isEmpty(point.getShortName())) {
return getIcon(R.drawable.ic_small_group);
} else {
return null;
int id = getPointTypeIconId();
if (id != NO_ICON) {
return getIcon(id);
}
return null;
}
@NonNull
@ -102,11 +107,69 @@ public class AMapPointMenuController extends MenuController {
}
}
@Override
public int getAdditionalInfoColorId() {
return R.color.icon_color;
}
@Override
public CharSequence getAdditionalInfoStr() {
MapActivity activity = getMapActivity();
if (activity != null) {
float speed = getPointSpeed();
if (speed != NO_SPEED) {
String formatted = OsmAndFormatter.getFormattedSpeed(speed, activity.getMyApplication());
return activity.getString(R.string.map_widget_speed) + ": " + formatted;
}
}
return super.getAdditionalInfoStr();
}
@Override
public int getAdditionalInfoIconRes() {
if (getPointSpeed() != NO_SPEED) {
return R.drawable.ic_action_speed_16;
}
return super.getAdditionalInfoIconRes();
}
@Override
public boolean isShowInfoCompassSeparator() {
return getPointSpeed() != NO_SPEED;
}
@Override
public boolean needStreetName() {
return false;
}
private int getPointTypeIconId() {
MapActivity activity = getMapActivity();
if (activity != null) {
String iconName = point.getParams().get(AMapPoint.POINT_TYPE_ICON_NAME_PARAM);
if (!TextUtils.isEmpty(iconName)) {
OsmandApplication app = activity.getMyApplication();
return app.getResources().getIdentifier(iconName, "drawable", app.getPackageName());
}
}
if (!TextUtils.isEmpty(point.getShortName())) {
return R.drawable.ic_small_group;
}
return NO_ICON;
}
private float getPointSpeed() {
String speed = point.getParams().get(AMapPoint.POINT_SPEED_PARAM);
if (!TextUtils.isEmpty(speed)) {
try {
return Float.parseFloat(speed);
} catch (NumberFormatException e) {
return NO_SPEED;
}
}
return NO_SPEED;
}
@Nullable
private Drawable getPointDrawable() {
MapActivity mapActivity = getMapActivity();