Search in sources :

Example 36 with Pair

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);
        }
    });
}
Also used : TranSappAccount(cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappAccount) ArrayList(java.util.ArrayList) TranSappUser(cl.smartcities.isci.transportinspector.gamification.transappUser.TranSappUser) Intent(android.content.Intent) BusAvatar(cl.smartcities.isci.transportinspector.backend.BusAvatar) ImageView(android.widget.ImageView) View(android.view.View) ActiveBusView(cl.smartcities.isci.transportinspector.drawables.ActiveBusView) TextView(android.widget.TextView) NonNull(android.support.annotation.NonNull) RankingRequest(cl.smartcities.isci.transportinspector.serverConnection.requests.pullRequests.RankingRequest) Pair(android.support.v4.util.Pair) UiThread(android.support.annotation.UiThread)

Example 37 with Pair

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;
}
Also used : RotatedTileBox(net.osmand.data.RotatedTileBox) Pair(android.support.v4.util.Pair)

Example 38 with Pair

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();
        }
    };
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) View(android.view.View) OsmandSettings(net.osmand.plus.OsmandSettings) LinkedHashMap(java.util.LinkedHashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) ArrayAdapter(android.widget.ArrayAdapter) Pair(android.support.v4.util.Pair)

Example 39 with Pair

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();
    }
}
Also used : OsmandRasterMapsPlugin(net.osmand.plus.rastermaps.OsmandRasterMapsPlugin) OsmandSettings(net.osmand.plus.OsmandSettings) Pair(android.support.v4.util.Pair)

Example 40 with Pair

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();
        }
    };
}
Also used : AlertDialog(android.support.v7.app.AlertDialog) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) View(android.view.View) OsmandSettings(net.osmand.plus.OsmandSettings) ArrayAdapter(android.widget.ArrayAdapter) Pair(android.support.v4.util.Pair)

Aggregations

Pair (android.support.v4.util.Pair)75 ArrayList (java.util.ArrayList)37 View (android.view.View)26 Pair (org.apache.commons.math3.util.Pair)25 ActivityOptionsCompat (android.support.v4.app.ActivityOptionsCompat)16 Intent (android.content.Intent)15 TextView (android.widget.TextView)14 List (java.util.List)12 ImageView (android.widget.ImageView)10 RecyclerView (android.support.v7.widget.RecyclerView)8 AlertDialog (android.support.v7.app.AlertDialog)7 ByteProcessor (ij.process.ByteProcessor)7 HashMap (java.util.HashMap)7 Map (java.util.Map)7 Pair (mpicbg.trakem2.util.Pair)7 NonNull (android.support.annotation.NonNull)6 OsmandSettings (net.osmand.plus.OsmandSettings)6 DialogInterface (android.content.DialogInterface)5 Transition (android.transition.Transition)4 RealLocalizable (net.imglib2.RealLocalizable)4