]> average.org Git - WhereAmI.git/commitdiff
make configurable calendar selection
authorEugene Crosser <crosser@average.org>
Fri, 3 Feb 2012 07:45:14 +0000 (11:45 +0400)
committerEugene Crosser <crosser@average.org>
Fri, 3 Feb 2012 07:45:14 +0000 (11:45 +0400)
res/values/strings.xml
res/xml/preferences.xml
src/org/average/whereami/Authorize.java
src/org/average/whereami/CredentialStore.java [deleted file]
src/org/average/whereami/LastLocation.java
src/org/average/whereami/Oracle.java
src/org/average/whereami/PersistentStore.java [new file with mode: 0644]
src/org/average/whereami/PhoneLog.java
src/org/average/whereami/WhereAmI.java

index 34b65b812138a45501e8aab77bcfbd3f2ce3cc2e..b12cf7127b854edf1231b0042e36eafe4ae9d241 100644 (file)
     <string name="managewifisummary">Отключать WiFi между обновлениями</string>
     <string name="updatetitle">Периодичность обновления</string>
     <string name="updatesummary">Как часто обновлять информацию</string>
+    <string name="calnametitle">Название календаря</string>
+    <string name="calnamesummary">Полное название, с учетом заглавных букв</string>
+    <string name="eventseltitle">Строчка выбора событий</string>
+    <string name="eventselsummary">Подстрока выделяющая нужные события</string>
     <string-array name="month">
         <item>января</item>
         <item>февраля</item>
index bb3c0548f2c2100a394d9318d58f01a1dbadfb76..a74d5b4a4548fe107284209aeef16d881103e611 100644 (file)
       android:entries="@array/updatenames"
       android:entryValues="@array/updatevals"
     />
+    <EditTextPreference
+      android:key="calendar_name"
+      android:title="@string/calnametitle"
+      android:summary="@string/calnamesummary"
+      android:defaultValue="Call Log"
+    />
+    <EditTextPreference
+      android:key="peer_name"
+      android:title="@string/eventseltitle"
+      android:summary="@string/eventselsummary"
+      android:defaultValue="Call"
+    />
 </PreferenceScreen>
index aa3b834bb0cca7ddd1b6b0a8bcbef86e686521c6..1137ea57e454e3518509c40edaa21553aca8156c 100644 (file)
@@ -6,7 +6,7 @@ package org.average.whereami;
 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;
@@ -68,12 +68,12 @@ public class Authorize extends Activity {
                                 ClientCredentials.CLIENT_SECRET,
                                 code,
                                 ClientCredentials.REDIRECT_URI).execute();
-                            CredentialStore credentialStore =
-                                                    new CredentialStore(prefs);
+                            PersistentStore credentialStore =
+                                                    new PersistentStore(prefs);
                             credentialStore.write(accessTokenResponse);
                             finish();
                         } else if (url.indexOf("error=")!=-1) {
-                            new CredentialStore(prefs).clear();
+                            new PersistentStore(prefs).clear();
                             finish();
                         }
                     } catch (IOException e) {
diff --git a/src/org/average/whereami/CredentialStore.java b/src/org/average/whereami/CredentialStore.java
deleted file mode 100644 (file)
index 7b1fd19..0000000
+++ /dev/null
@@ -1,54 +0,0 @@
-package org.average.whereami;
-
-import android.content.Context;
-import android.content.SharedPreferences;
-import android.content.SharedPreferences.Editor;
-
-import com.google.api.client.auth.oauth2.draft10.AccessTokenResponse;
-
-public class CredentialStore {
-
-    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";
-
-    private SharedPreferences prefs;
-
-    public CredentialStore(SharedPreferences prefs) {
-        this.prefs = prefs;
-    }
-
-    public AccessTokenResponse read() {
-        AccessTokenResponse accessTokenResponse = new AccessTokenResponse();
-        accessTokenResponse.accessToken = prefs.getString(ACCESS_TOKEN, "");
-        accessTokenResponse.expiresIn = prefs.getLong(EXPIRES_IN, 0);
-        accessTokenResponse.refreshToken = prefs.getString(REFRESH_TOKEN, "");
-        accessTokenResponse.scope = prefs.getString(SCOPE, "");
-        return accessTokenResponse;
-    }
-
-    public void write(AccessTokenResponse accessTokenResponse) {
-        Editor editor = prefs.edit();
-        editor.putString(ACCESS_TOKEN,accessTokenResponse.accessToken);
-        editor.putLong(EXPIRES_IN,accessTokenResponse.expiresIn);
-        editor.putString(REFRESH_TOKEN,accessTokenResponse.refreshToken);
-        editor.putString(SCOPE,accessTokenResponse.scope);
-        editor.commit();
-    }
-
-    public void clear() {
-        Editor editor = prefs.edit();
-        editor.remove(ACCESS_TOKEN);
-        editor.remove(EXPIRES_IN);
-        editor.remove(REFRESH_TOKEN);
-        editor.remove(SCOPE);
-        editor.commit();
-    }
-
-    public void updateAccessToken(String accessToken) {
-        Editor editor = prefs.edit();
-        editor.putString(ACCESS_TOKEN,accessToken);
-        editor.commit();
-    }
-}
index f911b6bd3e6412dc72281d3b74141204ae6b21fa..b02a4b1b4f9765e1e4f6871544e6b5c44c7ba092 100644 (file)
@@ -1,6 +1,6 @@
 package org.average.whereami;
 
-import org.average.whereami.CredentialStore;
+import org.average.whereami.PersistentStore;
 
 import java.lang.Math;
 import java.io.IOException;
@@ -34,7 +34,7 @@ public final class LastLocation extends Oracle {
        private String hours2to4;
        private String hours5up;
 
-       public LastLocation(final Resources res, final CredentialStore store) {
+       public LastLocation(final Resources res, final PersistentStore store) {
                super(res, store);
                loc_names = res.getStringArray(R.array.loc_names);
                loc_lats = res.getStringArray(R.array.loc_lats);
index 157c988a3f3df4c3ea77e8b349d2713c0c653bf4..28effd937f81521374ccc0e3302e97f5104fd781 100644 (file)
@@ -1,6 +1,6 @@
 package org.average.whereami;
 
-import org.average.whereami.CredentialStore;
+import org.average.whereami.PersistentStore;
 
 import com.google.api.client.extensions.android2.AndroidHttp;
 import com.google.api.client.auth.oauth2.draft10.AccessTokenResponse;
@@ -25,7 +25,7 @@ public class Oracle {
 
        public String authErrorMessage;
 
-       public Oracle(final Resources res, final CredentialStore store) {
+       public Oracle(final Resources res, final PersistentStore store) {
                authErrorMessage = res.getString(R.string.autherror);
 
                httpTransport = AndroidHttp.newCompatibleTransport();
diff --git a/src/org/average/whereami/PersistentStore.java b/src/org/average/whereami/PersistentStore.java
new file mode 100644 (file)
index 0000000..595fbf7
--- /dev/null
@@ -0,0 +1,64 @@
+package org.average.whereami;
+
+import android.content.Context;
+import android.content.SharedPreferences;
+import android.content.SharedPreferences.Editor;
+
+import com.google.api.client.auth.oauth2.draft10.AccessTokenResponse;
+
+public class PersistentStore {
+
+    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";
+
+    private SharedPreferences prefs;
+
+    public PersistentStore(SharedPreferences prefs) {
+        this.prefs = prefs;
+    }
+
+    public AccessTokenResponse read() {
+        AccessTokenResponse accessTokenResponse = new AccessTokenResponse();
+        accessTokenResponse.accessToken = prefs.getString(ACCESS_TOKEN, "");
+        accessTokenResponse.expiresIn = prefs.getLong(EXPIRES_IN, 0);
+        accessTokenResponse.refreshToken = prefs.getString(REFRESH_TOKEN, "");
+        accessTokenResponse.scope = prefs.getString(SCOPE, "");
+        return accessTokenResponse;
+    }
+
+    public void write(AccessTokenResponse accessTokenResponse) {
+        Editor editor = prefs.edit();
+        editor.putString(ACCESS_TOKEN,accessTokenResponse.accessToken);
+        editor.putLong(EXPIRES_IN,accessTokenResponse.expiresIn);
+        editor.putString(REFRESH_TOKEN,accessTokenResponse.refreshToken);
+        editor.putString(SCOPE,accessTokenResponse.scope);
+        editor.commit();
+    }
+
+    public void clear() {
+        Editor editor = prefs.edit();
+        editor.remove(ACCESS_TOKEN);
+        editor.remove(EXPIRES_IN);
+        editor.remove(REFRESH_TOKEN);
+        editor.remove(SCOPE);
+        editor.commit();
+    }
+
+    public void updateAccessToken(String accessToken) {
+        Editor editor = prefs.edit();
+        editor.putString(ACCESS_TOKEN,accessToken);
+        editor.commit();
+    }
+
+    public String get(String key) {
+        return prefs.getString(key, "");
+    }
+
+    public void put(String key, String value) {
+        Editor editor = prefs.edit();
+        editor.putString(key, value);
+        editor.commit();
+    }
+}
index fca10d6a2b006433bef1d89d580f22b17c90bf61..3bb34d25effe10a1f194e0b0fce055adc7812265 100644 (file)
@@ -1,6 +1,6 @@
 package org.average.whereami;
 
-import org.average.whereami.CredentialStore;
+import org.average.whereami.PersistentStore;
 
 import java.io.IOException;
 
@@ -25,12 +25,17 @@ public final class PhoneLog extends Oracle {
 
        private Calendar calendar;
 
-       private String calendar_name = "Call Log";
-       private String calendar_id = null;
-       private String peer_name = "Alla Cherkashina";
+       private PersistentStore store;
+       private String calendar_name;
+       private String peer_name;
+       private String calendar_id;
 
-       public PhoneLog(final Resources res, final CredentialStore store) {
+       public PhoneLog(final Resources res, final PersistentStore store) {
                super(res, store);
+               this.store = store;
+               calendar_name = store.get("calendar_name");
+               peer_name = store.get("peer_name");
+               calendar_id = store.get("calendar_id");
 
                calendar = Calendar.builder(httpTransport, jsonFactory)
                        .setHttpRequestInitializer(accessProtectedResource)
@@ -41,8 +46,9 @@ public final class PhoneLog extends Oracle {
        public final String getResult() {
                try {
                        Log.v(TAG, "entering getResult");
-                       if (calendar_id == null) {
+                       if (calendar_id == null || calendar_id == "") {
                                calendar_id = scanCalendars(calendar_name);
+                               store.put("calendar_id", calendar_id);
                        }
                        return scanEvents(calendar_id, peer_name);
                } catch (GoogleJsonResponseException e) {
index 959bd0e876f41a48b97fea8c88e6170401c47164..d127fedc0a53351082dc0fe304954e3280d5742d 100644 (file)
@@ -38,7 +38,7 @@ public class WhereAmI extends Activity
     private Long updatedelay = 60000L;
     private Integer runningtasks = 0;
     private SharedPreferences prefs;
-    private CredentialStore store;
+    private PersistentStore store;
 
     private class UpdateTarget {
         private TextView tv;
@@ -200,7 +200,7 @@ public class WhereAmI extends Activity
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         prefs = PreferenceManager.getDefaultSharedPreferences(this);
-        store = new CredentialStore(prefs);
+        store = new PersistentStore(prefs);
         wifiman = (WifiManager)getSystemService(Context.WIFI_SERVICE);
         requestWindowFeature(Window.FEATURE_NO_TITLE);
         getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);