Change markers options menu

This commit is contained in:
Alexander Sytnyk 2017-11-13 19:06:44 +02:00
parent 73b074b070
commit 2492b3aaa5
7 changed files with 217 additions and 118 deletions

View file

@ -9,7 +9,8 @@
<android.support.design.widget.AppBarLayout <android.support.design.widget.AppBarLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/dashboard_map_toolbar"> android:layout_height="@dimen/dashboard_map_toolbar"
android:background="?attr/actionModeBackground">
<android.support.v7.widget.Toolbar <android.support.v7.widget.Toolbar
android:id="@+id/map_markers_toolbar" android:id="@+id/map_markers_toolbar"
@ -19,40 +20,16 @@
app:contentInsetLeft="54dp" app:contentInsetLeft="54dp"
app:contentInsetStart="54dp"> app:contentInsetStart="54dp">
<LinearLayout <net.osmand.plus.widgets.TextViewEx
android:layout_width="match_parent" android:layout_width="wrap_content"
android:layout_height="match_parent" android:layout_height="match_parent"
android:ellipsize="end"
android:gravity="center_vertical" android:gravity="center_vertical"
android:orientation="horizontal"> android:maxLines="1"
android:text="@string/map_markers"
<net.osmand.plus.widgets.TextViewEx android:textColor="@color/color_white"
android:layout_width="0dp" android:textSize="@dimen/dialog_header_text_size"
android:layout_height="match_parent" osmand:typeface="@string/font_roboto_medium"/>
android:layout_weight="1"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:text="@string/map_markers"
android:textColor="@color/color_white"
android:textSize="@dimen/dialog_header_text_size"
osmand:typeface="@string/font_roboto_medium"/>
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/options_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground"
android:ellipsize="end"
android:gravity="center_vertical"
android:maxLines="1"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:text="@string/shared_string_options"
android:textAllCaps="true"
android:textColor="@color/color_white"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_medium"/>
</LinearLayout>
</android.support.v7.widget.Toolbar> </android.support.v7.widget.Toolbar>
@ -75,6 +52,12 @@
android:layout_height="match_parent"/> android:layout_height="match_parent"/>
</android.support.design.widget.CoordinatorLayout> </android.support.design.widget.CoordinatorLayout>
<FrameLayout
android:id="@+id/menu_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center_horizontal"/>
<ImageView <ImageView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="@dimen/shadow_height" android:layout_height="@dimen/shadow_height"

View file

@ -230,27 +230,4 @@
</ScrollView> </ScrollView>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>
<FrameLayout
android:id="@+id/cancel_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_cancel_button_height"
android:background="?attr/selectableItemBackground">
<TextView
android:id="@+id/cancel_row_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/shared_string_close"
android:textAllCaps="true"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_desc_text_size"
android:textStyle="bold"/>
</FrameLayout>
</LinearLayout> </LinearLayout>

View file

@ -14,4 +14,8 @@
android:id="@+id/action_history" android:id="@+id/action_history"
android:icon="@drawable/ic_action_history" android:icon="@drawable/ic_action_history"
android:title="@string/shared_string_history"/> android:title="@string/shared_string_history"/>
<item android:id="@+id/action_more"
android:icon="@drawable/ic_navigation_drawer"
android:title="@string/shared_string_more_without_dots"/>
</menu> </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="shared_string_more_without_dots">More</string>
<string name="appearance_on_the_map">Appearance on the map</string> <string name="appearance_on_the_map">Appearance on the map</string>
<string name="add_track_to_markers_descr">Select track waypoints of which OsmAnd will add to markers</string> <string name="add_track_to_markers_descr">Select track waypoints of which OsmAnd will add to markers</string>
<string name="add_favourites_group_to_markers_descr">Select which favourite group you want to add to markers</string> <string name="add_favourites_group_to_markers_descr">Select which favourite group you want to add to markers</string>

View file

@ -44,12 +44,14 @@ public abstract class BottomSheetDialogFragment extends DialogFragment {
public void onStart() { public void onStart() {
super.onStart(); super.onStart();
final Window window = getDialog().getWindow(); if (getDialog() != null) {
WindowManager.LayoutParams params = window.getAttributes(); final Window window = getDialog().getWindow();
params.height = ViewGroup.LayoutParams.WRAP_CONTENT; WindowManager.LayoutParams params = window.getAttributes();
params.gravity = Gravity.BOTTOM; params.height = ViewGroup.LayoutParams.WRAP_CONTENT;
params.width = ViewGroup.LayoutParams.MATCH_PARENT; params.gravity = Gravity.BOTTOM;
window.setAttributes(params); params.width = ViewGroup.LayoutParams.MATCH_PARENT;
window.setAttributes(params);
}
} }

View file

@ -1,11 +1,13 @@
package net.osmand.plus.mapmarkers; package net.osmand.plus.mapmarkers;
import android.app.Dialog;
import android.content.Intent; import android.content.Intent;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.support.design.widget.BottomNavigationView; import android.support.design.widget.BottomNavigationView;
import android.support.design.widget.Snackbar; import android.support.design.widget.Snackbar;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment; import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager; import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter; import android.support.v4.app.FragmentPagerAdapter;
@ -26,6 +28,7 @@ import net.osmand.plus.OsmandSettings.MapMarkersOrderByMode;
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.activities.TrackActivity; import net.osmand.plus.activities.TrackActivity;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment.OnMapMarkersSavedListener; import net.osmand.plus.mapmarkers.CoordinateInputDialogFragment.OnMapMarkersSavedListener;
import net.osmand.plus.mapmarkers.DirectionIndicationDialogFragment.DirectionIndicationFragmentListener; import net.osmand.plus.mapmarkers.DirectionIndicationDialogFragment.DirectionIndicationFragmentListener;
import net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.MarkerOptionsFragmentListener; import net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.MarkerOptionsFragmentListener;
@ -36,6 +39,9 @@ import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import static net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.SHOW_MOVE_ALL_TO_HISTORY_ROW;
import static net.osmand.plus.mapmarkers.OptionsBottomSheetDialogFragment.SHOW_SORT_BY_ROW;
public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragment { public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragment {
public static final String TAG = "MapMarkersDialogFragment"; public static final String TAG = "MapMarkersDialogFragment";
@ -52,9 +58,12 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
private Snackbar snackbar; private Snackbar snackbar;
private LockableViewPager viewPager; private LockableViewPager viewPager;
private BottomNavigationView bottomNav;
private boolean lightTheme; private boolean lightTheme;
private boolean optionsMenuVisible;
@Override @Override
public void onCreate(Bundle savedInstanceState) { public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); super.onCreate(savedInstanceState);
@ -64,6 +73,22 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
setStyle(STYLE_NO_FRAME, themeId); setStyle(STYLE_NO_FRAME, themeId);
} }
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
return new Dialog(getActivity(), getTheme()) {
@Override
public void onBackPressed() {
if (optionsMenuVisible) {
restoreSelectedNavItem();
dismissOptionsMenuFragment();
} else {
super.onBackPressed();
}
}
};
}
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
@ -97,6 +122,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
FragmentManager fragmentManager = getChildFragmentManager(); FragmentManager fragmentManager = getChildFragmentManager();
Fragment optionsFragment = fragmentManager.findFragmentByTag(OptionsBottomSheetDialogFragment.TAG); Fragment optionsFragment = fragmentManager.findFragmentByTag(OptionsBottomSheetDialogFragment.TAG);
if (optionsFragment != null) { if (optionsFragment != null) {
optionsMenuVisible = true;
((OptionsBottomSheetDialogFragment) optionsFragment).setListener(createOptionsFragmentListener()); ((OptionsBottomSheetDialogFragment) optionsFragment).setListener(createOptionsFragmentListener());
} }
Fragment directionIndicationFragment = fragmentManager.findFragmentByTag(DirectionIndicationDialogFragment.TAG); Fragment directionIndicationFragment = fragmentManager.findFragmentByTag(DirectionIndicationDialogFragment.TAG);
@ -118,12 +144,9 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
View mainView = inflater.inflate(R.layout.fragment_map_markers_dialog, container); View mainView = inflater.inflate(R.layout.fragment_map_markers_dialog, container);
Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.map_markers_toolbar);
if (!lightTheme) {
toolbar.setBackgroundColor(ContextCompat.getColor(getContext(), R.color.actionbar_dark_color));
}
setOrderByMode(getMyApplication().getSettings().MAP_MARKERS_ORDER_BY_MODE.get()); setOrderByMode(getMyApplication().getSettings().MAP_MARKERS_ORDER_BY_MODE.get());
Toolbar toolbar = (Toolbar) mainView.findViewById(R.id.map_markers_toolbar);
toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.ic_arrow_back)); toolbar.setNavigationIcon(getMyApplication().getIconsCache().getIcon(R.drawable.ic_arrow_back));
toolbar.setNavigationOnClickListener(new View.OnClickListener() { toolbar.setNavigationOnClickListener(new View.OnClickListener() {
@Override @Override
@ -131,21 +154,6 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
dismiss(); dismiss();
} }
}); });
final View optionsButton = mainView.findViewById(R.id.options_button);
optionsButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
OptionsBottomSheetDialogFragment fragment = new OptionsBottomSheetDialogFragment();
fragment.setUsedOnMap(false);
fragment.setListener(createOptionsFragmentListener());
Bundle args = new Bundle();
int pos = viewPager.getCurrentItem();
args.putBoolean(OptionsBottomSheetDialogFragment.SHOW_SORT_BY_ROW, pos == ACTIVE_MARKERS_POSITION);
args.putBoolean(OptionsBottomSheetDialogFragment.SHOW_MOVE_ALL_TO_HISTORY_ROW, pos != HISTORY_MARKERS_POSITION);
fragment.setArguments(args);
fragment.show(getChildFragmentManager(), OptionsBottomSheetDialogFragment.TAG);
}
});
viewPager = mainView.findViewById(R.id.map_markers_view_pager); viewPager = mainView.findViewById(R.id.map_markers_view_pager);
viewPager.setOffscreenPageLimit(3); viewPager.setOffscreenPageLimit(3);
@ -153,7 +161,12 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
final MapMarkersViewPagerAdapter adapter = new MapMarkersViewPagerAdapter(getChildFragmentManager()); final MapMarkersViewPagerAdapter adapter = new MapMarkersViewPagerAdapter(getChildFragmentManager());
viewPager.setAdapter(adapter); viewPager.setAdapter(adapter);
BottomNavigationView bottomNav = mainView.findViewById(R.id.map_markers_bottom_navigation); if (!AndroidUiHelper.isOrientationPortrait(getActivity())) {
mainView.findViewById(R.id.menu_container).getLayoutParams().width =
getResources().getDimensionPixelSize(R.dimen.landscape_bottom_sheet_dialog_fragment_width);
}
bottomNav = mainView.findViewById(R.id.map_markers_bottom_navigation);
if (!lightTheme) { if (!lightTheme) {
bottomNav.setItemIconTintList(ContextCompat.getColorStateList(getContext(), R.color.bottom_navigation_color_selector_dark)); bottomNav.setItemIconTintList(ContextCompat.getColorStateList(getContext(), R.color.bottom_navigation_color_selector_dark));
bottomNav.setItemTextColor(ContextCompat.getColorStateList(getContext(), R.color.bottom_navigation_color_selector_dark)); bottomNav.setItemTextColor(ContextCompat.getColorStateList(getContext(), R.color.bottom_navigation_color_selector_dark));
@ -169,37 +182,24 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) { public boolean onNavigationItemSelected(@NonNull MenuItem menuItem) {
switch (menuItem.getItemId()) { switch (menuItem.getItemId()) {
case R.id.action_active: case R.id.action_active:
activeFragment.startLocationUpdate(); setupLocationUpdate(true, false);
groupsFragment.stopLocationUpdate(); setupActiveFragment(ACTIVE_MARKERS_POSITION);
if (viewPager.getCurrentItem() != ACTIVE_MARKERS_POSITION) {
hideSnackbar();
activeFragment.updateAdapter();
historyFragment.hideSnackbar();
groupsFragment.hideSnackbar();
}
viewPager.setCurrentItem(ACTIVE_MARKERS_POSITION);
return true; return true;
case R.id.action_groups: case R.id.action_groups:
activeFragment.stopLocationUpdate(); setupLocationUpdate(false, true);
groupsFragment.startLocationUpdate(); setupActiveFragment(GROUPS_POSITION);
if (viewPager.getCurrentItem() != GROUPS_POSITION) {
hideSnackbar();
groupsFragment.updateAdapter();
activeFragment.hideSnackbar();
historyFragment.hideSnackbar();
}
viewPager.setCurrentItem(GROUPS_POSITION);
return true; return true;
case R.id.action_history: case R.id.action_history:
activeFragment.stopLocationUpdate(); setupLocationUpdate(false, false);
groupsFragment.stopLocationUpdate(); setupActiveFragment(HISTORY_MARKERS_POSITION);
if (viewPager.getCurrentItem() != HISTORY_MARKERS_POSITION) { return true;
hideSnackbar(); case R.id.action_more:
historyFragment.updateAdapter(); if (optionsMenuVisible) {
groupsFragment.hideSnackbar(); restoreSelectedNavItem();
activeFragment.hideSnackbar(); dismissOptionsMenuFragment();
} else {
showOptionsMenuFragment();
} }
viewPager.setCurrentItem(HISTORY_MARKERS_POSITION);
return true; return true;
} }
return false; return false;
@ -209,6 +209,46 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
return mainView; return mainView;
} }
private void setupLocationUpdate(boolean activeFr, boolean groupsFr) {
if (activeFr) {
activeFragment.startLocationUpdate();
} else {
activeFragment.stopLocationUpdate();
}
if (groupsFr) {
groupsFragment.startLocationUpdate();
} else {
groupsFragment.stopLocationUpdate();
}
}
private void setupActiveFragment(int position) {
if (optionsMenuVisible) {
dismissOptionsMenuFragment();
}
if (viewPager.getCurrentItem() != position) {
hideSnackbar();
switch (position) {
case ACTIVE_MARKERS_POSITION:
activeFragment.updateAdapter();
groupsFragment.hideSnackbar();
historyFragment.hideSnackbar();
break;
case GROUPS_POSITION:
activeFragment.hideSnackbar();
groupsFragment.updateAdapter();
historyFragment.hideSnackbar();
break;
case HISTORY_MARKERS_POSITION:
activeFragment.hideSnackbar();
groupsFragment.hideSnackbar();
historyFragment.updateAdapter();
break;
}
viewPager.setCurrentItem(position);
}
}
private void updateAdapters() { private void updateAdapters() {
activeFragment.updateAdapter(); activeFragment.updateAdapter();
groupsFragment.updateAdapter(); groupsFragment.updateAdapter();
@ -228,6 +268,47 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
}; };
} }
private void showOptionsMenuFragment() {
OptionsBottomSheetDialogFragment fragment = new OptionsBottomSheetDialogFragment();
fragment.setListener(createOptionsFragmentListener());
Bundle args = new Bundle();
args.putBoolean(SHOW_SORT_BY_ROW, viewPager.getCurrentItem() == ACTIVE_MARKERS_POSITION);
args.putBoolean(SHOW_MOVE_ALL_TO_HISTORY_ROW, viewPager.getCurrentItem() != HISTORY_MARKERS_POSITION);
fragment.setArguments(args);
getChildFragmentManager().beginTransaction()
.add(R.id.menu_container, fragment, OptionsBottomSheetDialogFragment.TAG)
.commitAllowingStateLoss();
optionsMenuVisible = true;
}
private void dismissOptionsMenuFragment() {
Fragment optionsMenu = getChildFragmentManager().findFragmentByTag(OptionsBottomSheetDialogFragment.TAG);
if (optionsMenu != null) {
((DialogFragment) optionsMenu).dismiss();
}
optionsMenuVisible = false;
}
private void restoreSelectedNavItem() {
if (bottomNav.getSelectedItemId() == R.id.action_more) {
int id = -1;
switch (viewPager.getCurrentItem()) {
case ACTIVE_MARKERS_POSITION:
id = R.id.action_active;
break;
case GROUPS_POSITION:
id = R.id.action_groups;
break;
case HISTORY_MARKERS_POSITION:
id = R.id.action_history;
break;
}
if (id != -1) {
bottomNav.setSelectedItemId(id);
}
}
}
private MarkerOptionsFragmentListener createOptionsFragmentListener() { private MarkerOptionsFragmentListener createOptionsFragmentListener() {
return new MarkerOptionsFragmentListener() { return new MarkerOptionsFragmentListener() {
@ -269,7 +350,7 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
Toast.makeText(mapActivity, getString(R.string.plan_route_no_markers_toast), Toast.LENGTH_SHORT).show(); Toast.makeText(mapActivity, getString(R.string.plan_route_no_markers_toast), Toast.LENGTH_SHORT).show();
} else { } else {
PlanRouteFragment.showInstance(mapActivity); PlanRouteFragment.showInstance(mapActivity);
dismiss(); MapMarkersDialogFragment.this.dismiss();
} }
} }
} }
@ -316,6 +397,12 @@ public class MapMarkersDialogFragment extends android.support.v4.app.DialogFragm
snackbar.show(); snackbar.show();
} }
} }
@Override
public void dismiss() {
optionsMenuVisible = false;
restoreSelectedNavItem();
}
}; };
} }

View file

@ -1,18 +1,23 @@
package net.osmand.plus.mapmarkers; package net.osmand.plus.mapmarkers;
import android.app.Activity;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.view.ContextThemeWrapper; import android.view.ContextThemeWrapper;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.ImageView; import android.widget.ImageView;
import net.osmand.AndroidUtils;
import net.osmand.plus.OsmandSettings; import net.osmand.plus.OsmandSettings;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment; import net.osmand.plus.base.BottomSheetDialogFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragment { public class OptionsBottomSheetDialogFragment extends BottomSheetDialogFragment {
public final static String TAG = "OptionsBottomSheetDialogFragment"; public final static String TAG = "OptionsBottomSheetDialogFragment";
public final static String SHOW_SORT_BY_ROW = "show_sort_by_row"; public final static String SHOW_SORT_BY_ROW = "show_sort_by_row";
@ -37,9 +42,9 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm
@Nullable @Nullable
@Override @Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme; final int themeRes = getMyApplication().getSettings().isLightContent() ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme;
final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_options_bottom_sheet_dialog, container); final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.fragment_marker_options_bottom_sheet_dialog, null);
((ImageView) mainView.findViewById(R.id.sort_by_icon)).setImageDrawable(getContentIcon(R.drawable.ic_sort_waypoint_dark)); ((ImageView) mainView.findViewById(R.id.sort_by_icon)).setImageDrawable(getContentIcon(R.drawable.ic_sort_waypoint_dark));
OsmandSettings.MapMarkersMode mode = getMyApplication().getSettings().MAP_MARKERS_MODE.get(); OsmandSettings.MapMarkersMode mode = getMyApplication().getSettings().MAP_MARKERS_MODE.get();
@ -128,18 +133,56 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm
} }
}); });
} }
mainView.findViewById(R.id.cancel_row).setOnClickListener(new View.OnClickListener() {
mainView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override @Override
public void onClick(View view) { public void onGlobalLayout() {
dismiss(); Activity activity = getActivity();
boolean nightMode = !getMyApplication().getSettings().isLightContent();
int allowedHeight = getAllowedHeight();
if (AndroidUiHelper.isOrientationPortrait(activity)) {
if (allowedHeight - mainView.getHeight() >= getResources().getDimension(R.dimen.bottom_sheet_content_padding_small)) {
AndroidUtils.setBackground(activity, mainView, nightMode, R.drawable.bg_bottom_menu_light, R.drawable.bg_bottom_menu_dark);
}
} else {
if (allowedHeight - mainView.getHeight() >= getResources().getDimension(R.dimen.bottom_sheet_content_padding_small)) {
AndroidUtils.setBackground(activity, mainView, nightMode,
R.drawable.bg_bottom_sheet_topsides_landscape_light, R.drawable.bg_bottom_sheet_topsides_landscape_dark);
} else {
AndroidUtils.setBackground(activity, mainView, nightMode,
R.drawable.bg_bottom_sheet_sides_landscape_light, R.drawable.bg_bottom_sheet_sides_landscape_dark);
}
}
ViewTreeObserver obs = mainView.getViewTreeObserver();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
obs.removeOnGlobalLayoutListener(this);
} else {
obs.removeGlobalOnLayoutListener(this);
}
} }
}); });
setupHeightAndBackground(mainView, R.id.marker_options_scroll_view);
return mainView; return mainView;
} }
@Override
public void dismiss() {
if (listener != null) {
listener.dismiss();
}
super.dismiss();
}
private int getAllowedHeight() {
Activity activity = getActivity();
int scrH = AndroidUtils.getScreenHeight(activity);
int stBarH = AndroidUtils.getStatusBarHeight(activity);
int nBarH = AndroidUtils.getNavBarHeight(activity);
return scrH - stBarH - nBarH - getResources().getDimensionPixelSize(R.dimen.dashboard_map_toolbar) - AndroidUtils.dpToPx(activity, 56);
}
interface MarkerOptionsFragmentListener { interface MarkerOptionsFragmentListener {
void sortByOnClick(); void sortByOnClick();
@ -153,5 +196,7 @@ public class OptionsBottomSheetDialogFragment extends MenuBottomSheetDialogFragm
void saveAsNewTrackOnClick(); void saveAsNewTrackOnClick();
void moveAllToHistoryOnClick(); void moveAllToHistoryOnClick();
void dismiss();
} }
} }