Add toolbar switch to proxy screen

This commit is contained in:
Chumva 2019-09-26 13:27:44 +03:00
parent 10a887af3f
commit cfdb172936
10 changed files with 232 additions and 80 deletions

View file

@ -0,0 +1,50 @@
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/actionModeBackground"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:minHeight="@dimen/toolbar_height"
android:orientation="horizontal">
<ImageButton
android:id="@+id/close_button"
style="@style/Widget.AppCompat.Toolbar.Button.Navigation"
android:layout_width="@dimen/toolbar_height"
android:layout_height="@dimen/toolbar_height"
android:contentDescription="@string/access_shared_string_navigate_up"
android:src="@drawable/ic_action_mode_back" />
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/toolbar_title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:textColor="?attr/app_bar_primary_item_color"
android:textSize="@dimen/dialog_header_text_size"
app:typeface="@string/font_roboto_medium"
tools:text="@string/routing_settings_2" />
</LinearLayout>
<include layout="@layout/preference_toolbar_switch" />
</LinearLayout>
</android.support.v7.widget.Toolbar>

View file

@ -22,38 +22,18 @@
android:layout_marginLeft="@dimen/content_padding" android:layout_marginLeft="@dimen/content_padding"
android:layout_marginRight="@dimen/content_padding" /> android:layout_marginRight="@dimen/content_padding" />
<LinearLayout <net.osmand.plus.widgets.TextViewEx
android:id="@android:id/title"
android:layout_width="0dp" android:layout_width="0dp"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_gravity="center_vertical" android:layout_gravity="center_vertical"
android:layout_weight="1" android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="@dimen/content_padding" android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"> android:paddingRight="@dimen/content_padding"
<net.osmand.plus.widgets.TextViewEx
android:id="@android:id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textColor="?android:textColorPrimary" android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size" android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular" /> osmand:typeface="@string/font_roboto_regular" />
<net.osmand.plus.widgets.TextViewEx
android:id="@android:id/summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:letterSpacing="@dimen/description_letter_spacing"
android:maxLines="4"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular" />
</LinearLayout>
<android.support.v7.widget.SwitchCompat <android.support.v7.widget.SwitchCompat
android:id="@+id/switchWidget" android:id="@+id/switchWidget"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View file

@ -0,0 +1,71 @@
<?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:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/list_background_color"
android:gravity="center_vertical">
<LinearLayout
android:id="@+id/selectable_list_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="@dimen/bottom_sheet_list_item_height"
tools:background="?android:attr/selectableItemBackground">
<ImageView
android:id="@android:id/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_marginTop="@dimen/bottom_sheet_icon_margin"
android:layout_marginRight="@dimen/content_padding"
android:layout_marginBottom="@dimen/bottom_sheet_icon_margin" />
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding">
<net.osmand.plus.widgets.TextViewEx
android:id="@android:id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:fadingEdge="horizontal"
android:singleLine="true"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_regular" />
<net.osmand.plus.widgets.TextViewEx
android:id="@android:id/summary"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:letterSpacing="@dimen/description_letter_spacing"
android:maxLines="4"
android:textColor="?android:textColorSecondary"
android:textSize="@dimen/default_desc_text_size"
osmand:typeface="@string/font_roboto_regular" />
</LinearLayout>
<android.support.v7.widget.SwitchCompat
android:id="@+id/switchWidget"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@null"
android:clickable="false"
android:focusable="false"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding" />
</LinearLayout>
</LinearLayout>

View file

@ -0,0 +1,46 @@
<?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/toolbar_switch_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/list_background_color"
android:orientation="vertical">
<LinearLayout
android:id="@+id/selectable_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:minHeight="@dimen/toolbar_height">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/switchButtonText"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/toolbar_height"
android:layout_marginLeft="@dimen/toolbar_height"
android:layout_weight="1"
android:gravity="center_vertical"
android:letterSpacing="@dimen/title_letter_spacing"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:textColor="?attr/text_color_tab_active"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:text="@string/shared_string_off" />
<android.support.v7.widget.SwitchCompat
android:id="@+id/switchWidget"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@null"
android:clickable="false"
android:focusable="false"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding" />
</LinearLayout>
</LinearLayout>

View file

@ -53,47 +53,7 @@
</LinearLayout> </LinearLayout>
<LinearLayout <include layout="@layout/preference_toolbar_switch" />
android:id="@+id/toolbar_switch_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/list_background_color">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:minHeight="@dimen/toolbar_height">
<net.osmand.plus.widgets.TextViewEx
android:id="@+id/switchButtonText"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginStart="@dimen/toolbar_height"
android:layout_marginLeft="@dimen/toolbar_height"
android:layout_weight="1"
android:gravity="center_vertical"
android:letterSpacing="@dimen/title_letter_spacing"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding"
android:textColor="?attr/text_color_tab_active"
android:textSize="@dimen/default_list_text_size"
osmand:typeface="@string/font_roboto_medium"
tools:text="@string/shared_string_off" />
<android.support.v7.widget.SwitchCompat
android:id="@+id/switchWidget"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="@null"
android:clickable="false"
android:focusable="false"
android:paddingLeft="@dimen/content_padding"
android:paddingRight="@dimen/content_padding" />
</LinearLayout>
</LinearLayout>
</LinearLayout> </LinearLayout>

View file

@ -84,7 +84,7 @@
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:key="do_not_use_animations" android:key="do_not_use_animations"
android:layout="@layout/preference_switch" android:layout="@layout/preference_switch_with_descr"
android:summaryOff="@string/shared_string_off" android:summaryOff="@string/shared_string_off"
android:summaryOn="@string/shared_string_on" android:summaryOn="@string/shared_string_on"
android:title="@string/do_not_use_animations" /> android:title="@string/do_not_use_animations" />

View file

@ -34,7 +34,7 @@
<net.osmand.plus.settings.preferences.SwitchPreferenceEx <net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:icon="@drawable/ic_action_privacy_and_security" android:icon="@drawable/ic_action_privacy_and_security"
android:key="send_anonymous_data" android:key="send_anonymous_data"
android:layout="@layout/preference_dialog_and_switch" android:layout="@layout/preference_with_descr_dialog_and_switch"
android:persistent="false" android:persistent="false"
android:summaryOff="@string/shared_string_off" android:summaryOff="@string/shared_string_off"
android:summaryOn="@string/shared_string_on" android:summaryOn="@string/shared_string_on"
@ -43,14 +43,14 @@
<SwitchPreferenceCompat <SwitchPreferenceCompat
android:icon="@drawable/ic_action_notification" android:icon="@drawable/ic_action_notification"
android:key="do_not_show_startup_messages" android:key="do_not_show_startup_messages"
android:layout="@layout/preference_switch" android:layout="@layout/preference_switch_with_descr"
android:summaryOff="@string/shared_string_off" android:summaryOff="@string/shared_string_off"
android:summaryOn="@string/shared_string_on" android:summaryOn="@string/shared_string_on"
android:title="@string/start_up_message_pref" /> android:title="@string/start_up_message_pref" />
<net.osmand.plus.settings.preferences.SwitchPreferenceEx <net.osmand.plus.settings.preferences.SwitchPreferenceEx
android:key="enable_proxy" android:key="enable_proxy"
android:layout="@layout/preference_dialog_and_switch" android:layout="@layout/preference_with_descr_dialog_and_switch"
android:summaryOff="@string/shared_string_off" android:summaryOff="@string/shared_string_off"
android:summaryOn="@string/shared_string_on" android:summaryOn="@string/shared_string_on"
android:title="@string/proxy_pref_title" android:title="@string/proxy_pref_title"

View file

@ -5,11 +5,6 @@
android:key="proxy" android:key="proxy"
android:title="@string/proxy_pref_title"> android:title="@string/proxy_pref_title">
<SwitchPreferenceCompat
android:key="enable_proxy"
android:summaryOff="@string/shared_string_off"
android:summaryOn="@string/shared_string_on" />
<Preference <Preference
android:key="proxy_preferences_info" android:key="proxy_preferences_info"
android:layout="@layout/preference_info" android:layout="@layout/preference_info"
@ -19,14 +14,14 @@
tools:icon="@drawable/ic_action_info_dark" /> tools:icon="@drawable/ic_action_info_dark" />
<net.osmand.plus.settings.preferences.EditTextPreferenceEx <net.osmand.plus.settings.preferences.EditTextPreferenceEx
android:dependency="enable_proxy"
android:key="proxy_host" android:key="proxy_host"
android:layout="@layout/preference_with_descr"
android:summary="@string/proxy_host_descr" android:summary="@string/proxy_host_descr"
android:title="@string/proxy_host_title" /> android:title="@string/proxy_host_title" />
<net.osmand.plus.settings.preferences.EditTextPreferenceEx <net.osmand.plus.settings.preferences.EditTextPreferenceEx
android:dependency="enable_proxy"
android:key="proxy_port" android:key="proxy_port"
android:layout="@layout/preference_with_descr"
android:summary="@string/proxy_port_descr" android:summary="@string/proxy_port_descr"
android:title="@string/proxy_port_title" /> android:title="@string/proxy_port_title" />

View file

@ -1,10 +1,18 @@
package net.osmand.plus.settings; package net.osmand.plus.settings;
import android.graphics.drawable.Drawable;
import android.support.v4.content.ContextCompat;
import android.support.v7.preference.Preference; import android.support.v7.preference.Preference;
import android.support.v7.widget.SwitchCompat;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import net.osmand.AndroidUtils;
import net.osmand.osm.io.NetworkUtils; import net.osmand.osm.io.NetworkUtils;
import net.osmand.plus.R; import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.settings.preferences.EditTextPreferenceEx; import net.osmand.plus.settings.preferences.EditTextPreferenceEx;
import static net.osmand.plus.activities.SettingsGeneralActivity.IP_ADDRESS_PATTERN; import static net.osmand.plus.activities.SettingsGeneralActivity.IP_ADDRESS_PATTERN;
@ -25,7 +33,7 @@ public class ProxySettingsFragment extends BaseSettingsFragment {
@Override @Override
protected int getToolbarResId() { protected int getToolbarResId() {
return R.layout.global_preference_toolbar; return R.layout.global_preferences_toolbar_with_switch;
} }
@Override @Override
@ -47,6 +55,48 @@ public class ProxySettingsFragment extends BaseSettingsFragment {
setupProxyPortPref(); setupProxyPortPref();
} }
@Override
protected void createToolbar(LayoutInflater inflater, View view) {
super.createToolbar(inflater, view);
view.findViewById(R.id.toolbar_switch_container).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
boolean checked = !settings.ENABLE_PROXY.get();
settings.ENABLE_PROXY.set(checked);
updateToolbarSwitch();
enableDisablePreferences(checked);
}
});
TextView title = (TextView) view.findViewById(R.id.switchButtonText);
title.setTextColor(ContextCompat.getColor(app, isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
}
@Override
protected void updateToolbar() {
super.updateToolbar();
updateToolbarSwitch();
}
private void updateToolbarSwitch() {
View view = getView();
if (view == null) {
return;
}
boolean checked = settings.ENABLE_PROXY.get();
View selectableView = view.findViewById(R.id.selectable_item);
SwitchCompat switchView = (SwitchCompat) selectableView.findViewById(R.id.switchWidget);
switchView.setChecked(checked);
TextView title = (TextView) selectableView.findViewById(R.id.switchButtonText);
title.setText(checked ? R.string.shared_string_on : R.string.shared_string_off);
Drawable drawable = UiUtilities.getColoredSelectableDrawable(app, getActiveProfileColor(), 0.3f);
AndroidUtils.setBackground(selectableView, drawable);
}
private void setupProxyHostPref() { private void setupProxyHostPref() {
EditTextPreferenceEx hostPref = (EditTextPreferenceEx) findPreference(settings.PROXY_HOST.getId()); EditTextPreferenceEx hostPref = (EditTextPreferenceEx) findPreference(settings.PROXY_HOST.getId());
hostPref.setPersistent(false); hostPref.setPersistent(false);

View file

@ -221,7 +221,7 @@ public class VoiceAnnouncesFragment extends BaseSettingsFragment {
} }
private void setupInterruptMusicPref() { private void setupInterruptMusicPref() {
Preference interruptMusicPref = createSwitchPreference(settings.INTERRUPT_MUSIC, R.string.interrupt_music, R.string.interrupt_music_descr, R.layout.preference_switch); Preference interruptMusicPref = createSwitchPreference(settings.INTERRUPT_MUSIC, R.string.interrupt_music, R.string.interrupt_music_descr, R.layout.preference_switch_with_descr);
interruptMusicPref.setIconSpaceReserved(true); interruptMusicPref.setIconSpaceReserved(true);
getPreferenceScreen().addPreference(interruptMusicPref); getPreferenceScreen().addPreference(interruptMusicPref);
} }