CameraApp.java revision f33880ba31aebb4d5e993bd8e8d7f715242fb984
1/* 2 * Copyright (C) 2013 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.camera.app; 18 19import android.app.Application; 20import android.app.NotificationManager; 21import android.content.Context; 22 23import com.android.camera.MediaSaverImpl; 24import com.android.camera.processing.ProcessingServiceManager; 25import com.android.camera.remote.RemoteShutterListener; 26import com.android.camera.session.CaptureSessionManager; 27import com.android.camera.session.CaptureSessionManagerImpl; 28import com.android.camera.session.PlaceholderManager; 29import com.android.camera.session.SessionStorageManager; 30import com.android.camera.session.SessionStorageManagerImpl; 31import com.android.camera.util.CameraUtil; 32import com.android.camera.util.RemoteShutterHelper; 33import com.android.camera.util.UsageStatistics; 34 35/** 36 * The Camera application class containing important services and functionality 37 * to be used across modules. 38 */ 39public class CameraApp extends Application implements CameraServices { 40 private MediaSaver mMediaSaver; 41 private CaptureSessionManager mSessionManager; 42 private SessionStorageManager mSessionStorageManager; 43 private MemoryManagerImpl mMemoryManager; 44 private PlaceholderManager mPlaceHolderManager; 45 private RemoteShutterListener mRemoteShutterListener; 46 47 @Override 48 public void onCreate() { 49 super.onCreate(); 50 51 UsageStatistics.instance().initialize(this); 52 CameraUtil.initialize(this); 53 54 Context context = getApplicationContext(); 55 ProcessingServiceManager.initSingleton(context); 56 57 mMediaSaver = new MediaSaverImpl(); 58 mPlaceHolderManager = new PlaceholderManager(context); 59 mSessionStorageManager = SessionStorageManagerImpl.create(this); 60 mSessionManager = new CaptureSessionManagerImpl(mMediaSaver, getContentResolver(), 61 mPlaceHolderManager, mSessionStorageManager); 62 mMemoryManager = MemoryManagerImpl.create(getApplicationContext(), mMediaSaver); 63 mRemoteShutterListener = RemoteShutterHelper.create(this); 64 65 clearNotifications(); 66 } 67 68 @Override 69 public CaptureSessionManager getCaptureSessionManager() { 70 return mSessionManager; 71 } 72 73 @Override 74 public MemoryManager getMemoryManager() { 75 return mMemoryManager; 76 } 77 78 @Override 79 @Deprecated 80 public MediaSaver getMediaSaver() { 81 return mMediaSaver; 82 } 83 84 @Override 85 public RemoteShutterListener getRemoteShutterListener() { 86 return mRemoteShutterListener; 87 } 88 89 /** 90 * Clears all notifications. This cleans up notifications that we might have 91 * created earlier but remained after a crash. 92 */ 93 private void clearNotifications() { 94 NotificationManager manager = (NotificationManager) getSystemService( 95 Context.NOTIFICATION_SERVICE); 96 if (manager != null) { 97 manager.cancelAll(); 98 } 99 } 100} 101