import java.io.IOException;
import org.average.whereami.ClientCredentials;
-import org.average.whereami.CredentialStore;
+import org.average.whereami.PersistentStore;
import android.app.Activity;
import android.os.Bundle;
import android.graphics.Bitmap;
+import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
-import android.content.SharedPreferences.Editor;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
public class Authorize extends Activity {
final String TAG = getClass().getName();
-
- private SharedPreferences prefs;
- private static final String ACCESS_TOKEN = "access_token";
- private static final String EXPIRES_IN = "expires_in";
- private static final String REFRESH_TOKEN = "refresh_token";
- private static final String SCOPE = "scope";
+ SharedPreferences prefs;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
- Log.w(TAG, "Starting task to retrieve request token.");
+ Log.v(TAG, "Starting task to retrieve request token.");
prefs = PreferenceManager.getDefaultSharedPreferences(this);
}
webview.setWebViewClient(new WebViewClient() {
@Override
public void onPageStarted(WebView view, String url, Bitmap bitmap) {
- Log.w(TAG, "onPageStarted : " + url);
+ Log.v(TAG, "onPageStarted : " + url);
}
@Override
public void onPageFinished(WebView view, String url) {
ClientCredentials.CLIENT_SECRET,
code,
ClientCredentials.REDIRECT_URI).execute();
- CredentialStore credentialStore =
- new CredentialStore(prefs);
- credentialStore.write(accessTokenResponse);
+ PersistentStore store = new PersistentStore(prefs);
+ store.writeTokens(accessTokenResponse);
finish();
- //view.setVisibility(View.INVISIBLE);
- //startActivity(new Intent(Authorize.this,
- // WhereAmI.class));
} else if (url.indexOf("error=")!=-1) {
- new CredentialStore(prefs).clear();
+ new PersistentStore(prefs).clearTokens();
finish();
- //view.setVisibility(View.INVISIBLE);
- //startActivity(new Intent(Authorize.this,
- // WhereAmI.class));
}
} catch (IOException e) {
e.printStackTrace();
}
}
- Log.w(TAG, "onPageFinished : " + url);
+ Log.v(TAG, "onPageFinished : " + url);
}
private String extractCodeFromUrl(String url) {