MainApp.java 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. import android.app.Application;
  19. import android.content.Context;
  20. import com.owncloud.android.datamodel.ThumbnailsCacheManager;
  21. import com.owncloud.android.lib.common.OwnCloudClientManagerFactory;
  22. import com.owncloud.android.lib.common.OwnCloudClientManagerFactory.Policy;
  23. import com.owncloud.android.lib.common.utils.Log_OC;
  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. private static final String AUTH_ON = "on";
  35. @SuppressWarnings("unused")
  36. private static final String POLICY_SINGLE_SESSION_PER_ACCOUNT = "single session per account";
  37. @SuppressWarnings("unused")
  38. private static final String POLICY_ALWAYS_NEW_CLIENT = "always new client";
  39. private static Context mContext;
  40. public void onCreate(){
  41. super.onCreate();
  42. MainApp.mContext = getApplicationContext();
  43. boolean isSamlAuth = AUTH_ON.equals(getString(R.string.auth_method_saml_web_sso));
  44. if (isSamlAuth) {
  45. OwnCloudClientManagerFactory.setDefaultPolicy(Policy.SINGLE_SESSION_PER_ACCOUNT);
  46. } else {
  47. OwnCloudClientManagerFactory.setDefaultPolicy(Policy.ALWAYS_NEW_CLIENT);
  48. }
  49. // initialise thumbnails cache on background thread
  50. new ThumbnailsCacheManager.InitDiskCacheTask().execute();
  51. if (BuildConfig.DEBUG) {
  52. String dataFolder = getDataFolder();
  53. // Set folder for store logs
  54. Log_OC.setLogDataFolder(dataFolder);
  55. Log_OC.startLogging();
  56. Log_OC.d("Debug", "start logging");
  57. }
  58. }
  59. public static Context getAppContext() {
  60. return MainApp.mContext;
  61. }
  62. // Methods to obtain Strings referring app_name
  63. // From AccountAuthenticator
  64. // public static final String ACCOUNT_TYPE = "owncloud";
  65. public static String getAccountType() {
  66. return getAppContext().getResources().getString(R.string.account_type);
  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. // From AccountAuthenticator
  74. // public static final String AUTH_TOKEN_TYPE = "org.owncloud";
  75. public static String getAuthTokenType() {
  76. return getAppContext().getResources().getString(R.string.authority);
  77. }
  78. // From ProviderMeta
  79. // public static final String DB_FILE = "owncloud.db";
  80. public static String getDBFile() {
  81. return getAppContext().getResources().getString(R.string.db_file);
  82. }
  83. // From ProviderMeta
  84. // private final String mDatabaseName = "ownCloud";
  85. public static String getDBName() {
  86. return getAppContext().getResources().getString(R.string.db_name);
  87. }
  88. // data_folder
  89. public static String getDataFolder() {
  90. return getAppContext().getResources().getString(R.string.data_folder);
  91. }
  92. // log_name
  93. public static String getLogName() {
  94. return getAppContext().getResources().getString(R.string.log_name);
  95. }
  96. }