• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2008 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.camera;
18 
19 import android.app.Activity;
20 import android.content.ActivityNotFoundException;
21 import android.content.Intent;
22 import android.provider.MediaStore;
23 import android.util.Log;
24 import android.view.Menu;
25 import android.view.MenuItem;
26 import android.view.MenuItem.OnMenuItemClickListener;
27 
28 
29 /**
30  * A utility class to handle various kinds of menu operations.
31  */
32 public class MenuHelper {
33     private static final String TAG = "MenuHelper";
34 
35     // TODO: These should be public and added to frameworks.
36     private static final int INCLUDE_IMAGES = (1 << 0);
37     private static final int INCLUDE_VIDEOS = (1 << 2);
38 
39     private static final String CAMERA_CLASS = "com.android.camera.Camera";
40     private static final String PANORAMA_CLASS = "com.android.camera.PanoramaActivity";
41     private static final String VIDEO_CAMERA_CLASS = "com.android.camera.VideoCamera";
42 
startCameraActivity(Activity activity, Intent intent, String className)43     private static void startCameraActivity(Activity activity, Intent intent,
44             String className) {
45         intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
46         intent.addFlags(Intent.FLAG_ACTIVITY_FORWARD_RESULT);
47         intent.setClassName(activity.getPackageName(), className);
48 
49         // Keep the camera instance for a while.
50         // This avoids re-opening the camera and saves time.
51         CameraHolder.instance().keep();
52 
53         try {
54             activity.startActivity(intent);
55         } catch (ActivityNotFoundException e) {
56             intent.setComponent(null);
57             activity.startActivity(intent);
58         }
59         activity.overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out);
60     }
61 
gotoMode(int mode, Activity activity)62     public static void gotoMode(int mode, Activity activity) {
63         String action, className;
64         switch (mode) {
65             case ModePicker.MODE_PANORAMA:
66                 action = PANORAMA_CLASS;
67                 className = PANORAMA_CLASS;
68                 break;
69             case ModePicker.MODE_VIDEO:
70                 action = MediaStore.INTENT_ACTION_VIDEO_CAMERA;
71                 className = VIDEO_CAMERA_CLASS;
72                 break;
73             case ModePicker.MODE_CAMERA:
74                 action = MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA;
75                 className = CAMERA_CLASS;
76                 break;
77             default:
78                 Log.e(TAG, "unknown camera mode:" + mode);
79                 return;
80         }
81         Intent it = new Intent(action);
82         startCameraActivity(activity, it, className);
83     }
84 }
85