use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class RasterMapMenu method createLayersItems.
private static void createLayersItems(final ContextMenuAdapter contextMenuAdapter, final MapActivity mapActivity, final RasterMapType type) {
final OsmandApplication app = mapActivity.getMyApplication();
final OsmandSettings settings = app.getSettings();
final OsmandRasterMapsPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class);
assert plugin != null;
final OsmandSettings.CommonPreference<Integer> mapTransparencyPreference;
final OsmandSettings.CommonPreference<String> mapTypePreference;
final OsmandSettings.CommonPreference<String> exMapTypePreference;
final LayerTransparencySeekbarMode currentMapTypeSeekbarMode = type == RasterMapType.OVERLAY ? LayerTransparencySeekbarMode.OVERLAY : LayerTransparencySeekbarMode.UNDERLAY;
@StringRes final int mapTypeString;
@StringRes final int mapTypeStringTransparency;
if (type == RasterMapType.OVERLAY) {
mapTransparencyPreference = settings.MAP_OVERLAY_TRANSPARENCY;
mapTypePreference = settings.MAP_OVERLAY;
exMapTypePreference = settings.MAP_OVERLAY_PREVIOUS;
mapTypeString = R.string.map_overlay;
mapTypeStringTransparency = R.string.overlay_transparency;
} else if (type == RasterMapType.UNDERLAY) {
mapTransparencyPreference = settings.MAP_TRANSPARENCY;
mapTypePreference = settings.MAP_UNDERLAY;
exMapTypePreference = settings.MAP_UNDERLAY_PREVIOUS;
mapTypeString = R.string.map_underlay;
mapTypeStringTransparency = R.string.map_transparency;
} else {
throw new RuntimeException("Unexpected raster map type");
}
final OsmandSettings.CommonPreference<Boolean> hidePolygonsPref = mapActivity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons");
String mapTypeDescr = mapTypePreference.get();
final boolean selected = mapTypeDescr != null;
final int toggleActionStringId = selected ? R.string.shared_string_enabled : R.string.shared_string_disabled;
final OnMapSelectedCallback onMapSelectedCallback = new OnMapSelectedCallback() {
@Override
public void onMapSelected(boolean canceled) {
if (type == RasterMapType.UNDERLAY && !canceled && !selected) {
hidePolygonsPref.set(true);
refreshMapComplete(mapActivity);
} else if (type == RasterMapType.UNDERLAY && !canceled && mapTypePreference.get() == null) {
hidePolygonsPref.set(false);
refreshMapComplete(mapActivity);
}
mapActivity.getDashboard().refreshContent(true);
}
};
final MapActivityLayers mapLayers = mapActivity.getMapLayers();
ContextMenuAdapter.OnRowItemClick l = new ContextMenuAdapter.OnRowItemClick() {
@Override
public boolean onRowItemClick(ArrayAdapter<ContextMenuItem> adapter, View view, int itemId, int pos) {
if (itemId == mapTypeString) {
if (selected) {
plugin.selectMapOverlayLayer(mapActivity.getMapView(), mapTypePreference, exMapTypePreference, true, mapActivity, onMapSelectedCallback);
}
return false;
}
return super.onRowItemClick(adapter, view, itemId, pos);
}
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> adapter, final int itemId, final int pos, final boolean isChecked, int[] viewCoordinates) {
if (itemId == toggleActionStringId) {
app.runInUIThread(new Runnable() {
@Override
public void run() {
plugin.toggleUnderlayState(mapActivity, type, onMapSelectedCallback);
refreshMapComplete(mapActivity);
}
});
} else if (itemId == R.string.show_polygons) {
hidePolygonsPref.set(!isChecked);
refreshMapComplete(mapActivity);
} else if (itemId == R.string.show_transparency_seekbar) {
settings.LAYER_TRANSPARENCY_SEEKBAR_MODE.set(isChecked ? currentMapTypeSeekbarMode : LayerTransparencySeekbarMode.OFF);
if (isChecked) {
mapLayers.getMapControlsLayer().showTransparencyBar(mapTransparencyPreference);
} else {
mapLayers.getMapControlsLayer().hideTransparencyBar(mapTransparencyPreference);
}
mapLayers.getMapControlsLayer().setTransparencyBarEnabled(isChecked);
}
return false;
}
};
mapTypeDescr = selected ? mapTypeDescr : mapActivity.getString(R.string.shared_string_none);
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(toggleActionStringId, mapActivity).hideDivider(true).setListener(l).setSelected(selected).createItem());
if (selected) {
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(mapTypeString, mapActivity).hideDivider(true).setListener(l).setLayout(R.layout.list_item_icon_and_menu_wide).setDescription(mapTypeDescr).createItem());
ContextMenuAdapter.OnIntegerValueChangedListener integerListener = new ContextMenuAdapter.OnIntegerValueChangedListener() {
@Override
public boolean onIntegerValueChangedListener(int newValue) {
mapTransparencyPreference.set(newValue);
mapActivity.getMapView().refreshMap();
return false;
}
};
// android:max="255" in layout is expected
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(mapTypeStringTransparency, mapActivity).hideDivider(true).setLayout(R.layout.list_item_progress).setIcon(R.drawable.ic_action_opacity).setProgress(mapTransparencyPreference.get()).setListener(l).setIntegerListener(integerListener).createItem());
if (type == RasterMapType.UNDERLAY) {
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.show_polygons, mapActivity).hideDivider(true).setListener(l).setSelected(!hidePolygonsPref.get()).createItem());
}
Boolean transparencySwitchState = isSeekbarVisible(app, type);
contextMenuAdapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.show_transparency_seekbar, mapActivity).hideDivider(true).setListener(l).setSelected(transparencySwitchState).createItem());
}
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class DashDashboardOrDrawerFragment method initView.
@Override
public View initView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = getActivity().getLayoutInflater().inflate(R.layout.dash_dashboard_or_drawer_fragment, container, false);
view.findViewById(R.id.useDashboardButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final OsmandSettings settings = getMyApplication().getSettings();
settings.SHOW_DASHBOARD_ON_START.set(true);
settings.SHOW_DASHBOARD_ON_MAP_SCREEN.set(true);
settings.SHOW_CARD_TO_CHOOSE_DRAWER.set(false);
dashboard.hideFragmentByTag(TAG);
}
});
view.findViewById(R.id.useDrawerButton).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final OsmandSettings settings = getMyApplication().getSettings();
settings.SHOW_DASHBOARD_ON_START.set(false);
settings.SHOW_DASHBOARD_ON_MAP_SCREEN.set(false);
settings.SHOW_CARD_TO_CHOOSE_DRAWER.set(false);
dashboard.hideDashboard();
}
});
return view;
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class DashboardOnMap method removeMapillaryFiltersFragment.
private void removeMapillaryFiltersFragment() {
FragmentManager manager = mapActivity.getSupportFragmentManager();
Fragment mapillaryFragment = manager.findFragmentByTag(MapillaryFiltersFragment.TAG);
if (mapillaryFragment != null) {
OsmandSettings settings = getMyApplication().getSettings();
TransactionBuilder builder = new TransactionBuilder(manager, settings, mapActivity);
builder.getFragmentTransaction().remove(mapillaryFragment).commit();
}
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class DashboardOnMap method setDashboardVisibility.
public void setDashboardVisibility(boolean visible, DashboardType type, DashboardType prevItem, boolean animation, int[] animationCoordinates) {
if (visible == this.visible && type == visibleType) {
return;
}
mapActivity.getRoutingHelper().removeListener(this);
nightMode = mapActivity.getMyApplication().getDaynightHelper().isNightModeForMapControls();
this.previousVisibleType = prevItem;
this.visible = visible;
ApplicationMode currentAppMode = getMyApplication().getSettings().APPLICATION_MODE.get();
boolean appModeChanged = currentAppMode != previousAppMode;
boolean refresh = this.visibleType == type && !appModeChanged;
previousAppMode = currentAppMode;
this.visibleType = type;
DashboardOnMap.staticVisible = visible;
DashboardOnMap.staticVisibleType = type;
mapActivity.enableDrawer();
if (swipeDismissListener != null) {
swipeDismissListener.discardUndo();
}
removeMapillaryFiltersFragment();
if (visible) {
mapActivity.dismissCardDialog();
mapActivity.getContextMenu().hideMenues();
mapViewLocation = mapActivity.getMapLocation();
mapRotation = mapActivity.getMapRotate();
mapLinkedToLocation = mapActivity.getMapViewTrackingUtilities().isMapLinkedToLocation();
myLocation = mapActivity.getMyApplication().getLocationProvider().getLastKnownLocation();
mapActivity.getMapViewTrackingUtilities().setDashboard(this);
mapActivity.disableDrawer();
dashboardView.setVisibility(View.VISIBLE);
if (isActionButtonVisible()) {
setActionButton(visibleType);
actionButton.setVisibility(View.VISIBLE);
} else {
hideActionButton();
if (visibleType == DashboardType.CONFIGURE_MAP) {
int btnSizePx = mapActivity.getResources().getDimensionPixelSize(R.dimen.map_small_button_size);
compassButton = mapActivity.getMapLayers().getMapControlsLayer().moveCompassButton(dashboardView, getActionButtonLayoutParams(btnSizePx), nightMode);
}
}
updateDownloadBtn();
View listViewLayout = dashboardView.findViewById(R.id.dash_list_view_layout);
ScrollView scrollView = (ScrollView) dashboardView.findViewById(R.id.main_scroll);
if (visibleType == DashboardType.DASHBOARD || visibleType == DashboardType.MAPILLARY) {
if (visibleType == DashboardType.DASHBOARD) {
addOrUpdateDashboardFragments();
} else {
mapActivity.getSupportFragmentManager().beginTransaction().replace(R.id.content, new MapillaryFiltersFragment(), MapillaryFiltersFragment.TAG).commit();
}
scrollView.setVisibility(View.VISIBLE);
scrollView.scrollTo(0, 0);
listViewLayout.setVisibility(View.GONE);
onScrollChanged(scrollView.getScrollY(), false, false);
} else {
scrollView.setVisibility(View.GONE);
listViewLayout.setVisibility(View.VISIBLE);
if (refresh) {
refreshContent(false);
} else {
listView.scrollTo(0, 0);
listView.clearParams();
onScrollChanged(listView.getScrollY(), false, false);
updateListAdapter();
}
updateListBackgroundHeight();
applyDayNightMode();
}
mapActivity.findViewById(R.id.toolbar_back).setVisibility(isBackButtonVisible() ? View.VISIBLE : View.GONE);
mapActivity.getMapLayers().getMapControlsLayer().hideMapControls();
boolean portrait = AndroidUiHelper.isOrientationPortrait(mapActivity);
if (!portrait) {
AndroidUiHelper.updateVisibility(mapActivity.findViewById(R.id.map_route_land_left_margin_external), true);
mapActivity.getMapView().setMapPositionX(1);
mapActivity.refreshMap();
}
updateToolbarActions();
// fabButton.showFloatingActionButton();
open(animation, animationCoordinates);
updateLocation(true, true, false);
// addOrUpdateDashboardFragments();
mapActivity.getRoutingHelper().addListener(this);
} else {
mapActivity.getMapViewTrackingUtilities().setDashboard(null);
hide(animation);
if (!MapRouteInfoMenu.isVisible()) {
AndroidUiHelper.updateVisibility(mapActivity.findViewById(R.id.map_route_land_left_margin_external), false);
mapActivity.getMapView().setMapPositionX(0);
mapActivity.getMapView().refreshMap();
}
mapActivity.getMapLayers().getMapControlsLayer().showMapControlsIfHidden();
hideActionButton();
for (WeakReference<DashBaseFragment> df : fragList) {
if (df.get() != null) {
df.get().onCloseDash();
}
}
OsmandSettings settings = getMyApplication().getSettings();
if (settings.SHOW_MAPILLARY.get() && !settings.MAPILLARY_FIRST_DIALOG_SHOWN.get()) {
MapillaryFirstDialogFragment fragment = new MapillaryFirstDialogFragment();
fragment.show(mapActivity.getSupportFragmentManager(), MapillaryFirstDialogFragment.TAG);
settings.MAPILLARY_FIRST_DIALOG_SHOWN.set(true);
}
}
mapActivity.updateStatusBarColor();
}
use of net.osmand.plus.OsmandSettings in project Osmand by osmandapp.
the class RateUsBottomSheetDialog method shouldShow.
public static boolean shouldShow(OsmandApplication application) {
if (Version.isMarketEnabled(application)) {
return false;
}
OsmandSettings settings = application.getSettings();
if (!settings.LAST_DISPLAY_TIME.isSet()) {
settings.LAST_DISPLAY_TIME.set(System.currentTimeMillis());
}
long lastDisplayTimeInMillis = settings.LAST_DISPLAY_TIME.get();
int numberOfApplicationRuns = settings.NUMBER_OF_APPLICATION_STARTS.get();
RateUsState state = settings.RATE_US_STATE.get();
Calendar modifiedTime = Calendar.getInstance();
Calendar lastDisplayTime = Calendar.getInstance();
lastDisplayTime.setTimeInMillis(lastDisplayTimeInMillis);
int bannerFreeRuns = 0;
switch(state) {
case LIKED:
return false;
case INITIAL_STATE:
break;
case IGNORED:
modifiedTime.add(Calendar.WEEK_OF_YEAR, -1);
bannerFreeRuns = 5;
break;
case DISLIKED_WITH_MESSAGE:
modifiedTime.add(Calendar.MONTH, -3);
bannerFreeRuns = 3;
break;
case DISLIKED_WITHOUT_MESSAGE:
modifiedTime.add(Calendar.MONTH, -2);
break;
default:
throw new IllegalStateException("Unexpected state:" + state);
}
if (state != RateUsState.INITIAL_STATE) {
if (modifiedTime.after(lastDisplayTime) && numberOfApplicationRuns >= bannerFreeRuns) {
settings.RATE_US_STATE.set(RateUsState.INITIAL_STATE);
modifiedTime = Calendar.getInstance();
} else {
return false;
}
}
// Initial state now
modifiedTime.add(Calendar.HOUR, -72);
bannerFreeRuns = 3;
return modifiedTime.after(lastDisplayTime) && numberOfApplicationRuns >= bannerFreeRuns;
}
Aggregations