Add toolbar

This commit is contained in:
Alexander Sytnyk 2017-08-01 17:23:29 +03:00
parent 36d4f5d4ab
commit 40c6ba307b
5 changed files with 88 additions and 1 deletions

View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/action_save_as_gpx"
android:icon="@drawable/ic_action_polygom_dark"
android:title="@string/shared_string_save_as_gpx"/>
<item
android:id="@+id/action_clear_all"
android:icon="@drawable/ic_action_reset_to_default_dark"
android:title="@string/shared_string_clear_all"/>
</menu>

View file

@ -9,6 +9,7 @@
3. All your modified/created strings are in the top of the file (to make easier find what\'s translated). 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 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="measurement_tool_action_bar">Select a location on the map and click "Add" to add a point to the ruler.</string>
<string name="measurement_tool">Measurement tool</string> <string name="measurement_tool">Measurement tool</string>
<string name="quick_action_resume_pause_navigation">Resume/Pause Navigation</string> <string name="quick_action_resume_pause_navigation">Resume/Pause Navigation</string>
<string name="quick_action_resume_pause_navigation_descr">Press this button to pause the navigation, or to resume it if it was already paused.</string> <string name="quick_action_resume_pause_navigation_descr">Press this button to pause the navigation, or to resume it if it was already paused.</string>

View file

@ -5,20 +5,28 @@ import android.support.annotation.Nullable;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast;
import net.osmand.AndroidUtils; import net.osmand.AndroidUtils;
import net.osmand.plus.IconsCache; import net.osmand.plus.IconsCache;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity; import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;
import net.osmand.plus.widgets.IconPopupMenu;
public class MeasurementToolFragment extends Fragment { public class MeasurementToolFragment extends Fragment {
public static final String TAG = "MeasurementToolFragment"; public static final String TAG = "MeasurementToolFragment";
private MeasurementToolBarController toolBarController;
private TextView distanceTv; private TextView distanceTv;
private TextView pointsTv; private TextView pointsTv;
private String pointsSt; private String pointsSt;
@ -28,11 +36,12 @@ public class MeasurementToolFragment extends Fragment {
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
MapActivity mapActivity = (MapActivity) getActivity(); final MapActivity mapActivity = (MapActivity) getActivity();
final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer(); final MeasurementToolLayer measurementLayer = mapActivity.getMapLayers().getMeasurementToolLayer();
IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache(); IconsCache iconsCache = mapActivity.getMyApplication().getIconsCache();
final boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls(); final boolean nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
boolean portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
pointsSt = mapActivity.getString(R.string.points).toLowerCase(); pointsSt = mapActivity.getString(R.string.points).toLowerCase();
@ -63,6 +72,45 @@ public class MeasurementToolFragment extends Fragment {
enterMeasurementMode(); enterMeasurementMode();
if (portrait) {
toolBarController = new MeasurementToolBarController();
toolBarController.setTitle(mapActivity.getString(R.string.measurement_tool_action_bar));
toolBarController.setOnBackButtonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mapActivity.onBackPressed();
}
});
toolBarController.setOnCloseButtonClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
IconPopupMenu popup = new IconPopupMenu(mapActivity, mapActivity.findViewById(R.id.widget_top_bar_close_button));
popup.getMenuInflater().inflate(R.menu.measurement_tool_menu, popup.getMenu());
final Menu menu = popup.getMenu();
IconsCache ic = mapActivity.getMyApplication().getIconsCache();
menu.findItem(R.id.action_save_as_gpx).setIcon(ic.getThemedIcon(R.drawable.ic_action_polygom_dark));
menu.findItem(R.id.action_clear_all).setIcon(ic.getThemedIcon(R.drawable.ic_action_reset_to_default_dark));
popup.setOnMenuItemClickListener(new IconPopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem menuItem) {
switch (menuItem.getItemId()) {
case R.id.action_save_as_gpx:
Toast.makeText(mapActivity, "Save as gpx", Toast.LENGTH_SHORT).show();
return true;
case R.id.action_clear_all:
measurementLayer.clearPoints();
updateText();
return true;
}
return false;
}
});
popup.show();
}
});
mapActivity.showTopToolbar(toolBarController);
}
return view; return view;
} }
@ -119,6 +167,9 @@ public class MeasurementToolFragment extends Fragment {
MapActivity mapActivity = getMapActivity(); MapActivity mapActivity = getMapActivity();
MeasurementToolLayer measurementLayer = getMeasurementLayer(); MeasurementToolLayer measurementLayer = getMeasurementLayer();
if (mapActivity != null && measurementLayer != null) { if (mapActivity != null && measurementLayer != null) {
if (toolBarController != null) {
mapActivity.hideTopToolbar(toolBarController);
}
measurementLayer.setInMeasurementMode(false); measurementLayer.setInMeasurementMode(false);
mapActivity.refreshMap(); mapActivity.refreshMap();
mapActivity.enableDrawer(); mapActivity.enableDrawer();
@ -146,4 +197,26 @@ public class MeasurementToolFragment extends Fragment {
} }
} }
} }
private static class MeasurementToolBarController extends TopToolbarController {
MeasurementToolBarController() {
super(MapInfoWidgetsFactory.TopToolbarControllerType.MEASUREMENT_TOOL);
setBackBtnIconClrIds(0, 0);
setCloseBtnIconClrIds(0, 0);
setTitleTextClrIds(R.color.primary_text_dark, R.color.primary_text_dark);
setDescrTextClrIds(R.color.primary_text_dark, R.color.primary_text_dark);
setBgIds(R.drawable.gradient_toolbar, R.drawable.gradient_toolbar,
R.drawable.gradient_toolbar, R.drawable.gradient_toolbar);
setCloseBtnIconIds(R.drawable.ic_overflow_menu_white, R.drawable.ic_overflow_menu_white);
setBackBtnIconIds(R.drawable.ic_action_remove_dark, R.drawable.ic_action_remove_dark);
setSingleLineTitle(false);
}
@Override
public void updateToolbar(MapInfoWidgetsFactory.TopToolbarView view) {
super.updateToolbar(view);
view.getShadowView().setVisibility(View.GONE);
}
}
} }

View file

@ -78,6 +78,7 @@ public class MeasurementToolLayer extends OsmandMapLayer {
void clearPoints() { void clearPoints() {
measurementPoints.clear(); measurementPoints.clear();
view.refreshMap();
} }
@Override @Override

View file

@ -46,6 +46,7 @@ public class MapInfoWidgetsFactory {
CONTEXT_MENU, CONTEXT_MENU,
TRACK_DETAILS, TRACK_DETAILS,
DISCOUNT, DISCOUNT,
MEASUREMENT_TOOL
} }
public TextInfoWidget createAltitudeControl(final MapActivity map) { public TextInfoWidget createAltitudeControl(final MapActivity map) {