Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package com.android.gallery3d.app; |
| 18 | |
Owen Lin | 73a04ff | 2012-03-14 17:27:24 +0800 | [diff] [blame] | 19 | import android.app.Application; |
| 20 | import android.content.Context; |
| 21 | |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 22 | import com.android.gallery3d.data.DataManager; |
| 23 | import com.android.gallery3d.data.DownloadCache; |
| 24 | import com.android.gallery3d.data.ImageCacheService; |
Owen Lin | 5673202 | 2011-08-18 21:48:19 +0800 | [diff] [blame] | 25 | import com.android.gallery3d.gadget.WidgetUtils; |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 26 | import com.android.gallery3d.picasasource.PicasaSource; |
| 27 | import com.android.gallery3d.util.GalleryUtils; |
| 28 | import com.android.gallery3d.util.ThreadPool; |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 29 | |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 30 | import java.io.File; |
| 31 | |
| 32 | public class GalleryAppImpl extends Application implements GalleryApp { |
| 33 | |
| 34 | private static final String DOWNLOAD_FOLDER = "download"; |
| 35 | private static final long DOWNLOAD_CAPACITY = 64 * 1024 * 1024; // 64M |
| 36 | |
| 37 | private ImageCacheService mImageCacheService; |
| 38 | private DataManager mDataManager; |
| 39 | private ThreadPool mThreadPool; |
| 40 | private DownloadCache mDownloadCache; |
| 41 | |
| 42 | @Override |
| 43 | public void onCreate() { |
| 44 | super.onCreate(); |
Chih-Chung Chang | def22b6 | 2012-03-08 20:10:53 +0800 | [diff] [blame] | 45 | com.android.camera.Util.initialize(this); |
Owen Lin | a2fba68 | 2011-08-17 22:07:43 +0800 | [diff] [blame] | 46 | GalleryUtils.initialize(this); |
| 47 | WidgetUtils.initialize(this); |
| 48 | PicasaSource.initialize(this); |
| 49 | } |
| 50 | |
| 51 | public Context getAndroidContext() { |
| 52 | return this; |
| 53 | } |
| 54 | |
| 55 | public synchronized DataManager getDataManager() { |
| 56 | if (mDataManager == null) { |
| 57 | mDataManager = new DataManager(this); |
| 58 | mDataManager.initializeSourceMap(); |
| 59 | } |
| 60 | return mDataManager; |
| 61 | } |
| 62 | |
| 63 | public synchronized ImageCacheService getImageCacheService() { |
| 64 | if (mImageCacheService == null) { |
| 65 | mImageCacheService = new ImageCacheService(getAndroidContext()); |
| 66 | } |
| 67 | return mImageCacheService; |
| 68 | } |
| 69 | |
| 70 | public synchronized ThreadPool getThreadPool() { |
| 71 | if (mThreadPool == null) { |
| 72 | mThreadPool = new ThreadPool(); |
| 73 | } |
| 74 | return mThreadPool; |
| 75 | } |
| 76 | |
| 77 | public synchronized DownloadCache getDownloadCache() { |
| 78 | if (mDownloadCache == null) { |
| 79 | File cacheDir = new File(getExternalCacheDir(), DOWNLOAD_FOLDER); |
| 80 | |
| 81 | if (!cacheDir.isDirectory()) cacheDir.mkdirs(); |
| 82 | |
| 83 | if (!cacheDir.isDirectory()) { |
| 84 | throw new RuntimeException( |
| 85 | "fail to create: " + cacheDir.getAbsolutePath()); |
| 86 | } |
| 87 | mDownloadCache = new DownloadCache(this, cacheDir, DOWNLOAD_CAPACITY); |
| 88 | } |
| 89 | return mDownloadCache; |
| 90 | } |
| 91 | } |