quick action fab tutorial

This commit is contained in:
Korusn Oleksandr 2017-01-06 19:11:26 +02:00
parent 1527c32755
commit 15d6603496
4 changed files with 46 additions and 9 deletions

View file

@ -2546,4 +2546,6 @@ If you need help with OsmAnd application, please contact our support team: suppo
<string name="quick_action_map_source_action">Add Source</string>
<string name="quick_action_map_source_switch">Map source has been changed to the \"%s\".</string>
<string name="quick_action_poi_add">Add</string>
<string name="quck_action_btn_tutorial_title">Change button position</string>
<string name="quick_action_btn_tutorial_description">Long tap and drag button on the screen to change position</string>
</resources>

View file

@ -2458,6 +2458,8 @@ public class OsmandSettings {
public final CommonPreference<String> QUICK_ACTION_LIST = new StringPreference("quick_action_list", "").makeGlobal();
public final CommonPreference<Boolean> IS_QUICK_ACTION_TUTORIAL_SHOWN = new BooleanPreference("quick_action_tutorial", false).makeGlobal();
public boolean setPortraitFabMargin(int x, int y) {
return settingsAPI.edit(globalPreferences).putInt(QUICK_FAB_MARGIN_X_PORTRAIT_MARGIN, x)
.putInt(QUICK_FAB_MARGIN_Y_PORTRAIT_MARGIN, y).commit();

View file

@ -53,7 +53,6 @@ import net.osmand.plus.ContextMenuAdapter;
import net.osmand.plus.ContextMenuItem;
import net.osmand.plus.FavouritesDbHelper;
import net.osmand.plus.GeocodingLookupService;
import net.osmand.plus.IconsCache;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandPlugin;
import net.osmand.plus.OsmandSettings;

View file

@ -13,6 +13,9 @@ import android.widget.FrameLayout;
import android.widget.ImageButton;
import android.widget.ImageView;
import com.getkeepsafe.taptargetview.TapTarget;
import com.getkeepsafe.taptargetview.TapTargetView;
import net.osmand.data.LatLon;
import net.osmand.data.RotatedTileBox;
import net.osmand.plus.OsmandApplication;
@ -73,8 +76,8 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
quickActionButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (!showTutorialIfNeeded())
setLayerState(quickActionsWidget.getVisibility() == View.VISIBLE);
}
});
@ -101,7 +104,6 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
}
});
}
public void refreshLayer() {
@ -110,6 +112,38 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
setUpQuickActionBtnVisibility();
}
private boolean showTutorialIfNeeded() {
if (isLayerOn && !settings.IS_QUICK_ACTION_TUTORIAL_SHOWN.get()) {
TapTargetView.showFor(mapActivity, // `this` is an Activity
TapTarget.forView(quickActionButton, mapActivity.getString(R.string.quck_action_btn_tutorial_title), mapActivity.getString(R.string.quick_action_btn_tutorial_description))
// All options below are optional
.outerCircleColor(R.color.osmand_orange) // Specify a color for the outer circle
.targetCircleColor(R.color.color_white) // Specify a color for the target circle
.titleTextSize(20) // Specify the size (in sp) of the title text
.descriptionTextSize(16) // Specify the size (in sp) of the description text
// .textColor(R.color.color_white) // Specify a color for both the title and description text
.descriptionTextColor(R.color.color_white) // Specify a color for both the title and description text
.titleTextColor(R.color.color_white) // Specify a color for both the title and description text
// .textTypeface(Typeface.SANS_SERIF) // Specify a typeface for the text
// .dimColor(R.color.black) // If set, will dim behind the view with 30% opacity of the given color
.drawShadow(true) // Whether to draw a drop shadow or not
.cancelable(false) // Whether tapping outside the outer circle dismisses the view
.tintTarget(false) // Whether to tint the target view's color
.transparentTarget(false) // Specify whether the target is transparent (displays the content underneath)
// .icon(Drawable) // Specify a custom drawable to draw as the target
.targetRadius(50), // Specify the target radius (in dp)
new TapTargetView.Listener() { // The listener can listen for regular clicks, long clicks or cancels
@Override
public void onTargetClick(TapTargetView view) {
super.onTargetClick(view); // This call is optional
settings.IS_QUICK_ACTION_TUTORIAL_SHOWN.set(true);
}
});
return true;
} else
return false;
}
private void setQuickActionButtonMargin() {
FrameLayout.LayoutParams param = (FrameLayout.LayoutParams) quickActionButton.getLayoutParams();
if (AndroidUiHelper.isOrientationPortrait(mapActivity)) {
@ -167,7 +201,7 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
private void enterMovingMode(RotatedTileBox tileBox) {
previousMapPosition = view.getMapPosition();
view.setMapPosition( OsmandSettings.BOTTOM_CONSTANT);
view.setMapPosition(OsmandSettings.BOTTOM_CONSTANT);
MapContextMenu menu = mapActivity.getContextMenu();
LatLon ll = menu.isActive() && tileBox.containsLatLon(menu.getLatLon()) ? menu.getLatLon() : tileBox.getCenterLatLon();
@ -220,14 +254,14 @@ public class MapQuickActionLayer extends OsmandMapLayer implements QuickActionRe
@Override
public boolean onSingleTap(PointF point, RotatedTileBox tileBox) {
if (isInChangeMarkerPositionMode() && !pressedQuickActionWidget(point.x, point.y)){
if (isInChangeMarkerPositionMode() && !pressedQuickActionWidget(point.x, point.y)) {
setLayerState(true);
return true;
} else
return false;
}
private boolean pressedQuickActionWidget(float px , float py) {
private boolean pressedQuickActionWidget(float px, float py) {
return py <= quickActionsWidget.getHeight();
}