use of net.osmand.render.RenderingRulesStorage in project Osmand by osmandapp.
the class TrackSegmentFragment method updateColorView.
private void updateColorView(View colorView) {
final ImageView colorImageView = (ImageView) colorView.findViewById(R.id.colorImage);
int color = getGpxDataItem() != null ? getGpxDataItem().getColor() : 0;
if (color == 0 && getGpx() != null) {
if (getGpx().showCurrentTrack) {
color = app.getSettings().CURRENT_TRACK_COLOR.get();
} else {
color = getGpx().getColor(0);
}
}
if (color == 0) {
final RenderingRulesStorage renderer = app.getRendererRegistry().getCurrentSelectedRenderer();
final OsmandSettings.CommonPreference<String> prefColor = app.getSettings().getCustomRenderProperty(CURRENT_TRACK_COLOR_ATTR);
color = GpxAppearanceAdapter.parseTrackColor(renderer, prefColor.get());
}
if (color == 0) {
colorImageView.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_circle));
} else {
colorImageView.setImageDrawable(app.getIconsCache().getPaintedIcon(R.drawable.ic_action_circle, color));
}
trackColor = color;
}
use of net.osmand.render.RenderingRulesStorage in project Osmand by osmandapp.
the class ConfigureMapMenu method createRenderingAttributeItems.
private void createRenderingAttributeItems(List<RenderingRuleProperty> customRules, final ContextMenuAdapter adapter, final MapActivity activity) {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_map_rendering, activity).setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_widget_renderer, activity).setDescription(getRenderDescr(activity)).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_map).setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
AlertDialog.Builder bld = new AlertDialog.Builder(activity);
bld.setTitle(R.string.renderers);
final OsmandApplication app = activity.getMyApplication();
final ArrayList<String> items = new ArrayList<>(app.getRendererRegistry().getRendererNames());
boolean nauticalPluginDisabled = OsmandPlugin.getEnabledPlugin(NauticalMapsPlugin.class) == null;
final List<String> visibleNamesList = new ArrayList<>();
int selected = -1;
final String selectedName = app.getRendererRegistry().getCurrentSelectedRenderer().getName();
int i = 0;
Iterator<String> iterator = items.iterator();
while (iterator.hasNext()) {
String item = iterator.next();
if (nauticalPluginDisabled && item.equals(RendererRegistry.NAUTICAL_RENDER)) {
iterator.remove();
} else {
if (item.equals(selectedName)) {
selected = i;
}
String translation = RendererRegistry.getTranslatedRendererName(activity, item);
visibleNamesList.add(translation != null ? translation : item.replace('_', ' ').replace('-', ' '));
i++;
}
}
bld.setSingleChoiceItems(visibleNamesList.toArray(new String[visibleNamesList.size()]), selected, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String renderer = items.get(which);
RenderingRulesStorage loaded = app.getRendererRegistry().getRenderer(renderer);
if (loaded != null) {
OsmandMapTileView view = activity.getMapView();
view.getSettings().RENDERER.set(renderer);
app.getRendererRegistry().setCurrentSelectedRender(loaded);
refreshMapComplete(activity);
} else {
Toast.makeText(app, R.string.renderer_load_exception, Toast.LENGTH_SHORT).show();
}
adapter.getItem(pos).setDescription(getRenderDescr(activity));
activity.getDashboard().refreshContent(true);
dialog.dismiss();
}
});
bld.setNegativeButton(R.string.shared_string_dismiss, null);
bld.show();
return false;
}
}).createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_mode, activity).setDescription(getDayNightDescr(activity)).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(getDayNightIcon(activity)).setListener(new ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
final OsmandMapTileView view = activity.getMapView();
AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
bld.setTitle(R.string.daynight);
final String[] items = new String[OsmandSettings.DayNightMode.values().length];
for (int i = 0; i < items.length; i++) {
items[i] = OsmandSettings.DayNightMode.values()[i].toHumanString(activity.getMyApplication());
}
int i = view.getSettings().DAYNIGHT_MODE.get().ordinal();
bld.setSingleChoiceItems(items, i, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
view.getSettings().DAYNIGHT_MODE.set(OsmandSettings.DayNightMode.values()[which]);
refreshMapComplete(activity);
dialog.dismiss();
activity.getDashboard().refreshContent(true);
// adapter.getItem(pos).setDescription(s, getDayNightDescr(activity));
// ad.notifyDataSetInvalidated();
}
});
bld.setNegativeButton(R.string.shared_string_dismiss, null);
bld.show();
return false;
}
}).createItem());
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_magnifier, activity).setDescription(String.format(Locale.UK, "%.0f", 100f * activity.getMyApplication().getSettings().MAP_DENSITY.get()) + " %").setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_action_map_magnifier).setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
final OsmandMapTileView view = activity.getMapView();
final OsmandSettings.OsmandPreference<Float> mapDensity = view.getSettings().MAP_DENSITY;
final AlertDialog.Builder bld = new AlertDialog.Builder(view.getContext());
int p = (int) (mapDensity.get() * 100);
final TIntArrayList tlist = new TIntArrayList(new int[] { 33, 50, 75, 100, 150, 200, 300, 400 });
final List<String> values = new ArrayList<>();
int i = -1;
for (int k = 0; k <= tlist.size(); k++) {
final boolean end = k == tlist.size();
if (i == -1) {
if ((end || p < tlist.get(k))) {
values.add(p + " %");
i = k;
} else if (p == tlist.get(k)) {
i = k;
}
}
if (k < tlist.size()) {
values.add(tlist.get(k) + " %");
}
}
if (values.size() != tlist.size()) {
tlist.insert(i, p);
}
bld.setTitle(R.string.map_magnifier);
bld.setSingleChoiceItems(values.toArray(new String[values.size()]), i, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
int p = tlist.get(which);
mapDensity.set(p / 100.0f);
view.setComplexZoom(view.getZoom(), view.getSettingsMapDensity());
MapRendererContext mapContext = NativeCoreContext.getMapRendererContext();
if (mapContext != null) {
mapContext.updateMapSettings();
}
adapter.getItem(pos).setDescription(String.format(Locale.UK, "%.0f", 100f * activity.getMyApplication().getSettings().MAP_DENSITY.get()) + " %");
ad.notifyDataSetInvalidated();
dialog.dismiss();
}
});
bld.setNegativeButton(R.string.shared_string_dismiss, null);
bld.show();
return false;
}
}).createItem());
ContextMenuItem props;
props = createRenderingProperty(customRules, adapter, activity, R.drawable.ic_action_intersection, ROAD_STYLE_ATTR);
if (props != null) {
adapter.addItem(props);
}
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.text_size, activity).setDescription(getScale(activity)).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_action_map_text_size).setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
final OsmandMapTileView view = activity.getMapView();
AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
// test old descr as title
b.setTitle(R.string.text_size);
final Float[] txtValues = new Float[] { 0.75f, 1f, 1.25f, 1.5f, 2f, 3f };
int selected = -1;
final String[] txtNames = new String[txtValues.length];
for (int i = 0; i < txtNames.length; i++) {
txtNames[i] = (int) (txtValues[i] * 100) + " %";
if (Math.abs(view.getSettings().TEXT_SCALE.get() - txtValues[i]) < 0.1f) {
selected = i;
}
}
b.setSingleChoiceItems(txtNames, selected, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
view.getSettings().TEXT_SCALE.set(txtValues[which]);
refreshMapComplete(activity);
adapter.getItem(pos).setDescription(getScale(activity));
ad.notifyDataSetInvalidated();
dialog.dismiss();
}
});
b.setNegativeButton(R.string.shared_string_dismiss, null);
b.show();
return false;
}
}).createItem());
String localeDescr = activity.getMyApplication().getSettings().MAP_PREFERRED_LOCALE.get();
localeDescr = localeDescr == null || localeDescr.equals("") ? activity.getString(R.string.local_map_names) : localeDescr;
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.map_locale, activity).setDescription(localeDescr).setLayout(R.layout.list_item_single_line_descrition_narrow).setIcon(R.drawable.ic_action_map_language).setListener(new ContextMenuAdapter.ItemClickListener() {
@Override
public boolean onContextMenuClick(final ArrayAdapter<ContextMenuItem> ad, int itemId, final int pos, boolean isChecked, int[] viewCoordinates) {
final OsmandMapTileView view = activity.getMapView();
final AlertDialog.Builder b = new AlertDialog.Builder(view.getContext());
b.setTitle(activity.getString(R.string.map_locale));
final String[] txtIds = getSortedMapNamesIds(activity, mapNamesIds, getMapNamesValues(activity, mapNamesIds));
final String[] txtValues = getMapNamesValues(activity, txtIds);
int selected = -1;
for (int i = 0; i < txtIds.length; i++) {
if (view.getSettings().MAP_PREFERRED_LOCALE.get().equals(txtIds[i])) {
selected = i;
break;
}
}
selectedLanguageIndex = selected;
transliterateNames = view.getSettings().MAP_TRANSLITERATE_NAMES.get();
final OnCheckedChangeListener translitChangdListener = new OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
transliterateNames = isChecked;
}
};
final ArrayAdapter<CharSequence> singleChoiceAdapter = new ArrayAdapter<CharSequence>(activity, R.layout.single_choice_switch_item, R.id.text1, txtValues) {
@NonNull
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View v = super.getView(position, convertView, parent);
AppCompatCheckedTextView checkedTextView = (AppCompatCheckedTextView) v.findViewById(R.id.text1);
if (position == selectedLanguageIndex && position > 0) {
checkedTextView.setChecked(true);
v.findViewById(R.id.topDivider).setVisibility(View.VISIBLE);
v.findViewById(R.id.bottomDivider).setVisibility(View.VISIBLE);
v.findViewById(R.id.switchLayout).setVisibility(View.VISIBLE);
TextView switchText = (TextView) v.findViewById(R.id.switchText);
switchText.setText(activity.getString(R.string.translit_name_if_miss, txtValues[position]));
SwitchCompat check = (SwitchCompat) v.findViewById(R.id.check);
check.setChecked(transliterateNames);
check.setOnCheckedChangeListener(translitChangdListener);
} else {
checkedTextView.setChecked(position == selectedLanguageIndex);
v.findViewById(R.id.topDivider).setVisibility(View.GONE);
v.findViewById(R.id.bottomDivider).setVisibility(View.GONE);
v.findViewById(R.id.switchLayout).setVisibility(View.GONE);
}
return v;
}
};
b.setAdapter(singleChoiceAdapter, null);
b.setSingleChoiceItems(txtValues, selected, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
selectedLanguageIndex = which;
((AlertDialog) dialog).getListView().setSelection(which);
singleChoiceAdapter.notifyDataSetChanged();
}
});
b.setNegativeButton(R.string.shared_string_cancel, null);
b.setPositiveButton(R.string.shared_string_apply, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
view.getSettings().MAP_TRANSLITERATE_NAMES.set(selectedLanguageIndex > 0 && transliterateNames);
AlertDialog dlg = (AlertDialog) dialog;
int index = dlg.getListView().getCheckedItemPosition();
view.getSettings().MAP_PREFERRED_LOCALE.set(txtIds[index]);
refreshMapComplete(activity);
String localeDescr = txtIds[index];
localeDescr = localeDescr == null || localeDescr.equals("") ? activity.getString(R.string.local_map_names) : localeDescr;
adapter.getItem(pos).setDescription(localeDescr);
ad.notifyDataSetInvalidated();
}
});
b.show();
return false;
}
}).createItem());
props = createProperties(customRules, null, R.string.rendering_category_transport, R.drawable.ic_action_bus_dark, "transport", null, adapter, activity, true);
if (props != null) {
adapter.addItem(props);
}
props = createProperties(customRules, null, R.string.rendering_category_details, R.drawable.ic_action_layers_dark, "details", null, adapter, activity, true);
if (props != null) {
adapter.addItem(props);
}
props = createProperties(customRules, null, R.string.rendering_category_hide, R.drawable.ic_action_hide, "hide", null, adapter, activity, true);
if (props != null) {
adapter.addItem(props);
}
List<RenderingRuleProperty> customRulesIncluded = new ArrayList<>();
for (RenderingRuleProperty p : customRules) {
if (p.getAttrName().equals(HIKING_ROUTES_OSMC_ATTR)) {
customRulesIncluded.add(p);
break;
}
}
props = createProperties(customRules, customRulesIncluded, R.string.rendering_category_routes, R.drawable.ic_action_map_routes, "routes", null, adapter, activity, true);
if (props != null) {
adapter.addItem(props);
}
if (getCustomRenderingPropertiesSize(customRules) > 0) {
adapter.addItem(new ContextMenuItem.ItemBuilder().setTitleId(R.string.rendering_category_others, activity).setCategory(true).setLayout(R.layout.list_group_title_with_switch).createItem());
createCustomRenderingProperties(adapter, activity, customRules);
}
}
use of net.osmand.render.RenderingRulesStorage in project Osmand by osmandapp.
the class SettingsGeneralActivity method loadNativeLibrary.
public void loadNativeLibrary() {
if (!NativeOsmandLibrary.isLoaded()) {
final RenderingRulesStorage storage = getMyApplication().getRendererRegistry().getCurrentSelectedRenderer();
new AsyncTask<Void, Void, Void>() {
@Override
protected void onPreExecute() {
setProgressVisibility(true);
}
@Override
protected Void doInBackground(Void... params) {
NativeOsmandLibrary.getLibrary(storage, getMyApplication());
return null;
}
@Override
protected void onPostExecute(Void result) {
setProgressVisibility(false);
if (!NativeOsmandLibrary.isNativeSupported(storage, getMyApplication())) {
Toast.makeText(SettingsGeneralActivity.this, R.string.native_library_not_supported, Toast.LENGTH_LONG).show();
}
}
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
use of net.osmand.render.RenderingRulesStorage in project Osmand by osmandapp.
the class AppInitializer method initNativeCore.
private void initNativeCore() {
if (!"qnx".equals(System.getProperty("os.name"))) {
OsmandSettings osmandSettings = app.getSettings();
if (osmandSettings.USE_OPENGL_RENDER.get()) {
boolean success = false;
if (!osmandSettings.OPENGL_RENDER_FAILED.get()) {
osmandSettings.OPENGL_RENDER_FAILED.set(true);
success = NativeCoreContext.tryCatchInit(app);
if (success) {
osmandSettings.OPENGL_RENDER_FAILED.set(false);
}
}
if (!success) {
// try next time once again ?
osmandSettings.OPENGL_RENDER_FAILED.set(false);
warnings.add("Native OpenGL library is not supported. Please try again after exit");
}
}
if (osmandSettings.NATIVE_RENDERING_FAILED.get()) {
osmandSettings.SAFE_MODE.set(true);
osmandSettings.NATIVE_RENDERING_FAILED.set(false);
warnings.add(app.getString(R.string.native_library_not_supported));
} else {
osmandSettings.SAFE_MODE.set(false);
osmandSettings.NATIVE_RENDERING_FAILED.set(true);
startTask(app.getString(R.string.init_native_library), -1);
RenderingRulesStorage storage = app.getRendererRegistry().getCurrentSelectedRenderer();
NativeOsmandLibrary lib = NativeOsmandLibrary.getLibrary(storage, app);
boolean initialized = lib != null;
osmandSettings.NATIVE_RENDERING_FAILED.set(false);
if (!initialized) {
LOG.info("Native library could not be loaded!");
} else {
File ls = app.getAppPath("fonts");
lib.loadFontData(ls);
}
}
app.getResourceManager().initMapBoundariesCacheNative();
}
}
use of net.osmand.render.RenderingRulesStorage in project Osmand by osmandapp.
the class MapRendererContext method getMapStyleSettings.
protected QStringStringHash getMapStyleSettings() {
// Apply map style settings
OsmandSettings prefs = app.getSettings();
RenderingRulesStorage storage = app.getRendererRegistry().getCurrentSelectedRenderer();
Map<String, String> props = new HashMap<String, String>();
for (RenderingRuleProperty customProp : storage.PROPS.getCustomRules()) {
if (RenderingRuleStorageProperties.UI_CATEGORY_HIDDEN.equals(customProp.getCategory())) {
continue;
} else if (customProp.isBoolean()) {
CommonPreference<Boolean> pref = prefs.getCustomRenderBooleanProperty(customProp.getAttrName());
props.put(customProp.getAttrName(), pref.get() + "");
} else {
CommonPreference<String> settings = prefs.getCustomRenderProperty(customProp.getAttrName());
String res = settings.get();
if (!Algorithms.isEmpty(res)) {
props.put(customProp.getAttrName(), res);
}
}
}
QStringStringHash convertedStyleSettings = new QStringStringHash();
for (Map.Entry<String, String> setting : props.entrySet()) {
convertedStyleSettings.set(setting.getKey(), setting.getValue());
}
if (nightMode) {
convertedStyleSettings.set("nightMode", "true");
}
return convertedStyleSettings;
}
Aggregations