Merge remote-tracking branch 'upstream/develop' into imageGrid
[pub/Android/ownCloud.git] / src / com / owncloud / android / MainApp.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012-2013 ownCloud Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 */
17 package com.owncloud.android;
18
19 import android.app.Application;
20 import android.content.Context;
21
22 import com.owncloud.android.authentication.AccountUtils;
23 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
24 import android.app.Application;
25 import android.content.Context;
26
27 import com.owncloud.android.authentication.AccountUtils;
28 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
29 import android.app.Application;
30 import android.content.Context;
31
32 import com.owncloud.android.authentication.AccountUtils;
33 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
34 import android.app.Application;
35 import android.content.Context;
36
37 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
38 import android.app.Application;
39 import android.content.Context;
40
41 import com.owncloud.android.authentication.AccountUtils;
42 import com.owncloud.android.datamodel.ThumbnailsCacheManager;
43 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
44 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory.Policy;
45 import com.owncloud.android.lib.common.utils.Log_OC;
46 /**
47 * Main Application of the project
48 *
49 * Contains methods to build the "static" strings. These strings were before constants in different
50 * classes
51 *
52 * @author masensio
53 * @author David A. Velasco
54 */
55 public class MainApp extends Application {
56
57 private static final String AUTH_ON = "on";
58
59 @SuppressWarnings("unused")
60 private static final String POLICY_SINGLE_SESSION_PER_ACCOUNT = "single session per account";
61 @SuppressWarnings("unused")
62 private static final String POLICY_ALWAYS_NEW_CLIENT = "always new client";
63
64 private static Context mContext;
65
66 public void onCreate(){
67 super.onCreate();
68 MainApp.mContext = getApplicationContext();
69
70 boolean isSamlAuth = AUTH_ON.equals(getString(R.string.auth_method_saml_web_sso));
71
72 if (isSamlAuth) {
73 OwnCloudClientManagerFactory.setDefaultPolicy(Policy.SINGLE_SESSION_PER_ACCOUNT);
74
75 } else {
76 OwnCloudClientManagerFactory.setDefaultPolicy(Policy.ALWAYS_NEW_CLIENT);
77 }
78
79 // initialise thumbnails cache on background thread
80 new ThumbnailsCacheManager.InitDiskCacheTask().execute();
81
82 if (BuildConfig.DEBUG) {
83
84 String dataFolder = getDataFolder();
85
86 // Set folder for store logs
87 Log_OC.setLogDataFolder(dataFolder);
88
89 Log_OC.startLogging();
90 Log_OC.d("Debug", "start logging");
91 }
92 }
93
94 public static Context getAppContext() {
95 return MainApp.mContext;
96 }
97
98 // Methods to obtain Strings referring app_name
99 // From AccountAuthenticator
100 // public static final String ACCOUNT_TYPE = "owncloud";
101 public static String getAccountType() {
102 return getAppContext().getResources().getString(R.string.account_type);
103 }
104
105 // From AccountAuthenticator
106 // public static final String AUTHORITY = "org.owncloud";
107 public static String getAuthority() {
108 return getAppContext().getResources().getString(R.string.authority);
109 }
110
111 // From AccountAuthenticator
112 // public static final String AUTH_TOKEN_TYPE = "org.owncloud";
113 public static String getAuthTokenType() {
114 return getAppContext().getResources().getString(R.string.authority);
115 }
116
117 // From ProviderMeta
118 // public static final String DB_FILE = "owncloud.db";
119 public static String getDBFile() {
120 return getAppContext().getResources().getString(R.string.db_file);
121 }
122
123 // From ProviderMeta
124 // private final String mDatabaseName = "ownCloud";
125 public static String getDBName() {
126 return getAppContext().getResources().getString(R.string.db_name);
127 }
128
129 // data_folder
130 public static String getDataFolder() {
131 return getAppContext().getResources().getString(R.string.data_folder);
132 }
133
134 // log_name
135 public static String getLogName() {
136 return getAppContext().getResources().getString(R.string.log_name);
137 }
138
139 }