Merge pull request #10706 from osmandapp/graph-toggle

Graph toggle
This commit is contained in:
Vitaliy 2021-02-01 11:38:32 +02:00 committed by GitHub
commit 71c7cfbdbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 224 additions and 160 deletions

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:id="@+id/center_button_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/center_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:text="@string/altitude"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium" />
</FrameLayout>

View file

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/custom_radio_buttons"
android:layout_width="match_parent"
@ -13,59 +12,22 @@
android:orientation="horizontal"
tools:showIn="@layout/fragment_route_between_points_bottom_sheet_dialog">
<FrameLayout
android:id="@+id/left_button_container"
<include
layout="@layout/left_button_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
android:layout_weight="1" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/left_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:text="@string/shared_string_left"/>
</FrameLayout>
<FrameLayout
android:id="@+id/center_button_container"
<include
layout="@layout/center_button_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:visibility="gone">
android:layout_weight="1" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/center_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:text="@string/position_on_map_center"/>
</FrameLayout>
<FrameLayout
android:id="@+id/right_button_container"
<include
layout="@layout/right_button_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/right_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:text="@string/shared_string_right"/>
</FrameLayout>
android:layout_weight="1" />
</LinearLayout>

View file

@ -1,24 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">
android:layout_height="wrap_content"
android:orientation="vertical">
<include layout="@layout/list_item_divider" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:orientation="vertical">
<net.osmand.plus.views.controls.PagerSlidingTabStrip
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="?attr/bg_color"/>
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
android:minHeight="@dimen/dialog_button_height"
android:paddingTop="@dimen/content_padding" />
<net.osmand.plus.views.controls.WrapContentHeightViewPager
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/bg_color"
android:paddingTop="4dp" />
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:id="@+id/left_button_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/left_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:text="@string/shared_string_overview"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium" />
</FrameLayout>

View file

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:id="@+id/right_button_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/right_button"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/selectableItemBackground"
android:gravity="center"
android:text="@string/map_widget_speed"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_medium" />
</FrameLayout>

View file

@ -87,6 +87,7 @@ public class UiUtilities {
public enum CustomRadioButtonType {
START,
CENTER,
END,
}
@ -456,6 +457,8 @@ public class UiUtilities {
TextView startButtonText = buttonsView.findViewById(R.id.left_button);
View startButtonContainer = buttonsView.findViewById(R.id.left_button_container);
TextView centerButtonText = buttonsView.findViewById(R.id.center_button);
View centerButtonContainer = buttonsView.findViewById(R.id.center_button_container);
TextView endButtonText = buttonsView.findViewById(R.id.right_button);
View endButtonContainer = buttonsView.findViewById(R.id.right_button_container);
GradientDrawable background = new GradientDrawable();
@ -471,6 +474,24 @@ public class UiUtilities {
endButtonText.setTextColor(activeColor);
startButtonContainer.setBackgroundDrawable(background);
startButtonText.setTextColor(textColor);
if (centerButtonContainer != null) {
centerButtonText.setTextColor(activeColor);
centerButtonContainer.setBackgroundColor(Color.TRANSPARENT);
}
} else if (buttonType == CustomRadioButtonType.CENTER) {
background.setCornerRadii(new float[] {0, 0, 0, 0, 0, 0, 0, 0});
centerButtonContainer.setBackgroundDrawable(background);
centerButtonText.setTextColor(textColor);
if (endButtonContainer != null) {
endButtonText.setTextColor(activeColor);
endButtonContainer.setBackgroundColor(Color.TRANSPARENT);
}
if (startButtonContainer != null) {
startButtonText.setTextColor(activeColor);
startButtonContainer.setBackgroundColor(Color.TRANSPARENT);
}
} else {
if (isLayoutRtl) {
background.setCornerRadii(new float[] {radius, radius, 0, 0, 0, 0, radius, radius});
@ -481,6 +502,11 @@ public class UiUtilities {
endButtonText.setTextColor(textColor);
startButtonContainer.setBackgroundColor(Color.TRANSPARENT);
startButtonText.setTextColor(activeColor);
if (centerButtonContainer != null) {
centerButtonText.setTextColor(activeColor);
centerButtonContainer.setBackgroundColor(Color.TRANSPARENT);
}
}
}

View file

@ -7,6 +7,7 @@ import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.MarginLayoutParams;
import android.widget.ImageView;
import android.widget.TextView;
@ -35,6 +36,7 @@ import net.osmand.plus.OsmAndFormatter;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.UiUtilities.CustomRadioButtonType;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.helpers.GpxUiHelper;
import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetAxisType;
@ -42,7 +44,6 @@ import net.osmand.plus.helpers.GpxUiHelper.GPXDataSetType;
import net.osmand.plus.helpers.GpxUiHelper.LineGraphType;
import net.osmand.plus.helpers.GpxUiHelper.OrderedLineDataSet;
import net.osmand.plus.track.TrackDisplayHelper;
import net.osmand.plus.views.controls.PagerSlidingTabStrip;
import net.osmand.plus.views.controls.PagerSlidingTabStrip.CustomTabProvider;
import net.osmand.plus.views.controls.WrapContentHeightViewPager.ViewAtPositionInterface;
import net.osmand.util.Algorithms;
@ -51,6 +52,7 @@ import net.osmand.util.MapUtils;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
@ -72,23 +74,23 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
private GpxDisplayItem gpxItem;
private GPXTabItemType[] tabTypes;
private PagerSlidingTabStrip tabs;
private SparseArray<View> views = new SparseArray<>();
private SegmentActionsListener actionsListener;
private boolean chartClicked;
private boolean nightMode;
public GPXItemPagerAdapter(@NonNull PagerSlidingTabStrip tabs,
public GPXItemPagerAdapter(@NonNull OsmandApplication app,
@NonNull GpxDisplayItem gpxItem,
@NonNull TrackDisplayHelper displayHelper,
@NonNull SegmentActionsListener actionsListener) {
boolean nightMode, @NonNull SegmentActionsListener actionsListener) {
super();
this.tabs = tabs;
this.app = app;
this.gpxItem = gpxItem;
this.nightMode = nightMode;
this.displayHelper = displayHelper;
this.actionsListener = actionsListener;
app = (OsmandApplication) tabs.getContext().getApplicationContext();
iconsCache = app.getUIUtilities();
fetchTabTypes();
}
@ -556,40 +558,60 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
return view == object;
}
int singleTabLayoutId[] = {R.layout.center_button_container};
int doubleTabsLayoutIds[] = {R.layout.left_button_container, R.layout.right_button_container};
int tripleTabsLayoutIds[] = {R.layout.left_button_container, R.layout.center_button_container, R.layout.right_button_container};
@Override
public View getCustomTabView(@NonNull ViewGroup parent, int position) {
View tab = LayoutInflater.from(parent.getContext()).inflate(R.layout.gpx_tab, parent, false);
int layoutId;
int count = getCount();
if (count == 1) {
layoutId = singleTabLayoutId[position];
} else if (count == 2) {
layoutId = doubleTabsLayoutIds[position];
} else {
layoutId = tripleTabsLayoutIds[position];
}
View tab = LayoutInflater.from(parent.getContext()).inflate(layoutId, parent, false);
tab.setTag(tabTypes[position].name());
deselect(tab);
return tab;
}
@Override
public void select(View tab) {
GPXTabItemType tabType = GPXTabItemType.valueOf((String) tab.getTag());
ImageView img = tab.findViewById(R.id.tab_image);
switch (tabs.getTabSelectionType()) {
case ALPHA:
img.setAlpha(tabs.getTabTextSelectedAlpha());
break;
case SOLID_COLOR:
img.setImageDrawable(iconsCache.getPaintedIcon(tabType.getIconId(), tabs.getTextColor()));
break;
}
int index = Arrays.asList(tabTypes).indexOf(tabType);
View parent = (View) tab.getParent();
UiUtilities.updateCustomRadioButtons(app, parent, nightMode, getCustomRadioButtonType(index));
}
@Override
public void deselect(View tab) {
GPXTabItemType tabType = GPXTabItemType.valueOf((String) tab.getTag());
ImageView img = tab.findViewById(R.id.tab_image);
switch (tabs.getTabSelectionType()) {
case ALPHA:
img.setAlpha(tabs.getTabTextAlpha());
break;
case SOLID_COLOR:
img.setImageDrawable(iconsCache.getPaintedIcon(tabType.getIconId(), tabs.getTabInactiveTextColor()));
break;
}
@Override
public void tabStylesUpdated(View tabsContainer, int currentPosition) {
ViewGroup.MarginLayoutParams params = (MarginLayoutParams) tabsContainer.getLayoutParams();
params.height = app.getResources().getDimensionPixelSize(R.dimen.dialog_button_height);
tabsContainer.setLayoutParams(params);
UiUtilities.updateCustomRadioButtons(app, tabsContainer, nightMode, getCustomRadioButtonType(currentPosition));
}
private CustomRadioButtonType getCustomRadioButtonType(int index) {
int count = getCount();
CustomRadioButtonType type = CustomRadioButtonType.CENTER;
if (count == 2) {
type = index > 0 ? CustomRadioButtonType.END : CustomRadioButtonType.START;
} else if (count == 3) {
if (index == 0) {
type = CustomRadioButtonType.START;
} else if (index == 2) {
type = CustomRadioButtonType.END;
}
}
return type;
}
@Override

View file

@ -6,7 +6,6 @@ import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import net.osmand.AndroidUtils;
import net.osmand.plus.GpxSelectionHelper.GpxDisplayItem;
@ -56,7 +55,7 @@ public class SegmentGPXAdapter extends ArrayAdapter<GpxDisplayItem> {
WrapContentHeightViewPager pager = row.findViewById(R.id.pager);
PagerSlidingTabStrip tabLayout = row.findViewById(R.id.sliding_tabs);
pager.setAdapter(new GPXItemPagerAdapter(tabLayout, item, displayHelper, listener));
pager.setAdapter(new GPXItemPagerAdapter(app, item, displayHelper, nightMode, listener));
if (create) {
tabLayout.setViewPager(pager);
} else {
@ -72,15 +71,8 @@ public class SegmentGPXAdapter extends ArrayAdapter<GpxDisplayItem> {
View row = UiUtilities.getInflater(context, nightMode).inflate(R.layout.gpx_list_item_tab_content, root, false);
PagerSlidingTabStrip tabLayout = row.findViewById(R.id.sliding_tabs);
tabLayout.setTabBackground(R.color.color_transparent);
tabLayout.setIndicatorColorResource(nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light);
tabLayout.setIndicatorBgColorResource(nightMode ? R.color.divider_color_dark : R.color.divider_color_light);
tabLayout.setIndicatorHeight(AndroidUtils.dpToPx(context, 1f));
if (!nightMode) {
tabLayout.setTextColor(tabLayout.getIndicatorColor());
tabLayout.setTabInactiveTextColor(ContextCompat.getColor(row.getContext(), R.color.text_color_secondary_light));
}
tabLayout.setTextSize(AndroidUtils.spToPx(context, 12f));
tabLayout.setTabBackground(AndroidUtils.resolveAttribute(context, R.attr.btn_bg_border_inactive));
tabLayout.setIndicatorHeight(0);
tabLayout.setShouldExpand(true);
WrapContentHeightViewPager pager = row.findViewById(R.id.pager);
pager.setSwipeable(false);

View file

@ -47,7 +47,7 @@ public class SegmentsCard extends BaseCard {
WrapContentHeightViewPager pager = segmentView.findViewById(R.id.pager);
PagerSlidingTabStrip tabLayout = segmentView.findViewById(R.id.sliding_tabs);
pager.setAdapter(new GPXItemPagerAdapter(tabLayout, displayItem, displayHelper, listener));
pager.setAdapter(new GPXItemPagerAdapter(app, displayItem, displayHelper, nightMode, listener));
tabLayout.setViewPager(pager);
container.addView(segmentView);

View file

@ -68,6 +68,7 @@ public class PagerSlidingTabStrip extends HorizontalScrollView {
public View getCustomTabView(@NonNull ViewGroup parent, int position);
public void select(View tab);
public void deselect(View tab);
public void tabStylesUpdated(View tabsContainer, int currentPosition);
}
public interface OnTabReselectedListener {
@ -307,6 +308,10 @@ public class PagerSlidingTabStrip extends HorizontalScrollView {
}
}
public int getCurrentPosition() {
return currentPosition;
}
private void addTab(final int position, CharSequence title, View tabView) {
TextView textView = (TextView) tabView.findViewById(R.id.tab_title);
if (textView != null) {
@ -332,41 +337,31 @@ public class PagerSlidingTabStrip extends HorizontalScrollView {
private void updateTabStyles() {
tabsContainer.setBackgroundResource(tabBackgroundResId);
if (pager.getAdapter() instanceof CustomTabProvider) {
((CustomTabProvider) pager.getAdapter()).tabStylesUpdated(tabsContainer, currentPosition);
} else {
for (int i = 0; i < tabCount; i++) {
View v = tabsContainer.getChildAt(i);
v.setBackgroundResource(tabBackgroundResId);
v.setPadding(tabPadding, v.getPaddingTop(), tabPadding, v.getPaddingBottom());
TextView tab_title = (TextView) v.findViewById(R.id.tab_title);
if (tab_title != null) {
tab_title.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
tab_title.setTypeface(tabTypeface, pager.getCurrentItem() == i ? tabTypefaceSelectedStyle : tabTypefaceStyle);
TextView tabTitle = v.findViewById(R.id.tab_title);
if (tabTitle != null) {
tabTitle.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
tabTitle.setTypeface(tabTypeface, pager.getCurrentItem() == i ? tabTypefaceSelectedStyle : tabTypefaceStyle);
switch (tabSelectionType) {
case ALPHA:
float alpha = pager.getCurrentItem() == i ? tabTextSelectedAlpha : tabTextAlpha;
tab_title.setAlpha(alpha);
tab_title.setTextColor(tabTextColor);
tabTitle.setAlpha(alpha);
tabTitle.setTextColor(tabTextColor);
break;
case SOLID_COLOR:
tab_title.setAlpha(OPAQUE);
tab_title.setTextColor(pager.getCurrentItem() == i ? tabTextColor : tabInactiveTextColor);
tabTitle.setAlpha(OPAQUE);
tabTitle.setTextColor(pager.getCurrentItem() == i ? tabTextColor : tabInactiveTextColor);
break;
}
if (pager.getAdapter() instanceof CustomTabProvider) {
if (pager.getCurrentItem() == i) {
((CustomTabProvider) pager.getAdapter()).select(v);
} else {
((CustomTabProvider) pager.getAdapter()).deselect(v);
}
}
// setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
// pre-ICS-build
if (textAllCaps) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
tab_title.setAllCaps(true);
} else {
tab_title.setText(tab_title.getText().toString().toUpperCase(locale));
tabTitle.setAllCaps(true);
}
}
}
@ -558,7 +553,10 @@ public class PagerSlidingTabStrip extends HorizontalScrollView {
private void notSelected(View tab) {
if (tab != null) {
TextView title = (TextView) tab.findViewById(R.id.tab_title);
if (pager.getAdapter() instanceof CustomTabProvider) {
((CustomTabProvider) pager.getAdapter()).deselect(tab);
} else {
TextView title = tab.findViewById(R.id.tab_title);
if (title != null) {
title.setTypeface(tabTypeface, tabTypefaceStyle);
switch (tabSelectionType) {
@ -570,15 +568,16 @@ public class PagerSlidingTabStrip extends HorizontalScrollView {
break;
}
}
if (pager.getAdapter() instanceof CustomTabProvider) {
((CustomTabProvider) pager.getAdapter()).deselect(tab);
}
}
}
private void selected(View tab) {
if (tab != null) {
TextView title = (TextView) tab.findViewById(R.id.tab_title);
if (pager.getAdapter() instanceof CustomTabProvider) {
((CustomTabProvider) pager.getAdapter()).select(tab);
} else {
TextView title = tab.findViewById(R.id.tab_title);
if (title != null) {
title.setTypeface(tabTypeface, tabTypefaceSelectedStyle);
switch (tabSelectionType) {
@ -589,8 +588,6 @@ public class PagerSlidingTabStrip extends HorizontalScrollView {
title.setTextColor(tabTextColor);
break;
}
if (pager.getAdapter() instanceof CustomTabProvider) {
((CustomTabProvider) pager.getAdapter()).select(tab);
}
}
}