Merge pull request #9305 from osmandapp/Fix_vehicle_parameters

Fix vehicle parameters
This commit is contained in:
vshcherb 2020-06-25 11:06:48 +02:00 committed by GitHub
commit 640f52d723
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 65 additions and 15 deletions

View file

@ -0,0 +1,9 @@
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/active_buttons_and_links_bg_pressed_dark">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="@color/active_color_primary_dark" />
<corners android:radius="18dp" />
</shape>
</item>
</ripple>

View file

@ -0,0 +1,9 @@
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="@color/active_buttons_and_links_bg_pressed_light">
<item android:id="@android:id/mask">
<shape android:shape="rectangle">
<solid android:color="@color/active_color_primary_light" />
<corners android:radius="18dp" />
</shape>
</item>
</ripple>

View file

@ -19,7 +19,10 @@
android:paddingRight="@dimen/content_padding"
android:paddingTop="@dimen/content_padding_small"
android:paddingBottom="@dimen/content_padding_small"
android:textAppearance="@style/TextAppearance.ListItemCategoryTitle"
android:letterSpacing="@dimen/text_button_letter_spacing"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:text="Some Title"
android:paddingStart="@dimen/content_padding"
android:paddingEnd="@dimen/content_padding" />

View file

@ -1,6 +1,7 @@
package net.osmand.plus.mapcontextmenu.other;
import android.graphics.drawable.GradientDrawable;
import android.os.Build;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
@ -43,7 +44,8 @@ public class HorizontalSelectionAdapter extends RecyclerView.Adapter<HorizontalS
@Override
public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view;
view = UiUtilities.getInflater(parent.getContext(), nightMode).inflate(R.layout.point_editor_icon_category_item, parent, false);
view = UiUtilities.getInflater(parent.getContext(), nightMode).inflate(R.layout.point_editor_icon_category_item,
parent, false);
return new ItemViewHolder(view);
}
@ -53,8 +55,8 @@ public class HorizontalSelectionAdapter extends RecyclerView.Adapter<HorizontalS
TextView textView = holder.buttonText;
int activeColorResId = nightMode ? R.color.active_color_primary_dark : R.color.active_color_primary_light;
if (item.equals(selectedItem)) {
AndroidUtils.setBackground(holder.button, app.getUIUtilities().getPaintedIcon(R.drawable.bg_select_icon_group_button,
ContextCompat.getColor(app, activeColorResId)));
AndroidUtils.setBackground(holder.button, app.getUIUtilities().getPaintedIcon(
R.drawable.bg_select_icon_group_button, ContextCompat.getColor(app, activeColorResId)));
textView.setTextColor(ContextCompat.getColor(app, R.color.color_white));
} else {
textView.setTextColor(ContextCompat.getColor(app,
@ -78,6 +80,11 @@ public class HorizontalSelectionAdapter extends RecyclerView.Adapter<HorizontalS
}
}
});
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
View buttonContainer = holder.button.findViewById(R.id.button_container);
AndroidUtils.setBackground(app, buttonContainer, nightMode, R.drawable.ripple_solid_light_18dp,
R.drawable.ripple_solid_dark_18dp);
}
}
@Override
@ -110,7 +117,7 @@ public class HorizontalSelectionAdapter extends RecyclerView.Adapter<HorizontalS
ItemViewHolder(@NonNull View itemView) {
super(itemView);
buttonText = itemView.findViewById(R.id.button_text);
button = itemView.findViewById(R.id.button_container);
button = itemView.findViewById(R.id.button);
}
}
}

View file

@ -1,6 +1,7 @@
package net.osmand.plus.settings.bottomsheets;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
@ -22,12 +23,12 @@ import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.recyclerview.widget.RecyclerView;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.mapcontextmenu.other.HorizontalSelectionAdapter;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.settings.fragments.ApplyQueryType;
@ -37,6 +38,7 @@ import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import java.text.DecimalFormat;
import java.util.Arrays;
public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet {
@ -76,6 +78,7 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet {
final TextView metric = mainView.findViewById(R.id.metric);
metric.setText(app.getString(preference.getAssets().getMetricRes()));
final RecyclerView recyclerView = mainView.findViewById(R.id.recycler_view);
final DecimalFormat df = new DecimalFormat("#.####");
text = mainView.findViewById(R.id.text_edit);
try {
currentValue = Float.parseFloat(preference.getValue());
@ -83,8 +86,7 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet {
currentValue = 0.0f;
}
selectedItem = preference.getEntryFromValue(preference.getValue());
String currentValueStr = currentValue == 0.0f ? "" : String.valueOf(currentValue + 0.01f);
String currentValueStr = currentValue == 0.0f ? "" : String.valueOf(df.format(currentValue + 0.01f));
text.setText(currentValueStr);
text.clearFocus();
text.setOnTouchListener(new View.OnTouchListener() {
@ -130,7 +132,8 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet {
public void onItemSelected(String item) {
selectedItem = item;
currentValue = preference.getValueFromEntries(selectedItem);
String currentValueStr = currentValue == 0.0f ? "" : String.valueOf(currentValue + 0.01f);
String currentValueStr = currentValue == 0.0f
? "" : String.valueOf(df.format(currentValue + 0.01f));
text.setText(currentValueStr);
if (text.hasFocus()) {
text.setSelection(text.getText().length());
@ -155,21 +158,21 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet {
private ViewTreeObserver.OnGlobalLayoutListener getOnGlobalLayoutListener() {
final int buttonsHeight = getResources().getDimensionPixelSize(R.dimen.dialog_button_ex_height);
final int shadowHeight = AndroidUtils.dpToPx(getContext(), 8);
final int statusBarHeight = AndroidUtils.getStatusBarHeight(getContext());
return new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
Rect visibleDisplayFrame = new Rect();
final ScrollView scrollView = getView().findViewById(R.id.scroll_view);
scrollView.getWindowVisibleDisplayFrame(visibleDisplayFrame);
int contentHeight = visibleDisplayFrame.bottom - visibleDisplayFrame.top - buttonsHeight
- shadowHeight - statusBarHeight;
boolean showTopShadow;
int contentHeight = visibleDisplayFrame.bottom - visibleDisplayFrame.top - buttonsHeight;
if (contentHeightPrevious != contentHeight) {
if (scrollView.getHeight() > contentHeight) {
scrollView.getLayoutParams().height = contentHeight;
showTopShadow = false;
} else {
scrollView.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;
showTopShadow = true;
}
scrollView.requestLayout();
int delay = Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP ? 300 : 1000;
@ -179,6 +182,24 @@ public class VehicleParametersBottomSheet extends BasePreferenceBottomSheet {
}
}, delay);
contentHeightPrevious = contentHeight;
drawTopShadow(showTopShadow);
}
}
private void drawTopShadow(boolean showTopShadow) {
final Activity activity = getActivity();
View mainView = getView();
if (activity == null || mainView == null) {
return;
}
if (AndroidUiHelper.isOrientationPortrait(activity)) {
mainView.setBackgroundResource(showTopShadow ? getPortraitBgResId() : getBgColorId());
if (!showTopShadow) {
mainView.setPadding(0, 0, 0, 0);
}
} else {
mainView.setBackgroundResource(showTopShadow
? getLandscapeTopsidesBgResId() : getLandscapeSidesBgResId());
}
}
};

View file

@ -88,6 +88,7 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O
? ROUTING_PARAMETER_NUMERIC_DEFAULT : ROUTING_PARAMETER_SYMBOLIC_DEFAULT;
OsmandSettings.StringPreference pref = (OsmandSettings.StringPreference) app.getSettings()
.getCustomRoutingProperty(parameterId, defValue);
VehicleSizeAssets assets = VehicleSizeAssets.getAssets(parameterId, routerProfile);
Object[] values = parameter.getPossibleValues();
String[] valuesStr = new String[values.length];
for (int i = 0; i < values.length; i++) {
@ -98,7 +99,7 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O
for (int i = 1; i < entriesStr.length; i++) {
int firstCharIndex = Algorithms.findFirstNumberEndIndex(entriesStr[i]);
entriesStr[i] = String.format(app.getString(R.string.ltr_or_rtl_combine_via_space),
entriesStr[i].substring(0, firstCharIndex), entriesStr[i].substring(firstCharIndex));
entriesStr[i].substring(0, firstCharIndex), getString(assets.getMetricShortRes()));
}
Context ctx = getContext();
@ -107,7 +108,7 @@ public class VehicleParametersFragment extends BaseSettingsFragment implements O
}
SizePreference vehicleSizePref = new SizePreference(ctx);
vehicleSizePref.setKey(pref.getId());
vehicleSizePref.setAssets(VehicleSizeAssets.getAssets(parameterId, routerProfile));
vehicleSizePref.setAssets(assets);
vehicleSizePref.setDefaultValue(defValue);
vehicleSizePref.setTitle(title);
vehicleSizePref.setEntries(entriesStr);