Android Open Source - droidcon Venue Search Activity From Project Back to project page droidcon .
License The source code is released under:
Apache License
If you think the Android project droidcon listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code package com.timehop.droidcon2014retrofitsample;
/ * w w w . j a v a 2 s . c o m * /
import android.app.Activity;
import android.app.AlertDialog;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.util.Log;
import android.widget.ListView;
import com.timehop.droidcon2014retrofitsample.data.foursquare.FoursquareService;
import com.timehop.droidcon2014retrofitsample.data.foursquare.api.FoursquareException;
import com.timehop.droidcon2014retrofitsample.data.foursquare.api.FoursquareResponse;
import com.timehop.droidcon2014retrofitsample.data.foursquare.model.Venue;
import com.timehop.droidcon2014retrofitsample.ui.VenueAdapter;
import java.util.List;
import retrofit.Callback;
import retrofit.RetrofitError;
import retrofit.client.Response;
public class VenueSearchActivity extends Activity {
public static final String TAG = VenueSearchActivity.class.getSimpleName();
public static final String EXTRA_LOCATION = "location" ;
private ListView mListView;
private VenueAdapter mAdapter;
private ProgressDialog mProgressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
String location = getIntent().getStringExtra(EXTRA_LOCATION);
setContentView(R.layout.activity_venue_search);
mListView = (ListView) findViewById(android.R.id.list);
mAdapter = new VenueAdapter(this );
mListView.setAdapter(mAdapter);
mProgressDialog = new ProgressDialog(this );
mProgressDialog.setMessage("Loading venues..." );
mProgressDialog.setCancelable(false);
mProgressDialog.show();
FoursquareService.Implementation.get().searchVenues(location,
new Callback<FoursquareResponse>() {
@Override
public void success(FoursquareResponse foursquareResponse, Response response) {
if (isDestroyed()) return ;
mProgressDialog.dismiss();
List<Venue> venues = foursquareResponse.getResponse().getVenues();
onVenuesReceived(venues);
}
@Override
public void failure(RetrofitError error) {
if (isDestroyed()) return ;
Log.e(TAG, "Failed to load venues" , error);
mProgressDialog.dismiss();
String message = "Loading failed :(" ;
try {
throw (error.getCause());
} catch (FoursquareException e) {
Log.e(TAG, "Venue request failed" , e);
// save the error message to display in a dialog
message = e.getMessage();
} catch (Throwable e) {
Log.e(TAG, "Venue request failed" , e);
}
new AlertDialog.Builder(VenueSearchActivity.this)
.setMessage(message)
.setCancelable(false)
.setNeutralButton("OK" , new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
})
.show();
}
});
}
@Override
protected void onDestroy() {
super.onDestroy();
mProgressDialog.dismiss();
}
private void onVenuesReceived(List<Venue> venues) {
for (Venue venue : venues) {
mAdapter.add(venue);
}
}
}
Java Source Code List com.timehop.droidcon2014retrofitsample.CommentsActivity.java com.timehop.droidcon2014retrofitsample.MainActivity.java com.timehop.droidcon2014retrofitsample.SubredditActivity.java com.timehop.droidcon2014retrofitsample.VenueSearchActivity.java com.timehop.droidcon2014retrofitsample.data.SynchronousExecutor.java com.timehop.droidcon2014retrofitsample.data.foursquare.FoursquareService.java com.timehop.droidcon2014retrofitsample.data.foursquare.FoursquareTests.java com.timehop.droidcon2014retrofitsample.data.foursquare.api.FoursquareCredentials.java com.timehop.droidcon2014retrofitsample.data.foursquare.api.FoursquareErrorHandler.java com.timehop.droidcon2014retrofitsample.data.foursquare.api.FoursquareException.java com.timehop.droidcon2014retrofitsample.data.foursquare.api.FoursquareRequestInterceptor.java com.timehop.droidcon2014retrofitsample.data.foursquare.api.FoursquareResponse.java com.timehop.droidcon2014retrofitsample.data.foursquare.legacy.VenueSearchTask.java com.timehop.droidcon2014retrofitsample.data.foursquare.model.Category.java com.timehop.droidcon2014retrofitsample.data.foursquare.model.Contact.java com.timehop.droidcon2014retrofitsample.data.foursquare.model.Icon.java com.timehop.droidcon2014retrofitsample.data.foursquare.model.Location.java com.timehop.droidcon2014retrofitsample.data.foursquare.model.Menu.java com.timehop.droidcon2014retrofitsample.data.foursquare.model.Meta.java com.timehop.droidcon2014retrofitsample.data.foursquare.model.Price.java com.timehop.droidcon2014retrofitsample.data.foursquare.model.ResponseWrapper.java com.timehop.droidcon2014retrofitsample.data.foursquare.model.Stats.java com.timehop.droidcon2014retrofitsample.data.foursquare.model.Venue.java com.timehop.droidcon2014retrofitsample.data.reddit.DateTimeDeserializer.java com.timehop.droidcon2014retrofitsample.data.reddit.MockRedditService.java com.timehop.droidcon2014retrofitsample.data.reddit.RedditObjectDeserializer.java com.timehop.droidcon2014retrofitsample.data.reddit.RedditService.java com.timehop.droidcon2014retrofitsample.data.reddit.RedditTests.java com.timehop.droidcon2014retrofitsample.data.reddit.RedditType.java com.timehop.droidcon2014retrofitsample.data.reddit.model.MockModelHelper.java com.timehop.droidcon2014retrofitsample.data.reddit.model.RedditAccount.java com.timehop.droidcon2014retrofitsample.data.reddit.model.RedditComment.java com.timehop.droidcon2014retrofitsample.data.reddit.model.RedditLink.java com.timehop.droidcon2014retrofitsample.data.reddit.model.RedditListing.java com.timehop.droidcon2014retrofitsample.data.reddit.model.RedditMore.java com.timehop.droidcon2014retrofitsample.data.reddit.model.RedditObjectWrapper.java com.timehop.droidcon2014retrofitsample.data.reddit.model.RedditObject.java com.timehop.droidcon2014retrofitsample.data.reddit.model.RedditResponse.java com.timehop.droidcon2014retrofitsample.data.reddit.model.RedditSubmission.java com.timehop.droidcon2014retrofitsample.ui.CommentsAdapter.java com.timehop.droidcon2014retrofitsample.ui.LinkAdapter.java com.timehop.droidcon2014retrofitsample.ui.VenueAdapter.java