blob: ac551dd95f29369c85545440cf90fa67e44fae5e [file] [log] [blame]
Owen Lina2fba682011-08-17 22:07:43 +08001/*
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
17package com.android.gallery3d.app;
18
Owen Lin73a04ff2012-03-14 17:27:24 +080019import android.app.Application;
20import android.content.Context;
21
Owen Lina2fba682011-08-17 22:07:43 +080022import com.android.gallery3d.data.DataManager;
23import com.android.gallery3d.data.DownloadCache;
24import com.android.gallery3d.data.ImageCacheService;
Owen Lin56732022011-08-18 21:48:19 +080025import com.android.gallery3d.gadget.WidgetUtils;
Owen Lina2fba682011-08-17 22:07:43 +080026import com.android.gallery3d.picasasource.PicasaSource;
27import com.android.gallery3d.util.GalleryUtils;
28import com.android.gallery3d.util.ThreadPool;
Owen Lina2fba682011-08-17 22:07:43 +080029
Owen Lina2fba682011-08-17 22:07:43 +080030import java.io.File;
31
32public 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 Changdef22b62012-03-08 20:10:53 +080045 com.android.camera.Util.initialize(this);
Owen Lina2fba682011-08-17 22:07:43 +080046 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}