Search in sources :

Example 1 with MainActivity

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

the class MapMultiSelectionMenuFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    menu = ((MainActivity) getActivity()).getContextMenu().getMultiSelectionMenu();
    view = inflater.inflate(R.layout.menu_obj_selection_fragment, container, false);
    if (menu.isLandscapeLayout()) {
        AndroidUtils.setBackground(view.getContext(), view, !menu.isLight(), R.drawable.bg_left_menu_light, 0);
    } else {
        AndroidUtils.setBackground(view.getContext(), view, !menu.isLight(), R.drawable.bg_bottom_menu_light, 0);
    }
    ListView listView = (ListView) view.findViewById(R.id.list);
    listAdapter = createAdapter();
    listView.setAdapter(listAdapter);
    listView.setOnItemClickListener(this);
    if (!oldAndroid()) {
        runLayoutListener();
    }
    return view;
}
Also used : ListView(android.widget.ListView) MainActivity(net.osmand.core.samples.android.sample1.MainActivity) Nullable(android.support.annotation.Nullable)

Example 2 with MainActivity

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

the class MapMultiSelectionMenuFragment method buildHeader.

private void buildHeader(View view, MenuObject item, MainActivity mainActivity) {
    AndroidUtils.setBackground(mainActivity, view, !menu.isLight(), R.drawable.expandable_list_item_background_light, 0);
    IconsCache iconsCache = mainActivity.getMyApplication().getIconsCache();
    final View iconLayout = view.findViewById(R.id.context_menu_icon_layout);
    final ImageView iconView = (ImageView) view.findViewById(R.id.context_menu_icon_view);
    Drawable icon = item.getLeftIcon();
    int iconId = item.getLeftIconId();
    if (icon != null) {
        iconView.setImageDrawable(icon);
        iconLayout.setVisibility(View.VISIBLE);
    } else if (iconId != 0) {
        iconView.setImageDrawable(iconsCache.getOsmandIcon(iconId, menu.isLight() ? R.color.osmand_orange : R.color.osmand_orange_dark));
        iconLayout.setVisibility(View.VISIBLE);
    } else {
        iconLayout.setVisibility(View.GONE);
    }
    // Text line 1
    TextView line1 = (TextView) view.findViewById(R.id.context_menu_line1);
    AndroidUtils.setTextPrimaryColor(mainActivity, line1, !menu.isLight());
    line1.setText(item.getTitleStr());
    // Text line 2
    TextView line2 = (TextView) view.findViewById(R.id.context_menu_line2);
    AndroidUtils.setTextSecondaryColor(mainActivity, line2, !menu.isLight());
    line2.setText(item.getTypeStr());
    Drawable slIcon = item.getTypeIcon();
    line2.setCompoundDrawablesWithIntrinsicBounds(slIcon, null, null, null);
    line2.setCompoundDrawablePadding(dpToPx(5f));
}
Also used : Drawable(android.graphics.drawable.Drawable) TextView(android.widget.TextView) IconsCache(net.osmand.core.samples.android.sample1.IconsCache) ImageView(android.widget.ImageView) ImageView(android.widget.ImageView) View(android.view.View) AdapterView(android.widget.AdapterView) TextView(android.widget.TextView) ListView(android.widget.ListView) SuppressLint(android.annotation.SuppressLint)

Example 3 with MainActivity

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

the class QuickSearchDialogFragment method onDismiss.

@Override
public void onDismiss(DialogInterface dialog) {
    MainActivity mainActivity = getMainActivity();
    if (mainActivity != null) {
        hideToolbar();
        getChildFragmentManager().popBackStack();
    }
    super.onDismiss(dialog);
}
Also used : MainActivity(net.osmand.core.samples.android.sample1.MainActivity)

Example 4 with MainActivity

use of net.osmand.core.samples.android.sample1.MainActivity 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 5 with MainActivity

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

the class MenuController method getMenuController.

public static MenuController getMenuController(MainActivity mainActivity, LatLon latLon, PointDescription pointDescription, Object object, MenuType menuType) {
    SampleApplication app = mainActivity.getMyApplication();
    MenuController menuController = null;
    if (object != null) {
        if (object instanceof Amenity) {
            menuController = new AmenityMenuController(mainActivity, pointDescription, (Amenity) object);
        } else if (object instanceof LatLon) {
            if (pointDescription.isMyLocation()) {
                menuController = new MyLocationMenuController(mainActivity, pointDescription);
            }
        }
    }
    if (menuController == null) {
        menuController = new PointDescriptionMenuController(mainActivity, pointDescription);
    }
    menuController.menuType = menuType;
    menuController.setLatLon(latLon);
    return menuController;
}
Also used : SampleApplication(net.osmand.core.samples.android.sample1.SampleApplication) Amenity(net.osmand.data.Amenity) LatLon(net.osmand.data.LatLon) AmenityMenuController(net.osmand.core.samples.android.sample1.mapcontextmenu.controllers.AmenityMenuController) MyLocationMenuController(net.osmand.core.samples.android.sample1.mapcontextmenu.controllers.MyLocationMenuController) PointDescriptionMenuController(net.osmand.core.samples.android.sample1.mapcontextmenu.controllers.PointDescriptionMenuController) AmenityMenuController(net.osmand.core.samples.android.sample1.mapcontextmenu.controllers.AmenityMenuController) PointDescriptionMenuController(net.osmand.core.samples.android.sample1.mapcontextmenu.controllers.PointDescriptionMenuController) MyLocationMenuController(net.osmand.core.samples.android.sample1.mapcontextmenu.controllers.MyLocationMenuController)

Aggregations

MainActivity (net.osmand.core.samples.android.sample1.MainActivity)3 SuppressLint (android.annotation.SuppressLint)2 View (android.view.View)2 ImageView (android.widget.ImageView)2 ListView (android.widget.ListView)2 TextView (android.widget.TextView)2 LatLon (net.osmand.data.LatLon)2 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1 Nullable (android.support.annotation.Nullable)1 Editable (android.text.Editable)1 TextWatcher (android.text.TextWatcher)1 OnClickListener (android.view.View.OnClickListener)1 AdapterView (android.widget.AdapterView)1 IconsCache (net.osmand.core.samples.android.sample1.IconsCache)1 SampleApplication (net.osmand.core.samples.android.sample1.SampleApplication)1 PointDescription (net.osmand.core.samples.android.sample1.data.PointDescription)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