Add bottom sheet behaviour dialog
This commit is contained in:
parent
b703536bfe
commit
029b555667
6 changed files with 384 additions and 37 deletions
11
OsmAnd/res/drawable/bottom_sheet_buttons_bg_dark.xml
Normal file
11
OsmAnd/res/drawable/bottom_sheet_buttons_bg_dark.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<nine-patch android:src="@drawable/bg_shadow_bottomsheet_sides"/>
|
||||
</item>
|
||||
<item>
|
||||
<shape>
|
||||
<solid android:color="@color/list_background_color_dark"/>
|
||||
</shape>
|
||||
</item>
|
||||
</layer-list>
|
11
OsmAnd/res/drawable/bottom_sheet_buttons_bg_light.xml
Normal file
11
OsmAnd/res/drawable/bottom_sheet_buttons_bg_light.xml
Normal file
|
@ -0,0 +1,11 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<item>
|
||||
<nine-patch android:src="@drawable/bg_shadow_bottomsheet_sides"/>
|
||||
</item>
|
||||
<item>
|
||||
<shape>
|
||||
<solid android:color="@color/list_background_color_light"/>
|
||||
</shape>
|
||||
</item>
|
||||
</layer-list>
|
50
OsmAnd/res/layout/bottom_sheet_behaviour_base.xml
Normal file
50
OsmAnd/res/layout/bottom_sheet_behaviour_base.xml
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
android:id="@+id/scroll_view_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1">
|
||||
|
||||
<androidx.core.widget.NestedScrollView
|
||||
android:id="@+id/bottom_sheet_scroll_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:behavior_hideable="false"
|
||||
app:layout_behavior="com.google.android.material.bottomsheet.BottomSheetBehavior">
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/items_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical"
|
||||
android:paddingBottom="@dimen/bottom_sheet_content_padding_small" />
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/bottom_buttons_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<androidx.appcompat.widget.AppCompatImageView
|
||||
android:id="@+id/buttons_shadow"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="10dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="@drawable/bg_contextmenu_shadow_top_light"
|
||||
android:visibility="gone" />
|
||||
|
||||
<include layout="@layout/bottom_buttons" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</LinearLayout>
|
|
@ -1,47 +1,40 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.core.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:osmand="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
android:orientation="horizontal"
|
||||
android:paddingStart="@dimen/content_padding"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingTop="@dimen/bottom_sheet_title_padding_top"
|
||||
android:paddingEnd="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:paddingBottom="@dimen/bottom_sheet_title_padding_bottom">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/last_edited"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
android:paddingStart="@dimen/content_padding"
|
||||
android:paddingLeft="@dimen/content_padding"
|
||||
android:paddingTop="@dimen/bottom_sheet_title_padding_top"
|
||||
android:paddingEnd="@dimen/content_padding"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:paddingBottom="@dimen/bottom_sheet_title_padding_bottom">
|
||||
|
||||
<net.osmand.plus.widgets.TextViewEx
|
||||
android:id="@+id/last_edited"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:letterSpacing="@dimen/description_letter_spacing"
|
||||
android:text="@string/plan_route_last_edited"
|
||||
android:textColor="?attr/active_color_basic"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/gpx_track_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
tools:itemCount="1"
|
||||
tools:listitem="@layout/gpx_track_select_item" />
|
||||
android:letterSpacing="@dimen/description_letter_spacing"
|
||||
android:text="@string/plan_route_last_edited"
|
||||
android:textColor="?attr/active_color_basic"
|
||||
android:textSize="@dimen/default_desc_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</androidx.core.widget.NestedScrollView>
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/gpx_track_list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="0dp"
|
||||
android:layout_weight="1"
|
||||
tools:itemCount="1"
|
||||
tools:listitem="@layout/gpx_track_select_item" />
|
||||
|
||||
</LinearLayout>
|
|
@ -0,0 +1,282 @@
|
|||
package net.osmand.plus.base;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import androidx.annotation.ColorInt;
|
||||
import androidx.annotation.ColorRes;
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior;
|
||||
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.UiUtilities.DialogButtonType;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||
import net.osmand.plus.helpers.AndroidUiHelper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BottomSheetBehaviourDialogFragment extends BottomSheetDialogFragment {
|
||||
|
||||
private static final String USED_ON_MAP_KEY = "used_on_map";
|
||||
private static final int DEFAULT_VALUE = -1;
|
||||
|
||||
protected List<BaseBottomSheetItem> items = new ArrayList<>();
|
||||
|
||||
protected boolean usedOnMap = true;
|
||||
protected boolean nightMode;
|
||||
protected boolean portrait;
|
||||
|
||||
protected View dismissButton;
|
||||
protected View rightButton;
|
||||
|
||||
private LinearLayout itemsContainer;
|
||||
|
||||
public void setUsedOnMap(boolean usedOnMap) {
|
||||
this.usedOnMap = usedOnMap;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (savedInstanceState != null) {
|
||||
usedOnMap = savedInstanceState.getBoolean(USED_ON_MAP_KEY);
|
||||
}
|
||||
nightMode = isNightMode(requiredMyApplication());
|
||||
portrait = AndroidUiHelper.isOrientationPortrait(requireActivity());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup parent, Bundle savedInstanceState) {
|
||||
LayoutInflater themedInflater = UiUtilities.getInflater(requireContext(), nightMode);
|
||||
View mainView = themedInflater.inflate(R.layout.bottom_sheet_behaviour_base, parent, false);
|
||||
itemsContainer = (LinearLayout) mainView.findViewById(R.id.items_container);
|
||||
|
||||
View scrollView = mainView.findViewById(R.id.bottom_sheet_scroll_view);
|
||||
final BottomSheetBehavior behavior = BottomSheetBehavior.from(scrollView);
|
||||
behavior.setPeekHeight(getPeekHeight());
|
||||
|
||||
LinearLayout buttonsContainer = (LinearLayout) mainView.findViewById(R.id.buttons_container);
|
||||
buttonsContainer.setBackgroundResource(getButtonsContainerBg());
|
||||
|
||||
if (!portrait) {
|
||||
Dialog dialog = getDialog();
|
||||
if (dialog != null) {
|
||||
dialog.setOnShowListener(new DialogInterface.OnShowListener() {
|
||||
@Override
|
||||
public void onShow(DialogInterface dialog) {
|
||||
behavior.setState(BottomSheetBehavior.STATE_EXPANDED);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
createMenuItems(savedInstanceState);
|
||||
inflateMenuItems();
|
||||
|
||||
dismissButton = mainView.findViewById(R.id.dismiss_button);
|
||||
UiUtilities.setupDialogButton(nightMode, dismissButton, getDismissButtonType(), getDismissButtonTextId());
|
||||
dismissButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onDismissButtonClickAction();
|
||||
dismiss();
|
||||
}
|
||||
});
|
||||
if (hideButtonsContainer()) {
|
||||
mainView.findViewById(R.id.buttons_container).setVisibility(View.GONE);
|
||||
} else {
|
||||
int rightBottomButtonTextId = getRightBottomButtonTextId();
|
||||
if (rightBottomButtonTextId != DEFAULT_VALUE) {
|
||||
mainView.findViewById(R.id.buttons_divider).setVisibility(View.VISIBLE);
|
||||
rightButton = mainView.findViewById(R.id.right_bottom_button);
|
||||
UiUtilities.setupDialogButton(nightMode, rightButton, getRightBottomButtonType(), rightBottomButtonTextId);
|
||||
rightButton.setVisibility(View.VISIBLE);
|
||||
rightButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
onRightBottomButtonClick();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
updateBackground();
|
||||
updateBottomButtons();
|
||||
return mainView;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
FragmentActivity activity = requireActivity();
|
||||
if (!AndroidUiHelper.isOrientationPortrait(activity)) {
|
||||
Dialog dialog = getDialog();
|
||||
Window window = dialog != null ? dialog.getWindow() : null;
|
||||
if (window != null) {
|
||||
WindowManager.LayoutParams params = window.getAttributes();
|
||||
params.width = activity.getResources().getDimensionPixelSize(R.dimen.landscape_bottom_sheet_dialog_fragment_width);
|
||||
window.setAttributes(params);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(@NonNull Bundle outState) {
|
||||
super.onSaveInstanceState(outState);
|
||||
outState.putBoolean(USED_ON_MAP_KEY, usedOnMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
items.clear();
|
||||
if (itemsContainer != null) {
|
||||
itemsContainer.removeAllViews();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract void createMenuItems(Bundle savedInstanceState);
|
||||
|
||||
protected void inflateMenuItems() {
|
||||
Activity activity = requireActivity();
|
||||
for (BaseBottomSheetItem item : items) {
|
||||
item.inflate(activity, itemsContainer, nightMode);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Drawable getContentIcon(@DrawableRes int id) {
|
||||
return getIcon(id, nightMode ? R.color.icon_color_default_dark : R.color.icon_color_default_light);
|
||||
}
|
||||
|
||||
protected Drawable getActiveIcon(@DrawableRes int id) {
|
||||
return getIcon(id, getActiveColorId());
|
||||
}
|
||||
|
||||
@ColorRes
|
||||
protected int getActiveColorId() {
|
||||
return nightMode ? R.color.osmand_orange : R.color.color_myloc_distance;
|
||||
}
|
||||
|
||||
@ColorInt
|
||||
protected int getResolvedColor(@ColorRes int colorId) {
|
||||
Context ctx = getContext();
|
||||
return ctx != null ? ContextCompat.getColor(ctx, colorId) : 0;
|
||||
}
|
||||
|
||||
private void updateBackground() {
|
||||
if (portrait) {
|
||||
itemsContainer.setBackgroundResource(getPortraitBgResId());
|
||||
} else {
|
||||
itemsContainer.setBackgroundResource(getLandscapeTopsidesBgResId());
|
||||
}
|
||||
}
|
||||
|
||||
protected int getPeekHeight() {
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
protected boolean hideButtonsContainer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@StringRes
|
||||
protected int getDismissButtonTextId() {
|
||||
return R.string.shared_string_cancel;
|
||||
}
|
||||
|
||||
protected DialogButtonType getDismissButtonType() {
|
||||
return DialogButtonType.SECONDARY;
|
||||
}
|
||||
|
||||
protected void onDismissButtonClickAction() {
|
||||
|
||||
}
|
||||
|
||||
@StringRes
|
||||
protected int getRightBottomButtonTextId() {
|
||||
return DEFAULT_VALUE;
|
||||
}
|
||||
|
||||
protected DialogButtonType getRightBottomButtonType() {
|
||||
return DialogButtonType.PRIMARY;
|
||||
}
|
||||
|
||||
protected void onRightBottomButtonClick() {
|
||||
|
||||
}
|
||||
|
||||
protected boolean isDismissButtonEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected boolean isRightBottomButtonEnabled() {
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void updateBottomButtons() {
|
||||
if (dismissButton != null) {
|
||||
boolean enabled = isDismissButtonEnabled();
|
||||
dismissButton.setEnabled(enabled);
|
||||
dismissButton.findViewById(R.id.button_text).setEnabled(enabled);
|
||||
}
|
||||
if (rightButton != null) {
|
||||
boolean enabled = isRightBottomButtonEnabled();
|
||||
rightButton.setEnabled(enabled);
|
||||
rightButton.findViewById(R.id.button_text).setEnabled(enabled);
|
||||
}
|
||||
}
|
||||
|
||||
@ColorRes
|
||||
protected int getBgColorId() {
|
||||
return nightMode ? R.color.list_background_color_dark : R.color.list_background_color_light;
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
protected int getPortraitBgResId() {
|
||||
return nightMode ? R.drawable.bg_bottom_menu_dark : R.drawable.bg_bottom_menu_light;
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
protected int getLandscapeTopsidesBgResId() {
|
||||
return nightMode ? R.drawable.bg_bottom_sheet_topsides_landscape_dark : R.drawable.bg_bottom_sheet_topsides_landscape_light;
|
||||
}
|
||||
|
||||
@DrawableRes
|
||||
protected int getLandscapeSidesBgResId() {
|
||||
return nightMode ? R.drawable.bg_bottom_sheet_sides_landscape_dark : R.drawable.bg_bottom_sheet_sides_landscape_light;
|
||||
}
|
||||
|
||||
private int getButtonsContainerBg() {
|
||||
if (portrait) {
|
||||
return getBgColorId();
|
||||
}
|
||||
return nightMode ? R.drawable.bottom_sheet_buttons_bg_dark : R.drawable.bottom_sheet_buttons_bg_light;
|
||||
}
|
||||
|
||||
protected boolean isNightMode(@NonNull OsmandApplication app) {
|
||||
if (usedOnMap) {
|
||||
return app.getDaynightHelper().isNightModeForMapControls();
|
||||
}
|
||||
return !app.getSettings().isLightContent();
|
||||
}
|
||||
}
|
|
@ -19,7 +19,7 @@ import net.osmand.IndexConstants;
|
|||
import net.osmand.PlatformUtil;
|
||||
import net.osmand.plus.OsmandApplication;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
|
||||
import net.osmand.plus.base.BottomSheetBehaviourDialogFragment;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithDescription;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.DividerItem;
|
||||
|
@ -38,7 +38,7 @@ import java.util.List;
|
|||
|
||||
import static net.osmand.plus.helpers.GpxUiHelper.getSortedGPXFilesInfo;
|
||||
|
||||
public class StartPlanRouteBottomSheet extends MenuBottomSheetDialogFragment {
|
||||
public class StartPlanRouteBottomSheet extends BottomSheetBehaviourDialogFragment {
|
||||
|
||||
public static final String TAG = StartPlanRouteBottomSheet.class.getSimpleName();
|
||||
private static final Log LOG = PlatformUtil.getLog(StartPlanRouteBottomSheet.class);
|
||||
|
@ -136,8 +136,8 @@ public class StartPlanRouteBottomSheet extends MenuBottomSheetDialogFragment {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected int getCustomHeight() {
|
||||
return AndroidUtils.dpToPx(mainView.getContext(), BOTTOM_SHEET_HEIGHT_DP);
|
||||
protected int getPeekHeight() {
|
||||
return AndroidUtils.dpToPx(getContext(), BOTTOM_SHEET_HEIGHT_DP);
|
||||
}
|
||||
|
||||
private void onItemClick(int position, List<GPXInfo> gpxInfoList) {
|
||||
|
|
Loading…
Reference in a new issue