List of usage examples for android.database MatrixCursor getColumnIndex
@Override public int getColumnIndex(String columnName)
From source file:com.esri.arcgisruntime.sample.findaddress.MainActivity.java
/** * Sets up the address SearchView. Uses MatrixCursor to show suggestions to the user as the user inputs text. *///ww w . j av a 2 s . c o m private void setupAddressSearchView() { mAddressGeocodeParameters = new GeocodeParameters(); // get place name and address attributes mAddressGeocodeParameters.getResultAttributeNames().add("PlaceName"); mAddressGeocodeParameters.getResultAttributeNames().add("StAddr"); // return only the closest result mAddressGeocodeParameters.setMaxResults(1); mAddressSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String address) { // geocode typed address geoCodeTypedAddress(address); // clear focus from search views mAddressSearchView.clearFocus(); return true; } @Override public boolean onQueryTextChange(String newText) { // as long as newText isn't empty, get suggestions from the locatorTask if (!newText.equals("")) { final ListenableFuture<List<SuggestResult>> suggestionsFuture = mLocatorTask .suggestAsync(newText); suggestionsFuture.addDoneListener(new Runnable() { @Override public void run() { try { // get the results of the async operation List<SuggestResult> suggestResults = suggestionsFuture.get(); MatrixCursor suggestionsCursor = new MatrixCursor(mColumnNames); int key = 0; // add each address suggestion to a new row for (SuggestResult result : suggestResults) { suggestionsCursor.addRow(new Object[] { key++, result.getLabel() }); } // define SimpleCursorAdapter String[] cols = new String[] { COLUMN_NAME_ADDRESS }; int[] to = new int[] { R.id.suggestion_address }; final SimpleCursorAdapter suggestionAdapter = new SimpleCursorAdapter( MainActivity.this, R.layout.suggestion, suggestionsCursor, cols, to, 0); mAddressSearchView.setSuggestionsAdapter(suggestionAdapter); // handle an address suggestion being chosen mAddressSearchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() { @Override public boolean onSuggestionSelect(int position) { return false; } @Override public boolean onSuggestionClick(int position) { // get the selected row MatrixCursor selectedRow = (MatrixCursor) suggestionAdapter .getItem(position); // get the row's index int selectedCursorIndex = selectedRow.getColumnIndex(COLUMN_NAME_ADDRESS); // get the string from the row at index String address = selectedRow.getString(selectedCursorIndex); // use clicked suggestion as query mAddressSearchView.setQuery(address, true); return true; } }); } catch (Exception e) { Log.e(TAG, "Geocode suggestion error: " + e.getMessage()); } } }); } return true; } }); }
From source file:com.esri.arcgisruntime.sample.findplace.MainActivity.java
/** * Sets up the POI SearchView. Uses MatrixCursor to show suggestions to the user as the user inputs text. *//* ww w .jav a 2s . c o m*/ private void setupPoi() { mPoiSuggestParameters = new SuggestParameters(); // filter categories for POI mPoiSuggestParameters.getCategories().add("POI"); mPoiGeocodeParameters = new GeocodeParameters(); // get all attributes mPoiGeocodeParameters.getResultAttributeNames().add("*"); mPoiSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String address) { // if proximity SearchView text box is empty, use the device location if (mProximitySearchViewEmpty) { mPreferredSearchProximity = mLocationDisplay.getMapLocation(); mProximitySearchView.setQuery("Using current location...", false); } // keep track of typed address mPoiAddress = address; // geocode typed address geoCodeTypedAddress(address); // clear focus from search views mPoiSearchView.clearFocus(); mProximitySearchView.clearFocus(); return true; } @Override public boolean onQueryTextChange(final String newText) { // as long as newText isn't empty, get suggestions from the locatorTask if (!newText.equals("")) { mPoiSuggestParameters.setSearchArea(mCurrentExtentGeometry); final ListenableFuture<List<SuggestResult>> suggestionsFuture = mLocatorTask .suggestAsync(newText, mPoiSuggestParameters); suggestionsFuture.addDoneListener(new Runnable() { @Override public void run() { try { // get the results of the async operation List<SuggestResult> suggestResults = suggestionsFuture.get(); if (!suggestResults.isEmpty()) { MatrixCursor suggestionsCursor = new MatrixCursor(mColumnNames); int key = 0; // add each poi_suggestion result to a new row for (SuggestResult result : suggestResults) { suggestionsCursor.addRow(new Object[] { key++, result.getLabel() }); } // define SimpleCursorAdapter String[] cols = new String[] { COLUMN_NAME_ADDRESS }; int[] to = new int[] { R.id.suggestion_address }; final SimpleCursorAdapter suggestionAdapter = new SimpleCursorAdapter( MainActivity.this, R.layout.suggestion, suggestionsCursor, cols, to, 0); mPoiSearchView.setSuggestionsAdapter(suggestionAdapter); // handle a poi_suggestion being chosen mPoiSearchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() { @Override public boolean onSuggestionSelect(int position) { return false; } @Override public boolean onSuggestionClick(int position) { // get the selected row MatrixCursor selectedRow = (MatrixCursor) suggestionAdapter .getItem(position); // get the row's index int selectedCursorIndex = selectedRow .getColumnIndex(COLUMN_NAME_ADDRESS); // get the string from the row at index mPoiAddress = selectedRow.getString(selectedCursorIndex); mPoiSearchView.setQuery(mPoiAddress, true); return true; } }); } else { mPoiAddress = newText; } } catch (Exception e) { Log.e(TAG, "Geocode suggestion error: " + e.getMessage()); } } }); } return true; } }); }
From source file:com.esri.arcgisruntime.sample.findplace.MainActivity.java
/** * Sets up the proximity SearchView. Uses MatrixCursor to show suggestions to the user as the user inputs text. *//*from w w w . java2s . com*/ private void setupProximity() { mProximitySuggestParameters = new SuggestParameters(); mProximitySuggestParameters.getCategories().add("Populated Place"); mProximityGeocodeParameters = new GeocodeParameters(); // get all attributes mProximityGeocodeParameters.getResultAttributeNames().add("*"); mProximitySearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String address) { geoCodeTypedAddress(address); // clear focus from search views mPoiSearchView.clearFocus(); mProximitySearchView.clearFocus(); return true; } @Override public boolean onQueryTextChange(String newText) { // as long as newText isn't empty, get suggestions from the locatorTask if (!newText.equals("")) { mProximitySearchViewEmpty = false; final ListenableFuture<List<SuggestResult>> suggestionsFuture = mLocatorTask .suggestAsync(newText, mProximitySuggestParameters); suggestionsFuture.addDoneListener(new Runnable() { @Override public void run() { try { // get the list of suggestions List<SuggestResult> suggestResults = suggestionsFuture.get(); MatrixCursor suggestionsCursor = new MatrixCursor(mColumnNames); int key = 0; // add each SuggestResult to a new row for (SuggestResult result : suggestResults) { suggestionsCursor.addRow(new Object[] { key++, result.getLabel() }); } // define SimpleCursorAdapter String[] cols = new String[] { COLUMN_NAME_ADDRESS }; int[] to = new int[] { R.id.suggestion_address }; final SimpleCursorAdapter suggestionAdapter = new SimpleCursorAdapter( MainActivity.this, R.layout.suggestion, suggestionsCursor, cols, to, 0); mProximitySearchView.setSuggestionsAdapter(suggestionAdapter); mProximitySearchView.setOnSuggestionListener(new SearchView.OnSuggestionListener() { @Override public boolean onSuggestionSelect(int position) { return false; } @Override public boolean onSuggestionClick(int position) { // get the selected row MatrixCursor selectedRow = (MatrixCursor) suggestionAdapter .getItem(position); // get the row's index int selectedCursorIndex = selectedRow.getColumnIndex(COLUMN_NAME_ADDRESS); // get the string from the row at index final String address = selectedRow.getString(selectedCursorIndex); mLocatorTask.addDoneLoadingListener(new Runnable() { @Override public void run() { if (mLocatorTask.getLoadStatus() == LoadStatus.LOADED) { // geocode the selected address to get location of address final ListenableFuture<List<GeocodeResult>> geocodeFuture = mLocatorTask .geocodeAsync(address, mProximityGeocodeParameters); geocodeFuture.addDoneListener(new Runnable() { @Override public void run() { try { // Get the results of the async operation List<GeocodeResult> geocodeResults = geocodeFuture .get(); if (geocodeResults.size() > 0) { // use geocodeResult to focus search area GeocodeResult geocodeResult = geocodeResults .get(0); // update preferred search area to the geocode result mPreferredSearchProximity = geocodeResult .getDisplayLocation(); mPoiGeocodeParameters.setSearchArea( mPreferredSearchProximity); // set the address string to the SearchView, but don't submit as a query mProximitySearchView.setQuery(address, false); // call POI search query mPoiSearchView.setQuery(mPoiAddress, true); // clear focus from search views mProximitySearchView.clearFocus(); mPoiSearchView.clearFocus(); } else { Toast.makeText(getApplicationContext(), getString(R.string.location_not_found) + address, Toast.LENGTH_LONG).show(); } } catch (InterruptedException | ExecutionException e) { Log.e(TAG, "Geocode error: " + e.getMessage()); Toast.makeText(getApplicationContext(), getString(R.string.geo_locate_error), Toast.LENGTH_LONG).show(); } } }); } } }); return true; } }); } catch (Exception e) { Log.e(TAG, "Geocode suggestion error: " + e.getMessage()); } } }); // if search view is empty, set flag } else { mProximitySearchViewEmpty = true; } return true; } }); }
From source file:com.esri.android.mapsapp.MapFragment.java
/** * Displays the search view layout// w ww .ja v a 2s. com * */ private void showSearchBoxLayout() { // Inflating the layout from the xml file mSearchBox = mInflater.inflate(R.layout.searchview, null); // Inflate navigation drawer button on SearchView navButton = (ImageButton) mSearchBox.findViewById(R.id.btn_nav_menu); // Get the navigation drawer from Activity mDrawerLayout = (DrawerLayout) getActivity().findViewById(R.id.maps_app_activity_drawer_layout); mDrawerList = (ListView) getActivity().findViewById(R.id.maps_app_activity_left_drawer); // Set click listener to open/close drawer navButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mDrawerLayout.isDrawerOpen(mDrawerList)) { mDrawerLayout.closeDrawer(mDrawerList); } else { mDrawerLayout.openDrawer(mDrawerList); } } }); // Setting the layout parameters to the layout mSearchBox.setLayoutParams(mlayoutParams); // Initializing the searchview and the image view mSearchview = (SearchView) mSearchBox.findViewById(R.id.searchView1); ImageView iv_route = (ImageView) mSearchBox.findViewById(R.id.imageView1); mSearchview.setIconifiedByDefault(false); mSearchview.setQueryHint(SEARCH_HINT); applySuggestionCursor(); // navButton = (Button)mSearchBox.findViewById(R.id.navbutton); // Adding the layout to the map conatiner mMapContainer.addView(mSearchBox); // Setup the listener for the route onclick iv_route.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { showRoutingDialogFragment(); } }); // Setup the listener when the search button is pressed on the keyboard mSearchview.setOnQueryTextListener(new OnQueryTextListener() { @Override public boolean onQueryTextSubmit(String query) { onSearchButtonClicked(query); mSearchview.clearFocus(); return true; } @Override public boolean onQueryTextChange(String newText) { if (mLocator == null) return false; getSuggestions(newText); return true; } }); // Add the compass after getting the height of the layout mSearchBox.getViewTreeObserver().addOnGlobalLayoutListener(new OnGlobalLayoutListener() { @Override public void onGlobalLayout() { addCompass(mSearchBox.getHeight()); mSearchBox.getViewTreeObserver().removeGlobalOnLayoutListener(this); } }); mSearchview.setOnSuggestionListener(new SearchView.OnSuggestionListener() { @Override public boolean onSuggestionSelect(int position) { return false; } @Override public boolean onSuggestionClick(int position) { // Obtain the content of the selected suggesting place via cursor MatrixCursor cursor = (MatrixCursor) mSearchview.getSuggestionsAdapter().getItem(position); int indexColumnSuggestion = cursor.getColumnIndex(COLUMN_NAME_ADDRESS); final String address = cursor.getString(indexColumnSuggestion); suggestionClickFlag = true; // Find the Location of the suggestion new FindLocationTask(address).execute(address); cursor.close(); return true; } }); }