Added mapillary welcome dialog

This commit is contained in:
Alexey Kulish 2017-04-29 18:15:19 +03:00
parent ab3d6eba90
commit a2297fae39
9 changed files with 239 additions and 1 deletions

View file

@ -0,0 +1,130 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?attr/bottom_menu_view_bg"
xmlns:tools="http://schemas.android.com/tools">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<android.support.v7.widget.AppCompatImageView
android:id="@+id/titleIconImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="16dp"
android:src="@drawable/ic_action_mapillary"
android:tint="@color/mapillary_color"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="24dp"
android:paddingRight="8dp"
android:text="@string/mapillary"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/dialog_header_text_size"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="24dp"
android:paddingRight="24dp"
android:text="@string/mapillary_descr"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="24dp"
android:text="@string/mapillary_widget"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="6dp"
android:paddingRight="24dp"
android:text="@string/mapillary_widget_descr"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_sub_text_size"/>
</LinearLayout>
<android.support.v7.widget.SwitchCompat
android:id="@+id/widget_switch"
android:layout_width="wrap_content"
android:layout_height="match_parent"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="24dp"
android:background="?attr/dashboard_divider"/>
<Button
android:id="@+id/actionButton"
android:layout_width="wrap_content"
android:layout_height="36dp"
android:layout_marginLeft="16dp"
android:layout_marginTop="6dp"
android:layout_marginBottom="6dp"
android:paddingLeft="8dp"
android:paddingRight="8dp"
style="@style/Widget.AppCompat.Button.Borderless"
android:gravity="left|center_vertical"
android:textColor="?attr/contextMenuButtonColor"
android:text="@string/shared_string_ok"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</FrameLayout>

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="mapillary_color">#3db878</color>
<color name="buy_button_color">#50ae55</color>
<color name="buy_button_pressed_color">#b5e5b9</color>

View file

@ -9,6 +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="mapillary_widget">Mapillary widget</string>
<string name="mapillary_widget_descr">Allow you to quick contribute to Mapillary</string>
<string name="mapillary_descr">Online Street-Photos for everyone. Discover places, collaborate, capture the world.</string>
<string name="mapillary">Mapillary</string>
<string name="private_access_routing_req">Your destination is located in the area with a private access. Do you want to allow access to the private roads for this trip?</string>
<string name="restart_search">Restart search</string>

View file

@ -894,6 +894,7 @@ public class OsmandSettings {
public final OsmandPreference<Boolean> SHOW_POI_LABEL = new BooleanPreference("show_poi_label", false).makeGlobal();
public final OsmandPreference<Boolean> SHOW_MAPILLARY = new BooleanPreference("show_mapillary", false).makeGlobal();
public final OsmandPreference<Boolean> MAPILLARY_FIRST_DIALOG_SHOWN = new BooleanPreference("mapillary_first_dialog_shown", false).makeGlobal();
// this value string is synchronized with settings_pref.xml preference name
public final OsmandPreference<String> PREFERRED_LOCALE = new StringPreference("preferred_locale", "").makeGlobal();

View file

@ -74,6 +74,8 @@ import net.osmand.plus.helpers.WaypointHelper.LocationPointWrapper;
import net.osmand.plus.mapcontextmenu.other.MapRouteInfoMenu;
import net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu;
import net.osmand.plus.mapcontextmenu.other.RoutePreferencesMenu.LocalRoutingParameter;
import net.osmand.plus.mapillary.MapillaryPlugin;
import net.osmand.plus.mapillary.MapillaryPlugin.MapillaryFirstDialogFragment;
import net.osmand.plus.rastermaps.OsmandRasterMapsPlugin;
import net.osmand.plus.routing.RoutingHelper;
import net.osmand.plus.routing.RoutingHelper.IRouteInformationListener;
@ -866,6 +868,13 @@ public class DashboardOnMap implements ObservableScrollViewCallbacks, DynamicLis
df.get().onCloseDash();
}
}
OsmandSettings settings = getMyApplication().getSettings();
if (settings.SHOW_MAPILLARY.get() && !settings.MAPILLARY_FIRST_DIALOG_SHOWN.get()) {
MapillaryFirstDialogFragment fragment = new MapillaryFirstDialogFragment();
fragment.show(mapActivity.getSupportFragmentManager(), MapillaryFirstDialogFragment.TAG);
settings.MAPILLARY_FIRST_DIALOG_SHOWN.set(true);
}
}
}

View file

@ -76,6 +76,7 @@ public class SettingsDevelopmentActivity extends SettingsBaseActivity {
public boolean onPreferenceClick(Preference preference) {
getMyApplication().getAppInitializer().resetFirstTimeRun();
getMyApplication().getSettings().FIRST_MAP_IS_DOWNLOADED.set(false);
getMyApplication().getSettings().MAPILLARY_FIRST_DIALOG_SHOWN.set(false);
getMyApplication().showToastMessage(R.string.shared_string_ok);
return true;
}

View file

@ -1,10 +1,18 @@
package net.osmand.plus.mapillary;
import android.app.Activity;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentActivity;
import android.support.v7.widget.SwitchCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import net.osmand.map.ITileSource;
import net.osmand.map.TileSourceManager;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.OsmandApplication;
@ -13,16 +21,24 @@ import net.osmand.plus.OsmandSettings;
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.views.MapInfoLayer;
import net.osmand.plus.views.MapTileLayer;
import net.osmand.plus.views.OsmandMapTileView;
import net.osmand.plus.views.mapwidgets.MapWidgetRegistry.MapWidgetRegInfo;
import net.osmand.plus.views.mapwidgets.TextInfoWidget;
import net.osmand.util.Algorithms;
import java.util.List;
public class MapillaryPlugin extends OsmandPlugin {
public static final String ID = "osmand.mapillary";
private OsmandSettings settings;
private OsmandApplication app;
private MapillaryLayer rasterLayer;
private TextInfoWidget mapillaryControl;
private MapWidgetRegInfo mapillaryWidgetRegInfo;
public MapillaryPlugin(OsmandApplication app) {
this.app = app;
@ -57,6 +73,7 @@ public class MapillaryPlugin extends OsmandPlugin {
@Override
public void registerLayers(MapActivity activity) {
createLayers();
registerWidget(activity);
}
private void createLayers() {
@ -138,4 +155,75 @@ public class MapillaryPlugin extends OsmandPlugin {
.setPosition(11)
.createItem());
}
private void registerWidget(MapActivity activity) {
MapInfoLayer layer = activity.getMapLayers().getMapInfoLayer();
mapillaryControl = createMonitoringControl(activity);
mapillaryWidgetRegInfo = layer.registerSideWidget(mapillaryControl,
R.drawable.ic_action_mapillary, R.string.mapillary, "mapillary", false, 19);
layer.recreateControls();
}
private TextInfoWidget createMonitoringControl(final MapActivity map) {
mapillaryControl = new TextInfoWidget(map);
mapillaryControl.setText(map.getString(R.string.mapillary), "");
mapillaryControl.setIcons(R.drawable.widget_mapillary_day, R.drawable.widget_mapillary_night);
mapillaryControl.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// todo open mapillary app
}
});
return mapillaryControl;
}
public void setWidgetVisible(MapActivity mapActivity, boolean visible) {
if (mapillaryWidgetRegInfo != null) {
final List<ApplicationMode> allModes = ApplicationMode.allPossibleValues();
for (ApplicationMode mode : allModes) {
mapActivity.getMapLayers().getMapWidgetRegistry().setVisibility(mode, mapillaryWidgetRegInfo, visible, false);
}
MapInfoLayer mil = mapActivity.getMapLayers().getMapInfoLayer();
if (mil != null) {
mil.recreateControls();
}
mapActivity.refreshMap();
}
}
public static class MapillaryFirstDialogFragment extends BottomSheetDialogFragment {
public static final String TAG = "MapillaryFirstDialogFragment";
private static final String KEY_SHOW_WIDGET = "key_show_widget";
private boolean showWidget = true;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
if (savedInstanceState != null) {
showWidget = savedInstanceState.getBoolean(KEY_SHOW_WIDGET, true);
}
View view = inflater.inflate(R.layout.mapillary_first_dialog, container, false);
final SwitchCompat widgetSwitch = (SwitchCompat) view.findViewById(R.id.widget_switch);
widgetSwitch.setChecked(showWidget);
view.findViewById(R.id.actionButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentActivity activity = getActivity();
MapillaryPlugin plugin = OsmandPlugin.getPlugin(MapillaryPlugin.class);
if (plugin != null && activity instanceof MapActivity) {
plugin.setWidgetVisible((MapActivity) activity, widgetSwitch.isChecked());
}
dismiss();
}
});
return view;
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
outState.putBoolean(KEY_SHOW_WIDGET, showWidget);
}
}
}

View file

@ -87,10 +87,11 @@ public class MapInfoLayer extends OsmandMapLayer {
recreateControls();
}
public void registerSideWidget(TextInfoWidget widget, int drawableMenu,
public MapWidgetRegInfo registerSideWidget(TextInfoWidget widget, int drawableMenu,
int messageId, String key, boolean left, int priorityOrder) {
MapWidgetRegInfo reg = mapInfoControls.registerSideWidgetInternal(widget, drawableMenu, messageId, key, left, priorityOrder);
updateReg(calculateTextState(), reg);
return reg;
}
public MapWidgetRegInfo registerSideWidget(TextInfoWidget widget, int drawableMenu,

View file

@ -240,6 +240,10 @@ public class MapWidgetRegistry {
public void setVisibility(MapWidgetRegInfo m, boolean visible, boolean collapsed) {
ApplicationMode mode = settings.APPLICATION_MODE.get();
setVisibility(mode, m, visible, collapsed);
}
public void setVisibility(ApplicationMode mode, MapWidgetRegInfo m, boolean visible, boolean collapsed) {
defineDefaultSettingsElement(mode);
// clear everything
this.visibleElementsFromSettings.get(mode).remove(m.key);