4f77b2b43454ab3012e33eac3a436a884d0eb580
[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.OwnCloudClientManagerFactory;
20 import com.owncloud.android.lib.common.OwnCloudClientManagerFactory.Policy;
21
22 import android.app.Application;
23 import android.content.Context;
24 /**
25 * Main Application of the project
26 *
27 * Contains methods to build the "static" strings. These strings were before constants in different
28 * 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 public void onCreate(){
42 super.onCreate();
43 MainApp.mContext = getApplicationContext();
44
45 String clientPolicy = getString(R.string.client_creation_policy);
46 if (clientPolicy != null &&
47 POLICY_SINGLE_SESSION_PER_ACCOUNT.equals(clientPolicy.toLowerCase())) {
48
49 OwnCloudClientManagerFactory.setDefaultPolicy(Policy.SINGLE_SESSION_PER_ACCOUNT);
50
51 } else {
52 OwnCloudClientManagerFactory.setDefaultPolicy(Policy.ALWAYS_NEW_CLIENT);
53 }
54
55 }
56
57 public static Context getAppContext() {
58 return MainApp.mContext;
59 }
60
61 // Methods to obtain Strings referring app_name
62 // From AccountAuthenticator
63 // public static final String ACCOUNT_TYPE = "owncloud";
64 public static String getAccountType() {
65 return getAppContext().getResources().getString(R.string.account_type);
66 }
67
68 // From AccountAuthenticator
69 // public static final String AUTHORITY = "org.owncloud";
70 public static String getAuthority() {
71 return getAppContext().getResources().getString(R.string.authority);
72 }
73
74 // From AccountAuthenticator
75 // public static final String AUTH_TOKEN_TYPE = "org.owncloud";
76 public static String getAuthTokenType() {
77 return getAppContext().getResources().getString(R.string.authority);
78 }
79
80 // From ProviderMeta
81 // public static final String DB_FILE = "owncloud.db";
82 public static String getDBFile() {
83 return getAppContext().getResources().getString(R.string.db_file);
84 }
85
86 // From ProviderMeta
87 // private final String mDatabaseName = "ownCloud";
88 public static String getDBName() {
89 return getAppContext().getResources().getString(R.string.db_name);
90 }
91
92 // data_folder
93 public static String getDataFolder() {
94 return getAppContext().getResources().getString(R.string.data_folder);
95 }
96
97 // log_name
98 public static String getLogName() {
99 return getAppContext().getResources().getString(R.string.log_name);
100 }
101
102 }