Search in sources :

Example 16 with PoiType

use of io.jawg.osmcontributor.model.entities.PoiType in project osm-contributor by jawg.

the class MapFragment method loadPoiTypeFloatingBtn.

public void loadPoiTypeFloatingBtn() {
    if (addPoiFloatingMenu != null) {
        addPoiFloatingMenu.removeAllMenuButtons();
    }
    FloatingActionButton floatingActionButton;
    // add note
    if (!FlavorUtils.isBus()) {
        floatingActionButton = new FloatingActionButton(getActivity());
        floatingActionButton.setLabelText(getString(R.string.note));
        floatingActionButton.setColorPressed(ContextCompat.getColor(getActivity(), R.color.material_green_700));
        floatingActionButton.setColorNormal(ContextCompat.getColor(getActivity(), R.color.material_green_500));
        floatingActionButton.setButtonSize(FloatingActionButton.SIZE_MINI);
        floatingActionButton.setImageDrawable(bitmapHandler.getIconWhite(null));
        floatingActionButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                switchMode(MapMode.NOTE_CREATION);
                addPoiFloatingMenu.close(true);
            }
        });
        addPoiFloatingMenu.addMenuButton(floatingActionButton);
    }
    if (presenter.getNumberOfPoiTypes() <= maxPoiType) {
        // add a btn per poiType
        for (final PoiType poiType : presenter.getPoiTypes()) {
            floatingActionButton = new FloatingActionButton(getActivity());
            floatingActionButton.setLabelText(poiType.getName());
            floatingActionButton.setColorPressed(ContextCompat.getColor(getActivity(), R.color.material_blue_grey_800));
            floatingActionButton.setColorNormal(ContextCompat.getColor(getActivity(), R.color.material_blue_500));
            floatingActionButton.setButtonSize(FloatingActionButton.SIZE_MINI);
            floatingActionButton.setImageDrawable(bitmapHandler.getIconWhite(poiType));
            floatingActionButton.setOnClickListener(new View.OnClickListener() {

                @Override
                public void onClick(View view) {
                    if (configManager.hasPoiAddition()) {
                        switchMode(MapMode.POI_CREATION);
                        poiTypeSelected(poiType);
                        addPoiFloatingMenu.close(true);
                    } else {
                        Toast.makeText(getActivity(), getResources().getString(R.string.point_modification_forbidden), Toast.LENGTH_SHORT).show();
                    }
                }
            });
            addPoiFloatingMenu.addMenuButton(floatingActionButton);
        }
    } else {
        // add a btn for all poiTypes
        floatingActionButton = new FloatingActionButton(getActivity());
        floatingActionButton.setLabelText(getResources().getString(R.string.add_poi));
        floatingActionButton.setColorPressed(ContextCompat.getColor(getActivity(), R.color.material_blue_grey_800));
        floatingActionButton.setColorNormal(ContextCompat.getColor(getActivity(), R.color.material_blue_500));
        floatingActionButton.setButtonSize(FloatingActionButton.SIZE_MINI);
        floatingActionButton.setImageDrawable(ContextCompat.getDrawable(getActivity(), R.drawable.fab_poi));
        floatingActionButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View view) {
                if (configManager.hasPoiAddition()) {
                    switchMode(MapMode.TYPE_PICKER);
                } else {
                    Toast.makeText(getActivity(), getResources().getString(R.string.point_modification_forbidden), Toast.LENGTH_SHORT).show();
                }
            }
        });
        addPoiFloatingMenu.addMenuButton(floatingActionButton);
    }
}
Also used : PleaseLoadLastUsedPoiType(io.jawg.osmcontributor.ui.events.map.PleaseLoadLastUsedPoiType) PoiType(io.jawg.osmcontributor.model.entities.PoiType) FloatingActionButton(com.github.clans.fab.FloatingActionButton) ImageView(android.widget.ImageView) MapView(com.mapbox.mapboxsdk.maps.MapView) LocationMarkerView(io.jawg.osmcontributor.ui.utils.views.map.marker.LocationMarkerView) BindView(butterknife.BindView) View(android.view.View) TextView(android.widget.TextView) ListView(android.widget.ListView)

Example 17 with PoiType

use of io.jawg.osmcontributor.model.entities.PoiType in project osm-contributor by jawg.

the class TypeManager method onInternalRemovePoiTagEvent.

@Subscribe(threadMode = ThreadMode.ASYNC)
public void onInternalRemovePoiTagEvent(InternalRemovePoiTagEvent event) {
    PoiTypeTag poiTypeTag = event.getPoiTypeTag();
    // FIXME clone POI type to avoid border effects?;
    PoiType poiType = poiTypeTag.getPoiType();
    poiType.getTags().remove(poiTypeTag);
    poiManager.savePoiType(poiType);
    Timber.i("Removed poi tag %d", poiTypeTag.getId());
    bus.post(new PoiTagDeletedEvent(poiTypeTag));
}
Also used : PoiType(io.jawg.osmcontributor.model.entities.PoiType) PoiTypeTag(io.jawg.osmcontributor.model.entities.PoiTypeTag) PoiTagDeletedEvent(io.jawg.osmcontributor.ui.events.type.PoiTagDeletedEvent) Subscribe(org.greenrobot.eventbus.Subscribe)

Example 18 with PoiType

use of io.jawg.osmcontributor.model.entities.PoiType in project osm-contributor by jawg.

the class PoiMapperTest method poiType.

private PoiType poiType(String name, String... tags) {
    PoiType t1 = new PoiType();
    t1.setName(name);
    List<PoiTypeTag> poiTypeTags = new ArrayList<>();
    if (tags.length % 2 != 0) {
        throw new AssertionError("Malformed tags ! Array must be an even number");
    }
    for (int i = 0; i < tags.length; i += 2) {
        poiTypeTags.add(poiTypeTag(tags[i], tags[i + 1]));
    }
    t1.setTags(poiTypeTags);
    return t1;
}
Also used : PoiType(io.jawg.osmcontributor.model.entities.PoiType) ArrayList(java.util.ArrayList) PoiTypeTag(io.jawg.osmcontributor.model.entities.PoiTypeTag)

Example 19 with PoiType

use of io.jawg.osmcontributor.model.entities.PoiType in project osm-contributor by jawg.

the class PoiManager method savePoiTypes.

public void savePoiTypes(List<PoiType> poiTypes) {
    if (poiTypes != null) {
        Timber.d("Loaded %s poiTypes, trying to insert them", poiTypes.size());
        for (PoiType poiType : poiTypes) {
            Timber.d("saving poiType %s", poiType);
            savePoiType(poiType);
            Timber.d("poiType saved");
        }
    }
}
Also used : PleaseLoadLastUsedPoiType(io.jawg.osmcontributor.ui.events.map.PleaseLoadLastUsedPoiType) PoiType(io.jawg.osmcontributor.model.entities.PoiType)

Example 20 with PoiType

use of io.jawg.osmcontributor.model.entities.PoiType in project osm-contributor by jawg.

the class PoiManager method loadPoiTypes.

/**
 * Get all the PoiTypes in the database.
 *
 * @return A ID,PoiType map with all the PoiTypes.
 */
public Map<Long, PoiType> loadPoiTypes() {
    List<PoiType> poiTypes = poiTypeDao.queryForAll();
    Map<Long, PoiType> result = new HashMap<>();
    for (PoiType poiType : poiTypes) {
        result.put(poiType.getId(), poiType);
    }
    return result;
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) PleaseLoadLastUsedPoiType(io.jawg.osmcontributor.ui.events.map.PleaseLoadLastUsedPoiType) PoiType(io.jawg.osmcontributor.model.entities.PoiType)

Aggregations

PoiType (io.jawg.osmcontributor.model.entities.PoiType)28 PoiTypeTag (io.jawg.osmcontributor.model.entities.PoiTypeTag)9 Subscribe (org.greenrobot.eventbus.Subscribe)9 ArrayList (java.util.ArrayList)7 PleaseLoadLastUsedPoiType (io.jawg.osmcontributor.ui.events.map.PleaseLoadLastUsedPoiType)5 View (android.view.View)3 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 BindView (butterknife.BindView)2 Poi (io.jawg.osmcontributor.model.entities.Poi)2 PoiTag (io.jawg.osmcontributor.model.entities.PoiTag)2 PoiTypesLoaded (io.jawg.osmcontributor.model.events.PoiTypesLoaded)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 DateTime (org.joda.time.DateTime)2 NonNull (android.support.annotation.NonNull)1 Snackbar (android.support.design.widget.Snackbar)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 ListView (android.widget.ListView)1