From 037cb8fe34228adc45247498dff852a1af8d304f Mon Sep 17 00:00:00 2001 From: Eugene Crosser Date: Fri, 3 Feb 2012 11:45:14 +0400 Subject: [PATCH] make configurable calendar selection --- res/values/strings.xml | 4 ++++ res/xml/preferences.xml | 12 ++++++++++++ src/org/average/whereami/Authorize.java | 8 ++++---- src/org/average/whereami/LastLocation.java | 4 ++-- src/org/average/whereami/Oracle.java | 4 ++-- ...edentialStore.java => PersistentStore.java} | 14 ++++++++++++-- src/org/average/whereami/PhoneLog.java | 18 ++++++++++++------ src/org/average/whereami/WhereAmI.java | 4 ++-- 8 files changed, 50 insertions(+), 18 deletions(-) rename src/org/average/whereami/{CredentialStore.java => PersistentStore.java} (84%) diff --git a/res/values/strings.xml b/res/values/strings.xml index 34b65b8..b12cf71 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -24,6 +24,10 @@ Отключать WiFi между обновлениями Периодичность обновления Как часто обновлять информацию + Название календаря + Полное название, с учетом заглавных букв + Строчка выбора событий + Подстрока выделяющая нужные события января февраля diff --git a/res/xml/preferences.xml b/res/xml/preferences.xml index bb3c054..a74d5b4 100644 --- a/res/xml/preferences.xml +++ b/res/xml/preferences.xml @@ -20,4 +20,16 @@ android:entries="@array/updatenames" android:entryValues="@array/updatevals" /> + + diff --git a/src/org/average/whereami/Authorize.java b/src/org/average/whereami/Authorize.java index aa3b834..1137ea5 100644 --- a/src/org/average/whereami/Authorize.java +++ b/src/org/average/whereami/Authorize.java @@ -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/LastLocation.java b/src/org/average/whereami/LastLocation.java index f911b6b..b02a4b1 100644 --- a/src/org/average/whereami/LastLocation.java +++ b/src/org/average/whereami/LastLocation.java @@ -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); diff --git a/src/org/average/whereami/Oracle.java b/src/org/average/whereami/Oracle.java index 157c988..28effd9 100644 --- a/src/org/average/whereami/Oracle.java +++ b/src/org/average/whereami/Oracle.java @@ -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/CredentialStore.java b/src/org/average/whereami/PersistentStore.java similarity index 84% rename from src/org/average/whereami/CredentialStore.java rename to src/org/average/whereami/PersistentStore.java index 7b1fd19..595fbf7 100644 --- a/src/org/average/whereami/CredentialStore.java +++ b/src/org/average/whereami/PersistentStore.java @@ -6,7 +6,7 @@ import android.content.SharedPreferences.Editor; import com.google.api.client.auth.oauth2.draft10.AccessTokenResponse; -public class CredentialStore { +public class PersistentStore { private static final String ACCESS_TOKEN = "access_token"; private static final String EXPIRES_IN = "expires_in"; @@ -15,7 +15,7 @@ public class CredentialStore { private SharedPreferences prefs; - public CredentialStore(SharedPreferences prefs) { + public PersistentStore(SharedPreferences prefs) { this.prefs = prefs; } @@ -51,4 +51,14 @@ public class CredentialStore { 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(); + } } diff --git a/src/org/average/whereami/PhoneLog.java b/src/org/average/whereami/PhoneLog.java index fca10d6..3bb34d2 100644 --- a/src/org/average/whereami/PhoneLog.java +++ b/src/org/average/whereami/PhoneLog.java @@ -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) { diff --git a/src/org/average/whereami/WhereAmI.java b/src/org/average/whereami/WhereAmI.java index 959bd0e..d127fed 100644 --- a/src/org/average/whereami/WhereAmI.java +++ b/src/org/average/whereami/WhereAmI.java @@ -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); -- 2.43.0