Merge remote-tracking branch 'origin/enable_cookies' into enable_cookies
[pub/Android/ownCloud.git] / src / com / owncloud / android / MainApp.java
1 /* ownCloud Android client application
2 * Copyright (C) 2012-2015 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.datamodel.ThumbnailsCacheManager;
23 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
24 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory.Policy;
25 import com.owncloud.android.lib.common.utils.Log_OC;
26 /**
27 * Main Application of the project
28 *
29 * Contains methods to build the "static" strings. These strings were before constants in different
30 * classes
31 *
32 * @author masensio
33 * @author David A. Velasco
34 */
35 public class MainApp extends Application {
36
37 private static final String AUTH_ON = "on";
38
39 private static Context mContext;
40
41 public void onCreate(){
42 super.onCreate();
43 MainApp.mContext = getApplicationContext();
44
45 // keep a single session per account handling session cookie in requests (& all the other cookies)
46 OwnCloudClientManagerFactory.setDefaultPolicy(Policy.SINGLE_SESSION_PER_ACCOUNT);
47
48 // initialise thumbnails cache on background thread
49 new ThumbnailsCacheManager.InitDiskCacheTask().execute();
50
51 if (BuildConfig.DEBUG) {
52
53 String dataFolder = getDataFolder();
54
55 // Set folder for store logs
56 Log_OC.setLogDataFolder(dataFolder);
57
58 Log_OC.startLogging();
59 Log_OC.d("Debug", "start logging");
60 }
61 }
62
63 public static Context getAppContext() {
64 return MainApp.mContext;
65 }
66
67 // Methods to obtain Strings referring app_name
68 // From AccountAuthenticator
69 // public static final String ACCOUNT_TYPE = "owncloud";
70 public static String getAccountType() {
71 return getAppContext().getResources().getString(R.string.account_type);
72 }
73
74 // From AccountAuthenticator
75 // public static final String AUTHORITY = "org.owncloud";
76 public static String getAuthority() {
77 return getAppContext().getResources().getString(R.string.authority);
78 }
79
80 // From AccountAuthenticator
81 // public static final String AUTH_TOKEN_TYPE = "org.owncloud";
82 public static String getAuthTokenType() {
83 return getAppContext().getResources().getString(R.string.authority);
84 }
85
86 // From ProviderMeta
87 // public static final String DB_FILE = "owncloud.db";
88 public static String getDBFile() {
89 return getAppContext().getResources().getString(R.string.db_file);
90 }
91
92 // From ProviderMeta
93 // private final String mDatabaseName = "ownCloud";
94 public static String getDBName() {
95 return getAppContext().getResources().getString(R.string.db_name);
96 }
97
98 // data_folder
99 public static String getDataFolder() {
100 return getAppContext().getResources().getString(R.string.data_folder);
101 }
102
103 // log_name
104 public static String getLogName() {
105 return getAppContext().getResources().getString(R.string.log_name);
106 }
107
108 }