本文整理汇总了Java中com.google.android.gms.location.places.AutocompletePrediction类的典型用法代码示例。如果您正苦于以下问题:Java AutocompletePrediction类的具体用法?Java AutocompletePrediction怎么用?Java AutocompletePrediction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AutocompletePrediction类属于com.google.android.gms.location.places包,在下文中一共展示了AutocompletePrediction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getView
import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = super.getView(position, convertView, parent);
// Sets the primary and secondary text for a row.
// Note that getPrimaryText() and getSecondaryText() return a CharSequence that may contain
// styling based on the given CharacterStyle.
AutocompletePrediction item = getItem(position);
TextView textView1 = (TextView) row.findViewById(android.R.id.text1);
TextView textView2 = (TextView) row.findViewById(android.R.id.text2);
textView1.setText(item.getPrimaryText(STYLE_BOLD));
textView2.setText(item.getSecondaryText(STYLE_BOLD));
return row;
}
示例2: getAutocomplete
import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
private ArrayList<AutocompletePrediction> getAutocomplete(CharSequence constraint) {
if (mGoogleApiClient.isConnected()) {
PendingResult<AutocompletePredictionBuffer> results =
Places.GeoDataApi
.getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
mBounds, mPlaceFilter);
AutocompletePredictionBuffer autocompletePredictions = results
.await(60, TimeUnit.SECONDS);
final Status status = autocompletePredictions.getStatus();
if (!status.isSuccess()) {
Toast.makeText(getContext(), "Error contacting API: " + status.toString(),
Toast.LENGTH_SHORT).show();
autocompletePredictions.release();
return null;
}
return DataBufferUtils.freezeAndClose(autocompletePredictions);
}
return null;
}
示例3: getAutocompleteResults
import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
public Observable<PlacePrediction> getAutocompleteResults(final GoogleApiClient mGoogleApiClient, final String query, final LatLngBounds bounds) {
return Observable.create(new Observable.OnSubscribe<PlacePrediction>() {
@Override
public void call(Subscriber<? super PlacePrediction> subscriber) {
PendingResult<AutocompletePredictionBuffer> results =
Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient, query,
bounds, null);
AutocompletePredictionBuffer autocompletePredictions = results
.await(60, TimeUnit.SECONDS);
final Status status = autocompletePredictions.getStatus();
if (!status.isSuccess()) {
autocompletePredictions.release();
subscriber.onError(null);
} else {
for (AutocompletePrediction autocompletePrediction : autocompletePredictions) {
subscriber.onNext(
new PlacePrediction(
autocompletePrediction.getPlaceId(),
autocompletePrediction.getDescription()
));
}
autocompletePredictions.release();
subscriber.onCompleted();
}
}
});
}
示例4: getAutocomplete
import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
private ArrayList<AutocompletePrediction> getAutocomplete(CharSequence constraint) {
if (mGoogleApiClient.isConnected()) {
PendingResult<AutocompletePredictionBuffer> results =
Places.GeoDataApi.getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
mBounds, mPlaceFilter);
AutocompletePredictionBuffer autocompletePredictions = results.await(60, TimeUnit.SECONDS);
final Status status = autocompletePredictions.getStatus();
if (!status.isSuccess()) {
Toast.makeText(getContext(), "Error contacting API: " + status.toString(),
Toast.LENGTH_SHORT).show();
autocompletePredictions.release();
return null;
}
return DataBufferUtils.freezeAndClose(autocompletePredictions);
}
return null;
}
示例5: getAutocomplete
import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
private ArrayList<AutocompletePrediction> getAutocomplete(CharSequence constraint) {
if (mGoogleApiClient.isConnected()) {
PendingResult<AutocompletePredictionBuffer> results =
Places.GeoDataApi
.getAutocompletePredictions(mGoogleApiClient, constraint.toString(),
mBounds, mPlaceFilter);
AutocompletePredictionBuffer autocompletePredictions = results
.await(60, TimeUnit.SECONDS);
final Status status = autocompletePredictions.getStatus();
if (!status.isSuccess()) {
if (callback != null) callback.onSuggestFail(status);
autocompletePredictions.release();
return null;
}
return DataBufferUtils.freezeAndClose(autocompletePredictions);
}
return null;
}
示例6: getView
import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = super.getView(position, convertView, parent);
// Sets the primary and secondary text for a row.
// Note that getPrimaryText() and getSecondaryText() return a CharSequence that may contain
// styling based on the given CharacterStyle.
AutocompletePrediction item = getItem(position);
try{
TextView textView1 = (TextView) row.findViewById(android.R.id.text1);
TextView textView2 = (TextView) row.findViewById(android.R.id.text2);
textView1.setText(item.getPrimaryText(STYLE_BOLD));
textView2.setText(item.getSecondaryText(STYLE_BOLD));
} catch (Exception e){
e.printStackTrace();
}
return row;
}
示例7: onItemClick
import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
@Override
public void onItemClick (AdapterView<?> parent, View view, int position, long id) {
/*
Retrieve the place ID of the selected item from the Adapter.
The adapter stores each Place suggestion in a AutocompletePrediction from which we
read the place ID and title.
*/
final AutocompletePrediction item = mAdapter.getItem (position);
final String placeId = item.getPlaceId ();
final CharSequence primaryText = item.getPrimaryText (null);
Log.i("", "Autocomplete item selected: " + primaryText);
/*
Issue a request to the Places Geo Data API to retrieve a Place object with additional
details about the place.
*/
PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi
.getPlaceById (mGoogleApiClient, placeId);
placeResult.setResultCallback (mUpdatePlaceDetailsCallback);
Log.i("", "Called getPlaceById to get Place details for " + placeId);
mSearchLocation.setThreshold(1000);
}
示例8: onItemClick
import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
/*
Retrieve the place ID of the selected item from the Adapter.
The adapter stores each Place suggestion in a AutocompletePrediction from which we
read the place ID and title.
*/
final AutocompletePrediction item = mAdapter.getItem(position);
final String placeId = item.getPlaceId();
final CharSequence primaryText = item.getPrimaryText(null);
Log.i(TAG, "Autocomplete item selected: " + primaryText);
/*
Issue a request to the Places Geo Data API to retrieve a Place object with additional
details about the place.
*/
PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi
.getPlaceById(mGoogleApiClient, placeId);
placeResult.setResultCallback(mUpdatePlaceDetailsCallback);
Toast.makeText(getApplicationContext(), "Clicked: " + primaryText,
Toast.LENGTH_SHORT).show();
Log.i(TAG, "Called getPlaceById to get Place details for " + placeId);
}
示例9: updateToOfflineHistory
import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
private void updateToOfflineHistory() {
FileOutputStream outputStream;
try {
// delete file content
PrintWriter writer = new PrintWriter(historyFile);
writer.print("");
writer.close();
outputStream = appContext.openFileOutput(historyFileName, Context.MODE_APPEND); //todo MODE_PRIVATE ?
for (AutocompletePrediction prediction : onlineHistory){
outputStream.write(prediction.getPlaceId().concat("\n").getBytes());
}
outputStream.close();
} catch (Exception e) {
e.printStackTrace();
}
}
示例10: showOnlyFixedResults
import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
private void showOnlyFixedResults() {
PlaceAutocompleteAdapter currAdapter = (PlaceAutocompleteAdapter) currView.getAdapter();
ArrayList<AutocompletePrediction> fixedResults = new ArrayList();
fixedResults.addAll(currAdapter.getFixedResults());
if (searchHistoryCollector != null && !searchHistoryCollector.getOnlineHistory().isEmpty()){
fixedResults.addAll(searchHistoryCollector.getOnlineHistory());
}
currAdapter.setResultsList(fixedResults);
currView.getHandler().postDelayed(new Runnable() {
@Override
public void run() {
currView.showDropDown();
}
}, 500);
}
示例11: onItemClick
import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
/*
Retrieve the place ID of the selected item from the Adapter.
The adapter stores each Place suggestion in a AutocompletePrediction from which we
read the place ID and title.
*/
final AutocompletePrediction item = mAdapter.getItem(position);
final String placeId = item.getPlaceId();
final CharSequence primaryText = item.getPrimaryText(null);
Log.i(TAG, "Autocomplete item selected: " + primaryText);
/*
Issue a request to the Places Geo Data Client to retrieve a Place object with
additional details about the place.
*/
Task<PlaceBufferResponse> placeResult = mGeoDataClient.getPlaceById(placeId);
placeResult.addOnCompleteListener(mUpdatePlaceDetailsCallback);
Toast.makeText(getApplicationContext(), "Clicked: " + primaryText,
Toast.LENGTH_SHORT).show();
Log.i(TAG, "Called getPlaceById to get Place details for " + placeId);
}
示例12: performQuery
import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
void performQuery(final String query) {
Timber.d("performQuery: %s", query);
placeEngine.queryAutocompletion(query)
.subscribe(new Subscriber<Iterable<AutocompletePrediction>>() {
@Override
public void onCompleted() {
}
@Override
public void onError(Throwable e) {
Timber.w(e, "failed to queryAutocompletion queryAutocompletion for: %s", query);
}
@Override
public void onNext(Iterable<AutocompletePrediction> predictions) {
clear();
addAll(convertToSpannedList(predictions));
}
});
}
示例13: onItemClick
import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
AnalyticsManager.getInstance().trackSearch();
final AutocompletePrediction item = mAdapter.getItem(position);
final String placeId = item.getPlaceId();
final CharSequence primaryText = item.getPrimaryText(null);
PendingResult<PlaceBuffer> placeResult = Places.GeoDataApi
.getPlaceById(mGoogleApiClient, placeId);
placeResult.setResultCallback(mUpdatePlaceDetailsCallback);
}
示例14: onItemClick
import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
@Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
UIUtils.hideKeyboard(AutoCompleteLocation.this.getContext(), AutoCompleteLocation.this);
final AutocompletePrediction item = mAutoCompleteAdapter.getItem(position);
if (item != null) {
final String placeId = item.getPlaceId();
PendingResult<PlaceBuffer> placeResult =
Places.GeoDataApi.getPlaceById(mGoogleApiClient, placeId);
placeResult.setResultCallback(mUpdatePlaceDetailsCallback);
}
}
示例15: getView
import com.google.android.gms.location.places.AutocompletePrediction; //导入依赖的package包/类
@Override public View getView(int position, View convertView, ViewGroup parent) {
View row = super.getView(position, convertView, parent);
AutocompletePrediction item = getItem(position);
TextView textView1 = (TextView) row.findViewById(android.R.id.text1);
TextView textView2 = (TextView) row.findViewById(android.R.id.text2);
textView1.setText(item.getPrimaryText(STYLE_BOLD));
textView2.setText(item.getSecondaryText(STYLE_BOLD));
return row;
}