Merge pull request #8155 from osmandapp/Manage_profile_settings

Manage profile settings Fix
This commit is contained in:
max-klaus 2020-01-02 14:15:40 +03:00 committed by GitHub
commit 00aa0b120e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 214 additions and 102 deletions

View file

@ -1,5 +1,6 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@android:color/transparent" />
<stroke
android:width="1dp"
android:color="@color/divider_color_dark" />

View file

@ -1,5 +1,6 @@
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="@android:color/transparent" />
<stroke
android:width="1dp"
android:color="@color/divider_color_light" />

View file

@ -24,7 +24,8 @@
android:layout_height="match_parent"
android:background="?attr/list_background_color"
android:clipToPadding="false"
android:paddingBottom="72dp" />
android:paddingBottom="72dp"
android:paddingTop="16dp"/>
<LinearLayout
android:layout_width="match_parent"

View file

@ -12,11 +12,11 @@
app:srcCompat="@drawable/circle_contour_bg_light" />
<ImageView
android:id="@+id/bckgroundCircle"
android:id="@+id/backgroundCircle"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_margin="4dp"
app:srcCompat="@drawable/ic_action_circle" />
android:background="@drawable/circle_background_light" />
<ImageView
android:id="@+id/checkMark"
@ -31,5 +31,4 @@
android:layout_marginStart="16dp"
android:layout_marginEnd="4dp" />
</FrameLayout>

View file

@ -1,7 +1,7 @@
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
@ -10,22 +10,21 @@
<net.osmand.plus.widgets.OsmandTextFieldBoxes
android:id="@+id/profile_name_otfb"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_margin="@dimen/list_content_padding"
android:layout_height="wrap_content"
android:layout_weight="1"
app:labelText="@string/profile_name_hint"
android:layout_margin="@dimen/list_content_padding"
app:primaryColor="@color/active_color_primary_dark"
app:secondaryColor="?android:textColorSecondary">
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:lines="1"
android:maxLines="1"
android:singleLine="true"
android:inputType="textMultiLine"
android:scrollHorizontally="false"
android:maxLines="4"
tools:text="@string/lorem_ipsum" />
</net.osmand.plus.widgets.OsmandTextFieldBoxes>
</LinearLayout>

View file

@ -3248,7 +3248,7 @@
<string name="profile_alert_need_save_title">حفظ التغييرات</string>
<string name="profile_alert_need_save_msg">احفظ التغييرات في ملف التعريف أولاً</string>
<string name="profile_alert_delete_title">حذف الملف الشخصي</string>
<string name="profile_alert_delete_msg">هل تريد بالتأكيد حذف ملف التعريف \"٪ s\"</string>
<string name="profile_alert_delete_msg">هل تريد بالتأكيد حذف ملف التعريف \"%s\"</string>
<string name="select_base_profile_dialog_title">حدد ملف تعريف أساسي</string>
<string name="select_base_profile_dialog_message">إسناد ملف التعريف المخصص الخاص بك إلى أحد ملفات تعريف التطبيق الافتراضية ، يحدد الإعداد الأساسي مثل الرؤية الافتراضية لعناصر واجهة المستخدم ووحدات السرعة والمسافة. وهذه هي ملفات تعريف التطبيق الافتراضية ، إلى جانب أمثلة لملفات تعريف مخصصة يمكن تمديدها إلى:</string>
<string name="select_nav_profile_dialog_title">حدد نوع الملاحة</string>

View file

@ -48,6 +48,7 @@ import android.util.TypedValue;
import android.view.Gravity;
import android.view.View;
import android.view.ViewParent;
import android.view.ViewTreeObserver;
import android.view.inputmethod.InputMethodManager;
import android.widget.FrameLayout;
import android.widget.ImageButton;
@ -551,19 +552,40 @@ public class AndroidUtils {
return coordinates;
}
public static void enterToFullScreen(Activity activity) {
public static void enterToFullScreen(Activity activity, View view) {
if (Build.VERSION.SDK_INT >= 21) {
requestLayout(view);
activity.getWindow().getDecorView()
.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
}
}
public static void exitFromFullScreen(Activity activity) {
public static void exitFromFullScreen(Activity activity, View view) {
if (Build.VERSION.SDK_INT >= 21) {
requestLayout(view);
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}
}
private static void requestLayout(final View view) {
if (view != null) {
ViewTreeObserver vto = view.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
ViewTreeObserver obs = view.getViewTreeObserver();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
obs.removeOnGlobalLayoutListener(this);
} else {
obs.removeGlobalOnLayoutListener(this);
}
view.requestLayout();
}
});
}
}
public static <K, V extends Comparable<? super V>> Map<K, V> sortByValue(Map<K, V> map) {
List<Map.Entry<K, V>> list = new LinkedList<>(map.entrySet());
Collections.sort(list, new Comparator<Map.Entry<K, V>>() {

View file

@ -373,12 +373,12 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
mIsDestroyed = false;
}
public void exitFromFullScreen() {
AndroidUtils.exitFromFullScreen(this);
public void exitFromFullScreen(View view) {
AndroidUtils.exitFromFullScreen(this, view);
}
public void enterToFullScreen() {
AndroidUtils.enterToFullScreen(this);
AndroidUtils.enterToFullScreen(this, getLayout());
}
@Override
@ -1060,7 +1060,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
private BaseSettingsFragment getVisibleBaseSettingsFragment(int... ids) {
for (int id : ids) {
Fragment fragment = getSupportFragmentManager().findFragmentById(id);
if (fragment != null && !fragment.isRemoving() && fragment.isVisible() && fragment instanceof BaseSettingsFragment
if (fragment != null && !fragment.isRemoving() && fragment instanceof BaseSettingsFragment
&& ((BaseSettingsFragment) fragment).getStatusBarColorId() != -1) {
return (BaseSettingsFragment) fragment;
}

View file

@ -59,7 +59,6 @@ import net.osmand.plus.mapmarkers.MapMarkersDialogFragment;
import net.osmand.plus.mapmarkers.MarkersPlanRouteContext;
import net.osmand.plus.measurementtool.MeasurementToolFragment;
import net.osmand.plus.monitoring.OsmandMonitoringPlugin;
import net.osmand.plus.profiles.SettingsProfileActivity;
import net.osmand.plus.routepreparationmenu.MapRouteInfoMenu;
import net.osmand.plus.routepreparationmenu.WaypointsFragment;
import net.osmand.plus.routing.RouteProvider.GPXRouteParamsBuilder;
@ -706,9 +705,7 @@ public class MapActivityActions implements DialogProvider {
.setListener(new ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
Intent intent = new Intent(app, SettingsProfileActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
app.startActivity(intent);
BaseSettingsFragment.showInstance(mapActivity, BaseSettingsFragment.SettingsScreenType.MAIN_SETTINGS);
return true;
}
})

View file

@ -1,6 +1,5 @@
package net.osmand.plus.base;
import android.annotation.TargetApi;
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Build;
@ -14,13 +13,12 @@ import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewTreeObserver;
import android.view.animation.Animation;
import android.widget.ImageView;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.OsmandSettings;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.activities.OsmandActionBarActivity;
import net.osmand.plus.activities.OsmandInAppPurchaseActivity;
@ -47,25 +45,7 @@ public class BaseOsmAndFragment extends Fragment implements TransitionAnimator {
}
}
if (!isFullScreenAllowed() && activity instanceof MapActivity) {
View view = getView();
if (view != null) {
ViewTreeObserver vto = view.getViewTreeObserver();
vto.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@TargetApi(Build.VERSION_CODES.JELLY_BEAN)
@Override
public void onGlobalLayout() {
View view = getView();
if (view != null) {
ViewTreeObserver obs = view.getViewTreeObserver();
obs.removeOnGlobalLayoutListener(this);
view.requestLayout();
}
}
});
}
((MapActivity) activity).exitFromFullScreen();
((MapActivity) activity).exitFromFullScreen(getView());
}
}
}

View file

@ -68,7 +68,7 @@ import net.osmand.plus.measurementtool.command.ClearPointsCommand;
import net.osmand.plus.measurementtool.command.MovePointCommand;
import net.osmand.plus.measurementtool.command.RemovePointCommand;
import net.osmand.plus.measurementtool.command.ReorderPointCommand;
import net.osmand.plus.profiles.ReorderItemTouchHelperCallback;
import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory;
import net.osmand.plus.views.mapwidgets.MapInfoWidgetsFactory.TopToolbarController;

View file

@ -20,7 +20,7 @@ import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.measurementtool.NewGpxData.ActionType;
import net.osmand.plus.profiles.ReorderItemTouchHelperCallback;
import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback;
import java.util.Collections;
import java.util.List;

View file

@ -1,7 +1,6 @@
package net.osmand.plus.profiles;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
@ -9,14 +8,11 @@ import android.view.ContextThemeWrapper;
import android.view.View;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
import net.osmand.plus.base.bottomsheetmenu.BaseBottomSheetItem;
import net.osmand.plus.base.bottomsheetmenu.simpleitems.TitleItem;
import static net.osmand.plus.profiles.SettingsProfileFragment.IS_USER_PROFILE;
import static net.osmand.plus.profiles.SettingsProfileFragment.PROFILE_STRING_KEY;
import net.osmand.plus.settings.BaseSettingsFragment;
public abstract class AppModesBottomSheetDialogFragment<T extends AbstractProfileMenuAdapter> extends MenuBottomSheetDialogFragment
implements AbstractProfileMenuAdapter.ButtonPressedListener, AbstractProfileMenuAdapter.ProfilePressedListener {
@ -79,17 +75,13 @@ public abstract class AppModesBottomSheetDialogFragment<T extends AbstractProfil
@Override
public void onProfilePressed(ApplicationMode item) {
Intent intent = new Intent(getActivity(), EditProfileActivity.class);
intent.putExtra(PROFILE_STRING_KEY, item.getStringKey());
intent.putExtra(IS_USER_PROFILE, item.isCustomProfile());
startActivity(intent);
this.dismiss();
BaseSettingsFragment.showInstance(getActivity(), BaseSettingsFragment.SettingsScreenType.CONFIGURE_PROFILE, item);
}
@Override
public void onButtonPressed() {
OsmandApplication app = requiredMyApplication();
Intent intent = new Intent(app, SettingsProfileActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
app.startActivity(intent);
this.dismiss();
BaseSettingsFragment.showInstance(getActivity(), BaseSettingsFragment.SettingsScreenType.MAIN_SETTINGS);
}
}

View file

@ -29,6 +29,7 @@ import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.settings.BaseSettingsFragment;
import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback;
import java.util.ArrayList;
import java.util.Collections;
@ -47,6 +48,9 @@ public class EditProfilesFragment extends BaseOsmAndFragment {
private EditProfilesAdapter adapter;
private boolean nightMode;
private boolean wasDrawerDisabled;
@Nullable
@Override
public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
@ -59,9 +63,9 @@ public class EditProfilesFragment extends BaseOsmAndFragment {
appModesOrders.put(mode.getStringKey(), mode.getOrder());
}
}
View mainView = inflater.inflate(R.layout.edit_profiles_list_fragment, container, false);
AndroidUtils.addStatusBarPadding21v(getContext(), mainView);
nightMode = !app.getSettings().isLightContent();
View mainView =UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.edit_profiles_list_fragment, container, false);
ImageButton closeButton = mainView.findViewById(R.id.close_button);
closeButton.setImageResource(R.drawable.ic_action_remove_dark);
closeButton.setOnClickListener(new View.OnClickListener() {
@ -124,7 +128,7 @@ public class EditProfilesFragment extends BaseOsmAndFragment {
recyclerView.setAdapter(adapter);
View cancelButton = mainView.findViewById(R.id.dismiss_button);
UiUtilities.setupDialogButton(false, cancelButton, UiUtilities.DialogButtonType.SECONDARY, R.string.shared_string_cancel);
UiUtilities.setupDialogButton(nightMode, cancelButton, UiUtilities.DialogButtonType.SECONDARY, R.string.shared_string_cancel);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
@ -138,7 +142,7 @@ public class EditProfilesFragment extends BaseOsmAndFragment {
mainView.findViewById(R.id.buttons_divider).setVisibility(View.VISIBLE);
View applyButton = mainView.findViewById(R.id.right_bottom_button);
UiUtilities.setupDialogButton(false, applyButton, UiUtilities.DialogButtonType.PRIMARY, R.string.shared_string_apply);
UiUtilities.setupDialogButton(nightMode, applyButton, UiUtilities.DialogButtonType.PRIMARY, R.string.shared_string_apply);
applyButton.setVisibility(View.VISIBLE);
applyButton.setOnClickListener(new View.OnClickListener() {
@Override
@ -179,6 +183,11 @@ public class EditProfilesFragment extends BaseOsmAndFragment {
return mainView;
}
@Override
protected boolean isFullScreenAllowed() {
return false;
}
@Override
public void onSaveInstanceState(@NonNull Bundle outState) {
super.onSaveInstanceState(outState);
@ -186,6 +195,41 @@ public class EditProfilesFragment extends BaseOsmAndFragment {
outState.putStringArrayList(DELETED_APP_MODES_KEY, deletedModesKeys);
}
@Override
public void onResume() {
super.onResume();
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
wasDrawerDisabled = mapActivity.isDrawerDisabled();
if (!wasDrawerDisabled) {
mapActivity.disableDrawer();
}
}
}
public void onPause() {
super.onPause();
MapActivity mapActivity = getMapActivity();
if (mapActivity != null && !wasDrawerDisabled) {
mapActivity.enableDrawer();
}
}
@Override
public int getStatusBarColorId() {
return nightMode ? R.color.status_bar_color_dark : R.color.status_bar_color_light;
}
@Nullable
public MapActivity getMapActivity() {
FragmentActivity activity = getActivity();
if (activity instanceof MapActivity) {
return (MapActivity) activity;
} else {
return null;
}
}
public List<EditProfileDataObject> getProfiles(boolean deleted) {
List<EditProfileDataObject> profiles = new ArrayList<>();
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {

View file

@ -28,9 +28,9 @@ import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.profiles.ReorderItemTouchHelperCallback;
import net.osmand.plus.profiles.ReorderItemTouchHelperCallback.UnmovableItem;
import net.osmand.plus.profiles.ReorderItemTouchHelperCallback.OnItemMoveCallback;
import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback;
import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback.UnmovableItem;
import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback.OnItemMoveCallback;
import java.util.ArrayList;
import java.util.Collections;

View file

@ -20,7 +20,7 @@ import android.widget.TextView;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.dialogs.SelectMapViewQuickActionsBottomSheet;
import net.osmand.plus.profiles.ReorderItemTouchHelperCallback;
import net.osmand.plus.views.controls.ReorderItemTouchHelperCallback;
import java.util.ArrayList;
import java.util.Collections;

View file

@ -19,7 +19,6 @@ import android.support.transition.Transition;
import android.support.transition.TransitionListenerAdapter;
import android.support.transition.TransitionManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.AppCompatImageView;
import android.view.View;
@ -71,7 +70,6 @@ import net.osmand.plus.mapcontextmenu.other.TrackDetailsMenuFragment;
import net.osmand.plus.mapmarkers.MapMarkerSelectionFragment;
import net.osmand.plus.poi.PoiUIFilter;
import net.osmand.plus.profiles.AppModesBottomSheetDialogFragment;
import net.osmand.plus.profiles.AppModesBottomSheetDialogFragment.UpdateMapRouteMenuListener;
import net.osmand.plus.profiles.ConfigureAppModesBottomSheetDialogFragment;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidPTTypesRoutingParameter;
import net.osmand.plus.routepreparationmenu.RoutingOptionsHelper.AvoidRoadsRoutingParameter;
@ -798,14 +796,14 @@ public class MapRouteInfoMenu implements IRouteInformationListener, CardListener
private void showProfileBottomSheetDialog() {
final AppModesBottomSheetDialogFragment fragment = new ConfigureAppModesBottomSheetDialogFragment();
fragment.setUsedOnMap(true);
fragment.setUpdateMapRouteMenuListener(new UpdateMapRouteMenuListener() {
fragment.setUpdateMapRouteMenuListener(new AppModesBottomSheetDialogFragment.UpdateMapRouteMenuListener() {
@Override
public void updateAppModeMenu() {
updateApplicationModes();
}
});
getMapActivity().getSupportFragmentManager().beginTransaction()
.add(fragment, ConfigureAppModesBottomSheetDialogFragment.TAG).commitAllowingStateLoss();
.add(fragment, ConfigureAppModesBottomSheetDialogFragment.TAG).commitAllowingStateLoss();
}
private void updateApplicationMode(ApplicationMode mode, ApplicationMode next) {

View file

@ -143,7 +143,6 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
updateTheme();
View view = super.onCreateView(inflater, container, savedInstanceState);
if (view != null) {
AndroidUtils.addStatusBarPadding21v(getContext(), view);
if (getPreferenceScreen() != null) {
PreferenceManager prefManager = getPreferenceManager();
PreferenceScreen preferenceScreen = prefManager.inflateFromResource(prefManager.getContext(), currentScreenType.preferencesResId, null);
@ -229,6 +228,9 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
activity.getWindow().setStatusBarColor(ContextCompat.getColor(activity, colorId));
}
}
if (activity instanceof MapActivity) {
((MapActivity) activity).exitFromFullScreen(getView());
}
}
}
}
@ -237,17 +239,19 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
public void onPause() {
super.onPause();
MapActivity mapActivity = getMapActivity();
if (!wasDrawerDisabled && mapActivity != null) {
mapActivity.enableDrawer();
}
Activity activity = getActivity();
if (activity != null) {
if (!wasDrawerDisabled && activity instanceof MapActivity) {
((MapActivity) activity).enableDrawer();
}
if (Build.VERSION.SDK_INT >= 21) {
Activity activity = getActivity();
if (activity != null) {
if (Build.VERSION.SDK_INT >= 21) {
if (!(activity instanceof MapActivity) && statusBarColor != -1) {
activity.getWindow().setStatusBarColor(statusBarColor);
}
if (activity instanceof MapActivity) {
((MapActivity) activity).enterToFullScreen();
}
}
}
}
@ -748,4 +752,11 @@ public abstract class BaseSettingsFragment extends PreferenceFragmentCompat impl
}
return false;
}
void updateRouteInfoMenu() {
MapActivity mapActivity = getMapActivity();
if (mapActivity != null) {
mapActivity.getMapRouteInfoMenu().updateMenu();
}
}
}

View file

@ -119,6 +119,12 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
}
}
@Override
public void onPause() {
updateRouteInfoMenu();
super.onPause();
}
private void updateToolbarSwitch() {
View view = getView();
if (view == null) {

View file

@ -38,7 +38,7 @@ public class MainSettingsFragment extends BaseSettingsFragment {
private static final String APP_PROFILES = "app_profiles";
private static final String SELECTED_PROFILE = "selected_profile";
private static final String CREATE_PROFILE = "create_profile";
private static final String IMPORT_PROFILE = "import_profile";
// private static final String IMPORT_PROFILE = "import_profile";
private static final String REORDER_PROFILES = "reorder_profiles";
private List<ApplicationMode> allAppModes;
@ -136,7 +136,7 @@ public class MainSettingsFragment extends BaseSettingsFragment {
Preference createProfile = findPreference(CREATE_PROFILE);
createProfile.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_plus,
isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
Preference importProfile = findPreference(IMPORT_PROFILE);
// Preference importProfile = findPreference(IMPORT_PROFILE);
// importProfile.setIcon(app.getUIUtilities().getIcon(R.drawable.ic_action_import,
// isNightMode() ? R.color.active_color_primary_dark : R.color.active_color_primary_light));
Preference reorderProfiles = findPreference(REORDER_PROFILES);
@ -198,4 +198,10 @@ public class MainSettingsFragment extends BaseSettingsFragment {
}
return selectProfileListener;
}
@Override
public void onPause() {
updateRouteInfoMenu();
super.onPause();
}
}

View file

@ -53,10 +53,12 @@ public class NavigationFragment extends BaseSettingsFragment {
SwitchPreferenceCompat turnScreenOn = (SwitchPreferenceCompat) findPreference(settings.TURN_SCREEN_ON_ENABLED.getId());
SwitchPreferenceEx animateMyLocation = (SwitchPreferenceEx) findPreference(settings.ANIMATE_MY_LOCATION.getId());
if (getSelectedAppMode().getRoutingProfile() != null) {
GeneralRouter gr = app.getRoutingConfig().getRouter(getSelectedAppMode().getRoutingProfile());
RoutingProfilesResources routingProfilesResources = RoutingProfilesResources.valueOf(gr.getProfileName().toUpperCase());
navigationType.setSummary(routingProfilesResources.getStringRes());
navigationType.setIcon(getContentIcon(routingProfilesResources.getIconRes()));
GeneralRouter routingProfile = app.getRoutingConfig().getRouter(getSelectedAppMode().getRoutingProfile());
if (routingProfile != null) {
RoutingProfilesResources routingProfilesResources = RoutingProfilesResources.valueOf(routingProfile.getProfileName().toUpperCase());
navigationType.setSummary(routingProfilesResources.getStringRes());
navigationType.setIcon(getContentIcon(routingProfilesResources.getIconRes()));
}
}
routeParameters.setIcon(getContentIcon(R.drawable.ic_action_route_distance));
showRoutingAlarms.setIcon(getContentIcon(R.drawable.ic_action_alert));

View file

@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.graphics.PorterDuff;
import android.graphics.drawable.GradientDrawable;
import android.os.Bundle;
import android.support.annotation.Nullable;
@ -14,6 +15,7 @@ import android.support.v7.app.AlertDialog;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceViewHolder;
import android.text.Editable;
import android.text.InputType;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
@ -74,6 +76,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
private EditText profileName;
private FlowLayout colorItems;
private FlowLayout iconItems;
private OsmandTextFieldBoxes profileNameOtfb;
@Override
public void onCreate(Bundle savedInstanceState) {
@ -93,7 +96,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
if (baseModeForNewProfile != null) {
profile.stringKey = baseModeForNewProfile.getStringKey() + "_" + System.currentTimeMillis();
profile.parent = baseModeForNewProfile;
profile.name = baseModeForNewProfile.toHumanString(getContext());
profile.name = baseModeForNewProfile.toHumanString(app);
profile.color = baseModeForNewProfile.getIconColorInfo();
profile.iconRes = baseModeForNewProfile.getIconRes();
profile.routingProfile = baseModeForNewProfile.getRoutingProfile();
@ -113,7 +116,11 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
} else {
changedProfile.stringKey = profile.stringKey;
changedProfile.parent = profile.parent;
changedProfile.name = profile.name;
if (baseModeForNewProfile != null) {
changedProfile.name = createNonDuplicateName(baseModeForNewProfile.toHumanString(app));
} else {
changedProfile.name = profile.name;
}
changedProfile.color = profile.color;
changedProfile.iconRes = profile.iconRes;
changedProfile.routingProfile = profile.routingProfile;
@ -121,6 +128,39 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
}
}
private String createNonDuplicateName(String oldName) {
int suffix = 0;
int i = oldName.length() - 1;
do {
try {
if (oldName.charAt(i) == ' ' || oldName.charAt(i) == '-') {
throw new NumberFormatException();
}
suffix = Integer.parseInt(oldName.substring(i));
} catch (NumberFormatException e) {
break;
}
i--;
} while (i >= 0);
String newName;
String divider = suffix == 0 ? " " : "";
do {
suffix++;
newName = oldName.substring(0, i + 1) + divider + suffix;
}
while (hasProfileWithName(newName));
return newName;
}
private boolean hasProfileWithName(String newName) {
for (ApplicationMode m : ApplicationMode.allPossibleValues()) {
if (m.toHumanString(app).equals(newName)) {
return true;
}
}
return false;
}
@Override
protected void setupPreferences() {
findPreference(SELECT_COLOR).setIconSpaceReserved(false);
@ -147,8 +187,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
AndroidUtils.setBackground(getContext(), buttonsContainer, isNightMode(), R.color.list_background_color_light, R.color.list_background_color_dark);
UiUtilities.setupDialogButton(false, cancelButton, DialogButtonType.SECONDARY, R.string.shared_string_cancel);
UiUtilities.setupDialogButton(false, saveButton, DialogButtonType.PRIMARY, R.string.shared_string_save);
UiUtilities.setupDialogButton(isNightMode(), cancelButton, DialogButtonType.SECONDARY, R.string.shared_string_cancel);
UiUtilities.setupDialogButton(isNightMode(), saveButton, DialogButtonType.PRIMARY, R.string.shared_string_save);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
@ -162,10 +202,13 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
@Override
public void onClick(View v) {
if (getActivity() != null) {
hideKeyboard();
if (isChanged()) {
if (saveNewProfile()) {
profile = changedProfile;
getActivity().onBackPressed();
ProfileAppearanceFragment.this.dismiss();
BaseSettingsFragment.showInstance(getMapActivity(), SettingsScreenType.CONFIGURE_PROFILE,
ApplicationMode.valueOfStringKey(changedProfile.stringKey, null));
}
}
}
@ -240,6 +283,7 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
if (PROFILE_NAME.equals(preference.getKey())) {
profileName = (EditText) holder.findViewById(R.id.profile_name_et);
profileName.setImeOptions(EditorInfo.IME_ACTION_DONE);
profileName.setRawInputType(InputType.TYPE_CLASS_TEXT);
profileName.setText(changedProfile.name);
profileName.requestFocus();
profileName.addTextChangedListener(new TextWatcher() {
@ -256,8 +300,10 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
changedProfile.name = s.toString();
}
});
profileNameOtfb = (OsmandTextFieldBoxes) holder.findViewById(R.id.profile_name_otfb);
} else if (MASTER_PROFILE.equals(preference.getKey())) {
baseProfileName = (EditText) holder.findViewById(R.id.master_profile_et);
baseProfileName.setFocusable(false);
baseProfileName.setText(changedProfile.parent != null
? changedProfile.parent.toHumanString(getContext())
: getSelectedAppMode().toHumanString(getContext()));
@ -318,8 +364,9 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
private View createColorItemView(final ApplicationMode.ProfileIconColors colorRes, ViewGroup rootView) {
FrameLayout colorItemView = (FrameLayout) UiUtilities.getInflater(getContext(), isNightMode())
.inflate(R.layout.preference_circle_item, rootView, false);
ImageView coloredCircle = colorItemView.findViewById(R.id.bckgroundCircle);
coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light,
ImageView coloredCircle = colorItemView.findViewById(R.id.backgroundCircle);
AndroidUtils.setBackground(coloredCircle,
UiUtilities.tintDrawable(ContextCompat.getDrawable(app, R.drawable.circle_background_light),
ContextCompat.getColor(app, colorRes.getColor(isNightMode()))));
coloredCircle.setOnClickListener(new View.OnClickListener() {
@Override
@ -344,6 +391,10 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
if (iconItems != null) {
setIconNewColor(changedProfile.iconRes);
}
int selectedColor = ContextCompat.getColor(app,
changedProfile.color.getColor(isNightMode()));
profileNameOtfb.setPrimaryColor(selectedColor);
profileName.getBackground().mutate().setColorFilter(selectedColor, PorterDuff.Mode.SRC_ATOP);
updateProfileButton();
}
@ -352,8 +403,9 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
.inflate(R.layout.preference_circle_item, rootView, false);
ImageView checkMark = iconItemView.findViewById(R.id.checkMark);
checkMark.setImageDrawable(app.getUIUtilities().getIcon(iconRes, R.color.icon_color_default_light));
ImageView coloredCircle = iconItemView.findViewById(R.id.bckgroundCircle);
coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light,
ImageView coloredCircle = iconItemView.findViewById(R.id.backgroundCircle);
AndroidUtils.setBackground(coloredCircle,
UiUtilities.tintDrawable(ContextCompat.getDrawable(app, R.drawable.circle_background_light),
UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, R.color.icon_color_default_light), 0.1f)));
coloredCircle.setOnClickListener(new View.OnClickListener() {
@Override
@ -373,8 +425,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
iconItem.findViewById(R.id.outlineCircle).setVisibility(View.GONE);
ImageView checkMark = iconItem.findViewById(R.id.checkMark);
checkMark.setImageDrawable(app.getUIUtilities().getIcon(changedProfile.iconRes, R.color.icon_color_default_light));
ImageView coloredCircle = iconItem.findViewById(R.id.bckgroundCircle);
coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light,
AndroidUtils.setBackground(iconItem.findViewById(R.id.backgroundCircle),
UiUtilities.tintDrawable(ContextCompat.getDrawable(app, R.drawable.circle_background_light),
UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, R.color.icon_color_default_light), 0.1f)));
changedProfile.iconRes = iconRes;
updateProfileButton();
@ -385,8 +437,8 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
app.getDaynightHelper().isNightModeForMapControls()));
View iconItem = iconItems.findViewWithTag(iconRes);
if (iconItem != null) {
ImageView coloredCircle = iconItem.findViewById(R.id.bckgroundCircle);
coloredCircle.setImageDrawable(getPaintedIcon(R.drawable.circle_background_light,
AndroidUtils.setBackground(iconItem.findViewById(R.id.backgroundCircle),
UiUtilities.tintDrawable(ContextCompat.getDrawable(app, R.drawable.circle_background_light),
UiUtilities.getColorWithAlpha(ContextCompat.getColor(app, changedProfile.color.getColor(isNightMode())), 0.1f)));
ImageView outlineCircle = iconItem.findViewById(R.id.outlineCircle);
GradientDrawable circleContourDrawable = (GradientDrawable) ContextCompat.getDrawable(app, R.drawable.circle_contour_bg_light);
@ -487,10 +539,11 @@ public class ProfileAppearanceFragment extends BaseSettingsFragment {
}
public boolean isProfileAppearanceChanged(final MapActivity mapActivity) {
hideKeyboard();
if (isChanged()) {
AlertDialog.Builder dismissDialog = createWarningDialog(getActivity(),
R.string.shared_string_dismiss, R.string.exit_without_saving, R.string.shared_string_cancel);
dismissDialog.setPositiveButton(R.string.shared_string_ok, new DialogInterface.OnClickListener() {
dismissDialog.setPositiveButton(R.string.shared_string_exit, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
changedProfile = profile;

View file

@ -1,4 +1,4 @@
package net.osmand.plus.profiles;
package net.osmand.plus.views.controls;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.helper.ItemTouchHelper;