<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>
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>
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;
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) {
+++ /dev/null
-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();
- }
-}
package org.average.whereami;
-import org.average.whereami.CredentialStore;
+import org.average.whereami.PersistentStore;
import java.lang.Math;
import java.io.IOException;
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);
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;
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();
--- /dev/null
+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();
+ }
+}
package org.average.whereami;
-import org.average.whereami.CredentialStore;
+import org.average.whereami.PersistentStore;
import java.io.IOException;
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)
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) {
private Long updatedelay = 60000L;
private Integer runningtasks = 0;
private SharedPreferences prefs;
- private CredentialStore store;
+ private PersistentStore store;
private class UpdateTarget {
private TextView tv;
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);