Optimising bottom sheet menus in progress

This commit is contained in:
Alexander Sytnyk 2018-02-26 16:00:24 +02:00
parent 227e66c130
commit bdebb86bc6
7 changed files with 159 additions and 286 deletions

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/close_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_cancel_button_height"
android:background="?attr/selectableItemBackground">
<TextView
android:id="@+id/close_row_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/shared_string_cancel"
android:textAllCaps="true"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_desc_text_size"
android:textStyle="bold"/>
</FrameLayout>

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<net.osmand.plus.widgets.TextViewEx
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:id="@+id/title"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_title_height"
android:gravity="center_vertical"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:textAppearance="@style/TextAppearance.ListItemTitle"
osmand:typeface="@string/font_roboto_medium"
tools:text="Some Title"/>

View file

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:minHeight="@dimen/bottom_sheet_selected_item_title_height"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding">
<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/list_destination"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.ListItemTitle"
tools:text="Some title"/>
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/searchbar_text_hint_light"
android:textSize="@dimen/default_desc_text_size"
tools:text="Some description"/>
</LinearLayout>
</LinearLayout>

View file

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
@ -19,111 +18,15 @@
android:orientation="vertical"
android:paddingBottom="@dimen/bottom_sheet_content_padding_small">
<net.osmand.plus.widgets.TextViewEx
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_title_height"
android:gravity="center_vertical"
android:paddingEnd="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingStart="@dimen/content_padding"
android:text="@string/new_destination_point_dialog"
android:textAppearance="@style/TextAppearance.ListItemTitle"
osmand:typeface="@string/font_roboto_medium"/>
<include layout="@layout/bottom_sheet_item_title"/>
<LinearLayout
<include
android:id="@+id/replace_dest_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:minHeight="@dimen/bottom_sheet_selected_item_title_height"
android:paddingEnd="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingStart="@dimen/content_padding">
layout="@layout/bottom_sheet_item_with_descr_56dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
android:src="@drawable/list_destination"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/replace_destination_point"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<TextView
android:id="@+id/current_dest_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/searchbar_text_hint_light"
android:textSize="@dimen/default_desc_text_size"
tools:text="Current: Some street 46"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
<include
android:id="@+id/replace_start_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:minHeight="@dimen/bottom_sheet_selected_item_title_height"
android:paddingEnd="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingStart="@dimen/content_padding">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
android:src="@drawable/list_startpoint"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/make_as_start_point"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<TextView
android:id="@+id/current_start_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textColor="@color/searchbar_text_hint_light"
android:textSize="@dimen/default_desc_text_size"
tools:text="Current: My location"/>
</LinearLayout>
</LinearLayout>
layout="@layout/bottom_sheet_item_with_descr_56dp"/>
<View
android:id="@+id/current_dest_divider"
@ -135,149 +38,17 @@
android:layout_marginTop="@dimen/bottom_sheet_content_padding_small"
android:background="?attr/dashboard_divider"/>
<LinearLayout
<include
android:id="@+id/subsequent_dest_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:minHeight="@dimen/bottom_sheet_selected_item_title_height"
android:paddingEnd="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingStart="@dimen/content_padding">
layout="@layout/bottom_sheet_item_with_descr_56dp"/>
<ImageView
android:id="@+id/subsequent_dest_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:foreground="@drawable/ic_action_route_subsequent_destination"
tools:src="@drawable/ic_action_route_subsequent_destination_point"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/keep_and_add_destination_point"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:text="@string/subsequent_dest_description"
android:textColor="@color/searchbar_text_hint_light"
android:textSize="@dimen/default_desc_text_size"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
<include
android:id="@+id/first_intermediate_dest_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:minHeight="@dimen/bottom_sheet_selected_item_title_height"
android:paddingEnd="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingStart="@dimen/content_padding">
layout="@layout/bottom_sheet_item_with_descr_56dp"/>
<ImageView
android:id="@+id/first_interm_dest_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:foreground="@drawable/ic_action_route_first_intermediate"
tools:src="@drawable/ic_action_route_first_intermediate_point"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/add_as_first_destination_point"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:text="@string/first_intermediate_dest_description"
android:textColor="@color/searchbar_text_hint_light"
android:textSize="@dimen/default_desc_text_size"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
<include
android:id="@+id/last_intermediate_dest_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:minHeight="@dimen/bottom_sheet_selected_item_title_height"
android:paddingEnd="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:paddingStart="@dimen/content_padding">
<ImageView
android:id="@+id/last_interm_dest_icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:foreground="@drawable/ic_action_route_last_intermediate"
tools:src="@drawable/ic_action_route_last_intermediate_point"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:text="@string/add_as_last_destination_point"
android:textAppearance="@style/TextAppearance.ListItemTitle"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:text="@string/last_intermediate_dest_description"
android:textColor="@color/searchbar_text_hint_light"
android:textSize="@dimen/default_desc_text_size"/>
</LinearLayout>
</LinearLayout>
layout="@layout/bottom_sheet_item_with_descr_56dp"/>
</LinearLayout>
@ -289,21 +60,6 @@
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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/shared_string_cancel"
android:textAllCaps="true"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_desc_text_size"
android:textStyle="bold"/>
</FrameLayout>
<include layout="@layout/bottom_sheet_item_cancel"/>
</LinearLayout>

View file

@ -41,21 +41,6 @@
android:layout_height="1dp"
android:background="?attr/dashboard_divider"/>
<FrameLayout
android:id="@+id/close_row"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_cancel_button_height"
android:background="?attr/selectableItemBackground">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/shared_string_cancel"
android:textAllCaps="true"
android:textColor="?attr/color_dialog_buttons"
android:textSize="@dimen/default_desc_text_size"
android:textStyle="bold"/>
</FrameLayout>
<include layout="@layout/bottom_sheet_item_cancel"/>
</LinearLayout>

View file

@ -5,10 +5,14 @@ import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.DrawableRes;
import android.support.annotation.IdRes;
import android.support.annotation.NonNull;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.AndroidUtils;
import net.osmand.plus.R;
@ -99,6 +103,29 @@ public abstract class MenuBottomSheetDialogFragment extends BottomSheetDialogFra
});
}
protected void setupItems(@NonNull final View mainView,
@NonNull @IdRes int[] itemIds,
@NonNull Drawable[] icons,
@NonNull String[] titles,
@NonNull String[] descriptions,
@NonNull View.OnClickListener onClickListener) {
for (int i = 0; i < itemIds.length; i++) {
View item = mainView.findViewById(itemIds[i]);
if (item != null) {
if (icons[i] != null) {
((ImageView) item.findViewById(R.id.icon)).setImageDrawable(icons[i]);
}
if (titles[i] != null) {
((TextView) item.findViewById(R.id.title)).setText(titles[i]);
}
if (descriptions[i] != null) {
((TextView) item.findViewById(R.id.description)).setText(descriptions[i]);
}
item.setOnClickListener(onClickListener);
}
}
}
@DrawableRes
protected int getPortraitBgResId() {
return nightMode ? R.drawable.bg_bottom_menu_dark : R.drawable.bg_bottom_menu_light;

View file

@ -7,13 +7,13 @@ import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Bundle;
import android.support.annotation.DrawableRes;
import android.support.annotation.IdRes;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import net.osmand.data.LatLon;
@ -43,14 +43,43 @@ public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogF
final View mainView = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
R.layout.fragment_add_waypoint_bottom_sheet_dialog, container);
((TextView) mainView.findViewById(R.id.current_dest_text_view))
.setText(getCurrentPointName(targetPointsHelper.getPointToNavigate(), false));
((TextView) mainView.findViewById(R.id.current_start_text_view))
.setText(getCurrentPointName(targetPointsHelper.getPointToStart(), true));
((TextView) mainView.findViewById(R.id.title)).setText(R.string.new_destination_point_dialog);
((ImageView) mainView.findViewById(R.id.subsequent_dest_icon)).setImageDrawable(getSubsequentDestIcon());
((ImageView) mainView.findViewById(R.id.first_interm_dest_icon)).setImageDrawable(getFirstIntermDestIcon());
((ImageView) mainView.findViewById(R.id.last_interm_dest_icon)).setImageDrawable(getLastIntermDistIcon());
@IdRes int[] ids = new int[]{
R.id.replace_dest_row,
R.id.replace_start_row,
R.id.subsequent_dest_row,
R.id.first_intermediate_dest_row,
R.id.last_intermediate_dest_row,
R.id.close_row
};
Drawable[] icons = new Drawable[]{
getIcon(R.drawable.list_destination, 0),
getIcon(R.drawable.list_startpoint, 0),
getSubsequentDestIcon(),
getFirstIntermDestIcon(),
getLastIntermDistIcon(),
null
};
String[] titles = new String[]{
getString(R.string.replace_destination_point),
getString(R.string.make_as_start_point),
getString(R.string.keep_and_add_destination_point),
getString(R.string.add_as_first_destination_point),
getString(R.string.add_as_last_destination_point),
null
};
String[] descriptions = new String[]{
getCurrentPointName(targetPointsHelper.getPointToNavigate(), false),
getCurrentPointName(targetPointsHelper.getPointToStart(), true),
getString(R.string.subsequent_dest_description),
getString(R.string.first_intermediate_dest_description),
getString(R.string.last_intermediate_dest_description),
null
};
View.OnClickListener onClickListener = new View.OnClickListener() {
@Override
@ -77,12 +106,7 @@ public class AddWaypointBottomSheetDialogFragment extends MenuBottomSheetDialogF
}
};
mainView.findViewById(R.id.replace_dest_row).setOnClickListener(onClickListener);
mainView.findViewById(R.id.replace_start_row).setOnClickListener(onClickListener);
mainView.findViewById(R.id.subsequent_dest_row).setOnClickListener(onClickListener);
mainView.findViewById(R.id.first_intermediate_dest_row).setOnClickListener(onClickListener);
mainView.findViewById(R.id.last_intermediate_dest_row).setOnClickListener(onClickListener);
mainView.findViewById(R.id.cancel_row).setOnClickListener(onClickListener);
setupItems(mainView, ids, icons, titles, descriptions, onClickListener);
if (nightMode) {
int dividerColor = ContextCompat.getColor(getContext(), R.color.route_info_bottom_view_bg_dark);