From 5d6101f23aae4c9d2324bb0a33ca688fbde06747 Mon Sep 17 00:00:00 2001 From: Skalii Date: Wed, 20 Jan 2021 17:22:44 +0200 Subject: [PATCH 001/158] set overview as default tab; add layout for overview fragment; add layouts for action items; add OverviewCard. --- OsmAnd/res/layout/gpx_overview_fragment.xml | 104 ++++++ OsmAnd/res/layout/item_gpx_action.xml | 22 ++ OsmAnd/res/layout/item_gpx_action_segment.xml | 46 +++ .../res/menu/track_menu_bottom_navigation.xml | 8 +- .../net/osmand/plus/track/OverviewCard.java | 334 ++++++++++++++++++ .../osmand/plus/track/TrackMenuFragment.java | 22 +- 6 files changed, 528 insertions(+), 8 deletions(-) create mode 100644 OsmAnd/res/layout/gpx_overview_fragment.xml create mode 100644 OsmAnd/res/layout/item_gpx_action.xml create mode 100644 OsmAnd/res/layout/item_gpx_action_segment.xml create mode 100644 OsmAnd/src/net/osmand/plus/track/OverviewCard.java diff --git a/OsmAnd/res/layout/gpx_overview_fragment.xml b/OsmAnd/res/layout/gpx_overview_fragment.xml new file mode 100644 index 0000000000..e02826fcbf --- /dev/null +++ b/OsmAnd/res/layout/gpx_overview_fragment.xml @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/item_gpx_action.xml b/OsmAnd/res/layout/item_gpx_action.xml new file mode 100644 index 0000000000..940f85d8bf --- /dev/null +++ b/OsmAnd/res/layout/item_gpx_action.xml @@ -0,0 +1,22 @@ + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/item_gpx_action_segment.xml b/OsmAnd/res/layout/item_gpx_action_segment.xml new file mode 100644 index 0000000000..962941b95c --- /dev/null +++ b/OsmAnd/res/layout/item_gpx_action_segment.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/menu/track_menu_bottom_navigation.xml b/OsmAnd/res/menu/track_menu_bottom_navigation.xml index fa07fb12a4..1b0de6b246 100644 --- a/OsmAnd/res/menu/track_menu_bottom_navigation.xml +++ b/OsmAnd/res/menu/track_menu_bottom_navigation.xml @@ -1,10 +1,10 @@ - - - - + items = new ArrayList<>(); + items.add(item1); + items.add(item2); + items.add(item3); + items.add(item4); + items.add(item5); + items.add(item6); + + rvOverview = view.findViewById(R.id.recycler_overview); + LinearLayoutManager llManager = new LinearLayoutManager(app); + llManager.setOrientation(LinearLayoutManager.HORIZONTAL); + rvOverview.setLayoutManager(llManager); + rvOverview.setItemAnimator(new DefaultItemAnimator()); + final SegmentItemAdapter oiAdapter = new SegmentItemAdapter(items); + rvOverview.setAdapter(oiAdapter); + rvOverview.addItemDecoration(new HorizontalDividerDecoration(app)); + + } + + private void initShowButton(final int iconColorDef, final int iconColorPres) { + final AppCompatImageView image = showButton.findViewById(R.id.image); + final AppCompatImageView filled = showButton.findViewById(R.id.filled); + final int iconShowResId = R.drawable.ic_action_view; + final int iconHideResId = R.drawable.ic_action_hide; + final boolean[] gpxFileSelected = {isGpxFileSelected(app, gpxFile)}; + filled.setImageResource(R.drawable.bg_topbar_shield_exit_ref); + filled.setAlpha(gpxFileSelected[0] ? 1f : 0.1f); + setImageDrawable(image, gpxFileSelected[0] ? iconShowResId : iconHideResId, + gpxFileSelected[0] ? iconColorPres : iconColorDef); + showButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + gpxFileSelected[0] = !gpxFileSelected[0]; + + setImageDrawable(image, gpxFileSelected[0] ? iconShowResId : iconHideResId, + gpxFileSelected[0] ? iconColorPres : iconColorDef); + + filled.setAlpha(gpxFileSelected[0] ? 1f : 0.1f); + + CardListener listener = getListener(); + if (listener != null) { + listener.onCardButtonPressed(OverviewCard.this, SHOW_ON_MAP_BUTTON_INDEX); + } + } + }); + } + + private void initAppearanceButton(int iconColorDef, int iconColorPres) { + initButton(appearanceButton, APPEARANCE_BUTTON_INDEX, R.drawable.ic_action_appearance, iconColorDef, iconColorPres); + } + + private void initEditButton(int iconColorDef, int iconColorPres) { + initButton(editButton, EDIT_BUTTON_INDEX, R.drawable.ic_action_edit_dark, iconColorDef, iconColorPres); + } + + private void initDirectionsButton(int iconColorDef, int iconColorPres) { + initButton(directionsButton, DIRECTIONS_BUTTON_INDEX, R.drawable.ic_action_gdirections_dark, iconColorDef, iconColorPres); + } + + private void initButton(View item, final int buttonIndex, int iconResId, int iconColorDef, int iconColorPres) { + final AppCompatImageView image = item.findViewById(R.id.image); + final AppCompatImageView filled = item.findViewById(R.id.filled); + filled.setImageResource(R.drawable.bg_topbar_shield_exit_ref); + filled.setAlpha(0.1f); + setImageDrawable(image, iconResId, iconColorDef); + setOnTouchItem(item, image, filled, iconResId, iconColorDef, iconColorPres); + item.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + CardListener listener = getListener(); + if (listener != null) { + listener.onCardButtonPressed(OverviewCard.this, buttonIndex); + } + } + }); + } + + private void setImageDrawable(ImageView iv, @DrawableRes int resId, @ColorRes int color) { + Drawable icon = app.getUIUtilities().getIcon(resId, color); + iv.setImageDrawable(icon); + } + + private void setOnTouchItem(View item, final ImageView image, final ImageView filled, @DrawableRes final int resId, @ColorRes final int colorDef, @ColorRes final int colorPres) { + item.setOnTouchListener(new View.OnTouchListener() { + @SuppressLint("ClickableViewAccessibility") + @Override + public boolean onTouch(View v, MotionEvent event) { + switch (event.getAction()) { + case MotionEvent.ACTION_DOWN: { + filled.setAlpha(1f); + setImageDrawable(image, resId, colorPres); + break; + } + case MotionEvent.ACTION_UP: + case MotionEvent.ACTION_CANCEL: { + filled.setAlpha(0.1f); + setImageDrawable(image, resId, colorDef); + break; + } + } + return false; + } + }); + } + + private class SegmentItemAdapter extends RecyclerView.Adapter { + private final List segmentItems; + + public SegmentItemAdapter(List segmentItems) { + this.segmentItems = segmentItems; + } + + @Override + public int getItemCount() { + return segmentItems.size(); + } + + @NonNull + @Override + public SegmentItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View itemView = LayoutInflater.from(parent.getContext()) + .inflate(R.layout.item_gpx_action_segment, parent, false); + return new SegmentItemViewHolder(itemView); + } + + @Override + public void onBindViewHolder(SegmentItemViewHolder holder, int position) { + SegmentItem item = segmentItems.get(position); + holder.bind(item); + } + + + class SegmentItemViewHolder extends RecyclerView.ViewHolder { + private final TextViewEx valueText; + private final TextView titleText; + private final AppCompatImageView imageView; + + SegmentItemViewHolder(View view) { + super(view); + valueText = view.findViewById(R.id.value); + titleText = view.findViewById(R.id.title); + imageView = view.findViewById(R.id.image); + } + + public void bind(SegmentItem overviewItem) { + valueText.setText(overviewItem.value); + titleText.setText(overviewItem.title); + setImageDrawable(imageView, overviewItem.imageResId, R.color.text_color_primary_light); //todo change color + } + } + } + + private class HorizontalDividerDecoration extends RecyclerView.ItemDecoration { + private final Drawable divider; + + public HorizontalDividerDecoration(Context context) { + int[] ATTRS = new int[]{android.R.attr.listDivider}; + final TypedArray a = context.obtainStyledAttributes(ATTRS); + divider = a.getDrawable(0); + a.recycle(); +// mDivider = getMyApplication().getUIUtilities().getIcon(R.drawable.divider_solid, R.color.divider_color_light); //todo change drawable + } + + @Override + public void onDraw(@NonNull Canvas c, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { + drawHorizontal(c, parent); + } + + public void drawHorizontal(Canvas c, RecyclerView parent) { + final int marginV = parent.getContext().getResources().getDimensionPixelSize(R.dimen.map_small_button_margin); + final int marginH = parent.getContext().getResources().getDimensionPixelSize(R.dimen.content_padding); + final int childCount = parent.getChildCount(); + for (int i = 0; i < childCount; i++) { + final View child = parent.getChildAt(i); + final int left = child.getRight() - divider.getIntrinsicWidth() + marginH; + final int right = left + divider.getIntrinsicHeight(); + final int top = child.getTop() + marginV; + final int bottom = child.getBottom() - marginV; + divider.setBounds(left, top, right, bottom); + divider.draw(c); + } + } + + @Override + public void getItemOffsets(Rect outRect, @NonNull View view, @NonNull RecyclerView parent, @NonNull RecyclerView.State state) { + int marginV = parent.getContext().getResources().getDimensionPixelSize(R.dimen.map_small_button_margin); + int marginH = parent.getContext().getResources().getDimensionPixelSize(R.dimen.content_padding); + outRect.set(marginH - divider.getIntrinsicWidth(), marginV, marginH + divider.getIntrinsicWidth(), marginV); + } + } + + private class SegmentItem { + private String title; + private String value; + private int imageResId; + + public SegmentItem(String title, String value, int imageResId) { + this.title = title; + this.value = value; + this.imageResId = imageResId; + } + + public String getTitle() { + return title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getValue() { + return value; + } + + public void setValue(String value) { + this.value = value; + } + + public int getImageResId() { + return imageResId; + } + + public void setImageResId(int imageResId) { + this.imageResId = imageResId; + } + } +} \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 03f8ab374a..f102331bfc 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -109,15 +109,17 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card private TextView headerTitle; private ImageView headerIcon; private BottomNavigationView bottomNav; - private TrackMenuType menuType = TrackMenuType.TRACK; + private TrackMenuType menuType = TrackMenuType.OVERVIEW; private SegmentsCard segmentsCard; private OptionsCard optionsCard; + private OverviewCard overviewCard; private TrackChartPoints trackChartPoints; private int menuTitleHeight; public enum TrackMenuType { + OVERVIEW(R.id.action_overview, R.string.shared_string_overview), TRACK(R.id.action_track, R.string.shared_string_gpx_tracks), POINTS(R.id.action_points, R.string.shared_string_gpx_points), OPTIONS(R.id.action_options, R.string.shared_string_options); @@ -234,7 +236,19 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card if (mapActivity != null) { ViewGroup cardsContainer = getCardsContainer(); cardsContainer.removeAllViews(); - if (menuType == TrackMenuType.TRACK) { + if (menuType == TrackMenuType.OVERVIEW) { + if (overviewCard != null && overviewCard.getView() != null) { + ViewGroup parent = (ViewGroup) overviewCard.getView().getParent(); + if (parent != null) { + parent.removeAllViews(); + } + cardsContainer.addView(overviewCard.getView()); + } else { + overviewCard = new OverviewCard(mapActivity, displayHelper, this); + overviewCard.setListener(this); + cardsContainer.addView(overviewCard.build(mapActivity)); + } + } else if (menuType == TrackMenuType.TRACK) { if (segmentsCard != null && segmentsCard.getView() != null) { ViewGroup parent = (ViewGroup) segmentsCard.getView().getParent(); if (parent != null) { @@ -415,7 +429,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card if (mapActivity == null) { return; } - if (card instanceof OptionsCard) { + if (card instanceof OptionsCard || card instanceof OverviewCard) { final GPXFile gpxFile = getGpx(); if (buttonIndex == SHOW_ON_MAP_BUTTON_INDEX) { boolean gpxFileSelected = !isGpxFileSelected(app, gpxFile); @@ -567,7 +581,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card BottomNavigationView bottomNav = view.findViewById(R.id.bottom_navigation); bottomNav.setItemIconTintList(navColorStateList); bottomNav.setItemTextColor(navColorStateList); - bottomNav.setSelectedItemId(R.id.action_track); + bottomNav.setSelectedItemId(R.id.action_overview); bottomNav.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { From a4cc3f83c87bd5d56c4ecb4a9c092077249a397c Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Wed, 20 Jan 2021 22:19:27 +0200 Subject: [PATCH 002/158] Track tab - GPX Context menu Change UI for statistic block (Distance, Timespan etc). The text should be on the left and icon on the right, the icon is 16dp (currently is used big 24dp icons) Options edit, delete, split interval --- OsmAnd/res/layout/gpx_item_altitude.xml | 446 ++++++++---------- OsmAnd/res/layout/gpx_item_general.xml | 397 +++++++--------- OsmAnd/res/layout/gpx_item_speed.xml | 355 ++++++-------- OsmAnd/res/menu/track_segment_menu.xml | 5 + .../plus/myplaces/GPXItemPagerAdapter.java | 41 +- .../plus/myplaces/SegmentActionsListener.java | 2 +- .../plus/myplaces/TrackSegmentFragment.java | 16 +- .../osmand/plus/track/TrackMenuFragment.java | 16 +- 8 files changed, 563 insertions(+), 715 deletions(-) diff --git a/OsmAnd/res/layout/gpx_item_altitude.xml b/OsmAnd/res/layout/gpx_item_altitude.xml index af46a440a4..6563cb8c31 100644 --- a/OsmAnd/res/layout/gpx_item_altitude.xml +++ b/OsmAnd/res/layout/gpx_item_altitude.xml @@ -1,11 +1,11 @@ + 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" + android:background="?attr/bg_color" + android:orientation="vertical"> + android:layout_height="@dimen/list_item_description_width" + android:layout_gravity="center_vertical" /> + osmand:typeface="@string/font_roboto_regular" /> + android:paddingEnd="@dimen/content_padding" + android:paddingRight="@dimen/content_padding" /> @@ -61,242 +61,98 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" - android:paddingTop="13dp" - android:paddingBottom="11dp"> + android:paddingTop="@dimen/context_menu_first_line_top_margin" + android:paddingBottom="@dimen/content_padding_small"> - - + android:layout_marginStart="@dimen/content_padding" + android:layout_marginLeft="@dimen/content_padding" + android:layout_marginEnd="@dimen/content_padding_small" + android:layout_marginRight="@dimen/content_padding_small" + android:layout_weight="1" + android:orientation="horizontal"> - - + android:layout_weight="1" + android:orientation="vertical"> + android:textSize="@dimen/default_desc_text_size" /> + + + + - - + android:orientation="horizontal"> - - + android:layout_weight="1" + android:orientation="vertical"> - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + android:textSize="@dimen/default_desc_text_size" /> - - + tools:text="30m - 53m" /> - - - - - - - - - - - - + android:layout_height="@dimen/poi_icon_size" + android:layout_marginTop="@dimen/subHeaderPadding" + osmand:srcCompat="@drawable/ic_action_altitude_average" /> @@ -305,61 +161,157 @@ + android:layout_marginStart="@dimen/content_padding_small" + android:layout_marginLeft="@dimen/content_padding_small" + android:layout_marginEnd="@dimen/content_padding_small" + android:layout_marginRight="@dimen/content_padding_small" + android:background="?attr/dashboard_divider" /> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + android:gravity="center" + android:orientation="horizontal"> - - + android:textColor="?attr/color_dialog_buttons" + android:textSize="@dimen/default_list_text_size" + osmand:typeface="@string/font_roboto_regular" /> + + diff --git a/OsmAnd/res/layout/gpx_item_general.xml b/OsmAnd/res/layout/gpx_item_general.xml index d0f23f6a38..b24f63be69 100644 --- a/OsmAnd/res/layout/gpx_item_general.xml +++ b/OsmAnd/res/layout/gpx_item_general.xml @@ -1,11 +1,11 @@ + 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" + android:background="?attr/bg_color" + android:orientation="vertical"> + android:layout_height="@dimen/list_item_description_width" + android:layout_gravity="center_vertical" /> + osmand:typeface="@string/font_roboto_regular" /> + android:paddingEnd="@dimen/content_padding" + android:paddingRight="@dimen/content_padding" /> @@ -61,144 +61,112 @@ android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" - android:paddingTop="13dp" - android:paddingBottom="11dp"> + android:paddingTop="@dimen/context_menu_first_line_top_margin" + android:paddingBottom="@dimen/content_padding"> - - + android:layout_marginStart="@dimen/content_padding" + android:layout_marginLeft="@dimen/content_padding" + android:layout_marginEnd="@dimen/content_padding_small" + android:layout_marginRight="@dimen/content_padding_small" + android:layout_weight="1" + android:orientation="horizontal"> - - + android:layout_weight="1" + android:orientation="vertical"> + android:textSize="@dimen/default_desc_text_size" /> + + + + - - + android:orientation="horizontal"> - - + android:layout_weight="1" + android:orientation="vertical"> + android:textSize="@dimen/default_desc_text_size" /> + + + + + - - - - - - - - - - - - - - - + android:layout_height="1dp" + android:layout_marginStart="@dimen/content_padding_small" + android:layout_marginLeft="@dimen/content_padding_small" + android:layout_marginEnd="@dimen/content_padding_small" + android:layout_marginRight="@dimen/content_padding_small" + android:background="?attr/dashboard_divider" /> - - + android:layout_marginStart="@dimen/content_padding" + android:layout_marginLeft="@dimen/content_padding" + android:layout_marginEnd="@dimen/content_padding_small" + android:layout_marginRight="@dimen/content_padding_small" + android:layout_weight="1" + android:orientation="horizontal"> - - - - + android:layout_weight="1" + android:orientation="vertical"> + android:textSize="@dimen/default_desc_text_size" /> + + + + + + - - + android:orientation="horizontal"> - - - - + android:layout_weight="1" + android:orientation="vertical"> + android:textSize="@dimen/default_desc_text_size" /> + + + + + + @@ -323,61 +291,46 @@ + android:background="?attr/dashboard_divider" /> - - + android:gravity="center" + android:orientation="horizontal"> - - + android:textColor="?attr/color_dialog_buttons" + android:textSize="@dimen/default_list_text_size" + osmand:typeface="@string/font_roboto_regular" /> + + diff --git a/OsmAnd/res/layout/gpx_item_speed.xml b/OsmAnd/res/layout/gpx_item_speed.xml index 0c98402703..d2cbbff4f2 100644 --- a/OsmAnd/res/layout/gpx_item_speed.xml +++ b/OsmAnd/res/layout/gpx_item_speed.xml @@ -1,11 +1,11 @@ + 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" + android:background="?attr/bg_color" + android:orientation="vertical"> + android:layout_gravity="center_vertical" /> + osmand:typeface="@string/font_roboto_regular" /> + android:paddingEnd="@dimen/content_padding" + android:paddingRight="@dimen/content_padding" /> @@ -66,139 +66,106 @@ - - + android:layout_marginStart="@dimen/content_padding" + android:layout_marginLeft="@dimen/content_padding" + android:layout_marginEnd="@dimen/content_padding_small" + android:layout_marginRight="@dimen/content_padding_small" + android:layout_weight="1" + android:orientation="horizontal"> - - + android:layout_weight="1" + android:orientation="vertical"> + android:textSize="@dimen/default_desc_text_size" /> + + + + - - + android:orientation="horizontal"> - - + android:layout_weight="1" + android:orientation="vertical"> + android:textSize="@dimen/default_desc_text_size" /> + + + + - - - - - - - - - - - - - - - + android:layout_height="1dp" + android:layout_marginStart="@dimen/content_padding_small" + android:layout_marginLeft="@dimen/content_padding_small" + android:layout_marginEnd="@dimen/content_padding_small" + android:layout_marginRight="@dimen/content_padding_small" + android:background="?attr/dashboard_divider" /> - - + android:layout_marginStart="@dimen/content_padding" + android:layout_marginLeft="@dimen/content_padding" + android:layout_marginEnd="@dimen/content_padding_small" + android:layout_marginRight="@dimen/content_padding_small" + android:layout_weight="1" + android:orientation="horizontal"> - - + android:layout_weight="1" + android:orientation="vertical"> + android:textSize="@dimen/default_desc_text_size" /> + + + + - - + android:orientation="horizontal"> + android:layout_weight="1" + android:orientation="vertical"> + + - - + tools:text="42 km" /> + + @@ -305,61 +273,46 @@ + android:background="?attr/dashboard_divider" /> - - + android:gravity="center" + android:orientation="horizontal"> - - + android:textColor="?attr/color_dialog_buttons" + android:textSize="@dimen/default_list_text_size" + osmand:typeface="@string/font_roboto_regular" /> + + diff --git a/OsmAnd/res/menu/track_segment_menu.xml b/OsmAnd/res/menu/track_segment_menu.xml index 196bb49b2f..2b5b3ba46d 100644 --- a/OsmAnd/res/menu/track_segment_menu.xml +++ b/OsmAnd/res/menu/track_segment_menu.xml @@ -9,4 +9,9 @@ android:id="@+id/action_delete" android:icon="@drawable/ic_action_remove_dark" android:title="@string/shared_string_delete"/> + + \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java b/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java index 81d9ee9d72..185c915cbc 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/GPXItemPagerAdapter.java @@ -275,17 +275,7 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid openAnalyzeOnMap(GPXTabItemType.GPX_TAB_ITEM_SPEED); } }); - if (gpxFile.showCurrentTrack) { - view.findViewById(R.id.split_interval).setVisibility(View.GONE); - } else { - view.findViewById(R.id.split_interval).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - openSplitIntervalScreen(); - } - }); - } - ImageView overflowMenu = view.findViewById(R.id.overflow_menu); + TextView overflowMenu = view.findViewById(R.id.overflow_menu); if (!gpxItem.group.getTrack().generalTrack) { setupOptionsPopupMenu(overflowMenu, false); } else { @@ -293,13 +283,12 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid } } - private void setupOptionsPopupMenu(ImageView overflowMenu, final boolean confirmDeletion) { - overflowMenu.setImageDrawable(iconsCache.getThemedIcon(R.drawable.ic_overflow_menu_white)); + private void setupOptionsPopupMenu(TextView overflowMenu, final boolean confirmDeletion) { overflowMenu.setVisibility(View.VISIBLE); overflowMenu.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - actionsListener.showOptionsPopupMenu(view, getTrkSegment(), confirmDeletion); + actionsListener.showOptionsPopupMenu(view, getTrkSegment(), confirmDeletion, gpxItem); } }); } @@ -359,17 +348,7 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid openAnalyzeOnMap(GPXTabItemType.GPX_TAB_ITEM_ALTITUDE); } }); - if (gpxFile.showCurrentTrack) { - view.findViewById(R.id.split_interval).setVisibility(View.GONE); - } else { - view.findViewById(R.id.split_interval).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - openSplitIntervalScreen(); - } - }); - } - ImageView overflowMenu = view.findViewById(R.id.overflow_menu); + TextView overflowMenu = view.findViewById(R.id.overflow_menu); if (!gpxItem.group.getTrack().generalTrack) { setupOptionsPopupMenu(overflowMenu, false); } else { @@ -436,17 +415,7 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid openAnalyzeOnMap(GPXTabItemType.GPX_TAB_ITEM_GENERAL); } }); - if (gpxFile.showCurrentTrack) { - view.findViewById(R.id.split_interval).setVisibility(View.GONE); - } else { - view.findViewById(R.id.split_interval).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - openSplitIntervalScreen(); - } - }); - } - ImageView overflowMenu = view.findViewById(R.id.overflow_menu); + TextView overflowMenu = view.findViewById(R.id.overflow_menu); if (!gpxItem.group.getTrack().generalTrack) { setupOptionsPopupMenu(overflowMenu, true); } else { diff --git a/OsmAnd/src/net/osmand/plus/myplaces/SegmentActionsListener.java b/OsmAnd/src/net/osmand/plus/myplaces/SegmentActionsListener.java index 4033dedd7a..e6bea1b9f6 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/SegmentActionsListener.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/SegmentActionsListener.java @@ -21,7 +21,7 @@ public interface SegmentActionsListener { void openSplitInterval(GpxDisplayItem gpxItem, TrkSegment trkSegment); - void showOptionsPopupMenu(View view, TrkSegment trkSegment, boolean confirmDeletion); + void showOptionsPopupMenu(View view, TrkSegment trkSegment, boolean confirmDeletion, GpxDisplayItem gpxItem); void openAnalyzeOnMap(GpxDisplayItem gpxItem, List dataSets, GPXTabItemType tabType); } diff --git a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java index c10fa883ad..c60092ea1f 100644 --- a/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java +++ b/OsmAnd/src/net/osmand/plus/myplaces/TrackSegmentFragment.java @@ -66,7 +66,7 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit private TrackDisplayHelper displayHelper; private TrackActivityFragmentAdapter fragmentAdapter; private SegmentGPXAdapter adapter; - private final GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[] {GpxDisplayItemType.TRACK_SEGMENT}; + private final GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[]{GpxDisplayItemType.TRACK_SEGMENT}; private IconPopupMenu optionsPopupMenu; private boolean updateEnable; @@ -357,14 +357,20 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit } @Override - public void showOptionsPopupMenu(View view, final TrkSegment segment, final boolean confirmDeletion) { + public void showOptionsPopupMenu(final View view, final TrkSegment segment, final boolean confirmDeletion, final GpxDisplayItem gpxItem) { FragmentActivity activity = getActivity(); if (activity != null) { - optionsPopupMenu = new IconPopupMenu(activity, view.findViewById(R.id.overflow_menu)); - Menu menu = optionsPopupMenu.getMenu(); + IconPopupMenu optionsPopupMenu = new IconPopupMenu(activity, view.findViewById(R.id.overflow_menu)); + final Menu menu = optionsPopupMenu.getMenu(); optionsPopupMenu.getMenuInflater().inflate(R.menu.track_segment_menu, menu); menu.findItem(R.id.action_edit).setIcon(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_edit_dark)); menu.findItem(R.id.action_delete).setIcon(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_remove_dark)); + boolean isSelectedTrackRecordingNow = displayHelper.getGpx().showCurrentTrack; + if (isSelectedTrackRecordingNow) { + menu.findItem(R.id.split_interval).setVisible(false); + } else { + menu.findItem(R.id.split_interval).setIcon(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_split_interval)); + } optionsPopupMenu.setOnMenuItemClickListener(new IconPopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { @@ -389,6 +395,8 @@ public class TrackSegmentFragment extends OsmAndListFragment implements TrackBit builder.show(); } return true; + } else if (i == R.id.split_interval) { + openSplitInterval(gpxItem, segment); } return false; } diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 03f8ab374a..c066e0136f 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -462,7 +462,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card segment = segments.get(0); } } - GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[] {GpxDisplayItemType.TRACK_SEGMENT}; + GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[]{GpxDisplayItemType.TRACK_SEGMENT}; List items = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes)); if (segment != null && !Algorithms.isEmpty(items)) { SplitSegmentDialogFragment.showInstance(fragmentManager, displayHelper, items.get(0), segment); @@ -677,14 +677,20 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } @Override - public void showOptionsPopupMenu(View view, final TrkSegment segment, final boolean confirmDeletion) { + public void showOptionsPopupMenu(final View view, final TrkSegment segment, final boolean confirmDeletion, final GpxDisplayItem gpxItem) { FragmentActivity activity = getActivity(); if (activity != null) { IconPopupMenu optionsPopupMenu = new IconPopupMenu(activity, view.findViewById(R.id.overflow_menu)); - Menu menu = optionsPopupMenu.getMenu(); + final Menu menu = optionsPopupMenu.getMenu(); optionsPopupMenu.getMenuInflater().inflate(R.menu.track_segment_menu, menu); menu.findItem(R.id.action_edit).setIcon(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_edit_dark)); menu.findItem(R.id.action_delete).setIcon(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_remove_dark)); + boolean isSelectedTrackRecordingNow = displayHelper.getGpx().showCurrentTrack; + if (isSelectedTrackRecordingNow) { + menu.findItem(R.id.split_interval).setVisible(false); + } else { + menu.findItem(R.id.split_interval).setIcon(app.getUIUtilities().getThemedIcon(R.drawable.ic_action_split_interval)); + } optionsPopupMenu.setOnMenuItemClickListener(new IconPopupMenu.OnMenuItemClickListener() { @Override public boolean onMenuItemClick(MenuItem item) { @@ -709,6 +715,8 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card builder.show(); } return true; + } else if (i == R.id.split_interval) { + openSplitInterval(gpxItem, segment); } return false; } @@ -762,7 +770,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card @Override public void gpxSavingFinished(Exception errorMessage) { if (selectedGpxFile != null) { - List groups = displayHelper.getDisplayGroups(new GpxDisplayItemType[] {GpxDisplayItemType.TRACK_SEGMENT}); + List groups = displayHelper.getDisplayGroups(new GpxDisplayItemType[]{GpxDisplayItemType.TRACK_SEGMENT}); selectedGpxFile.setDisplayGroups(groups, app); selectedGpxFile.processPoints(app); } From 3a2b54bbcc4866b02143a38899e9de76523670a5 Mon Sep 17 00:00:00 2001 From: androiddevkotlin <64539346+androiddevkotlin@users.noreply.github.com> Date: Wed, 20 Jan 2021 22:58:21 +0200 Subject: [PATCH 003/158] Hide/show divider fix --- OsmAnd/res/layout/gpx_item_altitude.xml | 8 ++++++++ OsmAnd/res/layout/gpx_item_general.xml | 13 ++++++++++--- OsmAnd/res/layout/gpx_item_speed.xml | 9 +++++++++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/OsmAnd/res/layout/gpx_item_altitude.xml b/OsmAnd/res/layout/gpx_item_altitude.xml index 6563cb8c31..2deccbca65 100644 --- a/OsmAnd/res/layout/gpx_item_altitude.xml +++ b/OsmAnd/res/layout/gpx_item_altitude.xml @@ -158,6 +158,12 @@ + + + + - + + + + + android:paddingTop="@dimen/context_menu_first_line_top_margin" + android:paddingBottom="@dimen/content_padding_small"> + + + + + Date: Thu, 21 Jan 2021 05:10:08 +0200 Subject: [PATCH 004/158] amend track menu layout; add init for action segments; Taping on any stat block should open "Analyze on map"; --- OsmAnd/res/layout/gpx_overview_fragment.xml | 5 +- OsmAnd/res/layout/item_gpx_action.xml | 4 +- OsmAnd/res/layout/track_menu.xml | 11 +- OsmAnd/res/values/colors.xml | 1 + .../net/osmand/plus/track/OverviewCard.java | 124 +++++++++++++----- 5 files changed, 102 insertions(+), 43 deletions(-) diff --git a/OsmAnd/res/layout/gpx_overview_fragment.xml b/OsmAnd/res/layout/gpx_overview_fragment.xml index e02826fcbf..d088caa167 100644 --- a/OsmAnd/res/layout/gpx_overview_fragment.xml +++ b/OsmAnd/res/layout/gpx_overview_fragment.xml @@ -1,16 +1,15 @@ - diff --git a/OsmAnd/res/layout/track_menu.xml b/OsmAnd/res/layout/track_menu.xml index 9d33f73e88..9f70c126b8 100644 --- a/OsmAnd/res/layout/track_menu.xml +++ b/OsmAnd/res/layout/track_menu.xml @@ -43,12 +43,13 @@ android:paddingStart="@dimen/context_menu_padding_margin_default" android:paddingLeft="@dimen/context_menu_padding_margin_default" android:paddingEnd="@dimen/context_menu_padding_margin_default" - android:paddingRight="@dimen/context_menu_padding_margin_default"> + android:paddingRight="@dimen/context_menu_padding_margin_default" + android:paddingBottom="@dimen/context_menu_direction_margin"> + android:visibility="gone" + tools:text="@string/amenity_type_finance" /> @@ -79,7 +81,7 @@ android:id="@+id/icon_view" android:layout_width="@dimen/map_widget_icon" android:layout_height="@dimen/map_widget_icon" - android:layout_marginTop="@dimen/context_menu_padding_margin_default" + android:layout_marginTop="@dimen/context_menu_second_line_top_margin" android:tint="?attr/default_icon_color" osmand:srcCompat="@drawable/ic_action_polygom_dark" /> @@ -94,7 +96,6 @@ android:layout_width="match_parent" android:layout_height="match_parent" android:background="?attr/activity_background_basic" - android:foreground="@drawable/bg_contextmenu_shadow" android:foregroundGravity="top|fill_horizontal"> #197d2a #b3b3b3 + #87CC70 #fafafa #101821 diff --git a/OsmAnd/src/net/osmand/plus/track/OverviewCard.java b/OsmAnd/src/net/osmand/plus/track/OverviewCard.java index 51be5dd49b..bb1f9c4a08 100644 --- a/OsmAnd/src/net/osmand/plus/track/OverviewCard.java +++ b/OsmAnd/src/net/osmand/plus/track/OverviewCard.java @@ -21,18 +21,28 @@ import androidx.recyclerview.widget.DefaultItemAnimator; import androidx.recyclerview.widget.LinearLayoutManager; import androidx.recyclerview.widget.RecyclerView; +import com.github.mikephil.charting.charts.LineChart; +import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; + import net.osmand.GPXUtilities.GPXFile; +import net.osmand.GPXUtilities.GPXTrackAnalysis; +import net.osmand.plus.GPXDatabase.GpxDataItem; +import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem; import net.osmand.plus.GpxSelectionHelper.GpxDisplayItemType; +import net.osmand.plus.OsmAndFormatter; import net.osmand.plus.R; import net.osmand.plus.UiUtilities.UpdateLocationViewCache; import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.helpers.GpxUiHelper; +import net.osmand.plus.helpers.GpxUiHelper.LineGraphType; import net.osmand.plus.mapcontextmenu.MapContextMenu; import net.osmand.plus.myplaces.SegmentActionsListener; import net.osmand.plus.myplaces.SegmentGPXAdapter; import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.widgets.TextViewEx; +import net.osmand.util.Algorithms; -import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import static net.osmand.plus.myplaces.TrackActivityFragmentAdapter.isGpxFileSelected; @@ -54,7 +64,7 @@ public class OverviewCard extends BaseCard { private TrackDisplayHelper displayHelper; private GPXFile gpxFile; - private GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[] {GpxDisplayItemType.TRACK_SEGMENT}; + private GpxDisplayItemType[] filterTypes = new GpxDisplayItemType[]{GpxDisplayItemType.TRACK_SEGMENT}; private SegmentGPXAdapter adapter; private SegmentActionsListener listener; @@ -78,13 +88,19 @@ public class OverviewCard extends BaseCard { int iconColorDef = R.color.icon_color_active_light; int iconColorPres = R.color.active_buttons_and_links_text_dark; + boolean fileAvailable = gpxFile.path != null && !gpxFile.showCurrentTrack; showButton = view.findViewById(R.id.show_button); appearanceButton = view.findViewById(R.id.appearance_button); editButton = view.findViewById(R.id.edit_button); directionsButton = view.findViewById(R.id.directions_button); + rvOverview = view.findViewById(R.id.recycler_overview); - boolean fileAvailable = gpxFile.path != null && !gpxFile.showCurrentTrack; + menu = mapActivity.getContextMenu(); + distanceText = (TextView) view.findViewById(R.id.distance); + direction = (ImageView) view.findViewById(R.id.direction); + UpdateLocationViewCache updateLocationViewCache = app.getUIUtilities().getUpdateLocationViewCache(); + app.getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, menu.getLatLon()); initShowButton(iconColorDef, iconColorPres); initAppearanceButton(iconColorDef, iconColorPres); @@ -93,35 +109,37 @@ public class OverviewCard extends BaseCard { initDirectionsButton(iconColorDef, iconColorPres); } - menu = mapActivity.getContextMenu(); - distanceText = (TextView) view.findViewById(R.id.distance); - direction = (ImageView) view.findViewById(R.id.direction); - UpdateLocationViewCache updateLocationViewCache = app.getUIUtilities().getUpdateLocationViewCache(); - app.getUIUtilities().updateLocationView(updateLocationViewCache, direction, distanceText, menu.getLatLon()); + initSegments(); + } - SegmentItem item1 = new SegmentItem("Distance", "700 km", R.drawable.ic_action_track_16); - SegmentItem item2 = new SegmentItem("Ascent", "156 km", R.drawable.ic_action_arrow_up_16); - SegmentItem item3 = new SegmentItem("Descent", "338 km", R.drawable.ic_action_arrow_down_16); - SegmentItem item4 = new SegmentItem("Average speed", "9.9 km/h", R.drawable.ic_action_speed_16); - SegmentItem item5 = new SegmentItem("Max. speed", "12.7 km/h", R.drawable.ic_action_max_speed_16); - SegmentItem item6 = new SegmentItem("Time span", "4:00:18", R.drawable.ic_action_time_span_16); - List items = new ArrayList<>(); - items.add(item1); - items.add(item2); - items.add(item3); - items.add(item4); - items.add(item5); - items.add(item6); + void initSegments() { + GpxDisplayItem gpxItem = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes)).get(0); + GPXTrackAnalysis analysis = gpxItem.analysis; + boolean joinSegments = displayHelper.isJoinSegments(); + float totalDistance = !joinSegments && gpxItem.isGeneralTrack() ? analysis.totalDistanceWithoutGaps : analysis.totalDistance; + float timeSpan = !joinSegments && gpxItem.isGeneralTrack() ? analysis.timeSpanWithoutGaps : analysis.timeSpan; + String asc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationUp, app); + String desc = OsmAndFormatter.getFormattedAlt(analysis.diffElevationDown, app); + String avg = OsmAndFormatter.getFormattedSpeed(analysis.avgSpeed, app); + String max = OsmAndFormatter.getFormattedSpeed(analysis.maxSpeed, app); + + SegmentItem sDistance = new SegmentItem(app.getResources().getString(R.string.distance), OsmAndFormatter.getFormattedDistance(totalDistance, app), + R.drawable.ic_action_track_16, R.color.icon_color_default_light, LineGraphType.ALTITUDE, LineGraphType.SPEED); + SegmentItem sAscent = new SegmentItem(app.getResources().getString(R.string.altitude_ascent), asc, R.drawable.ic_action_arrow_up_16, R.color.gpx_chart_red, LineGraphType.SLOPE, null); + SegmentItem sDescent = new SegmentItem(app.getResources().getString(R.string.altitude_descent), desc, R.drawable.ic_action_arrow_down_16, R.color.gpx_pale_green, LineGraphType.ALTITUDE, LineGraphType.SLOPE); + SegmentItem sAvSpeed = new SegmentItem(app.getResources().getString(R.string.average_speed), avg, R.drawable.ic_action_speed_16, R.color.icon_color_default_light, LineGraphType.SPEED, null); + SegmentItem sMaxSpeed = new SegmentItem(app.getResources().getString(R.string.max_speed), max, R.drawable.ic_action_max_speed_16, R.color.icon_color_default_light, LineGraphType.SPEED, null); + SegmentItem sTimeSpan = new SegmentItem(app.getResources().getString(R.string.shared_string_time_span), Algorithms.formatDuration((int) (timeSpan / 1000), app.accessibilityEnabled()), + R.drawable.ic_action_time_span_16, R.color.icon_color_default_light, LineGraphType.SPEED, null); - rvOverview = view.findViewById(R.id.recycler_overview); LinearLayoutManager llManager = new LinearLayoutManager(app); llManager.setOrientation(LinearLayoutManager.HORIZONTAL); rvOverview.setLayoutManager(llManager); rvOverview.setItemAnimator(new DefaultItemAnimator()); - final SegmentItemAdapter oiAdapter = new SegmentItemAdapter(items); - rvOverview.setAdapter(oiAdapter); + List items = Arrays.asList(sDistance, sAscent, sDescent, sAvSpeed, sMaxSpeed, sTimeSpan); + final SegmentItemAdapter siAdapter = new SegmentItemAdapter(items); + rvOverview.setAdapter(siAdapter); rvOverview.addItemDecoration(new HorizontalDividerDecoration(app)); - } private void initShowButton(final int iconColorDef, final int iconColorPres) { @@ -138,12 +156,9 @@ public class OverviewCard extends BaseCard { @Override public void onClick(View v) { gpxFileSelected[0] = !gpxFileSelected[0]; - + filled.setAlpha(gpxFileSelected[0] ? 1f : 0.1f); setImageDrawable(image, gpxFileSelected[0] ? iconShowResId : iconHideResId, gpxFileSelected[0] ? iconColorPres : iconColorDef); - - filled.setAlpha(gpxFileSelected[0] ? 1f : 0.1f); - CardListener listener = getListener(); if (listener != null) { listener.onCardButtonPressed(OverviewCard.this, SHOW_ON_MAP_BUTTON_INDEX); @@ -236,7 +251,6 @@ public class OverviewCard extends BaseCard { holder.bind(item); } - class SegmentItemViewHolder extends RecyclerView.ViewHolder { private final TextViewEx valueText; private final TextView titleText; @@ -249,10 +263,23 @@ public class OverviewCard extends BaseCard { imageView = view.findViewById(R.id.image); } - public void bind(SegmentItem overviewItem) { + public void bind(final SegmentItem overviewItem) { valueText.setText(overviewItem.value); + valueText.setTextColor(app.getResources().getColor(R.color.active_color_primary_light)); titleText.setText(overviewItem.title); - setImageDrawable(imageView, overviewItem.imageResId, R.color.text_color_primary_light); //todo change color + titleText.setTextColor(app.getResources().getColor(R.color.text_color_secondary_light)); + setImageDrawable(imageView, overviewItem.imageResId, overviewItem.imageColorId); + itemView.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + GpxDisplayItem gpxItem = TrackDisplayHelper.flatten(displayHelper.getOriginalGroups(filterTypes)).get(0); + GPXTrackAnalysis analysis = gpxItem.analysis; + GpxDataItem gpxDataItem = displayHelper.getGpxDataItem(); + boolean calcWithoutGaps = gpxItem.isGeneralTrack() && gpxDataItem != null && !gpxDataItem.isJoinSegments(); + List dataSets = GpxUiHelper.getDataSets(new LineChart(app), app, analysis, overviewItem.firstType, overviewItem.secondType, calcWithoutGaps); + listener.openAnalyzeOnMap(gpxItem, dataSets, null); + } + }); } } } @@ -300,11 +327,17 @@ public class OverviewCard extends BaseCard { private String title; private String value; private int imageResId; + private int imageColorId; + private LineGraphType firstType; + private LineGraphType secondType; - public SegmentItem(String title, String value, int imageResId) { + public SegmentItem(String title, String value, @DrawableRes int imageResId, @ColorRes int imageColorId, LineGraphType firstType, LineGraphType secondType) { this.title = title; this.value = value; this.imageResId = imageResId; + this.imageColorId = imageColorId; + this.firstType = firstType; + this.secondType = secondType; } public String getTitle() { @@ -330,5 +363,30 @@ public class OverviewCard extends BaseCard { public void setImageResId(int imageResId) { this.imageResId = imageResId; } + + public int getImageColorId() { + return imageColorId; + } + + public void setImageColorId(int imageColorId) { + this.imageColorId = imageColorId; + } + + public LineGraphType getFirstType() { + return firstType; + } + + public void setFirstType(LineGraphType firstType) { + this.firstType = firstType; + } + + public LineGraphType getSecondType() { + return secondType; + } + + public void getSecondType(LineGraphType secondType) { + this.secondType = secondType; + } + } } \ No newline at end of file From 6755a76aad8a80867b968d132824a54bc07fd1a9 Mon Sep 17 00:00:00 2001 From: Skalii Date: Thu, 21 Jan 2021 14:28:17 +0200 Subject: [PATCH 005/158] return bg_contextmenu_shadow in header; move OverviewCard build in header; minor fixes; --- OsmAnd/res/layout/gpx_overview_fragment.xml | 3 +- ...on_segment.xml => item_gpx_stat_block.xml} | 2 - OsmAnd/res/layout/track_menu.xml | 1 + .../net/osmand/plus/track/OverviewCard.java | 133 ++++++------------ .../osmand/plus/track/TrackMenuFragment.java | 38 +++-- 5 files changed, 69 insertions(+), 108 deletions(-) rename OsmAnd/res/layout/{item_gpx_action_segment.xml => item_gpx_stat_block.xml} (94%) diff --git a/OsmAnd/res/layout/gpx_overview_fragment.xml b/OsmAnd/res/layout/gpx_overview_fragment.xml index d088caa167..cdea20a2be 100644 --- a/OsmAnd/res/layout/gpx_overview_fragment.xml +++ b/OsmAnd/res/layout/gpx_overview_fragment.xml @@ -15,7 +15,7 @@ android:orientation="horizontal" tools:itemCount="4" tools:layoutManager="androidx.recyclerview.widget.LinearLayoutManager" - tools:listitem="@layout/item_gpx_action_segment" /> + tools:listitem="@layout/item_gpx_stat_block" /> diff --git a/OsmAnd/res/layout/item_gpx_action_segment.xml b/OsmAnd/res/layout/item_gpx_stat_block.xml similarity index 94% rename from OsmAnd/res/layout/item_gpx_action_segment.xml rename to OsmAnd/res/layout/item_gpx_stat_block.xml index 962941b95c..b7eedc1a9a 100644 --- a/OsmAnd/res/layout/item_gpx_action_segment.xml +++ b/OsmAnd/res/layout/item_gpx_stat_block.xml @@ -5,8 +5,6 @@ android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> - items = Arrays.asList(sDistance, sAscent, sDescent, sAvSpeed, sMaxSpeed, sTimeSpan); - final SegmentItemAdapter siAdapter = new SegmentItemAdapter(items); + List items = Arrays.asList(sDistance, sAscent, sDescent, sAvSpeed, sMaxSpeed, sTimeSpan); + final StatBlockAdapter siAdapter = new StatBlockAdapter(items); rvOverview.setAdapter(siAdapter); rvOverview.addItemDecoration(new HorizontalDividerDecoration(app)); } @@ -225,45 +222,45 @@ public class OverviewCard extends BaseCard { }); } - private class SegmentItemAdapter extends RecyclerView.Adapter { - private final List segmentItems; + private class StatBlockAdapter extends RecyclerView.Adapter { + private final List StatBlocks; - public SegmentItemAdapter(List segmentItems) { - this.segmentItems = segmentItems; + public StatBlockAdapter(List StatBlocks) { + this.StatBlocks = StatBlocks; } @Override public int getItemCount() { - return segmentItems.size(); + return StatBlocks.size(); } @NonNull @Override - public SegmentItemViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + public StatBlockViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { View itemView = LayoutInflater.from(parent.getContext()) - .inflate(R.layout.item_gpx_action_segment, parent, false); - return new SegmentItemViewHolder(itemView); + .inflate(R.layout.item_gpx_stat_block, parent, false); + return new StatBlockViewHolder(itemView); } @Override - public void onBindViewHolder(SegmentItemViewHolder holder, int position) { - SegmentItem item = segmentItems.get(position); + public void onBindViewHolder(StatBlockViewHolder holder, int position) { + StatBlock item = StatBlocks.get(position); holder.bind(item); } - class SegmentItemViewHolder extends RecyclerView.ViewHolder { + class StatBlockViewHolder extends RecyclerView.ViewHolder { private final TextViewEx valueText; private final TextView titleText; private final AppCompatImageView imageView; - SegmentItemViewHolder(View view) { + StatBlockViewHolder(View view) { super(view); valueText = view.findViewById(R.id.value); titleText = view.findViewById(R.id.title); imageView = view.findViewById(R.id.image); } - public void bind(final SegmentItem overviewItem) { + public void bind(final StatBlock overviewItem) { valueText.setText(overviewItem.value); valueText.setTextColor(app.getResources().getColor(R.color.active_color_primary_light)); titleText.setText(overviewItem.title); @@ -289,10 +286,10 @@ public class OverviewCard extends BaseCard { public HorizontalDividerDecoration(Context context) { int[] ATTRS = new int[]{android.R.attr.listDivider}; - final TypedArray a = context.obtainStyledAttributes(ATTRS); - divider = a.getDrawable(0); - a.recycle(); -// mDivider = getMyApplication().getUIUtilities().getIcon(R.drawable.divider_solid, R.color.divider_color_light); //todo change drawable + final TypedArray ta = context.obtainStyledAttributes(ATTRS); + divider = ta.getDrawable(0); +// DrawableCompat.setTint(divider, context.getResources().getColor(R.color.divider_color_light)); //todo change drawable color + ta.recycle(); } @Override @@ -323,7 +320,7 @@ public class OverviewCard extends BaseCard { } } - private class SegmentItem { + private static class StatBlock { private String title; private String value; private int imageResId; @@ -331,7 +328,7 @@ public class OverviewCard extends BaseCard { private LineGraphType firstType; private LineGraphType secondType; - public SegmentItem(String title, String value, @DrawableRes int imageResId, @ColorRes int imageColorId, LineGraphType firstType, LineGraphType secondType) { + public StatBlock(String title, String value, @DrawableRes int imageResId, @ColorRes int imageColorId, LineGraphType firstType, LineGraphType secondType) { this.title = title; this.value = value; this.imageResId = imageResId; @@ -340,53 +337,5 @@ public class OverviewCard extends BaseCard { this.secondType = secondType; } - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } - - public int getImageResId() { - return imageResId; - } - - public void setImageResId(int imageResId) { - this.imageResId = imageResId; - } - - public int getImageColorId() { - return imageColorId; - } - - public void setImageColorId(int imageColorId) { - this.imageColorId = imageColorId; - } - - public LineGraphType getFirstType() { - return firstType; - } - - public void setFirstType(LineGraphType firstType) { - this.firstType = firstType; - } - - public LineGraphType getSecondType() { - return secondType; - } - - public void getSecondType(LineGraphType secondType) { - this.secondType = secondType; - } - } } \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index f102331bfc..6b93a6d166 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -221,6 +221,10 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } private void updateHeader() { + ViewGroup headerContainer = (ViewGroup) routeMenuTopShadowAll; + if (overviewCard != null && overviewCard.getView() != null) { + headerContainer.removeView(overviewCard.getView()); + } if (menuType == TrackMenuType.OPTIONS) { headerTitle.setText(menuType.titleId); AndroidUiHelper.updateVisibility(headerIcon, false); @@ -228,7 +232,27 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card String fileName = Algorithms.getFileWithoutDirs(getGpx().path); headerTitle.setText(GpxUiHelper.getGpxTitle(fileName)); AndroidUiHelper.updateVisibility(headerIcon, true); + if (menuType == TrackMenuType.OVERVIEW) { + if (overviewCard != null && overviewCard.getView() != null) { + ViewGroup parent = ((ViewGroup) overviewCard.getView().getParent()); + if (parent != null) { + parent.removeView(overviewCard.getView()); + } + headerContainer.addView(overviewCard.getView()); + } else { + overviewCard = new OverviewCard(getMapActivity(), displayHelper, this); + overviewCard.setListener(this); + headerContainer.addView(overviewCard.build(getMapActivity())); + } + } } + runLayoutListener(); + headerContainer.post(new Runnable() { + @Override + public void run() { + openMenuScreen(menuType == TrackMenuType.OVERVIEW ? MenuState.HEADER_ONLY : MenuState.HALF_SCREEN, false); + } + }); } private void setupCards() { @@ -236,19 +260,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card if (mapActivity != null) { ViewGroup cardsContainer = getCardsContainer(); cardsContainer.removeAllViews(); - if (menuType == TrackMenuType.OVERVIEW) { - if (overviewCard != null && overviewCard.getView() != null) { - ViewGroup parent = (ViewGroup) overviewCard.getView().getParent(); - if (parent != null) { - parent.removeAllViews(); - } - cardsContainer.addView(overviewCard.getView()); - } else { - overviewCard = new OverviewCard(mapActivity, displayHelper, this); - overviewCard.setListener(this); - cardsContainer.addView(overviewCard.build(mapActivity)); - } - } else if (menuType == TrackMenuType.TRACK) { + if (menuType == TrackMenuType.TRACK) { if (segmentsCard != null && segmentsCard.getView() != null) { ViewGroup parent = (ViewGroup) segmentsCard.getView().getParent(); if (parent != null) { From 431c7b30e7382554138193c02223a915e2f1d48c Mon Sep 17 00:00:00 2001 From: Skalii Date: Thu, 21 Jan 2021 15:17:06 +0200 Subject: [PATCH 006/158] fix margins in item_gpx_stat_block.xml --- OsmAnd/res/layout/item_gpx_stat_block.xml | 36 +++++++++++------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/OsmAnd/res/layout/item_gpx_stat_block.xml b/OsmAnd/res/layout/item_gpx_stat_block.xml index b7eedc1a9a..5bd38821ca 100644 --- a/OsmAnd/res/layout/item_gpx_stat_block.xml +++ b/OsmAnd/res/layout/item_gpx_stat_block.xml @@ -4,12 +4,12 @@ xmlns:tools="http://schemas.android.com/tools" android:layout_width="wrap_content" android:layout_height="wrap_content" - android:orientation="horizontal"> + android:orientation="vertical"> + android:orientation="horizontal"> - + - + \ No newline at end of file From e748bbd03ea1afd52f2fb2556f8c6c24b0ad785e Mon Sep 17 00:00:00 2001 From: Skalii Date: Fri, 22 Jan 2021 00:27:32 +0200 Subject: [PATCH 007/158] fix top padding of TextFieldBoxes --- .../plus/onlinerouting/ui/OnlineRoutingCard.java | 10 +++++++--- .../onlinerouting/ui/OnlineRoutingEngineFragment.java | 1 + .../net/osmand/plus/widgets/OsmandTextFieldBoxes.java | 11 +++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingCard.java b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingCard.java index 4403d512f4..66efbaa8ed 100644 --- a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingCard.java +++ b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingCard.java @@ -123,8 +123,8 @@ public class OnlineRoutingCard extends BaseCard { } public void setSelectionMenu(@NonNull List items, - @NonNull String selectedItemTitle, - @NonNull final CallbackWithObject callback) { + @NonNull String selectedItemTitle, + @NonNull final CallbackWithObject callback) { showElements(rvSelectionMenu); rvSelectionMenu.setLayoutManager( new LinearLayoutManager(app, RecyclerView.HORIZONTAL, false)); @@ -166,6 +166,10 @@ public class OnlineRoutingCard extends BaseCard { textFieldBoxes.setLabelText(labelText); } + public void hideFieldBoxLabel() { + textFieldBoxes.makeCompactPadding(); + } + public void setFieldBoxHelperText(@NonNull String helperText) { showElements(fieldBoxContainer, tvHelperText); fieldBoxHelperTextShowed = true; @@ -202,7 +206,7 @@ public class OnlineRoutingCard extends BaseCard { } public void setButton(@NonNull String title, - @NonNull OnClickListener listener) { + @NonNull OnClickListener listener) { showElements(button); button.setOnClickListener(listener); UiUtilities.setupDialogButton(nightMode, button, DialogButtonType.PRIMARY, title); diff --git a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java index adfbfb1bc0..231ee50dc4 100644 --- a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java +++ b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java @@ -359,6 +359,7 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { exampleCard = new OnlineRoutingCard(mapActivity, isNightMode(), appMode); exampleCard.build(mapActivity); exampleCard.setHeaderTitle(getString(R.string.shared_string_example)); + exampleCard.hideFieldBoxLabel(); List locationItems = new ArrayList<>(); for (ExampleLocation location : ExampleLocation.values()) { locationItems.add(new HorizontalSelectionItem(location.getName(), location)); diff --git a/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java b/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java index 9f6aed3c9e..06bc7e385d 100644 --- a/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java +++ b/OsmAnd/src/net/osmand/plus/widgets/OsmandTextFieldBoxes.java @@ -2,6 +2,9 @@ package net.osmand.plus.widgets; import android.content.Context; import android.util.AttributeSet; +import android.view.View; + +import net.osmand.plus.R; import studio.carbonylgroup.textfieldboxes.TextFieldBoxes; @@ -19,4 +22,12 @@ public class OsmandTextFieldBoxes extends TextFieldBoxes { super(context, attrs, defStyleAttr); } + public void makeCompactPadding() { + floatingLabel.setVisibility(View.GONE); + labelSpace.setVisibility(View.GONE); + labelSpaceBelow.setVisibility(View.GONE); + int paddingH = getResources().getDimensionPixelSize(R.dimen.route_info_card_details_margin); + inputLayout.setPadding(0, paddingH, 0, paddingH); + } + } From f3bee7262ece2e4acdd5ab6274bd17e198b33bce Mon Sep 17 00:00:00 2001 From: Skalii Date: Fri, 22 Jan 2021 04:16:32 +0200 Subject: [PATCH 008/158] fix exit confirmation dialog if name has index --- .../ui/OnlineRoutingEngineFragment.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java index 231ee50dc4..0041c93853 100644 --- a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java +++ b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java @@ -512,8 +512,8 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { } private void showTestResults(final boolean resultOk, - final @NonNull String message, - final @NonNull ExampleLocation location) { + final @NonNull String message, + final @NonNull ExampleLocation location) { app.runInUIThread(new Runnable() { @Override public void run() { @@ -568,6 +568,10 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { public void showExitDialog() { View focus = view.findFocus(); AndroidUtils.hideSoftKeyboard(mapActivity, focus); + if (hasNameDuplicate(initEngine)) { + List cachedEngines = helper.getEnginesExceptMentionedKeys(editedEngineKey); + OnlineRoutingUtils.generateUniqueName(app, initEngine, cachedEngines); + } if (!engine.equals(initEngine)) { AlertDialog.Builder dismissDialog = createWarningDialog(mapActivity, R.string.shared_string_dismiss, R.string.exit_without_saving, R.string.shared_string_cancel); @@ -700,8 +704,8 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { } public static void showInstance(@NonNull FragmentActivity activity, - @NonNull ApplicationMode appMode, - @Nullable String editedEngineKey) { + @NonNull ApplicationMode appMode, + @Nullable String editedEngineKey) { FragmentManager fm = activity.getSupportFragmentManager(); if (!fm.isStateSaved() && fm.findFragmentByTag(OnlineRoutingEngineFragment.TAG) == null) { OnlineRoutingEngineFragment fragment = new OnlineRoutingEngineFragment(); From e85cc6544198f4368b0e39cc6d98e47a1e2405db Mon Sep 17 00:00:00 2001 From: Skalii Date: Fri, 22 Jan 2021 16:52:33 +0200 Subject: [PATCH 009/158] Shadow should be shown below the "Save/Cancel" buttons (when content is below buttons); Add confirmation dialog before deleting online routing; fix descrease padding below scroll buttons for all blocks; fix padding of results container; minor fixes; --- .../layout/online_routing_engine_fragment.xml | 39 ++- .../online_routing_preference_segment.xml | 32 --- .../onlinerouting/ui/OnlineRoutingCard.java | 28 +-- .../ui/OnlineRoutingEngineFragment.java | 229 ++++++++++++------ 4 files changed, 201 insertions(+), 127 deletions(-) diff --git a/OsmAnd/res/layout/online_routing_engine_fragment.xml b/OsmAnd/res/layout/online_routing_engine_fragment.xml index 69cc042252..98b3317f66 100644 --- a/OsmAnd/res/layout/online_routing_engine_fragment.xml +++ b/OsmAnd/res/layout/online_routing_engine_fragment.xml @@ -1,9 +1,8 @@ - + android:background="?attr/list_background_color"> + android:layout_height="match_parent" + android:layout_marginBottom="@dimen/dialog_button_ex_height"> + android:orientation="vertical" + android:paddingTop="@dimen/dialog_button_ex_height" + android:paddingBottom="@dimen/context_menu_buttons_bottom_height" /> - + android:layout_height="wrap_content" + android:layout_gravity="bottom" + android:orientation="vertical"> - \ No newline at end of file + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/online_routing_preference_segment.xml b/OsmAnd/res/layout/online_routing_preference_segment.xml index 437ba875e5..3e5373aa6a 100644 --- a/OsmAnd/res/layout/online_routing_preference_segment.xml +++ b/OsmAnd/res/layout/online_routing_preference_segment.xml @@ -164,36 +164,4 @@ tools:visibility="visible" android:visibility="gone" /> - - - - - - - - \ No newline at end of file diff --git a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingCard.java b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingCard.java index 66efbaa8ed..b18ee19fdb 100644 --- a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingCard.java +++ b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingCard.java @@ -25,8 +25,6 @@ import net.osmand.plus.helpers.AndroidUiHelper; import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter; import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionAdapterListener; import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter.HorizontalSelectionItem; -import net.osmand.plus.onlinerouting.VehicleType; -import net.osmand.plus.onlinerouting.engine.OnlineRoutingEngine; import net.osmand.plus.routepreparationmenu.cards.BaseCard; import net.osmand.plus.settings.backend.ApplicationMode; import net.osmand.plus.widgets.OsmandTextFieldBoxes; @@ -137,23 +135,15 @@ public class OnlineRoutingCard extends BaseCard { if (callback.processResult(item)) { adapter.setSelectedItem(item); } - Object obj = item.getObject(); - updateBottomMarginSelectionMenu(obj); } }); - Object item = adapter.getItemByTitle(selectedItemTitle).getObject(); - updateBottomMarginSelectionMenu(item); rvSelectionMenu.setAdapter(adapter); } - private void updateBottomMarginSelectionMenu(Object item) { - if (item instanceof VehicleType) { - VehicleType vt = (VehicleType) item; - boolean hasPadding = vt.equals(OnlineRoutingEngine.CUSTOM_VEHICLE); - ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) rvSelectionMenu.getLayoutParams(); - int contentPadding = app.getResources().getDimensionPixelSize(R.dimen.content_padding); - params.bottomMargin = hasPadding ? contentPadding : 0; - } + private void updateBottomMarginSelectionMenu() { + ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) rvSelectionMenu.getLayoutParams(); + int contentPadding = app.getResources().getDimensionPixelSize(R.dimen.content_padding); + params.bottomMargin = isVisibleViewsBelowSelectionMenu() ? contentPadding : 0; } public void setDescription(@NonNull String description) { @@ -230,10 +220,20 @@ public class OnlineRoutingCard extends BaseCard { private void showElements(View... views) { AndroidUiHelper.setVisibility(View.VISIBLE, views); + updateBottomMarginSelectionMenu(); } private void hideElements(View... views) { AndroidUiHelper.setVisibility(View.GONE, views); + updateBottomMarginSelectionMenu(); + } + + private boolean isVisibleViewsBelowSelectionMenu() { + return isVisible(tvDescription) || isVisible(fieldBoxContainer) || isVisible(button); + } + + public boolean isVisible(View view) { + return view.getVisibility() == View.VISIBLE; } public void setOnTextChangedListener(@Nullable OnTextChangedListener onTextChangedListener) { diff --git a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java index 0041c93853..ee8b2ee827 100644 --- a/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java +++ b/OsmAnd/src/net/osmand/plus/onlinerouting/ui/OnlineRoutingEngineFragment.java @@ -14,6 +14,7 @@ import android.view.View.OnClickListener; import android.view.ViewGroup; import android.view.ViewTreeObserver; import android.view.ViewTreeObserver.OnGlobalLayoutListener; +import android.view.ViewTreeObserver.OnScrollChangedListener; import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.ScrollView; @@ -23,6 +24,7 @@ import androidx.activity.OnBackPressedCallback; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; +import androidx.appcompat.widget.AppCompatImageView; import androidx.appcompat.widget.Toolbar; import androidx.fragment.app.FragmentActivity; import androidx.fragment.app.FragmentManager; @@ -82,7 +84,9 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { private View testResultsContainer; private View saveButton; private ScrollView scrollView; + private AppCompatImageView buttonsShadow; private OnGlobalLayoutListener onGlobalLayout; + private OnScrollChangedListener onScroll; private boolean isKeyboardShown = false; private OnlineRoutingEngine engine; @@ -112,7 +116,6 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { }); } - @SuppressLint("ClickableViewAccessibility") @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @@ -121,7 +124,8 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { view = getInflater().inflate( R.layout.online_routing_engine_fragment, container, false); segmentsContainer = (ViewGroup) view.findViewById(R.id.segments_container); - scrollView = (ScrollView) segmentsContainer.getParent(); + scrollView = (ScrollView) view.findViewById(R.id.segments_scroll); + buttonsShadow = (AppCompatImageView) view.findViewById(R.id.buttons_shadow); if (Build.VERSION.SDK_INT >= 21) { AndroidUtils.addStatusBarPadding21v(getContext(), view); } @@ -138,67 +142,9 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { generateUniqueNameIfNeeded(); updateCardViews(nameCard, typeCard, vehicleCard, exampleCard); - scrollView.setOnTouchListener(new View.OnTouchListener() { - int scrollViewY = 0; - - @Override - public boolean onTouch(View v, MotionEvent event) { - int y = scrollView.getScrollY(); - if (isKeyboardShown && scrollViewY != y) { - scrollViewY = y; - View focus = mapActivity.getCurrentFocus(); - if (focus != null) { - AndroidUtils.hideSoftKeyboard(mapActivity, focus); - focus.clearFocus(); - } - } - return false; - } - }); - - onGlobalLayout = new ViewTreeObserver.OnGlobalLayoutListener() { - private int layoutHeightPrevious; - private int layoutHeightMin; - - @Override - public void onGlobalLayout() { - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - view.getViewTreeObserver().removeOnGlobalLayoutListener(this); - } else { - view.getViewTreeObserver().removeGlobalOnLayoutListener(this); - } - - Rect visibleDisplayFrame = new Rect(); - view.getWindowVisibleDisplayFrame(visibleDisplayFrame); - int layoutHeight = visibleDisplayFrame.bottom; - - if (layoutHeight < layoutHeightPrevious) { - isKeyboardShown = true; - layoutHeightMin = layoutHeight; - } else { - isKeyboardShown = layoutHeight == layoutHeightMin; - } - - if (layoutHeight != layoutHeightPrevious) { - FrameLayout.LayoutParams rootViewLayout = (FrameLayout.LayoutParams) view.getLayoutParams(); - rootViewLayout.height = layoutHeight; - view.requestLayout(); - layoutHeightPrevious = layoutHeight; - } - - view.post(new Runnable() { - @Override - public void run() { - view.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayout); - } - }); - - } - }; - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - view.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayout); - } + showShadowBelowButtons(); + showButtonsAboveKeyboard(); + hideKeyboardOnScroll(); return view; } @@ -223,8 +169,7 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { actionBtn.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - onDeleteEngine(); - dismiss(); + delete(mapActivity); } }); } else { @@ -391,7 +336,7 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { private void setupResultsContainer() { testResultsContainer = getInflater().inflate( R.layout.bottom_sheet_item_with_descr_64dp, segmentsContainer, false); - testResultsContainer.setVisibility(View.INVISIBLE); + testResultsContainer.setVisibility(View.GONE); segmentsContainer.addView(testResultsContainer); } @@ -481,6 +426,22 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { helper.deleteEngine(engine); } + private void delete(Activity activity) { + if (engine != null) { + AlertDialog.Builder builder = new AlertDialog.Builder(UiUtilities.getThemedContext(activity, isNightMode())); + builder.setMessage(getString(R.string.delete_online_routing_engine)); + builder.setNegativeButton(R.string.shared_string_no, null); + builder.setPositiveButton(R.string.shared_string_yes, new DialogInterface.OnClickListener() { + @Override + public void onClick(DialogInterface dialog, int which) { + onDeleteEngine(); + dismiss(); + } + }); + builder.create().show(); + } + } + private boolean isEditingMode() { return editedEngineKey != null; } @@ -529,6 +490,12 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { tvTitle.setText(String.format(getString(R.string.message_server_error), message)); } tvDescription.setText(location.getName()); + scrollView.post(new Runnable() { + @Override + public void run() { + scrollView.scrollTo(0, scrollView.getChildAt(0).getBottom()); + } + }); } }); } @@ -632,11 +599,8 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { @Override public void onDestroyView() { super.onDestroyView(); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { - view.getViewTreeObserver().removeOnGlobalLayoutListener(onGlobalLayout); - } else { - view.getViewTreeObserver().removeGlobalOnLayoutListener(onGlobalLayout); - } + removeOnGlobalLayoutListener(); + removeOnScrollListener(); } @Override @@ -716,4 +680,127 @@ public class OnlineRoutingEngineFragment extends BaseOsmAndFragment { .addToBackStack(TAG).commitAllowingStateLoss(); } } + + @SuppressLint("ClickableViewAccessibility") + private void hideKeyboardOnScroll() { + scrollView.setOnTouchListener(new View.OnTouchListener() { + int scrollViewY = 0; + + @Override + public boolean onTouch(View v, MotionEvent event) { + int y = scrollView.getScrollY(); + if (isKeyboardShown && scrollViewY != y) { + scrollViewY = y; + View focus = mapActivity.getCurrentFocus(); + if (focus != null) { + AndroidUtils.hideSoftKeyboard(mapActivity, focus); + focus.clearFocus(); + } + } + return false; + } + }); + } + + private void showShadowBelowButtons() { + if (onScroll != null) { + scrollView.getViewTreeObserver().addOnScrollChangedListener(onScroll); + } else { + initShowShadowOnScrollListener(); + showShadowBelowButtons(); + } + } + + private void showButtonsAboveKeyboard() { + if (onGlobalLayout != null) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + view.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayout); + } + } else { + initShowButtonsOnGlobalListener(); + showButtonsAboveKeyboard(); + } + } + + private void initShowShadowOnScrollListener() { + onScroll = new OnScrollChangedListener() { + @Override + public void onScrollChanged() { + boolean scrollToBottomAvailable = scrollView.canScrollVertically(1); + if (scrollToBottomAvailable) { + showShadowButton(); + } else { + hideShadowButton(); + } + } + }; + } + + private void initShowButtonsOnGlobalListener() { + onGlobalLayout = new ViewTreeObserver.OnGlobalLayoutListener() { + private int layoutHeightPrevious; + private int layoutHeightMin; + + @Override + public void onGlobalLayout() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + view.getViewTreeObserver().removeOnGlobalLayoutListener(this); + } else { + view.getViewTreeObserver().removeGlobalOnLayoutListener(this); + } + + Rect visibleDisplayFrame = new Rect(); + view.getWindowVisibleDisplayFrame(visibleDisplayFrame); + int layoutHeight = visibleDisplayFrame.bottom; + + if (layoutHeight < layoutHeightPrevious) { + isKeyboardShown = true; + layoutHeightMin = layoutHeight; + } else { + isKeyboardShown = layoutHeight == layoutHeightMin; + } + + if (layoutHeight != layoutHeightPrevious) { + FrameLayout.LayoutParams rootViewLayout = (FrameLayout.LayoutParams) view.getLayoutParams(); + rootViewLayout.height = layoutHeight; + view.requestLayout(); + layoutHeightPrevious = layoutHeight; + } + + view.post(new Runnable() { + @Override + public void run() { + view.getViewTreeObserver().addOnGlobalLayoutListener(onGlobalLayout); + } + }); + + } + }; + } + + private void removeOnScrollListener() { + scrollView.getViewTreeObserver().removeOnScrollChangedListener(onScroll); + } + + private void removeOnGlobalLayoutListener() { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { + view.getViewTreeObserver().removeOnGlobalLayoutListener(onGlobalLayout); + } else { + view.getViewTreeObserver().removeGlobalOnLayoutListener(onGlobalLayout); + } + } + + private void showShadowButton() { + buttonsShadow.setVisibility(View.VISIBLE); + buttonsShadow.animate() + .alpha(0.8f) + .setDuration(200) + .setListener(null); + } + + private void hideShadowButton() { + buttonsShadow.animate() + .alpha(0f) + .setDuration(200); + } } From 58c46a3a072dabb32f30373629c8c76a1ba527a5 Mon Sep 17 00:00:00 2001 From: Skalii Date: Fri, 22 Jan 2021 16:53:02 +0200 Subject: [PATCH 010/158] add string for delete online routing engine --- OsmAnd/res/values/strings.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 8605ea2189..cf6efbd62d 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -12,6 +12,7 @@ --> + Delete this online routing engine? The name is already exists Server error: %1$s MTB From bbbfe6600474165868a88b360097829b7a9170a0 Mon Sep 17 00:00:00 2001 From: Skalii Date: Sat, 23 Jan 2021 17:45:42 +0200 Subject: [PATCH 011/158] fix first menu opening in header-only state; minor fixes --- .../osmand/plus/track/TrackMenuFragment.java | 70 ++++++++++--------- 1 file changed, 38 insertions(+), 32 deletions(-) diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 6b93a6d166..46c1829e61 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -117,6 +117,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card private TrackChartPoints trackChartPoints; private int menuTitleHeight; + private String gpxTitle; public enum TrackMenuType { OVERVIEW(R.id.action_overview, R.string.shared_string_overview), @@ -162,6 +163,11 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card return MenuState.HEADER_ONLY | MenuState.HALF_SCREEN | MenuState.FULL_SCREEN; } + @Override + public int getInitialMenuState() { + return MenuState.HEADER_ONLY; + } + public TrackDisplayHelper getDisplayHelper() { return displayHelper; } @@ -186,6 +192,8 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card selectedGpxFile = app.getSelectedGpxHelper().getSelectedFileByPath(gpxFilePath); } displayHelper.setGpx(selectedGpxFile.getGpxFile()); + String fileName = Algorithms.getFileWithoutDirs(getGpx().path); + gpxTitle = GpxUiHelper.getGpxTitle(fileName); } } @@ -203,7 +211,11 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card headerIcon = view.findViewById(R.id.icon_view); if (isPortrait()) { - updateCardsLayout(); + View mainView = getMainView(); + View topShadow = getTopShadow(); + FrameLayout bottomContainer = getBottomContainer(); + topShadow.setVisibility(View.VISIBLE); + AndroidUtils.setBackground(mainView.getContext(), bottomContainer, isNightMode(), R.color.list_background_color_light, R.color.list_background_color_dark); } else { int widthNoShadow = getLandscapeNoShadowWidth(); FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(widthNoShadow, ViewGroup.LayoutParams.WRAP_CONTENT); @@ -220,39 +232,33 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card return view; } + private void setHeaderTitle(String text, boolean iconVisibility) { + headerTitle.setText(text); + AndroidUiHelper.updateVisibility(headerIcon, iconVisibility); + } + private void updateHeader() { ViewGroup headerContainer = (ViewGroup) routeMenuTopShadowAll; - if (overviewCard != null && overviewCard.getView() != null) { - headerContainer.removeView(overviewCard.getView()); - } - if (menuType == TrackMenuType.OPTIONS) { - headerTitle.setText(menuType.titleId); - AndroidUiHelper.updateVisibility(headerIcon, false); - } else { - String fileName = Algorithms.getFileWithoutDirs(getGpx().path); - headerTitle.setText(GpxUiHelper.getGpxTitle(fileName)); - AndroidUiHelper.updateVisibility(headerIcon, true); - if (menuType == TrackMenuType.OVERVIEW) { - if (overviewCard != null && overviewCard.getView() != null) { - ViewGroup parent = ((ViewGroup) overviewCard.getView().getParent()); - if (parent != null) { - parent.removeView(overviewCard.getView()); - } - headerContainer.addView(overviewCard.getView()); - } else { - overviewCard = new OverviewCard(getMapActivity(), displayHelper, this); - overviewCard.setListener(this); - headerContainer.addView(overviewCard.build(getMapActivity())); + if (menuType == TrackMenuType.OVERVIEW) { + setHeaderTitle(gpxTitle, true); + if (overviewCard != null && overviewCard.getView() != null) { + ViewGroup parent = ((ViewGroup) overviewCard.getView().getParent()); + if (parent != null) { + parent.removeView(overviewCard.getView()); } + headerContainer.addView(overviewCard.getView()); + } else { + overviewCard = new OverviewCard(getMapActivity(), displayHelper, this); + overviewCard.setListener(this); + headerContainer.addView(overviewCard.build(getMapActivity())); } + } else { + if (overviewCard != null && overviewCard.getView() != null) { + headerContainer.removeView(overviewCard.getView()); + } + boolean isOptions = menuType == TrackMenuType.OPTIONS; + setHeaderTitle(isOptions ? app.getString(menuType.titleId) : gpxTitle, !isOptions); } - runLayoutListener(); - headerContainer.post(new Runnable() { - @Override - public void run() { - openMenuScreen(menuType == TrackMenuType.OVERVIEW ? MenuState.HEADER_ONLY : MenuState.HALF_SCREEN, false); - } - }); } private void setupCards() { @@ -573,7 +579,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } } - private void updateCardsLayout() { + /*private void updateCardsLayout() { View mainView = getMainView(); if (mainView != null) { View topShadow = getTopShadow(); @@ -586,7 +592,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card AndroidUtils.setBackground(mainView.getContext(), bottomContainer, isNightMode(), R.color.list_background_color_light, R.color.list_background_color_dark); } } - } + }*/ private void setupButtons(View view) { ColorStateList navColorStateList = AndroidUtils.createBottomNavColorStateList(getContext(), isNightMode()); @@ -814,7 +820,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card Bundle args = new Bundle(); args.putString(TRACK_FILE_NAME, path); args.putBoolean(CURRENT_RECORDING, showCurrentTrack); - args.putInt(ContextMenuFragment.MENU_STATE_KEY, MenuState.HALF_SCREEN); + args.putInt(ContextMenuFragment.MENU_STATE_KEY, MenuState.HEADER_ONLY); TrackMenuFragment fragment = new TrackMenuFragment(); fragment.setArguments(args); From 101402a3c412cb437c3b0bdcae8a927d6b5a254e Mon Sep 17 00:00:00 2001 From: cepprice Date: Sat, 23 Jan 2021 21:06:59 +0500 Subject: [PATCH 012/158] Add description card --- .../main/java/net/osmand/GPXUtilities.java | 4 + .../layout/gpx_description_preview_card.xml | 128 ++++++++++++++++++ .../res/menu/track_menu_bottom_navigation.xml | 9 +- OsmAnd/res/values/strings.xml | 2 + OsmAnd/src/net/osmand/FileUtils.java | 4 + .../osmand/plus/track/DescriptionCard.java | 110 +++++++++++++++ .../osmand/plus/track/TrackMenuFragment.java | 60 ++++++-- 7 files changed, 302 insertions(+), 15 deletions(-) create mode 100644 OsmAnd/res/layout/gpx_description_preview_card.xml create mode 100644 OsmAnd/src/net/osmand/plus/track/DescriptionCard.java diff --git a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java index ede3b6f8cf..ed80b55b05 100644 --- a/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java +++ b/OsmAnd-java/src/main/java/net/osmand/GPXUtilities.java @@ -449,6 +449,10 @@ public class GPXUtilities { public String getArticleLang() { return getExtensionsToRead().get("article_lang"); } + + public String getDescription() { + return getExtensionsToRead().get("desc"); + } } public static class Author extends GPXExtensions { diff --git a/OsmAnd/res/layout/gpx_description_preview_card.xml b/OsmAnd/res/layout/gpx_description_preview_card.xml new file mode 100644 index 0000000000..b9c4518b2d --- /dev/null +++ b/OsmAnd/res/layout/gpx_description_preview_card.xml @@ -0,0 +1,128 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/menu/track_menu_bottom_navigation.xml b/OsmAnd/res/menu/track_menu_bottom_navigation.xml index fa07fb12a4..54f7d7e05e 100644 --- a/OsmAnd/res/menu/track_menu_bottom_navigation.xml +++ b/OsmAnd/res/menu/track_menu_bottom_navigation.xml @@ -1,9 +1,10 @@ - - - - + + + Edit description + Read full The name is already exists Server error: %1$s MTB diff --git a/OsmAnd/src/net/osmand/FileUtils.java b/OsmAnd/src/net/osmand/FileUtils.java index 580450df60..7fe28bf418 100644 --- a/OsmAnd/src/net/osmand/FileUtils.java +++ b/OsmAnd/src/net/osmand/FileUtils.java @@ -196,4 +196,8 @@ public class FileUtils { public interface RenameCallback { void renamedTo(File file); } + + public interface GpxEditedCallback { + void onGpxChanged(); + } } diff --git a/OsmAnd/src/net/osmand/plus/track/DescriptionCard.java b/OsmAnd/src/net/osmand/plus/track/DescriptionCard.java new file mode 100644 index 0000000000..2a6d460588 --- /dev/null +++ b/OsmAnd/src/net/osmand/plus/track/DescriptionCard.java @@ -0,0 +1,110 @@ +package net.osmand.plus.track; + +import android.text.TextUtils; +import android.view.View; + +import com.squareup.picasso.Callback; +import com.squareup.picasso.Picasso; +import com.squareup.picasso.RequestCreator; + +import net.osmand.GPXUtilities; +import net.osmand.GPXUtilities.GPXFile; +import net.osmand.PicassoUtils; +import net.osmand.plus.R; +import net.osmand.plus.activities.MapActivity; +import net.osmand.plus.helpers.AndroidUiHelper; +import net.osmand.plus.routepreparationmenu.cards.BaseCard; +import net.osmand.plus.widgets.TextViewEx; +import net.osmand.plus.wikipedia.WikiArticleHelper; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.appcompat.widget.AppCompatImageView; + +public class DescriptionCard extends BaseCard { + + private final GPXFile gpxFile; + + public DescriptionCard(MapActivity mapActivity, GPXFile gpxFile) { + super(mapActivity); + this.gpxFile = gpxFile; + } + + @Override + public int getCardLayoutId() { + return R.layout.gpx_description_preview_card; + } + + @Override + protected void updateContent() { + final String title = gpxFile.metadata.getArticleTitle(); + final String imageUrl = getMetadataImageLink(gpxFile.metadata); + final String descriptionHtml = gpxFile.metadata.getDescription(); + + setupImage(imageUrl); + + TextViewEx tvDescription = view.findViewById(R.id.description); + tvDescription.setText(getFirstParagraph(descriptionHtml)); + + TextViewEx readBtn = view.findViewById(R.id.btn_read_full); + readBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + } + }); + TextViewEx editBtn = view.findViewById(R.id.btn_edit); + editBtn.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + } + }); + } + + @Nullable + private String getMetadataImageLink(@NonNull GPXUtilities.Metadata metadata) { + String link = metadata.link; + if (!TextUtils.isEmpty(link)) { + String lowerCaseLink = link.toLowerCase(); + if (lowerCaseLink.contains(".jpg") + || lowerCaseLink.contains(".jpeg") + || lowerCaseLink.contains(".png") + || lowerCaseLink.contains(".bmp") + || lowerCaseLink.contains(".webp")) { + return link; + } + } + return null; + } + + private String getFirstParagraph(String descriptionHtml) { + if (descriptionHtml != null) { + String firstParagraph = WikiArticleHelper.getPartialContent(descriptionHtml); + if (!TextUtils.isEmpty(firstParagraph)) { + return firstParagraph; + } + } + return descriptionHtml; + } + + private void setupImage(final String imageUrl) { + if (imageUrl == null) { + return; + } + final PicassoUtils picasso = PicassoUtils.getPicasso(app); + RequestCreator rc = Picasso.get().load(imageUrl); + final AppCompatImageView image = view.findViewById(R.id.main_image); + rc.into(image, new Callback() { + @Override + public void onSuccess() { + picasso.setResultLoaded(imageUrl, true); + AndroidUiHelper.updateVisibility(image, true); + } + + @Override + public void onError(Exception e) { + picasso.setResultLoaded(imageUrl, false); + } + }); + } + +} diff --git a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java index 03f8ab374a..d284d820ce 100644 --- a/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java +++ b/OsmAnd/src/net/osmand/plus/track/TrackMenuFragment.java @@ -15,19 +15,12 @@ import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.TextView; -import androidx.annotation.DrawableRes; -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; -import androidx.annotation.StringRes; -import androidx.appcompat.app.AlertDialog; -import androidx.fragment.app.FragmentActivity; -import androidx.fragment.app.FragmentManager; - import com.github.mikephil.charting.interfaces.datasets.ILineDataSet; import com.google.android.material.bottomnavigation.BottomNavigationView; import net.osmand.AndroidUtils; import net.osmand.FileUtils; +import net.osmand.FileUtils.GpxEditedCallback; import net.osmand.FileUtils.RenameCallback; import net.osmand.GPXUtilities.GPXFile; import net.osmand.GPXUtilities.Track; @@ -79,6 +72,14 @@ import org.apache.commons.logging.Log; import java.io.File; import java.util.List; +import androidx.annotation.DrawableRes; +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; +import androidx.annotation.StringRes; +import androidx.appcompat.app.AlertDialog; +import androidx.fragment.app.FragmentActivity; +import androidx.fragment.app.FragmentManager; + import static net.osmand.plus.activities.TrackActivity.CURRENT_RECORDING; import static net.osmand.plus.activities.TrackActivity.TRACK_FILE_NAME; import static net.osmand.plus.myplaces.TrackActivityFragmentAdapter.isGpxFileSelected; @@ -96,7 +97,7 @@ import static net.osmand.plus.track.OptionsCard.SHOW_ON_MAP_BUTTON_INDEX; import static net.osmand.plus.track.OptionsCard.UPLOAD_OSM_BUTTON_INDEX; public class TrackMenuFragment extends ContextMenuScrollFragment implements CardListener, - SegmentActionsListener, RenameCallback, OnTrackFileMoveListener { + SegmentActionsListener, RenameCallback, OnTrackFileMoveListener, GpxEditedCallback { public static final String TAG = TrackMenuFragment.class.getName(); private static final Log log = PlatformUtil.getLog(TrackMenuFragment.class); @@ -109,15 +110,17 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card private TextView headerTitle; private ImageView headerIcon; private BottomNavigationView bottomNav; - private TrackMenuType menuType = TrackMenuType.TRACK; + private TrackMenuType menuType = TrackMenuType.OVERVIEW; private SegmentsCard segmentsCard; private OptionsCard optionsCard; + private DescriptionCard descriptionCard; private TrackChartPoints trackChartPoints; private int menuTitleHeight; public enum TrackMenuType { + OVERVIEW(R.id.action_overview, R.string.shared_string_overview), TRACK(R.id.action_track, R.string.shared_string_gpx_tracks), POINTS(R.id.action_points, R.string.shared_string_gpx_points), OPTIONS(R.id.action_options, R.string.shared_string_options); @@ -219,6 +222,10 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } private void updateHeader() { + ViewGroup headerContainer = (ViewGroup) routeMenuTopShadowAll; + if (descriptionCard != null && descriptionCard.getView() != null) { + headerContainer.removeView(descriptionCard.getView()); + } if (menuType == TrackMenuType.OPTIONS) { headerTitle.setText(menuType.titleId); AndroidUiHelper.updateVisibility(headerIcon, false); @@ -226,7 +233,17 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card String fileName = Algorithms.getFileWithoutDirs(getGpx().path); headerTitle.setText(GpxUiHelper.getGpxTitle(fileName)); AndroidUiHelper.updateVisibility(headerIcon, true); + if (menuType == TrackMenuType.OVERVIEW) { + fillOverviewTab(headerContainer); + } } + runLayoutListener(); + headerContainer.post(new Runnable() { + @Override + public void run() { + openMenuScreen(menuType == TrackMenuType.OVERVIEW ? MenuState.HEADER_ONLY : MenuState.HALF_SCREEN, false); + } + }); } private void setupCards() { @@ -262,6 +279,19 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } } + private void fillOverviewTab(ViewGroup headerContainer) { + if (descriptionCard != null && descriptionCard.getView() != null) { + ViewGroup parent = ((ViewGroup) descriptionCard.getView().getParent()); + if (parent != null) { + parent.removeView(descriptionCard.getView()); + } + headerContainer.addView(descriptionCard.getView()); + } else { + descriptionCard = new DescriptionCard(getMapActivity(), displayHelper.getGpx()); + headerContainer.addView(descriptionCard.build(getMapActivity())); + } + } + @Override protected void calculateLayout(View view, boolean initLayout) { menuTitleHeight = routeMenuTopShadowAll.getHeight() @@ -306,6 +336,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card if (mapActivity != null && trackChartPoints != null) { mapActivity.getMapLayers().getGpxLayer().setTrackChartPoints(trackChartPoints); } + updateHeader(); } @Override @@ -567,7 +598,7 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card BottomNavigationView bottomNav = view.findViewById(R.id.bottom_navigation); bottomNav.setItemIconTintList(navColorStateList); bottomNav.setItemTextColor(navColorStateList); - bottomNav.setSelectedItemId(R.id.action_track); + bottomNav.setSelectedItemId(R.id.action_overview); bottomNav.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { @@ -783,6 +814,13 @@ public class TrackMenuFragment extends ContextMenuScrollFragment implements Card } } + @Override + public void onGpxChanged() { + if (descriptionCard != null) { + descriptionCard.update(); + } + } + public static boolean showInstance(@NonNull MapActivity mapActivity, String path, boolean showCurrentTrack) { try { Bundle args = new Bundle(); From b98b6014721405849073f8f8318cc77f7ff6abf9 Mon Sep 17 00:00:00 2001 From: cepprice Date: Sat, 23 Jan 2021 21:17:08 +0500 Subject: [PATCH 013/158] Add dialog fragments to edit and read gpx description --- OsmAnd/res/drawable/btn_border_active.xml | 8 + .../layout/dialog_edit_gpx_description.xml | 85 ++++++++ .../layout/dialog_read_gpx_description.xml | 95 ++++++++ OsmAnd/res/menu/edit_description_menu.xml | 8 + OsmAnd/res/values/attrs.xml | 1 + OsmAnd/res/values/styles.xml | 2 + .../osmand/plus/track/DescriptionCard.java | 2 + .../GpxEditDescriptionDialogFragment.java | 120 +++++++++++ .../GpxReadDescriptionDialogFragment.java | 202 ++++++++++++++++++ 9 files changed, 523 insertions(+) create mode 100644 OsmAnd/res/drawable/btn_border_active.xml create mode 100644 OsmAnd/res/layout/dialog_edit_gpx_description.xml create mode 100644 OsmAnd/res/layout/dialog_read_gpx_description.xml create mode 100644 OsmAnd/res/menu/edit_description_menu.xml create mode 100644 OsmAnd/src/net/osmand/plus/track/GpxEditDescriptionDialogFragment.java create mode 100644 OsmAnd/src/net/osmand/plus/track/GpxReadDescriptionDialogFragment.java diff --git a/OsmAnd/res/drawable/btn_border_active.xml b/OsmAnd/res/drawable/btn_border_active.xml new file mode 100644 index 0000000000..f670a7dfc9 --- /dev/null +++ b/OsmAnd/res/drawable/btn_border_active.xml @@ -0,0 +1,8 @@ + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/dialog_edit_gpx_description.xml b/OsmAnd/res/layout/dialog_edit_gpx_description.xml new file mode 100644 index 0000000000..e8e8443c98 --- /dev/null +++ b/OsmAnd/res/layout/dialog_edit_gpx_description.xml @@ -0,0 +1,85 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/OsmAnd/res/layout/dialog_read_gpx_description.xml b/OsmAnd/res/layout/dialog_read_gpx_description.xml new file mode 100644 index 0000000000..d21ae172c9 --- /dev/null +++ b/OsmAnd/res/layout/dialog_read_gpx_description.xml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/OsmAnd/res/menu/edit_description_menu.xml b/OsmAnd/res/menu/edit_description_menu.xml new file mode 100644 index 0000000000..8b3c09dc51 --- /dev/null +++ b/OsmAnd/res/menu/edit_description_menu.xml @@ -0,0 +1,8 @@ + + + + diff --git a/OsmAnd/res/values/attrs.xml b/OsmAnd/res/values/attrs.xml index caf08aef6a..c1463657dc 100644 --- a/OsmAnd/res/values/attrs.xml +++ b/OsmAnd/res/values/attrs.xml @@ -141,6 +141,7 @@ + diff --git a/OsmAnd/res/values/styles.xml b/OsmAnd/res/values/styles.xml index a7cbb98fda..5c074185ef 100644 --- a/OsmAnd/res/values/styles.xml +++ b/OsmAnd/res/values/styles.xml @@ -248,6 +248,7 @@ @style/RadioButtonStyle @color/text_input_background_light @drawable/img_help_announcement_time_day + @color/switch_button_active_light