use of net.imglib2.util.Pair in project androidApp by InspectorIncognito.
the class UserFragment method updateUI.
@UiThread
private void updateUI() {
final TranSappAccount account = TranSappAccountManager.getCurrentAccount();
if (!TranSappAccountManager.isLoggedIn()) {
getActivity().finish();
return;
}
progressImage.setProgressValues(account.getScore(), account.getLevelMinScore(), account.getLevelMaxScore());
progressImage.loadImage(account);
userName.setText(account.getName());
level.setText(String.format(Locale.getDefault(), "NIVEL %d", account.getLevelPosition()));
score.setText(String.format(Locale.getDefault(), "%s de %s ptos", account.getFormattedScore(), account.getFormattedLevelMaxScore()));
levelName.setText(account.getLevelName());
levelBackground.setImageResource(account.getLevelBackgroundImage());
rankingPosition.setText(String.format(Locale.getDefault(), "%d", account.currentUser.globalRankingPosition));
rankingFrame.setImageResource(account.getLevelSimpleFrame());
int id = account.getBusAvatarId();
userBusAvatarView.setAvatarId(id);
BusAvatar avatar = Avatar.getBusAvatarById(id);
userBusAvatarTitle.setText(getString(avatar.titleId));
rankingButton.setClickable(true);
rankingPosition.setVisibility(View.VISIBLE);
rankingProgressBar.setVisibility(View.GONE);
rankingButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
rankingButton.setClickable(false);
rankingPosition.setVisibility(View.GONE);
rankingProgressBar.setVisibility(View.VISIBLE);
RankingRequest request = new RankingRequest(new Request.RequestListener<Pair<ArrayList<TranSappUser>, ArrayList<TranSappUser>>>() {
@Override
public void onRequestError() {
if (getActivity() == null || getContext() == null) {
return;
}
Toast.makeText(getActivity(), "Ranking no disponible", Toast.LENGTH_SHORT).show();
rankingButton.setClickable(true);
rankingPosition.setVisibility(View.VISIBLE);
rankingProgressBar.setVisibility(View.GONE);
}
@Override
public void onRequestResult(@NonNull Pair<ArrayList<TranSappUser>, ArrayList<TranSappUser>> response) {
if (getActivity() == null || getContext() == null) {
return;
}
Intent intent = new Intent(getActivity(), RankingActivity.class);
intent.putParcelableArrayListExtra(RankingActivity.TOP_RANKING_KEY, response.first);
intent.putParcelableArrayListExtra(RankingActivity.USER_RANKING_KEY, response.second);
startActivityForResult(intent, RANKING_ACTIVITY_CODE);
}
}, account);
ServerController.sendRequest(request, null);
}
});
}
use of net.imglib2.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 net.imglib2.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 net.imglib2.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 net.imglib2.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();
}
};
}
Aggregations