From: Eugene Crosser Date: Fri, 3 Feb 2012 07:45:14 +0000 (+0400) Subject: make configurable calendar selection X-Git-Url: http://average.org/gitweb/?a=commitdiff_plain;h=037cb8fe34228adc45247498dff852a1af8d304f;p=WhereAmI.git make configurable calendar selection --- 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/CredentialStore.java b/src/org/average/whereami/CredentialStore.java deleted file mode 100644 index 7b1fd19..0000000 --- a/src/org/average/whereami/CredentialStore.java +++ /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(); - } -} 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/PersistentStore.java b/src/org/average/whereami/PersistentStore.java new file mode 100644 index 0000000..595fbf7 --- /dev/null +++ b/src/org/average/whereami/PersistentStore.java @@ -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(); + } +} 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);