use of mpicbg.trakem2.util.Pair in project Osmand by osmandapp.
the class MapViewTrackingUtilities method autozoom.
public Pair<Integer, Double> autozoom(Location location) {
if (location.hasSpeed()) {
long now = System.currentTimeMillis();
final RotatedTileBox tb = mapView.getCurrentRotatedTileBox();
float zdelta = defineZoomFromSpeed(tb, location.getSpeed());
if (Math.abs(zdelta) >= 0.5) /*?Math.sqrt(0.5)*/
{
// prevent ui hysteresis (check time interval for autozoom)
if (zdelta >= 2) {
// decrease a bit
zdelta -= 1;
} else if (zdelta <= -2) {
// decrease a bit
zdelta += 1;
}
double targetZoom = Math.min(tb.getZoom() + tb.getZoomFloatPart() + zdelta, settings.AUTO_ZOOM_MAP_SCALE.get().maxZoom);
int threshold = settings.AUTO_FOLLOW_ROUTE.get();
if (now - lastTimeAutoZooming > 4500 && (now - lastTimeAutoZooming > threshold || !isUserZoomed)) {
isUserZoomed = false;
lastTimeAutoZooming = now;
// double settingsZoomScale = Math.log(mapView.getSettingsMapDensity()) / Math.log(2.0f);
// double zoomScale = Math.log(tb.getMapDensity()) / Math.log(2.0f);
// double complexZoom = tb.getZoom() + zoomScale + zdelta;
// round to 0.33
targetZoom = Math.round(targetZoom * 3) / 3f;
int newIntegerZoom = (int) Math.round(targetZoom);
double zPart = targetZoom - newIntegerZoom;
return new Pair<>(newIntegerZoom, zPart);
}
}
}
return null;
}
use of mpicbg.trakem2.util.Pair in project Osmand by osmandapp.
the class MapSourceAction method getOnAddBtnClickListener.
@Override
protected View.OnClickListener getOnAddBtnClickListener(final MapActivity activity, final Adapter adapter) {
return new View.OnClickListener() {
@Override
public void onClick(View view) {
final OsmandSettings settings = activity.getMyApplication().getSettings();
final LinkedHashMap<String, String> entriesMap = new LinkedHashMap<>();
entriesMap.put(LAYER_OSM_VECTOR, activity.getString(R.string.vector_data));
entriesMap.putAll(settings.getTileSourceEntries());
final List<Map.Entry<String, String>> entriesMapList = new ArrayList<>(entriesMap.entrySet());
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final String[] items = new String[entriesMapList.size()];
int i = 0;
for (Map.Entry<String, String> entry : entriesMapList) {
items[i++] = entry.getValue();
}
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(activity, R.layout.dialog_text_item);
arrayAdapter.addAll(items);
builder.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
Pair<String, String> layer = new Pair<>(entriesMapList.get(i).getKey(), entriesMapList.get(i).getValue());
adapter.addItem(layer, activity);
dialog.dismiss();
}
});
builder.setNegativeButton(R.string.shared_string_dismiss, null);
builder.show();
}
};
}
use of mpicbg.trakem2.util.Pair in project Osmand by osmandapp.
the class MapUnderlayAction method execute.
@Override
public void execute(MapActivity activity) {
OsmandRasterMapsPlugin plugin = OsmandPlugin.getEnabledPlugin(OsmandRasterMapsPlugin.class);
if (plugin != null) {
OsmandSettings settings = activity.getMyApplication().getSettings();
List<Pair<String, String>> sources = loadListFromParams();
Pair<String, String> currentSource = new Pair<>(settings.MAP_UNDERLAY.get(), settings.MAP_UNDERLAY.get());
Pair<String, String> nextSource = sources.get(0);
int index = sources.indexOf(currentSource);
if (index >= 0 && index + 1 < sources.size()) {
nextSource = sources.get(index + 1);
}
boolean hasUnderlay = !nextSource.first.equals(KEY_NO_UNDERLAY);
if (hasUnderlay) {
settings.MAP_UNDERLAY.set(nextSource.first);
settings.MAP_UNDERLAY_PREVIOUS.set(nextSource.first);
} else {
settings.MAP_UNDERLAY.set(null);
settings.MAP_UNDERLAY_PREVIOUS.set(null);
}
final OsmandSettings.CommonPreference<Boolean> hidePolygonsPref = activity.getMyApplication().getSettings().getCustomRenderBooleanProperty("noPolygons");
hidePolygonsPref.set(hasUnderlay);
plugin.updateMapLayers(activity.getMapView(), settings.MAP_UNDERLAY, activity.getMapLayers());
Toast.makeText(activity, activity.getString(R.string.quick_action_map_underlay_switch, nextSource.second), Toast.LENGTH_SHORT).show();
}
}
use of mpicbg.trakem2.util.Pair in project Osmand by osmandapp.
the class MapUnderlayAction method getOnAddBtnClickListener.
@Override
protected View.OnClickListener getOnAddBtnClickListener(final MapActivity activity, final Adapter adapter) {
return new View.OnClickListener() {
@Override
public void onClick(View view) {
final OsmandSettings settings = activity.getMyApplication().getSettings();
Map<String, String> entriesMap = settings.getTileSourceEntries();
entriesMap.put(KEY_NO_UNDERLAY, activity.getString(R.string.no_underlay));
AlertDialog.Builder builder = new AlertDialog.Builder(activity);
final ArrayList<String> keys = new ArrayList<>(entriesMap.keySet());
final String[] items = new String[entriesMap.size()];
int i = 0;
for (String it : entriesMap.values()) {
items[i++] = it;
}
final ArrayAdapter<String> arrayAdapter = new ArrayAdapter<>(activity, R.layout.dialog_text_item);
arrayAdapter.addAll(items);
builder.setAdapter(arrayAdapter, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
Pair<String, String> layer = new Pair<>(keys.get(i), items[i]);
adapter.addItem(layer, activity);
dialog.dismiss();
}
}).setNegativeButton(R.string.shared_string_cancel, null);
builder.show();
}
};
}
use of mpicbg.trakem2.util.Pair in project streamline by hortonworks.
the class ZookeeperServiceRegistrar method createZookeeperServerComponent.
private Pair<Component, List<ComponentProcess>> createZookeeperServerComponent(Config config, Map<String, String> flattenConfigMap) {
if (!config.contains(PARAM_ZOOKEEPER_SERVER_HOSTNAMES)) {
throw new IllegalArgumentException("Required parameter " + PARAM_ZOOKEEPER_SERVER_HOSTNAMES + " not present.");
}
if (!config.contains(PARAM_ZOOKEEPER_PORT)) {
throw new IllegalArgumentException("Required parameter " + PARAM_ZOOKEEPER_PORT + " not present.");
}
List<String> zookeeperServerHosts;
try {
zookeeperServerHosts = config.getAny(PARAM_ZOOKEEPER_SERVER_HOSTNAMES);
} catch (ClassCastException e) {
throw new IllegalArgumentException("Required parameter " + PARAM_ZOOKEEPER_SERVER_HOSTNAMES + " should be list of string.");
}
Number zookeeperPort;
try {
zookeeperPort = config.getAny(PARAM_ZOOKEEPER_PORT);
} catch (ClassCastException e) {
throw new IllegalArgumentException("Required parameter " + PARAM_ZOOKEEPER_PORT + " should be number.");
}
Component zookeeperServer = new Component();
zookeeperServer.setName(COMPONENT_ZOOKEEPER_SERVER);
List<ComponentProcess> componentProcesses = zookeeperServerHosts.stream().map(host -> {
ComponentProcess cp = new ComponentProcess();
cp.setHost(host);
cp.setPort(zookeeperPort.intValue());
return cp;
}).collect(toList());
return new Pair<>(zookeeperServer, componentProcesses);
}
Aggregations