Revision: ab0a0be7b5
Author: mar...@gmail.com
Date: Mon Oct 11 11:30:21 2010
Log: Added a textview which shows how many characters are left for adding
a...
http://code.google.com/r/markww-foursquared/source/detail?r=ab0a0be7b5
Revision: 8b406ced96
Author: mar...@gmail.com
Date: Mon Oct 11 11:31:54 2010
Log: Updated changelog for characters-left widgets.
http://code.google.com/r/markww-foursquared/source/detail?r=8b406ced96
Revision: 0a4ac5d1cd
Author: mar...@gmail.com
Date: Thu Oct 14 00:13:03 2010
Log: Trying to get image downloads and cache under better control. Right
no...
http://code.google.com/r/markww-foursquared/source/detail?r=0a4ac5d1cd
==============================================================================
Revision: ab0a0be7b5
Author: mar...@gmail.com
Date: Mon Oct 11 11:30:21 2010
Log: Added a textview which shows how many characters are left for adding a
tip/todo.
http://code.google.com/r/markww-foursquared/source/detail?r=ab0a0be7b5
Added:
/main/src/com/joelapenna/foursquared/widget/CharactersLeft.java
Modified:
/main/res/layout/add_tip_activity.xml
/main/res/layout/add_todo_activity.xml
/main/res/values/strings.xml
/main/src/com/joelapenna/foursquared/AddTipActivity.java
/main/src/com/joelapenna/foursquared/AddTodoActivity.java
/main/src/com/joelapenna/foursquared/widget/PhotoStrip.java
=======================================
--- /dev/null
+++ /main/src/com/joelapenna/foursquared/widget/CharactersLeft.java Mon Oct
11 11:30:21 2010
@@ -0,0 +1,54 @@
+/**
+ * Copyright 2010 Mark Wyszomierski
+ */
+package com.joelapenna.foursquared.widget;
+
+import android.content.res.Resources;
+import android.text.Editable;
+import android.text.TextWatcher;
+import android.widget.EditText;
+import android.widget.TextView;
+
+/**
+ * Takes an EditText and a TextView, and as the user types in the
EditText, updates
+ * the TextView with the number of characters left until maxLength is
reached.
+ *
+ * Unfortunately we can't find out the max length from the EditText
itself, or from
+ * a possible InputFilter.LengthFilter applied to it. We take the
maxLength value
+ * from the user and trust that's really the max that was set.
+ *
+ * @date October 11, 2010
+ * @author Mark Wyszomierski (mar...@gmail.com)
+ */
+public class CharactersLeft {
+
+ /**
+ * @param resources From context.getResources().
+ * @param source The EditText to bind to.
+ * @param target The TextView to update whenever the user types in the
EditText.
+ * @param sentence The string resource ID to use for the TextView,
should have two %d
+ * in it, the first for # characters typed, the second
for the max length.
+ * @param maxLength The max number of characters the EditText will
accept.
+ */
+ public static void bind(final Resources resources,
+ final EditText source,
+ final TextView target,
+ final int sentence,
+ final int maxLength) {
+ source.addTextChangedListener(new TextWatcher() {
+ @Override
+ public void afterTextChanged(Editable s) {
+ }
+
+ @Override
+ public void beforeTextChanged(CharSequence s, int start, int
count, int after) {
+ }
+
+ @Override
+ public void onTextChanged(CharSequence s, int start, int
before, int count) {
+ target.setText(resources.getString(sentence, s.length(),
maxLength));
+ }
+ });
+ target.setText(resources.getString(sentence, 0, maxLength));
+ }
+}
=======================================
--- /main/res/layout/add_tip_activity.xml Thu Sep 16 15:38:32 2010
+++ /main/res/layout/add_tip_activity.xml Mon Oct 11 11:30:21 2010
@@ -27,7 +27,16 @@
android:layout_height="wrap_content"
android:textAppearance="@style/TextViewStyleAddTipTodoActivityNormal"
android:text="Venue Address"
- android:layout_marginBottom="14dip" />
+ android:layout_marginBottom="2dip" />
+
+ <TextView
+ android:id="@+id/addTipActivityCharactersLeft"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="@style/TextViewStyleAddTipTodoActivityNormal"
+ android:text="N / N"
+ android:layout_marginRight="4dip"
+ android:gravity="right" />
<EditText
android:id="@+id/addTipActivityText"
=======================================
--- /main/res/layout/add_todo_activity.xml Wed Sep 22 11:57:13 2010
+++ /main/res/layout/add_todo_activity.xml Mon Oct 11 11:30:21 2010
@@ -27,7 +27,16 @@
android:layout_height="wrap_content"
android:textAppearance="@style/TextViewStyleAddTipTodoActivityNormal"
android:text="Venue Address"
- android:layout_marginBottom="14dip" />
+ android:layout_marginBottom="2dip" />
+
+ <TextView
+ android:id="@+id/addTodoActivityCharactersLeft"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:textAppearance="@style/TextViewStyleAddTipTodoActivityNormal"
+ android:text="N / N"
+ android:layout_marginRight="4dip"
+ android:gravity="right" />
<EditText
android:id="@+id/addTodoActivityText"
=======================================
--- /main/res/values/strings.xml Wed Oct 6 09:06:43 2010
+++ /main/res/values/strings.xml Mon Oct 11 11:30:21 2010
@@ -412,4 +412,5 @@
<string name="no_todos">There are no To-Do items here</string>
<string name="venue_map_activity_title">Foursquare - %s</string>
<string name="venue_checkins_activity_title">Foursquare Checkins
- %s</string>
+ <string name="characters_left">%d / %d</string>
</resources>
=======================================
--- /main/src/com/joelapenna/foursquared/AddTipActivity.java Wed Sep 22
11:57:13 2010
+++ /main/src/com/joelapenna/foursquared/AddTipActivity.java Mon Oct 11
11:30:21 2010
@@ -4,6 +4,13 @@
package com.joelapenna.foursquared;
+import com.joelapenna.foursquare.types.Tip;
+import com.joelapenna.foursquare.types.Venue;
+import com.joelapenna.foursquared.location.LocationUtils;
+import com.joelapenna.foursquared.util.NotificationsUtil;
+import com.joelapenna.foursquared.util.StringFormatters;
+import com.joelapenna.foursquared.widget.CharactersLeft;
+
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
@@ -20,12 +27,6 @@
import android.widget.TextView;
import android.widget.Toast;
-import com.joelapenna.foursquare.types.Tip;
-import com.joelapenna.foursquare.types.Venue;
-import com.joelapenna.foursquared.location.LocationUtils;
-import com.joelapenna.foursquared.util.NotificationsUtil;
-import com.joelapenna.foursquared.util.StringFormatters;
-
/**
* Lets the user add a tip to a venue.
*
@@ -83,11 +84,15 @@
tvVenueAddress.setText(StringFormatters.getVenueLocationCrossStreetOrCity(
mStateHolder.getVenue()));
+ TextView tvCharactersLeft =
(TextView)findViewById(R.id.addTipActivityCharactersLeft);
+
+ final EditText et = (EditText)findViewById(R.id.addTipActivityText);
+ CharactersLeft.bind(getResources(), et, tvCharactersLeft,
R.string.characters_left, 200);
+
Button btn = (Button) findViewById(R.id.addTipActivityButton);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
- EditText et = (EditText)findViewById(R.id.addTipActivityText);
String text = et.getText().toString();
if (!TextUtils.isEmpty(text)) {
mStateHolder.startTaskAddTip(AddTipActivity.this,
mStateHolder.getVenue().getId(), text);
=======================================
--- /main/src/com/joelapenna/foursquared/AddTodoActivity.java Wed Sep 22
11:57:13 2010
+++ /main/src/com/joelapenna/foursquared/AddTodoActivity.java Mon Oct 11
11:30:21 2010
@@ -25,6 +25,7 @@
import com.joelapenna.foursquared.location.LocationUtils;
import com.joelapenna.foursquared.util.NotificationsUtil;
import com.joelapenna.foursquared.util.StringFormatters;
+import com.joelapenna.foursquared.widget.CharactersLeft;
/**
* Lets the user add a todo for a venue.
@@ -83,11 +84,15 @@
tvVenueAddress.setText(StringFormatters.getVenueLocationCrossStreetOrCity(
mStateHolder.getVenue()));
+ TextView tvCharactersLeft =
(TextView)findViewById(R.id.addTodoActivityCharactersLeft);
+
+ final EditText et = (EditText)findViewById(R.id.addTodoActivityText);
+ CharactersLeft.bind(getResources(), et, tvCharactersLeft,
R.string.characters_left, 200);
+
Button btn = (Button) findViewById(R.id.addTodoActivityButton);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
- EditText et =
(EditText)findViewById(R.id.addTodoActivityText);
String text = et.getText().toString();
mStateHolder.startTaskAddTodo(AddTodoActivity.this,
mStateHolder.getVenue().getId(), text);
}
=======================================
--- /main/src/com/joelapenna/foursquared/widget/PhotoStrip.java Thu Sep 30
11:43:33 2010
+++ /main/src/com/joelapenna/foursquared/widget/PhotoStrip.java Mon Oct 11
11:30:21 2010
@@ -1,3 +1,6 @@
+/**
+ * Copyright 2010 Mark Wyszomierski
+ */
package com.joelapenna.foursquared.widget;
import com.joelapenna.foursquare.types.Checkin;
==============================================================================
Revision: 8b406ced96
Author: mar...@gmail.com
Date: Mon Oct 11 11:31:54 2010
Log: Updated changelog for characters-left widgets.
http://code.google.com/r/markww-foursquared/source/detail?r=8b406ced96
Modified:
/main/assets/changelog-en.html
=======================================
--- /main/assets/changelog-en.html Mon Oct 11 08:52:11 2010
+++ /main/assets/changelog-en.html Mon Oct 11 11:31:54 2010
@@ -40,6 +40,7 @@
<h4><span>What's new in v2010-10-11?</span></h4>
<ul>
+ <li>Added characters-left widget on add-tip/add-to-do
activities.</li>
<li>Hiding Twitter/Facebook checkboxes in checkin dialog if the user
has not linked their
Foursquare account with Twitter/Facebook through the Foursquare
website settings page.</li>
<li>Updated login screen.</li>
==============================================================================
Revision: 0a4ac5d1cd
Author: mar...@gmail.com
Date: Thu Oct 14 00:13:03 2010
Log: Trying to get image downloads and cache under better control. Right
now long lists of thumbnails grind the app to a halt in most cases.
Condensed the http api classes into a single class, HttpImpl, in
preparation for new OAuth2 implementation. This will be a much simpler task
than trying to support basic auth + Oauth1. Support will be done
simultaneously as we'll need to still use some v1 api methods.
http://code.google.com/r/markww-foursquared/source/detail?r=0a4ac5d1cd
Added:
/main/src/com/joelapenna/foursquare/http/HttpImpl.java
/main/src/com/joelapenna/foursquared/util/NewImageFetcher.java
Modified:
/main/.classpath
/main/AndroidManifest.xml
/main/assets/changelog-en.html
/main/src/com/joelapenna/foursquare/Foursquare.java
/main/src/com/joelapenna/foursquare/FoursquareHttpApiV1.java
/main/src/com/joelapenna/foursquare/http/AbstractHttpApi.java
/main/src/com/joelapenna/foursquare/http/HttpApi.java
/main/src/com/joelapenna/foursquared/Foursquared.java
/main/src/com/joelapenna/foursquared/FriendsActivity.java
/main/src/com/joelapenna/foursquared/NearbyVenuesActivity.java
/main/src/com/joelapenna/foursquared/SearchVenuesActivity.java
/main/src/com/joelapenna/foursquared/TipsActivity.java
/main/src/com/joelapenna/foursquared/TodosActivity.java
/main/src/com/joelapenna/foursquared/UserDetailsActivity.java
/main/src/com/joelapenna/foursquared/UserDetailsTipsActivity.java
/main/src/com/joelapenna/foursquared/VenueActivity.java
/main/src/com/joelapenna/foursquared/VenueTipsActivity.java
/main/src/com/joelapenna/foursquared/VenueTodosActivity.java
/main/src/com/joelapenna/foursquared/preferences/Preferences.java
/main/src/com/joelapenna/foursquared/providers/GlobalSearchProvider.java
/main/src/com/joelapenna/foursquared/util/BaseDiskCache.java
/main/src/com/joelapenna/foursquared/util/RemoteResourceFetcher.java
/main/src/com/joelapenna/foursquared/util/RemoteResourceManager.java
/main/src/com/joelapenna/foursquared/widget/BaseGroupAdapter.java
/main/src/com/joelapenna/foursquared/widget/CheckinListAdapter.java
/main/src/com/joelapenna/foursquared/widget/FriendActionableListAdapter.java
/main/src/com/joelapenna/foursquared/widget/FriendListAdapter.java
/main/src/com/joelapenna/foursquared/widget/FriendRequestsAdapter.java
/main/src/com/joelapenna/foursquared/widget/FriendSearchAddFriendAdapter.java
/main/src/com/joelapenna/foursquared/widget/FriendSearchInviteNonFoursquareUserAdapter.java
/main/src/com/joelapenna/foursquared/widget/PhotoStrip.java
/main/src/com/joelapenna/foursquared/widget/SeparatedListAdapter.java
/main/src/com/joelapenna/foursquared/widget/TipsListAdapter.java
/main/src/com/joelapenna/foursquared/widget/TodosListAdapter.java
=======================================
--- /dev/null
+++ /main/src/com/joelapenna/foursquare/http/HttpImpl.java Thu Oct 14
00:13:03 2010
@@ -0,0 +1,226 @@
+/**
+ * Copyright 2010 Mark Wyszomierski
+ */
+package com.joelapenna.foursquare.http;
+
+import com.joelapenna.foursquare.Foursquare;
+import com.joelapenna.foursquare.parsers.json.Parser;
+import com.joelapenna.foursquare.types.FoursquareType;
+import com.joelapenna.foursquare.util.JSONUtils;
+
+import org.apache.http.HttpException;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
+import org.apache.http.HttpResponse;
+import org.apache.http.NameValuePair;
+import org.apache.http.auth.AuthScope;
+import org.apache.http.auth.AuthState;
+import org.apache.http.auth.UsernamePasswordCredentials;
+import org.apache.http.client.CredentialsProvider;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
+import org.apache.http.client.methods.HttpGet;
+import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpUriRequest;
+import org.apache.http.client.params.HttpClientParams;
+import org.apache.http.client.protocol.ClientContext;
+import org.apache.http.client.utils.URLEncodedUtils;
+import org.apache.http.conn.ClientConnectionManager;
+import org.apache.http.conn.scheme.PlainSocketFactory;
+import org.apache.http.conn.scheme.Scheme;
+import org.apache.http.conn.scheme.SchemeRegistry;
+import org.apache.http.conn.scheme.SocketFactory;
+import org.apache.http.conn.ssl.SSLSocketFactory;
+import org.apache.http.impl.auth.BasicScheme;
+import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.impl.conn.SingleClientConnManager;
+import org.apache.http.params.BasicHttpParams;
+import org.apache.http.params.HttpConnectionParams;
+import org.apache.http.params.HttpParams;
+import org.apache.http.protocol.ExecutionContext;
+import org.apache.http.protocol.HTTP;
+import org.apache.http.protocol.HttpContext;
+import org.apache.http.util.EntityUtils;
+
+import android.util.Log;
+
+import java.io.IOException;
+import java.net.HttpURLConnection;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.logging.Logger;
+
+
+/**
+ * @date October 13, 2010
+ * @author Mark Wyszomierski (mar...@gmail.com)
+ */
+public class HttpImpl {
+ protected static final Logger LOG =
Logger.getLogger(AbstractHttpApi.class.getCanonicalName());
+ protected static final boolean DEBUG = Foursquare.DEBUG;
+
+ private static final String DEFAULT_CLIENT_VERSION
= "com.joelapenna.foursquare";
+ private static final String CLIENT_VERSION_HEADER = "User-Agent";
+ private static final int TIMEOUT = 60;
+
+ private static final int TYPE_GET = 0;
+ private static final int TYPE_POST = 1;
+
+ private final String mClientVersion;
+ private String mUsername;
+ private String mPassword;
+ //private String mToken;
+
+ public HttpImpl(String clientVersion) {
+ if (clientVersion != null) {
+ mClientVersion = clientVersion;
+ } else {
+ mClientVersion = DEFAULT_CLIENT_VERSION;
+ }
+ }
+
+ public boolean getHasCredentials() {
+ return mUsername != null && mPassword != null &&
+ mUsername.length() > 0 && mPassword.length() > 0;
+ }
+
+ public void setCredentials(String username, String password) {
+ // TODO: this should be made thread-safe.
+ mUsername = username;
+ mPassword = password;
+ }
+
+ public FoursquareType httpGet(
+ String url,
+ Parser<? extends FoursquareType> parser,
+ NameValuePair... nameValuePairs) throws Exception {
+ return executeWithRetries(url, TYPE_GET, parser, nameValuePairs);
+ }
+
+ public FoursquareType httpPost(
+ String url,
+ Parser<? extends FoursquareType> parser,
+ NameValuePair... nameValuePairs) throws Exception {
+ return executeWithRetries(url, TYPE_POST, parser, nameValuePairs);
+ }
+
+ private FoursquareType executeWithRetries(String url,
+ int method,
+ Parser<? extends
FoursquareType> parser,
+ NameValuePair...
nameValuePairs) throws Exception{
+ Log.v("^^^", "Ok, doing request...");
+
+ Exception last = null;
+ for (int i = 0; i < 3; i++) {
+ try {
+ String response = buildClient(createGetOrPost(method, url,
nameValuePairs));
+ return JSONUtils.consume(parser, response);
+ } catch (Exception ex) {
+ Log.v("^^^", " Failed http connection attempt(" + i
+ ")");
+ ex = last;
+ }
+ }
+
+ throw last;
+ }
+
+ private HttpUriRequest createGetOrPost(int method, String url,
NameValuePair ... nameValuePairs)
+ throws Exception {
+
+ HttpUriRequest request = null;
+ switch (method) {
+ case TYPE_GET:
+ String query =
URLEncodedUtils.format(stripNulls(nameValuePairs), HTTP.UTF_8);
+ request = new HttpGet(url + "?" + query);
+ break;
+ case TYPE_POST:
+ HttpPost post = new HttpPost(url);
+ post.setEntity(new
UrlEncodedFormEntity(stripNulls(nameValuePairs), HTTP.UTF_8));
+ request = post;
+ break;
+ default:
+ throw new IllegalStateException("Unknown http method
supplied.");
+ }
+
+ // TODO: Inject OAuth2 token here.
+ request.addHeader(CLIENT_VERSION_HEADER, mClientVersion);
+ return request;
+ }
+
+ private static List<NameValuePair> stripNulls(NameValuePair...
nameValuePairs) {
+ List<NameValuePair> params = new ArrayList<NameValuePair>();
+ for (int i = 0; i < nameValuePairs.length; i++) {
+ NameValuePair param = nameValuePairs[i];
+ if (param.getValue() != null) {
+ params.add(param);
+ }
+ }
+ return params;
+ }
+
+ /** We'll dump this later, it's only used by user/update right now. */
+ public HttpURLConnection createHttpURLConnectionPost(URL url, String
boundary)
+ throws IOException {
+ HttpURLConnection conn = (HttpURLConnection) url.openConnection();
+ conn.setDoInput(true);
+ conn.setDoOutput(true);
+ conn.setUseCaches(false);
+ conn.setConnectTimeout(TIMEOUT * 1000);
+ conn.setRequestMethod("POST");
+
+ conn.setRequestProperty(CLIENT_VERSION_HEADER, mClientVersion);
+ conn.setRequestProperty("Connection", "Keep-Alive");
+
conn.setRequestProperty("Content-Type", "multipart/form-data;boundary=" +
boundary);
+
+ return conn;
+ }
+
+ private String buildClient(HttpUriRequest request) throws Exception {
+
+ SchemeRegistry supportedSchemes = new SchemeRegistry();
+ SocketFactory sf = PlainSocketFactory.getSocketFactory();
+ supportedSchemes.register(new Scheme("http", sf, 80));
+ supportedSchemes.register(new Scheme("https",
SSLSocketFactory.getSocketFactory(), 443));
+
+ HttpParams params = new BasicHttpParams();
+ HttpClientParams.setRedirecting(params, false);
+ HttpConnectionParams.setConnectionTimeout(params, 10000);
+ HttpConnectionParams.setSoTimeout(params, 10000);
+
+ ClientConnectionManager conman = new
SingleClientConnManager(params, supportedSchemes);
+ DefaultHttpClient client = new DefaultHttpClient(conman, params);
+
+ HttpRequestInterceptor preemptiveAuth = new
HttpRequestInterceptor() {
+ public void process(final HttpRequest request, final
HttpContext context) throws HttpException, IOException {
+ AuthState authState = (AuthState)
context.getAttribute(ClientContext.TARGET_AUTH_STATE);
+ CredentialsProvider credsProvider = (CredentialsProvider)
context.getAttribute(
+ ClientContext.CREDS_PROVIDER);
+ HttpHost targetHost = (HttpHost)
context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
+
+ if (authState.getAuthScheme() == null) {
+ AuthScope authScope = new
AuthScope(targetHost.getHostName(), targetHost.getPort());
+ org.apache.http.auth.Credentials creds =
credsProvider.getCredentials(authScope);
+ if (creds != null) {
+ authState.setAuthScheme(new BasicScheme());
+ authState.setCredentials(creds);
+ }
+ }
+ }
+ };
+ client.addRequestInterceptor(preemptiveAuth, 0);
+ client.getCredentialsProvider().setCredentials(
+ new AuthScope("api.foursquare.com", 80),
+ new UsernamePasswordCredentials(mUsername, mPassword));
+
+ HttpResponse response = client.execute(request);
+ if (response != null) {
+ int statusCode = response.getStatusLine().getStatusCode();
+ Log.v("^^^", " It worked with code: " + statusCode);
+ return EntityUtils.toString(response.getEntity());
+ } else {
+ Log.v("^^^", " nope..");
+ throw new Exception("HttpResponse was null!");
+ }
+ }
+}
=======================================
--- /dev/null
+++ /main/src/com/joelapenna/foursquared/util/NewImageFetcher.java Thu Oct
14 00:13:03 2010
@@ -0,0 +1,161 @@
+/**
+ * Copyright 2010 Mark Wyszomierski
+ */
+package com.joelapenna.foursquared.util;
+
+import android.net.Uri;
+import android.os.Handler;
+import android.os.Handler.Callback;
+import android.os.Message;
+import android.os.Process;
+import android.util.Log;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Observable;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+
+/**
+ * Acts as a per-activity image download manager. This is for testing only.
+ * The global resource fetcher's requests live between activities. In most
+ * cases we want to stop all requests as soon as an activity is completed.
+ *
+ * Create an instance of this fetcher as part of an activity's state
holder.
+ * Add request urls to it as usual. When the activity is finishing, just
+ * call shutdown();
+ *
+ * We are limited to a single download thread, and we set its process
+ * priority to the lowest possible. Therefore image downloads won't
+ * consume much cpu while the user is interacting with the UI (which will
+ * mostly end up being the user scrolling lists).
+ *
+ * @date October 12, 2010
+ * @author Mark Wyszomierski (mar...@gmail.com)
+ */
+public class NewImageFetcher extends Observable {
+
+ private static final String TAG = "NewImageFetcher";
+ private static final int MSG = 500;
+
+ private Set<String> mRequests;
+ private AtomicBoolean mRun;
+ private WorkerThread mThread;
+ private DiskCache mDiskCache;
+
+
+
+
+ public NewImageFetcher(String cacheName) {
+ this(new BaseDiskCache("foursquare", cacheName));
+ }
+
+ public NewImageFetcher(DiskCache cache) {
+ mDiskCache = cache;
+ mRequests = new LinkedHashSet<String>();
+ mRun = new AtomicBoolean(true);
+ mThread = new WorkerThread();
+ }
+
+ public void addRequest(String url) {
+ synchronized (mRequests) {
+ if (!mRequests.contains(url)) {
+ mRequests.add(url);
+ }
+ }
+ mThread.notify();
+ }
+
+ public void shutdown() {
+ mRun.set(false);
+ mThread.notify();
+ mHandler.removeMessages(MSG);
+ }
+
+ /**
+ * Probably makes sense to call this whenever an activity is
finishing, we probably
+ * don't care about any of those requests, even if some may be useful
in the next
+ * activity to be shown.
+ */
+ public void clearRequests() {
+ synchronized (mRequests) {
+ mRequests.clear();
+ }
+ }
+
+ private class WorkerThread extends Thread {
+ public WorkerThread() {
+ Log.e(TAG, "Worker thread started.");
+ }
+
+ @Override
+ public void run() {
+ Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);
+
+ while (mRun.get()) {
+ List<String> requests = new ArrayList<String>();
+ synchronized (mRequests) {
+ if (mRequests.size() > 0) {
+ // Copy over values, get out of guard.
+ for (String it : mRequests) {
+ requests.add(it);
+ }
+ } else {
+ try {
+ mRequests.wait();
+ } catch (InterruptedException ex) {
+ }
+ }
+ }
+
+ // Service any requests we had.
+ for (String it : requests) {
+ //uri, Uri.encode(uri.toString());
+
+ // Store is being down in a background thread.
+ mDiskCache.store(Uri.encode(it), downloadImage(it));
+ mHandler.sendMessage(mHandler.obtainMessage(MSG, it));
+ }
+ }
+ }
+ };
+
+ private InputStream downloadImage(String url) {
+ try {
+ URLConnection conn = new URL(url).openConnection();
+ conn.setConnectTimeout(7 * 1000);
+ conn.setReadTimeout(7 * 1000);
+ conn.connect();
+ return conn.getInputStream();
+ } catch (Exception ex) {
+ Log.e(TAG, "Error getting bitmap at url [" + url + "].", ex);
+ }
+
+ return null;
+ }
+
+ private Handler mHandler = new Handler(new Callback() {
+ @Override
+ public boolean handleMessage(Message msg) {
+ notifyObservers(msg.obj);
+ /*
+ if (mListView != null) {
+ ListAdapter adapter = mListView.getAdapter();
+ if (adapter instanceof RemoteResourcesListAdapter) {
+ String url = (String)msg.obj;
+ for (int i = 0, m = mListView.getChildCount(); i < m;
i++) {
+ View view = mListView.getChildAt(i);
+
((RemoteResourcesListAdapter)adapter).onResourcesDownloaded(view, url);
+ }
+ }
+ }
+ */
+ return false;
+ }
+ });
+}
=======================================
--- /main/.classpath Thu Jun 17 14:16:29 2010
+++ /main/.classpath Thu Oct 14 00:13:03 2010
@@ -3,8 +3,6 @@
<classpathentry kind="src" path="src"/>
<classpathentry kind="con"
path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="src" path="gen"/>
- <classpathentry kind="lib" path="lib/signpost-commonshttp.jar"/>
- <classpathentry kind="lib" path="lib/signpost-core.jar"/>
<classpathentry kind="lib" path="lib/dumpcatcher.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
=======================================
--- /main/AndroidManifest.xml Mon Oct 11 08:20:45 2010
+++ /main/AndroidManifest.xml Thu Oct 14 00:13:03 2010
@@ -4,7 +4,7 @@
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.joelapenna.foursquared"
android:installLocation="auto"
- android:versionName="2010-10-11" android:versionCode="2010101100" >
+ android:versionName="2010-10-13" android:versionCode="2010101300" >
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION" />
=======================================
--- /main/assets/changelog-en.html Mon Oct 11 11:31:54 2010
+++ /main/assets/changelog-en.html Thu Oct 14 00:13:03 2010
@@ -38,8 +38,10 @@
<body>
- <h4><span>What's new in v2010-10-11?</span></h4>
+ <h4><span>What's new in v2010-10-13?</span></h4>
<ul>
+ <li>Long lists with thumbnails (like user details pages) should be
more responsive
+ while loading.</li>
<li>Added characters-left widget on add-tip/add-to-do
activities.</li>
<li>Hiding Twitter/Facebook checkboxes in checkin dialog if the user
has not linked their
Foursquare account with Twitter/Facebook through the Foursquare
website settings page.</li>
=======================================
--- /main/src/com/joelapenna/foursquare/Foursquare.java Thu Sep 30 12:01:25
2010
+++ /main/src/com/joelapenna/foursquare/Foursquare.java Thu Oct 14 00:13:03
2010
@@ -11,7 +11,6 @@
import com.joelapenna.foursquare.types.Category;
import com.joelapenna.foursquare.types.Checkin;
import com.joelapenna.foursquare.types.CheckinResult;
-import com.joelapenna.foursquare.types.Credentials;
import com.joelapenna.foursquare.types.FriendInvitesResult;
import com.joelapenna.foursquare.types.Group;
import com.joelapenna.foursquare.types.Response;
@@ -47,8 +46,6 @@
public static final String MALE = "male";
public static final String FEMALE = "female";
- private String mPhone;
- private String mPassword;
private FoursquareHttpApiV1 mFoursquareV1;
@V1
@@ -57,56 +54,32 @@
}
public void setCredentials(String phone, String password) {
- mPhone = phone;
- mPassword = password;
mFoursquareV1.setCredentials(phone, password);
}
-
- @V1
- public void setOAuthToken(String token, String secret) {
- mFoursquareV1.setOAuthTokenWithSecret(token, secret);
- }
-
- @V1
- public void setOAuthConsumerCredentials(String oAuthConsumerKey,
String oAuthConsumerSecret) {
- mFoursquareV1.setOAuthConsumerCredentials(oAuthConsumerKey,
oAuthConsumerSecret);
- }
public void clearAllCredentials() {
setCredentials(null, null);
- setOAuthToken(null, null);
}
@V1
public boolean hasCredentials() {
- return mFoursquareV1.hasCredentials() &&
mFoursquareV1.hasOAuthTokenWithSecret();
+ return mFoursquareV1.hasCredentials();
}
@V1
public boolean hasLoginAndPassword() {
return mFoursquareV1.hasCredentials();
}
-
- @V1
- public Credentials authExchange() throws FoursquareException,
FoursquareError,
- FoursquareCredentialsException, IOException {
- if (mFoursquareV1 == null) {
- throw new NoSuchMethodError(
- "authExchange is unavailable without a consumer
key/secret.");
- }
- return mFoursquareV1.authExchange(mPhone, mPassword);
- }
@V1
public Tip addTip(String vid, String text, String type, Location
location)
- throws FoursquareException, FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.addtip(vid, text, type, location.geolat,
location.geolong,
location.geohacc, location.geovacc, location.geoalt);
}
@V1
- public Tip tipDetail(String tid)
- throws FoursquareException, FoursquareError, IOException {
+ public Tip tipDetail(String tid) throws Exception {
return mFoursquareV1.tipDetail(tid);
}
@@ -114,8 +87,7 @@
@LocationRequired
public Venue addVenue(String name, String address, String crossstreet,
String city,
String state, String zip, String phone, String categoryId,
Location location)
- throws FoursquareException,
- FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.addvenue(name, address, crossstreet, city,
state, zip, phone,
categoryId, location.geolat, location.geolong,
location.geohacc, location.geovacc,
location.geoalt);
@@ -124,68 +96,61 @@
@V1
public CheckinResult checkin(String venueId, String venueName,
Location location, String shout,
boolean isPrivate, boolean tellFollowers, boolean twitter,
boolean facebook)
- throws FoursquareException,
- FoursquareError,
- IOException {
+ throws Exception {
return mFoursquareV1.checkin(venueId, venueName, location.geolat,
location.geolong,
location.geohacc, location.geovacc, location.geoalt,
shout, isPrivate,
tellFollowers, twitter, facebook);
}
@V1
- public Group<Checkin> checkins(Location location) throws
FoursquareException, FoursquareError,
- IOException {
+ public Group<Checkin> checkins(Location location) throws Exception {
return mFoursquareV1.checkins(location.geolat, location.geolong,
location.geohacc,
location.geovacc, location.geoalt);
}
@V1
- public Group<User> friends(String userId, Location location) throws
FoursquareException,
- FoursquareError, IOException {
+ public Group<User> friends(String userId, Location location) throws
Exception {
return mFoursquareV1.friends(userId, location.geolat,
location.geolong,
location.geohacc, location.geovacc, location.geoalt);
}
@V1
- public Group<User> friendRequests() throws FoursquareException,
FoursquareError, IOException {
+ public Group<User> friendRequests() throws Exception {
return mFoursquareV1.friendRequests();
}
@V1
- public User friendApprove(String userId) throws FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
+ public User friendApprove(String userId) throws Exception {
return mFoursquareV1.friendApprove(userId);
}
@V1
- public User friendDeny(String userId) throws FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
+ public User friendDeny(String userId) throws Exception {
return mFoursquareV1.friendDeny(userId);
}
@V1
- public User friendSendrequest(String userId) throws
FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
+ public User friendSendrequest(String userId) throws Exception {
return mFoursquareV1.friendSendrequest(userId);
}
@V1
public Group<Tip> tips(Location location, String uid, String filter,
String sort, int limit)
- throws FoursquareException, FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.tips(location.geolat, location.geolong,
location.geohacc,
location.geovacc, location.geoalt, uid, filter, sort,
limit);
}
@V1
public Group<Todo> todos(Location location, String uid, boolean
recent, boolean nearby, int limit)
- throws FoursquareException, FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.todos(uid, location.geolat, location.geolong,
location.geohacc,
location.geovacc, location.geoalt, recent, nearby, limit);
}
@V1
public User user(String user, boolean mayor, boolean badges, boolean
stats, Location location)
- throws FoursquareException, FoursquareError, IOException {
+ throws Exception {
if (location != null) {
return mFoursquareV1.user(user, mayor, badges, stats,
location.geolat, location.geolong,
location.geohacc, location.geovacc, location.geoalt);
@@ -195,8 +160,7 @@
}
@V1
- public Venue venue(String id, Location location) throws
FoursquareException, FoursquareError,
- IOException {
+ public Venue venue(String id, Location location) throws Exception {
return mFoursquareV1.venue(id, location.geolat, location.geolong,
location.geohacc,
location.geovacc, location.geoalt);
}
@@ -204,129 +168,129 @@
@V1
@LocationRequired
public Group<Group<Venue>> venues(Location location, String query, int
limit)
- throws FoursquareException, FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.venues(location.geolat, location.geolong,
location.geohacc,
location.geovacc, location.geoalt, query, limit);
}
@V1
public Group<User> findFriendsByName(String text)
- throws FoursquareException, FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.findFriendsByName(text);
}
@V1
public Group<User> findFriendsByPhone(String text)
- throws FoursquareException, FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.findFriendsByPhone(text);
}
@V1
public Group<User> findFriendsByFacebook(String text)
- throws FoursquareException, FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.findFriendsByFacebook(text);
}
@V1
public Group<User> findFriendsByTwitter(String text)
- throws FoursquareException, FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.findFriendsByTwitter(text);
}
@V1
public Group<Category> categories()
- throws FoursquareException, FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.categories();
}
@V1
public Group<Checkin> history(String limit, String sinceid)
- throws FoursquareException, FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.history(limit, sinceid);
}
@V1
public Todo markTodo(String tid)
- throws FoursquareException, FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.markTodo(tid);
}
@V1
public Todo markTodoVenue(String vid)
- throws FoursquareException, FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.markTodoVenue(vid);
}
@V1
public Tip markIgnore(String tid)
- throws FoursquareException, FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.markIgnore(tid);
}
@V1
public Tip markDone(String tid)
- throws FoursquareException, FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.markDone(tid);
}
@V1
public Tip unmarkTodo(String tid)
- throws FoursquareException, FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.unmarkTodo(tid);
}
@V1
public Tip unmarkDone(String tid)
- throws FoursquareException, FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.unmarkDone(tid);
}
@V1
public FriendInvitesResult findFriendsByPhoneOrEmail(String phones,
String emails)
- throws FoursquareException, FoursquareCredentialsException,
FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.findFriendsByPhoneOrEmail(phones, emails);
}
@V1
public Response inviteByEmail(String emails)
- throws FoursquareException, FoursquareCredentialsException,
FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.inviteByEmail(emails);
}
@V1
public Settings setpings(boolean on)
- throws FoursquareException, FoursquareCredentialsException,
FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.setpings(on);
}
@V1
public Settings setpings(String userid, boolean on)
- throws FoursquareException, FoursquareCredentialsException,
FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.setpings(userid, on);
}
@V1
public Response flagclosed(String venueid)
- throws FoursquareException, FoursquareCredentialsException,
FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.flagclosed(venueid);
}
@V1
public Response flagmislocated(String venueid)
- throws FoursquareException, FoursquareCredentialsException,
FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.flagmislocated(venueid);
}
@V1
public Response flagduplicate(String venueid)
- throws FoursquareException, FoursquareCredentialsException,
FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.flagduplicate(venueid);
}
@V1
public Response proposeedit(String venueId, String name, String
address, String crossstreet,
String city, String state, String zip, String phone, String
categoryId, Location location)
- throws FoursquareException, FoursquareCredentialsException,
FoursquareError, IOException {
+ throws Exception {
return mFoursquareV1.proposeedit(venueId, name, address,
crossstreet, city, state, zip,
phone, categoryId, location.geolat, location.geolong,
location.geohacc,
location.geovacc, location.geoalt);
@@ -338,14 +302,13 @@
return mFoursquareV1.userUpdate(imagePathToJpg, username,
password);
}
- public static final FoursquareHttpApiV1 createHttpApi(String domain,
String clientVersion,
- boolean useOAuth) {
+ public static final FoursquareHttpApiV1 createHttpApi(String domain,
String clientVersion) {
LOG.log(Level.INFO, "Using foursquare.com for requests.");
- return new FoursquareHttpApiV1(domain, clientVersion, useOAuth);
+ return new FoursquareHttpApiV1(domain, clientVersion);
}
- public static final FoursquareHttpApiV1 createHttpApi(String
clientVersion, boolean useOAuth) {
- return createHttpApi(FOURSQUARE_API_DOMAIN, clientVersion,
useOAuth);
+ public static final FoursquareHttpApiV1 createHttpApi(String
clientVersion) {
+ return createHttpApi(FOURSQUARE_API_DOMAIN, clientVersion);
}
public static final String createLeaderboardUrl(String userId,
Location location) {
=======================================
--- /main/src/com/joelapenna/foursquare/FoursquareHttpApiV1.java Wed Sep 29
11:12:24 2010
+++ /main/src/com/joelapenna/foursquare/FoursquareHttpApiV1.java Thu Oct 14
00:13:03 2010
@@ -8,15 +8,11 @@
import com.joelapenna.foursquare.error.FoursquareError;
import com.joelapenna.foursquare.error.FoursquareException;
import com.joelapenna.foursquare.error.FoursquareParseException;
-import com.joelapenna.foursquare.http.AbstractHttpApi;
-import com.joelapenna.foursquare.http.HttpApi;
-import com.joelapenna.foursquare.http.HttpApiWithBasicAuth;
-import com.joelapenna.foursquare.http.HttpApiWithOAuth;
+import com.joelapenna.foursquare.http.HttpImpl;
import com.joelapenna.foursquare.parsers.json.CategoryParser;
import com.joelapenna.foursquare.parsers.json.CheckinParser;
import com.joelapenna.foursquare.parsers.json.CheckinResultParser;
import com.joelapenna.foursquare.parsers.json.CityParser;
-import com.joelapenna.foursquare.parsers.json.CredentialsParser;
import com.joelapenna.foursquare.parsers.json.FriendInvitesResultParser;
import com.joelapenna.foursquare.parsers.json.GroupParser;
import com.joelapenna.foursquare.parsers.json.ResponseParser;
@@ -29,7 +25,6 @@
import com.joelapenna.foursquare.types.Checkin;
import com.joelapenna.foursquare.types.CheckinResult;
import com.joelapenna.foursquare.types.City;
-import com.joelapenna.foursquare.types.Credentials;
import com.joelapenna.foursquare.types.FriendInvitesResult;
import com.joelapenna.foursquare.types.Group;
import com.joelapenna.foursquare.types.Response;
@@ -41,11 +36,6 @@
import com.joelapenna.foursquare.util.JSONUtils;
import com.joelapenna.foursquared.util.Base64Coder;
-import org.apache.http.auth.AuthScope;
-import org.apache.http.auth.UsernamePasswordCredentials;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.client.methods.HttpPost;
-import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import java.io.BufferedReader;
@@ -57,7 +47,6 @@
import java.net.HttpURLConnection;
import java.net.SocketTimeoutException;
import java.net.URL;
-import java.util.logging.Level;
import java.util.logging.Logger;
/**
@@ -70,8 +59,6 @@
private static final String DATATYPE = ".json";
- private static final String URL_API_AUTHEXCHANGE = "/authexchange";
-
private static final String URL_API_ADDVENUE = "/addvenue";
private static final String URL_API_ADDTIP = "/addtip";
private static final String URL_API_CITIES = "/cities";
@@ -108,78 +95,43 @@
private static final String URL_API_UNMARK_DONE = "/unmark/done";
private static final String URL_API_TIP_DETAIL = "/tip/detail";
- private final DefaultHttpClient mHttpClient =
AbstractHttpApi.createHttpClient();
- private HttpApi mHttpApi;
+ //private final DefaultHttpClient mHttpClient =
AbstractHttpApi.createHttpClient();
+ //private HttpApi mHttpApi;
private final String mApiBaseUrl;
- private final AuthScope mAuthScope;
-
- public FoursquareHttpApiV1(String domain, String clientVersion,
boolean useOAuth) {
+ //private final AuthScope mAuthScope;
+
+ private HttpImpl mHttp;
+
+
+ public FoursquareHttpApiV1(String domain, String clientVersion) {
mApiBaseUrl = "https://" + domain + "/v1";
- mAuthScope = new AuthScope(domain, 80);
-
- if (useOAuth) {
- mHttpApi = new HttpApiWithOAuth(mHttpClient, clientVersion);
- } else {
- mHttpApi = new HttpApiWithBasicAuth(mHttpClient,
clientVersion);
- }
+ // mAuthScope = new AuthScope(domain, 80);
+
+ // mHttpApi = new HttpApiWithBasicAuth(mHttpClient, clientVersion);
+ mHttp = new HttpImpl(clientVersion);
+ }
+
+ public boolean hasCredentials() {
+ return mHttp.getHasCredentials();
}
void setCredentials(String phone, String password) {
if (phone == null || phone.length() == 0 || password == null ||
password.length() == 0) {
- if (DEBUG) LOG.log(Level.FINE, "Clearing Credentials");
- mHttpClient.getCredentialsProvider().clear();
+ mHttp.setCredentials(null, null);
} else {
- if (DEBUG) LOG.log(Level.FINE, "Setting Phone/Password: " +
phone + "/******");
- mHttpClient.getCredentialsProvider().setCredentials(mAuthScope,
- new UsernamePasswordCredentials(phone, password));
+ mHttp.setCredentials(phone, password);
}
}
-
- public boolean hasCredentials() {
- return
mHttpClient.getCredentialsProvider().getCredentials(mAuthScope) != null;
- }
-
- public void setOAuthConsumerCredentials(String oAuthConsumerKey,
String oAuthConsumerSecret) {
- if (DEBUG) {
- LOG.log(Level.FINE, "Setting consumer key/secret: " +
oAuthConsumerKey + " "
- + oAuthConsumerSecret);
- }
- ((HttpApiWithOAuth)
mHttpApi).setOAuthConsumerCredentials(oAuthConsumerKey,
- oAuthConsumerSecret);
- }
-
- public void setOAuthTokenWithSecret(String token, String secret) {
- if (DEBUG) LOG.log(Level.FINE, "Setting oauth token/secret: " +
token + " " + secret);
- ((HttpApiWithOAuth) mHttpApi).setOAuthTokenWithSecret(token,
secret);
- }
-
- public boolean hasOAuthTokenWithSecret() {
- return ((HttpApiWithOAuth) mHttpApi).hasOAuthTokenWithSecret();
- }
-
- /*
- *
/authexchange?oauth_consumer_key=d123...a1bffb5&oauth_consumer_secret=fec...
- * 18
- */
- public Credentials authExchange(String phone, String password) throws
FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- if (((HttpApiWithOAuth) mHttpApi).hasOAuthTokenWithSecret()) {
- throw new IllegalStateException("Cannot do authExchange with
OAuthToken already set");
- }
- HttpPost httpPost =
mHttpApi.createHttpPost(fullUrl(URL_API_AUTHEXCHANGE), //
- new BasicNameValuePair("fs_username", phone), //
- new BasicNameValuePair("fs_password", password));
- return (Credentials) mHttpApi.doHttpRequest(httpPost, new
CredentialsParser());
- }
/*
* /addtip?vid=1234&text=I%20added%20a%20tip&type=todo (type
defaults "tip")
*/
Tip addtip(String vid, String text, String type, String geolat, String
geolong, String geohacc,
- String geovacc, String geoalt) throws FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpPost httpPost =
mHttpApi.createHttpPost(fullUrl(URL_API_ADDTIP), //
+ String geovacc, String geoalt) throws Exception {
+ return (Tip)mHttp.httpPost(
+ fullUrl(URL_API_ADDTIP),
+ new TipParser(),
new BasicNameValuePair("vid", vid), //
new BasicNameValuePair("text", text), //
new BasicNameValuePair("type", type), //
@@ -188,7 +140,6 @@
new BasicNameValuePair("geohacc", geohacc), //
new BasicNameValuePair("geovacc", geovacc), //
new BasicNameValuePair("geoalt", geoalt));
- return (Tip) mHttpApi.doHttpRequest(httpPost, new TipParser());
}
/**
@@ -207,9 +158,9 @@
*/
Venue addvenue(String name, String address, String crossstreet, String
city, String state,
String zip, String phone, String categoryId, String geolat,
String geolong, String geohacc,
- String geovacc, String geoalt) throws FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpPost httpPost =
mHttpApi.createHttpPost(fullUrl(URL_API_ADDVENUE), //
+ String geovacc, String geoalt) throws Exception {
+ return (Venue)mHttp.httpPost(fullUrl(URL_API_ADDVENUE), //
+ new VenueParser(),
new BasicNameValuePair("name", name), //
new BasicNameValuePair("address", address), //
new BasicNameValuePair("crossstreet", crossstreet), //
@@ -222,19 +173,17 @@
new BasicNameValuePair("geolong", geolong), //
new BasicNameValuePair("geohacc", geohacc), //
new BasicNameValuePair("geovacc", geovacc), //
- new BasicNameValuePair("geoalt", geoalt) //
- );
- return (Venue) mHttpApi.doHttpRequest(httpPost, new VenueParser());
+ new BasicNameValuePair("geoalt", geoalt));
}
/*
* /cities
*/
@SuppressWarnings("unchecked")
- Group<City> cities() throws FoursquareException,
FoursquareCredentialsException,
- FoursquareError, IOException {
- HttpGet httpGet = mHttpApi.createHttpGet(fullUrl(URL_API_CITIES));
- return (Group<City>) mHttpApi.doHttpRequest(httpGet, new
GroupParser(new CityParser()));
+ Group<City> cities() throws Exception {
+ return (Group<City>)mHttp.httpGet(
+ fullUrl(URL_API_CITIES),
+ new GroupParser(new CityParser()));
}
/*
@@ -242,15 +191,15 @@
*/
@SuppressWarnings("unchecked")
Group<Checkin> checkins(String geolat, String geolong, String geohacc,
String geovacc,
- String geoalt) throws FoursquareException, FoursquareError,
IOException {
- HttpGet httpGet =
mHttpApi.createHttpGet(fullUrl(URL_API_CHECKINS), //
+ String geoalt) throws Exception {
+ return (Group<Checkin>)mHttp.httpGet(
+ fullUrl(URL_API_CHECKINS), //
+ new GroupParser(new CheckinParser()),
new BasicNameValuePair("geolat", geolat), //
new BasicNameValuePair("geolong", geolong), //
new BasicNameValuePair("geohacc", geohacc), //
new BasicNameValuePair("geovacc", geovacc), //
new BasicNameValuePair("geoalt", geoalt));
- return (Group<Checkin>) mHttpApi.doHttpRequest(httpGet,
- new GroupParser(new CheckinParser()));
}
/*
@@ -258,8 +207,10 @@
*/
CheckinResult checkin(String vid, String venue, String geolat, String
geolong, String geohacc,
String geovacc, String geoalt, String shout, boolean
isPrivate, boolean tellFollowers,
- boolean twitter, boolean facebook) throws FoursquareException,
FoursquareError, IOException {
- HttpPost httpPost =
mHttpApi.createHttpPost(fullUrl(URL_API_CHECKIN), //
+ boolean twitter, boolean facebook) throws Exception {
+ return (CheckinResult)mHttp.httpPost(
+ fullUrl(URL_API_CHECKIN), //
+ new CheckinResultParser(),
new BasicNameValuePair("vid", vid), //
new BasicNameValuePair("venue", venue), //
new BasicNameValuePair("geolat", geolat), //
@@ -273,16 +224,16 @@
new BasicNameValuePair("twitter", (twitter) ? "1" : "0"),
//
new BasicNameValuePair("facebook",
(facebook) ? "1" : "0"), //
new BasicNameValuePair("markup", "android")); // used only
by android for checkin result 'extras'.
- return (CheckinResult) mHttpApi.doHttpRequest(httpPost, new
CheckinResultParser());
}
/**
* /user?uid=9937
*/
User user(String uid, boolean mayor, boolean badges, boolean stats,
String geolat, String geolong,
- String geohacc, String geovacc, String geoalt) throws
FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpGet httpGet = mHttpApi.createHttpGet(fullUrl(URL_API_USER), //
+ String geohacc, String geovacc, String geoalt) throws
Exception {
+ return (User)mHttp.httpGet(
+ fullUrl(URL_API_USER), //
+ new UserParser(),
new BasicNameValuePair("uid", uid), //
new BasicNameValuePair("mayor", (mayor) ? "1" : "0"), //
new BasicNameValuePair("badges", (badges) ? "1" : "0"), //
@@ -291,9 +242,7 @@
new BasicNameValuePair("geolong", geolong), //
new BasicNameValuePair("geohacc", geohacc), //
new BasicNameValuePair("geovacc", geovacc), //
- new BasicNameValuePair("geoalt", geoalt) //
- );
- return (User) mHttpApi.doHttpRequest(httpGet, new UserParser());
+ new BasicNameValuePair("geoalt", geoalt));
}
/**
@@ -301,9 +250,10 @@
*/
@SuppressWarnings("unchecked")
Group<Group<Venue>> venues(String geolat, String geolong, String
geohacc, String geovacc,
- String geoalt, String query, int limit) throws
FoursquareException, FoursquareError,
- IOException {
- HttpGet httpGet = mHttpApi.createHttpGet(fullUrl(URL_API_VENUES),
//
+ String geoalt, String query, int limit) throws Exception {
+ return (Group<Group<Venue>>)mHttp.httpGet(
+ fullUrl(URL_API_VENUES), //
+ new GroupParser(new GroupParser(new VenueParser())),
new BasicNameValuePair("geolat", geolat), //
new BasicNameValuePair("geolong", geolong), //
new BasicNameValuePair("geohacc", geohacc), //
@@ -311,25 +261,22 @@
new BasicNameValuePair("geoalt", geoalt), //
new BasicNameValuePair("q", query), //
new BasicNameValuePair("l", String.valueOf(limit)));
- return (Group<Group<Venue>>) mHttpApi.doHttpRequest(httpGet, new
GroupParser(
- new GroupParser(new VenueParser())));
}
/**
* /venue?vid=1234
*/
Venue venue(String vid, String geolat, String geolong, String geohacc,
String geovacc,
- String geoalt) throws FoursquareException,
FoursquareCredentialsException,
- FoursquareError, IOException {
- HttpGet httpGet = mHttpApi.createHttpGet(fullUrl(URL_API_VENUE), //
+ String geoalt) throws Exception {
+ return (Venue)mHttp.httpGet(
+ fullUrl(URL_API_VENUE), //
+ new VenueParser(),
new BasicNameValuePair("vid", vid), //
new BasicNameValuePair("geolat", geolat), //
new BasicNameValuePair("geolong", geolong), //
new BasicNameValuePair("geohacc", geohacc), //
new BasicNameValuePair("geovacc", geovacc), //
- new BasicNameValuePair("geoalt", geoalt) //
- );
- return (Venue) mHttpApi.doHttpRequest(httpGet, new VenueParser());
+ new BasicNameValuePair("geoalt", geoalt));
}
/**
@@ -337,9 +284,10 @@
*/
@SuppressWarnings("unchecked")
Group<Tip> tips(String geolat, String geolong, String geohacc, String
geovacc,
- String geoalt, String uid, String filter, String sort, int
limit) throws FoursquareException,
- FoursquareError, IOException {
- HttpGet httpGet = mHttpApi.createHttpGet(fullUrl(URL_API_TIPS), //
+ String geoalt, String uid, String filter, String sort, int
limit) throws Exception {
+ return (Group<Tip>)mHttp.httpGet(
+ fullUrl(URL_API_TIPS), //
+ new GroupParser(new TipParser()),
new BasicNameValuePair("geolat", geolat), //
new BasicNameValuePair("geolong", geolong), //
new BasicNameValuePair("geohacc", geohacc), //
@@ -348,10 +296,7 @@
new BasicNameValuePair("uid", uid), //
new BasicNameValuePair("filter", filter), //
new BasicNameValuePair("sort", sort), //
- new BasicNameValuePair("l", String.valueOf(limit)) //
- );
- return (Group<Tip>) mHttpApi.doHttpRequest(httpGet, new
GroupParser(
- new TipParser()));
+ new BasicNameValuePair("l", String.valueOf(limit)));
}
/**
@@ -359,15 +304,16 @@
*/
@SuppressWarnings("unchecked")
Group<Todo> todos(String uid, String geolat, String geolong, String
geohacc, String geovacc,
- String geoalt, boolean recent, boolean nearby, int limit)
- throws FoursquareException, FoursquareError, IOException {
+ String geoalt, boolean recent, boolean nearby, int limit)
throws Exception {
String sort = null;
if (recent) {
sort = "recent";
} else if (nearby) {
sort = "nearby";
}
- HttpGet httpGet = mHttpApi.createHttpGet(fullUrl(URL_API_TODOS), //
+ return (Group<Todo>)mHttp.httpGet(
+ fullUrl(URL_API_TODOS), //
+ new GroupParser(new TodoParser()),
new BasicNameValuePair("uid", uid), //
new BasicNameValuePair("geolat", geolat), //
new BasicNameValuePair("geolong", geolong), //
@@ -375,10 +321,7 @@
new BasicNameValuePair("geovacc", geovacc), //
new BasicNameValuePair("geoalt", geoalt), //
new BasicNameValuePair("sort", sort), //
- new BasicNameValuePair("l", String.valueOf(limit)) //
- );
- return (Group<Todo>) mHttpApi.doHttpRequest(httpGet, new
GroupParser(
- new TodoParser()));
+ new BasicNameValuePair("l", String.valueOf(limit)));
}
/*
@@ -386,263 +329,264 @@
*/
@SuppressWarnings("unchecked")
Group<User> friends(String uid, String geolat, String geolong, String
geohacc, String geovacc,
- String geoalt) throws FoursquareException, FoursquareError,
IOException {
- HttpGet httpGet = mHttpApi.createHttpGet(fullUrl(URL_API_FRIENDS),
//
+ String geoalt) throws Exception {
+ return (Group<User>)mHttp.httpGet(
+ fullUrl(URL_API_FRIENDS), //
+ new GroupParser(new UserParser()),
new BasicNameValuePair("uid", uid), //
new BasicNameValuePair("geolat", geolat), //
new BasicNameValuePair("geolong", geolong), //
new BasicNameValuePair("geohacc", geohacc), //
new BasicNameValuePair("geovacc", geovacc), //
- new BasicNameValuePair("geoalt", geoalt) //
- );
- return (Group<User>) mHttpApi.doHttpRequest(httpGet, new
GroupParser(new UserParser()));
+ new BasicNameValuePair("geoalt", geoalt));
}
/*
* /friend/requests
*/
@SuppressWarnings("unchecked")
- Group<User> friendRequests() throws FoursquareException,
FoursquareError, IOException {
- HttpGet httpGet =
mHttpApi.createHttpGet(fullUrl(URL_API_FRIEND_REQUESTS));
- return (Group<User>) mHttpApi.doHttpRequest(httpGet, new
GroupParser(new UserParser()));
+ Group<User> friendRequests() throws Exception {
+ return (Group<User>)mHttp.httpGet(
+ fullUrl(URL_API_FRIEND_REQUESTS),
+ new GroupParser(new UserParser()));
}
/*
* /friend/approve?uid=9937
*/
- User friendApprove(String uid) throws FoursquareException,
FoursquareCredentialsException,
- FoursquareError, IOException {
- HttpPost httpPost =
mHttpApi.createHttpPost(fullUrl(URL_API_FRIEND_APPROVE), //
- new BasicNameValuePair("uid", uid));
- return (User) mHttpApi.doHttpRequest(httpPost, new UserParser());
+ User friendApprove(String uid) throws Exception {
+ return (User)mHttp.httpPost(
+ fullUrl(URL_API_FRIEND_APPROVE),
+ new UserParser(),
+ new BasicNameValuePair("uid", uid));
}
/*
* /friend/deny?uid=9937
*/
- User friendDeny(String uid) throws FoursquareException,
FoursquareCredentialsException,
- FoursquareError, IOException {
- HttpPost httpPost =
mHttpApi.createHttpPost(fullUrl(URL_API_FRIEND_DENY), //
- new BasicNameValuePair("uid", uid));
- return (User) mHttpApi.doHttpRequest(httpPost, new UserParser());
+ User friendDeny(String uid) throws Exception {
+ return (User)mHttp.httpPost(
+ fullUrl(URL_API_FRIEND_DENY),
+ new UserParser(),
+ new BasicNameValuePair("uid", uid));
}
/*
* /friend/sendrequest?uid=9937
*/
- User friendSendrequest(String uid) throws FoursquareException,
FoursquareCredentialsException,
- FoursquareError, IOException {
- HttpPost httpPost =
mHttpApi.createHttpPost(fullUrl(URL_API_FRIEND_SENDREQUEST), //
- new BasicNameValuePair("uid", uid));
- return (User) mHttpApi.doHttpRequest(httpPost, new UserParser());
+ User friendSendrequest(String uid) throws Exception {
+ return (User)mHttp.httpPost(
+ fullUrl(URL_API_FRIEND_SENDREQUEST),
+ new UserParser(),
+ new BasicNameValuePair("uid", uid));
}
/**
* /findfriends/byname?q=john doe, mary smith
*/
@SuppressWarnings("unchecked")
- public Group<User> findFriendsByName(String text) throws
FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpGet httpGet =
mHttpApi.createHttpGet(fullUrl(URL_API_FIND_FRIENDS_BY_NAME), //
+ public Group<User> findFriendsByName(String text) throws Exception {
+ return (Group<User>)mHttp.httpGet(
+ fullUrl(URL_API_FIND_FRIENDS_BY_NAME),
+ new GroupParser(new UserParser()),
new BasicNameValuePair("q", text));
- return (Group<User>) mHttpApi.doHttpRequest(httpGet, new
GroupParser(new UserParser()));
}
/**
* /findfriends/byphone?q=555-5555,555-5556
*/
@SuppressWarnings("unchecked")
- public Group<User> findFriendsByPhone(String text) throws
FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpPost httpPost =
mHttpApi.createHttpPost(fullUrl(URL_API_FIND_FRIENDS_BY_PHONE), //
+ public Group<User> findFriendsByPhone(String text) throws Exception {
+ return (Group<User>)mHttp.httpGet(
+ fullUrl(URL_API_FIND_FRIENDS_BY_PHONE),
+ new GroupParser(new UserParser()),
new BasicNameValuePair("q", text));
- return (Group<User>) mHttpApi.doHttpRequest(httpPost, new
GroupParser(new UserParser()));
}
/**
* /findfriends/byfacebook?q=friendid,friendid,friendid
*/
@SuppressWarnings("unchecked")
- public Group<User> findFriendsByFacebook(String text) throws
FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpPost httpPost =
mHttpApi.createHttpPost(fullUrl(URL_API_FIND_FRIENDS_BY_FACEBOOK), //
+ public Group<User> findFriendsByFacebook(String text) throws Exception
{
+ return (Group<User>)mHttp.httpPost(
+ fullUrl(URL_API_FIND_FRIENDS_BY_FACEBOOK),
+ new GroupParser(new UserParser()),
new BasicNameValuePair("q", text));
- return (Group<User>) mHttpApi.doHttpRequest(httpPost, new
GroupParser(new UserParser()));
}
/**
* /findfriends/bytwitter?q=yourtwittername
*/
@SuppressWarnings("unchecked")
- public Group<User> findFriendsByTwitter(String text) throws
FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpGet httpGet =
mHttpApi.createHttpGet(fullUrl(URL_API_FIND_FRIENDS_BY_TWITTER), //
+ public Group<User> findFriendsByTwitter(String text) throws Exception {
+ return (Group<User>)mHttp.httpGet(
+ fullUrl(URL_API_FIND_FRIENDS_BY_TWITTER),
+ new GroupParser(new UserParser()),
new BasicNameValuePair("q", text));
- return (Group<User>) mHttpApi.doHttpRequest(httpGet, new
GroupParser(new UserParser()));
}
/**
* /categories
*/
@SuppressWarnings("unchecked")
- public Group<Category> categories() throws FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpGet httpGet =
mHttpApi.createHttpGet(fullUrl(URL_API_CATEGORIES));
- return (Group<Category>) mHttpApi.doHttpRequest(httpGet, new
GroupParser(new CategoryParser()));
+ public Group<Category> categories() throws Exception {
+ return (Group<Category>)mHttp.httpGet(
+ fullUrl(URL_API_CATEGORIES),
+ new GroupParser(new CategoryParser()));
}
/**
* /history
*/
@SuppressWarnings("unchecked")
- public Group<Checkin> history(String limit, String sinceid) throws
FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpGet httpGet = mHttpApi.createHttpGet(fullUrl(URL_API_HISTORY),
+ public Group<Checkin> history(String limit, String sinceid) throws
Exception {
+ return (Group<Checkin>)mHttp.httpGet(
+ fullUrl(URL_API_HISTORY),
+ new GroupParser(new CheckinParser()),
new BasicNameValuePair("l", limit),
new BasicNameValuePair("sinceid", sinceid));
- return (Group<Checkin>) mHttpApi.doHttpRequest(httpGet, new
GroupParser(new CheckinParser()));
}
/**
* /mark/todo
*/
- public Todo markTodo(String tid) throws FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpPost httpPost =
mHttpApi.createHttpPost(fullUrl(URL_API_MARK_TODO), //
+ public Todo markTodo(String tid) throws Exception {
+ return (Todo)mHttp.httpPost(
+ fullUrl(URL_API_MARK_TODO),
+ new TodoParser(),
new BasicNameValuePair("tid", tid));
- return (Todo) mHttpApi.doHttpRequest(httpPost, new TodoParser());
}
/**
* This is a hacky special case, hopefully the api will be updated in
v2 for this.
* /mark/todo
*/
- public Todo markTodoVenue(String vid) throws FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpPost httpPost =
mHttpApi.createHttpPost(fullUrl(URL_API_MARK_TODO), //
+ public Todo markTodoVenue(String vid) throws Exception {
+ return (Todo)mHttp.httpPost(
+ fullUrl(URL_API_MARK_TODO),
+ new TodoParser(),
new BasicNameValuePair("vid", vid));
- return (Todo) mHttpApi.doHttpRequest(httpPost, new TodoParser());
}
/**
* /mark/ignore
*/
- public Tip markIgnore(String tid) throws FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpPost httpPost =
mHttpApi.createHttpPost(fullUrl(URL_API_MARK_IGNORE), //
+ public Tip markIgnore(String tid) throws Exception {
+ return (Tip)mHttp.httpPost(
+ fullUrl(URL_API_MARK_IGNORE),
+ new TipParser(),
new BasicNameValuePair("tid", tid));
- return (Tip) mHttpApi.doHttpRequest(httpPost, new TipParser());
}
/**
* /mark/done
*/
- public Tip markDone(String tid) throws FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpPost httpPost =
mHttpApi.createHttpPost(fullUrl(URL_API_MARK_DONE), //
+ public Tip markDone(String tid) throws Exception {
+ return (Tip)mHttp.httpPost(
+ fullUrl(URL_API_MARK_DONE),
+ new TipParser(),
new BasicNameValuePair("tid", tid));
- return (Tip) mHttpApi.doHttpRequest(httpPost, new TipParser());
}
/**
* /unmark/todo
*/
- public Tip unmarkTodo(String tid) throws FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpPost httpPost =
mHttpApi.createHttpPost(fullUrl(URL_API_UNMARK_TODO), //
- new BasicNameValuePair("tid", tid));
- return (Tip) mHttpApi.doHttpRequest(httpPost, new TipParser());
+ public Tip unmarkTodo(String tid) throws Exception {
+ return (Tip)mHttp.httpPost(
+ fullUrl(URL_API_UNMARK_TODO),
+ new TipParser(),
+ new BasicNameValuePair("tid", tid));
}
/**
* /unmark/done
*/
- public Tip unmarkDone(String tid) throws FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpPost httpPost =
mHttpApi.createHttpPost(fullUrl(URL_API_UNMARK_DONE), //
- new BasicNameValuePair("tid", tid));
- return (Tip) mHttpApi.doHttpRequest(httpPost, new TipParser());
+ public Tip unmarkDone(String tid) throws Exception {
+ return (Tip)mHttp.httpPost(
+ fullUrl(URL_API_UNMARK_DONE),
+ new TipParser(),
+ new BasicNameValuePair("tid", tid));
}
/**
* /tip/detail?tid=1234
*/
- public Tip tipDetail(String tid) throws FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpGet httpGet =
mHttpApi.createHttpGet(fullUrl(URL_API_TIP_DETAIL), //
+ public Tip tipDetail(String tid) throws Exception {
+ return (Tip)mHttp.httpPost(
+ fullUrl(URL_API_TIP_DETAIL),
+ new TipParser(),
new BasicNameValuePair("tid", tid));
- return (Tip) mHttpApi.doHttpRequest(httpGet, new TipParser());
}
/**
*
/findfriends/byphoneoremail?p=comma-sep-list-of-phones&e=comma-sep-list-of-emails
*/
- public FriendInvitesResult findFriendsByPhoneOrEmail(String phones,
String emails) throws FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpPost httpPost =
mHttpApi.createHttpPost(fullUrl(URL_API_FIND_FRIENDS_BY_PHONE_OR_EMAIL), //
+ public FriendInvitesResult findFriendsByPhoneOrEmail(String phones,
String emails) throws Exception {
+ return (FriendInvitesResult)mHttp.httpPost(
+ fullUrl(URL_API_FIND_FRIENDS_BY_PHONE_OR_EMAIL),
+ new FriendInvitesResultParser(),
new BasicNameValuePair("p", phones),
new BasicNameValuePair("e", emails));
- return (FriendInvitesResult) mHttpApi.doHttpRequest(httpPost, new
FriendInvitesResultParser());
}
/**
* /invite/byemail?q=comma-sep-list-of-emails
*/
- public Response inviteByEmail(String emails) throws
FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpPost httpPost =
mHttpApi.createHttpPost(fullUrl(URL_API_INVITE_BY_EMAIL), //
+ public Response inviteByEmail(String emails) throws Exception {
+ return (Response)mHttp.httpPost(
+ fullUrl(URL_API_INVITE_BY_EMAIL),
+ new ResponseParser(),
new BasicNameValuePair("q", emails));
- return (Response) mHttpApi.doHttpRequest(httpPost, new
ResponseParser());
}
/**
* /settings/setpings?self=[on|off]
*/
- public Settings setpings(boolean on) throws FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpPost httpPost =
mHttpApi.createHttpPost(fullUrl(URL_API_SETPINGS), //
+ public Settings setpings(boolean on) throws Exception {
+ return (Settings)mHttp.httpPost(
+ fullUrl(URL_API_SETPINGS),
+ new SettingsParser(),
new BasicNameValuePair("self", on ? "on" : "off"));
- return (Settings) mHttpApi.doHttpRequest(httpPost, new
SettingsParser());
}
/**
* /settings/setpings?uid=userid
*/
- public Settings setpings(String userid, boolean on) throws
FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpPost httpPost =
mHttpApi.createHttpPost(fullUrl(URL_API_SETPINGS), //
+ public Settings setpings(String userid, boolean on) throws Exception {
+ return (Settings)mHttp.httpPost(
+ fullUrl(URL_API_SETPINGS),
+ new SettingsParser(),
new BasicNameValuePair(userid, on ? "on" : "off"));
- return (Settings) mHttpApi.doHttpRequest(httpPost, new
SettingsParser());
}
/**
* /venue/flagclosed?vid=venueid
*/
- public Response flagclosed(String venueId) throws FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpPost httpPost =
mHttpApi.createHttpPost(fullUrl(URL_API_VENUE_FLAG_CLOSED), //
+ public Response flagclosed(String venueId) throws Exception {
+ return (Response)mHttp.httpPost(
+ fullUrl(URL_API_VENUE_FLAG_CLOSED),
+ new ResponseParser(),
new BasicNameValuePair("vid", venueId));
- return (Response) mHttpApi.doHttpRequest(httpPost, new
ResponseParser());
}
/**
* /venue/flagmislocated?vid=venueid
*/
- public Response flagmislocated(String venueId) throws
FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpPost httpPost =
mHttpApi.createHttpPost(fullUrl(URL_API_VENUE_FLAG_MISLOCATED), //
+ public Response flagmislocated(String venueId) throws Exception {
+ return (Response)mHttp.httpPost(
+ fullUrl(URL_API_VENUE_FLAG_MISLOCATED),
+ new ResponseParser(),
new BasicNameValuePair("vid", venueId));
- return (Response) mHttpApi.doHttpRequest(httpPost, new
ResponseParser());
}
/**
* /venue/flagduplicate?vid=venueid
*/
- public Response flagduplicate(String venueId) throws
FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpPost httpPost =
mHttpApi.createHttpPost(fullUrl(URL_API_VENUE_FLAG_DUPLICATE), //
+ public Response flagduplicate(String venueId) throws Exception {
+ return (Response)mHttp.httpPost(
+ fullUrl(URL_API_VENUE_FLAG_DUPLICATE),
+ new ResponseParser(),
new BasicNameValuePair("vid", venueId));
- return (Response) mHttpApi.doHttpRequest(httpPost, new
ResponseParser());
}
/**
@@ -650,9 +594,10 @@
*/
public Response proposeedit(String venueId, String name, String
address, String crossstreet,
String city, String state, String zip, String phone, String
categoryId, String geolat,
- String geolong, String geohacc, String geovacc, String geoalt)
throws FoursquareException,
- FoursquareCredentialsException, FoursquareError, IOException {
- HttpPost httpPost =
mHttpApi.createHttpPost(fullUrl(URL_API_VENUE_PROPOSE_EDIT), //
+ String geolong, String geohacc, String geovacc, String geoalt)
throws Exception {
+ return (Response)mHttp.httpPost(
+ fullUrl(URL_API_VENUE_PROPOSE_EDIT), //
+ new ResponseParser(),
new BasicNameValuePair("vid", venueId), //
new BasicNameValuePair("name", name), //
new BasicNameValuePair("address", address), //
@@ -666,9 +611,7 @@
new BasicNameValuePair("geolong", geolong), //
new BasicNameValuePair("geohacc", geohacc), //
new BasicNameValuePair("geovacc", geovacc), //
- new BasicNameValuePair("geoalt", geoalt) //
- );
- return (Response) mHttpApi.doHttpRequest(httpPost, new
ResponseParser());
+ new BasicNameValuePair("geoalt", geoalt));
}
private String fullUrl(String url) {
@@ -693,7 +636,7 @@
FileInputStream fileInputStream = new FileInputStream(file);
URL url = new URL(fullUrl(URL_API_USER_UPDATE));
- HttpURLConnection conn = mHttpApi.createHttpURLConnectionPost(url,
BOUNDARY);
+ HttpURLConnection conn = mHttp.createHttpURLConnectionPost(url,
BOUNDARY);
conn.setRequestProperty("Authorization", "Basic " +
Base64Coder.encodeString(username + ":" + password));
// We are always saving the image to a jpg so we can use .jpg as
the extension below.
=======================================
--- /main/src/com/joelapenna/foursquare/http/AbstractHttpApi.java Mon Sep
27 09:39:25 2010
+++ /main/src/com/joelapenna/foursquare/http/AbstractHttpApi.java Thu Oct
14 00:13:03 2010
@@ -14,7 +14,6 @@
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
-import org.apache.http.ParseException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
@@ -74,8 +73,6 @@
if (DEBUG) LOG.log(Level.FINE, "doHttpRequest: " +
httpRequest.getURI());
HttpResponse response = executeHttpRequest(httpRequest);
- if (DEBUG) LOG.log(Level.FINE, "executed HttpRequest for: "
- + httpRequest.getURI().toString());
int statusCode = response.getStatusLine().getStatusCode();
switch (statusCode) {
@@ -111,37 +108,6 @@
throw new FoursquareException("Error connecting to
Foursquare: " + statusCode + ". Try again later.");
}
}
-
- public String doHttpPost(String url, NameValuePair... nameValuePairs)
- throws FoursquareCredentialsException,
FoursquareParseException, FoursquareException,
- IOException {
- if (DEBUG) LOG.log(Level.FINE, "doHttpPost: " + url);
- HttpPost httpPost = createHttpPost(url, nameValuePairs);
-
- HttpResponse response = executeHttpRequest(httpPost);
- if (DEBUG) LOG.log(Level.FINE, "executed HttpRequest for: " +
httpPost.getURI().toString());
-
- switch (response.getStatusLine().getStatusCode()) {
- case 200:
- try {
- return EntityUtils.toString(response.getEntity());
- } catch (ParseException e) {
- throw new FoursquareParseException(e.getMessage());
- }
-
- case 401:
- response.getEntity().consumeContent();
- throw new
FoursquareCredentialsException(response.getStatusLine().toString());
-
- case 404:
- response.getEntity().consumeContent();
- throw new
FoursquareException(response.getStatusLine().toString());
-
- default:
- response.getEntity().consumeContent();
- throw new
FoursquareException(response.getStatusLine().toString());
- }
- }
/**
* execute() an httpRequest catching exceptions and returning null
instead.
@@ -151,8 +117,6 @@
* @throws IOException
*/
public HttpResponse executeHttpRequest(HttpRequestBase httpRequest)
throws IOException {
- if (DEBUG) LOG.log(Level.FINE, "executing HttpRequest for: "
- + httpRequest.getURI().toString());
try {
mHttpClient.getConnectionManager().closeExpiredConnections();
return mHttpClient.execute(httpRequest);
@@ -163,16 +127,13 @@
}
public HttpGet createHttpGet(String url, NameValuePair...
nameValuePairs) {
- if (DEBUG) LOG.log(Level.FINE, "creating HttpGet for: " + url);
String query = URLEncodedUtils.format(stripNulls(nameValuePairs),
HTTP.UTF_8);
HttpGet httpGet = new HttpGet(url + "?" + query);
httpGet.addHeader(CLIENT_VERSION_HEADER, mClientVersion);
- if (DEBUG) LOG.log(Level.FINE, "Created: " + httpGet.getURI());
return httpGet;
}
public HttpPost createHttpPost(String url, NameValuePair...
nameValuePairs) {
- if (DEBUG) LOG.log(Level.FINE, "creating HttpPost for: " + url);
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader(CLIENT_VERSION_HEADER, mClientVersion);
try {
@@ -180,7 +141,7 @@
} catch (UnsupportedEncodingException e1) {
throw new IllegalArgumentException("Unable to encode http
parameters.");
}
- if (DEBUG) LOG.log(Level.FINE, "Created: " + httpPost);
+
return httpPost;
}
@@ -253,5 +214,4 @@
return params;
}
-
-}
+}
=======================================
--- /main/src/com/joelapenna/foursquare/http/HttpApi.java Thu Sep 2
17:41:04 2010
+++ /main/src/com/joelapenna/foursquare/http/HttpApi.java Thu Oct 14
00:13:03 2010
@@ -28,10 +28,6 @@
Parser<? extends FoursquareType> parser) throws
FoursquareCredentialsException,
FoursquareParseException, FoursquareException, IOException;
- abstract public String doHttpPost(String url, NameValuePair...
nameValuePairs)
- throws FoursquareCredentialsException,
FoursquareParseException, FoursquareException,
- IOException;
-
abstract public HttpGet createHttpGet(String url, NameValuePair...
nameValuePairs);
abstract public HttpPost createHttpPost(String url, NameValuePair...
nameValuePairs);
=======================================
--- /main/src/com/joelapenna/foursquared/Foursquared.java Thu Sep 23
21:08:59 2010
+++ /main/src/com/joelapenna/foursquared/Foursquared.java Thu Oct 14
00:13:03 2010
@@ -5,8 +5,6 @@
package com.joelapenna.foursquared;
import com.joelapenna.foursquare.Foursquare;
-import com.joelapenna.foursquare.error.FoursquareError;
-import com.joelapenna.foursquare.error.FoursquareException;
import com.joelapenna.foursquare.types.User;
import com.joelapenna.foursquare.util.IconUtils;
import com.joelapenna.foursquared.app.FoursquaredService;
@@ -40,7 +38,6 @@
import android.util.Log;
import java.io.File;
-import java.io.IOException;
import java.util.Observer;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -68,7 +65,7 @@
private SharedPreferences mPrefs;
private RemoteResourceManager mRemoteResourceManager;
-
+
private Foursquare mFoursquare;
private BestLocationListener mBestLocationListener = new
BestLocationListener();
@@ -227,9 +224,9 @@
// Try logging in and setting up foursquare oauth, then user
// credentials.
if (FoursquaredSettings.USE_DEBUG_SERVER) {
- mFoursquare = new
Foursquare(Foursquare.createHttpApi("10.0.2.2:8080", mVersion, false));
+ mFoursquare = new
Foursquare(Foursquare.createHttpApi("10.0.2.2:8080", mVersion));
} else {
- mFoursquare = new
Foursquare(Foursquare.createHttpApi(mVersion, false));
+ mFoursquare = new
Foursquare(Foursquare.createHttpApi(mVersion));
}
if (FoursquaredSettings.DEBUG) Log.d(TAG, "loadCredentials()");
@@ -254,9 +251,9 @@
public static Foursquare createFoursquare(Context context) {
String version = getVersionString(context);
if (FoursquaredSettings.USE_DEBUG_SERVER) {
- return new
Foursquare(Foursquare.createHttpApi("10.0.2.2:8080", version, false));
+ return new
Foursquare(Foursquare.createHttpApi("10.0.2.2:8080", version));
} else {
- return new Foursquare(Foursquare.createHttpApi(version,
false));
+ return new Foursquare(Foursquare.createHttpApi(version));
}
}
@@ -404,15 +401,8 @@
mBestLocationListener.updateLocation(primeLocation);
}
- } catch (FoursquareError e) {
- if (DEBUG) Log.d(TAG, "FoursquareError", e);
- // TODO Auto-generated catch block
- } catch (FoursquareException e) {
- if (DEBUG) Log.d(TAG, "FoursquareException", e);
- // TODO Auto-generated catch block
- } catch (IOException e) {
- if (DEBUG) Log.d(TAG, "IOException", e);
- // TODO Auto-generated catch block
+ } catch (Exception e) {
+ Log.e(TAG, "FoursquareError", e);
}
return;
=======================================
--- /main/src/com/joelapenna/foursquared/FriendsActivity.java Tue Sep 28
18:18:51 2010
+++ /main/src/com/joelapenna/foursquared/FriendsActivity.java Thu Oct 14
00:13:03 2010
@@ -4,7 +4,6 @@
package com.joelapenna.foursquared;
-import com.joelapenna.foursquare.error.FoursquareException;
import com.joelapenna.foursquare.types.Checkin;
import com.joelapenna.foursquare.types.Group;
import
com.joelapenna.foursquared.app.LoadableListActivityWithViewAndHeader;
@@ -41,7 +40,6 @@
import android.widget.ListView;
import android.widget.ScrollView;
-import java.io.IOException;
import java.util.Collections;
import java.util.Date;
import java.util.LinkedHashMap;
@@ -490,7 +488,7 @@
}
}
- private Group<Checkin> checkins() throws FoursquareException,
IOException {
+ private Group<Checkin> checkins() throws Exception {
// If we're the startup tab, it's likely that we won't have a
geo location
// immediately. For now we can use this ugly method of
sleeping for N
=======================================
--- /main/src/com/joelapenna/foursquared/NearbyVenuesActivity.java Sat Oct
2 08:47:42 2010
+++ /main/src/com/joelapenna/foursquared/NearbyVenuesActivity.java Thu Oct
14 00:13:03 2010
@@ -275,7 +275,7 @@
if (resultCode == Activity.RESULT_OK &&
data.hasExtra(VenueActivity.EXTRA_VENUE_RETURNED)) {
Venue venue =
(Venue)data.getParcelableExtra(VenueActivity.EXTRA_VENUE_RETURNED);
mStateHolder.updateVenue(venue);
- mListAdapter.notifyDataSetInvalidated();
+ mListAdapter.notifyDataSetChanged();
}
break;
}
=======================================
--- /main/src/com/joelapenna/foursquared/SearchVenuesActivity.java Fri Oct
1 19:00:15 2010
+++ /main/src/com/joelapenna/foursquared/SearchVenuesActivity.java Thu Oct
14 00:13:03 2010
@@ -5,10 +5,8 @@
package com.joelapenna.foursquared;
import com.joelapenna.foursquare.Foursquare;
-import com.joelapenna.foursquare.error.FoursquareException;
import com.joelapenna.foursquare.types.Group;
import com.joelapenna.foursquare.types.Venue;
-import com.joelapenna.foursquared.error.LocationException;
import com.joelapenna.foursquared.location.LocationUtils;
import com.joelapenna.foursquared.providers.VenueQuerySuggestionsProvider;
import com.joelapenna.foursquared.util.Comparators;
@@ -47,7 +45,6 @@
import android.widget.TextView;
import android.widget.Toast;
-import java.io.IOException;
import java.util.Collections;
import java.util.Observable;
@@ -411,8 +408,7 @@
}
}
- public Group<Group<Venue>> search() throws FoursquareException,
LocationException,
- IOException {
+ public Group<Group<Venue>> search() throws Exception {
Foursquare foursquare = ((Foursquared)
getApplication()).getFoursquare();
Location location = ((Foursquared)
getApplication()).getLastKnownLocationOrThrow();
=======================================
--- /main/src/com/joelapenna/foursquared/TipsActivity.java Wed Sep 29
11:12:24 2010
+++ /main/src/com/joelapenna/foursquared/TipsActivity.java Thu Oct 14
00:13:03 2010
@@ -245,7 +245,7 @@
private void updateTip(Tip tip) {
mStateHolder.updateTip(tip);
- mListAdapter.notifyDataSetInvalidated();
+ mListAdapter.notifyDataSetChanged();
}
private void onStartTaskTips() {
=======================================
--- /main/src/com/joelapenna/foursquared/TodosActivity.java Sat Oct 2
08:36:28 2010
+++ /main/src/com/joelapenna/foursquared/TodosActivity.java Thu Oct 14
00:13:03 2010
@@ -267,7 +267,7 @@
private void updateTodo(Tip tip) {
mStateHolder.updateTodo(tip);
- mListAdapter.notifyDataSetInvalidated();
+ mListAdapter.notifyDataSetChanged();
}
private void onStartTaskTodos() {
=======================================
--- /main/src/com/joelapenna/foursquared/UserDetailsActivity.java Thu Sep
30 11:43:33 2010
+++ /main/src/com/joelapenna/foursquared/UserDetailsActivity.java Thu Oct
14 00:13:03 2010
@@ -508,13 +508,17 @@
try {
Bitmap bitmap =
BitmapFactory.decodeStream(mRrm.getInputStream(Uri.parse(user
.getPhoto())));
- ivPhoto.setImageBitmap(bitmap);
+ if (bitmap != null) {
+ ivPhoto.setImageBitmap(bitmap);
+ } else {
+
ivPhoto.setImageResource(UserUtils.getDrawableByGenderForUserThumbnail(user));
+ }
} catch (IOException e) {
- setUserPhotoMissing(ivPhoto, user);
+
ivPhoto.setImageResource(UserUtils.getDrawableByGenderForUserThumbnail(user));
}
} else {
+
ivPhoto.setImageResource(UserUtils.getDrawableByGenderForUserThumbnail(user));
mRrm.request(uriPhoto);
- setUserPhotoMissing(ivPhoto, user);
}
ivPhoto.postInvalidate();
@@ -546,14 +550,6 @@
}
});
}
-
- private void setUserPhotoMissing(ImageView ivPhoto, User user) {
- if (Foursquare.MALE.equals(user.getGender())) {
- ivPhoto.setImageResource(R.drawable.blank_boy);
- } else {
- ivPhoto.setImageResource(R.drawable.blank_girl);
- }
- }
@Override
public Object onRetainNonConfigurationInstance() {
=======================================
--- /main/src/com/joelapenna/foursquared/UserDetailsTipsActivity.java Wed
Sep 29 12:59:38 2010
+++ /main/src/com/joelapenna/foursquared/UserDetailsTipsActivity.java Thu
Oct 14 00:13:03 2010
@@ -260,7 +260,7 @@
private void updateTip(Tip tip) {
mStateHolder.updateTip(tip);
- mListAdapter.notifyDataSetInvalidated();
+ mListAdapter.notifyDataSetChanged();
}
private void onStartTaskTips() {
=======================================
--- /main/src/com/joelapenna/foursquared/VenueActivity.java Sat Oct 2
08:36:28 2010
+++ /main/src/com/joelapenna/foursquared/VenueActivity.java Thu Oct 14
00:13:03 2010
@@ -222,11 +222,16 @@
if (mRrm.exists(uriPhoto)) {
try {
Bitmap bitmap =
BitmapFactory.decodeStream(mRrm.getInputStream(Uri.parse(photoUrl)));
- ivMayorPhoto.setImageBitmap(bitmap);
- } catch (IOException e) {
+ if (bitmap != null) {
+ ivMayorPhoto.setImageBitmap(bitmap);
+ } else {
+
ivMayorPhoto.setImageResource(UserUtils.getDrawableByGenderForUserThumbnail(mayor.getUser()));
+ }
+ } catch (IOException e) {
+
ivMayorPhoto.setImageResource(UserUtils.getDrawableByGenderForUserThumbnail(mayor.getUser()));
}
} else {
-
ivMayorPhoto.setImageResource(UserUtils.getDrawableByGenderForUserThumbnail(mayor.getUser()));
+
ivMayorPhoto.setImageResource(UserUtils.getDrawableByGenderForUserThumbnail(mayor.getUser()));
ivMayorPhoto.setTag(photoUrl);
mRrm.request(uriPhoto);
}
=======================================
--- /main/src/com/joelapenna/foursquared/VenueTipsActivity.java Wed Sep 29
12:59:38 2010
+++ /main/src/com/joelapenna/foursquared/VenueTipsActivity.java Thu Oct 14
00:13:03 2010
@@ -173,7 +173,7 @@
private void updateTip(Tip tip, Todo todo) {
mStateHolder.updateTip(tip, todo);
- mListAdapter.notifyDataSetInvalidated();
+ mListAdapter.notifyDataSetChanged();
prepareResultIntent();
}
=======================================
--- /main/src/com/joelapenna/foursquared/VenueTodosActivity.java Thu Sep 30
13:00:32 2010
+++ /main/src/com/joelapenna/foursquared/VenueTodosActivity.java Thu Oct 14
00:13:03 2010
@@ -145,7 +145,7 @@
// If there are no more todos, there's nothing left to.. do.
prepareResultIntent();
if (mStateHolder.getVenue().getHasTodo()) {
- mListAdapter.notifyDataSetInvalidated();
+ mListAdapter.notifyDataSetChanged();
} else {
finish();
}
=======================================
--- /main/src/com/joelapenna/foursquared/preferences/Preferences.java Thu
Sep 23 21:08:59 2010
+++ /main/src/com/joelapenna/foursquared/preferences/Preferences.java Thu
Oct 14 00:13:03 2010
@@ -5,8 +5,6 @@
package com.joelapenna.foursquared.preferences;
import com.joelapenna.foursquare.Foursquare;
-import com.joelapenna.foursquare.error.FoursquareCredentialsException;
-import com.joelapenna.foursquare.error.FoursquareException;
import com.joelapenna.foursquare.types.City;
import com.joelapenna.foursquare.types.User;
import com.joelapenna.foursquared.FoursquaredSettings;
@@ -19,7 +17,6 @@
import android.content.res.Resources;
import android.util.Log;
-import java.io.IOException;
import java.util.UUID;
/**
@@ -138,8 +135,7 @@
}
public static boolean loginUser(Foursquare foursquare, String login,
String password,
- Foursquare.Location location, Editor editor) throws
FoursquareCredentialsException,
- FoursquareException, IOException {
+ Foursquare.Location location, Editor editor) throws Exception {
if (DEBUG) Log.d(Preferences.TAG, "Trying to log in.");
foursquare.setCredentials(login, password);
=======================================
---
/main/src/com/joelapenna/foursquared/providers/GlobalSearchProvider.java
Tue Feb 2 02:55:05 2010
+++
/main/src/com/joelapenna/foursquared/providers/GlobalSearchProvider.java
Thu Oct 14 00:13:03 2010
@@ -108,7 +108,11 @@
} catch (IOException e) {
if (DEBUG) Log.w(TAG, "Could not get venue list for
query: " + query, e);
return cursor;
- }
+ } catch (Exception e) {
+ if (DEBUG) Log.w(TAG, "Could not get venue list for
query: " + query, e);
+ return cursor;
+ }
+
for (int groupIndex = 0; groupIndex < venueGroups.size();
groupIndex++) {
Group<Venue> venueGroup = venueGroups.get(groupIndex);
@@ -152,7 +156,11 @@
} catch (IOException e) {
if (DEBUG) Log.w(TAG, "Could not get venue details for
venue ID: " + query, e);
return cursor;
- }
+ } catch (Exception e) {
+ if (DEBUG) Log.w(TAG, "Could not get venue list for
query: " + query, e);
+ return cursor;
+ }
+
if (DEBUG) {
Log.d(TAG, "Updated venue details: " + venue.getName()
+ " ("
+ venue.getAddress() + ")");
=======================================
--- /main/src/com/joelapenna/foursquared/util/BaseDiskCache.java Mon Sep 27
12:49:27 2010
+++ /main/src/com/joelapenna/foursquared/util/BaseDiskCache.java Thu Oct 14
00:13:03 2010
@@ -17,6 +17,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
+import java.util.HashSet;
+import java.util.Set;
/**
* @author Joe LaPenna (j...@joelapenna.com)
@@ -29,8 +31,10 @@
private static final int MIN_FILE_SIZE_IN_BYTES = 100;
private File mStorageDirectory;
+
BaseDiskCache(String dirPath, String name) {
+
// Lets make sure we can actually cache things!
File baseDirectory = new
File(Environment.getExternalStorageDirectory(), dirPath);
File storageDirectory = new File(baseDirectory, name);
=======================================
--- /main/src/com/joelapenna/foursquared/util/RemoteResourceFetcher.java
Sun Aug 23 18:49:41 2009
+++ /main/src/com/joelapenna/foursquared/util/RemoteResourceFetcher.java
Thu Oct 14 00:13:03 2010
@@ -1,180 +1,163 @@
/**
- * Copyright 2009 Joe LaPenna
+ * Copyright 2010 Mark Wyszomierski
*/
-
package com.joelapenna.foursquared.util;
-import com.joelapenna.foursquared.FoursquaredSettings;
-
-import org.apache.http.Header;
-import org.apache.http.HttpEntity;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
-import org.apache.http.client.methods.HttpGet;
-import org.apache.http.conn.ClientConnectionManager;
-import org.apache.http.conn.scheme.PlainSocketFactory;
-import org.apache.http.conn.scheme.Scheme;
-import org.apache.http.conn.scheme.SchemeRegistry;
-import org.apache.http.conn.scheme.SocketFactory;
-import org.apache.http.impl.client.DefaultHttpClient;
-import org.apache.http.impl.conn.tsccm.ThreadSafeClientConnManager;
-import org.apache.http.params.BasicHttpParams;
-import org.apache.http.params.HttpConnectionParams;
-import org.apache.http.params.HttpParams;
-
import android.net.Uri;
+import android.os.Handler;
+import android.os.Handler.Callback;
+import android.os.Message;
+import android.os.Process;
import android.util.Log;
-import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
+import java.net.URLConnection;
+import java.util.ArrayList;
+import java.util.LinkedHashSet;
+import java.util.List;
import java.util.Observable;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ExecutorService;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.zip.GZIPInputStream;
+import java.util.Set;
+import java.util.concurrent.atomic.AtomicBoolean;
+
/**
- * @author Joe LaPenna (j...@joelapenna.com)
+ * Acts as a per-activity image download manager. This is for testing only.
+ * The global resource fetcher's requests live between activities. In most
+ * cases we want to stop all requests as soon as an activity is completed.
+ *
+ * Create an instance of this fetcher as part of an activity's state
holder.
+ * Add request urls to it as usual. When the activity is finishing, just
+ * call shutdown();
+ *
+ * We are limited to a single download thread, and we set its process
+ * priority to the lowest possible. Therefore image downloads won't
+ * consume much cpu while the user is interacting with the UI (which will
+ * mostly end up being the user scrolling lists).
+ *
+ * @date October 12, 2010
+ * @author Mark Wyszomierski (mar...@gmail.com)
*/
-class RemoteResourceFetcher extends Observable {
- public static final String TAG = "RemoteResourceFetcher";
- public static final boolean DEBUG = FoursquaredSettings.DEBUG;
-
- private DiskCache mResourceCache;
- private ExecutorService mExecutor;
-
- private HttpClient mHttpClient;
-
- private ConcurrentHashMap<Request, Callable<Request>>
mActiveRequestsMap = new ConcurrentHashMap<Request, Callable<Request>>();
-
+public class RemoteResourceFetcher extends Observable {
+
+ private static final String TAG = "RemoteResourceFetcher-NEW";
+ private static final int MSG = 500;
+
+ private Object mGuard;
+ private Set<String> mRequests;
+ private AtomicBoolean mRun;
+ private WorkerThread mThread;
+ private DiskCache mDiskCache;
+
+
+ public RemoteResourceFetcher(String cacheName) {
+ this(new BaseDiskCache("foursquare", cacheName));
+ }
+
public RemoteResourceFetcher(DiskCache cache) {
- mResourceCache = cache;
- mHttpClient = createHttpClient();
- mExecutor = Executors.newCachedThreadPool();
+ mGuard = new Object();
+ mDiskCache = cache;
+ mRequests = new LinkedHashSet<String>();
+ mRun = new AtomicBoolean(true);
+ mThread = new WorkerThread();
+ mThread.start();
}
- @Override
- public void notifyObservers(Object data) {
- setChanged();
- super.notifyObservers(data);
- }
-
- public Future<Request> fetch(Uri uri, String hash) {
- Request request = new Request(uri, hash);
- synchronized (mActiveRequestsMap) {
- Callable<Request> fetcher = newRequestCall(request);
- if (mActiveRequestsMap.putIfAbsent(request, fetcher) == null) {
- if (DEBUG) Log.d(TAG, "issuing new request for: " + uri);
- return mExecutor.submit(fetcher);
- } else {
- if (DEBUG) Log.d(TAG, "Already have a pending request
for: " + uri);
+ public void fetch(Uri uri, String hash) {
+ String url = uri.toString();
+ synchronized (mGuard) {
+ if (!mRequests.contains(url)) {
+ mRequests.add(url);
+ mGuard.notify();
}
}
- return null;
- }
-
+ }
+
public void shutdown() {
- mExecutor.shutdownNow();
- }
-
- private Callable<Request> newRequestCall(final Request request) {
- return new Callable<Request>() {
- public Request call() {
- try {
- if (DEBUG) Log.d(TAG, "Requesting: " + request.uri);
- HttpGet httpGet = new HttpGet(request.uri.toString());
- httpGet.addHeader("Accept-Encoding", "gzip");
- HttpResponse response = mHttpClient.execute(httpGet);
- HttpEntity entity = response.getEntity();
- InputStream is = getUngzippedContent(entity);
- mResourceCache.store(request.hash, is);
- if (DEBUG) Log.d(TAG, "Request successful: " +
request.uri);
- } catch (IOException e) {
- if (DEBUG) Log.d(TAG, "IOException", e);
- } finally {
- if (DEBUG) Log.d(TAG, "Request finished: " +
request.uri);
- mActiveRequestsMap.remove(request);
- notifyObservers(request.uri);
- }
- return request;
- }
- };
- }
-
+ mRun.set(false);
+ synchronized (mGuard) {
+ mGuard.notify();
+ }
+ mHandler.removeMessages(MSG);
+ }
+
/**
- * Gets the input stream from a response entity. If the entity is
gzipped then this will get a
- * stream over the uncompressed data.
- *
- * @param entity the entity whose content should be read
- * @return the input stream to read from
- * @throws IOException
+ * Probably makes sense to call this whenever an activity is
finishing, we probably
+ * don't care about any of those requests, even if some may be useful
in the next
+ * activity to be shown.
*/
- public static InputStream getUngzippedContent(HttpEntity entity)
throws IOException {
- InputStream responseStream = entity.getContent();
- if (responseStream == null) {
- return responseStream;
- }
- Header header = entity.getContentEncoding();
- if (header == null) {
- return responseStream;
- }
- String contentEncoding = header.getValue();
- if (contentEncoding == null) {
- return responseStream;
- }
- if (contentEncoding.contains("gzip")) {
- responseStream = new GZIPInputStream(responseStream);
- }
- return responseStream;
- }
-
- /**
- * Create a thread-safe client. This client does not do redirecting,
to allow us to capture
- * correct "error" codes.
- *
- * @return HttpClient
- */
- public static final DefaultHttpClient createHttpClient() {
- // Shamelessly cribbed from AndroidHttpClient
- HttpParams params = new BasicHttpParams();
-
- // Turn off stale checking. Our connections break all the time
anyway,
- // and it's not worth it to pay the penalty of checking every time.
- HttpConnectionParams.setStaleCheckingEnabled(params, false);
-
- // Default connection and socket timeout of 10 seconds. Tweak to
taste.
- HttpConnectionParams.setConnectionTimeout(params, 10 * 1000);
- HttpConnectionParams.setSoTimeout(params, 10 * 1000);
- HttpConnectionParams.setSocketBufferSize(params, 8192);
-
- // Sets up the http part of the service.
- final SchemeRegistry supportedSchemes = new SchemeRegistry();
-
- // Register the "http" protocol scheme, it is required
- // by the default operator to look up socket factories.
- final SocketFactory sf = PlainSocketFactory.getSocketFactory();
- supportedSchemes.register(new Scheme("http", sf, 80));
-
- final ClientConnectionManager ccm = new
ThreadSafeClientConnManager(params,
- supportedSchemes);
- return new DefaultHttpClient(ccm, params);
- }
-
- private static class Request {
- Uri uri;
- String hash;
-
- public Request(Uri requestUri, String requestHash) {
- uri = requestUri;
- hash = requestHash;
- }
-
+ public void clearRequests() {
+ synchronized (mGuard) {
+ mRequests.clear();
+ }
+ }
+
+ private class WorkerThread extends Thread {
+ public WorkerThread() {
+ Log.e(TAG, "Worker thread started.");
+ }
+
+ @Override
+ public void run() {
+ Process.setThreadPriority(Process.THREAD_PRIORITY_LOWEST);
+
+ while (mRun.get()) {
+ List<String> requests = new ArrayList<String>();
+ synchronized (mGuard) {
+ if (mRequests.size() > 0) {
+ // Copy over values, get out of guard.
+ for (String it : mRequests) {
+ requests.add(it);
+ }
+
+ // Clear out current requests while we're guarded.
+ mRequests.clear();
+ } else {
+ Log.e(TAG, "Worker thread waiting for more jobs
please...");
+ try {
+ mGuard.wait();
+ } catch (InterruptedException ex) {
+ }
+ }
+ }
+
+ // Service any requests we had, do them in reverse order.
+ for (int i = requests.size()-1; i > -1; i--) {
+ // Store is being done in the context of this
background thread,
+ // so make sure that mDiskCache.store() is thread-safe.
+ String url = requests.get(i);
+ mDiskCache.store(Uri.encode(url), downloadImage(url));
+ mHandler.sendMessage(mHandler.obtainMessage(MSG, url));
+ }
+ }
+ }
+ };
+
+ private InputStream downloadImage(String url) {
+ try {
+ URLConnection conn = new URL(url).openConnection();
+ conn.setConnectTimeout(7 * 1000);
+ conn.setReadTimeout(7 * 1000);
+ conn.connect();
+ return conn.getInputStream();
+ } catch (Exception ex) {
+ Log.e(TAG, "Error getting bitmap at url [" + url + "].", ex);
+ }
+
+ return null;
+ }
+
+ private Handler mHandler = new Handler(new Callback() {
@Override
- public int hashCode() {
- return hash.hashCode();
- }
- }
-
-}
+ public boolean handleMessage(Message msg) {
+ notifyObservers(msg.obj);
+ return true;
+ }
+ });
+
+ @Override
+ public void notifyObservers(Object data) {
+ setChanged();
+ super.notifyObservers(data);
+ }
+}
=======================================
--- /main/src/com/joelapenna/foursquared/util/RemoteResourceManager.java
Mon Jul 12 14:18:23 2010
+++ /main/src/com/joelapenna/foursquared/util/RemoteResourceManager.java
Thu Oct 14 00:13:03 2010
@@ -27,7 +27,7 @@
private FetcherObserver mFetcherObserver = new FetcherObserver();
public RemoteResourceManager(String cacheName) {
- this(new BaseDiskCache("foursquare", cacheName));
+ this(new NewDiskCache("foursquare", cacheName));
}
public RemoteResourceManager(DiskCache cache) {
@@ -106,7 +106,6 @@
* Relay the observed download to this controlling class.
*/
private class FetcherObserver implements Observer {
-
@Override
public void update(Observable observable, Object data) {
setChanged();
=======================================
--- /main/src/com/joelapenna/foursquared/widget/BaseGroupAdapter.java Wed
Sep 15 09:23:40 2010
+++ /main/src/com/joelapenna/foursquared/widget/BaseGroupAdapter.java Thu
Oct 14 00:13:03 2010
@@ -4,11 +4,14 @@
package com.joelapenna.foursquared.widget;
+import com.joelapenna.foursquare.types.FoursquareType;
+import com.joelapenna.foursquare.types.Group;
+
import android.content.Context;
import android.widget.BaseAdapter;
-import com.joelapenna.foursquare.types.FoursquareType;
-import com.joelapenna.foursquare.types.Group;
+import java.util.HashSet;
+import java.util.Set;
/**
* @author Joe LaPenna (j...@joelapenna.com)
@@ -16,6 +19,7 @@
abstract class BaseGroupAdapter<T extends FoursquareType> extends
BaseAdapter {
Group<T> group = null;
+ Set<String> mRequestedUrls = new HashSet<String>();
public BaseGroupAdapter(Context context) {
}
@@ -47,6 +51,14 @@
public void setGroup(Group<T> g) {
group = g;
- notifyDataSetInvalidated();
+ notifyDataSetChanged();
+ }
+
+ public boolean getDidRequestUrl(String url) {
+ return mRequestedUrls.contains(url);
+ }
+
+ public void addRequestedUrl(String url) {
+ mRequestedUrls.add(url);
}
}
=======================================
--- /main/src/com/joelapenna/foursquared/widget/CheckinListAdapter.java Thu
Sep 30 11:51:02 2010
+++ /main/src/com/joelapenna/foursquared/widget/CheckinListAdapter.java Thu
Oct 14 00:13:03 2010
@@ -4,7 +4,6 @@
package com.joelapenna.foursquared.widget;
-import com.joelapenna.foursquare.Foursquare;
import com.joelapenna.foursquare.types.Checkin;
import com.joelapenna.foursquare.types.Group;
import com.joelapenna.foursquare.types.User;
@@ -13,6 +12,7 @@
import com.joelapenna.foursquared.util.RemoteResourceManager;
import com.joelapenna.foursquared.util.StringFormatters;
import com.joelapenna.foursquared.util.UiUtil;
+import com.joelapenna.foursquared.util.UserUtils;
import android.content.Context;
import android.graphics.Bitmap;
@@ -29,6 +29,7 @@
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
+import java.util.Map;
import java.util.Observable;
import java.util.Observer;
@@ -46,7 +47,7 @@
private RemoteResourceManager mRrm;
private RemoteResourceManagerObserver mResourcesObserver;
private Handler mHandler = new Handler();
- private HashMap<String, String> mCachedTimestamps;
+ private Map<String, String> mCachedTimestamps;
private boolean mIsSdk3;
@@ -100,12 +101,17 @@
try {
Bitmap bitmap =
BitmapFactory.decodeStream(mRrm.getInputStream(photoUri));
- holder.photo.setImageBitmap(bitmap);
- } catch (IOException e) {
- if (Foursquare.MALE.equals(user.getGender())) {
- holder.photo.setImageResource(R.drawable.blank_boy);
+ if (bitmap != null) {
+ holder.photo.setImageBitmap(bitmap);
} else {
- holder.photo.setImageResource(R.drawable.blank_girl);
+
holder.photo.setImageResource(UserUtils.getDrawableByGenderForUserThumbnail(user));
+ }
+ } catch (IOException e) {
+
holder.photo.setImageResource(UserUtils.getDrawableByGenderForUserThumbnail(user));
+
+ if (!getDidRequestUrl(user.getPhoto())) {
+ addRequestedUrl(user.getPhoto());
+ mRrm.request(Uri.parse(user.getPhoto()));
}
}
@@ -138,11 +144,6 @@
CheckinTimestampSort timestamps = new CheckinTimestampSort();
for (Checkin it : g) {
- Uri photoUri = Uri.parse(it.getUser().getPhoto());
- if (!mRrm.exists(photoUri)) {
- mRrm.request(photoUri);
- }
-
Date date = new Date(it.getCreated());
if (date.after(timestamps.getBoundaryRecent())) {
mCachedTimestamps.put(it.getId(),
=======================================
---
/main/src/com/joelapenna/foursquared/widget/FriendActionableListAdapter.java
Thu Sep 30 11:51:02 2010
+++
/main/src/com/joelapenna/foursquared/widget/FriendActionableListAdapter.java
Thu Oct 14 00:13:03 2010
@@ -4,8 +4,6 @@
package com.joelapenna.foursquared.widget;
-import com.joelapenna.foursquare.Foursquare;
-import com.joelapenna.foursquare.types.Group;
import com.joelapenna.foursquare.types.User;
import com.joelapenna.foursquared.R;
import com.joelapenna.foursquared.util.RemoteResourceManager;
@@ -41,7 +39,6 @@
private RemoteResourceManager mRrm;
private RemoteResourceManagerObserver mResourcesObserver;
private Handler mHandler = new Handler();
- private int mLoadedPhotoIndex;
public FriendActionableListAdapter(Context context,
ButtonRowClickHandler clickListener,
@@ -52,7 +49,6 @@
mClickListener = clickListener;
mRrm = rrm;
mResourcesObserver = new RemoteResourceManagerObserver();
- mLoadedPhotoIndex = 0;
mRrm.addObserver(mResourcesObserver);
}
@@ -64,7 +60,6 @@
}
public void removeObserver() {
- mHandler.removeCallbacks(mRunnableLoadPhotos);
mHandler.removeCallbacks(mUpdatePhotos);
mRrm.deleteObserver(mResourcesObserver);
}
@@ -95,12 +90,17 @@
final Uri photoUri = Uri.parse(user.getPhoto());
try {
Bitmap bitmap =
BitmapFactory.decodeStream(mRrm.getInputStream(photoUri));
- holder.photo.setImageBitmap(bitmap);
- } catch (IOException e) {
- if (Foursquare.MALE.equals(user.getGender())) {
- holder.photo.setImageResource(R.drawable.blank_boy);
+ if (bitmap != null) {
+ holder.photo.setImageBitmap(bitmap);
} else {
- holder.photo.setImageResource(R.drawable.blank_girl);
+
holder.photo.setImageResource(UserUtils.getDrawableByGenderForUserThumbnail(user));
+ }
+ } catch (IOException e) {
+
holder.photo.setImageResource(UserUtils.getDrawableByGenderForUserThumbnail(user));
+
+ if (!getDidRequestUrl(user.getPhoto())) {
+ addRequestedUrl(user.getPhoto());
+ mRrm.request(Uri.parse(user.getPhoto()));
}
}
@@ -142,15 +142,7 @@
public void removeItem(int position) throws IndexOutOfBoundsException {
group.remove(position);
- notifyDataSetInvalidated();
- }
-
- @Override
- public void setGroup(Group<User> g) {
- super.setGroup(g);
- mLoadedPhotoIndex = 0;
-
- mHandler.postDelayed(mRunnableLoadPhotos, 10L);
+ notifyDataSetChanged();
}
private class RemoteResourceManagerObserver implements Observer {
@@ -166,20 +158,6 @@
notifyDataSetChanged();
}
};
-
- private Runnable mRunnableLoadPhotos = new Runnable() {
- @Override
- public void run() {
- if (mLoadedPhotoIndex < getCount()) {
- User user = (User)getItem(mLoadedPhotoIndex++);
- Uri photoUri = Uri.parse(user.getPhoto());
- if (!mRrm.exists(photoUri)) {
- mRrm.request(photoUri);
- }
- mHandler.postDelayed(mRunnableLoadPhotos, 200L);
- }
- }
- };
static class ViewHolder {
ImageView photo;
=======================================
--- /main/src/com/joelapenna/foursquared/widget/FriendListAdapter.java Thu
Sep 30 11:43:33 2010
+++ /main/src/com/joelapenna/foursquared/widget/FriendListAdapter.java Thu
Oct 14 00:13:03 2010
@@ -4,10 +4,10 @@
package com.joelapenna.foursquared.widget;
-import com.joelapenna.foursquare.Foursquare;
import com.joelapenna.foursquare.types.User;
import com.joelapenna.foursquared.R;
import com.joelapenna.foursquared.util.RemoteResourceManager;
+import com.joelapenna.foursquared.util.UserUtils;
import android.content.Context;
import android.graphics.Bitmap;
@@ -21,10 +21,8 @@
import android.widget.TextView;
import java.io.IOException;
-import java.util.HashSet;
import java.util.Observable;
import java.util.Observer;
-import java.util.Set;
/**
* @date March 8, 2010
@@ -39,7 +37,6 @@
private RemoteResourceManagerObserver mResourcesObserver;
private Handler mHandler = new Handler();
- private Set<String> mLaunchedPhotoFetches;
public FriendListAdapter(Context context, RemoteResourceManager rrm) {
super(context);
@@ -47,7 +44,6 @@
mLayoutToInflate = R.layout.friend_list_item;
mRrm = rrm;
mResourcesObserver = new RemoteResourceManagerObserver();
- mLaunchedPhotoFetches = new HashSet<String>();
mRrm.addObserver(mResourcesObserver);
}
@@ -92,17 +88,17 @@
Uri photoUri = Uri.parse(user.getPhoto());
try {
Bitmap bitmap =
BitmapFactory.decodeStream(mRrm.getInputStream(photoUri));
- holder.photo.setImageBitmap(bitmap);
- } catch (IOException e) {
- if (Foursquare.MALE.equals(user.getGender())) {
- holder.photo.setImageResource(R.drawable.blank_boy);
+ if (bitmap != null) {
+ holder.photo.setImageBitmap(bitmap);
} else {
- holder.photo.setImageResource(R.drawable.blank_girl);
- }
-
- if (!mLaunchedPhotoFetches.contains(user.getId())) {
- mLaunchedPhotoFetches.add(user.getId());
- mRrm.request(photoUri);
+
holder.photo.setImageResource(UserUtils.getDrawableByGenderForUserThumbnail(user));
+ }
+ } catch (IOException e) {
+
holder.photo.setImageResource(UserUtils.getDrawableByGenderForUserThumbnail(user));
+
+ if (!getDidRequestUrl(user.getPhoto())) {
+ addRequestedUrl(user.getPhoto());
+ mRrm.request(Uri.parse(user.getPhoto()));
}
}
@@ -111,10 +107,10 @@
return convertView;
}
-
+
public void removeItem(int position) throws IndexOutOfBoundsException {
group.remove(position);
- notifyDataSetInvalidated();
+ notifyDataSetChanged();
}
private class RemoteResourceManagerObserver implements Observer {
=======================================
--- /main/src/com/joelapenna/foursquared/widget/FriendRequestsAdapter.java
Tue Mar 23 17:57:24 2010
+++ /main/src/com/joelapenna/foursquared/widget/FriendRequestsAdapter.java
Thu Oct 14 00:13:03 2010
@@ -4,23 +4,20 @@
package com.joelapenna.foursquared.widget;
-import com.joelapenna.foursquare.Foursquare;
-import com.joelapenna.foursquare.types.Group;
import com.joelapenna.foursquare.types.User;
-import com.joelapenna.foursquared.FoursquaredSettings;
import com.joelapenna.foursquared.R;
import com.joelapenna.foursquared.util.RemoteResourceManager;
+import com.joelapenna.foursquared.util.UserUtils;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Handler;
-import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
-import android.view.ViewGroup;
import android.view.View.OnClickListener;
+import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
@@ -37,16 +34,12 @@
public class FriendRequestsAdapter extends BaseGroupAdapter<User>
implements ObservableAdapter {
- private static final String TAG = "FriendRequestsAdapter";
- private static final boolean DEBUG = FoursquaredSettings.DEBUG;
-
private LayoutInflater mInflater;
private int mLayoutToInflate;
private ButtonRowClickHandler mClickListener;
private RemoteResourceManager mRrm;
private RemoteResourceManagerObserver mResourcesObserver;
private Handler mHandler = new Handler();
- private int mLoadedPhotoIndex;
public FriendRequestsAdapter(Context context, ButtonRowClickHandler
clickListener,
@@ -57,7 +50,6 @@
mClickListener = clickListener;
mRrm = rrm;
mResourcesObserver = new RemoteResourceManagerObserver();
- mLoadedPhotoIndex = 0;
mRrm.addObserver(mResourcesObserver);
}
@@ -69,7 +61,7 @@
}
public void removeObserver() {
- mHandler.removeCallbacks(mRunnableLoadPhotos);
+ mHandler.removeCallbacks(mRunnableUpdatePhotos);
mRrm.deleteObserver(mResourcesObserver);
}
@@ -110,12 +102,17 @@
final Uri photoUri = Uri.parse(user.getPhoto());
try {
Bitmap bitmap =
BitmapFactory.decodeStream(mRrm.getInputStream(photoUri));
- holder.photo.setImageBitmap(bitmap);
- } catch (IOException e) {
- if (Foursquare.MALE.equals(user.getGender())) {
- holder.photo.setImageResource(R.drawable.blank_boy);
+ if (bitmap != null) {
+ holder.photo.setImageBitmap(bitmap);
} else {
- holder.photo.setImageResource(R.drawable.blank_girl);
+
holder.photo.setImageResource(UserUtils.getDrawableByGenderForUserThumbnail(user));
+ }
+ } catch (IOException e) {
+
holder.photo.setImageResource(UserUtils.getDrawableByGenderForUserThumbnail(user));
+
+ if (!getDidRequestUrl(user.getPhoto())) {
+ addRequestedUrl(user.getPhoto());
+ mRrm.request(Uri.parse(user.getPhoto()));
}
}
@@ -156,41 +153,20 @@
public void removeItem(int position) throws IndexOutOfBoundsException {
group.remove(position);
- notifyDataSetInvalidated();
- }
-
- @Override
- public void setGroup(Group<User> g) {
- super.setGroup(g);
- mLoadedPhotoIndex = 0;
-
- mHandler.postDelayed(mRunnableLoadPhotos, 10L);
+ notifyDataSetChanged();
}
private class RemoteResourceManagerObserver implements Observer {
@Override
public void update(Observable observable, Object data) {
- if (DEBUG) Log.d(TAG, "Fetcher got: " + data);
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- notifyDataSetChanged();
- }
- });
+ mHandler.post(mRunnableUpdatePhotos);
}
}
- private Runnable mRunnableLoadPhotos = new Runnable() {
+ private Runnable mRunnableUpdatePhotos = new Runnable() {
@Override
public void run() {
- if (mLoadedPhotoIndex < getCount()) {
- User user = (User)getItem(mLoadedPhotoIndex++);
- Uri photoUri = Uri.parse(user.getPhoto());
- if (!mRrm.exists(photoUri)) {
- mRrm.request(photoUri);
- }
- mHandler.postDelayed(mRunnableLoadPhotos, 200L);
- }
+ notifyDataSetChanged();
}
};
=======================================
---
/main/src/com/joelapenna/foursquared/widget/FriendSearchAddFriendAdapter.java
Wed Sep 15 09:23:40 2010
+++
/main/src/com/joelapenna/foursquared/widget/FriendSearchAddFriendAdapter.java
Thu Oct 14 00:13:03 2010
@@ -4,16 +4,16 @@
package com.joelapenna.foursquared.widget;
-import java.io.IOException;
-import java.util.Observable;
-import java.util.Observer;
+import com.joelapenna.foursquare.types.User;
+import com.joelapenna.foursquared.R;
+import com.joelapenna.foursquared.util.RemoteResourceManager;
+import com.joelapenna.foursquared.util.UserUtils;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Handler;
-import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
@@ -23,12 +23,9 @@
import android.widget.LinearLayout;
import android.widget.TextView;
-import com.joelapenna.foursquare.Foursquare;
-import com.joelapenna.foursquare.types.Group;
-import com.joelapenna.foursquare.types.User;
-import com.joelapenna.foursquared.FoursquaredSettings;
-import com.joelapenna.foursquared.R;
-import com.joelapenna.foursquared.util.RemoteResourceManager;
+import java.io.IOException;
+import java.util.Observable;
+import java.util.Observer;
/**
* @date February 14, 2010
@@ -37,9 +34,6 @@
public class FriendSearchAddFriendAdapter extends BaseGroupAdapter<User>
implements
ObservableAdapter {
- private static final String TAG = "";
- private static final boolean DEBUG = FoursquaredSettings.DEBUG;
-
private LayoutInflater mInflater;
private int mLayoutToInflate;
private ButtonRowClickHandler mClickListener;
@@ -60,6 +54,7 @@
}
public void removeObserver() {
+ mHandler.removeCallbacks(mRunnableUpdatePhotos);
mRrm.deleteObserver(mResourcesObserver);
}
@@ -105,12 +100,17 @@
final Uri photoUri = Uri.parse(user.getPhoto());
try {
Bitmap bitmap =
BitmapFactory.decodeStream(mRrm.getInputStream(photoUri));
- holder.photo.setImageBitmap(bitmap);
- } catch (IOException e) {
- if (Foursquare.MALE.equals(user.getGender())) {
- holder.photo.setImageResource(R.drawable.blank_boy);
+ if (bitmap != null) {
+ holder.photo.setImageBitmap(bitmap);
} else {
- holder.photo.setImageResource(R.drawable.blank_girl);
+
holder.photo.setImageResource(UserUtils.getDrawableByGenderForUserThumbnail(user));
+ }
+ } catch (IOException e) {
+
holder.photo.setImageResource(UserUtils.getDrawableByGenderForUserThumbnail(user));
+
+ if (!getDidRequestUrl(user.getPhoto())) {
+ addRequestedUrl(user.getPhoto());
+ mRrm.request(Uri.parse(user.getPhoto()));
}
}
@@ -142,30 +142,20 @@
public void removeItem(int position) throws IndexOutOfBoundsException {
group.remove(position);
- notifyDataSetInvalidated();
+ notifyDataSetChanged();
}
- @Override
- public void setGroup(Group<User> g) {
- super.setGroup(g);
- for (int i = 0; i < g.size(); i++) {
- Uri photoUri = Uri.parse(g.get(i).getPhoto());
- if (!mRrm.exists(photoUri)) {
- mRrm.request(photoUri);
- }
- }
- }
-
+ private Runnable mRunnableUpdatePhotos = new Runnable() {
+ @Override
+ public void run() {
+ notifyDataSetChanged();
+ }
+ };
+
private class RemoteResourceManagerObserver implements Observer {
@Override
public void update(Observable observable, Object data) {
- if (DEBUG) Log.d(TAG, "Fetcher got: " + data);
- mHandler.post(new Runnable() {
- @Override
- public void run() {
- notifyDataSetChanged();
- }
- });
+ mHandler.post(mRunnableUpdatePhotos);
}
}
=======================================
---
/main/src/com/joelapenna/foursquared/widget/FriendSearchInviteNonFoursquareUserAdapter.java
Thu May 6 16:56:46 2010
+++
/main/src/com/joelapenna/foursquared/widget/FriendSearchInviteNonFoursquareUserAdapter.java
Thu Oct 14 00:13:03 2010
@@ -114,7 +114,7 @@
public void removeItem(int position) throws IndexOutOfBoundsException {
mEmailsAndNames.remove(position);
- notifyDataSetInvalidated();
+ notifyDataSetChanged();
}
public void setContacts(List<ContactSimple> contacts) {
=======================================
--- /main/src/com/joelapenna/foursquared/widget/PhotoStrip.java Mon Oct 11
11:30:21 2010
+++ /main/src/com/joelapenna/foursquared/widget/PhotoStrip.java Thu Oct 14
00:13:03 2010
@@ -164,8 +164,10 @@
if (mRrm.exists(uriPhoto)) {
try {
Bitmap bitmap =
BitmapFactory.decodeStream(mRrm.getInputStream(Uri.parse(photoUrl)));
- mCachedBitmaps.put(photoUrl, bitmap);
- return bitmap;
+ if (bitmap != null) {
+ mCachedBitmaps.put(photoUrl, bitmap);
+ return bitmap;
+ }
} catch (IOException e) {
}
} else {
=======================================
--- /main/src/com/joelapenna/foursquared/widget/SeparatedListAdapter.java
Mon Mar 8 14:51:42 2010
+++ /main/src/com/joelapenna/foursquared/widget/SeparatedListAdapter.java
Thu Oct 14 00:13:03 2010
@@ -56,7 +56,7 @@
public void clear() {
headers.clear();
sections.clear();
- notifyDataSetInvalidated();
+ notifyDataSetChanged();
}
@Override
=======================================
--- /main/src/com/joelapenna/foursquared/widget/TipsListAdapter.java Thu
Sep 30 12:20:32 2010
+++ /main/src/com/joelapenna/foursquared/widget/TipsListAdapter.java Thu
Oct 14 00:13:03 2010
@@ -4,7 +4,6 @@
package com.joelapenna.foursquared.widget;
-import com.joelapenna.foursquare.Foursquare;
import com.joelapenna.foursquare.types.Category;
import com.joelapenna.foursquare.types.Group;
import com.joelapenna.foursquare.types.Tip;
@@ -14,6 +13,7 @@
import com.joelapenna.foursquared.util.RemoteResourceManager;
import com.joelapenna.foursquared.util.StringFormatters;
import com.joelapenna.foursquared.util.TipUtils;
+import com.joelapenna.foursquared.util.UserUtils;
import android.content.Context;
import android.content.res.Resources;
@@ -46,7 +46,6 @@
private RemoteResourceManager mRrm;
private RemoteResourceManagerObserver mResourcesObserver;
private Handler mHandler = new Handler();
- private int mLoadedPhotoIndex;
private boolean mDisplayTipVenueTitles;
private Map<String, String> mCachedTimestamps;
@@ -58,7 +57,6 @@
mResources = context.getResources();
mRrm = rrm;
mResourcesObserver = new RemoteResourceManagerObserver();
- mLoadedPhotoIndex = 0;
mDisplayTipVenueTitles = true;
mCachedTimestamps = new HashMap<String, String>();
@@ -67,7 +65,6 @@
public void removeObserver() {
mHandler.removeCallbacks(mUpdatePhotos);
- mHandler.removeCallbacks(mRunnableLoadPhotos);
mRrm.deleteObserver(mResourcesObserver);
}
@@ -96,16 +93,12 @@
holder.title = (TextView)
convertView.findViewById(R.id.tvTitle);
holder.body = (TextView) convertView.findViewById(R.id.tvBody);
holder.dateAndAuthor = (TextView)
convertView.findViewById(R.id.tvDateAndAuthor);
- //holder.friendCountTodoImg = (ImageView)
convertView.findViewById(R.id.ivFriendCountAsTodo);
- //holder.friendCountTodo = (TextView)
convertView.findViewById(R.id.tvFriendCountAsTodo);
holder.friendCountCompletedImg = (ImageView)
convertView.findViewById(R.id.ivFriendCountCompleted);
holder.friendCountCompleted = (TextView)
convertView.findViewById(R.id.tvFriendCountCompleted);
holder.corner = (ImageView)
convertView.findViewById(R.id.ivTipCorner);
convertView.setTag(holder);
} else {
- // Get the ViewHolder back to get fast access to the TextView
- // and the ImageView.
holder = (ViewHolder) convertView.getTag();
}
@@ -115,12 +108,17 @@
Uri photoUri = Uri.parse(user.getPhoto());
try {
Bitmap bitmap =
BitmapFactory.decodeStream(mRrm.getInputStream(photoUri));
- holder.photo.setImageBitmap(bitmap);
- } catch (IOException e) {
- if (Foursquare.MALE.equals(user.getGender())) {
- holder.photo.setImageResource(R.drawable.blank_boy);
+ if (bitmap != null) {
+ holder.photo.setImageBitmap(bitmap);
} else {
- holder.photo.setImageResource(R.drawable.blank_girl);
+
holder.photo.setImageResource(UserUtils.getDrawableByGenderForUserThumbnail(user));
+ }
+ } catch (IOException e) {
+
holder.photo.setImageResource(UserUtils.getDrawableByGenderForUserThumbnail(user));
+
+ if (!getDidRequestUrl(user.getPhoto())) {
+ addRequestedUrl(user.getPhoto());
+ mRrm.request(Uri.parse(user.getPhoto()));
}
}
} else {
@@ -132,7 +130,9 @@
Uri photoUri = Uri.parse(category.getIconUrl());
try {
Bitmap bitmap =
BitmapFactory.decodeStream(mRrm.getInputStream(photoUri));
- holder.photo.setImageBitmap(bitmap);
+ if (bitmap != null) {
+ holder.photo.setImageBitmap(bitmap);
+ }
} catch (IOException e) {
holder.photo.setImageResource(R.drawable.category_none);
}
@@ -164,16 +164,7 @@
R.string.tip_age_via,
StringFormatters.getUserFullName(user)));
}
- /*
- if (tip.getStats().getTodoCount() > 0) {
- holder.friendCountTodoImg.setVisibility(View.VISIBLE);
- holder.friendCountTodo.setVisibility(View.VISIBLE);
-
holder.friendCountTodo.setText(String.valueOf(tip.getStats().getTodoCount()));
- } else {
- holder.friendCountTodoImg.setVisibility(View.GONE);
- holder.friendCountTodo.setVisibility(View.GONE);
- }
- */
+
if (tip.getStats().getDoneCount() > 0) {
holder.friendCountCompletedImg.setVisibility(View.VISIBLE);
holder.friendCountCompleted.setVisibility(View.VISIBLE);
@@ -198,15 +189,12 @@
public void removeItem(int position) throws IndexOutOfBoundsException {
group.remove(position);
- notifyDataSetInvalidated();
+ notifyDataSetChanged();
}
@Override
public void setGroup(Group<Tip> g) {
super.setGroup(g);
- mLoadedPhotoIndex = 0;
-
- mHandler.postDelayed(mRunnableLoadPhotos, 10L);
mCachedTimestamps.clear();
for (Tip it : g) {
@@ -232,22 +220,6 @@
notifyDataSetChanged();
}
};
-
- private Runnable mRunnableLoadPhotos = new Runnable() {
- @Override
- public void run() {
- if (mLoadedPhotoIndex < getCount()) {
- Tip tip = (Tip)getItem(mLoadedPhotoIndex++);
- if (tip.getUser() != null) {
- Uri photoUri = Uri.parse(tip.getUser().getPhoto());
- if (!mRrm.exists(photoUri)) {
- mRrm.request(photoUri);
- }
- mHandler.postDelayed(mRunnableLoadPhotos, 200L);
- }
- }
- }
- };
static class ViewHolder {
ImageView photo;
=======================================
--- /main/src/com/joelapenna/foursquared/widget/TodosListAdapter.java Thu
Sep 30 13:00:32 2010
+++ /main/src/com/joelapenna/foursquared/widget/TodosListAdapter.java Thu
Oct 14 00:13:03 2010
@@ -125,7 +125,11 @@
Uri photoUri =
Uri.parse(tip.getVenue().getCategory().getIconUrl());
try {
Bitmap bitmap =
BitmapFactory.decodeStream(mRrm.getInputStream(photoUri));
- holder.photo.setImageBitmap(bitmap);
+ if (bitmap != null) {
+ holder.photo.setImageBitmap(bitmap);
+ } else {
+
holder.photo.setImageResource(R.drawable.category_none);
+ }
} catch (IOException e) {
holder.photo.setImageResource(R.drawable.category_none);
}
@@ -179,7 +183,7 @@
public void removeItem(int position) throws IndexOutOfBoundsException {
group.remove(position);
- notifyDataSetInvalidated();
+ notifyDataSetChanged();
}
@Override