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