use of net.osmand.plus.profiles.data.ProfileDataObject in project Osmand by osmandapp.
the class MapActivityActions method createSwitchProfileOptionsMenu.
private ContextMenuAdapter createSwitchProfileOptionsMenu(final OsmandApplication app, ContextMenuAdapter optionsMenuHelper, boolean nightMode) {
drawerMode = DRAWER_MODE_NORMAL;
createProfilesController(app, optionsMenuHelper, nightMode, true);
List<ApplicationMode> activeModes = ApplicationMode.values(app);
ApplicationMode currentMode = app.getSettings().APPLICATION_MODE.get();
String modeDescription;
Map<String, ProfileDataObject> profilesObjects = routingDataUtils.getRoutingProfiles();
for (final ApplicationMode appMode : activeModes) {
if (appMode.isCustomProfile()) {
modeDescription = getProfileDescription(app, appMode, profilesObjects, getString(R.string.profile_type_user_string));
} else {
modeDescription = getProfileDescription(app, appMode, profilesObjects, getString(R.string.profile_type_osmand_string));
}
int tag = currentMode.equals(appMode) ? PROFILES_CHOSEN_PROFILE_TAG : PROFILES_NORMAL_PROFILE_TAG;
optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.profile_list_item).setIcon(appMode.getIconRes()).setColor(appMode.getProfileColor(nightMode)).setTag(tag).setTitle(appMode.toHumanString()).setDescription(modeDescription).setListener(new ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
app.getSettings().setApplicationMode(appMode);
updateDrawerMenu();
return false;
}
}).createItem());
}
optionsMenuHelper.addItem(new ItemBuilder().setLayout(R.layout.profile_list_item).setColor(ColorUtilities.getActiveColor(app, nightMode)).setTag(PROFILES_CONTROL_BUTTON_TAG).setTitle(getString(R.string.shared_string_manage)).setListener(new ItemClickListener() {
@Override
public boolean onContextMenuClick(ArrayAdapter<ContextMenuItem> adapter, int itemId, int position, boolean isChecked, int[] viewCoordinates) {
BaseSettingsFragment.showInstance(mapActivity, BaseSettingsFragment.SettingsScreenType.MAIN_SETTINGS);
return true;
}
}).createItem());
return optionsMenuHelper;
}
use of net.osmand.plus.profiles.data.ProfileDataObject in project Osmand by osmandapp.
the class SelectNavProfileBottomSheet method addNonePredefinedView.
private void addNonePredefinedView() {
int padding = getDimen(R.dimen.content_padding_half);
addGroupHeader(getString(R.string.shared_string_predefined));
addMessageWithRoundedBackground(getString(R.string.failed_loading_predefined_engines), 0, padding);
if (OnlineRoutingEngine.isPredefinedEngineKey(selectedItemKey)) {
ProfileDataObject selectedProfile = getDataUtils().getOnlineEngineByKey(selectedItemKey);
addProfileItem(selectedProfile);
}
addDivider();
}
use of net.osmand.plus.profiles.data.ProfileDataObject in project Osmand by osmandapp.
the class SelectMultipleProfilesBottomSheet method refreshProfiles.
private void refreshProfiles(OsmandApplication app) {
profiles.clear();
List<ApplicationMode> appModes = ApplicationMode.allPossibleValues();
profiles.addAll(ProfileDataUtils.getDataObjects(app, appModes));
for (ProfileDataObject profile : profiles) {
String key = profile.getStringKey();
profile.setSelected(selectedProfiles.contains(key));
profile.setEnabled(!disabledProfiles.contains(key));
}
}
use of net.osmand.plus.profiles.data.ProfileDataObject in project Osmand by osmandapp.
the class EditProfilesFragment method onCreateView.
@Nullable
@Override
public View onCreateView(@NonNull final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
OsmandApplication app = requireMyApplication();
if (savedInstanceState != null && savedInstanceState.containsKey(APP_MODES_ORDER_KEY) && savedInstanceState.containsKey(DELETED_APP_MODES_KEY)) {
appModesOrders = (HashMap<String, Integer>) savedInstanceState.getSerializable(APP_MODES_ORDER_KEY);
deletedModesKeys = savedInstanceState.getStringArrayList(DELETED_APP_MODES_KEY);
} else {
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
appModesOrders.put(mode.getStringKey(), mode.getOrder());
}
}
nightMode = !app.getSettings().isLightContent();
View mainView = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.edit_arrangement_list_fragment, container, false);
AppBarLayout appbar = mainView.findViewById(R.id.appbar);
View toolbar = UiUtilities.getInflater(getContext(), nightMode).inflate(R.layout.global_preference_toolbar, container, false);
appbar.addView(toolbar);
ImageButton closeButton = mainView.findViewById(R.id.close_button);
closeButton.setImageResource(R.drawable.ic_action_remove_dark);
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentActivity fragmentActivity = getActivity();
if (fragmentActivity != null) {
fragmentActivity.onBackPressed();
}
}
});
TextView toolbarTitle = mainView.findViewById(R.id.toolbar_title);
toolbarTitle.setText(R.string.edit_profiles);
RecyclerView recyclerView = mainView.findViewById(R.id.profiles_list);
recyclerView.setLayoutManager(new LinearLayoutManager(getContext()));
adapter = new EditProfilesAdapter(app);
updateItems();
final ItemTouchHelper touchHelper = new ItemTouchHelper(new ReorderItemTouchHelperCallback(adapter));
touchHelper.attachToRecyclerView(recyclerView);
adapter.setAdapterListener(new ProfilesAdapterListener() {
private int fromPosition;
private int toPosition;
@Override
public void onDragStarted(RecyclerView.ViewHolder holder) {
fromPosition = holder.getAdapterPosition();
touchHelper.startDrag(holder);
}
@Override
public void onDragOrSwipeEnded(RecyclerView.ViewHolder holder) {
toPosition = holder.getAdapterPosition();
if (toPosition >= 0 && fromPosition >= 0 && toPosition != fromPosition) {
adapter.notifyDataSetChanged();
}
}
@Override
public void onButtonClicked(int pos) {
Object item = adapter.getItem(pos);
if (item instanceof EditProfileDataObject) {
EditProfileDataObject profileDataObject = (EditProfileDataObject) item;
profileDataObject.toggleDeleted();
if (profileDataObject.deleted) {
deletedModesKeys.add(profileDataObject.getStringKey());
} else {
deletedModesKeys.remove(profileDataObject.getStringKey());
}
updateItems();
}
}
});
recyclerView.setAdapter(adapter);
View cancelButton = mainView.findViewById(R.id.dismiss_button);
UiUtilities.setupDialogButton(nightMode, cancelButton, UiUtilities.DialogButtonType.SECONDARY, R.string.shared_string_cancel);
cancelButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
FragmentActivity fragmentActivity = getActivity();
if (fragmentActivity != null) {
fragmentActivity.onBackPressed();
}
}
});
mainView.findViewById(R.id.buttons_divider).setVisibility(View.VISIBLE);
View applyButton = mainView.findViewById(R.id.right_bottom_button);
UiUtilities.setupDialogButton(nightMode, applyButton, UiUtilities.DialogButtonType.PRIMARY, R.string.shared_string_apply);
applyButton.setVisibility(View.VISIBLE);
applyButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
MapActivity mapActivity = (MapActivity) getActivity();
if (mapActivity != null) {
OsmandApplication app = mapActivity.getMyApplication();
if (!deletedModesKeys.isEmpty()) {
List<ApplicationMode> deletedModes = new ArrayList<>();
for (String modeKey : deletedModesKeys) {
ApplicationMode mode = ApplicationMode.valueOfStringKey(modeKey, null);
if (mode != null) {
deletedModes.add(mode);
}
}
ApplicationMode.deleteCustomModes(deletedModes, app);
}
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
String modeKey = mode.getStringKey();
Integer order = appModesOrders.get(modeKey);
if (order == null) {
order = mode.getOrder();
}
mode.setOrder(order);
}
ApplicationMode.reorderAppModes();
mapActivity.onBackPressed();
}
}
});
if (Build.VERSION.SDK_INT >= 21) {
AndroidUtils.addStatusBarPadding21v(app, mainView);
}
return mainView;
}
use of net.osmand.plus.profiles.data.ProfileDataObject in project Osmand by osmandapp.
the class SelectNavProfileBottomSheet method createProfilesList.
private void createProfilesList() {
for (ProfilesGroup group : profileGroups) {
List<ProfileDataObject> items = group.getProfiles();
if (!Algorithms.isEmpty(items)) {
addGroupHeader(group.getTitle(), group.getDescription(app, nightMode));
for (ProfileDataObject item : items) {
addProfileItem(item);
}
addDivider();
}
}
}
Aggregations