1b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project/* 2b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project * Copyright (C) 2007 The Android Open Source Project 3b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project * 4b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project * Licensed under the Apache License, Version 2.0 (the "License"); 5b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project * you may not use this file except in compliance with the License. 6b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project * You may obtain a copy of the License at 7b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project * 8b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project * http://www.apache.org/licenses/LICENSE-2.0 9b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project * 10b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project * Unless required by applicable law or agreed to in writing, software 11b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project * distributed under the License is distributed on an "AS IS" BASIS, 12b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project * See the License for the specific language governing permissions and 14b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project * limitations under the License. 15b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project */ 16b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project 17b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Projectpackage com.android.camera; 18b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project 1923c51b794e95c201290e36737f379c4bb8eefeaeRay Chenimport android.content.BroadcastReceiver; 20b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Projectimport android.content.Context; 21b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Projectimport android.content.Intent; 22b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project 2377c1cdc8f2cda250b1db842204efb49f87e094aeChih-Chung Chang/** 24271b3095b9f763421c0547109da9de774795072dChih-Chung Chang * {@code CameraButtonIntentReceiver} is invoked when the camera button is 25271b3095b9f763421c0547109da9de774795072dChih-Chung Chang * long-pressed. 2677c1cdc8f2cda250b1db842204efb49f87e094aeChih-Chung Chang * 27271b3095b9f763421c0547109da9de774795072dChih-Chung Chang * It is declared in {@code AndroidManifest.xml} to receive the 2877c1cdc8f2cda250b1db842204efb49f87e094aeChih-Chung Chang * {@code android.intent.action.CAMERA_BUTTON} intent. 2977c1cdc8f2cda250b1db842204efb49f87e094aeChih-Chung Chang * 3077c1cdc8f2cda250b1db842204efb49f87e094aeChih-Chung Chang * After making sure we can use the camera hardware, it starts the Camera 3177c1cdc8f2cda250b1db842204efb49f87e094aeChih-Chung Chang * activity. 3277c1cdc8f2cda250b1db842204efb49f87e094aeChih-Chung Chang */ 33b05be85099d2f886882c44791c8a37511f2cc691Chih-Chung Changpublic class CameraButtonIntentReceiver extends BroadcastReceiver { 340a475e11e2ceadbaa70308b52e06f4e6d9e56f12Chih-Chung Chang 35b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project @Override 36b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project public void onReceive(Context context, Intent intent) { 373f3c857e3f34650c15d764810335024654b0fcc3Owen Lin // Try to get the camera hardware 38d9e32402bbc5ebaac40ccd2c4b734f8e5743343eOwen Lin CameraHolder holder = CameraHolder.instance(); 39d9e32402bbc5ebaac40ccd2c4b734f8e5743343eOwen Lin if (holder.tryOpen() == null) return; 40d9e32402bbc5ebaac40ccd2c4b734f8e5743343eOwen Lin 41d9e32402bbc5ebaac40ccd2c4b734f8e5743343eOwen Lin // We are going to launch the camera, so hold the camera for later use 42d9e32402bbc5ebaac40ccd2c4b734f8e5743343eOwen Lin holder.keep(); 43d9e32402bbc5ebaac40ccd2c4b734f8e5743343eOwen Lin holder.release(); 44b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project Intent i = new Intent(Intent.ACTION_MAIN); 45b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project i.setClass(context, Camera.class); 46609d8cc0c7d05aa294aeebea8dcbb9111aefc1e1Cheng-Ru Lin i.addCategory(Intent.CATEGORY_LAUNCHER); 47609d8cc0c7d05aa294aeebea8dcbb9111aefc1e1Cheng-Ru Lin i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 48609d8cc0c7d05aa294aeebea8dcbb9111aefc1e1Cheng-Ru Lin | Intent.FLAG_ACTIVITY_CLEAR_TOP); 49b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project context.startActivity(i); 50b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project } 51b64d345c9d51cabce43b5191532a0c185d2a70a5The Android Open Source Project} 52