Night mode fix, separate layout

This commit is contained in:
androiddevkotlin 2021-01-28 18:29:10 +02:00
parent 2cdb8953f6
commit c50e1d0679
6 changed files with 136 additions and 11 deletions

View file

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:id="@+id/custom_radio_buttons"
android:layout_width="match_parent"
android:minHeight="@dimen/dialog_button_height"
@ -12,10 +13,58 @@
android:orientation="horizontal"
tools:showIn="@layout/fragment_route_between_points_bottom_sheet_dialog">
<include layout="@layout/left_button_container"/>
<FrameLayout
android:id="@+id/left_button_container"
android:layout_width="0dp"
android:layout_height="match_parent"
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"/>
<include layout="@layout/center_button_container"/>
</FrameLayout>
<include layout="@layout/right_button_container"/>
<FrameLayout
android:id="@+id/center_button_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:visibility="gone">
<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"
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>
</LinearLayout>

View file

@ -0,0 +1,68 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:osmand="http://schemas.android.com/apk/res-auto"
android:id="@+id/custom_radio_buttons"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/content_padding"
android:layout_marginEnd="@dimen/content_padding"
android:background="?attr/btn_bg_border_inactive"
android:baselineAligned="false"
android:orientation="horizontal">
<FrameLayout
android:id="@+id/left_button_container"
android:layout_width="0dp"
android:layout_height="match_parent"
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"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:visibility="gone">
<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"
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>
</LinearLayout>

View file

@ -490,6 +490,7 @@ public class UiUtilities {
}
}
public static void updateCustomRadioButtonsGroup(Context app, View buttonsView, boolean nightMode,
CustomRadioButtonTypeGroup buttonType) {
int activeColor = ContextCompat.getColor(app, nightMode
@ -513,12 +514,14 @@ public class UiUtilities {
GradientDrawable background = new GradientDrawable();
background.setColor(UiUtilities.getColorWithAlpha(activeColor, 0.1f));
background.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(activeColor, 0.5f));
GradientDrawable startButtonRoundedCorner = new GradientDrawable();
startButtonRoundedCorner.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(inActiveColor, 0.5f));
GradientDrawable endButtonRoundedCorner = new GradientDrawable();
endButtonRoundedCorner.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(inActiveColor, 0.5f));
GradientDrawable centerButtonSharpCorner = new GradientDrawable();
centerButtonSharpCorner.setStroke(AndroidUtils.dpToPx(app, 1), UiUtilities.getColorWithAlpha(inActiveColor, 0.5f));
setStartEndCenterRoundedCorner(roundedCorner, isLayoutRtl, startButtonRoundedCorner, endButtonRoundedCorner, centerButtonSharpCorner);
if (buttonType == CustomRadioButtonTypeGroup.START) {
@ -564,6 +567,7 @@ public class UiUtilities {
centerButtonContainer.setBackgroundDrawable(endButtonRoundedCorner);
centerButtonText.setTextColor(textColor);
}
} else {
if (isLayoutRtl) {
background.setCornerRadii(new float[]{roundedCorner, roundedCorner, 0, 0, 0, 0, roundedCorner, roundedCorner});
@ -595,6 +599,7 @@ public class UiUtilities {
centerButtonSharpCorner.setCornerRadii(new float[]{0, 0, 0, 0, 0, 0, 0, 0});
}
public static void setupCompoundButtonDrawable(Context ctx, boolean nightMode, @ColorInt int activeColor, Drawable drawable) {
int inactiveColor = ContextCompat.getColor(ctx, nightMode ? R.color.icon_color_default_dark : R.color.icon_color_default_light);
int[][] states = new int[][]{
@ -747,7 +752,7 @@ public class UiUtilities {
int activeDisableColor = getColorWithAlpha(activeColor, 0.25f);
ColorStateList activeCsl = new ColorStateList(states, new int[] {activeColor, activeDisableColor});
int inactiveColor = ContextCompat.getColor(ctx, nightMode ? R.color.icon_color_default_dark : R.color.icon_color_secondary_light);
ColorStateList inactiveCsl = new ColorStateList(states, new int[] {inactiveColor, inactiveColor});
ColorStateList inactiveCsl = new ColorStateList(states, new int[] {activeDisableColor, inactiveColor});
slider.setTrackActiveTintList(activeCsl);
slider.setTrackInactiveTintList(inactiveCsl);
slider.setHaloTintList(activeCsl);

View file

@ -78,16 +78,19 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
private SegmentActionsListener actionsListener;
private boolean chartClicked;
private boolean nightMode;
public GPXItemPagerAdapter(@NonNull final PagerSlidingTabStrip tabs,
@NonNull GpxDisplayItem gpxItem,
@NonNull TrackDisplayHelper displayHelper,
@NonNull SegmentActionsListener actionsListener) {
@NonNull SegmentActionsListener actionsListener,
final boolean nightMode) {
super();
this.tabs = tabs;
this.gpxItem = gpxItem;
this.displayHelper = displayHelper;
this.nightMode = nightMode;
this.actionsListener = actionsListener;
app = (OsmandApplication) tabs.getContext().getApplicationContext();
iconsCache = app.getUIUtilities();
@ -106,7 +109,7 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
}
View parent = (View) tabs.getChildAt(0);
UiUtilities.updateCustomRadioButtonsGroup(app, parent, false, type);
UiUtilities.updateCustomRadioButtonsGroup(app, parent, nightMode, type);
}
@Override
@ -644,7 +647,7 @@ public class GPXItemPagerAdapter extends PagerAdapter implements CustomTabProvid
type = UiUtilities.CustomRadioButtonTypeGroup.END;
}
View parent = (View) tab.getParent();
UiUtilities.updateCustomRadioButtonsGroup(app, parent, false, type);
UiUtilities.updateCustomRadioButtonsGroup(app, parent, nightMode, type);
ViewGroup.MarginLayoutParams params = (ViewGroup.MarginLayoutParams) parent.getLayoutParams();
int contentPadding = app.getResources().getDimensionPixelSize(R.dimen.content_padding);

View file

@ -1,6 +1,7 @@
package net.osmand.plus.myplaces;
import android.content.Context;
import android.graphics.drawable.GradientDrawable;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
@ -21,7 +22,6 @@ import java.util.List;
public class SegmentGPXAdapter extends ArrayAdapter<GpxDisplayItem> {
private OsmandApplication app;
private TrackDisplayHelper displayHelper;
private SegmentActionsListener listener;
private boolean nightMode;
@ -31,7 +31,7 @@ public class SegmentGPXAdapter extends ArrayAdapter<GpxDisplayItem> {
@NonNull SegmentActionsListener listener,
boolean nightMode) {
super(context, R.layout.gpx_list_item_tab_content, items);
this.app = (OsmandApplication) context.getApplicationContext();
OsmandApplication app = (OsmandApplication) context.getApplicationContext();
this.displayHelper = displayHelper;
this.listener = listener;
this.nightMode = nightMode;
@ -56,7 +56,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(tabLayout, item, displayHelper, listener, nightMode));
if (create) {
tabLayout.setViewPager(pager);
} else {

View file

@ -48,7 +48,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(tabLayout, displayItem, displayHelper, listener, nightMode));
tabLayout.setViewPager(pager);
container.addView(segmentView);