Added empty state card
This commit is contained in:
parent
f5eb8f05fa
commit
36750a3dc8
27 changed files with 320 additions and 199 deletions
|
@ -1,18 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:bottom="-10dp"
|
||||
android:left="-10dp"
|
||||
android:right="-10dp"
|
||||
android:top="-10dp">
|
||||
<shape android:shape="rectangle">
|
||||
<stroke
|
||||
android:width="12dp"
|
||||
android:color="@color/ctx_menu_info_view_bg_dark" />
|
||||
<corners android:radius="8dp" />
|
||||
</shape>
|
||||
</item>
|
||||
<item>
|
||||
<nine-patch android:src="@drawable/bg_card_shadow" />
|
||||
<nine-patch android:src="@drawable/bg_card_shadow_grey_night" />
|
||||
</item>
|
||||
</layer-list>
|
||||
|
|
|
@ -1,18 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item
|
||||
android:bottom="-10dp"
|
||||
android:left="-10dp"
|
||||
android:right="-10dp"
|
||||
android:top="-10dp">
|
||||
<shape android:shape="rectangle">
|
||||
<stroke
|
||||
android:width="12dp"
|
||||
android:color="@color/ctx_menu_info_view_bg_light" />
|
||||
<corners android:radius="8dp" />
|
||||
</shape>
|
||||
</item>
|
||||
<item>
|
||||
<nine-patch android:src="@drawable/bg_card_shadow" />
|
||||
<nine-patch android:src="@drawable/bg_card_shadow_grey_day" />
|
||||
</item>
|
||||
</layer-list>
|
||||
|
|
|
@ -1,17 +1,18 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="@dimen/context_img_card_width"
|
||||
android:layout_height="@dimen/context_img_card_height"
|
||||
android:background="?attr/bg_card"
|
||||
android:background="?attr/bg_color"
|
||||
android:orientation="vertical">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="100dp"
|
||||
android:layout_height="104dp"
|
||||
android:paddingLeft="24dp"
|
||||
android:paddingRight="24dp"
|
||||
android:paddingTop="2dp"
|
||||
android:maxLines="4"
|
||||
android:gravity="center"
|
||||
android:ellipsize="end"
|
||||
|
@ -30,7 +31,13 @@
|
|||
android:drawablePadding="8dp"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="14dp"
|
||||
android:layout_marginBottom="16dp"
|
||||
android:textColor="@color/color_white"
|
||||
android:text="@string/shared_string_add_photos"/>
|
||||
|
||||
</LinearLayout>
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/context_menu_card"/>
|
||||
|
||||
</FrameLayout>
|
|
@ -18,6 +18,18 @@
|
|||
android:layout_height="match_parent"
|
||||
android:scaleType="centerCrop"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/url"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:gravity="center"
|
||||
android:padding="16dp"
|
||||
android:textColor="?attr/color_dialog_buttons"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
android:visibility="gone"
|
||||
tools:text="http://osmand.net/images/123456789012.jpg"
|
||||
tools:visibility="visible"/>
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
88
OsmAnd/res/layout/context_menu_card_no_images.xml
Normal file
88
OsmAnd/res/layout/context_menu_card_no_images.xml
Normal file
|
@ -0,0 +1,88 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="@dimen/context_img_card_width"
|
||||
android:layout_height="@dimen/context_img_card_height"
|
||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||
android:background="?attr/bg_color"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="30dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<android.support.v7.widget.AppCompatImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:tint="?attr/primary_icon_color"
|
||||
android:src="@drawable/ic_action_sadface"/>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/title"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="112dp"
|
||||
android:paddingLeft="20dp"
|
||||
android:paddingRight="24dp"
|
||||
android:paddingTop="2dp"
|
||||
android:maxLines="4"
|
||||
android:gravity="center_vertical"
|
||||
android:ellipsize="end"
|
||||
android:textColor="?android:textColorPrimary"
|
||||
android:textSize="@dimen/default_list_text_size"
|
||||
android:text="@string/no_photos_descr"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="?attr/ctx_menu_card_btn"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:background="?attr/selectableItemBackground">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="50dp"
|
||||
android:paddingBottom="2dp"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<android.support.v7.widget.AppCompatImageView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:tint="?attr/color_dialog_buttons"
|
||||
android:src="@drawable/ic_action_add_photos"/>
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginLeft="16dp"
|
||||
osmand:textAllCapsCompat="true"
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
android:textColor="?attr/color_dialog_buttons"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:text="@string/shared_string_add_photos"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:background="?attr/context_menu_card"/>
|
||||
|
||||
</FrameLayout>
|
|
@ -17,6 +17,7 @@
|
|||
<attr name="bg_color" format="reference" />
|
||||
<attr name="bg_card" format="reference" />
|
||||
<attr name="context_menu_card" format="reference" />
|
||||
<attr name="ctx_menu_card_btn" format="reference" />
|
||||
<attr name="bg_map_context_menu" format="reference" />
|
||||
<attr name="bg_point_editor_view" format="reference" />
|
||||
<attr name="ctx_menu_info_view_bg" format="reference" />
|
||||
|
|
|
@ -115,6 +115,8 @@
|
|||
<color name="ctx_menu_info_text_dark">#b4c3cc</color>
|
||||
<color name="ctx_menu_info_divider_light">#d9d9d9</color>
|
||||
<color name="ctx_menu_info_divider_dark">#333b40</color>
|
||||
<color name="ctx_menu_card_btn_light">#F5F5F5</color>
|
||||
<color name="ctx_menu_card_btn_dark">#3d474c</color>
|
||||
|
||||
<color name="dashboard_gpx_on_map">#448AFF</color>
|
||||
<color name="dashboard_background">#eaeaea</color>
|
||||
|
|
|
@ -9,7 +9,9 @@
|
|||
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated).
|
||||
PLEASE: Have a look at http://code.google.com/p/osmand/wiki/UIConsistency, it may really improve your and our work :-) Thx - Hardy
|
||||
-->
|
||||
<string name="online_photos">Online photos</string>
|
||||
<string name="shared_string_add_photos">Add photos</string>
|
||||
<string name="no_photos_descr">We don\'t have photos for this location</string>
|
||||
<string name="mapillary_action_descr">Contribute with your own street-level views of this location with Mapillary.</string>
|
||||
<string name="mapillary_widget">Mapillary widget</string>
|
||||
<string name="mapillary_widget_descr">Allow you to quick contribute to Mapillary</string>
|
||||
|
|
|
@ -79,6 +79,7 @@
|
|||
<item name="chart_marker_background">@drawable/chart_marker_background_light</item>
|
||||
<item name="routeParameterTitleColor">@color/color_myloc_distance</item>
|
||||
<item name="ctx_menu_info_divider">@color/ctx_menu_info_divider_light</item>
|
||||
<item name="ctx_menu_card_btn">@color/ctx_menu_card_btn_light</item>
|
||||
<item name="searchbar_text">@color/searchbar_text_light</item>
|
||||
<item name="searchbar_text_hint">@color/searchbar_text_hint_light</item>
|
||||
<item name="list_divider">@color/list_divider_dark</item>
|
||||
|
@ -251,6 +252,7 @@
|
|||
<item name="chart_marker_background">@drawable/chart_marker_background_dark</item>
|
||||
<item name="routeParameterTitleColor">@color/osmand_orange</item>
|
||||
<item name="ctx_menu_info_divider">@color/ctx_menu_info_divider_dark</item>
|
||||
<item name="ctx_menu_card_btn">@color/ctx_menu_card_btn_dark</item>
|
||||
<item name="searchbar_text">@color/searchbar_text_dark</item>
|
||||
<item name="searchbar_text_hint">@color/searchbar_text_hint_dark</item>
|
||||
<item name="list_divider">@color/list_divider_light</item>
|
||||
|
|
|
@ -23,6 +23,7 @@ import net.osmand.plus.dashboard.tools.DashFragmentData;
|
|||
import net.osmand.plus.development.OsmandDevelopmentPlugin;
|
||||
import net.osmand.plus.distancecalculator.DistanceCalculatorPlugin;
|
||||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
||||
import net.osmand.plus.mapcontextmenu.MenuController;
|
||||
import net.osmand.plus.mapillary.MapillaryPlugin;
|
||||
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
|
||||
import net.osmand.plus.myplaces.FavoritesActivity;
|
||||
|
@ -104,9 +105,22 @@ public abstract class OsmandPlugin {
|
|||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
* Return true in case if plugin should fill the map context menu with buildContextMenuRows method.
|
||||
*/
|
||||
public boolean isMenuControllerSupported(Class<? extends MenuController> menuControllerClass) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* Add menu rows to the map context menu.
|
||||
*/
|
||||
public void buildContextMenuRows(@NonNull MenuBuilder menuBuilder, @NonNull View view) {
|
||||
}
|
||||
|
||||
/*
|
||||
* Clear resources after menu was closed
|
||||
*/
|
||||
public void clearContextMenuRows() {
|
||||
}
|
||||
|
||||
|
|
|
@ -36,6 +36,13 @@ import net.osmand.plus.OsmandPlugin;
|
|||
import net.osmand.plus.OsmandSettings.OsmandPreference;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.mapcontextmenu.builders.cards.AbstractCard;
|
||||
import net.osmand.plus.mapcontextmenu.builders.cards.NoImagesCard;
|
||||
import net.osmand.plus.mapcontextmenu.builders.cards.CardsRowBuilder;
|
||||
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
|
||||
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask;
|
||||
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask.GetImageCardsListener;
|
||||
import net.osmand.plus.mapillary.AddMapillaryImagesCard;
|
||||
import net.osmand.plus.render.RenderingIcons;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
|
@ -61,7 +68,9 @@ public class MenuBuilder {
|
|||
private boolean hidden;
|
||||
private boolean showNearestWiki = false;
|
||||
protected List<Amenity> nearestWiki = new ArrayList<>();
|
||||
private List<Class<? extends OsmandPlugin>> pluginMenuBuilders = new ArrayList<>();
|
||||
private List<OsmandPlugin> menuPlugins = new ArrayList<>();
|
||||
private CardsRowBuilder onlinePhotoCardsRow;
|
||||
private List<AbstractCard> onlinePhotoCards;
|
||||
|
||||
public class PlainMenuItem {
|
||||
private int iconId;
|
||||
|
@ -197,8 +206,8 @@ public class MenuBuilder {
|
|||
this.showNearestWiki = showNearestWiki;
|
||||
}
|
||||
|
||||
public void addPluginMenuBuilder(Class<? extends OsmandPlugin> pluginClass) {
|
||||
pluginMenuBuilders.add(pluginClass);
|
||||
public void addMenuPlugin(OsmandPlugin plugin) {
|
||||
menuPlugins.add(plugin);
|
||||
}
|
||||
|
||||
public void setLight(boolean light) {
|
||||
|
@ -213,6 +222,7 @@ public class MenuBuilder {
|
|||
buildPlainMenuItems(view);
|
||||
}
|
||||
buildInternal(view);
|
||||
buildNearestPhotosRow(view);
|
||||
buildPluginRows(view);
|
||||
buildAfter(view);
|
||||
}
|
||||
|
@ -222,6 +232,8 @@ public class MenuBuilder {
|
|||
}
|
||||
|
||||
void onClose() {
|
||||
onlinePhotoCardsRow = null;
|
||||
onlinePhotoCards = null;
|
||||
clearPluginRows();
|
||||
}
|
||||
|
||||
|
@ -241,20 +253,14 @@ public class MenuBuilder {
|
|||
}
|
||||
|
||||
protected void buildPluginRows(View view) {
|
||||
for (Class<? extends OsmandPlugin> pluginClass : pluginMenuBuilders) {
|
||||
OsmandPlugin plugin = OsmandPlugin.getEnabledPlugin(pluginClass);
|
||||
if (plugin != null) {
|
||||
plugin.buildContextMenuRows(this, view);
|
||||
}
|
||||
for (OsmandPlugin plugin : menuPlugins) {
|
||||
plugin.buildContextMenuRows(this, view);
|
||||
}
|
||||
}
|
||||
|
||||
protected void clearPluginRows() {
|
||||
for (Class<? extends OsmandPlugin> pluginClass : pluginMenuBuilders) {
|
||||
OsmandPlugin plugin = OsmandPlugin.getEnabledPlugin(pluginClass);
|
||||
if (plugin != null) {
|
||||
plugin.clearContextMenuRows();
|
||||
}
|
||||
for (OsmandPlugin plugin : menuPlugins) {
|
||||
plugin.clearContextMenuRows();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -266,6 +272,56 @@ public class MenuBuilder {
|
|||
}
|
||||
}
|
||||
|
||||
protected void buildNearestPhotosRow(View view) {
|
||||
if (!app.getSettings().isInternetConnectionAvailable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean needUpdateOnly = onlinePhotoCardsRow != null && onlinePhotoCardsRow.getMenuBuilder() == this;
|
||||
onlinePhotoCardsRow = new CardsRowBuilder(this, view, false);
|
||||
onlinePhotoCardsRow.build();
|
||||
CollapsableView collapsableView = new CollapsableView(onlinePhotoCardsRow.getContentView(),
|
||||
app.getSettings().MAPILLARY_MENU_COLLAPSED);
|
||||
collapsableView.setOnCollExpListener(new CollapsableView.OnCollExpListener() {
|
||||
@Override
|
||||
public void onCollapseExpand(boolean collapsed) {
|
||||
if (!collapsed && onlinePhotoCards == null) {
|
||||
startLoadingImages(MenuBuilder.this);
|
||||
}
|
||||
}
|
||||
});
|
||||
buildRow(view, R.drawable.ic_action_photo_dark, app.getString(R.string.online_photos), 0, true,
|
||||
collapsableView, false, 1, false, null);
|
||||
|
||||
if (needUpdateOnly && onlinePhotoCards != null) {
|
||||
onlinePhotoCardsRow.setCards(onlinePhotoCards);
|
||||
} else if (!collapsableView.isCollapsed()) {
|
||||
startLoadingImages(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void startLoadingImages(final MenuBuilder menuBuilder) {
|
||||
onlinePhotoCards = new ArrayList<>();
|
||||
onlinePhotoCardsRow.setProgressCard();
|
||||
ImageCard.execute(new GetImageCardsTask(app, menuBuilder.getLatLon(),
|
||||
new GetImageCardsListener() {
|
||||
@Override
|
||||
public void onFinish(List<ImageCard> cardList) {
|
||||
if (!menuBuilder.isHidden()) {
|
||||
List<AbstractCard> cards = new ArrayList<>();
|
||||
cards.addAll(cardList);
|
||||
if (cardList.size() == 0) {
|
||||
cards.add(new NoImagesCard(app));
|
||||
} else {
|
||||
cards.add(new AddMapillaryImagesCard(app));
|
||||
}
|
||||
onlinePhotoCardsRow.setCards(cards);
|
||||
onlinePhotoCards = cards;
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
protected void buildInternal(View view) {
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import net.osmand.plus.GPXUtilities.WptPt;
|
|||
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
|
||||
import net.osmand.plus.MapMarkersHelper.MapMarker;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.OsmandPlugin;
|
||||
import net.osmand.plus.OsmandSettings;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.TargetPointsHelper.TargetPoint;
|
||||
|
@ -115,6 +116,11 @@ public abstract class MenuController extends BaseMenuController {
|
|||
}
|
||||
|
||||
public void build(View rootView) {
|
||||
for (OsmandPlugin plugin : OsmandPlugin.getEnabledPlugins()) {
|
||||
if (plugin.isMenuControllerSupported(this.getClass())) {
|
||||
builder.addMenuPlugin(plugin);
|
||||
}
|
||||
}
|
||||
builder.build(rootView);
|
||||
}
|
||||
|
||||
|
|
|
@ -50,7 +50,6 @@ public class AmenityMenuBuilder extends MenuBuilder {
|
|||
public AmenityMenuBuilder(MapActivity mapActivity, final Amenity amenity) {
|
||||
super(mapActivity);
|
||||
this.amenity = amenity;
|
||||
addPluginMenuBuilder(MapillaryPlugin.class);
|
||||
setShowNearestWiki(true, amenity.getId());
|
||||
}
|
||||
|
||||
|
|
|
@ -24,7 +24,6 @@ public class FavouritePointMenuBuilder extends MenuBuilder {
|
|||
public FavouritePointMenuBuilder(MapActivity mapActivity, final FavouritePoint fav) {
|
||||
super(mapActivity);
|
||||
this.fav = fav;
|
||||
addPluginMenuBuilder(MapillaryPlugin.class);
|
||||
setShowNearestWiki(true);
|
||||
acquireOriginObject();
|
||||
}
|
||||
|
|
|
@ -21,7 +21,6 @@ public class WptPtMenuBuilder extends MenuBuilder {
|
|||
public WptPtMenuBuilder(MapActivity mapActivity, final WptPt wpt) {
|
||||
super(mapActivity);
|
||||
this.wpt = wpt;
|
||||
addPluginMenuBuilder(MapillaryPlugin.class);
|
||||
setShowNearestWiki(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,8 +17,8 @@ import net.osmand.data.LatLon;
|
|||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.Version;
|
||||
import net.osmand.plus.mapillary.MapillaryImageCard;
|
||||
import net.osmand.util.Algorithms;
|
||||
import net.osmand.util.MapUtils;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
|
@ -28,8 +28,6 @@ import java.text.DateFormat;
|
|||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.Date;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
|
@ -40,8 +38,6 @@ import static java.text.DateFormat.FULL;
|
|||
|
||||
public abstract class ImageCard extends AbstractCard {
|
||||
|
||||
private static final int IMAGES_LIMIT = 15;
|
||||
|
||||
private String type;
|
||||
// Image location
|
||||
private LatLon location;
|
||||
|
@ -70,10 +66,6 @@ public abstract class ImageCard extends AbstractCard {
|
|||
private float bearingDiff = Float.NaN;
|
||||
private float distance = Float.NaN;
|
||||
|
||||
public interface ImageCardFactory<T> {
|
||||
T createCard(OsmandApplication app, JSONObject imageObject);
|
||||
}
|
||||
|
||||
public ImageCard(OsmandApplication app, JSONObject imageObject) {
|
||||
super(app);
|
||||
try {
|
||||
|
@ -112,6 +104,23 @@ public abstract class ImageCard extends AbstractCard {
|
|||
}
|
||||
}
|
||||
|
||||
private static ImageCard createCard(OsmandApplication app, JSONObject imageObject) {
|
||||
ImageCard imageCard = null;
|
||||
try {
|
||||
if (imageObject.has("type")) {
|
||||
String type = imageObject.getString("type");
|
||||
if ("mapillary-photo".equals(type)) {
|
||||
imageCard = new MapillaryImageCard(app, imageObject);
|
||||
} else {
|
||||
imageCard = new UrlImageCard(app, imageObject);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return imageCard;
|
||||
}
|
||||
|
||||
public double getCa() {
|
||||
return ca;
|
||||
}
|
||||
|
@ -243,29 +252,26 @@ public abstract class ImageCard extends AbstractCard {
|
|||
}
|
||||
}
|
||||
|
||||
public static class GetImageCardsTask<I extends ImageCard> extends AsyncTask<Void, Void, List<I>> {
|
||||
public static class GetImageCardsTask extends AsyncTask<Void, Void, List<ImageCard>> {
|
||||
|
||||
private OsmandApplication app;
|
||||
private LatLon latLon;
|
||||
private Listener<I> listener;
|
||||
private ImageCardFactory<I> imageCardFactory;
|
||||
private List<I> result;
|
||||
private GetImageCardsListener listener;
|
||||
private List<ImageCard> result;
|
||||
|
||||
public interface Listener<T extends ImageCard> {
|
||||
void onFinish(List<T> cardList);
|
||||
public interface GetImageCardsListener {
|
||||
void onFinish(List<ImageCard> cardList);
|
||||
}
|
||||
|
||||
public GetImageCardsTask(@NonNull ImageCardFactory<I> imageCardFactory,
|
||||
@NonNull OsmandApplication app, LatLon latLon, Listener<I> listener) {
|
||||
this.imageCardFactory = imageCardFactory;
|
||||
public GetImageCardsTask(@NonNull OsmandApplication app, LatLon latLon, GetImageCardsListener listener) {
|
||||
this.app = app;
|
||||
this.latLon = latLon;
|
||||
this.listener = listener;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected List<I> doInBackground(Void... params) {
|
||||
List<I> result = new ArrayList<>();
|
||||
protected List<ImageCard> doInBackground(Void... params) {
|
||||
List<ImageCard> result = new ArrayList<>();
|
||||
try {
|
||||
final Map<String, String> pms = new LinkedHashMap<>();
|
||||
pms.put("lat", "" + latLon.getLatitude());
|
||||
|
@ -286,7 +292,10 @@ public abstract class ImageCard extends AbstractCard {
|
|||
try {
|
||||
JSONObject imageObject = (JSONObject) images.get(i);
|
||||
if (imageObject != JSONObject.NULL) {
|
||||
result.add(imageCardFactory.createCard(app, imageObject));
|
||||
ImageCard imageCard = ImageCard.createCard(app, imageObject);
|
||||
if (imageCard != null) {
|
||||
result.add(imageCard);
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
|
@ -297,18 +306,11 @@ public abstract class ImageCard extends AbstractCard {
|
|||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
final Location loc = new Location("");
|
||||
loc.setLatitude(latLon.getLatitude());
|
||||
loc.setLongitude(latLon.getLongitude());
|
||||
sortImagesInfo(result, loc);
|
||||
if (result.size() > IMAGES_LIMIT) {
|
||||
result = result.subList(0, IMAGES_LIMIT);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(List<I> cardList) {
|
||||
protected void onPostExecute(List<ImageCard> cardList) {
|
||||
result = cardList;
|
||||
if (listener != null) {
|
||||
listener.onFinish(result);
|
||||
|
@ -316,48 +318,6 @@ public abstract class ImageCard extends AbstractCard {
|
|||
}
|
||||
}
|
||||
|
||||
private static <T extends ImageCard> void sortImagesInfo(List<T> cardList, @NonNull final Location location) {
|
||||
List<T> targetCards = new ArrayList<>();
|
||||
List<T> otherCards = new ArrayList<>();
|
||||
for (T c : cardList) {
|
||||
if (c.getLocation() != null) {
|
||||
Location l = new Location("");
|
||||
l.setLatitude(c.getLocation().getLatitude());
|
||||
l.setLongitude(c.getLocation().getLongitude());
|
||||
c.setDistance(l.distanceTo(location));
|
||||
if (!Double.isNaN(c.getCa())) {
|
||||
float bearingDiff = Math.abs(MapUtils.unifyRotationDiff(
|
||||
MapUtils.unifyRotationTo360((float) c.getCa()), l.bearingTo(location)));
|
||||
c.setBearingDiff(bearingDiff);
|
||||
if (bearingDiff < 30) {
|
||||
targetCards.add(c);
|
||||
} else {
|
||||
otherCards.add(c);
|
||||
}
|
||||
} else {
|
||||
otherCards.add(c);
|
||||
}
|
||||
}
|
||||
}
|
||||
Collections.sort(targetCards, new Comparator<ImageCard>() {
|
||||
|
||||
@Override
|
||||
public int compare(ImageCard i1, ImageCard i2) {
|
||||
return Float.compare(i1.bearingDiff, i2.bearingDiff);
|
||||
}
|
||||
});
|
||||
Collections.sort(otherCards, new Comparator<ImageCard>() {
|
||||
|
||||
@Override
|
||||
public int compare(ImageCard i1, ImageCard i2) {
|
||||
return Float.compare(i1.distance, i2.distance);
|
||||
}
|
||||
});
|
||||
cardList.clear();
|
||||
cardList.addAll(targetCards);
|
||||
cardList.addAll(otherCards);
|
||||
}
|
||||
|
||||
private class DownloadImageTask extends AsyncTask<Void, Void, Bitmap> {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
package net.osmand.plus.mapcontextmenu.builders.cards;
|
||||
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.mapillary.MapillaryPlugin;
|
||||
|
||||
public class NoImagesCard extends AbstractCard {
|
||||
|
||||
public NoImagesCard(OsmandApplication app) {
|
||||
super(app);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCardLayoutId() {
|
||||
return R.layout.context_menu_card_no_images;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (view != null) {
|
||||
view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
MapillaryPlugin.openMapillary(getMyApplication());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
package net.osmand.plus.mapcontextmenu.builders.cards;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.view.View;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
public class UrlImageCard extends ImageCard {
|
||||
|
||||
public UrlImageCard(OsmandApplication app, JSONObject imageObject) {
|
||||
super(app, imageObject);
|
||||
this.icon = app.getIconsCache().getIcon(R.drawable.ic_action_osmand_logo, R.color.osmand_orange);
|
||||
if (!Algorithms.isEmpty(getImageUrl())) {
|
||||
this.onClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW);
|
||||
intent.setData(Uri.parse(getImageUrl()));
|
||||
v.getContext().startActivity(intent);
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
if (view != null) {
|
||||
ImageView image = (ImageView) view.findViewById(R.id.image);
|
||||
image.setVisibility(View.GONE);
|
||||
TextView urlText = (TextView) view.findViewById(R.id.url);
|
||||
urlText.setText(getImageUrl());
|
||||
urlText.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -20,7 +20,6 @@ public class HistoryMenuController extends MenuController {
|
|||
public HistoryMenuController(MapActivity mapActivity, PointDescription pointDescription, final HistoryEntry entry) {
|
||||
super(new MenuBuilder(mapActivity), pointDescription, mapActivity);
|
||||
this.entry = entry;
|
||||
builder.addPluginMenuBuilder(MapillaryPlugin.class);
|
||||
builder.setShowNearestWiki(true);
|
||||
initData();
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ public class MapMarkerMenuController extends MenuController {
|
|||
public MapMarkerMenuController(MapActivity mapActivity, PointDescription pointDescription, MapMarker mapMarker) {
|
||||
super(new MenuBuilder(mapActivity), pointDescription, mapActivity);
|
||||
this.mapMarker = mapMarker;
|
||||
builder.addPluginMenuBuilder(MapillaryPlugin.class);
|
||||
builder.setShowNearestWiki(true);
|
||||
final MapMarkersHelper markersHelper = mapActivity.getMyApplication().getMapMarkersHelper();
|
||||
leftTitleButtonController = new TitleButtonController() {
|
||||
|
|
|
@ -14,7 +14,6 @@ public class MyLocationMenuController extends MenuController {
|
|||
|
||||
public MyLocationMenuController(MapActivity mapActivity, PointDescription pointDescription) {
|
||||
super(new MenuBuilder(mapActivity), pointDescription, mapActivity);
|
||||
builder.addPluginMenuBuilder(MapillaryPlugin.class);
|
||||
builder.setShowNearestWiki(true);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,6 @@ public class PointDescriptionMenuController extends MenuController {
|
|||
|
||||
public PointDescriptionMenuController(MapActivity mapActivity, final PointDescription pointDescription) {
|
||||
super(new MenuBuilder(mapActivity), pointDescription, mapActivity);
|
||||
builder.addPluginMenuBuilder(MapillaryPlugin.class);
|
||||
builder.setShowNearestWiki(true);
|
||||
initData();
|
||||
}
|
||||
|
|
|
@ -19,7 +19,6 @@ public class RenderedObjectMenuController extends MenuController {
|
|||
|
||||
public RenderedObjectMenuController(MapActivity mapActivity, PointDescription pointDescription, final RenderedObject renderedObject) {
|
||||
super(new MenuBuilder(mapActivity), pointDescription, mapActivity);
|
||||
builder.addPluginMenuBuilder(MapillaryPlugin.class);
|
||||
builder.setShowNearestWiki(true);
|
||||
this.renderedObject = renderedObject;
|
||||
}
|
||||
|
|
|
@ -20,7 +20,6 @@ public class TargetPointMenuController extends MenuController {
|
|||
public TargetPointMenuController(MapActivity mapActivity, PointDescription pointDescription, TargetPoint targetPoint) {
|
||||
super(new MenuBuilder(mapActivity), pointDescription, mapActivity);
|
||||
this.targetPoint = targetPoint;
|
||||
builder.addPluginMenuBuilder(MapillaryPlugin.class);
|
||||
builder.setShowNearestWiki(true);
|
||||
final TargetPointsHelper targetPointsHelper = getMapActivity().getMyApplication().getTargetPointsHelper();
|
||||
final int intermediatePointsCount = targetPointsHelper.getIntermediatePoints().size();
|
||||
|
|
|
@ -6,15 +6,15 @@ import net.osmand.plus.OsmandApplication;
|
|||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.mapcontextmenu.builders.cards.AbstractCard;
|
||||
|
||||
class AddMapillaryPhotoCard extends AbstractCard {
|
||||
public class AddMapillaryImagesCard extends AbstractCard {
|
||||
|
||||
AddMapillaryPhotoCard(OsmandApplication app) {
|
||||
public AddMapillaryImagesCard(OsmandApplication app) {
|
||||
super(app);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCardLayoutId() {
|
||||
return R.layout.mapillary_context_menu_action;
|
||||
return R.layout.context_menu_card_add_mapillary_images;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -28,4 +28,4 @@ class AddMapillaryPhotoCard extends AbstractCard {
|
|||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -8,16 +8,9 @@ import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
|
|||
|
||||
import org.json.JSONObject;
|
||||
|
||||
class MapillaryImageCard extends ImageCard {
|
||||
public class MapillaryImageCard extends ImageCard {
|
||||
|
||||
static class MapillaryImageCardFactory implements ImageCardFactory<MapillaryImageCard> {
|
||||
@Override
|
||||
public MapillaryImageCard createCard(OsmandApplication app, JSONObject imageObject) {
|
||||
return new MapillaryImageCard(app, imageObject);
|
||||
}
|
||||
}
|
||||
|
||||
private MapillaryImageCard(OsmandApplication app, JSONObject imageObject) {
|
||||
public MapillaryImageCard(OsmandApplication app, JSONObject imageObject) {
|
||||
super(app, imageObject);
|
||||
this.icon = app.getIconsCache().getIcon(R.drawable.ic_logo_mapillary);
|
||||
this.onClickListener = new View.OnClickListener() {
|
||||
|
|
|
@ -26,12 +26,6 @@ import net.osmand.plus.R;
|
|||
import net.osmand.plus.activities.MapActivity;
|
||||
import net.osmand.plus.activities.MapActivityLayers;
|
||||
import net.osmand.plus.base.BottomSheetDialogFragment;
|
||||
import net.osmand.plus.mapcontextmenu.MenuBuilder;
|
||||
import net.osmand.plus.mapcontextmenu.MenuBuilder.CollapsableView;
|
||||
import net.osmand.plus.mapcontextmenu.builders.cards.AbstractCard;
|
||||
import net.osmand.plus.mapcontextmenu.builders.cards.CardsRowBuilder;
|
||||
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
|
||||
import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard.GetImageCardsTask;
|
||||
import net.osmand.plus.views.MapInfoLayer;
|
||||
import net.osmand.plus.views.MapTileLayer;
|
||||
import net.osmand.plus.views.OsmandMapTileView;
|
||||
|
@ -39,7 +33,6 @@ import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo;
|
|||
import net.osmand.plus.views.mapwidgets.TextInfoWidget;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MapillaryPlugin extends OsmandPlugin {
|
||||
|
@ -51,8 +44,6 @@ public class MapillaryPlugin extends OsmandPlugin {
|
|||
private MapillaryLayer rasterLayer;
|
||||
private TextInfoWidget mapillaryControl;
|
||||
private MapWidgetRegInfo mapillaryWidgetRegInfo;
|
||||
private CardsRowBuilder contextMenuCardsRow;
|
||||
private List<AbstractCard> contextMenuCards;
|
||||
|
||||
public MapillaryPlugin(OsmandApplication app) {
|
||||
this.app = app;
|
||||
|
@ -206,60 +197,6 @@ public class MapillaryPlugin extends OsmandPlugin {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void buildContextMenuRows(@NonNull final MenuBuilder menuBuilder, @NonNull View view) {
|
||||
if (!menuBuilder.getApplication().getSettings().isInternetConnectionAvailable()) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean needUpdateOnly = contextMenuCardsRow != null && contextMenuCardsRow.getMenuBuilder() == menuBuilder;
|
||||
contextMenuCardsRow = new CardsRowBuilder(menuBuilder, view, false);
|
||||
contextMenuCardsRow.build();
|
||||
CollapsableView collapsableView = new CollapsableView(contextMenuCardsRow.getContentView(),
|
||||
app.getSettings().MAPILLARY_MENU_COLLAPSED);
|
||||
collapsableView.setOnCollExpListener(new CollapsableView.OnCollExpListener() {
|
||||
@Override
|
||||
public void onCollapseExpand(boolean collapsed) {
|
||||
if (!collapsed && contextMenuCards == null) {
|
||||
startLoadingImages(menuBuilder);
|
||||
}
|
||||
}
|
||||
});
|
||||
menuBuilder.buildRow(view, R.drawable.ic_action_photo_dark, "Online photos", 0, true,
|
||||
collapsableView, false, 1, false, null);
|
||||
|
||||
if (needUpdateOnly && contextMenuCards != null) {
|
||||
contextMenuCardsRow.setCards(contextMenuCards);
|
||||
} else if (!collapsableView.isCollapsed()) {
|
||||
startLoadingImages(menuBuilder);
|
||||
}
|
||||
}
|
||||
|
||||
private void startLoadingImages(final MenuBuilder menuBuilder) {
|
||||
contextMenuCards = new ArrayList<>();
|
||||
contextMenuCardsRow.setProgressCard();
|
||||
ImageCard.execute(new GetImageCardsTask<>(
|
||||
new MapillaryImageCard.MapillaryImageCardFactory(), app, menuBuilder.getLatLon(),
|
||||
new GetImageCardsTask.Listener<MapillaryImageCard>() {
|
||||
@Override
|
||||
public void onFinish(List<MapillaryImageCard> cardList) {
|
||||
if (!menuBuilder.isHidden()) {
|
||||
List<AbstractCard> cards = new ArrayList<>();
|
||||
cards.addAll(cardList);
|
||||
cards.add(new AddMapillaryPhotoCard(app));
|
||||
contextMenuCardsRow.setCards(cards);
|
||||
contextMenuCards = cards;
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearContextMenuRows() {
|
||||
contextMenuCardsRow = null;
|
||||
contextMenuCards = null;
|
||||
}
|
||||
|
||||
public static boolean openMapillary(OsmandApplication app) {
|
||||
boolean success = false;
|
||||
if (isPackageInstalled(MAPILLARY_PACKAGE_ID, app)) {
|
||||
|
|
Loading…
Reference in a new issue