Add profile appearance incomplete
This commit is contained in:
parent
c93859b117
commit
c3c65068e1
14 changed files with 456 additions and 39 deletions
42
OsmAnd/res/layout/preference_cancel_save_button.xml
Normal file
42
OsmAnd/res/layout/preference_cancel_save_button.xml
Normal file
|
@ -0,0 +1,42 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:id="@+id/buttons_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="?attr/bg_color"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<Button
|
||||
android:id="@+id/cancel_button"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="42dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginTop="@dimen/list_content_padding"
|
||||
android:layout_marginBottom="@dimen/list_content_padding"
|
||||
android:layout_marginStart="@dimen/list_content_padding"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginLeft="@dimen/list_content_padding"
|
||||
android:layout_marginRight="8dp"
|
||||
android:background="?attr/profile_cancel_btn"
|
||||
android:text="@string/shared_string_cancel"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="?attr/active_color_basic"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/save_profile_btn"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="42dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_marginTop="@dimen/list_content_padding"
|
||||
android:layout_marginBottom="@dimen/list_content_padding"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="@dimen/list_content_padding"
|
||||
android:layout_marginLeft="8dp"
|
||||
android:layout_marginRight="@dimen/list_content_padding"
|
||||
android:background="?attr/profile_save_btn"
|
||||
android:text="@string/shared_string_save"
|
||||
android:textAllCaps="false"
|
||||
android:textColor="@color/color_white"/>
|
||||
|
||||
</LinearLayout>
|
54
OsmAnd/res/layout/preference_dropdown_list.xml
Normal file
54
OsmAnd/res/layout/preference_dropdown_list.xml
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?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"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<FrameLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/list_header_top_margin"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginStart="@dimen/list_content_padding"
|
||||
android:layout_marginEnd="@dimen/list_content_padding"
|
||||
android:layout_marginLeft="@dimen/list_content_padding"
|
||||
android:layout_marginRight="@dimen/list_content_padding">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/type_down_arrow"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical|right"
|
||||
android:paddingRight="@dimen/content_padding"
|
||||
android:src="@drawable/ic_action_arrow_drop_down"
|
||||
android:tint="@color/settings_divider"/>
|
||||
|
||||
<net.osmand.plus.widgets.OsmandTextFieldBoxes
|
||||
android:id="@+id/navigation_type_otfb"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="60dp"
|
||||
app:primaryColor="@color/active_color_primary_dark"
|
||||
app:secondaryColor="?android:textColorSecondary"
|
||||
app:labelText="@string/nav_type_hint">
|
||||
|
||||
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
|
||||
android:id="@+id/navigation_type_et"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:focusable="false"
|
||||
android:maxLines="1"
|
||||
|
||||
tools:text="Car"/>
|
||||
|
||||
</net.osmand.plus.widgets.OsmandTextFieldBoxes>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/select_nav_type_btn"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:clickable="true"
|
||||
android:focusable="true"/>
|
||||
|
||||
</FrameLayout>
|
||||
</LinearLayout>
|
29
OsmAnd/res/layout/preference_text_field.xml
Normal file
29
OsmAnd/res/layout/preference_text_field.xml
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?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:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_vertical"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<net.osmand.plus.widgets.OsmandTextFieldBoxes
|
||||
android:id="@+id/profile_name_otfb"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="60dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_margin="@dimen/list_content_padding"
|
||||
app:primaryColor="@color/active_color_primary_dark"
|
||||
app:secondaryColor="?android:textColorSecondary"
|
||||
app:labelText="@string/profile_name_hint">
|
||||
|
||||
<studio.carbonylgroup.textfieldboxes.ExtendedEditText
|
||||
android:id="@+id/profile_name_et"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:maxLines="1"
|
||||
|
||||
tools:text="@string/lorem_ipsum"/>
|
||||
|
||||
</net.osmand.plus.widgets.OsmandTextFieldBoxes>
|
||||
</LinearLayout>
|
|
@ -10,7 +10,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<LinearLayout
|
||||
<FrameLayout
|
||||
android:id="@android:id/list_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
|
|
|
@ -37,6 +37,14 @@
|
|||
android:textSize="@dimen/dialog_header_text_size"
|
||||
osmand:typeface="@string/font_roboto_medium"
|
||||
tools:text="@string/routing_settings_2" />
|
||||
|
||||
<include
|
||||
layout="@layout/profile_button_small"
|
||||
android:layout_width="@dimen/route_info_toolbar_button_size"
|
||||
android:layout_height="@dimen/route_info_toolbar_button_size"
|
||||
android:layout_marginLeft="@dimen/content_padding_half"
|
||||
android:layout_marginRight="@dimen/content_padding_half" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
</android.support.v7.widget.Toolbar>
|
|
@ -11,7 +11,9 @@
|
|||
Thx - Hardy
|
||||
|
||||
-->
|
||||
<string name="delete_profiles_descr">After you tap Apply, deleted profiles will be lost completely.</string>
|
||||
<string name="delete_profiles_descr">After you tap Apply, deleted profiles will be lost completely.</string>
|
||||
<string name="master_profile">Master profile</string>
|
||||
<string name="select_color">Select color</string>
|
||||
<string name="shared_string_downloading_formatted">Downloading %s</string>
|
||||
<string name="edit_profiles_descr">You can’t delete default OsmAnd profiles, but you can disable them in previous screen, or move them to the bottom.</string>
|
||||
<string name="edit_profiles">Edit profiles</string>
|
||||
|
|
72
OsmAnd/res/xml/profile_appeariance.xml
Normal file
72
OsmAnd/res/xml/profile_appeariance.xml
Normal file
|
@ -0,0 +1,72 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:title="@string/profile_appearance">
|
||||
|
||||
<Preference
|
||||
android:key="master_profile"
|
||||
android:layout="@layout/preference_dropdown_list"
|
||||
android:title="@string/profile_name_hint" />
|
||||
|
||||
<Preference
|
||||
android:key="profile_name"
|
||||
android:layout="@layout/preference_text_field"
|
||||
android:title="@string/profile_name_hint" />
|
||||
|
||||
<Preference
|
||||
android:layout="@layout/simple_divider_item"
|
||||
android:selectable="false" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="select_color"
|
||||
android:layout="@layout/preference_category_with_descr"
|
||||
android:title="@string/select_color" />
|
||||
|
||||
<Preference
|
||||
android:key="color_items"
|
||||
android:layout="@layout/preference_with_descr"
|
||||
android:title="@string/select_color" />
|
||||
|
||||
<Preference
|
||||
android:layout="@layout/simple_divider_item"
|
||||
android:selectable="false" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="select_icon"
|
||||
android:layout="@layout/preference_category_with_descr"
|
||||
android:title="@string/select_icon_profile_dialog_title" />
|
||||
|
||||
<Preference
|
||||
android:key="icon_items"
|
||||
android:layout="@layout/preference_with_descr"
|
||||
android:title="@string/select_icon_profile_dialog_title" />
|
||||
|
||||
<Preference
|
||||
android:layout="@layout/simple_divider_item"
|
||||
android:selectable="false" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="select_map_icon"
|
||||
android:layout="@layout/preference_category_with_descr"
|
||||
android:title="@string/map_during_navigation" />
|
||||
|
||||
<Preference
|
||||
android:key="map_icon_items"
|
||||
android:layout="@layout/preference_with_descr"
|
||||
android:title="@string/map_during_navigation" />
|
||||
|
||||
<Preference
|
||||
android:layout="@layout/simple_divider_item"
|
||||
android:selectable="false" />
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="select_nav_icon"
|
||||
android:layout="@layout/preference_category_with_descr"
|
||||
android:title="@string/map_during_navigation" />
|
||||
|
||||
<Preference
|
||||
android:key="nav_icon_items"
|
||||
android:layout="@layout/preference_with_descr"
|
||||
android:title="@string/map_during_navigation" />
|
||||
|
||||
</PreferenceScreen>
|
|
@ -852,7 +852,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
|
|||
}
|
||||
}
|
||||
|
||||
private class ApplicationProfileObject {
|
||||
class ApplicationProfileObject {
|
||||
|
||||
int stringKeyName = -1;
|
||||
String stringKey;
|
||||
|
|
|
@ -18,6 +18,7 @@ import net.osmand.plus.base.bottomsheetmenu.BottomSheetItemWithCompoundButton;
|
|||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.LongDescriptionItem;
|
||||
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
|
||||
import net.osmand.plus.settings.NavigationFragment;
|
||||
import net.osmand.plus.settings.ProfileAppearanceFragment;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
|
@ -225,6 +226,7 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
|
|||
EditProfileFragment editProfileFragment = (EditProfileFragment) fragmentManager.findFragmentByTag(EditProfileFragment.TAG);
|
||||
SettingsProfileFragment settingsProfileFragment = (SettingsProfileFragment) fragmentManager.findFragmentByTag(SettingsProfileFragment.class.getName());
|
||||
NavigationFragment navigationFragment = (NavigationFragment) fragmentManager.findFragmentByTag(NavigationFragment.class.getName());
|
||||
ProfileAppearanceFragment profileAppearanceFragment = (ProfileAppearanceFragment) fragmentManager.findFragmentByTag(ProfileAppearanceFragment.class.getName());
|
||||
|
||||
if (editProfileFragment != null) {
|
||||
switch (type) {
|
||||
|
@ -243,7 +245,9 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
|
|||
listener = settingsProfileFragment.getBaseProfileListener();
|
||||
} else if (navigationFragment != null) {
|
||||
listener = navigationFragment.getNavProfileListener();
|
||||
}
|
||||
} else if (profileAppearanceFragment != null) {
|
||||
listener = profileAppearanceFragment.getParentProfileListener();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -170,7 +170,7 @@ public class SettingsProfileFragment extends BaseOsmAndFragment
|
|||
return typeListener;
|
||||
}
|
||||
|
||||
static List<ProfileDataObject> getBaseProfiles(Context ctx) {
|
||||
public static List<ProfileDataObject> getBaseProfiles(Context ctx) {
|
||||
List<ProfileDataObject> profiles = new ArrayList<>();
|
||||
for (ApplicationMode mode : ApplicationMode.getDefaultValues()) {
|
||||
if (mode != ApplicationMode.DEFAULT) {
|
||||
|
|
|
@ -97,7 +97,8 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
|
|||
MAP_DURING_NAVIGATION(MapDuringNavigationFragment.class.getName(), true, R.xml.map_during_navigation, R.layout.profile_preference_toolbar),
|
||||
TURN_SCREEN_ON(TurnScreenOnFragment.class.getName(), true, R.xml.turn_screen_on, R.layout.profile_preference_toolbar_with_switch),
|
||||
DATA_STORAGE(DataStorageFragment.class.getName(), false, R.xml.data_storage, R.layout.global_preference_toolbar),
|
||||
DIALOGS_AND_NOTIFICATIONS_SETTINGS(DialogsAndNotificationsSettingsFragment.class.getName(), false, R.xml.dialogs_and_notifications_preferences, R.layout.global_preferences_toolbar_with_switch);
|
||||
DIALOGS_AND_NOTIFICATIONS_SETTINGS(DialogsAndNotificationsSettingsFragment.class.getName(), false, R.xml.dialogs_and_notifications_preferences, R.layout.global_preferences_toolbar_with_switch),
|
||||
PROFILE_APPEARANCE(ProfileAppearanceFragment.class.getName(), true, R.xml.profile_appeariance, R.layout.profile_preference_toolbar);
|
||||
|
||||
public final String fragmentName;
|
||||
public final boolean profileDependent;
|
||||
|
|
|
@ -41,7 +41,6 @@ import net.osmand.plus.activities.MapActivity;
|
|||
import net.osmand.plus.activities.PluginActivity;
|
||||
import net.osmand.plus.helpers.FontCache;
|
||||
import net.osmand.plus.openseamapsplugin.NauticalMapsPlugin;
|
||||
import net.osmand.plus.profiles.EditProfileFragment;
|
||||
import net.osmand.plus.settings.preferences.SwitchPreferenceEx;
|
||||
import net.osmand.plus.skimapsplugin.SkiMapsPlugin;
|
||||
|
||||
|
@ -67,7 +66,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
|
|||
private static final String CONFIGURE_MAP = "configure_map";
|
||||
private static final String CONFIGURE_SCREEN = "configure_screen";
|
||||
private static final String EXPORT_PROFILE = "export_profile";
|
||||
private static final String PROFILE_APPEARANCE = "profile_appearance";
|
||||
private static final String PROFILE_APPEARANCE = "profile_appearance";
|
||||
|
||||
@ColorRes
|
||||
protected int getBackgroundColorRes() {
|
||||
|
@ -99,25 +98,20 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
|
|||
toolbarSubtitle.setText(R.string.configure_profile);
|
||||
toolbarSubtitle.setVisibility(View.VISIBLE);
|
||||
|
||||
if (!getSelectedAppMode().equals(ApplicationMode.DEFAULT)) {
|
||||
view.findViewById(R.id.toolbar_switch_container).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
ApplicationMode selectedMode = getSelectedAppMode();
|
||||
List<ApplicationMode> availableAppModes = ApplicationMode.values(getMyApplication());
|
||||
boolean isChecked = availableAppModes.contains(selectedMode);
|
||||
if (!isChecked) {
|
||||
availableAppModes.add(selectedMode);
|
||||
} else {
|
||||
availableAppModes.remove(selectedMode);
|
||||
}
|
||||
ApplicationMode.changeProfileAvailability(selectedMode, !isChecked, getMyApplication());
|
||||
updateToolbarSwitch();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
view.findViewById(R.id.switchWidget).setVisibility(View.GONE);
|
||||
}
|
||||
if (!getSelectedAppMode().equals(ApplicationMode.DEFAULT)) {
|
||||
view.findViewById(R.id.toolbar_switch_container).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
ApplicationMode selectedMode = getSelectedAppMode();
|
||||
List<ApplicationMode> availableAppModes = ApplicationMode.values(getMyApplication());
|
||||
boolean isChecked = availableAppModes.contains(selectedMode);
|
||||
ApplicationMode.changeProfileAvailability(selectedMode, !isChecked, getMyApplication());
|
||||
updateToolbarSwitch();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
view.findViewById(R.id.switchWidget).setVisibility(View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateToolbarSwitch() {
|
||||
|
@ -198,7 +192,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
|
|||
setupNavigationSettingsPref();
|
||||
setupConfigureMapPref();
|
||||
setupConfigureScreenPref();
|
||||
setupProfileAppearancePref();
|
||||
setupProfileAppearancePref();
|
||||
|
||||
PreferenceCategory pluginSettings = (PreferenceCategory) findPreference(PLUGIN_SETTINGS);
|
||||
pluginSettings.setIconSpaceReserved(false);
|
||||
|
@ -246,15 +240,15 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
|
|||
configureMap.setIntent(intent);
|
||||
}
|
||||
|
||||
private void setupProfileAppearancePref() {
|
||||
Context ctx = getContext();
|
||||
if (ctx == null) {
|
||||
return;
|
||||
}
|
||||
Preference configureMap = findPreference(PROFILE_APPEARANCE);
|
||||
configureMap.setIcon(getContentIcon(R.drawable.ic_action_offroad));
|
||||
configureMap.setFragment(EditProfileFragment.class.getName());
|
||||
}
|
||||
private void setupProfileAppearancePref() {
|
||||
Context ctx = getContext();
|
||||
if (ctx == null) {
|
||||
return;
|
||||
}
|
||||
Preference configureMap = findPreference(PROFILE_APPEARANCE);
|
||||
configureMap.setIcon(getContentIcon(getSelectedAppMode().getIconRes()));
|
||||
configureMap.setFragment(ProfileAppearanceFragment.class.getName());
|
||||
}
|
||||
|
||||
private void setupExportProfilePref() {
|
||||
Preference exportProfile = findPreference(EXPORT_PROFILE);
|
||||
|
|
|
@ -3,6 +3,8 @@ package net.osmand.plus.settings;
|
|||
import android.os.Bundle;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.SwitchPreferenceCompat;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.R;
|
||||
|
@ -24,6 +26,7 @@ import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TY
|
|||
public class NavigationFragment extends BaseSettingsFragment {
|
||||
|
||||
public static final String TAG = NavigationFragment.class.getSimpleName();
|
||||
public static final String NAVIGATION_TYPE = "navigation_type";
|
||||
private SelectProfileBottomSheetDialogFragment.SelectProfileListener navTypeListener;
|
||||
List<RoutingProfileDataObject> routingProfileDataObjects;
|
||||
private Preference navigationType;
|
||||
|
@ -34,9 +37,15 @@ public class NavigationFragment extends BaseSettingsFragment {
|
|||
routingProfileDataObjects = EditProfileFragment.getRoutingProfiles(app);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createToolbar(LayoutInflater inflater, View view) {
|
||||
super.createToolbar(inflater, view);
|
||||
view.findViewById(R.id.profile_button).setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupPreferences() {
|
||||
navigationType = findPreference("navigation_type");
|
||||
navigationType = findPreference(NAVIGATION_TYPE);
|
||||
Preference routeParameters = findPreference("route_parameters");
|
||||
SwitchPreferenceCompat showRoutingAlarms = (SwitchPreferenceCompat) findPreference(settings.SHOW_ROUTING_ALARMS.getId());
|
||||
SwitchPreferenceCompat speakRoutingAlarms = (SwitchPreferenceCompat) findPreference(settings.VOICE_MUTE.getId());
|
||||
|
@ -71,7 +80,7 @@ public class NavigationFragment extends BaseSettingsFragment {
|
|||
|
||||
@Override
|
||||
public boolean onPreferenceClick(Preference preference) {
|
||||
if (preference.getKey().equals("navigation_type")) {
|
||||
if (preference.getKey().equals(NAVIGATION_TYPE)) {
|
||||
final SelectProfileBottomSheetDialogFragment dialog = new SelectProfileBottomSheetDialogFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
if (getSelectedAppMode() != null) {
|
||||
|
|
|
@ -0,0 +1,202 @@
|
|||
package net.osmand.plus.settings;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceCategory;
|
||||
import android.support.v7.preference.PreferenceViewHolder;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import net.osmand.plus.ApplicationMode;
|
||||
import net.osmand.plus.R;
|
||||
import net.osmand.plus.UiUtilities;
|
||||
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment;
|
||||
import net.osmand.plus.profiles.SettingsProfileFragment;
|
||||
import net.osmand.plus.widgets.OsmandTextFieldBoxes;
|
||||
import net.osmand.util.Algorithms;
|
||||
|
||||
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.DIALOG_TYPE;
|
||||
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SELECTED_KEY;
|
||||
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_BASE_APP_PROFILE;
|
||||
|
||||
public class ProfileAppearanceFragment extends BaseSettingsFragment {
|
||||
|
||||
private static final String MASTER_PROFILE = "master_profile";
|
||||
private static final String PROFILE_NAME = "profile_name";
|
||||
private static final String SELECT_COLOR = "select_color";
|
||||
private static final String SELECT_ICON = "select_icon";
|
||||
private SelectProfileBottomSheetDialogFragment.SelectProfileListener parentProfileListener;
|
||||
private EditText baseProfileName;
|
||||
private ApplicationProfileObject profile;
|
||||
private ApplicationProfileObject changedProfile;
|
||||
private Button cancelButton;
|
||||
private Button saveButton;
|
||||
private EditText profileName;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (savedInstanceState != null) {
|
||||
profile.parent = getSelectedAppMode().getParent();
|
||||
} else {
|
||||
profile = new ApplicationProfileObject();
|
||||
profile.parent = getSelectedAppMode().getParent();
|
||||
profile.name = "";
|
||||
changedProfile = new ApplicationProfileObject();
|
||||
changedProfile.parent = profile.parent;
|
||||
changedProfile.name = profile.name;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setupPreferences() {
|
||||
PreferenceCategory selectColor = (PreferenceCategory) findPreference(SELECT_COLOR);
|
||||
selectColor.setIconSpaceReserved(false);
|
||||
PreferenceCategory selectIcon = (PreferenceCategory) findPreference(SELECT_ICON);
|
||||
selectIcon.setIconSpaceReserved(false);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@SuppressLint("InlinedApi")
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
View view = super.onCreateView(inflater, container, savedInstanceState);
|
||||
if (view != null) {
|
||||
FrameLayout frameLayout = view.findViewById(android.R.id.list_container);
|
||||
View inflatedLayout = UiUtilities.getInflater(getContext(), isNightMode())
|
||||
.inflate(R.layout.preference_cancel_save_button, frameLayout, false);
|
||||
(frameLayout).addView(inflatedLayout);
|
||||
cancelButton=inflatedLayout.findViewById(R.id.cancel_button);
|
||||
saveButton=inflatedLayout.findViewById(R.id.save_profile_btn);
|
||||
cancelButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (getActivity() != null) {
|
||||
getActivity().onBackPressed();
|
||||
}
|
||||
}
|
||||
});
|
||||
saveButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (getActivity() != null) {
|
||||
getActivity().onBackPressed();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void createToolbar(LayoutInflater inflater, View view) {
|
||||
super.createToolbar(inflater, view);
|
||||
View profileIcon = view.findViewById(R.id.profile_button);
|
||||
profileIcon.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBindPreferenceViewHolder(Preference preference, PreferenceViewHolder holder) {
|
||||
super.onBindPreferenceViewHolder(preference, holder);
|
||||
if (PROFILE_NAME.equals(preference.getKey())) {
|
||||
profileName = (EditText) holder.findViewById(R.id.profile_name_et);
|
||||
profileName.setText(getSelectedAppMode().toHumanString(getContext()));
|
||||
|
||||
profileName.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count, int after) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
profile.name = s.toString();
|
||||
}
|
||||
});
|
||||
} else if (MASTER_PROFILE.equals(preference.getKey())) {
|
||||
baseProfileName = (EditText) holder.findViewById(R.id.navigation_type_et);
|
||||
baseProfileName.setText(getSelectedAppMode().getParent() != null ? getSelectedAppMode().getParent().toHumanString(getContext()) : getSelectedAppMode().toHumanString(getContext()));
|
||||
OsmandTextFieldBoxes baseProfileNameHint = (OsmandTextFieldBoxes) holder.findViewById(R.id.navigation_type_otfb);
|
||||
baseProfileNameHint.setLabelText(getString(R.string.master_profile));
|
||||
FrameLayout selectNavTypeBtn = (FrameLayout) holder.findViewById(R.id.select_nav_type_btn);
|
||||
selectNavTypeBtn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
if (getSelectedAppMode().isCustomProfile()) {
|
||||
hideKeyboard();
|
||||
final SelectProfileBottomSheetDialogFragment fragment = new SelectProfileBottomSheetDialogFragment();
|
||||
Bundle bundle = new Bundle();
|
||||
if (getSelectedAppMode() != null) {
|
||||
bundle.putString(SELECTED_KEY, getSelectedAppMode().getRoutingProfile());
|
||||
}
|
||||
bundle.putString(DIALOG_TYPE, TYPE_BASE_APP_PROFILE);
|
||||
fragment.setArguments(bundle);
|
||||
if (getActivity() != null) {
|
||||
getActivity().getSupportFragmentManager().beginTransaction()
|
||||
.add(fragment, "select_nav_type").commitAllowingStateLoss();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void hideKeyboard() {
|
||||
Activity activity = getActivity();
|
||||
if (activity != null) {
|
||||
View cf = activity.getCurrentFocus();
|
||||
if (cf != null) {
|
||||
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
if (imm != null) {
|
||||
imm.hideSoftInputFromWindow(cf.getWindowToken(), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public SelectProfileBottomSheetDialogFragment.SelectProfileListener getParentProfileListener() {
|
||||
if (parentProfileListener == null) {
|
||||
parentProfileListener = new SelectProfileBottomSheetDialogFragment.SelectProfileListener() {
|
||||
@Override
|
||||
public void onSelectedType(int pos, String stringRes) {
|
||||
updateParentProfile(pos);
|
||||
}
|
||||
};
|
||||
}
|
||||
return parentProfileListener;
|
||||
}
|
||||
|
||||
void updateParentProfile(int pos) {
|
||||
|
||||
String key = SettingsProfileFragment.getBaseProfiles(getMyApplication()).get(pos).getStringKey();
|
||||
setupBaseProfileView(key);
|
||||
profile.parent = ApplicationMode.valueOfStringKey(key, ApplicationMode.DEFAULT);
|
||||
}
|
||||
|
||||
private void setupBaseProfileView(String stringKey) {
|
||||
for (ApplicationMode am : ApplicationMode.getDefaultValues()) {
|
||||
if (am.getStringKey().equals(stringKey)) {
|
||||
baseProfileName.setText(Algorithms.capitalizeFirstLetter(am.toHumanString(app)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ApplicationProfileObject {
|
||||
ApplicationMode parent = null;
|
||||
String name;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue