Merge pull request #9543 from osmandapp/Fix_4917

Fix #4917
This commit is contained in:
vshcherb 2020-07-30 18:53:22 +02:00 committed by GitHub
commit 7567a1b3ae
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 155 additions and 25 deletions

View file

@ -0,0 +1,96 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:minHeight="@dimen/bottom_sheet_selected_item_title_height">
<LinearLayout
android:id="@+id/basic_item_body"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="?attr/selectableItemBackground"
android:paddingStart="@dimen/content_padding"
android:paddingLeft="@dimen/content_padding"
android:paddingEnd="0dp"
android:paddingRight="0dp">
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center_vertical"
android:layout_marginEnd="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/bottom_sheet_icon_margin"
tools:src="@drawable/list_destination" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.ListItemTitle"
tools:text="Some title" />
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textAppearance="@style/TextAppearance.ContextMenuSubtitle"
tools:text="Some description" />
</LinearLayout>
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/compound_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginStart="@dimen/bottom_sheet_content_margin"
android:layout_marginLeft="@dimen/bottom_sheet_content_margin"
android:layout_marginEnd="@dimen/content_padding_half"
android:layout_marginRight="@dimen/content_padding_half"
android:background="@null"
android:clickable="false"
android:focusable="false"
android:focusableInTouchMode="false" />
</LinearLayout>
<LinearLayout
android:id="@+id/additional_button"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:layout_marginTop="@dimen/content_padding_half"
android:layout_marginBottom="@dimen/content_padding_half"
android:background="?attr/divider_color_basic" />
<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/additional_button_icon"
android:layout_width="@dimen/standard_icon_size"
android:layout_height="@dimen/standard_icon_size"
android:layout_gravity="center"
android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding"
tools:src="@drawable/ic_action_info_dark" />
</LinearLayout>
</LinearLayout>

View file

@ -2,9 +2,12 @@ package net.osmand.plus.routepreparationmenu;
import android.app.Activity;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Bundle;
import android.view.MenuItem;
import android.view.View;
import android.widget.CompoundButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
@ -19,6 +22,7 @@ import net.osmand.AndroidUtils;
import net.osmand.CallbackWithObject;
import net.osmand.GPXUtilities;
import net.osmand.StateChangedListener;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.settings.backend.ApplicationMode;
import net.osmand.plus.OsmAndLocationSimulation;
import net.osmand.plus.OsmandApplication;
@ -168,32 +172,62 @@ public class RouteOptionsBottomSheet extends MenuBottomSheetDialogFragment {
private BaseBottomSheetItem createMuteSoundItem(final LocalRoutingParameter optionsItem) {
boolean active = !routingHelper.getVoiceRouter().isMuteForMode(applicationMode);
final BottomSheetItemWithCompoundButton[] muteSoundItem = new BottomSheetItemWithCompoundButton[1];
muteSoundItem[0] = (BottomSheetItemWithCompoundButton) new BottomSheetItemWithCompoundButton.Builder()
.setCompoundButtonColorId(selectedModeColorId)
.setChecked(active)
.setDescription(getString(R.string.voice_announcements))
.setIcon(getContentIcon(active ? optionsItem.getActiveIconId() : optionsItem.getDisabledIconId()))
.setTitle(getString(R.string.shared_string_sound))
.setLayoutId(R.layout.bottom_sheet_item_with_descr_and_switch_56dp)
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
routingOptionsHelper.addNewRouteMenuParameter(applicationMode, optionsItem);
boolean active = !routingHelper.getVoiceRouter().isMuteForMode(applicationMode);
routingHelper.getVoiceRouter().setMuteForMode(applicationMode, active);
String voiceProvider = app.getSettings().VOICE_PROVIDER.getModeValue(applicationMode);
if (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) {
OsmAndDialogs.showVoiceProviderDialog(mapActivity, applicationMode, false);
} else {
muteSoundItem[0].setChecked(!active);
muteSoundItem[0].setIcon(getContentIcon(!active ? optionsItem.getActiveIconId() : optionsItem.getDisabledIconId()));
}
updateMenu();
}
})
int selectedModeColor = ContextCompat.getColor(app, selectedModeColorId);
final View itemView = UiUtilities.getInflater(app, nightMode).inflate(
R.layout.bottom_sheet_item_with_descr_switch_and_additional_button_56dp, null, false);
final ImageView icon = itemView.findViewById(R.id.icon);
TextView tvTitle = itemView.findViewById(R.id.title);
TextView tvDescription = itemView.findViewById(R.id.description);
View basicItem = itemView.findViewById(R.id.basic_item_body);
final CompoundButton cb = itemView.findViewById(R.id.compound_button);
View voicePromptsBtn = itemView.findViewById(R.id.additional_button);
ImageView voicePromptsBtnImage = itemView.findViewById(R.id.additional_button_icon);
tvTitle.setText(getString(R.string.shared_string_sound));
tvDescription.setText(getString(R.string.voice_announcements));
icon.setImageDrawable(getContentIcon(active ?
optionsItem.getActiveIconId() : optionsItem.getDisabledIconId()));
cb.setChecked(active);
cb.setFocusable(false);
UiUtilities.setupCompoundButton(nightMode, selectedModeColor, cb);
basicItem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
routingOptionsHelper.addNewRouteMenuParameter(applicationMode, optionsItem);
boolean active = !routingHelper.getVoiceRouter().isMuteForMode(applicationMode);
routingHelper.getVoiceRouter().setMuteForMode(applicationMode, active);
String voiceProvider = app.getSettings().VOICE_PROVIDER.getModeValue(applicationMode);
if (voiceProvider == null || OsmandSettings.VOICE_PROVIDER_NOT_USE.equals(voiceProvider)) {
OsmAndDialogs.showVoiceProviderDialog(mapActivity, applicationMode, false);
} else {
cb.setChecked(!active);
icon.setImageDrawable(getContentIcon(!active ? optionsItem.getActiveIconId() : optionsItem.getDisabledIconId()));
}
updateMenu();
}
});
Drawable drawable = app.getUIUtilities().getIcon(R.drawable.ic_action_settings,
nightMode ? R.color.route_info_control_icon_color_dark : R.color.route_info_control_icon_color_light);
if (Build.VERSION.SDK_INT >= 21) {
Drawable activeDrawable = app.getUIUtilities().getIcon(R.drawable.ic_action_settings, selectedModeColorId);
drawable = AndroidUtils.createPressedStateListDrawable(drawable, activeDrawable);
}
voicePromptsBtnImage.setImageDrawable(drawable);
voicePromptsBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
BaseSettingsFragment.showInstance(
mapActivity, BaseSettingsFragment.SettingsScreenType.VOICE_ANNOUNCES);
dismiss();
}
});
return new BaseBottomSheetItem.Builder()
.setCustomView(itemView)
.create();
return muteSoundItem[0];
}
private BaseBottomSheetItem createTimeConditionalRoutingItem(final LocalRoutingParameter optionsItem) {