--- /dev/null
+local.properties
+src/org/average/whereami/ClientCredentials.java
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) {
code,
ClientCredentials.REDIRECT_URI).execute();
CredentialStore credentialStore =
- new CredentialStore(prefs);
+ new CredentialStore(prefs);
credentialStore.write(accessTokenResponse);
finish();
- //view.setVisibility(View.INVISIBLE);
- //startActivity(new Intent(Authorize.this,
- // WhereAmI.class));
} else if (url.indexOf("error=")!=-1) {
new CredentialStore(prefs).clear();
finish();
- //view.setVisibility(View.INVISIBLE);
- //startActivity(new Intent(Authorize.this,
- // WhereAmI.class));
}
} catch (IOException e) {
e.printStackTrace();
package org.average.whereami;
+import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
editor.remove(SCOPE);
editor.commit();
}
+
+ public void updateAccessToken(String accessToken) {
+ Editor editor = prefs.edit();
+ editor.putString(ACCESS_TOKEN,accessToken);
+ editor.commit();
+ }
}
--- /dev/null
+package org.average.whereami;
+
+import org.average.whereami.CredentialStore;
+//import org.average.whereami.WhereAmIAccessResource;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+
+import com.google.api.client.auth.oauth2.draft10.AccessTokenResponse;
+import com.google.api.client.googleapis.auth.oauth2.draft10.GoogleAccessProtectedResource;
+import com.google.api.client.http.HttpTransport;
+import com.google.api.client.http.javanet.NetHttpTransport;
+import com.google.api.client.json.JsonFactory;
+import com.google.api.client.json.jackson.JacksonFactory;
+import com.google.api.services.latitude.Latitude;
+import com.google.api.services.latitude.LatitudeRequest;
+import com.google.api.services.latitude.model.Location;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.util.Log;
+
+public final class LastLocation extends Oracle {
+
+ final String TAG = getClass().getName();
+
+ private Latitude latitude;
+
+ public LastLocation(CredentialStore store) {
+ HttpTransport transport = new NetHttpTransport();
+ JsonFactory jsonFactory = new JacksonFactory();
+ AccessTokenResponse token = store.read();
+ GoogleAccessProtectedResource accessProtectedResource =
+ new GoogleAccessProtectedResource(
+ token.accessToken,
+ transport, jsonFactory,
+ ClientCredentials.CLIENT_ID,
+ ClientCredentials.CLIENT_SECRET,
+ token.refreshToken)
+ //{
+ //@Override
+ //public void onAccessToken(String accessToken) {
+ // store.updateAccessToken(accessToken);
+ // }
+ //}
+ ;
+ Latitude.Builder lbldr = Latitude.builder(transport,
+ jsonFactory);
+ lbldr.setHttpRequestInitializer(accessProtectedResource);
+ lbldr.setApplicationName("WhereAmI/1.0");
+ latitude = lbldr.build();
+ }
+
+ @Override
+ public final String getResult() {
+ try {
+ Latitude.CurrentLocation.Get request =
+ latitude.currentLocation().get();
+ request.setGranularity("best");
+ Location currentLocation = request.execute();
+ return locationMessage(currentLocation);
+ } catch (Exception ex) {
+ return ex.getMessage();
+ }
+ }
+
+ private String locationMessage(Location currentLocation) {
+ // lat = currentLocation.getLatitude();
+ // lon = currentLocation.getLongitude();
+ // tsm = currentLocation.getTimestampMs();
+ return "Current location: " + currentLocation;
+ }
+}
+++ /dev/null
-package org.average.whereami;
-
-import com.google.api.client.extensions.android2.AndroidHttp;
-import com.google.api.client.googleapis.GoogleHeaders;
-import com.google.api.client.http.HttpRequest;
-import com.google.api.client.http.HttpResponse;
-import com.google.api.client.http.HttpResponseException;
-import com.google.api.client.http.HttpTransport;
-import com.google.api.client.util.DateTime;
-
-import android.util.Log;
-import android.os.SystemClock;
-
-public final class Location extends Oracle {
-
- final String TAG = getClass().getName();
-
- @Override
- public final String getResult() {
- SystemClock.sleep(6000);
- return "Response from Location.getResult";
- }
-}
package org.average.whereami;
+import org.average.whereami.CredentialStore;
+
import com.google.api.client.extensions.android2.AndroidHttp;
import com.google.api.client.googleapis.GoogleHeaders;
import com.google.api.client.http.HttpRequest;
import android.util.Log;
import android.os.SystemClock;
+import android.content.Context;
+import android.content.SharedPreferences;
public final class PhoneLog extends Oracle {
final String TAG = getClass().getName();
+ public PhoneLog(CredentialStore store) {
+ }
+
@Override
public final String getResult() {
SystemClock.sleep(5000);
import org.average.whereami.WhereAmIprefs;
import org.average.whereami.Oracle;
import org.average.whereami.PhoneLog;
-import org.average.whereami.Location;
+import org.average.whereami.LastLocation;
import android.app.Activity;
import android.net.wifi.WifiManager;
private Long updatedelay = 60000L;
private Integer runningtasks = 0;
private SharedPreferences prefs;
+ private CredentialStore store;
private class UpdateTarget {
private TextView tv;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ prefs = PreferenceManager.getDefaultSharedPreferences(this);
+ store = new CredentialStore(prefs);
wifiman = (WifiManager)getSystemService(Context.WIFI_SERVICE);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
tvs = (TextView)findViewById(R.id.timestamp);
ut = new UpdateTarget[] {
new UpdateTarget((TextView)findViewById(R.id.location),
- new PhoneLog()),
+ new PhoneLog(store)),
new UpdateTarget((TextView)findViewById(R.id.phonecall),
- new Location())
+ new LastLocation(store))
};
Log.w(TAG, "created UI, about to start update task");
mHandler.post(updateClock);
@Override
public void onResume() {
super.onResume();
- prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean fullscreen = prefs.getBoolean("fullscreen", false);
managewifi = prefs.getBoolean("managewifi", false);
updatedelay = Long.parseLong(prefs.getString("updateperiod", "1200000"));