8a8b6c5164d1076d2371b4deb3d82c14d5f0a0a7
[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 java.io.File;
20
21 import android.app.Application;
22 import android.content.Context;
23 import android.os.Environment;
24
25 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
26 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory.Policy;
27 import com.owncloud.android.lib.common.utils.Log_OC;
28 /**
29 * Main Application of the project
30 *
31 * Contains methods to build the "static" strings. These strings were before constants in different
32 * classes
33 *
34 * @author masensio
35 * @author David A. Velasco
36 */
37 public class MainApp extends Application {
38
39 private static final String AUTH_ON = "on";
40
41 @SuppressWarnings("unused")
42 private static final String POLICY_SINGLE_SESSION_PER_ACCOUNT = "single session per account";
43 @SuppressWarnings("unused")
44 private static final String POLICY_ALWAYS_NEW_CLIENT = "always new client";
45
46 private static Context mContext;
47
48 public void onCreate(){
49 super.onCreate();
50 MainApp.mContext = getApplicationContext();
51
52 boolean isSamlAuth = AUTH_ON.equals(getString(R.string.auth_method_saml_web_sso));
53
54 if (isSamlAuth) {
55 OwnCloudClientManagerFactory.setDefaultPolicy(Policy.SINGLE_SESSION_PER_ACCOUNT);
56
57 } else {
58 OwnCloudClientManagerFactory.setDefaultPolicy(Policy.ALWAYS_NEW_CLIENT);
59 }
60
61 if (BuildConfig.DEBUG) {
62 String logpath = Environment.getExternalStorageDirectory()+File.separator+"owncloud"+File.separator+"log";
63 Log_OC.d("Debug", "start logging");
64 Log_OC.v("PATH", logpath);
65 Log_OC.startLogging(logpath);
66 }
67 }
68
69 public static Context getAppContext() {
70 return MainApp.mContext;
71 }
72
73 // Methods to obtain Strings referring app_name
74 // From AccountAuthenticator
75 // public static final String ACCOUNT_TYPE = "owncloud";
76 public static String getAccountType() {
77 return getAppContext().getResources().getString(R.string.account_type);
78 }
79
80 // From AccountAuthenticator
81 // public static final String AUTHORITY = "org.owncloud";
82 public static String getAuthority() {
83 return getAppContext().getResources().getString(R.string.authority);
84 }
85
86 // From AccountAuthenticator
87 // public static final String AUTH_TOKEN_TYPE = "org.owncloud";
88 public static String getAuthTokenType() {
89 return getAppContext().getResources().getString(R.string.authority);
90 }
91
92 // From ProviderMeta
93 // public static final String DB_FILE = "owncloud.db";
94 public static String getDBFile() {
95 return getAppContext().getResources().getString(R.string.db_file);
96 }
97
98 // From ProviderMeta
99 // private final String mDatabaseName = "ownCloud";
100 public static String getDBName() {
101 return getAppContext().getResources().getString(R.string.db_name);
102 }
103
104 // data_folder
105 public static String getDataFolder() {
106 return getAppContext().getResources().getString(R.string.data_folder);
107 }
108
109 // log_name
110 public static String getLogName() {
111 return getAppContext().getResources().getString(R.string.log_name);
112 }
113
114 }