Search in sources :

Example 1 with PointDescription

use of net.osmand.core.samples.android.sample1.data.PointDescription in project Osmand by osmandapp.

the class MenuBuilder method getCollapsableWikiView.

protected View getCollapsableWikiView(Context context, boolean collapsed) {
    final LinearLayout view = new LinearLayout(context);
    view.setOrientation(LinearLayout.VERTICAL);
    view.setVisibility(collapsed ? View.GONE : View.VISIBLE);
    LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    llParams.setMargins(dpToPx(68f), 0, dpToPx(12f), dpToPx(13f));
    view.setLayoutParams(llParams);
    for (final Amenity wiki : nearestWiki) {
        AppCompatButton wikiButton = new AppCompatButton(new ContextThemeWrapper(view.getContext(), R.style.AppTheme));
        LinearLayout.LayoutParams llWikiButtonParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        wikiButton.setLayoutParams(llWikiButtonParams);
        wikiButton.setPadding(dpToPx(14f), 0, dpToPx(14f), 0);
        wikiButton.setTextColor(app.getResources().getColor(light ? R.color.color_dialog_buttons_light : R.color.color_dialog_buttons_dark));
        wikiButton.setText(wiki.getName());
        wikiButton.setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
        wikiButton.setSingleLine(true);
        wikiButton.setEllipsize(TextUtils.TruncateAt.END);
        wikiButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                PointDescription pointDescription = MenuController.getObjectName(wiki);
                mainActivity.getContextMenu().show(new LatLon(wiki.getLocation().getLatitude(), wiki.getLocation().getLongitude()), pointDescription, wiki);
            }
        });
        view.addView(wikiButton);
    }
    return view;
}
Also used : Amenity(net.osmand.data.Amenity) LatLon(net.osmand.data.LatLon) ContextThemeWrapper(android.support.v7.view.ContextThemeWrapper) PointDescription(net.osmand.core.samples.android.sample1.data.PointDescription) OnClickListener(android.view.View.OnClickListener) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) LinearLayout(android.widget.LinearLayout) AppCompatButton(android.support.v7.widget.AppCompatButton)

Example 2 with PointDescription

use of net.osmand.core.samples.android.sample1.data.PointDescription in project Osmand by osmandapp.

the class QuickSearchDialogFragment method onCreateView.

@Override
@SuppressLint("PrivateResource, ValidFragment")
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final MainActivity mainActivity = getMainActivity();
    final View view = inflater.inflate(R.layout.search_dialog_fragment, container, false);
    /*
		toolbarController = new QuickSearchToolbarController();
		toolbarController.setOnBackButtonClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				mainActivity.showQuickSearch(ShowQuickSearchMode.CURRENT, false);
			}
		});
		toolbarController.setOnTitleClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				mainActivity.showQuickSearch(ShowQuickSearchMode.CURRENT, false);
			}
		});
		toolbarController.setOnCloseButtonClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				mainActivity.closeQuickSearch();
			}
		});
		*/
    Bundle arguments = getArguments();
    if (savedInstanceState != null) {
        searchQuery = savedInstanceState.getString(QUICK_SEARCH_QUERY_KEY);
        double lat = savedInstanceState.getDouble(QUICK_SEARCH_LAT_KEY, Double.NaN);
        double lon = savedInstanceState.getDouble(QUICK_SEARCH_LON_KEY, Double.NaN);
        if (!Double.isNaN(lat) && !Double.isNaN(lon)) {
            centerLatLon = new LatLon(lat, lon);
        }
        interruptedSearch = savedInstanceState.getBoolean(QUICK_SEARCH_INTERRUPTED_SEARCH_KEY, false);
        hidden = savedInstanceState.getBoolean(QUICK_SEARCH_HIDDEN_KEY, false);
        toolbarTitle = savedInstanceState.getString(QUICK_SEARCH_TOOLBAR_TITLE_KEY);
        toolbarVisible = savedInstanceState.getBoolean(QUICK_SEARCH_TOOLBAR_VISIBLE_KEY, false);
    }
    if (searchQuery == null && arguments != null) {
        searchQuery = arguments.getString(QUICK_SEARCH_QUERY_KEY);
        runSearchFirstTime = arguments.getBoolean(QUICK_SEARCH_RUN_SEARCH_FIRST_TIME_KEY, false);
        phraseDefined = arguments.getBoolean(QUICK_SEARCH_PHRASE_DEFINED_KEY, false);
        double lat = arguments.getDouble(QUICK_SEARCH_LAT_KEY, Double.NaN);
        double lon = arguments.getDouble(QUICK_SEARCH_LON_KEY, Double.NaN);
        if (!Double.isNaN(lat) && !Double.isNaN(lon)) {
            centerLatLon = new LatLon(lat, lon);
        }
        newSearch = true;
    }
    if (searchQuery == null)
        searchQuery = "";
    boolean showCategories = false;
    if (arguments != null) {
        showCategories = arguments.getBoolean(QUICK_SEARCH_SHOW_CATEGORIES_KEY, false);
    }
    searchView = view.findViewById(R.id.search_view);
    categoriesView = view.findViewById(R.id.categories_view);
    buttonToolbarView = view.findViewById(R.id.button_toolbar_layout);
    buttonToolbarImage = (ImageView) view.findViewById(R.id.buttonToolbarImage);
    buttonToolbarImage.setImageDrawable(app.getIconsCache().getThemedIcon("ic_action_marker_dark"));
    buttonToolbarText = (TextView) view.findViewById(R.id.buttonToolbarTitle);
    view.findViewById(R.id.buttonToolbar).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            SearchPhrase searchPhrase = searchUICore.getPhrase();
            SearchWord word = searchPhrase.getLastSelectedWord();
            if (word != null && word.getLocation() != null) {
                SearchResult searchResult = word.getResult();
                String name = QuickSearchListItem.getName(app, searchResult);
                String typeName = QuickSearchListItem.getTypeName(app, searchResult);
                PointDescription pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeName, name);
                mainActivity.showOnMap(searchResult.location, searchResult.preferredZoom);
                mainActivity.getContextMenu().show(searchResult.location, pointDescription, searchResult.object);
                hide();
            }
        }
    });
    toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    toolbar.setNavigationIcon(app.getIconsCache().getThemedIcon(R.drawable.ic_arrow_back));
    toolbar.setNavigationContentDescription(app.getString("access_shared_string_navigate_up"));
    toolbar.setNavigationOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            dismiss();
        }
    });
    searchEditText = (EditText) view.findViewById(R.id.searchEditText);
    searchEditText.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }

        @Override
        public void afterTextChanged(Editable s) {
            String newQueryText = s.toString();
            updateClearButtonAndHint();
            updateClearButtonVisibility(true);
            boolean textEmpty = newQueryText.length() == 0;
            updateViewsVisibility(textEmpty);
            if (!searchQuery.equalsIgnoreCase(newQueryText)) {
                searchQuery = newQueryText;
                if (Algorithms.isEmpty(searchQuery)) {
                    searchUICore.resetPhrase();
                } else {
                    runSearch();
                }
            } else if (runSearchFirstTime) {
                runSearchFirstTime = false;
                runSearch();
            }
        }
    });
    progressBar = (ProgressBar) view.findViewById(R.id.searchProgressBar);
    clearButton = (ImageButton) view.findViewById(R.id.clearButton);
    clearButton.setImageDrawable(app.getIconsCache().getThemedIcon(R.drawable.ic_action_remove_dark));
    clearButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (searchEditText.getText().length() > 0) {
                String newText = searchUICore.getPhrase().getTextWithoutLastWord();
                searchEditText.setText(newText);
                searchEditText.setSelection(newText.length());
            } else if (useMapCenter && location != null) {
                useMapCenter = false;
                centerLatLon = null;
                updateUseMapCenterUI();
                LatLon centerLatLon = new LatLon(location.getLatitude(), location.getLongitude());
                SearchSettings ss = searchUICore.getSearchSettings().setOriginalLocation(new LatLon(centerLatLon.getLatitude(), centerLatLon.getLongitude()));
                searchUICore.updateSettings(ss);
                updateClearButtonAndHint();
                updateClearButtonVisibility(true);
                startLocationUpdate();
            }
            updateToolbarButton();
        }
    });
    setupSearch(mainActivity);
    return view;
}
Also used : Bundle(android.os.Bundle) SearchWord(net.osmand.search.core.SearchWord) SearchResult(net.osmand.search.core.SearchResult) MainActivity(net.osmand.core.samples.android.sample1.MainActivity) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) SearchPhrase(net.osmand.search.core.SearchPhrase) SuppressLint(android.annotation.SuppressLint) LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.core.samples.android.sample1.data.PointDescription) OnClickListener(android.view.View.OnClickListener) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) SearchSettings(net.osmand.search.core.SearchSettings) SuppressLint(android.annotation.SuppressLint)

Example 3 with PointDescription

use of net.osmand.core.samples.android.sample1.data.PointDescription in project Osmand by osmandapp.

the class QuickSearchListFragment method showOnMap.

private void showOnMap(SearchResult searchResult) {
    if (searchResult.location != null) {
        SampleApplication app = getMyApplication();
        String lang = searchResult.requiredSearchPhrase.getSettings().getLang();
        boolean transliterate = searchResult.requiredSearchPhrase.getSettings().isTransliterate();
        PointDescription pointDescription = null;
        Object object = searchResult.object;
        switch(searchResult.objectType) {
            case POI:
                Amenity a = (Amenity) object;
                String poiSimpleFormat = SampleFormatter.getPoiStringWithoutType(a, lang, transliterate);
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_POI, poiSimpleFormat);
                pointDescription.setIconName(QuickSearchListItem.getAmenityIconName(a));
                break;
            case HOUSE:
                String typeNameHouse = null;
                String name = searchResult.localeName;
                if (searchResult.relatedObject instanceof City) {
                    name = ((City) searchResult.relatedObject).getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true) + " " + name;
                } else if (searchResult.relatedObject instanceof Street) {
                    String s = ((Street) searchResult.relatedObject).getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
                    typeNameHouse = ((Street) searchResult.relatedObject).getCity().getName(searchResult.requiredSearchPhrase.getSettings().getLang(), true);
                    name = s + " " + name;
                } else if (searchResult.localeRelatedObjectName != null) {
                    name = searchResult.localeRelatedObjectName + " " + name;
                }
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeNameHouse, name);
                pointDescription.setIconName("ic_action_building");
                break;
            case LOCATION:
                pointDescription = new PointDescription(searchResult.location.getLatitude(), searchResult.location.getLongitude());
                pointDescription.setIconName("ic_action_world_globe");
                break;
            case STREET_INTERSECTION:
                String typeNameIntersection = QuickSearchListItem.getTypeName(app, searchResult);
                if (Algorithms.isEmpty(typeNameIntersection)) {
                    typeNameIntersection = null;
                }
                pointDescription = new PointDescription(PointDescription.POINT_TYPE_ADDRESS, typeNameIntersection, QuickSearchListItem.getName(app, searchResult));
                pointDescription.setIconName("ic_action_intersection");
                break;
        }
        dialogFragment.hideToolbar();
        dialogFragment.hide();
        getMainActivity().showOnMap(searchResult.location, searchResult.preferredZoom);
        getMainActivity().getContextMenu().show(searchResult.location, pointDescription, object);
    }
}
Also used : SampleApplication(net.osmand.core.samples.android.sample1.SampleApplication) Amenity(net.osmand.data.Amenity) PointDescription(net.osmand.core.samples.android.sample1.data.PointDescription) Street(net.osmand.data.Street) City(net.osmand.data.City)

Example 4 with PointDescription

use of net.osmand.core.samples.android.sample1.data.PointDescription in project Osmand by osmandapp.

the class MapContextMenu method init.

public boolean init(@NonNull LatLon latLon, @Nullable PointDescription pointDescription, @Nullable Object object, boolean update, boolean restorePrevious) {
    if (myLocation == null) {
        myLocation = mainActivity.getMyApplication().getLocationProvider().getLastKnownLocationLatLon();
    }
    if (!update && isVisible()) {
        if (this.object == null || !this.object.equals(object)) {
            hide();
        } else {
            return false;
        }
    }
    if (pointDescription == null) {
        this.pointDescription = new PointDescription(latLon.getLatitude(), latLon.getLongitude());
    } else {
        this.pointDescription = pointDescription;
    }
    boolean needAcquireMenuController = menuController == null || !update || this.object == null && object != null || this.object != null && object == null || (this.object != null && object != null && !this.object.getClass().equals(object.getClass()));
    this.latLon = latLon;
    this.object = object;
    active = true;
    if (needAcquireMenuController) {
        acquireMenuController(restorePrevious);
    } else {
        menuController.update(pointDescription, object);
    }
    initTitle();
    if (menuController != null) {
        menuController.clearPlainMenuItems();
        menuController.addPlainMenuItems(typeStr, this.pointDescription, this.latLon);
    }
    mainActivity.refreshMap();
    return true;
}
Also used : PointDescription(net.osmand.core.samples.android.sample1.data.PointDescription)

Example 5 with PointDescription

use of net.osmand.core.samples.android.sample1.data.PointDescription in project Osmand by osmandapp.

the class MapMultiSelectionMenu method createCollection.

private void createCollection(List<Object> selectedObjects) {
    objects.clear();
    for (Object selectedObj : selectedObjects) {
        LatLon ll = MenuController.getObjectLocation(selectedObj);
        PointDescription pointDescription = MenuController.getObjectName(selectedObj);
        if (ll == null) {
            ll = latLon;
        }
        if (pointDescription == null) {
            pointDescription = new PointDescription(latLon.getLatitude(), latLon.getLongitude());
        }
        MenuObject menuObject = new MenuObject(ll, pointDescription, selectedObj, getMainActivity());
        menuObject.order = MenuController.getObjectPriority(selectedObj);
        objects.add(menuObject);
    }
    Collections.sort(objects, new Comparator<MenuObject>() {

        @Override
        public int compare(MenuObject obj1, MenuObject obj2) {
            if (obj1.order == obj2.order) {
                return obj1.getTitleStr().compareToIgnoreCase(obj2.getTitleStr());
            } else {
                return obj1.order - obj2.order;
            }
        }
    });
}
Also used : LatLon(net.osmand.data.LatLon) PointDescription(net.osmand.core.samples.android.sample1.data.PointDescription)

Aggregations

PointDescription (net.osmand.core.samples.android.sample1.data.PointDescription)5 LatLon (net.osmand.data.LatLon)4 Amenity (net.osmand.data.Amenity)3 View (android.view.View)2 OnClickListener (android.view.View.OnClickListener)2 ImageView (android.widget.ImageView)2 TextView (android.widget.TextView)2 SampleApplication (net.osmand.core.samples.android.sample1.SampleApplication)2 SuppressLint (android.annotation.SuppressLint)1 Bundle (android.os.Bundle)1 ContextThemeWrapper (android.support.v7.view.ContextThemeWrapper)1 AppCompatButton (android.support.v7.widget.AppCompatButton)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 LinearLayout (android.widget.LinearLayout)1 MainActivity (net.osmand.core.samples.android.sample1.MainActivity)1 AmenityMenuController (net.osmand.core.samples.android.sample1.mapcontextmenu.controllers.AmenityMenuController)1 MyLocationMenuController (net.osmand.core.samples.android.sample1.mapcontextmenu.controllers.MyLocationMenuController)1 PointDescriptionMenuController (net.osmand.core.samples.android.sample1.mapcontextmenu.controllers.PointDescriptionMenuController)1 City (net.osmand.data.City)1