saving app mode changes - work in progress

This commit is contained in:
madwasp79 2019-04-11 18:16:05 +03:00
parent 6c6ec759f1
commit 8682f688ff
8 changed files with 494 additions and 147 deletions

View file

@ -1,24 +1,22 @@
<?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:orientation="vertical"
android:background="?attr/bg_color">
android:background="?attr/bg_color"
android:orientation="vertical">
<TextView
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="?attr/main_font_color_basic"
android:textSize="@dimen/default_list_text_size"
android:textStyle="bold"
android:layout_marginLeft="@dimen/list_content_padding"
android:layout_marginStart="@dimen/list_content_padding"
android:layout_marginTop="@dimen/list_content_padding"
android:layout_marginBottom="@dimen/list_content_padding"
android:text="Select navigation type"/>
android:layout_marginStart="@dimen/list_content_padding"
android:layout_marginLeft="@dimen/list_content_padding"
android:text="Select navigation type"
android:textColor="?attr/main_font_color_basic"
android:textSize="@dimen/default_list_text_size"/>
<android.support.v7.widget.RecyclerView
@ -29,7 +27,7 @@
</android.support.v7.widget.RecyclerView>
<View
<View
android:id="@+id/bottom_row_divider"
android:layout_width="match_parent"
android:layout_height="1dp"
@ -38,9 +36,26 @@
<LinearLayout
android:id="@+id/buttons_container"
android:layout_width="match_parent"
android:layout_height="@dimen/bottom_sheet_cancel_button_height"
android:orientation="horizontal">
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
>
<Button
android:id="@+id/cancel_selection"
android:layout_width="0dp"
android:layout_height="@dimen/bottom_sheet_cancel_button_height"
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="@dimen/list_content_padding"
android:layout_marginLeft="@dimen/list_content_padding"
android:layout_marginRight="@dimen/list_content_padding"
android:background="@drawable/btn_right_round"
android:text="@string/shared_string_cancel"
android:textAllCaps="false"
android:textColor="@color/map_widget_blue"/>
</LinearLayout>

View file

@ -42,7 +42,6 @@
android:layout_marginLeft="@dimen/list_content_padding"
android:clickable="true"
android:focusable="true"
android:gravity="center"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
@ -350,6 +349,7 @@
android:background="?attr/bg_color">
<Button
android:id="@+id/cancel_button"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
@ -365,6 +365,7 @@
android:textColor="@color/map_widget_blue"/>
<Button
android:id="@+id/save_profile_btn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"

View file

@ -36,12 +36,12 @@ public class ApplicationMode {
public static final ApplicationMode PUBLIC_TRANSPORT = create(R.string.app_mode_public_transport, "public_transport").
icon(R.drawable.map_action_bus_dark, R.drawable.ic_action_bus_dark).reg();
public static final ApplicationMode BOAT = create(R.string.app_mode_boat, "boat").speed(5.5f, 20).carLocation().nauticalLocation().
public static final ApplicationMode BOAT = create(R.string.app_mode_boat, "boat").speed(5.5f, 20).nauticalLocation().
icon(R.drawable.map_action_sail_boat_dark, R.drawable.ic_action_sail_boat_dark).reg();
public static final ApplicationMode AIRCRAFT = create(R.string.app_mode_aircraft, "aircraft").speed(40f, 100).carLocation().
icon(R.drawable.map_action_aircraft, R.drawable.ic_action_aircraft).reg();
//---------------------------------------------------------------------------------------------------------------
public static final ApplicationMode HIKING = create(R.string.app_mode_hiking, "hiking").speed(1.5f, 5).parent(PEDESTRIAN).
icon(R.drawable.map_action_trekking_dark, R.drawable.ic_action_trekking_dark).reg();
@ -102,7 +102,7 @@ public class ApplicationMode {
private static class ApplicationModeBuilder {
public static class ApplicationModeBuilder {
private ApplicationMode applicationMode;
@ -192,8 +192,8 @@ public class ApplicationMode {
return builder;
}
public static ApplicationModeBuilder createCustomMode(int key, String stringKey) {
return create(key, stringKey);
public static ApplicationModeBuilder createCustomMode(String userProfileTitle, String stringKey) {
return create(-1, stringKey);
}
private ApplicationMode(int key, String stringKey) {
@ -400,13 +400,29 @@ public class ApplicationMode {
return offRouteDistance;
}
public void setUserProfileTitle(String userProfileTitle) {
this.userProfileTitle = userProfileTitle;
}
public void setMapIconId(int mapIconId) {
this.mapIconId = mapIconId;
}
public void setSmallIconDark(int smallIconDark) {
this.smallIconDark = smallIconDark;
}
public boolean isDerivedRoutingFrom(ApplicationMode mode) {
return this == mode || getParent() == mode;
}
public String getUserProfileTitle() {
return userProfileTitle;
}
private final int key;
private final String stringKey;
private String userName;
private String userProfileTitle = "";
private ApplicationMode parent;
private int mapIconId = R.drawable.map_world_globe_dark;
private int smallIconDark = R.drawable.ic_world_globe_dark;

View file

@ -79,6 +79,7 @@ import net.osmand.plus.base.FailSafeFuntions;
import net.osmand.plus.base.MapViewTrackingUtilities;
import net.osmand.plus.chooseplan.OsmLiveCancelledDialog;
import net.osmand.plus.dashboard.DashboardOnMap;
import net.osmand.plus.dashboard.DashboardOnMap.DashboardType;
import net.osmand.plus.dialogs.ErrorBottomSheetDialog;
import net.osmand.plus.dialogs.RateUsBottomSheetDialog;
import net.osmand.plus.dialogs.WhatsNewDialogFragment;
@ -104,6 +105,7 @@ import net.osmand.plus.mapmarkers.PlanRouteFragment;
import net.osmand.plus.measurementtool.MeasurementEditingContext;
import net.osmand.plus.measurementtool.MeasurementToolFragment;
import net.osmand.plus.measurementtool.NewGpxData;
import net.osmand.plus.profiles.SelectedProfileFragment;
import net.osmand.plus.render.RendererRegistry;
import net.osmand.plus.resources.ResourceManager;
import net.osmand.plus.routepreparationmenu.ChooseRouteFragment;
@ -773,6 +775,21 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
}
setIntent(null);
}
if (intent.hasExtra(SelectedProfileFragment.OPEN_CONFIG_ON_MAP)) {
switch (intent.getStringExtra(SelectedProfileFragment.OPEN_CONFIG_ON_MAP)) {
case SelectedProfileFragment.MAP_CONFIG:
LOG.debug("open map config");
this.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_MAP, null);
break;
case SelectedProfileFragment.SCREEN_CONFIG:
LOG.debug("open screen config");
this.getDashboard().setDashboardVisibility(true, DashboardType.CONFIGURE_SCREEN, null);
break;
}
setIntent(null);
}
}
mapView.refreshMap(true);
if (atlasMapRendererView != null) {

View file

@ -1,95 +0,0 @@
package net.osmand.plus.profiles;
import android.os.Parcel;
import android.os.Parcelable;
import net.osmand.plus.ApplicationMode;
public class AppProfile implements Parcelable {
private int iconRes;
private String title;
private String navType;
private boolean isSelected;
private String prefKey;
private float defSpeed;
private int distForTurn;
private int arrivalDistance;
private int offRouteDistance;
public AppProfile(int iconRes, String title, String descr) {
this.iconRes = iconRes;
this.title = title;
this.navType = descr;
}
public int getIconRes() {
return iconRes;
}
public void setIconRes(int iconRes) {
this.iconRes = iconRes;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getNavType() {
return navType;
}
public void setNavType(String descr) {
this.navType = descr;
}
public boolean isSelected() {
return isSelected;
}
public void setSelected(boolean isSelected) {
this.isSelected = isSelected;
}
protected AppProfile(Parcel in) {
iconRes = in.readInt();
title = in.readString();
navType = in.readString();
isSelected = in.readByte() != 0;
}
public static final Creator<AppProfile> CREATOR = new Creator<AppProfile>() {
@Override
public AppProfile createFromParcel(Parcel in) {
return new AppProfile(in);
}
@Override
public AppProfile[] newArray(int size) {
return new AppProfile[size];
}
};
@Override
public int describeContents() {
return 0;
}
@Override
public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(iconRes);
dest.writeString(title);
dest.writeString(navType);
dest.writeByte((byte) (isSelected ? 1 : 0));
}
}

View file

@ -1,6 +1,5 @@
package net.osmand.plus.profiles;
import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
@ -10,6 +9,7 @@ import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
@ -24,11 +24,11 @@ public class NavTypeBottomSheetDialogFragment extends BottomSheetDialogFragment
private static final Log LOG = PlatformUtil.getLog(NavTypeBottomSheetDialogFragment.class);
List<RoutingProfile> routingProfiles;
NavTypeDialogListener listener;
NavTypeDialogListener listListener;
RecyclerView recyclerView;
NavTypeAdapter adapter;
private List<RoutingProfile> routingProfiles;
private NavTypeDialogListener listener;
private NavTypeDialogListener listListener;
private RecyclerView recyclerView;
private NavTypeAdapter adapter;
public void setNavTypeListener(NavTypeDialogListener listener) {
this.listener = listener;
@ -36,15 +36,19 @@ public class NavTypeBottomSheetDialogFragment extends BottomSheetDialogFragment
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Bundle args = getArguments();
if (args != null) {
routingProfiles = args.getParcelableArrayList("routing_profiles");
}
final int themeRes = getMyApplication().getSettings().isLightContent() ? R.style.OsmandLightTheme : R.style.OsmandDarkTheme;
View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes), R.layout.bottom_sheet_nav_type_fragment, null);
final int themeRes = getMyApplication().getSettings().isLightContent()
? R.style.OsmandLightTheme
: R.style.OsmandDarkTheme;
View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
R.layout.bottom_sheet_select_type_fragment, null);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -55,12 +59,21 @@ public class NavTypeBottomSheetDialogFragment extends BottomSheetDialogFragment
@Override
public void selectedNavType(int pos) {
listener.selectedNavType(pos);
dismiss();
}
};
recyclerView = view.findViewById(R.id.menu_list_view);
adapter = new NavTypeAdapter(routingProfiles, isNightMode(getMyApplication()), listListener);
adapter = new NavTypeAdapter(routingProfiles, isNightMode(getMyApplication()),
listListener);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(adapter);
Button cancelBtn = view.findViewById(R.id.cancel_selection);
cancelBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
return view;
}
@ -70,6 +83,7 @@ public class NavTypeBottomSheetDialogFragment extends BottomSheetDialogFragment
}
class NavTypeAdapter extends RecyclerView.Adapter<ItemViewHolder> {
private final List<RoutingProfile> items;
private final boolean isNightMode;
private NavTypeDialogListener listener;
@ -91,18 +105,20 @@ public class NavTypeBottomSheetDialogFragment extends BottomSheetDialogFragment
@NonNull
@Override
public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ItemViewHolder(LayoutInflater.from(parent.getContext()).inflate(R.layout.bottom_sheet_item_with_descr_and_radio_btn, parent, false));
return new ItemViewHolder(LayoutInflater.from(parent.getContext())
.inflate(R.layout.bottom_sheet_item_with_descr_and_radio_btn, parent, false));
}
@Override
public void onBindViewHolder(@NonNull final ItemViewHolder holder, final int position) {
public void onBindViewHolder(@NonNull final ItemViewHolder holder, int position) {
final int pos = position;
final RoutingProfile item = items.get(position);
holder.title.setText(item.getName());
holder.descr.setText(item.getOrigin());
holder.icon.setImageDrawable(getIcon(item.getIconRes(), isNightMode
? R.color.active_buttons_and_links_dark
: R.color.active_buttons_and_links_light));
if(item.isSelected()) {
? R.color.active_buttons_and_links_dark
: R.color.active_buttons_and_links_light));
if (item.isSelected()) {
holder.radioButton.setChecked(true);
previousSelection = position;
} else {
@ -111,14 +127,12 @@ public class NavTypeBottomSheetDialogFragment extends BottomSheetDialogFragment
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.selectedNavType(position);
listener.selectedNavType(pos);
holder.radioButton.setChecked(true);
items.get(position).setSelected(true);
items.get(pos).setSelected(true);
items.get(previousSelection).setSelected(false);
notifyItemChanged(previousSelection);
previousSelection = position;
previousSelection = pos;
}
});
}
@ -129,7 +143,6 @@ public class NavTypeBottomSheetDialogFragment extends BottomSheetDialogFragment
}
}
class ItemViewHolder extends RecyclerView.ViewHolder {
TextView title, descr;
RadioButton radioButton;
@ -145,10 +158,9 @@ public class NavTypeBottomSheetDialogFragment extends BottomSheetDialogFragment
}
interface NavTypeDialogListener {
void selectedNavType(int pos);
}
interface IconIdListener {
void selecedIconId(int iconRes);
}
}

View file

@ -0,0 +1,209 @@
package net.osmand.plus.profiles;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.ContextThemeWrapper;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import net.osmand.PlatformUtil;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.base.BottomSheetDialogFragment;
import org.apache.commons.logging.Log;
public class SelectIconBottomSheetDialogFragment extends BottomSheetDialogFragment {
private static final Log LOG = PlatformUtil.getLog(SelectIconBottomSheetDialogFragment.class);
private List<IconResWithDescr> icons;
private IconIdListener listener;
private IconIdListener listListener;
private RecyclerView recyclerView;
private IconIdAdapter adapter;
public void setIconIdListener(IconIdListener listener) {
this.listener = listener;
}
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
icons = getProfileIcons();
Bundle args = getArguments();
if (args != null) {
int selectedIcon = args.getInt("selectedIcon", -1);
if(selectedIcon != -1) {
for (IconResWithDescr icon : icons) {
if (icon.resId == selectedIcon) {
icon.setSelected(true);
}
}
}
}
final int themeRes = getMyApplication().getSettings().isLightContent()
? R.style.OsmandLightTheme
: R.style.OsmandDarkTheme;
View view = View.inflate(new ContextThemeWrapper(getContext(), themeRes),
R.layout.bottom_sheet_select_type_fragment, null);
view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
listListener = new IconIdListener() {
@Override
public void selectedIconId(int iconRes) {
listener.selectedIconId(iconRes);
dismiss();
}
};
recyclerView = view.findViewById(R.id.menu_list_view);
adapter = new IconIdAdapter(icons, isNightMode(getMyApplication()), listListener);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
recyclerView.setAdapter(adapter);
Button cancelBtn = view.findViewById(R.id.cancel_selection);
cancelBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismiss();
}
});
return view;
}
private static boolean isNightMode(OsmandApplication ctx) {
return !ctx.getSettings().isLightContent();
}
class IconIdAdapter extends RecyclerView.Adapter<SelectIconBottomSheetDialogFragment.ItemViewHolder> {
private final List<IconResWithDescr> items;
private final boolean isNightMode;
private IconIdListener listener;
private int previousSelection;
private IconIdAdapter(@NonNull List<IconResWithDescr> objects,
@NonNull boolean isNightMode, IconIdListener listener) {
this.items = objects;
this.isNightMode = isNightMode;
this.listener = listener;
}
@NonNull
@Override
public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
return new ItemViewHolder(LayoutInflater.from(parent.getContext()).inflate(
R.layout.bottom_sheet_item_with_radio_btn, parent, false));
}
@Override
public void onBindViewHolder(@NonNull final ItemViewHolder holder, int position) {
final int pos = position;
final IconResWithDescr item = items.get(position);
holder.title.setText(item.getTitleId());
holder.icon.setImageDrawable(getIcon(item.getResId(), isNightMode
? R.color.active_buttons_and_links_dark
: R.color.active_buttons_and_links_light));
if(item.isSelected()) {
holder.radioButton.setChecked(true);
previousSelection = position;
} else {
holder.radioButton.setChecked(false);
}
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.selectedIconId(item.resId);
holder.radioButton.setChecked(true);
items.get(pos).setSelected(true);
items.get(previousSelection).setSelected(false);
notifyItemChanged(previousSelection);
previousSelection = pos;
}
});
}
@Override
public int getItemCount() {
return items.size();
}
}
class ItemViewHolder extends RecyclerView.ViewHolder {
TextView title;
RadioButton radioButton;
ImageView icon;
public ItemViewHolder(View itemView) {
super(itemView);
title = itemView.findViewById(R.id.title);
radioButton = itemView.findViewById(R.id.compound_button);
icon = itemView.findViewById(R.id.icon);
}
}
interface IconIdListener {
void selectedIconId(int iconRes);
}
public class IconResWithDescr {
private int resId;
private int titleId;
private boolean isSelected;
public IconResWithDescr(int resId, int titleId, boolean isSelected) {
this.resId = resId;
this.titleId = titleId;
this.isSelected = isSelected;
}
public int getResId() {
return resId;
}
public int getTitleId() {
return titleId;
}
public boolean isSelected() {
return isSelected;
}
public void setSelected(boolean selected) {
isSelected = selected;
}
}
private List<IconResWithDescr> getProfileIcons() {
List<IconResWithDescr> icons = new ArrayList<>();
icons.add(new IconResWithDescr(R.drawable.ic_action_car_dark, R.string.rendering_value_car_name,false));
icons.add(new IconResWithDescr(R.drawable.ic_action_bicycle_dark, R.string.rendering_value_bicycle_name,false));
icons.add(new IconResWithDescr(R.drawable.ic_action_pedestrian_dark, R.string.rendering_value_pedestrian_name,false));
icons.add(new IconResWithDescr(R.drawable.ic_action_bus_dark, R.string.app_mode_bus,false));
icons.add(new IconResWithDescr(R.drawable.ic_action_sail_boat_dark, R.string.app_mode_boat,false));
icons.add(new IconResWithDescr(R.drawable.ic_action_aircraft, R.string.app_mode_aircraft,false));
icons.add(new IconResWithDescr(R.drawable.ic_action_truck_dark, R.string.app_mode_truck,false));
icons.add(new IconResWithDescr(R.drawable.ic_action_motorcycle_dark, R.string.app_mode_motorcycle,false));
icons.add(new IconResWithDescr(R.drawable.ic_action_trekking_dark, R.string.app_mode_hiking,false));
return icons;
}
}

View file

@ -1,14 +1,20 @@
package net.osmand.plus.profiles;
import android.content.Intent;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.content.ContextCompat;
import android.support.v7.app.ActionBar;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
@ -17,9 +23,12 @@ import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmandActionBarActivity;
import net.osmand.plus.activities.SettingsNavigationActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.profiles.NavTypeBottomSheetDialogFragment.NavTypeDialogListener;
import net.osmand.plus.profiles.NavTypeBottomSheetDialogFragment.IconIdListener;
import net.osmand.plus.profiles.SelectIconBottomSheetDialogFragment.IconIdListener;
import net.osmand.plus.widgets.OsmandTextFieldBoxes;
import net.osmand.router.GeneralRouter.GeneralRouterProfile;
import org.apache.commons.logging.Log;
@ -29,9 +38,18 @@ public class SelectedProfileFragment extends BaseOsmAndFragment {
private static final Log LOG = PlatformUtil.getLog(SelectedProfileFragment.class);
public static final String OPEN_CONFIG_ON_MAP = "openConfigOnMap";
public static final String MAP_CONFIG = "openMapConfigMenu";
public static final String NAV_CONFIG = "openNavConfigMenu";
public static final String SCREEN_CONFIG = "openScreenConfigMenu";
public static final String SELECTED_PROFILE = "editedProfile";
ApplicationMode profile = null;
ApplicationMode parent = null;
ArrayList<RoutingProfile> routingProfiles;
OsmandApplication app;
RoutingProfile selectedRoutingProfile = null;
float defSpeed = 0f;
boolean isDataChanged = false;
@ -45,6 +63,7 @@ public class SelectedProfileFragment extends BaseOsmAndFragment {
if (getArguments() != null) {
String modeName = getArguments().getString("stringKey");
profile = ApplicationMode.valueOfStringKey(modeName, ApplicationMode.CAR);
//todo select parent
}
routingProfiles = getRoutingProfiles();
}
@ -53,7 +72,7 @@ public class SelectedProfileFragment extends BaseOsmAndFragment {
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
boolean isNightMode = !app.getSettings().isLightContent();
final boolean isNightMode = !app.getSettings().isLightContent();
View view = inflater.inflate(R.layout.fragment_selected_profile, container, false);
@ -63,7 +82,12 @@ public class SelectedProfileFragment extends BaseOsmAndFragment {
final OsmandTextFieldBoxes profileNameTextBox = view.findViewById(R.id.profile_name_otfb);
final ExtendedEditText navTypeEt = view.findViewById(R.id.navigation_type_et);
final OsmandTextFieldBoxes navTypeTextBox = view.findViewById(R.id.navigation_type_otfb);
final FrameLayout select_nav_type_btn = view.findViewById(R.id.select_nav_type_btn);
final FrameLayout selectNavTypeBtn = view.findViewById(R.id.select_nav_type_btn);
final Button cancelBtn = view.findViewById(R.id.cancel_button);
final Button saveButton = view.findViewById(R.id.save_profile_btn);
final View mapConfigBtn = view.findViewById(R.id.map_config_btn);
final View screenConfigBtn = view.findViewById(R.id.screen_config_btn);
final View navConfigBtn = view.findViewById(R.id.nav_settings_btn);
profileIconBtn.setBackgroundResource(R.drawable.rounded_background_3dp);
GradientDrawable selectIconBtnBackground = (GradientDrawable) profileIconBtn
@ -88,34 +112,182 @@ public class SelectedProfileFragment extends BaseOsmAndFragment {
navTypeDialogListener = new NavTypeDialogListener() {
@Override
public void selectedNavType(int pos) {
navTypeEt.setText(routingProfiles.get(pos).getName());
selectedRoutingProfile = routingProfiles.get(pos);
navTypeEt.setText(selectedRoutingProfile.getName());
}
};
select_nav_type_btn.setOnClickListener(new View.OnClickListener() {
iconIdListener = new IconIdListener() {
@Override
public void selectedIconId(int iconRes) {
profile.setMapIconId(iconRes);
profile.setSmallIconDark(iconRes);
profileIcon.setImageDrawable(app.getUIUtilities().getIcon(iconRes,
isNightMode ? R.color.active_buttons_and_links_dark
: R.color.active_buttons_and_links_light));
}
};
profileNameEt.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) {
if (getActivity() instanceof OsmandActionBarActivity) {
ActionBar actionBar = ((OsmandActionBarActivity) getActivity()).getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle(s.toString());
}
}
}
});
selectNavTypeBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
LOG.debug("select icon");
final NavTypeBottomSheetDialogFragment fragment = new NavTypeBottomSheetDialogFragment();
fragment.setNavTypeListener(navTypeDialogListener);
Bundle bundle = new Bundle();
bundle.putParcelableArrayList("routing_profiles", routingProfiles);
fragment.setArguments(bundle);
getActivity().getSupportFragmentManager().beginTransaction().add(fragment, "select_nav_type")
.commitAllowingStateLoss();
if (getActivity() != null) {
getActivity().getSupportFragmentManager().beginTransaction()
.add(fragment, "select_nav_type")
.commitAllowingStateLoss();
}
// navTypeEt.setText("Car");
// navTypeEt.setCursorVisible(false);
// navTypeEt.setTextIsSelectable(false);
// navTypeEt.clearFocus();
// navTypeEt.requestFocus(EditText.FOCUS_UP);
navTypeEt.requestFocus(ExtendedEditText.FOCUS_UP);
// LOG.debug("click on text");
}
});
profileIconBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
LOG.debug("select icon");
final SelectIconBottomSheetDialogFragment iconSelectDialog = new SelectIconBottomSheetDialogFragment();
iconSelectDialog.setIconIdListener(iconIdListener);
Bundle bundle = new Bundle();
bundle.putInt("selectedIcon", profile.getSmallIconDark());
iconSelectDialog.setArguments(bundle);
if (getActivity() != null) {
getActivity().getSupportFragmentManager().beginTransaction()
.add(iconSelectDialog, "select_icon")
.commitAllowingStateLoss();
}
}
});
//todo switch app to edited mode on activity start
mapConfigBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(isDataChanged) {
//todo save before living
} else {
Intent i = new Intent(getActivity(), MapActivity.class);
i.putExtra(OPEN_CONFIG_ON_MAP, MAP_CONFIG);
i.putExtra(SELECTED_PROFILE, profile.getStringKey());
startActivity(i);
}
}
});
screenConfigBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(isDataChanged) {
//todo save before living
} else {
Intent i = new Intent(getActivity(), MapActivity.class);
i.putExtra(OPEN_CONFIG_ON_MAP, SCREEN_CONFIG);
i.putExtra(SELECTED_PROFILE, profile.getStringKey());
startActivity(i);
}
}
});
//todo edited mode on activity start
navConfigBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if(isDataChanged) {
//todo save before living
} else {
Intent i = new Intent(getActivity(), SettingsNavigationActivity.class);
i.putExtra(OPEN_CONFIG_ON_MAP, NAV_CONFIG);
i.putExtra(SELECTED_PROFILE, profile.getStringKey());
startActivity(i);
}
}
});
cancelBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (getActivity() != null) {
getActivity().onBackPressed();
}
}
});
saveButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String title = profileNameTextBox.getEditText().getText().toString();
if (ApplicationMode.allPossibleValues().contains(profile)) {
updateProfile();
} else {
saveNewProfile(title, parent, selectedRoutingProfile, defSpeed);
}
}
});
return view;
}
private boolean saveNewProfile(
String userProfileTitle,
ApplicationMode profile,
RoutingProfile selectedRoutingProfile,
float defSpeed) {
String customStringKey = profile.getParent().getStringKey() + "_" + userProfileTitle.hashCode();
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
if (mode.getStringKey().equals(customStringKey)) {
//todo notify user that there is already profile with such name
return false;
}
}
ApplicationMode.createCustomMode(userProfileTitle, customStringKey);
//todo build profile, save and register:
return true;
}
private void updateProfile() {
}
/**
* For now there are only default nav profiles todo: add profiles from custom routing xml-s
*/