use of net.osmand.plus.quickaction.QuickActionRegistry in project Osmand by osmandapp.
the class QuickActionsSettingsItem method readItemsFromJson.
@Override
void readItemsFromJson(@NonNull JSONObject json) throws IllegalArgumentException {
try {
if (!json.has("items")) {
return;
}
Gson gson = new Gson();
Type type = new TypeToken<HashMap<String, String>>() {
}.getType();
QuickActionRegistry quickActionRegistry = app.getQuickActionRegistry();
JSONArray itemsJson = json.getJSONArray("items");
for (int i = 0; i < itemsJson.length(); i++) {
JSONObject object = itemsJson.getJSONObject(i);
String name = object.getString("name");
QuickAction quickAction = null;
if (object.has("actionType")) {
quickAction = quickActionRegistry.newActionByStringType(object.getString("actionType"));
} else if (object.has("type")) {
quickAction = quickActionRegistry.newActionByType(object.getInt("type"));
}
if (quickAction != null) {
String paramsString = object.getString("params");
HashMap<String, String> params = gson.fromJson(paramsString, type);
if (!name.isEmpty()) {
quickAction.setName(name);
}
quickAction.setParams(params);
items.add(quickAction);
} else {
warnings.add(app.getString(R.string.settings_item_read_error, name));
}
}
} catch (JSONException e) {
warnings.add(app.getString(R.string.settings_item_read_error, String.valueOf(getType())));
throw new IllegalArgumentException("Json parse error", e);
}
}
use of net.osmand.plus.quickaction.QuickActionRegistry in project Osmand by osmandapp.
the class SelectMapViewQuickActionsBottomSheet method createMenuItems.
@Override
public void createMenuItems(Bundle savedInstanceState) {
Bundle args = getArguments();
if (args == null) {
return;
}
MapActivity mapActivity = getMapActivity();
if (mapActivity == null) {
return;
}
long id = args.getLong(SwitchableAction.KEY_ID);
OsmandApplication app = mapActivity.getMyApplication();
QuickActionRegistry quickActionRegistry = app.getQuickActionRegistry();
action = quickActionRegistry.getQuickAction(id);
action = QuickActionRegistry.produceAction(action);
if (action == null) {
return;
}
OsmandSettings settings = app.getSettings();
if (savedInstanceState != null) {
selectedItem = savedInstanceState.getString(SELECTED_ITEM_KEY);
} else {
selectedItem = ((SwitchableAction<?>) action).getSelectedItem(app);
}
rbColorList = AndroidUtils.createCheckedColorStateList(app, R.color.icon_color_default_light, getActiveColorId());
items.add(new TitleItem(action.getName(app)));
NestedScrollView nestedScrollView = new NestedScrollView(app);
itemsContainer = new LinearLayout(app);
itemsContainer.setLayoutParams((new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT)));
itemsContainer.setOrientation(LinearLayout.VERTICAL);
int padding = getResources().getDimensionPixelSize(R.dimen.bottom_sheet_content_padding_small);
itemsContainer.setPadding(0, padding, 0, padding);
int itemsSize = 0;
if (action instanceof SwitchableAction) {
SwitchableAction switchableAction = (SwitchableAction) action;
List sources = switchableAction.loadListFromParams();
itemsSize = sources.size();
}
for (int i = 0; i < itemsSize; i++) {
LayoutInflater.from(new ContextThemeWrapper(app, themeRes)).inflate(R.layout.bottom_sheet_item_with_radio_btn, itemsContainer, true);
}
nestedScrollView.addView(itemsContainer);
items.add(new BaseBottomSheetItem.Builder().setCustomView(nestedScrollView).create());
populateItemsList();
}
use of net.osmand.plus.quickaction.QuickActionRegistry in project Osmand by osmandapp.
the class SettingsHelper method getSettingsItems.
private Map<ExportSettingsType, List<?>> getSettingsItems(@Nullable List<ExportSettingsType> settingsTypes, boolean addEmptyItems) {
Map<ExportSettingsType, List<?>> settingsItems = new LinkedHashMap<>();
if (settingsTypes == null || settingsTypes.contains(ExportSettingsType.PROFILE)) {
List<ApplicationModeBean> appModeBeans = new ArrayList<>();
for (ApplicationMode mode : ApplicationMode.allPossibleValues()) {
appModeBeans.add(mode.toModeBean());
}
settingsItems.put(ExportSettingsType.PROFILE, appModeBeans);
}
List<GlobalSettingsItem> globalSettingsList = settingsTypes == null || settingsTypes.contains(ExportSettingsType.GLOBAL) ? Collections.singletonList(new GlobalSettingsItem(app.getSettings())) : Collections.emptyList();
if (!globalSettingsList.isEmpty() || addEmptyItems) {
settingsItems.put(ExportSettingsType.GLOBAL, globalSettingsList);
}
QuickActionRegistry registry = app.getQuickActionRegistry();
List<QuickAction> actionsList = settingsTypes == null || settingsTypes.contains(ExportSettingsType.QUICK_ACTIONS) ? registry.getQuickActions() : Collections.emptyList();
if (!actionsList.isEmpty() || addEmptyItems) {
settingsItems.put(ExportSettingsType.QUICK_ACTIONS, actionsList);
}
List<PoiUIFilter> poiList = settingsTypes == null || settingsTypes.contains(ExportSettingsType.POI_TYPES) ? app.getPoiFilters().getUserDefinedPoiFilters(false) : Collections.emptyList();
if (!poiList.isEmpty() || addEmptyItems) {
settingsItems.put(ExportSettingsType.POI_TYPES, poiList);
}
Map<LatLon, AvoidRoadInfo> impassableRoads = settingsTypes == null || settingsTypes.contains(ExportSettingsType.AVOID_ROADS) ? app.getAvoidSpecificRoads().getImpassableRoads() : Collections.emptyMap();
if (!impassableRoads.isEmpty() || addEmptyItems) {
settingsItems.put(ExportSettingsType.AVOID_ROADS, new ArrayList<>(impassableRoads.values()));
}
return settingsItems;
}
use of net.osmand.plus.quickaction.QuickActionRegistry in project Osmand by osmandapp.
the class AppInitializer method onCreateApplication.
public void onCreateApplication() {
// always update application mode to default
OsmandSettings osmandSettings = app.getSettings();
if (osmandSettings.FOLLOW_THE_ROUTE.get()) {
ApplicationMode savedMode = osmandSettings.readApplicationMode();
if (!osmandSettings.APPLICATION_MODE.get().getStringKey().equals(savedMode.getStringKey())) {
osmandSettings.setApplicationMode(savedMode);
}
} else {
osmandSettings.setApplicationMode(osmandSettings.DEFAULT_APPLICATION_MODE.get());
}
startTime = System.currentTimeMillis();
getLazyRoutingConfig();
app.applyTheme(app);
startupInit(app.reconnectToBRouter(), IBRouterService.class);
app.backupHelper = startupInit(new BackupHelper(app), BackupHelper.class);
app.inAppPurchaseHelper = startupInit(new InAppPurchaseHelperImpl(app), InAppPurchaseHelperImpl.class);
app.poiTypes = startupInit(MapPoiTypes.getDefaultNoInit(), MapPoiTypes.class);
app.transportRoutingHelper = startupInit(new TransportRoutingHelper(app), TransportRoutingHelper.class);
app.routingHelper = startupInit(new RoutingHelper(app), RoutingHelper.class);
app.routingOptionsHelper = startupInit(new RoutingOptionsHelper(app), RoutingOptionsHelper.class);
app.resourceManager = startupInit(new ResourceManager(app), ResourceManager.class);
app.daynightHelper = startupInit(new DayNightHelper(app), DayNightHelper.class);
app.locationProvider = startupInit(new OsmAndLocationProvider(app), OsmAndLocationProvider.class);
app.avoidSpecificRoads = startupInit(new AvoidSpecificRoads(app), AvoidSpecificRoads.class);
app.avoidRoadsHelper = startupInit(new AvoidRoadsHelper(app), AvoidRoadsHelper.class);
app.savingTrackHelper = startupInit(new SavingTrackHelper(app), SavingTrackHelper.class);
app.analyticsHelper = startupInit(new AnalyticsHelper(app), AnalyticsHelper.class);
app.notificationHelper = startupInit(new NotificationHelper(app), NotificationHelper.class);
app.liveMonitoringHelper = startupInit(new LiveMonitoringHelper(app), LiveMonitoringHelper.class);
app.selectedGpxHelper = startupInit(new GpxSelectionHelper(app, app.savingTrackHelper), GpxSelectionHelper.class);
app.gpxDbHelper = startupInit(new GpxDbHelper(app), GpxDbHelper.class);
app.favoritesHelper = startupInit(new FavouritesHelper(app), FavouritesHelper.class);
app.waypointHelper = startupInit(new WaypointHelper(app), WaypointHelper.class);
app.aidlApi = startupInit(new OsmandAidlApi(app), OsmandAidlApi.class);
app.regions = startupInit(new OsmandRegions(), OsmandRegions.class);
updateRegionVars();
app.poiFilters = startupInit(new PoiFiltersHelper(app), PoiFiltersHelper.class);
app.rendererRegistry = startupInit(new RendererRegistry(app), RendererRegistry.class);
app.geocodingLookupService = startupInit(new GeocodingLookupService(app), GeocodingLookupService.class);
app.targetPointsHelper = startupInit(new TargetPointsHelper(app), TargetPointsHelper.class);
app.mapMarkersDbHelper = startupInit(new MapMarkersDbHelper(app), MapMarkersDbHelper.class);
app.mapMarkersHelper = startupInit(new MapMarkersHelper(app), MapMarkersHelper.class);
app.searchUICore = startupInit(new QuickSearchHelper(app), QuickSearchHelper.class);
app.mapViewTrackingUtilities = startupInit(new MapViewTrackingUtilities(app), MapViewTrackingUtilities.class);
app.osmandMap = startupInit(new OsmandMap(app), OsmandMap.class);
// TODO TRAVEL_OBF_HELPER check ResourceManager and use TravelObfHelper
TravelHelper travelHelper = !TravelDbHelper.checkIfDbFileExists(app) ? new TravelObfHelper(app) : new TravelDbHelper(app);
app.travelHelper = startupInit(travelHelper, TravelHelper.class);
app.travelRendererHelper = startupInit(new TravelRendererHelper(app), TravelRendererHelper.class);
app.lockHelper = startupInit(new LockHelper(app), LockHelper.class);
app.fileSettingsHelper = startupInit(new FileSettingsHelper(app), FileSettingsHelper.class);
app.networkSettingsHelper = startupInit(new NetworkSettingsHelper(app), NetworkSettingsHelper.class);
app.quickActionRegistry = startupInit(new QuickActionRegistry(app.getSettings()), QuickActionRegistry.class);
app.osmOAuthHelper = startupInit(new OsmOAuthHelper(app), OsmOAuthHelper.class);
app.oprAuthHelper = startupInit(new OprAuthHelper(app), OprAuthHelper.class);
app.onlineRoutingHelper = startupInit(new OnlineRoutingHelper(app), OnlineRoutingHelper.class);
app.launcherShortcutsHelper = startupInit(new LauncherShortcutsHelper(app), LauncherShortcutsHelper.class);
app.gpsFilterHelper = startupInit(new GpsFilterHelper(app), GpsFilterHelper.class);
app.downloadTilesHelper = startupInit(new DownloadTilesHelper(app), DownloadTilesHelper.class);
initOpeningHoursParser();
}
use of net.osmand.plus.quickaction.QuickActionRegistry in project Osmand by osmandapp.
the class CustomOsmandPlugin method removePluginItemsFromFile.
private void removePluginItemsFromFile(final File file, final PluginItemsListener itemsListener) {
app.getFileSettingsHelper().collectSettings(file, "", 1, new CollectListener() {
@Override
public void onCollectFinished(boolean succeed, boolean empty, @NonNull List<SettingsItem> items) {
if (succeed && !items.isEmpty()) {
for (SettingsItem item : items) {
if (item instanceof QuickActionsSettingsItem) {
QuickActionsSettingsItem quickActionsSettingsItem = (QuickActionsSettingsItem) item;
List<QuickAction> quickActions = quickActionsSettingsItem.getItems();
QuickActionRegistry actionRegistry = app.getQuickActionRegistry();
for (QuickAction action : quickActions) {
QuickAction savedAction = actionRegistry.getQuickAction(app, action.getType(), action.getName(app), action.getParams());
if (savedAction != null) {
actionRegistry.deleteQuickAction(savedAction);
}
}
} else if (item instanceof MapSourcesSettingsItem) {
MapSourcesSettingsItem mapSourcesSettingsItem = (MapSourcesSettingsItem) item;
List<ITileSource> mapSources = mapSourcesSettingsItem.getItems();
for (ITileSource tileSource : mapSources) {
String tileSourceName = tileSource.getName();
if (tileSource instanceof SQLiteTileSource) {
tileSourceName += SQLITE_EXT;
}
ITileSource savedTileSource = app.getSettings().getTileSourceByName(tileSourceName, false);
if (savedTileSource != null) {
if (savedTileSource instanceof SQLiteTileSource) {
SQLiteTileSource sqLiteTileSource = ((SQLiteTileSource) savedTileSource);
sqLiteTileSource.closeDB();
}
File tPath = app.getAppPath(IndexConstants.TILES_INDEX_DIR);
File dir = new File(tPath, tileSourceName);
Algorithms.removeAllFiles(dir);
}
}
} else if (item instanceof PoiUiFiltersSettingsItem) {
PoiUiFiltersSettingsItem poiUiFiltersSettingsItem = (PoiUiFiltersSettingsItem) item;
List<PoiUIFilter> poiUIFilters = poiUiFiltersSettingsItem.getItems();
for (PoiUIFilter filter : poiUIFilters) {
app.getPoiFilters().removePoiFilter(filter);
}
app.getPoiFilters().reloadAllPoiFilters();
app.getPoiFilters().loadSelectedPoiFilters();
app.getSearchUICore().refreshCustomPoiFilters();
} else if (item instanceof AvoidRoadsSettingsItem) {
AvoidRoadsSettingsItem avoidRoadsSettingsItem = (AvoidRoadsSettingsItem) item;
List<AvoidSpecificRoads.AvoidRoadInfo> avoidRoadInfos = avoidRoadsSettingsItem.getItems();
for (AvoidSpecificRoads.AvoidRoadInfo avoidRoad : avoidRoadInfos) {
app.getAvoidSpecificRoads().removeImpassableRoad(avoidRoad);
}
} else if (item instanceof ProfileSettingsItem) {
ProfileSettingsItem profileSettingsItem = (ProfileSettingsItem) item;
ApplicationMode mode = profileSettingsItem.getAppMode();
ApplicationMode savedMode = ApplicationMode.valueOfStringKey(mode.getStringKey(), null);
if (savedMode != null) {
ApplicationMode.changeProfileAvailability(savedMode, false, app);
}
}
}
}
if (itemsListener != null) {
itemsListener.onItemsRemoved();
}
}
});
}
Aggregations