github.com/olivere/camlistore@v0.0.0-20140121221811-1b7ac2da0199/clients/android/src/org/camlistore/Preferences.java (about) 1 /* 2 Copyright 2011 Google Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package org.camlistore; 18 19 import android.content.SharedPreferences; 20 21 public final class Preferences { 22 public static final String NAME = "CamliUploader"; 23 24 public static final String HOST = "camli.host"; 25 // TODO(mpl): list instead of single string later? seems overkill for now. 26 public static final String TRUSTED_CERT = "camli.trusted_cert"; 27 public static final String USERNAME = "camli.username"; 28 public static final String PASSWORD = "camli.password"; 29 public static final String AUTO = "camli.auto"; 30 public static final String AUTO_OPTS = "camli.auto.opts"; 31 public static final String MAX_CACHE_MB = "camli.max_cache_mb"; 32 public static final String DEV_IP = "camli.dev_ip"; 33 public static final String AUTO_REQUIRE_POWER = "camli.auto.require_power"; 34 public static final String AUTO_REQUIRE_WIFI = "camli.auto.require_wifi"; 35 public static final String AUTO_DIR_PHOTOS = "camli.auto.photos"; 36 public static final String AUTO_DIR_MYTRACKS = "camli.auto.mytracks"; 37 38 private final SharedPreferences mSP; 39 40 public Preferences(SharedPreferences prefs) { 41 mSP = prefs; 42 } 43 44 public boolean autoRequiresPower() { 45 return mSP.getBoolean(AUTO_REQUIRE_POWER, false); 46 } 47 48 public boolean autoRequiresWifi() { 49 return mSP.getBoolean(AUTO_REQUIRE_WIFI, false); 50 } 51 52 public boolean autoUpload() { 53 return mSP.getBoolean(AUTO, false); 54 } 55 56 public int maxCacheMb() { 57 return Integer.parseInt(mSP.getString(MAX_CACHE_MB, "256")); 58 } 59 60 public long maxCacheBytes() { 61 return maxCacheMb() * 1024 * 1024; 62 } 63 64 public boolean autoDirPhotos() { 65 return mSP.getBoolean(AUTO_DIR_PHOTOS, true); 66 } 67 68 public boolean autoDirMyTracks() { 69 return mSP.getBoolean(AUTO_DIR_MYTRACKS, true); 70 } 71 72 private String devIP() { 73 return mSP.getString(DEV_IP, ""); 74 } 75 76 private boolean inDevMode() { 77 return !devIP().isEmpty(); 78 } 79 80 public String username() { 81 if (inDevMode()) { 82 return "camlistore"; 83 } 84 return mSP.getString(USERNAME, ""); 85 } 86 87 public String password() { 88 if (inDevMode()) { 89 return "pass3179"; 90 } 91 return mSP.getString(PASSWORD, ""); 92 } 93 94 public HostPort hostPort() { 95 if (inDevMode()) { 96 return new HostPort("http://" + devIP() + ":3179"); 97 } 98 return new HostPort(mSP.getString(Preferences.HOST, "")); 99 } 100 101 public String trustedCert() { 102 return mSP.getString(TRUSTED_CERT, "").toLowerCase(); 103 } 104 105 public void setDevIP(String value) { 106 mSP.edit().putString(DEV_IP, value).apply(); 107 } 108 109 }