1 /* ownCloud Android client application 
   2  *   Copyright (C) 2012-2013 ownCloud Inc. 
   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. 
   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. 
  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/>. 
  17 package com
.owncloud
.android
; 
  19 import android
.app
.Application
; 
  20 import android
.content
.Context
; 
  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
; 
  27  * Main Application of the project 
  29  * Contains methods to build the "static" strings. These strings were before constants in different 
  33  * @author David A. Velasco 
  35 public class MainApp 
extends Application 
{ 
  37     private static final String AUTH_ON 
= "on"; 
  39     @SuppressWarnings("unused") 
  40     private static final String POLICY_SINGLE_SESSION_PER_ACCOUNT 
= "single session per account"; 
  41     @SuppressWarnings("unused") 
  42     private static final String POLICY_ALWAYS_NEW_CLIENT 
= "always new client"; 
  44     private static Context mContext
; 
  47     private static boolean mOnlyOnDevice 
= false
; 
  50     public void onCreate(){ 
  52         MainApp
.mContext 
= getApplicationContext(); 
  54         boolean isSamlAuth 
= AUTH_ON
.equals(getString(R
.string
.auth_method_saml_web_sso
)); 
  57             OwnCloudClientManagerFactory
.setDefaultPolicy(Policy
.SINGLE_SESSION_PER_ACCOUNT
); 
  60             OwnCloudClientManagerFactory
.setDefaultPolicy(Policy
.ALWAYS_NEW_CLIENT
); 
  63         // initialise thumbnails cache on background thread 
  64         new ThumbnailsCacheManager
.InitDiskCacheTask().execute(); 
  66         if (BuildConfig
.DEBUG
) { 
  68             String dataFolder 
= getDataFolder(); 
  70             // Set folder for store logs 
  71             Log_OC
.setLogDataFolder(dataFolder
); 
  73             Log_OC
.startLogging(); 
  74             Log_OC
.d("Debug", "start logging"); 
  78     public static Context 
getAppContext() { 
  79         return MainApp
.mContext
; 
  82     // Methods to obtain Strings referring app_name  
  83     //   From AccountAuthenticator  
  84     //   public static final String ACCOUNT_TYPE = "owncloud";     
  85     public static String 
getAccountType() { 
  86         return getAppContext().getResources().getString(R
.string
.account_type
); 
  89     //  From AccountAuthenticator  
  90     //  public static final String AUTHORITY = "org.owncloud"; 
  91     public static String 
getAuthority() { 
  92         return getAppContext().getResources().getString(R
.string
.authority
); 
  95     //  From AccountAuthenticator 
  96     //  public static final String AUTH_TOKEN_TYPE = "org.owncloud"; 
  97     public static String 
getAuthTokenType() { 
  98         return getAppContext().getResources().getString(R
.string
.authority
); 
 102     //  public static final String DB_FILE = "owncloud.db"; 
 103     public static String 
getDBFile() { 
 104         return getAppContext().getResources().getString(R
.string
.db_file
); 
 108     //  private final String mDatabaseName = "ownCloud"; 
 109     public static String 
getDBName() { 
 110         return getAppContext().getResources().getString(R
.string
.db_name
); 
 114     public static String 
getDataFolder() { 
 115         return getAppContext().getResources().getString(R
.string
.data_folder
); 
 119     public static String 
getLogName() { 
 120         return getAppContext().getResources().getString(R
.string
.log_name
); 
 123     public static void showOnlyFilesOnDevice(boolean state
){ 
 124         mOnlyOnDevice 
= state
; 
 127     public static boolean getOnlyOnDevice(){ 
 128         return mOnlyOnDevice
;