This commit is contained in:
Chumva 2019-09-30 15:17:15 +03:00
parent ab70f21acb
commit 192f84c80c
12 changed files with 416 additions and 259 deletions

View file

@ -1,9 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/activity_background_color"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/toolbar_height"
android:background="?attr/actionModeBackground"
app:contentInsetLeft="0dp"
app:contentInsetStart="0dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<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="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
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" />
<ImageButton
android:id="@+id/delete_button"
style="@style/Widget.AppCompat.Toolbar.Button.Navigation"
android:layout_width="@dimen/toolbar_height"
android:layout_height="@dimen/toolbar_height"
android:contentDescription="@string/shared_string_delete"
android:src="@drawable/ic_action_delete_dark" />
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/activity_background_color">
@ -379,7 +435,7 @@
android:textColor="@color/description_font_and_bottom_sheet_icons"/>
<LinearLayout
android:id="@+id/map_config_btn"
android:id="@+id/profile_config_btn"
android:layout_width="match_parent"
android:layout_height="65dp"
android:background="?android:attr/selectableItemBackground"
@ -387,133 +443,37 @@
android:orientation="horizontal">
<ImageView
android:id="@+id/map_config_icon"
android:id="@+id/profile_config_icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="@dimen/list_content_padding"
android:layout_marginLeft="@dimen/list_content_padding"
android:src="@drawable/ic_action_layers_dark"
android:src="@drawable/ic_action_settings"
android:tint="?attr/default_icon_color"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="@dimen/list_content_padding"
android:layout_marginLeft="24dp"
android:layout_marginEnd="@dimen/list_content_padding"
android:layout_marginRight="@dimen/list_content_padding"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/configure_map"
android:text="@string/configure_profile"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/edit_profile_setup_map_subtitle"
android:textColor="@color/description_font_and_bottom_sheet_icons"/>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="64dp"
android:layout_marginLeft="64dp"
android:background="?attr/divider_color"/>
<LinearLayout
android:id="@+id/screen_config_btn"
android:layout_width="match_parent"
android:layout_height="64dp"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/screen_config_icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="@dimen/list_content_padding"
android:layout_marginLeft="@dimen/list_content_padding"
android:src="@drawable/ic_configure_screen_dark"
android:tint="?attr/default_icon_color"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="@dimen/list_content_padding"
android:layout_marginLeft="24dp"
android:layout_marginRight="@dimen/list_content_padding"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/map_widget_config"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/edit_profile_screen_options_subtitle"
android:textColor="@color/description_font_and_bottom_sheet_icons"/>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginStart="64dp"
android:layout_marginLeft="64dp"
android:background="?attr/divider_color"
/>
<LinearLayout
android:id="@+id/nav_settings_btn"
android:layout_width="match_parent"
android:layout_height="64dp"
android:background="?android:attr/selectableItemBackground"
android:gravity="center_vertical"
android:orientation="horizontal">
<ImageView
android:id="@+id/nav_settings_icon"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_marginStart="@dimen/list_content_padding"
android:layout_marginLeft="@dimen/list_content_padding"
android:src="@drawable/ic_action_gdirections_dark"
android:tint="?attr/default_icon_color"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginEnd="@dimen/list_content_padding"
android:layout_marginLeft="24dp"
android:layout_marginRight="@dimen/list_content_padding"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/routing_settings_2"
android:textColor="?android:textColorPrimary"
android:textSize="@dimen/default_list_text_size"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/edit_profile_nav_settings_subtitle"
android:textColor="@color/description_font_and_bottom_sheet_icons"/>
android:textColor="@color/description_font_and_bottom_sheet_icons"
android:visibility="gone"
tools:text="@string/configure_profile_info"
tools:visibility="visible" />
</LinearLayout>
</LinearLayout>
@ -613,3 +573,5 @@
</LinearLayout>
</FrameLayout>
</LinearLayout>

View file

@ -1,6 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/activity_background_color"
android:orientation="vertical">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<include layout="@layout/global_preference_toolbar" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?attr/activity_background_color"
@ -48,3 +62,5 @@
</LinearLayout>
</RelativeLayout>
</LinearLayout>

View file

@ -36,6 +36,14 @@
android:title="@string/configure_map"
tools:icon="@drawable/ic_action_layers_dark" />
<Preference
android:key="configure_screen"
android:layout="@layout/preference_with_descr"
android:persistent="false"
android:summary="@string/edit_profile_screen_options_subtitle"
android:title="@string/map_widget_config"
tools:icon="@drawable/ic_configure_screen_dark" />
<Preference
android:layout="@layout/list_item_divider"
android:selectable="false" />

View file

@ -128,6 +128,7 @@ import net.osmand.plus.search.QuickSearchDialogFragment;
import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchTab;
import net.osmand.plus.search.QuickSearchDialogFragment.QuickSearchType;
import net.osmand.plus.settings.BaseSettingsFragment;
import net.osmand.plus.settings.ConfigureProfileFragment;
import net.osmand.plus.settings.MainSettingsFragment;
import net.osmand.plus.views.AddGpxPointBottomSheetHelper.NewGpxPoint;
import net.osmand.plus.views.AnimateDraggingMapThread;
@ -161,6 +162,8 @@ import java.util.concurrent.Executors;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import static net.osmand.plus.OsmAndCustomizationConstants.DRAWER_SETTINGS_ID;
public class MapActivity extends OsmandActionBarActivity implements DownloadEvents,
OnRequestPermissionsResultCallback, IRouteInformationListener, AMapPointUpdateListener,
MapMarkerChangedListener, OnDismissDialogFragmentListener, OnDrawMapListener,
@ -639,6 +642,13 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
chooseRouteFragment.dismiss(true);
return;
}
EditProfileFragment editProfileFragment = getEditProfileFragment();
if (editProfileFragment != null) {
if (!editProfileFragment.onBackPressedAllowed()) {
editProfileFragment.confirmCancelDialog(this);
return;
}
}
if (mapContextMenu.isVisible() && mapContextMenu.isClosable()) {
if (mapContextMenu.getCurrentMenuState() != MenuState.HEADER_ONLY) {
mapContextMenu.openMenuHeaderOnly();
@ -804,6 +814,13 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
}
setIntent(null);
}
if (intent.hasExtra(EditProfileFragment.OPEN_SETTINGS)) {
String settingsType = intent.getStringExtra(EditProfileFragment.OPEN_SETTINGS);
if (EditProfileFragment.OPEN_CONFIG_PROFILE.equals(settingsType)) {
ConfigureProfileFragment.showInstance(getSupportFragmentManager());
}
setIntent(null);
}
if (intent.hasExtra(EditProfileFragment.OPEN_CONFIG_ON_MAP)) {
switch (intent.getStringExtra(EditProfileFragment.OPEN_CONFIG_ON_MAP)) {
case EditProfileFragment.MAP_CONFIG:
@ -995,7 +1012,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 instanceof BaseSettingsFragment
if (fragment != null && !fragment.isRemoving() && fragment.isVisible() && fragment instanceof BaseSettingsFragment
&& ((BaseSettingsFragment) fragment).getStatusBarColorId() != -1) {
return (BaseSettingsFragment) fragment;
}
@ -1957,25 +1974,31 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
@Override
public boolean onPreferenceStartFragment(PreferenceFragmentCompat caller, Preference pref) {
if (caller instanceof BaseSettingsFragment) {
BaseSettingsFragment baseFragment = (BaseSettingsFragment) caller;
ApplicationMode mode = baseFragment.getSelectedAppMode();
if (mode != null) {
try {
String fragmentName = pref.getFragment();
Fragment fragment = Fragment.instantiate(this, fragmentName);
getSupportFragmentManager().beginTransaction()
.replace(R.id.fragmentContainer, fragment, fragmentName)
.addToBackStack(fragmentName)
.commitAllowingStateLoss();
.replace(R.id.fragmentContainer, fragment, fragment.getClass().getSimpleName())
.addToBackStack(DRAWER_SETTINGS_ID + ".new")
.commit();
return true;
} catch (Exception e) {
LOG.error(e);
}
}
return false;
}
public void dismissSettingsScreens() {
try {
getSupportFragmentManager().popBackStack(DRAWER_SETTINGS_ID + ".new", FragmentManager.POP_BACK_STACK_INCLUSIVE);
} catch (Exception e) {
e.printStackTrace();
}
}
private class ScreenOffReceiver extends BroadcastReceiver {
@Override
@ -2193,6 +2216,7 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
}
public void showSettings() {
dismissSettingsScreens();
MainSettingsFragment.showInstance(getSupportFragmentManager());
}
@ -2232,6 +2256,11 @@ public class MapActivity extends OsmandActionBarActivity implements DownloadEven
return fragment != null && !fragment.isDetached() && !fragment.isRemoving() ? (ChooseRouteFragment) fragment : null;
}
public EditProfileFragment getEditProfileFragment() {
Fragment fragment = getSupportFragmentManager().findFragmentByTag(EditProfileFragment.TAG);
return fragment != null && !fragment.isDetached() && !fragment.isRemoving() ? (EditProfileFragment) fragment : null;
}
public boolean isTopToolbarActive() {
MapInfoLayer mapInfoLayer = getMapLayers().getMapInfoLayer();
return mapInfoLayer.hasTopToolbar();

View file

@ -663,6 +663,7 @@ public class MapActivityActions implements DialogProvider {
.setListener(new ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
mapActivity.dismissSettingsScreens();
ConfigureProfileFragment.showInstance(mapActivity.getSupportFragmentManager());
return true;
}

View file

@ -8,14 +8,12 @@ import android.support.v4.view.MenuItemCompat;
import android.view.Menu;
import android.view.MenuItem;
import net.osmand.PlatformUtil;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmandActionBarActivity;
public class EditProfileActivity extends OsmandActionBarActivity {
public static final int DELETE_ID = 1010;
public static final String EDIT_PROFILE_FRAGMENT_TAG = "editProfileFragment";
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
@ -27,7 +25,7 @@ public class EditProfileActivity extends OsmandActionBarActivity {
EditProfileFragment editProfileFragment = new EditProfileFragment();
editProfileFragment.setArguments(getIntent().getExtras());
getSupportFragmentManager().beginTransaction().add(android.R.id.content,
editProfileFragment, EDIT_PROFILE_FRAGMENT_TAG).commit();
editProfileFragment, EditProfileFragment.TAG).commit();
}
}
@ -53,7 +51,7 @@ public class EditProfileActivity extends OsmandActionBarActivity {
return true;
case DELETE_ID:
((EditProfileFragment) getSupportFragmentManager().findFragmentByTag(
EDIT_PROFILE_FRAGMENT_TAG)).onDeleteProfileClick();
EditProfileFragment.TAG)).onDeleteProfileClick();
return true;
}
@ -63,7 +61,7 @@ public class EditProfileActivity extends OsmandActionBarActivity {
@Override
public void onBackPressed() {
final EditProfileFragment epf = (EditProfileFragment) getSupportFragmentManager()
.findFragmentByTag(EDIT_PROFILE_FRAGMENT_TAG);
.findFragmentByTag(EditProfileFragment.TAG);
if (epf.onBackPressedAllowed()) {
super.onBackPressed();
} else {

View file

@ -1,15 +1,5 @@
package net.osmand.plus.profiles;
import static net.osmand.plus.activities.SettingsNavigationActivity.INTENT_SKIP_DIALOG;
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;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_ICON;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_NAV_PROFILE;
import static net.osmand.plus.profiles.SettingsProfileFragment.IS_NEW_PROFILE;
import static net.osmand.plus.profiles.SettingsProfileFragment.IS_USER_PROFILE;
import static net.osmand.plus.profiles.SettingsProfileFragment.PROFILE_STRING_KEY;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
@ -22,17 +12,20 @@ import android.os.Build.VERSION_CODES;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.app.ActionBar;
import android.support.design.widget.AppBarLayout;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewCompat;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AlertDialog.Builder;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.ContextThemeWrapper;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
import android.view.inputmethod.InputMethodManager;
import android.widget.AdapterView;
@ -46,10 +39,7 @@ import android.widget.ListPopupWindow;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode;
@ -57,21 +47,41 @@ import net.osmand.plus.ApplicationMode.ProfileIconColors;
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.helpers.AndroidUiHelper;
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SelectProfileListener;
import net.osmand.plus.routing.RouteProvider.RouteService;
import net.osmand.plus.settings.ConfigureProfileFragment;
import net.osmand.plus.widgets.OsmandTextFieldBoxes;
import net.osmand.router.GeneralRouter;
import net.osmand.util.Algorithms;
import org.apache.commons.logging.Log;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import studio.carbonylgroup.textfieldboxes.ExtendedEditText;
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;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_ICON;
import static net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.TYPE_NAV_PROFILE;
import static net.osmand.plus.profiles.SettingsProfileFragment.IS_NEW_PROFILE;
import static net.osmand.plus.profiles.SettingsProfileFragment.IS_USER_PROFILE;
import static net.osmand.plus.profiles.SettingsProfileFragment.PROFILE_STRING_KEY;
public class EditProfileFragment extends BaseOsmAndFragment {
private static final Log LOG = PlatformUtil.getLog(EditProfileFragment.class);
public static final String TAG = EditProfileFragment.class.getSimpleName();
public static final String OPEN_CONFIG_PROFILE = "openConfigProfile";
public static final String OPEN_SETTINGS = "openSettings";
public static final String OPEN_CONFIG_ON_MAP = "openConfigOnMap";
public static final String MAP_CONFIG = "openMapConfigMenu";
public static final String NAV_CONFIG = "openNavConfigMenu";
@ -96,6 +106,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
private SelectProfileListener iconIdListener = null;
private SelectProfileListener baseTypeListener = null;
private TextView toolbarTitle;
private ImageView profileIcon;
private LinearLayout profileIconBtn;
private ImageView colorSample;
@ -107,9 +118,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
private FrameLayout selectNavTypeBtn;
private Button cancelBtn;
private Button saveButton;
private View mapConfigBtn;
private View screenConfigBtn;
private View navConfigBtn;
private View profileConfigBtn;
private LinearLayout buttonsLayout;
private FrameLayout clickBlockLayout;
private LinearLayout typeSelectionBtn;
@ -139,9 +148,15 @@ public class EditProfileFragment extends BaseOsmAndFragment {
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
final EditProfileActivity activity = (EditProfileActivity) getActivity();
final View view = inflater.inflate(R.layout.fragment_selected_profile, container, false);
final FragmentActivity activity = getActivity();
int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
Context themedContext = new ContextThemeWrapper(getContext(), themeRes);
final View view = inflater.cloneInContext(themedContext).inflate(R.layout.fragment_selected_profile, container, false);
setupToolbar(view);
toolbarTitle = view.findViewById(R.id.toolbar_title);
profileIcon = view.findViewById(R.id.profile_icon_img);
profileIconBtn = view.findViewById(R.id.select_icon_button);
colorSample = view.findViewById(R.id.color_sample_img);
@ -153,9 +168,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
selectNavTypeBtn = view.findViewById(R.id.select_nav_type_btn);
cancelBtn = view.findViewById(R.id.cancel_button);
saveButton = view.findViewById(R.id.save_profile_btn);
mapConfigBtn = view.findViewById(R.id.map_config_btn);
screenConfigBtn = view.findViewById(R.id.screen_config_btn);
navConfigBtn = view.findViewById(R.id.nav_settings_btn);
profileConfigBtn = view.findViewById(R.id.profile_config_btn);
buttonsLayout = view.findViewById(R.id.buttons_layout);
clickBlockLayout = view.findViewById(R.id.click_block_layout);
typeSelectionBtn = view.findViewById(R.id.type_selection_button);
@ -242,11 +255,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
}
profileNameEt.clearFocus();
if (getActivity() != null
&& ((EditProfileActivity) getActivity()).getSupportActionBar() != null) {
((EditProfileActivity) getActivity()).getSupportActionBar().setTitle(title);
((EditProfileActivity) getActivity()).getSupportActionBar().setElevation(5.0f);
}
updateToolbar(title);
int iconColor = profile.iconColor.getColor(nightMode);
@ -264,15 +273,10 @@ public class EditProfileFragment extends BaseOsmAndFragment {
@Override
public void afterTextChanged(Editable s) {
if (getActivity() instanceof OsmandActionBarActivity) {
ActionBar actionBar = ((OsmandActionBarActivity) getActivity())
.getSupportActionBar();
if (actionBar != null) {
actionBar.setTitle(s.toString());
profile.userProfileTitle = s.toString();
isCancelAllowed = false;
}
}
updateToolbar(s.toString());
}
});
@ -358,7 +362,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
}
mapConfigBtn.setOnClickListener(new OnClickListener() {
profileConfigBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (isDataChanged) {
@ -366,43 +370,18 @@ public class EditProfileFragment extends BaseOsmAndFragment {
} else if (getSettings() != null) {
activateMode(mode);
getSettings().APPLICATION_MODE.set(mode);
Intent i = new Intent(getActivity(), MapActivity.class);
i.putExtra(OPEN_CONFIG_ON_MAP, MAP_CONFIG);
i.putExtra(SELECTED_ITEM, profile.stringKey);
startActivity(i);
}
}
});
screenConfigBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (isDataChanged) {
needSaveDialog();
} else if (getSettings() != null) {
activateMode(mode);
getSettings().APPLICATION_MODE.set(mode);
if (activity instanceof EditProfileActivity) {
Intent i = new Intent(getActivity(), MapActivity.class);
i.putExtra(OPEN_CONFIG_ON_MAP, SCREEN_CONFIG);
i.putExtra(OPEN_SETTINGS, OPEN_CONFIG_PROFILE);
i.putExtra(SELECTED_ITEM, profile.stringKey);
startActivity(i);
} else {
FragmentManager fragmentManager = getFragmentManager();
if (fragmentManager != null) {
ConfigureProfileFragment.showInstance(fragmentManager);
}
}
});
navConfigBtn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
if (isDataChanged) {
needSaveDialog();
} else if (getSettings() != null) {
activateMode(mode);
getSettings().APPLICATION_MODE.set(mode);
Intent i = new Intent(getActivity(), SettingsNavigationActivity.class);
i.putExtra(INTENT_SKIP_DIALOG, true);
i.putExtra(OPEN_CONFIG_ON_MAP, NAV_CONFIG);
i.putExtra(SELECTED_ITEM, profile.stringKey);
startActivity(i);
}
}
});
@ -450,13 +429,13 @@ public class EditProfileFragment extends BaseOsmAndFragment {
});
}
final float d = getResources().getDisplayMetrics().density;
view.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
int marginShow = 66;
int marginHide = 0;
float d = getResources().getDisplayMetrics().density;
Rect r = new Rect();
view.getWindowVisibleDisplayFrame(r);
int screenHeight = view.getRootView().getHeight();
@ -483,7 +462,12 @@ public class EditProfileFragment extends BaseOsmAndFragment {
super.onResume();
}
boolean onBackPressedAllowed() {
@Override
public int getStatusBarColorId() {
return nightMode ? R.color.status_bar_color_dark : R.color.status_bar_color_light;
}
public boolean onBackPressedAllowed() {
return isCancelAllowed;
}
@ -567,6 +551,54 @@ public class EditProfileFragment extends BaseOsmAndFragment {
}
}
private void setupToolbar(View view) {
FragmentActivity activity = getActivity();
AppBarLayout appBar = (AppBarLayout) view.findViewById(R.id.appbar);
if ((activity instanceof EditProfileActivity)) {
EditProfileActivity editProfileActivity = (EditProfileActivity) activity;
if (editProfileActivity.getSupportActionBar() != null) {
editProfileActivity.getSupportActionBar().setElevation(5.0f);
}
AndroidUiHelper.updateVisibility(appBar, false);
} else {
setHasOptionsMenu(true);
AndroidUtils.addStatusBarPadding21v(activity, view);
ViewCompat.setElevation(appBar, 5.0f);
View closeButton = view.findViewById(R.id.close_button);
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentActivity fragmentActivity = getActivity();
if (fragmentActivity != null) {
fragmentActivity.onBackPressed();
}
}
});
View deleteBtn = view.findViewById(R.id.delete_button);
deleteBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
onDeleteProfileClick();
}
});
}
}
private void updateToolbar(String title) {
FragmentActivity activity = getActivity();
if (activity instanceof EditProfileActivity) {
EditProfileActivity editProfileActivity = (EditProfileActivity) activity;
if (editProfileActivity.getSupportActionBar() != null) {
editProfileActivity.getSupportActionBar().setTitle(title);
}
} else {
toolbarTitle.setText(title);
}
}
private void setupBaseProfileView(String stringKey) {
for (ApplicationMode am : ApplicationMode.getDefaultValues()) {
if (am.getStringKey().equals(stringKey)) {
@ -671,7 +703,7 @@ public class EditProfileFragment extends BaseOsmAndFragment {
bld.show();
}
void confirmCancelDialog(final Activity activity) {
public void confirmCancelDialog(final Activity activity) {
AlertDialog.Builder bld = new Builder(activity);
bld.setTitle(R.string.shared_string_dismiss);
bld.setMessage(R.string.exit_without_saving);
@ -699,12 +731,15 @@ public class EditProfileFragment extends BaseOsmAndFragment {
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
ApplicationMode
.deleteCustomMode(mode, getMyApplication());
OsmandApplication app = getMyApplication();
if (app != null) {
ApplicationMode.deleteCustomMode(mode, app);
app.getSettings().APPLICATION_MODE.set(ApplicationMode.DEFAULT);
}
if (getActivity() != null) {
getActivity().onBackPressed();
}
getSettings().APPLICATION_MODE.set(ApplicationMode.DEFAULT);
}
});
bld.setNegativeButton(R.string.shared_string_dismiss, null);
@ -726,6 +761,26 @@ public class EditProfileFragment extends BaseOsmAndFragment {
}
}
public static boolean showInstance(FragmentManager fragmentManager, boolean newProfile, boolean userProfile, String profileKey) {
try {
Bundle args = new Bundle();
args.putBoolean(IS_NEW_PROFILE, newProfile);
args.putBoolean(IS_USER_PROFILE, userProfile);
args.putString(PROFILE_STRING_KEY, profileKey);
EditProfileFragment editProfileFragment = new EditProfileFragment();
editProfileFragment.setArguments(args);
fragmentManager.beginTransaction()
.replace(R.id.fragmentContainer, editProfileFragment, TAG)
.addToBackStack(TAG)
.commit();
return true;
} catch (Exception e) {
return false;
}
}
static List<RoutingProfileDataObject> getRoutingProfiles(OsmandApplication context) {
List<RoutingProfileDataObject> profilesObjects = new ArrayList<>();
profilesObjects.add(new RoutingProfileDataObject(

View file

@ -7,16 +7,13 @@ import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.SwitchCompat;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.OsmandApplication;
import net.osmand.plus.R;
import net.osmand.plus.base.MenuBottomSheetDialogFragment;
@ -217,20 +214,29 @@ public class SelectProfileBottomSheetDialogFragment extends MenuBottomSheetDialo
private void getListener() {
if (getActivity() != null && getActivity() instanceof EditProfileActivity) {
EditProfileFragment f = (EditProfileFragment) getActivity().getSupportFragmentManager()
.findFragmentByTag(EditProfileActivity.EDIT_PROFILE_FRAGMENT_TAG);
if (type.equals(TYPE_BASE_APP_PROFILE)) {
listener = f.getBaseProfileListener();
} else if (type.equals(TYPE_NAV_PROFILE)) {
listener = f.getNavProfileListener();
} else if (type.equals(TYPE_ICON)) {
listener = f.getIconListener();
FragmentActivity activity = getActivity();
if (activity != null) {
FragmentManager fragmentManager = activity.getSupportFragmentManager();
if (fragmentManager != null) {
EditProfileFragment editProfileFragment = (EditProfileFragment) fragmentManager.findFragmentByTag(EditProfileFragment.TAG);
SettingsProfileFragment settingsProfileFragment = (SettingsProfileFragment) fragmentManager.findFragmentByTag(SettingsProfileFragment.TAG);
if (editProfileFragment != null) {
switch (type) {
case TYPE_BASE_APP_PROFILE:
listener = editProfileFragment.getBaseProfileListener();
break;
case TYPE_NAV_PROFILE:
listener = editProfileFragment.getNavProfileListener();
break;
case TYPE_ICON:
listener = editProfileFragment.getIconListener();
break;
}
} else if (settingsProfileFragment != null) {
listener = settingsProfileFragment.getBaseProfileListener();
}
}
} else if (getActivity() != null && getActivity() instanceof SettingsProfileActivity) {
SettingsProfileFragment f = (SettingsProfileFragment) getActivity().getSupportFragmentManager()
.findFragmentByTag(SettingsProfileActivity.SETTINGS_PROFILE_FRAGMENT_TAG);
listener = f.getBaseProfileListener();
}
}

View file

@ -2,13 +2,12 @@ package net.osmand.plus.profiles;
import android.os.Bundle;
import android.view.MenuItem;
import net.osmand.plus.R;
import net.osmand.plus.activities.OsmandActionBarActivity;
public class SettingsProfileActivity extends OsmandActionBarActivity {
public static final String SETTINGS_PROFILE_FRAGMENT_TAG = "settingsProfileFragment";
@Override
public void onCreate(Bundle savedInstanceState) {
getMyApplication().applyTheme(this);
@ -20,7 +19,7 @@ public class SettingsProfileActivity extends OsmandActionBarActivity {
SettingsProfileFragment profileFragment = new SettingsProfileFragment();
profileFragment.setArguments(getIntent().getExtras());
getSupportFragmentManager().beginTransaction()
.add(android.R.id.content, profileFragment, SETTINGS_PROFILE_FRAGMENT_TAG).commit();
.add(android.R.id.content, profileFragment, SettingsProfileFragment.TAG).commit();
}
}

View file

@ -10,21 +10,32 @@ import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.AppBarLayout;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v4.view.ViewCompat;
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.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;
import net.osmand.AndroidUtils;
import net.osmand.PlatformUtil;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.R;
import net.osmand.plus.activities.MapActivity;
import net.osmand.plus.base.BaseOsmAndFragment;
import net.osmand.plus.helpers.AndroidUiHelper;
import net.osmand.plus.profiles.SelectProfileBottomSheetDialogFragment.SelectProfileListener;
import org.apache.commons.logging.Log;
@ -34,21 +45,22 @@ public class SettingsProfileFragment extends BaseOsmAndFragment
private static final Log LOG = PlatformUtil.getLog(SettingsProfileFragment.class);
public static final String TAG = "SettingsProfileFragment";
public static final String PROFILE_STRING_KEY = "string_key";
public static final String IS_NEW_PROFILE = "new_profile";
public static final String IS_USER_PROFILE = "user_profile";
private ConfigureProfileMenuAdapter adapter;
private RecyclerView recyclerView;
private LinearLayout addNewProfileBtn;
SelectProfileListener typeListener = null;
private SelectProfileListener typeListener = null;
private List<ApplicationMode> allAppModes;
private Set<ApplicationMode> availableAppModes;
private List<ProfileDataObject> baseProfiles;
private boolean nightMode;
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@ -63,10 +75,36 @@ public class SettingsProfileFragment extends BaseOsmAndFragment
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
@Nullable Bundle savedInstanceState) {
nightMode = !requireSettings().isLightContent();
View view = inflater.inflate(R.layout.profiles_list_fragment, container, false);
recyclerView = view.findViewById(R.id.profiles_list);
addNewProfileBtn = view.findViewById(R.id.add_profile_btn);
int themeRes = nightMode ? R.style.OsmandDarkTheme : R.style.OsmandLightTheme;
Context themedContext = new ContextThemeWrapper(getContext(), themeRes);
View view = inflater.cloneInContext(themedContext).inflate(R.layout.profiles_list_fragment, container, false);
AppBarLayout appBar = (AppBarLayout) view.findViewById(R.id.appbar);
if (!(getActivity() instanceof SettingsProfileActivity)) {
AndroidUtils.addStatusBarPadding21v(getContext(), view);
ViewCompat.setElevation(appBar, 5.0f);
TextView toolbarTitle = (TextView) view.findViewById(R.id.toolbar_title);
toolbarTitle.setText(R.string.application_profiles);
View closeButton = view.findViewById(R.id.close_button);
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MapActivity mapActivity = (MapActivity) getActivity();
if (mapActivity != null) {
mapActivity.onBackPressed();
}
}
});
} else {
AndroidUiHelper.updateVisibility(appBar, false);
}
RecyclerView recyclerView = view.findViewById(R.id.profiles_list);
LinearLayout addNewProfileBtn = view.findViewById(R.id.add_profile_btn);
addNewProfileBtn.setOnClickListener(new OnClickListener() {
@ -102,16 +140,32 @@ public class SettingsProfileFragment extends BaseOsmAndFragment
adapter.updateItemsList(allAppModes, new LinkedHashSet<>(ApplicationMode.values(getMyApplication())));
}
@Override
public int getStatusBarColorId() {
return nightMode ? R.color.status_bar_color_dark : R.color.status_bar_color_light;
}
SelectProfileListener getBaseProfileListener() {
if (typeListener == null) {
typeListener = new SelectProfileListener() {
@Override
public void onSelectedType(int pos, String stringRes) {
FragmentActivity activity = getActivity();
if (activity != null) {
if (activity instanceof SettingsProfileActivity) {
Intent intent = new Intent(getActivity(), EditProfileActivity.class);
intent.putExtra(IS_NEW_PROFILE, true);
intent.putExtra(IS_USER_PROFILE, true);
intent.putExtra(PROFILE_STRING_KEY, baseProfiles.get(pos).getStringKey());
startActivity(intent);
activity.startActivity(intent);
} else {
FragmentManager fragmentManager = activity.getSupportFragmentManager();
if (fragmentManager != null) {
String profileKey = baseProfiles.get(pos).getStringKey();
EditProfileFragment.showInstance(fragmentManager, true, true, profileKey);
}
}
}
}
};
}
@ -131,17 +185,28 @@ public class SettingsProfileFragment extends BaseOsmAndFragment
@Override
public void onProfilePressed(ApplicationMode item) {
FragmentActivity activity = getActivity();
if (activity != null) {
if (activity instanceof SettingsProfileActivity) {
Intent intent = new Intent(getActivity(), EditProfileActivity.class);
intent.putExtra(PROFILE_STRING_KEY, item.getStringKey());
if (item.isCustomProfile()) {
intent.putExtra(IS_USER_PROFILE, true);
}
startActivity(intent);
activity.startActivity(intent);
} else {
FragmentManager fragmentManager = activity.getSupportFragmentManager();
if (fragmentManager != null) {
String profileKey = item.getStringKey();
EditProfileFragment.showInstance(fragmentManager, false, item.isCustomProfile(), profileKey);
}
}
}
}
@Override
public void onProfileSelected(ApplicationMode item, boolean isChecked) {
if(isChecked) {
if (isChecked) {
availableAppModes.add(item);
} else {
availableAppModes.remove(item);

View file

@ -43,6 +43,7 @@ import java.util.List;
import static net.osmand.plus.profiles.EditProfileFragment.MAP_CONFIG;
import static net.osmand.plus.profiles.EditProfileFragment.OPEN_CONFIG_ON_MAP;
import static net.osmand.plus.profiles.EditProfileFragment.SCREEN_CONFIG;
import static net.osmand.plus.profiles.EditProfileFragment.SELECTED_ITEM;
public class ConfigureProfileFragment extends BaseSettingsFragment {
@ -53,6 +54,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
private static final String PLUGIN_SETTINGS = "plugin_settings";
private static final String CONFIGURE_MAP = "configure_map";
private static final String CONFIGURE_SCREEN = "configure_screen";
@Override
protected String getFragmentTag() {
@ -181,6 +183,7 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
setupNavigationSettingsPref();
setupConfigureMapPref();
setupConfigureScreenPref();
PreferenceCategory pluginSettings = (PreferenceCategory) findPreference(PLUGIN_SETTINGS);
pluginSettings.setIconSpaceReserved(false);
@ -209,6 +212,20 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
configureMap.setIntent(intent);
}
private void setupConfigureScreenPref() {
Context ctx = getContext();
if (ctx == null) {
return;
}
Preference configureMap = findPreference(CONFIGURE_SCREEN);
configureMap.setIcon(getContentIcon(R.drawable.ic_configure_screen_dark));
Intent intent = new Intent(ctx, MapActivity.class);
intent.putExtra(OPEN_CONFIG_ON_MAP, SCREEN_CONFIG);
intent.putExtra(SELECTED_ITEM, getSelectedAppMode().getStringKey());
configureMap.setIntent(intent);
}
private void setupConnectedAppsPref(PreferenceCategory preferenceCategory) {
OsmandApplication app = getMyApplication();
if (app == null) {
@ -267,7 +284,9 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
@Override
public boolean onPreferenceClick(Preference preference) {
if (CONFIGURE_MAP.equals(preference.getKey())) {
String prefId = preference.getKey();
if (CONFIGURE_MAP.equals(prefId) || CONFIGURE_SCREEN.equals(prefId)) {
FragmentActivity activity = getActivity();
if (activity != null) {
try {
@ -297,7 +316,6 @@ public class ConfigureProfileFragment extends BaseSettingsFragment {
if ((plugin.isActive() || !plugin.needsInstallation())) {
if (OsmandPlugin.enablePlugin(getActivity(), app, plugin, (Boolean) newValue)) {
preference.setIcon(getPluginIcon(plugin));
updatePreference(preference);
return true;
}
} else if (plugin.needsInstallation() && preference.getIntent() != null) {

View file

@ -1,6 +1,5 @@
package net.osmand.plus.settings;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Build;
@ -14,7 +13,7 @@ import net.osmand.AndroidUtils;
import net.osmand.plus.ApplicationMode;
import net.osmand.plus.R;
import net.osmand.plus.UiUtilities;
import net.osmand.plus.profiles.SettingsProfileActivity;
import net.osmand.plus.profiles.SettingsProfileFragment;
public class MainSettingsFragment extends BaseSettingsFragment {
@ -89,7 +88,7 @@ public class MainSettingsFragment extends BaseSettingsFragment {
private void setupManageProfilesPref() {
Preference manageProfiles = findPreference("manage_profiles");
manageProfiles.setIcon(getIcon(R.drawable.ic_action_manage_profiles));
manageProfiles.setIntent(new Intent(getActivity(), SettingsProfileActivity.class));
manageProfiles.setFragment(SettingsProfileFragment.class.getName());
}
private void setupConfigureProfilePref() {
@ -111,7 +110,8 @@ public class MainSettingsFragment extends BaseSettingsFragment {
fragmentManager.beginTransaction()
.replace(R.id.fragmentContainer, MainSettingsFragment, TAG)
.addToBackStack(TAG)
.commitAllowingStateLoss();
.commit();
return true;
} catch (Exception e) {
return false;