Merge remote-tracking branch 'origin/master'

This commit is contained in:
Weblate 2017-05-05 11:31:50 +02:00
commit 4fe4e42c92
8 changed files with 75 additions and 21 deletions

View file

@ -456,8 +456,7 @@ public abstract class OsmandPlugin {
return collection;
}
private static boolean isPackageInstalled(String packageInfo,
OsmandApplication app) {
public static boolean isPackageInstalled(String packageInfo, OsmandApplication app) {
if (packageInfo == null) {
return false;
}

View file

@ -4,12 +4,19 @@ import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import net.osmand.plus.OsmandApplication;
public abstract class AbstractCard {
private OsmandApplication app;
protected View view;
public abstract int getCardLayoutId();
public AbstractCard(OsmandApplication app) {
this.app = app;
}
public View build(Context ctx) {
view = LayoutInflater.from(ctx).inflate(getCardLayoutId(), null);
update();
@ -18,4 +25,7 @@ public abstract class AbstractCard {
public abstract void update();
public OsmandApplication getOsmandApplication() {
return app;
}
}

View file

@ -22,14 +22,16 @@ public class CardsRowBuilder {
private MenuBuilder menuBuilder;
private View view;
private OsmandApplication app;
private boolean addToLayout;
private List<AbstractCard> cards = new ArrayList<>();
private LockableViewPager viewPager;
private ViewsPagerAdapter pagerAdapter;
private int dp10;
public CardsRowBuilder(MenuBuilder menuBuilder, View view) {
public CardsRowBuilder(MenuBuilder menuBuilder, View view, boolean addToLayout) {
this.menuBuilder = menuBuilder;
this.view = view;
this.addToLayout = addToLayout;
this.app = menuBuilder.getApplication();
this.dp10 = AndroidUtils.dpToPx(app, 10f);
}
@ -38,7 +40,7 @@ public class CardsRowBuilder {
return menuBuilder;
}
public LockableViewPager getViewPager() {
public View getContentView() {
return viewPager;
}
@ -58,7 +60,7 @@ public class CardsRowBuilder {
}
public void setProgressCard() {
setCards(new ProgressCard());
setCards(new ProgressCard(app));
}
public void build() {
@ -73,7 +75,9 @@ public class CardsRowBuilder {
pagerAdapter = new ViewsPagerAdapter();
viewPager.setAdapter(pagerAdapter);
viewPager.setSwipeLocked(itemsCount() < 2);
//((LinearLayout) view).addView(viewPager);
if (addToLayout) {
((LinearLayout) view).addView(viewPager);
}
}
private int itemsCount() {

View file

@ -58,7 +58,6 @@ public abstract class ImageCard extends AbstractCard {
// Image bitmap url
private String imageUrl;
private OsmandApplication app;
private int defaultImageLayoutId = R.layout.context_menu_card_image;
protected Drawable icon;
@ -76,7 +75,7 @@ public abstract class ImageCard extends AbstractCard {
}
public ImageCard(OsmandApplication app, JSONObject imageObject) {
this.app = app;
super(app);
try {
if (imageObject.has("type")) {
this.type = imageObject.getString("type");
@ -369,7 +368,7 @@ public abstract class ImageCard extends AbstractCard {
@Override
protected Bitmap doInBackground(Void... params) {
return AndroidNetworkUtils.downloadImage(app, imageUrl);
return AndroidNetworkUtils.downloadImage(getOsmandApplication(), imageUrl);
}
@Override

View file

@ -1,9 +1,14 @@
package net.osmand.plus.mapcontextmenu.builders.cards;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
public class ProgressCard extends AbstractCard {
public ProgressCard(OsmandApplication app) {
super(app);
}
@Override
public int getCardLayoutId() {
return R.layout.context_menu_card_progress;

View file

@ -2,10 +2,15 @@ package net.osmand.plus.mapillary;
import android.view.View;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.mapcontextmenu.builders.cards.AbstractCard;
public class AddMapillaryPhotoCard extends AbstractCard {
class AddMapillaryPhotoCard extends AbstractCard {
AddMapillaryPhotoCard(OsmandApplication app) {
super(app);
}
@Override
public int getCardLayoutId() {
@ -18,7 +23,7 @@ public class AddMapillaryPhotoCard extends AbstractCard {
view.findViewById(R.id.button).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// todo open mapillary
MapillaryPlugin.openMapillary(getOsmandApplication());
}
});
}

View file

@ -8,16 +8,16 @@ import net.osmand.plus.mapcontextmenu.builders.cards.ImageCard;
import org.json.JSONObject;
public class MapillaryImageCard extends ImageCard {
class MapillaryImageCard extends ImageCard {
public static class MapillaryImageCardFactory implements ImageCardFactory<MapillaryImageCard> {
static class MapillaryImageCardFactory implements ImageCardFactory<MapillaryImageCard> {
@Override
public MapillaryImageCard createCard(OsmandApplication app, JSONObject imageObject) {
return new MapillaryImageCard(app, imageObject);
}
}
public MapillaryImageCard(OsmandApplication app, JSONObject imageObject) {
private MapillaryImageCard(OsmandApplication app, JSONObject imageObject) {
super(app, imageObject);
this.icon = app.getIconsCache().getIcon(R.drawable.ic_logo_mapillary);
this.onClickListener = new View.OnClickListener() {

View file

@ -1,6 +1,9 @@
package net.osmand.plus.mapillary;
import android.app.Activity;
import android.content.ActivityNotFoundException;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentActivity;
@ -41,6 +44,7 @@ import java.util.List;
public class MapillaryPlugin extends OsmandPlugin {
public static final String ID = "osmand.mapillary";
private static final String MAPILLARY_PACKAGE_ID = "app.mapillary";
private OsmandSettings settings;
private OsmandApplication app;
@ -95,7 +99,7 @@ public class MapillaryPlugin extends OsmandPlugin {
updateMapLayers(mapView, activity.getMapLayers());
}
public void updateMapLayers(OsmandMapTileView mapView, final MapActivityLayers layers) {
private void updateMapLayers(OsmandMapTileView mapView, final MapActivityLayers layers) {
if (rasterLayer == null) {
createLayers();
}
@ -108,7 +112,7 @@ public class MapillaryPlugin extends OsmandPlugin {
layers.updateMapSource(mapView, null);
}
public void updateLayer(OsmandMapTileView mapView, MapTileLayer layer, float layerOrder) {
private void updateLayer(OsmandMapTileView mapView, MapTileLayer layer, float layerOrder) {
ITileSource mapillarySource = null;
if (settings.SHOW_MAPILLARY.get()) {
mapillarySource = settings.getTileSourceByName(TileSourceManager.getMapillarySource().getName(), false);
@ -181,14 +185,14 @@ public class MapillaryPlugin extends OsmandPlugin {
mapillaryControl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// todo open mapillary app
openMapillary(app);
}
});
return mapillaryControl;
}
public void setWidgetVisible(MapActivity mapActivity, boolean visible) {
private void setWidgetVisible(MapActivity mapActivity, boolean visible) {
if (mapillaryWidgetRegInfo != null) {
final List<ApplicationMode> allModes = ApplicationMode.allPossibleValues();
for (ApplicationMode mode : allModes) {
@ -209,9 +213,9 @@ public class MapillaryPlugin extends OsmandPlugin {
}
boolean needUpdateOnly = contextMenuCardsRow != null && contextMenuCardsRow.getMenuBuilder() == menuBuilder;
contextMenuCardsRow = new CardsRowBuilder(menuBuilder, view);
contextMenuCardsRow = new CardsRowBuilder(menuBuilder, view, false);
contextMenuCardsRow.build();
CollapsableView collapsableView = new CollapsableView(contextMenuCardsRow.getViewPager(),
CollapsableView collapsableView = new CollapsableView(contextMenuCardsRow.getContentView(),
app.getSettings().MAPILLARY_MENU_COLLAPSED);
collapsableView.setOnCollExpListener(new CollapsableView.OnCollExpListener() {
@Override
@ -243,7 +247,7 @@ public class MapillaryPlugin extends OsmandPlugin {
if (!menuBuilder.isHidden()) {
List<AbstractCard> cards = new ArrayList<>();
cards.addAll(cardList);
cards.add(new AddMapillaryPhotoCard());
cards.add(new AddMapillaryPhotoCard(app));
contextMenuCardsRow.setCards(cards);
contextMenuCards = cards;
}
@ -257,6 +261,34 @@ public class MapillaryPlugin extends OsmandPlugin {
contextMenuCards = null;
}
public static boolean openMapillary(OsmandApplication app) {
boolean success = false;
if (isPackageInstalled(MAPILLARY_PACKAGE_ID, app)) {
Intent launchIntent = app.getPackageManager().getLaunchIntentForPackage(MAPILLARY_PACKAGE_ID);
if (launchIntent != null) {
app.startActivity(launchIntent);
success = true;
}
} else {
success = execInstall(app, "market://search?q=pname:" + MAPILLARY_PACKAGE_ID);
if (!success) {
success = execInstall(app, "https://play.google.com/store/apps/details?id=" + MAPILLARY_PACKAGE_ID);
}
}
return success;
}
private static boolean execInstall(OsmandApplication app, String url) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
try {
app.startActivity(intent);
return true;
} catch (ActivityNotFoundException e) {
e.printStackTrace();
}
return false;
}
public static class MapillaryFirstDialogFragment extends BottomSheetDialogFragment {
public static final String TAG = "MapillaryFirstDialogFragment";