├── .gitignore ├── Camera ├── .classpath ├── .directory ├── .project ├── AndroidManifest.xml ├── proguard.cfg ├── project.properties ├── res │ ├── anim │ │ ├── on_screen_hint_enter.xml │ │ └── on_screen_hint_exit.xml │ ├── drawable-hdpi │ │ ├── .directory │ │ ├── border_last_picture_normal.9.png │ │ ├── border_last_picture_pressed.9.png │ │ ├── btn_camera_flashauto_disabled.png │ │ ├── btn_camera_flashauto_normal.png │ │ ├── btn_camera_flashauto_pressed.png │ │ ├── btn_camera_flashauto_selected.png │ │ ├── btn_camera_flashoff_disabled.png │ │ ├── btn_camera_flashoff_normal.png │ │ ├── btn_camera_flashoff_pressed.png │ │ ├── btn_camera_flashoff_selected.png │ │ ├── btn_camera_flashon_disabled.png │ │ ├── btn_camera_flashon_normal.png │ │ ├── btn_camera_flashon_pressed.png │ │ ├── btn_camera_flashon_selected.png │ │ ├── btn_camera_front_disabled.png │ │ ├── btn_camera_front_normal.png │ │ ├── btn_camera_front_pressed.png │ │ ├── btn_camera_front_selected.png │ │ ├── btn_camera_rear_disabled.png │ │ ├── btn_camera_rear_normal.png │ │ ├── btn_camera_rear_pressed.png │ │ ├── btn_camera_rear_selected.png │ │ ├── btn_camera_shoot_bg.png │ │ ├── btn_camera_shoot_disabled.png │ │ ├── btn_camera_shoot_normal.png │ │ ├── btn_camera_shoot_pressed.png │ │ ├── btn_camera_shoot_selected.png │ │ ├── camera_functions_bg.9.png │ │ ├── focus_focus_failed.9.png │ │ ├── focus_focused.9.png │ │ ├── focus_focusing.9.png │ │ ├── grey_bar_vertical.9.png │ │ ├── ic_launcher_quickcam.png │ │ ├── ic_menuselect_camera_facing_back.png │ │ ├── ic_menuselect_camera_facing_front.png │ │ ├── ic_menuselect_off.png │ │ ├── ic_menuselect_on.png │ │ ├── ic_menuselect_wb_auto.png │ │ ├── ic_menuselect_wb_cloudy.png │ │ ├── ic_menuselect_wb_daylight.png │ │ ├── ic_menuselect_wb_fluorescent.png │ │ ├── ic_menuselect_wb_incandescent.png │ │ ├── ic_viewfinder_camera_facing_back.png │ │ ├── ic_viewfinder_camera_facing_front.png │ │ ├── ic_viewfinder_gps_no_signal.png │ │ ├── ic_viewfinder_iconbar.9.png │ │ ├── ic_viewfinder_settings.png │ │ ├── ic_viewfinder_wb_auto.png │ │ ├── ic_viewfinder_wb_cloudy.png │ │ ├── ic_viewfinder_wb_daylight.png │ │ ├── ic_viewfinder_wb_fluorescent.png │ │ ├── ic_viewfinder_wb_incandescent.png │ │ ├── icon_settings.png │ │ ├── menu_popup.9.png │ │ ├── menu_popup_triangle.png │ │ ├── on_screen_hint_frame.9.png │ │ ├── scrollbar_handle_vertical.9.png │ │ ├── zoom_background.9.png │ │ ├── zoom_finetickmark.png │ │ ├── zoom_slider.png │ │ └── zoom_tickmark.png │ ├── drawable-ldpi │ │ └── ic_launcher_quickcam.png │ ├── drawable-mdpi │ │ └── ic_launcher_quickcam.png │ ├── drawable-xhdpi │ │ └── ic_launcher_quickcam.png │ ├── drawable │ │ ├── border_last_picture.xml │ │ ├── btn_camera_flashauto.xml │ │ ├── btn_camera_flashoff.xml │ │ ├── btn_camera_flashon.xml │ │ ├── btn_camera_front.xml │ │ ├── btn_camera_rear.xml │ │ └── btn_camera_shoot.xml │ ├── layout │ │ ├── camera.xml │ │ └── on_screen_hint.xml │ ├── menu │ │ └── menu.xml │ ├── values │ │ ├── arrays.xml │ │ ├── attrs.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── xml │ │ ├── camera_preferences.xml │ │ └── preferences.xml └── src │ └── com │ └── lightbox │ └── android │ └── camera │ ├── BitmapManager.java │ ├── CameraApplication.java │ ├── CameraButtonIntentReceiver.java │ ├── CameraHardwareException.java │ ├── CameraPreference.java │ ├── CameraSettings.java │ ├── ComboPreferences.java │ ├── FocusRectangle.java │ ├── IconIndicator.java │ ├── IconListPreference.java │ ├── ImageManager.java │ ├── IntArray.java │ ├── ListPreference.java │ ├── MenuHelper.java │ ├── NoSearchActivity.java │ ├── OnScreenHint.java │ ├── ParameterUtils.java │ ├── PreferenceGroup.java │ ├── PreferenceInflater.java │ ├── PreviewFrameLayout.java │ ├── RotateImageView.java │ ├── ShutterButton.java │ ├── Switcher.java │ ├── ThumbnailController.java │ ├── Util.java │ ├── activities │ ├── Camera.java │ └── Settings.java │ ├── device │ ├── CameraHolder.java │ ├── GingerbreadCameraHolder.java │ ├── HTCFrontFacingFixGingerbreadCameraHolder.java │ ├── LGOptimus2XCameraHolder.java │ ├── PreGingerbreadCameraHolder.java │ └── SamsungCaptivateGingerbreadCameraHolder.java │ ├── gallery │ ├── BaseImage.java │ ├── BaseImageList.java │ ├── IImage.java │ ├── IImageList.java │ ├── Image.java │ ├── ImageList.java │ ├── ImageListUber.java │ ├── LruCache.java │ ├── VideoList.java │ └── VideoObject.java │ ├── ui │ ├── AbstractIndicator.java │ ├── BasicIndicator.java │ ├── BasicTexture.java │ ├── BitmapTexture.java │ ├── CameraEGLConfigChooser.java │ ├── CameraHeadUpDisplay.java │ ├── CanvasTexture.java │ ├── ColorTexture.java │ ├── GLListView.java │ ├── GLOptionHeader.java │ ├── GLOptionItem.java │ ├── GLOutOfMemoryException.java │ ├── GLRootView.java │ ├── GLView.java │ ├── GpsIndicator.java │ ├── HeadUpDisplay.java │ ├── IndicatorBar.java │ ├── LinearLayout.java │ ├── MeasureHelper.java │ ├── NinePatchChunk.java │ ├── NinePatchTexture.java │ ├── OtherSettingsIndicator.java │ ├── PopupWindow.java │ ├── PreferenceAdapter.java │ ├── RawTexture.java │ ├── ResourceTexture.java │ ├── RestoreSettingsItem.java │ ├── RotatePane.java │ ├── StringTexture.java │ ├── Texture.java │ ├── ZoomController.java │ ├── ZoomControllerListener.java │ └── ZoomIndicator.java │ └── util │ └── MyLocation.java ├── README.md └── README.md~ /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | 15 | # Local configuration file (sdk path, etc) 16 | local.properties 17 | -------------------------------------------------------------------------------- /Camera/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /Camera/.directory: -------------------------------------------------------------------------------- 1 | [Dolphin] 2 | Timestamp=2012,5,9,13,48,3 3 | Version=2 4 | 5 | [Settings] 6 | ShowDotFiles=true 7 | -------------------------------------------------------------------------------- /Camera/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | Camera 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /Camera/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 18 | 19 | 20 | 21 | 26 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /Camera/proguard.cfg: -------------------------------------------------------------------------------- 1 | -optimizationpasses 5 2 | -dontusemixedcaseclassnames 3 | -dontskipnonpubliclibraryclasses 4 | -dontpreverify 5 | -verbose 6 | -optimizations !code/simplification/arithmetic,!field/*,!class/merging/* 7 | 8 | -keep public class * extends android.app.Activity 9 | -keep public class * extends android.app.Application 10 | -keep public class * extends android.app.Service 11 | -keep public class * extends android.content.BroadcastReceiver 12 | -keep public class * extends android.content.ContentProvider 13 | -keep public class * extends android.app.backup.BackupAgentHelper 14 | -keep public class * extends android.preference.Preference 15 | -keep public class com.android.vending.licensing.ILicensingService 16 | 17 | -keepclasseswithmembernames class * { 18 | native ; 19 | } 20 | 21 | -keepclasseswithmembers class * { 22 | public (android.content.Context, android.util.AttributeSet); 23 | } 24 | 25 | -keepclasseswithmembers class * { 26 | public (android.content.Context, android.util.AttributeSet, int); 27 | } 28 | 29 | -keepclassmembers class * extends android.app.Activity { 30 | public void *(android.view.View); 31 | } 32 | 33 | -keepclassmembers enum * { 34 | public static **[] values(); 35 | public static ** valueOf(java.lang.String); 36 | } 37 | 38 | -keep class * implements android.os.Parcelable { 39 | public static final android.os.Parcelable$Creator *; 40 | } 41 | -------------------------------------------------------------------------------- /Camera/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system use, 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | 10 | # Project target. 11 | target=android-14 12 | -------------------------------------------------------------------------------- /Camera/res/anim/on_screen_hint_enter.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 24 | -------------------------------------------------------------------------------- /Camera/res/anim/on_screen_hint_exit.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 24 | -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/.directory: -------------------------------------------------------------------------------- 1 | [Dolphin] 2 | ShowPreview=true 3 | Timestamp=2012,5,8,13,52,42 4 | Version=2 5 | -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/border_last_picture_normal.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/border_last_picture_normal.9.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/border_last_picture_pressed.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/border_last_picture_pressed.9.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_flashauto_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_flashauto_disabled.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_flashauto_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_flashauto_normal.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_flashauto_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_flashauto_pressed.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_flashauto_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_flashauto_selected.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_flashoff_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_flashoff_disabled.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_flashoff_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_flashoff_normal.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_flashoff_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_flashoff_pressed.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_flashoff_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_flashoff_selected.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_flashon_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_flashon_disabled.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_flashon_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_flashon_normal.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_flashon_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_flashon_pressed.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_flashon_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_flashon_selected.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_front_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_front_disabled.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_front_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_front_normal.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_front_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_front_pressed.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_front_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_front_selected.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_rear_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_rear_disabled.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_rear_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_rear_normal.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_rear_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_rear_pressed.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_rear_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_rear_selected.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_shoot_bg.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_shoot_bg.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_shoot_disabled.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_shoot_disabled.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_shoot_normal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_shoot_normal.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_shoot_pressed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_shoot_pressed.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/btn_camera_shoot_selected.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/btn_camera_shoot_selected.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/camera_functions_bg.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/camera_functions_bg.9.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/focus_focus_failed.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/focus_focus_failed.9.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/focus_focused.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/focus_focused.9.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/focus_focusing.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/focus_focusing.9.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/grey_bar_vertical.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/grey_bar_vertical.9.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/ic_launcher_quickcam.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/ic_launcher_quickcam.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/ic_menuselect_camera_facing_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/ic_menuselect_camera_facing_back.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/ic_menuselect_camera_facing_front.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/ic_menuselect_camera_facing_front.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/ic_menuselect_off.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/ic_menuselect_off.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/ic_menuselect_on.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/ic_menuselect_on.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/ic_menuselect_wb_auto.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/ic_menuselect_wb_auto.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/ic_menuselect_wb_cloudy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/ic_menuselect_wb_cloudy.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/ic_menuselect_wb_daylight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/ic_menuselect_wb_daylight.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/ic_menuselect_wb_fluorescent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/ic_menuselect_wb_fluorescent.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/ic_menuselect_wb_incandescent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/ic_menuselect_wb_incandescent.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/ic_viewfinder_camera_facing_back.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/ic_viewfinder_camera_facing_back.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/ic_viewfinder_camera_facing_front.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/ic_viewfinder_camera_facing_front.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/ic_viewfinder_gps_no_signal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/ic_viewfinder_gps_no_signal.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/ic_viewfinder_iconbar.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/ic_viewfinder_iconbar.9.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/ic_viewfinder_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/ic_viewfinder_settings.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/ic_viewfinder_wb_auto.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/ic_viewfinder_wb_auto.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/ic_viewfinder_wb_cloudy.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/ic_viewfinder_wb_cloudy.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/ic_viewfinder_wb_daylight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/ic_viewfinder_wb_daylight.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/ic_viewfinder_wb_fluorescent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/ic_viewfinder_wb_fluorescent.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/ic_viewfinder_wb_incandescent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/ic_viewfinder_wb_incandescent.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/icon_settings.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/icon_settings.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/menu_popup.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/menu_popup.9.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/menu_popup_triangle.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/menu_popup_triangle.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/on_screen_hint_frame.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/on_screen_hint_frame.9.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/scrollbar_handle_vertical.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/scrollbar_handle_vertical.9.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/zoom_background.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/zoom_background.9.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/zoom_finetickmark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/zoom_finetickmark.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/zoom_slider.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/zoom_slider.png -------------------------------------------------------------------------------- /Camera/res/drawable-hdpi/zoom_tickmark.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-hdpi/zoom_tickmark.png -------------------------------------------------------------------------------- /Camera/res/drawable-ldpi/ic_launcher_quickcam.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-ldpi/ic_launcher_quickcam.png -------------------------------------------------------------------------------- /Camera/res/drawable-mdpi/ic_launcher_quickcam.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-mdpi/ic_launcher_quickcam.png -------------------------------------------------------------------------------- /Camera/res/drawable-xhdpi/ic_launcher_quickcam.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lightbox/QuickSnap/d226fda62359457aa473c5755ce385f0021b0641/Camera/res/drawable-xhdpi/ic_launcher_quickcam.png -------------------------------------------------------------------------------- /Camera/res/drawable/border_last_picture.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /Camera/res/drawable/btn_camera_flashauto.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 9 | 10 | 12 | 13 | 15 | 16 | 18 | 19 | 21 | 22 | -------------------------------------------------------------------------------- /Camera/res/drawable/btn_camera_flashoff.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 9 | 10 | 12 | 13 | 15 | 16 | 18 | 19 | 21 | 22 | -------------------------------------------------------------------------------- /Camera/res/drawable/btn_camera_flashon.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 9 | 10 | 12 | 13 | 15 | 16 | 18 | 19 | 21 | 22 | -------------------------------------------------------------------------------- /Camera/res/drawable/btn_camera_front.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 9 | 10 | 12 | 13 | 15 | 16 | 18 | 19 | 21 | 22 | -------------------------------------------------------------------------------- /Camera/res/drawable/btn_camera_rear.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 9 | 10 | 12 | 13 | 15 | 16 | 18 | 19 | 21 | 22 | -------------------------------------------------------------------------------- /Camera/res/drawable/btn_camera_shoot.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 7 | 9 | 11 | 13 | 15 | 17 | 18 | -------------------------------------------------------------------------------- /Camera/res/layout/camera.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 17 | 18 | 22 | 23 | 27 | 28 | 32 | 33 | 34 | 35 | 40 | 41 | 45 | 46 | 47 | 54 | 55 | 66 | 67 | 68 | 77 | 78 | 88 | 89 | 97 | 98 | 106 | 107 | 108 | 109 | 113 | 114 | -------------------------------------------------------------------------------- /Camera/res/layout/on_screen_hint.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 20 | 25 | 26 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /Camera/res/menu/menu.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 7 | -------------------------------------------------------------------------------- /Camera/res/values/arrays.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | @string/pref_camera_focusmode_entry_auto 7 | @string/pref_camera_focusmode_entry_infinity 8 | @string/pref_camera_focusmode_entry_macro 9 | 10 | 11 | 12 | auto 13 | infinity 14 | macro 15 | 16 | 17 | 18 | auto 19 | on 20 | off 21 | 22 | 23 | 24 | 25 | @string/pref_camera_whitebalance_entry_auto 26 | @string/pref_camera_whitebalance_entry_incandescent 27 | @string/pref_camera_whitebalance_entry_daylight 28 | @string/pref_camera_whitebalance_entry_fluorescent 29 | @string/pref_camera_whitebalance_entry_cloudy 30 | 31 | 32 | 33 | auto 34 | incandescent 35 | daylight 36 | fluorescent 37 | cloudy-daylight 38 | 39 | 40 | 41 | @drawable/ic_menuselect_wb_auto 42 | @drawable/ic_menuselect_wb_incandescent 43 | @drawable/ic_menuselect_wb_daylight 44 | @drawable/ic_menuselect_wb_fluorescent 45 | @drawable/ic_menuselect_wb_cloudy 46 | 47 | 48 | 49 | @drawable/ic_viewfinder_wb_auto 50 | @drawable/ic_viewfinder_wb_incandescent 51 | @drawable/ic_viewfinder_wb_daylight 52 | @drawable/ic_viewfinder_wb_fluorescent 53 | @drawable/ic_viewfinder_wb_cloudy 54 | 55 | 56 | 57 | 58 | @string/pref_camera_scenemode_entry_auto 59 | @string/pref_camera_scenemode_entry_action 60 | @string/pref_camera_scenemode_entry_portrait 61 | @string/pref_camera_scenemode_entry_landscape 62 | @string/pref_camera_scenemode_entry_night 63 | @string/pref_camera_scenemode_entry_night_portrait 64 | @string/pref_camera_scenemode_entry_theatre 65 | @string/pref_camera_scenemode_entry_beach 66 | @string/pref_camera_scenemode_entry_snow 67 | @string/pref_camera_scenemode_entry_sunset 68 | @string/pref_camera_scenemode_entry_steadyphoto 69 | @string/pref_camera_scenemode_entry_fireworks 70 | @string/pref_camera_scenemode_entry_party 71 | @string/pref_camera_scenemode_entry_candlelight 72 | 73 | 74 | 75 | auto 76 | action 77 | portrait 78 | landscape 79 | night 80 | night-portrait 81 | theatre 82 | beach 83 | snow 84 | sunset 85 | steadyphoto 86 | fireworks 87 | party 88 | candlelight 89 | 90 | 91 | -------------------------------------------------------------------------------- /Camera/res/values/attrs.xml: -------------------------------------------------------------------------------- 1 | 2 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /Camera/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 20 | 21 | 64dip 22 | 23 | -------------------------------------------------------------------------------- /Camera/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 12 | 17 | 21 | 29 | 35 | -------------------------------------------------------------------------------- /Camera/res/xml/camera_preferences.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 5 | 7 | 13 | 17 | 23 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /Camera/res/xml/preferences.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | 13 | 14 | 19 | 20 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/BitmapManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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.lightbox.android.camera; 18 | 19 | import android.content.ContentResolver; 20 | import android.graphics.Bitmap; 21 | import android.graphics.BitmapFactory; 22 | import android.provider.MediaStore.Images; 23 | import android.provider.MediaStore.Video; 24 | import android.util.Log; 25 | 26 | import java.io.FileDescriptor; 27 | import java.util.WeakHashMap; 28 | 29 | import com.lightbox.android.camera.BitmapManager; 30 | 31 | /** 32 | * Provides utilities to decode bitmap, get thumbnail, and cancel the 33 | * operations. 34 | * 35 | *

The function {@link #decodeFileDescriptor(FileDescriptor, 36 | * BitmapFactory.Options)} is used to decode a bitmap. During decoding another 37 | * thread can cancel it using the function {@link #cancelThreadDecoding(Thread, 38 | * ContentResolver)} specifying the {@code Thread} which is in decoding. 39 | * 40 | *

{@code cancelThreadDecoding(Thread,ContentResolver)} is sticky until 41 | * {@code allowThreadDecoding(Thread) } is called. 42 | */ 43 | public class BitmapManager { 44 | private static final String TAG = "BitmapManager"; 45 | private static enum State {CANCEL, ALLOW} 46 | private static class ThreadStatus { 47 | public State mState = State.ALLOW; 48 | public BitmapFactory.Options mOptions; 49 | 50 | @Override 51 | public String toString() { 52 | String s; 53 | if (mState == State.CANCEL) { 54 | s = "Cancel"; 55 | } else if (mState == State.ALLOW) { 56 | s = "Allow"; 57 | } else { 58 | s = "?"; 59 | } 60 | s = "thread state = " + s + ", options = " + mOptions; 61 | return s; 62 | } 63 | } 64 | 65 | private final WeakHashMap mThreadStatus = 66 | new WeakHashMap(); 67 | 68 | private static BitmapManager sManager = null; 69 | 70 | private BitmapManager() { 71 | } 72 | 73 | /** 74 | * Get thread status and create one if specified. 75 | */ 76 | private synchronized ThreadStatus getOrCreateThreadStatus(Thread t) { 77 | ThreadStatus status = mThreadStatus.get(t); 78 | if (status == null) { 79 | status = new ThreadStatus(); 80 | mThreadStatus.put(t, status); 81 | } 82 | return status; 83 | } 84 | 85 | public synchronized boolean canThreadDecoding(Thread t) { 86 | ThreadStatus status = mThreadStatus.get(t); 87 | if (status == null) { 88 | // allow decoding by default 89 | return true; 90 | } 91 | 92 | boolean result = (status.mState != State.CANCEL); 93 | return result; 94 | } 95 | 96 | /** 97 | * Gets the thumbnail of the given ID of the original image. 98 | * 99 | *

This method wraps around @{code getThumbnail} in {@code 100 | * android.provider.MediaStore}. It provides the ability to cancel it. 101 | */ 102 | public Bitmap getThumbnail(ContentResolver cr, long origId, int kind, 103 | BitmapFactory.Options options, boolean isVideo) { 104 | Thread t = Thread.currentThread(); 105 | ThreadStatus status = getOrCreateThreadStatus(t); 106 | 107 | if (!canThreadDecoding(t)) { 108 | Log.d(TAG, "Thread " + t + " is not allowed to decode."); 109 | return null; 110 | } 111 | 112 | try { 113 | if (isVideo) { 114 | return Video.Thumbnails.getThumbnail(cr, origId, /*t.getId(),*/ 115 | kind, null); 116 | } else { 117 | return Images.Thumbnails.getThumbnail(cr, origId, /*t.getId(),*/ 118 | kind, null); 119 | } 120 | } finally { 121 | synchronized (status) { 122 | status.notifyAll(); 123 | } 124 | } 125 | } 126 | 127 | public static synchronized BitmapManager instance() { 128 | if (sManager == null) { 129 | sManager = new BitmapManager(); 130 | } 131 | return sManager; 132 | } 133 | } 134 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/CameraApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Lightbox 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.lightbox.android.camera; 18 | 19 | import java.io.IOException; 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | import java.util.Locale; 23 | 24 | import android.app.Application; 25 | import android.content.Context; 26 | import android.location.Address; 27 | import android.location.Geocoder; 28 | import android.view.OrientationEventListener; 29 | 30 | import com.lightbox.android.camera.util.MyLocation; 31 | import com.lightbox.android.camera.util.MyLocation.LocationResult; 32 | 33 | /** 34 | * CameraApplication 35 | * @author Nilesh Patel 36 | */ 37 | public class CameraApplication extends Application { 38 | /** Used to tag logs */ 39 | @SuppressWarnings("unused") 40 | private static final String TAG = "CameraApplication"; 41 | 42 | public static final int JPEG_HIGH_QUALITY = 90; 43 | 44 | private MyOrientationEventListener mOrientationEventListener; 45 | private long mLocationLastUpdateTime = 0; 46 | private ArrayList mOrientationChangeListeners = new ArrayList(); 47 | private int mLastKnownOrientation = -1; 48 | 49 | // Current location & nearby places 50 | public double lat = 0; 51 | public double lng = 0; 52 | public String locStr = ""; 53 | 54 | @Override 55 | public void onCreate() { 56 | super.onCreate(); 57 | 58 | mOrientationEventListener = new MyOrientationEventListener(getApplicationContext()); 59 | mOrientationEventListener.enable(); 60 | } 61 | 62 | public void registerOrientationChangeListener(OrientationChangeListener listener) { 63 | mOrientationChangeListeners.add(listener); 64 | } 65 | 66 | public void deregisterOrientationChangeListener(OrientationChangeListener listener) { 67 | mOrientationChangeListeners.remove(listener); 68 | } 69 | 70 | public interface OrientationChangeListener { 71 | public void onOrientationChanged(int orientation); 72 | } 73 | 74 | public int getLastKnownOrientation() { 75 | return mLastKnownOrientation; 76 | } 77 | 78 | public void requestLocationUpdate(boolean forceUpdate) { 79 | // Only request the location once an hour unless forceUpdate is set 80 | if (!forceUpdate && (System.currentTimeMillis() - mLocationLastUpdateTime < 1000 * 60 * 60)) { 81 | return; 82 | } 83 | 84 | mLocationLastUpdateTime = System.currentTimeMillis(); 85 | 86 | MyLocation myLocation = new MyLocation(this); 87 | myLocation.requestCurrentLocation(new LocationResult() { 88 | @Override 89 | public void gotLocation(final android.location.Location location) { 90 | Thread thread = new Thread(new Runnable() { 91 | @Override 92 | public void run() { 93 | updateWithNewLocation(location); 94 | } 95 | }); 96 | thread.start(); 97 | } 98 | }); 99 | } 100 | 101 | public void setLocation(double _lat, double _lng, String _locStr) { 102 | lat = _lat; 103 | lng = _lng; 104 | locStr = _locStr; 105 | } 106 | 107 | public void updateWithNewLocation(android.location.Location loc) { 108 | String locStr; 109 | 110 | if (loc != null) { 111 | double lat = loc.getLatitude(); 112 | double lng = loc.getLongitude(); 113 | String addrStr = ""; 114 | 115 | Geocoder gc = new Geocoder(this, Locale.getDefault()); 116 | try { 117 | List

addresses = gc.getFromLocation(lat, lng, 1); 118 | StringBuilder sb = new StringBuilder(); 119 | if (addresses.size() > 0) { 120 | Address addr = addresses.get(0); 121 | 122 | for (int i = 0; i < addr.getMaxAddressLineIndex() && i < 1; i++) { 123 | sb.append(addr.getAddressLine(i) + " "); 124 | } 125 | addrStr = sb.toString(); 126 | } 127 | } catch (IOException e) { 128 | } 129 | 130 | locStr = addrStr; 131 | 132 | this.lat = lat; 133 | this.lng = lng; 134 | } else { 135 | locStr = "Location not found"; 136 | 137 | this.lat = 0; 138 | this.lng = 0; 139 | } 140 | this.locStr = locStr; 141 | } 142 | 143 | 144 | //---------------------------------------------- 145 | // MyOrientationEventListener 146 | 147 | public class MyOrientationEventListener extends OrientationEventListener { 148 | public MyOrientationEventListener(Context context) { 149 | super(context); 150 | } 151 | 152 | @Override 153 | public void onOrientationChanged(int orientation) { 154 | mLastKnownOrientation = orientation; 155 | for (OrientationChangeListener listener : mOrientationChangeListeners) { 156 | listener.onOrientationChanged(orientation); 157 | } 158 | } 159 | } 160 | } 161 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/CameraButtonIntentReceiver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2007 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.lightbox.android.camera; 18 | 19 | import com.lightbox.android.camera.CameraSettings; 20 | import com.lightbox.android.camera.ComboPreferences; 21 | import com.lightbox.android.camera.activities.Camera; 22 | import com.lightbox.android.camera.device.CameraHolder; 23 | 24 | import android.content.BroadcastReceiver; 25 | import android.content.Context; 26 | import android.content.Intent; 27 | 28 | /** 29 | * {@code CameraButtonIntentReceiver} is invoked when the camera button is 30 | * long-pressed. 31 | * 32 | * It is declared in {@code AndroidManifest.xml} to receive the 33 | * {@code android.intent.action.CAMERA_BUTTON} intent. 34 | * 35 | * After making sure we can use the camera hardware, it starts the Camera 36 | * activity. 37 | */ 38 | public class CameraButtonIntentReceiver extends BroadcastReceiver { 39 | 40 | @Override 41 | public void onReceive(Context context, Intent intent) { 42 | // Try to get the camera hardware 43 | CameraHolder holder = CameraHolder.instance(); 44 | ComboPreferences pref = new ComboPreferences(context); 45 | int cameraId = CameraSettings.readPreferredCameraId(pref); 46 | if (holder.tryOpen(cameraId) == null) return; 47 | 48 | // We are going to launch the camera, so hold the camera for later use 49 | holder.keep(); 50 | holder.release(); 51 | Intent i = new Intent(Intent.ACTION_MAIN); 52 | i.setClass(context, Camera.class); 53 | i.addCategory(Intent.CATEGORY_LAUNCHER); 54 | i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK 55 | | Intent.FLAG_ACTIVITY_CLEAR_TOP); 56 | context.startActivity(i); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/CameraHardwareException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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.lightbox.android.camera; 18 | 19 | /** 20 | * This class represents the condition that we cannot open the camera hardware 21 | * successfully. For example, another process is using the camera. 22 | */ 23 | @SuppressWarnings("serial") 24 | public class CameraHardwareException extends Exception { 25 | 26 | public CameraHardwareException(Throwable t) { 27 | super(t); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/CameraPreference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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.lightbox.android.camera; 18 | 19 | import android.content.Context; 20 | import android.content.SharedPreferences; 21 | import android.content.res.TypedArray; 22 | import android.util.AttributeSet; 23 | 24 | import com.lightbox.android.camera.ComboPreferences; 25 | import com.lightbox.android.camera.R; 26 | 27 | /** 28 | * The base class of all Preferences used in Camera. The preferences can be 29 | * loaded from XML resource by PreferenceInflater. 30 | */ 31 | public abstract class CameraPreference { 32 | 33 | private final String mTitle; 34 | private SharedPreferences mSharedPreferences; 35 | private final Context mContext; 36 | 37 | public CameraPreference(Context context, AttributeSet attrs) { 38 | mContext = context; 39 | TypedArray a = context.obtainStyledAttributes( 40 | attrs, R.styleable.CameraPreference, 0, 0); 41 | mTitle = a.getString(R.styleable.CameraPreference_title); 42 | a.recycle(); 43 | } 44 | 45 | public String getTitle() { 46 | return mTitle; 47 | } 48 | 49 | public SharedPreferences getSharedPreferences() { 50 | if (mSharedPreferences == null) { 51 | mSharedPreferences = ComboPreferences.get(mContext); 52 | } 53 | return mSharedPreferences; 54 | } 55 | 56 | public abstract void reloadValue(); 57 | } 58 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/FocusRectangle.java: -------------------------------------------------------------------------------- 1 | package com.lightbox.android.camera; 2 | 3 | import com.lightbox.android.camera.R; 4 | 5 | import android.content.Context; 6 | import android.util.AttributeSet; 7 | import android.view.View; 8 | 9 | public class FocusRectangle extends View { 10 | 11 | @SuppressWarnings("unused") 12 | private static final String TAG = "FocusRectangle"; 13 | 14 | public FocusRectangle(Context context, AttributeSet attrs) { 15 | super(context, attrs); 16 | } 17 | 18 | private void setDrawable(int resid) { 19 | setBackgroundDrawable(getResources().getDrawable(resid)); 20 | } 21 | 22 | public void showStart() { 23 | setDrawable(R.drawable.focus_focusing); 24 | } 25 | 26 | public void showSuccess() { 27 | setDrawable(R.drawable.focus_focused); 28 | } 29 | 30 | public void showFail() { 31 | setDrawable(R.drawable.focus_focus_failed); 32 | } 33 | 34 | public void clear() { 35 | setBackgroundDrawable(null); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/IconIndicator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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.lightbox.android.camera; 18 | 19 | import com.lightbox.android.camera.R; 20 | 21 | import android.content.Context; 22 | import android.content.res.Resources; 23 | import android.content.res.TypedArray; 24 | import android.graphics.drawable.Drawable; 25 | import android.util.AttributeSet; 26 | import android.widget.ImageView; 27 | 28 | 29 | /** 30 | * This class draws an icon which changes according to the mode. For example, 31 | * The flash icon can have on, off, and auto modes. The user can use 32 | * {@link #setMode(String)} to change the mode (and the icon). 33 | */ 34 | public class IconIndicator extends ImageView { 35 | 36 | private Drawable[] mIcons; 37 | private CharSequence[] mModes; 38 | 39 | public IconIndicator(Context context, AttributeSet attrs, int defStyle) { 40 | super(context, attrs, defStyle); 41 | TypedArray a = context.obtainStyledAttributes( 42 | attrs, R.styleable.IconIndicator, defStyle, 0); 43 | Drawable icons[] = loadIcons(context.getResources(), 44 | a.getResourceId(R.styleable.IconIndicator_icons, 0)); 45 | CharSequence modes[] = 46 | a.getTextArray(R.styleable.IconIndicator_modes); 47 | a.recycle(); 48 | 49 | setModesAndIcons(modes, icons); 50 | setImageDrawable(mIcons.length > 0 ? mIcons[0] : null); 51 | } 52 | 53 | public IconIndicator(Context context, AttributeSet attrs) { 54 | this(context, attrs, 0); 55 | } 56 | 57 | private Drawable[] loadIcons(Resources resources, int iconsId) { 58 | TypedArray array = resources.obtainTypedArray(iconsId); 59 | int n = array.length(); 60 | Drawable drawable[] = new Drawable[n]; 61 | for (int i = 0; i < n; ++i) { 62 | int id = array.getResourceId(i, 0); 63 | drawable[i] = id == 0 ? null : resources.getDrawable(id); 64 | } 65 | array.recycle(); 66 | return drawable; 67 | } 68 | 69 | private void setModesAndIcons(CharSequence[] modes, Drawable icons[]) { 70 | if (modes.length != icons.length || icons.length == 0) { 71 | throw new IllegalArgumentException(); 72 | } 73 | mIcons = icons; 74 | mModes = modes; 75 | } 76 | 77 | public void setMode(String mode) { 78 | for (int i = 0, n = mModes.length; i < n; ++i) { 79 | if (mModes[i].equals(mode)) { 80 | setImageDrawable(mIcons[i]); 81 | return; 82 | } 83 | } 84 | throw new IllegalArgumentException("unknown mode: " + mode); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/IconListPreference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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.lightbox.android.camera; 18 | 19 | import android.content.Context; 20 | import android.content.res.Resources; 21 | import android.content.res.TypedArray; 22 | import android.util.AttributeSet; 23 | 24 | import com.lightbox.android.camera.IntArray; 25 | import com.lightbox.android.camera.ListPreference; 26 | import com.lightbox.android.camera.R; 27 | 28 | import java.util.List; 29 | 30 | /** A {@code ListPreference} where each entry has a corresponding icon. */ 31 | public class IconListPreference extends ListPreference { 32 | 33 | private int mIconIds[]; 34 | private int mLargeIconIds[]; 35 | 36 | public IconListPreference(Context context, AttributeSet attrs) { 37 | super(context, attrs); 38 | TypedArray a = context.obtainStyledAttributes( 39 | attrs, R.styleable.IconListPreference, 0, 0); 40 | Resources res = context.getResources(); 41 | mIconIds = getIconIds(res, a.getResourceId( 42 | R.styleable.IconListPreference_icons, 0)); 43 | mLargeIconIds = getIconIds(res, a.getResourceId( 44 | R.styleable.IconListPreference_largeIcons, 0)); 45 | a.recycle(); 46 | } 47 | 48 | public int[] getLargeIconIds() { 49 | return mLargeIconIds; 50 | } 51 | 52 | public int[] getIconIds() { 53 | return mIconIds; 54 | } 55 | 56 | public void setLargeIconIds(int[] largeIconIds) { 57 | mLargeIconIds = largeIconIds; 58 | } 59 | 60 | public void setIconIds(int[] iconIds) { 61 | mIconIds = iconIds; 62 | } 63 | 64 | private int[] getIconIds(Resources res, int iconsRes) { 65 | if (iconsRes == 0) return null; 66 | TypedArray array = res.obtainTypedArray(iconsRes); 67 | int n = array.length(); 68 | int ids[] = new int[n]; 69 | for (int i = 0; i < n; ++i) { 70 | ids[i] = array.getResourceId(i, 0); 71 | } 72 | array.recycle(); 73 | return ids; 74 | } 75 | 76 | @Override 77 | public void filterUnsupported(List supported) { 78 | CharSequence entryValues[] = getEntryValues(); 79 | IntArray iconIds = new IntArray(); 80 | IntArray largeIconIds = new IntArray(); 81 | 82 | for (int i = 0, len = entryValues.length; i < len; i++) { 83 | if (supported.indexOf(entryValues[i].toString()) >= 0) { 84 | iconIds.add(mIconIds[i]); 85 | largeIconIds.add(mLargeIconIds[i]); 86 | } 87 | } 88 | int size = iconIds.size(); 89 | mIconIds = iconIds.toArray(new int[size]); 90 | mLargeIconIds = iconIds.toArray(new int[size]); 91 | super.filterUnsupported(supported); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/IntArray.java: -------------------------------------------------------------------------------- 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.lightbox.android.camera; 18 | 19 | public class IntArray { 20 | private static final int INIT_CAPACITY = 8; 21 | 22 | private int mData[] = new int[INIT_CAPACITY]; 23 | private int mSize = 0; 24 | 25 | public void add(int value) { 26 | if (mData.length == mSize) { 27 | int temp[] = new int[mSize + mSize]; 28 | System.arraycopy(mData, 0, temp, 0, mSize); 29 | mData = temp; 30 | } 31 | mData[mSize++] = value; 32 | } 33 | 34 | public int size() { 35 | return mSize; 36 | } 37 | 38 | public int[] toArray(int[] result) { 39 | if (result == null || result.length < mSize) { 40 | result = new int[mSize]; 41 | } 42 | System.arraycopy(mData, 0, result, 0, mSize); 43 | return result; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ListPreference.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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.lightbox.android.camera; 18 | 19 | import android.content.Context; 20 | import android.content.SharedPreferences; 21 | import android.content.res.TypedArray; 22 | import android.util.AttributeSet; 23 | 24 | import com.lightbox.android.camera.CameraPreference; 25 | import com.lightbox.android.camera.Util; 26 | import com.lightbox.android.camera.R; 27 | 28 | import java.util.ArrayList; 29 | import java.util.List; 30 | 31 | /** 32 | * A type of CameraPreference whose number of possible values 33 | * is limited. 34 | */ 35 | public class ListPreference extends CameraPreference { 36 | 37 | private final String mKey; 38 | private String mValue; 39 | private final String mDefaultValue; 40 | 41 | private CharSequence[] mEntries; 42 | private CharSequence[] mEntryValues; 43 | private boolean mLoaded = false; 44 | 45 | public ListPreference(Context context, AttributeSet attrs) { 46 | super(context, attrs); 47 | 48 | TypedArray a = context.obtainStyledAttributes( 49 | attrs, R.styleable.ListPreference, 0, 0); 50 | 51 | mKey = Util.checkNotNull( 52 | a.getString(R.styleable.ListPreference_key)); 53 | mDefaultValue = a.getString(R.styleable.ListPreference_defaultValue); 54 | 55 | setEntries(a.getTextArray(R.styleable.ListPreference_entries)); 56 | setEntryValues(a.getTextArray( 57 | R.styleable.ListPreference_entryValues)); 58 | a.recycle(); 59 | } 60 | 61 | public String getKey() { 62 | return mKey; 63 | } 64 | 65 | public CharSequence[] getEntries() { 66 | return mEntries; 67 | } 68 | 69 | public CharSequence[] getEntryValues() { 70 | return mEntryValues; 71 | } 72 | 73 | public void setEntries(CharSequence entries[]) { 74 | mEntries = entries == null ? new CharSequence[0] : entries; 75 | } 76 | 77 | public void setEntryValues(CharSequence values[]) { 78 | mEntryValues = values == null ? new CharSequence[0] : values; 79 | } 80 | 81 | public String getValue() { 82 | if (!mLoaded) { 83 | mValue = getSharedPreferences().getString(mKey, mDefaultValue); 84 | mLoaded = true; 85 | } 86 | return mValue; 87 | } 88 | 89 | public void setValue(String value) { 90 | if (findIndexOfValue(value) < 0) throw new IllegalArgumentException(); 91 | mValue = value; 92 | persistStringValue(value); 93 | } 94 | 95 | public void setValueIndex(int index) { 96 | setValue(mEntryValues[index].toString()); 97 | } 98 | 99 | public int findIndexOfValue(String value) { 100 | for (int i = 0, n = mEntryValues.length; i < n; ++i) { 101 | if (Util.equals(mEntryValues[i], value)) return i; 102 | } 103 | return -1; 104 | } 105 | 106 | public String getEntry() { 107 | return mEntries[findIndexOfValue(getValue())].toString(); 108 | } 109 | 110 | protected void persistStringValue(String value) { 111 | SharedPreferences.Editor editor = getSharedPreferences().edit(); 112 | editor.putString(mKey, value); 113 | editor.commit(); 114 | } 115 | 116 | @Override 117 | public void reloadValue() { 118 | this.mLoaded = false; 119 | } 120 | 121 | public void filterUnsupported(List supported) { 122 | ArrayList entries = new ArrayList(); 123 | ArrayList entryValues = new ArrayList(); 124 | for (int i = 0, len = mEntryValues.length; i < len; i++) { 125 | if (supported.indexOf(mEntryValues[i].toString()) >= 0) { 126 | entries.add(mEntries[i]); 127 | entryValues.add(mEntryValues[i]); 128 | } 129 | } 130 | int size = entries.size(); 131 | mEntries = entries.toArray(new CharSequence[size]); 132 | mEntryValues = entryValues.toArray(new CharSequence[size]); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/NoSearchActivity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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.lightbox.android.camera; 18 | 19 | import android.app.Activity; 20 | 21 | /** 22 | * An activity which disables the search key function. 23 | * 24 | *

To use it, just inherit from {@code NoSearchActivity} instead of 25 | * {@code Activity}. 26 | */ 27 | public class NoSearchActivity extends Activity { 28 | @Override 29 | public boolean onSearchRequested() { 30 | return false; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ParameterUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Lightbox 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.lightbox.android.camera; 18 | 19 | import android.hardware.Camera.Parameters; 20 | 21 | public class ParameterUtils { 22 | private static final String KEY_EXPOSURE_COMPENSATION = "exposure-compensation"; 23 | private static final String KEY_MAX_EXPOSURE_COMPENSATION = "max-exposure-compensation"; 24 | private static final String KEY_MIN_EXPOSURE_COMPENSATION = "min-exposure-compensation"; 25 | private static final String KEY_EXPOSURE_COMPENSATION_STEP = "exposure-compensation-step"; 26 | 27 | private static final String KEY_ZOOM = "zoom"; 28 | private static final String KEY_MAX_ZOOM = "max-zoom"; 29 | private static final String KEY_ZOOM_RATIOS = "zoom-ratios"; 30 | private static final String KEY_ZOOM_SUPPORTED = "zoom-supported"; 31 | private static final String KEY_SMOOTH_ZOOM_SUPPORTED = "smooth-zoom-supported"; 32 | 33 | public static final String FOCUS_MODE_EDOF = "edof"; 34 | 35 | private static final String KEY_GPS_PROCESSING_METHOD = "gps-processing-method"; 36 | 37 | private static final String TRUE = "true"; 38 | 39 | public static int getMaxExposureCompensation(Parameters parameters) { 40 | String str = parameters.get(KEY_MAX_EXPOSURE_COMPENSATION); 41 | if (str != null) { 42 | try { 43 | return Integer.parseInt(str); 44 | } catch (NumberFormatException e) { 45 | return 0; 46 | } 47 | } 48 | return 0; 49 | } 50 | 51 | public static int getMinExposureCompensation(Parameters parameters) { 52 | String str = parameters.get(KEY_MIN_EXPOSURE_COMPENSATION); 53 | if (str != null) { 54 | try { 55 | return Integer.parseInt(str); 56 | } catch (NumberFormatException e) { 57 | return 0; 58 | } 59 | } 60 | return 0; 61 | } 62 | 63 | public static float getExposureCompensationStep(Parameters parameters) { 64 | String str = parameters.get(KEY_EXPOSURE_COMPENSATION_STEP); 65 | if (str != null) { 66 | try { 67 | return Float.parseFloat(str); 68 | } catch (NumberFormatException e) { 69 | return 0; 70 | } 71 | } 72 | return 0; 73 | } 74 | 75 | public static void setExposureCompensation(Parameters parameters, int value) { 76 | parameters.set(KEY_EXPOSURE_COMPENSATION, value); 77 | } 78 | 79 | public static boolean isZoomSupported(Parameters parameters) { 80 | String str = parameters.get(KEY_ZOOM_SUPPORTED); 81 | return (str != null && TRUE.equals(str)); 82 | } 83 | 84 | public static void setZoom(Parameters parameters, int value) { 85 | parameters.set(KEY_ZOOM, value); 86 | } 87 | 88 | public static void setGpsProcessingMethod(Parameters parameters, String processing_method) { 89 | parameters.set(KEY_GPS_PROCESSING_METHOD, processing_method); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/PreferenceGroup.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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.lightbox.android.camera; 18 | 19 | import java.util.ArrayList; 20 | 21 | import com.lightbox.android.camera.CameraPreference; 22 | import com.lightbox.android.camera.ListPreference; 23 | import com.lightbox.android.camera.PreferenceGroup; 24 | 25 | import android.content.Context; 26 | import android.util.AttributeSet; 27 | 28 | /** 29 | * A collection of CameraPreferences. It may contain other 30 | * PreferenceGroup and form a tree structure. 31 | */ 32 | public class PreferenceGroup extends CameraPreference { 33 | private ArrayList list = 34 | new ArrayList(); 35 | 36 | public PreferenceGroup(Context context, AttributeSet attrs) { 37 | super(context, attrs); 38 | } 39 | 40 | public void addChild(CameraPreference child) { 41 | list.add(child); 42 | } 43 | 44 | public void removePreference(int index) { 45 | list.remove(index); 46 | } 47 | 48 | public CameraPreference get(int index) { 49 | return list.get(index); 50 | } 51 | 52 | public int size() { 53 | return list.size(); 54 | } 55 | 56 | @Override 57 | public void reloadValue() { 58 | for (CameraPreference pref : list) { 59 | pref.reloadValue(); 60 | } 61 | } 62 | 63 | /** 64 | * Finds the preference with the given key recursively. Returns 65 | * null if cannot find. 66 | */ 67 | public ListPreference findPreference(String key) { 68 | // Find a leaf preference with the given key. Currently, the base 69 | // type of all "leaf" preference is "ListPreference". If we add some 70 | // other types later, we need to change the code. 71 | for (CameraPreference pref : list) { 72 | if (pref instanceof ListPreference) { 73 | ListPreference listPref = (ListPreference) pref; 74 | if(listPref.getKey().equals(key)) return listPref; 75 | } else if(pref instanceof PreferenceGroup) { 76 | ListPreference listPref = 77 | ((PreferenceGroup) pref).findPreference(key); 78 | if (listPref != null) return listPref; 79 | } 80 | } 81 | return null; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/PreferenceInflater.java: -------------------------------------------------------------------------------- 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.lightbox.android.camera; 18 | 19 | import org.xmlpull.v1.XmlPullParser; 20 | import org.xmlpull.v1.XmlPullParserException; 21 | 22 | import com.lightbox.android.camera.CameraPreference; 23 | import com.lightbox.android.camera.PreferenceGroup; 24 | import com.lightbox.android.camera.PreferenceInflater; 25 | 26 | import java.io.IOException; 27 | import java.lang.reflect.Constructor; 28 | import java.util.ArrayList; 29 | import java.util.HashMap; 30 | 31 | import android.content.Context; 32 | import android.util.AttributeSet; 33 | import android.util.Xml; 34 | import android.view.InflateException; 35 | 36 | /** 37 | * Inflate CameraPreference from XML resource. 38 | */ 39 | public class PreferenceInflater { 40 | private static final String PACKAGE_NAME = 41 | PreferenceInflater.class.getPackage().getName(); 42 | 43 | private static final Class[] CTOR_SIGNATURE = 44 | new Class[] {Context.class, AttributeSet.class}; 45 | private static final HashMap> sConstructorMap = 46 | new HashMap>(); 47 | 48 | private Context mContext; 49 | 50 | public PreferenceInflater(Context context) { 51 | mContext = context; 52 | } 53 | 54 | public CameraPreference inflate(int resId) { 55 | return inflate(mContext.getResources().getXml(resId)); 56 | } 57 | 58 | private CameraPreference newPreference(String tagName, Object[] args) { 59 | String name = PACKAGE_NAME + "." + tagName; 60 | Constructor constructor = sConstructorMap.get(name); 61 | try { 62 | if (constructor == null) { 63 | // Class not found in the cache, see if it's real, and try to 64 | // add it 65 | Class clazz = mContext.getClassLoader().loadClass(name); 66 | constructor = clazz.getConstructor(CTOR_SIGNATURE); 67 | sConstructorMap.put(name, constructor); 68 | } 69 | return (CameraPreference) constructor.newInstance(args); 70 | } catch (NoSuchMethodException e) { 71 | throw new InflateException("Error inflating class " + name, e); 72 | } catch (ClassNotFoundException e) { 73 | throw new InflateException("No such class: " + name, e); 74 | } catch (Exception e) { 75 | throw new InflateException("While create instance of" + name, e); 76 | } 77 | } 78 | 79 | private CameraPreference inflate(XmlPullParser parser) { 80 | 81 | AttributeSet attrs = Xml.asAttributeSet(parser); 82 | ArrayList list = new ArrayList(); 83 | Object args[] = new Object[]{mContext, attrs}; 84 | 85 | try { 86 | for (int type = parser.next(); 87 | type != XmlPullParser.END_DOCUMENT; type = parser.next()) { 88 | if (type != XmlPullParser.START_TAG) continue; 89 | CameraPreference pref = newPreference(parser.getName(), args); 90 | 91 | int depth = parser.getDepth(); 92 | if (depth > list.size()) { 93 | list.add(pref); 94 | } else { 95 | list.set(depth - 1, pref); 96 | } 97 | if (depth > 1) { 98 | ((PreferenceGroup) list.get(depth - 2)).addChild(pref); 99 | } 100 | } 101 | 102 | if (list.size() == 0) { 103 | throw new InflateException("No root element found"); 104 | } 105 | return list.get(0); 106 | } catch (XmlPullParserException e) { 107 | throw new InflateException(e); 108 | } catch (IOException e) { 109 | throw new InflateException(parser.getPositionDescription(), e); 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/PreviewFrameLayout.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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.lightbox.android.camera; 18 | 19 | import com.lightbox.android.camera.R; 20 | 21 | import android.app.Activity; 22 | import android.content.Context; 23 | import android.util.AttributeSet; 24 | import android.util.DisplayMetrics; 25 | import android.view.ViewGroup; 26 | import android.widget.FrameLayout; 27 | 28 | /** 29 | * A layout which handles the preview aspect ratio and the position of 30 | * the gripper. 31 | */ 32 | public class PreviewFrameLayout extends ViewGroup { 33 | private static final int MIN_HORIZONTAL_MARGIN = 10; // 10dp 34 | 35 | /** A callback to be invoked when the preview frame's size changes. */ 36 | public interface OnSizeChangedListener { 37 | public void onSizeChanged(); 38 | } 39 | 40 | private double mAspectRatio = 4.0 / 3.0; 41 | private FrameLayout mFrame; 42 | private OnSizeChangedListener mSizeListener; 43 | private final DisplayMetrics mMetrics = new DisplayMetrics(); 44 | 45 | public PreviewFrameLayout(Context context, AttributeSet attrs) { 46 | super(context, attrs); 47 | if (isInEditMode()) { 48 | return; 49 | } 50 | ((Activity) context).getWindowManager() 51 | .getDefaultDisplay().getMetrics(mMetrics); 52 | } 53 | 54 | public void setOnSizeChangedListener(OnSizeChangedListener listener) { 55 | mSizeListener = listener; 56 | } 57 | 58 | @Override 59 | protected void onFinishInflate() { 60 | mFrame = (FrameLayout) findViewById(R.id.frame); 61 | if (mFrame == null) { 62 | throw new IllegalStateException( 63 | "must provide child with id as \"frame\""); 64 | } 65 | } 66 | 67 | public void setAspectRatio(double ratio) { 68 | if (ratio <= 0.0) throw new IllegalArgumentException(); 69 | 70 | if (mAspectRatio != ratio) { 71 | mAspectRatio = ratio; 72 | requestLayout(); 73 | } 74 | } 75 | 76 | @Override 77 | protected void onLayout(boolean changed, int l, int t, int r, int b) { 78 | int frameWidth = getWidth(); 79 | int frameHeight = getHeight(); 80 | 81 | FrameLayout f = mFrame; 82 | int horizontalPadding = f.getPaddingLeft() + f.getPaddingRight(); 83 | int verticalPadding = f.getPaddingBottom() + f.getPaddingTop(); 84 | int previewHeight = frameHeight - verticalPadding; 85 | int previewWidth = frameWidth - horizontalPadding; 86 | 87 | // resize frame and preview for aspect ratio 88 | if (previewWidth > previewHeight * mAspectRatio) { 89 | previewWidth = (int) (previewHeight * mAspectRatio + .5); 90 | } else { 91 | previewHeight = (int) (previewWidth / mAspectRatio + .5); 92 | } 93 | 94 | frameWidth = previewWidth + horizontalPadding; 95 | frameHeight = previewHeight + verticalPadding; 96 | 97 | int hSpace = ((r - l) - frameWidth) / 2; 98 | int vSpace = ((b - t) - frameHeight) / 2; 99 | mFrame.measure( 100 | MeasureSpec.makeMeasureSpec(frameWidth, MeasureSpec.EXACTLY), 101 | MeasureSpec.makeMeasureSpec(frameHeight, MeasureSpec.EXACTLY)); 102 | mFrame.layout(l + hSpace, t + vSpace, r - hSpace, b - vSpace); 103 | if (mSizeListener != null) { 104 | mSizeListener.onSizeChanged(); 105 | } 106 | } 107 | 108 | } 109 | 110 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/RotateImageView.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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.lightbox.android.camera; 18 | 19 | import android.content.Context; 20 | import android.graphics.Canvas; 21 | import android.graphics.Rect; 22 | import android.graphics.drawable.Drawable; 23 | import android.util.AttributeSet; 24 | import android.view.animation.AnimationUtils; 25 | import android.widget.ImageView; 26 | 27 | /** 28 | * A @{code ImageView} which can rotate it's content. 29 | */ 30 | public class RotateImageView extends ImageView { 31 | 32 | @SuppressWarnings("unused") 33 | private static final String TAG = "RotateImageView"; 34 | 35 | private static final int ANIMATION_SPEED = 540; // 180 deg/sec 36 | 37 | private int mCurrentDegree = 0; // [0, 359] 38 | private int mStartDegree = 0; 39 | private int mTargetDegree = 0; 40 | 41 | private boolean mClockwise = false; 42 | 43 | private long mAnimationStartTime = 0; 44 | private long mAnimationEndTime = 0; 45 | 46 | public RotateImageView(Context context, AttributeSet attrs) { 47 | super(context, attrs); 48 | } 49 | 50 | public void setDegree(int degree) { 51 | // make sure in the range of [0, 359] 52 | degree = degree >= 0 ? degree % 360 : degree % 360 + 360; 53 | if (degree == mTargetDegree) return; 54 | 55 | mTargetDegree = degree; 56 | mStartDegree = mCurrentDegree; 57 | mAnimationStartTime = AnimationUtils.currentAnimationTimeMillis(); 58 | 59 | int diff = mTargetDegree - mCurrentDegree; 60 | diff = diff >= 0 ? diff : 360 + diff; // make it in range [0, 359] 61 | 62 | // Make it in range [-179, 180]. That's the shorted distance between the 63 | // two angles 64 | diff = diff > 180 ? diff - 360 : diff; 65 | 66 | mClockwise = diff >= 0; 67 | mAnimationEndTime = mAnimationStartTime 68 | + Math.abs(diff) * 1000 / ANIMATION_SPEED; 69 | 70 | invalidate(); 71 | } 72 | 73 | public void setDegreeInstant(int degree) { 74 | // make sure in the range of [0, 359] 75 | degree = degree >= 0 ? degree % 360 : degree % 360 + 360; 76 | if (degree == mTargetDegree) return; 77 | 78 | mTargetDegree = degree; 79 | mStartDegree = mCurrentDegree; 80 | mAnimationStartTime = AnimationUtils.currentAnimationTimeMillis(); 81 | 82 | int diff = mTargetDegree - mCurrentDegree; 83 | diff = diff >= 0 ? diff : 360 + diff; // make it in range [0, 359] 84 | 85 | // Make it in range [-179, 180]. That's the shorted distance between the 86 | // two angles 87 | diff = diff > 180 ? diff - 360 : diff; 88 | 89 | mClockwise = diff >= 0; 90 | mAnimationEndTime = mAnimationStartTime; 91 | 92 | invalidate(); 93 | } 94 | 95 | @Override 96 | protected void onDraw(Canvas canvas) { 97 | 98 | Drawable drawable = getDrawable(); 99 | if (drawable == null) return; 100 | 101 | Rect bounds = drawable.getBounds(); 102 | int w = bounds.right - bounds.left; 103 | int h = bounds.bottom - bounds.top; 104 | 105 | if (w == 0 || h == 0) return; // nothing to draw 106 | 107 | if (mCurrentDegree != mTargetDegree) { 108 | long time = AnimationUtils.currentAnimationTimeMillis(); 109 | if (time < mAnimationEndTime) { 110 | int deltaTime = (int)(time - mAnimationStartTime); 111 | int degree = mStartDegree + ANIMATION_SPEED 112 | * (mClockwise ? deltaTime : -deltaTime) / 1000; 113 | degree = degree >= 0 ? degree % 360 : degree % 360 + 360; 114 | mCurrentDegree = degree; 115 | invalidate(); 116 | } else { 117 | mCurrentDegree = mTargetDegree; 118 | } 119 | } 120 | 121 | int left = getPaddingLeft(); 122 | int top = getPaddingTop(); 123 | int right = getPaddingRight(); 124 | int bottom = getPaddingBottom(); 125 | int width = getWidth() - left - right; 126 | int height = getHeight() - top - bottom; 127 | 128 | int saveCount = canvas.getSaveCount(); 129 | canvas.translate(left + width / 2, top + height / 2); 130 | canvas.rotate(-mCurrentDegree); 131 | canvas.translate(-w / 2, -h / 2); 132 | drawable.draw(canvas); 133 | canvas.restoreToCount(saveCount); 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ShutterButton.java: -------------------------------------------------------------------------------- 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.lightbox.android.camera; 18 | 19 | import com.lightbox.android.camera.ShutterButton; 20 | 21 | import android.content.Context; 22 | import android.util.AttributeSet; 23 | import android.widget.ImageView; 24 | 25 | /** 26 | * A button designed to be used for the on-screen shutter button. 27 | * It's currently an {@code ImageView} that can call a delegate when the 28 | * pressed state changes. 29 | */ 30 | public class ShutterButton extends ImageView { 31 | /** 32 | * A callback to be invoked when a ShutterButton's pressed state changes. 33 | */ 34 | public interface OnShutterButtonListener { 35 | /** 36 | * Called when a ShutterButton has been pressed. 37 | * 38 | * @param b The ShutterButton that was pressed. 39 | */ 40 | void onShutterButtonFocus(ShutterButton b, boolean pressed); 41 | void onShutterButtonClick(ShutterButton b); 42 | } 43 | 44 | private OnShutterButtonListener mListener; 45 | private boolean mOldPressed; 46 | 47 | public ShutterButton(Context context) { 48 | super(context); 49 | } 50 | 51 | public ShutterButton(Context context, AttributeSet attrs) { 52 | super(context, attrs); 53 | } 54 | 55 | public ShutterButton(Context context, AttributeSet attrs, int defStyle) { 56 | super(context, attrs, defStyle); 57 | } 58 | 59 | public void setOnShutterButtonListener(OnShutterButtonListener listener) { 60 | mListener = listener; 61 | } 62 | 63 | /** 64 | * Hook into the drawable state changing to get changes to isPressed -- the 65 | * onPressed listener doesn't always get called when the pressed state 66 | * changes. 67 | */ 68 | @Override 69 | protected void drawableStateChanged() { 70 | super.drawableStateChanged(); 71 | final boolean pressed = isPressed(); 72 | if (pressed != mOldPressed) { 73 | if (!pressed) { 74 | // When pressing the physical camera button the sequence of 75 | // events is: 76 | // focus pressed, optional camera pressed, focus released. 77 | // We want to emulate this sequence of events with the shutter 78 | // button. When clicking using a trackball button, the view 79 | // system changes the the drawable state before posting click 80 | // notification, so the sequence of events is: 81 | // pressed(true), optional click, pressed(false) 82 | // When clicking using touch events, the view system changes the 83 | // drawable state after posting click notification, so the 84 | // sequence of events is: 85 | // pressed(true), pressed(false), optional click 86 | // Since we're emulating the physical camera button, we want to 87 | // have the same order of events. So we want the optional click 88 | // callback to be delivered before the pressed(false) callback. 89 | // 90 | // To do this, we delay the posting of the pressed(false) event 91 | // slightly by pushing it on the event queue. This moves it 92 | // after the optional click notification, so our client always 93 | // sees events in this sequence: 94 | // pressed(true), optional click, pressed(false) 95 | post(new Runnable() { 96 | public void run() { 97 | callShutterButtonFocus(pressed); 98 | } 99 | }); 100 | } else { 101 | callShutterButtonFocus(pressed); 102 | } 103 | mOldPressed = pressed; 104 | } 105 | } 106 | 107 | private void callShutterButtonFocus(boolean pressed) { 108 | if (mListener != null) { 109 | mListener.onShutterButtonFocus(this, pressed); 110 | } 111 | } 112 | 113 | @Override 114 | public boolean performClick() { 115 | boolean result = super.performClick(); 116 | if (mListener != null) { 117 | mListener.onShutterButtonClick(this); 118 | } 119 | return result; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/activities/Settings.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Lightbox 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.lightbox.android.camera.activities; 18 | 19 | 20 | import java.util.List; 21 | 22 | import com.lightbox.android.camera.R; 23 | 24 | import android.content.Context; 25 | import android.content.Intent; 26 | import android.content.pm.PackageManager; 27 | import android.content.pm.ResolveInfo; 28 | import android.net.Uri; 29 | import android.preference.Preference; 30 | import android.preference.PreferenceActivity; 31 | import android.preference.PreferenceScreen; 32 | 33 | /** 34 | * Settings 35 | * @author Nilesh Patel 36 | */ 37 | public class Settings extends PreferenceActivity { 38 | /** Used to tag logs */ 39 | @SuppressWarnings("unused") 40 | private static final String TAG = "Settings"; 41 | 42 | private static final String MARKET_APP_URI_FORMAT = "market://details?id=%s"; 43 | private static final String MARKET_WEB_URI_FORMAT = "http://market.android.com/details?id=%s"; 44 | private static final String LIGHTBOX_PACKAGE = "com.lightbox.android.photos"; 45 | 46 | @Override 47 | protected void onResume() { 48 | super.onResume(); 49 | 50 | PreferenceScreen prefScreenRoot = getPreferenceScreen(); 51 | if (prefScreenRoot != null) { 52 | prefScreenRoot.removeAll(); 53 | } 54 | addPreferencesFromResource(R.xml.preferences); 55 | 56 | Preference getLightboxPref = findPreference("get_lightbox"); 57 | getLightboxPref.setIntent(buildViewMarketDetailsIntent(this, LIGHTBOX_PACKAGE)); 58 | } 59 | 60 | public static Intent buildViewMarketDetailsIntent(Context context, String packageName) { 61 | // TODO: Support Amazon Market intent 62 | // http://stackoverflow.com/questions/7683130/how-to-support-amazon-and-android-market-links-in-same-apk/ 63 | // http://stackoverflow.com/questions/7658984/how-to-write-review-on-amazon-market-using-app 64 | 65 | // Build intent to view app details with the market app 66 | Intent viewMarketAppIntent = new Intent(Intent.ACTION_VIEW); 67 | viewMarketAppIntent.setData(Uri.parse(String.format(MARKET_APP_URI_FORMAT, packageName))); 68 | 69 | // If this device can resolve the intent, return it 70 | if (canResolveIntent(context, viewMarketAppIntent)) { 71 | return viewMarketAppIntent; 72 | } else { 73 | // Else, fall-back to the online market Intent that cannot fail 74 | Intent viewMarketWebIntent = new Intent(Intent.ACTION_VIEW); 75 | viewMarketWebIntent.setData(Uri.parse(String.format(MARKET_WEB_URI_FORMAT, packageName))); 76 | return viewMarketWebIntent; 77 | } 78 | } 79 | 80 | public static boolean canResolveIntent(Context context, Intent intent) { 81 | PackageManager packageManager = context.getPackageManager(); 82 | List resolveInfo = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); 83 | return (resolveInfo.size() > 0); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/device/GingerbreadCameraHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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 | /* 18 | * Modified by Nilesh Patel 19 | */ 20 | 21 | package com.lightbox.android.camera.device; 22 | 23 | import static com.lightbox.android.camera.Util.Assert; 24 | 25 | import android.hardware.Camera; 26 | import android.hardware.Camera.CameraInfo; 27 | import android.hardware.Camera.Size; 28 | import android.util.Log; 29 | 30 | import java.io.IOException; 31 | 32 | import com.lightbox.android.camera.CameraHardwareException; 33 | import com.lightbox.android.camera.device.CameraHolder; 34 | 35 | public class GingerbreadCameraHolder extends CameraHolder { 36 | private static final String TAG = "GingerbreadCameraHolder"; 37 | protected CameraInfo[] mInfo; 38 | 39 | protected GingerbreadCameraHolder() { 40 | super(); 41 | mNumberOfCameras = android.hardware.Camera.getNumberOfCameras(); 42 | mInfo = new CameraInfo[mNumberOfCameras]; 43 | for (int i = 0; i < mNumberOfCameras; i++) { 44 | mInfo[i] = new CameraInfo(); 45 | android.hardware.Camera.getCameraInfo(i, mInfo[i]); 46 | } 47 | } 48 | 49 | public int getNumberOfCameras() { 50 | return mNumberOfCameras; 51 | } 52 | 53 | public boolean isFrontFacing(int cameraId) { 54 | return (mInfo[cameraId].facing == CameraInfo.CAMERA_FACING_FRONT); 55 | } 56 | 57 | public int getCameraOrientation(int cameraId, int orientationSensorValue) { 58 | return mInfo[cameraId].orientation; 59 | } 60 | 61 | public synchronized android.hardware.Camera open(int cameraId) 62 | throws CameraHardwareException { 63 | Assert(mUsers == 0); 64 | if (mCameraDevice != null && mCameraId != cameraId) { 65 | mCameraDevice.release(); 66 | mCameraDevice = null; 67 | mCameraId = -1; 68 | } 69 | if (mCameraDevice == null) { 70 | try { 71 | Log.v(TAG, "open camera " + cameraId); 72 | mCameraDevice = android.hardware.Camera.open(cameraId); 73 | mCameraId = cameraId; 74 | } catch (RuntimeException e) { 75 | Log.e(TAG, "fail to connect Camera", e); 76 | throw new CameraHardwareException(e); 77 | } 78 | mParameters = mCameraDevice.getParameters(); 79 | } else { 80 | try { 81 | mCameraDevice.reconnect(); 82 | } catch (IOException e) { 83 | Log.e(TAG, "reconnect failed."); 84 | throw new CameraHardwareException(e); 85 | } 86 | mCameraDevice.setParameters(mParameters); 87 | } 88 | ++mUsers; 89 | mHandler.removeMessages(RELEASE_CAMERA); 90 | mKeepBeforeTime = 0; 91 | return mCameraDevice; 92 | } 93 | 94 | @Override 95 | public double getAspectRatio() { 96 | Size size = mParameters.getPictureSize(); 97 | return ((double) size.width / size.height); 98 | } 99 | 100 | @Override 101 | public int getFrontFacingCameraId() { 102 | int numCameras = getNumberOfCameras(); 103 | CameraInfo cameraInfo = new CameraInfo(); 104 | for (int cameraId = 0; cameraId < numCameras; cameraId++) { 105 | Camera.getCameraInfo(cameraId, cameraInfo); 106 | if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) { 107 | return cameraId; 108 | } 109 | } 110 | return 0; 111 | } 112 | 113 | @Override 114 | public int getRearFacingCameraId() { 115 | int numCameras = getNumberOfCameras(); 116 | CameraInfo cameraInfo = new CameraInfo(); 117 | for (int cameraId = 0; cameraId < numCameras; cameraId++) { 118 | Camera.getCameraInfo(cameraId, cameraInfo); 119 | if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) { 120 | return cameraId; 121 | } 122 | } 123 | return 0; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/device/HTCFrontFacingFixGingerbreadCameraHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Lightbox 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.lightbox.android.camera.device; 18 | 19 | import com.lightbox.android.camera.device.GingerbreadCameraHolder; 20 | 21 | public class HTCFrontFacingFixGingerbreadCameraHolder extends GingerbreadCameraHolder { 22 | @SuppressWarnings("unused") 23 | private static final String TAG = "HTCFrontFacingFixGingerbreadCameraHolder"; 24 | 25 | public int getCameraOrientation(int cameraId, int orientationSensorValue) { 26 | if (isFrontFacing(cameraId)) { 27 | switch (orientationSensorValue) { 28 | case 0: 29 | return 90; 30 | case 90: 31 | return 270; 32 | case 180: 33 | return 90; 34 | case 270: 35 | return 270; 36 | } 37 | } 38 | return mInfo[cameraId].orientation; 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/device/LGOptimus2XCameraHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Lightbox 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.lightbox.android.camera.device; 18 | 19 | import static com.lightbox.android.camera.Util.Assert; 20 | 21 | import java.io.IOException; 22 | 23 | import android.hardware.Camera; 24 | import android.hardware.Camera.Size; 25 | import android.util.Log; 26 | 27 | import com.lightbox.android.camera.CameraHardwareException; 28 | import com.lightbox.android.camera.device.CameraHolder; 29 | 30 | public class LGOptimus2XCameraHolder extends CameraHolder { 31 | private static final int CAMERA_REAR = 0; 32 | private static final int CAMERA_FRONT = 1; 33 | 34 | protected LGOptimus2XCameraHolder() { 35 | super(); 36 | mNumberOfCameras = 2; 37 | } 38 | 39 | @Override 40 | public int getCameraOrientation(int cameraId, int orientationSensorValue) { 41 | Log.d(TAG, "ori="+orientationSensorValue); 42 | if (mCameraId == CAMERA_REAR) { 43 | if (orientationSensorValue == 270 || orientationSensorValue == 90) { 44 | return 90; 45 | } else { 46 | return 270; 47 | } 48 | } 49 | return 0; 50 | } 51 | 52 | @Override 53 | public int getNumberOfCameras() { 54 | return mNumberOfCameras; 55 | } 56 | 57 | @Override 58 | public boolean isFrontFacing(int cameraId) { 59 | return (cameraId == CAMERA_FRONT); 60 | } 61 | 62 | @Override 63 | public synchronized Camera open(int cameraId) throws CameraHardwareException { 64 | Assert(mUsers == 0); 65 | if (mCameraDevice != null && mCameraId != cameraId) { 66 | mCameraDevice.release(); 67 | mCameraDevice = null; 68 | mCameraId = -1; 69 | } 70 | if (mCameraDevice == null) { 71 | try { 72 | Log.v(TAG, "open camera " + cameraId); 73 | mCameraDevice = openCamera(cameraId); 74 | mCameraId = cameraId; 75 | } catch (RuntimeException e) { 76 | Log.e(TAG, "fail to connect Camera", e); 77 | throw new CameraHardwareException(e); 78 | } 79 | mParameters = mCameraDevice.getParameters(); 80 | } else { 81 | try { 82 | mCameraDevice = openCamera(cameraId); 83 | mCameraId = cameraId; 84 | mCameraDevice.reconnect(); 85 | } catch (IOException e) { 86 | Log.e(TAG, "reconnect failed."); 87 | throw new CameraHardwareException(e); 88 | } 89 | mCameraDevice.setParameters(mParameters); 90 | } 91 | ++mUsers; 92 | mHandler.removeMessages(RELEASE_CAMERA); 93 | mKeepBeforeTime = 0; 94 | return mCameraDevice; 95 | } 96 | 97 | private static final String CAMERA_SENSOR = "camera-sensor"; 98 | private Camera openCamera(int cameraId) { 99 | Camera camera = null; 100 | if (cameraId == CAMERA_FRONT) { 101 | camera = Camera.open(); 102 | Camera.Parameters parameters = camera.getParameters(); 103 | parameters.set(CAMERA_SENSOR, 2); 104 | camera.setParameters(parameters); 105 | camera.setDisplayOrientation(270); 106 | } else if (cameraId == CAMERA_REAR) { 107 | camera = Camera.open(); 108 | Camera.Parameters parameters = camera.getParameters(); 109 | parameters.set(CAMERA_SENSOR, 0); 110 | camera.setParameters(parameters); 111 | camera.setDisplayOrientation(0); 112 | } 113 | 114 | return camera; 115 | } 116 | 117 | @Override 118 | public double getAspectRatio() { 119 | Size size = mParameters.getPictureSize(); 120 | if (mCameraId == CAMERA_FRONT) { 121 | return ((double) size.height / size.width); 122 | } else if (mCameraId == CAMERA_REAR) { 123 | return ((double) size.width / size.height); 124 | } 125 | return 4.0/3; 126 | } 127 | 128 | @Override 129 | public int getFrontFacingCameraId() { 130 | return CAMERA_FRONT; 131 | } 132 | 133 | @Override 134 | public int getRearFacingCameraId() { 135 | return CAMERA_REAR; 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/device/PreGingerbreadCameraHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Lightbox 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.lightbox.android.camera.device; 18 | 19 | import static com.lightbox.android.camera.Util.Assert; 20 | import android.hardware.Camera; 21 | import android.hardware.Camera.Size; 22 | import android.util.Log; 23 | 24 | import com.lightbox.android.camera.CameraHardwareException; 25 | 26 | public class PreGingerbreadCameraHolder extends CameraHolder { 27 | 28 | protected PreGingerbreadCameraHolder() { 29 | super(); 30 | mNumberOfCameras = 1; 31 | } 32 | 33 | @Override 34 | public boolean isFrontFacing(int cameraId) { 35 | return false; 36 | } 37 | 38 | @Override 39 | public int getCameraOrientation(int cameraId, int orientationSensorValue) { 40 | return 90; 41 | } 42 | 43 | @Override 44 | public int getNumberOfCameras() { 45 | return mNumberOfCameras; 46 | } 47 | 48 | @Override 49 | public synchronized Camera open(int cameraId) throws CameraHardwareException { 50 | Assert(mUsers == 0); 51 | if (mCameraDevice != null && mCameraId != cameraId) { 52 | mCameraDevice.release(); 53 | mCameraDevice = null; 54 | mCameraId = -1; 55 | } 56 | if (mCameraDevice == null) { 57 | try { 58 | Log.v(TAG, "open camera " + cameraId); 59 | mCameraDevice = android.hardware.Camera.open(); 60 | mCameraId = cameraId; 61 | } catch (RuntimeException e) { 62 | Log.e(TAG, "fail to connect Camera", e); 63 | throw new CameraHardwareException(e); 64 | } 65 | mParameters = mCameraDevice.getParameters(); 66 | } else { 67 | mCameraDevice.lock(); 68 | mCameraDevice.setParameters(mParameters); 69 | } 70 | ++mUsers; 71 | mHandler.removeMessages(RELEASE_CAMERA); 72 | mKeepBeforeTime = 0; 73 | return mCameraDevice; 74 | } 75 | 76 | @Override 77 | public double getAspectRatio() { 78 | Size size = mParameters.getPictureSize(); 79 | return ((double) size.width / size.height); 80 | } 81 | 82 | @Override 83 | public int getFrontFacingCameraId() { 84 | return 0; 85 | } 86 | 87 | @Override 88 | public int getRearFacingCameraId() { 89 | return 0; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/device/SamsungCaptivateGingerbreadCameraHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012 Lightbox 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.lightbox.android.camera.device; 18 | 19 | /** 20 | * SamsungCaptivate 21 | * @author Nilesh Patel 22 | */ 23 | public class SamsungCaptivateGingerbreadCameraHolder extends GingerbreadCameraHolder { 24 | /** Used to tag logs */ 25 | @SuppressWarnings("unused") 26 | private static final String TAG = "SamsungCaptivate"; 27 | 28 | public int getCameraOrientation(int cameraId, int orientationSensorValue) { 29 | switch (orientationSensorValue) { 30 | case 0: 31 | return 180; 32 | case 90: 33 | return 270; 34 | case 180: 35 | return 0; 36 | case 270: 37 | return 90; 38 | } 39 | return mInfo[cameraId].orientation; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/gallery/BaseImage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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.lightbox.android.camera.gallery; 18 | 19 | import com.lightbox.android.camera.BitmapManager; 20 | import com.lightbox.android.camera.Util; 21 | import com.lightbox.android.camera.gallery.IImage; 22 | import com.lightbox.android.camera.gallery.Image; 23 | 24 | import android.content.ContentResolver; 25 | import android.graphics.Bitmap; 26 | import android.net.Uri; 27 | import android.provider.MediaStore.Images; 28 | import android.util.Log; 29 | 30 | /** 31 | * Represents a particular image and provides access to the underlying bitmap 32 | * and two thumbnail bitmaps as well as other information such as the id, and 33 | * the path to the actual image data. 34 | */ 35 | public abstract class BaseImage implements IImage { 36 | private static final String TAG = "BaseImage"; 37 | protected ContentResolver mContentResolver; 38 | 39 | // Database field 40 | protected Uri mUri; 41 | protected long mId; 42 | private final long mDateTaken; 43 | 44 | protected BaseImage(ContentResolver cr, 45 | long id, Uri uri, long miniThumbMagic, 46 | long dateTaken) { 47 | mContentResolver = cr; 48 | mId = id; 49 | mUri = uri; 50 | mDateTaken = dateTaken; 51 | } 52 | 53 | @Override 54 | public boolean equals(Object other) { 55 | if (other == null || !(other instanceof Image)) return false; 56 | return mUri.equals(((Image) other).mUri); 57 | } 58 | 59 | @Override 60 | public int hashCode() { 61 | return mUri.hashCode(); 62 | } 63 | 64 | public Uri fullSizeImageUri() { 65 | return mUri; 66 | } 67 | 68 | public long getDateTaken() { 69 | return mDateTaken; 70 | } 71 | 72 | public int getDegreesRotated() { 73 | return 0; 74 | } 75 | 76 | public Bitmap miniThumbBitmap() { 77 | Bitmap b = null; 78 | try { 79 | long id = mId; 80 | b = BitmapManager.instance().getThumbnail(mContentResolver, id, 81 | Images.Thumbnails.MICRO_KIND, null, false); 82 | } catch (Throwable ex) { 83 | Log.e(TAG, "miniThumbBitmap got exception", ex); 84 | return null; 85 | } 86 | if (b != null) { 87 | b = Util.rotate(b, getDegreesRotated()); 88 | } 89 | return b; 90 | } 91 | 92 | @Override 93 | public String toString() { 94 | return mUri.toString(); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/gallery/IImage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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.lightbox.android.camera.gallery; 18 | 19 | import android.graphics.Bitmap; 20 | import android.net.Uri; 21 | 22 | /** 23 | * The interface of all images used in gallery. 24 | */ 25 | public interface IImage { 26 | static final int THUMBNAIL_TARGET_SIZE = 320; 27 | static final int MINI_THUMB_TARGET_SIZE = 96; 28 | static final int THUMBNAIL_MAX_NUM_PIXELS = 512 * 384; 29 | static final int MINI_THUMB_MAX_NUM_PIXELS = 128 * 128; 30 | static final int UNCONSTRAINED = -1; 31 | 32 | public static final boolean ROTATE_AS_NEEDED = true; 33 | public static final boolean NO_ROTATE = false; 34 | 35 | public abstract Uri fullSizeImageUri(); 36 | 37 | // Get metadata of the image 38 | public abstract long getDateTaken(); 39 | 40 | // Get the bitmap of the mini thumbnail. 41 | public abstract Bitmap miniThumbBitmap(); 42 | } 43 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/gallery/IImageList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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.lightbox.android.camera.gallery; 18 | 19 | import com.lightbox.android.camera.gallery.IImage; 20 | 21 | // 22 | // ImageList and Image classes have one-to-one correspondence. 23 | // The class hierarchy (* = abstract class): 24 | // 25 | // IImageList 26 | // - BaseImageList (*) 27 | // - VideoList 28 | // - ImageList 29 | // - DrmImageList 30 | // - SingleImageList (contains UriImage) 31 | // - ImageListUber 32 | // 33 | // IImage 34 | // - BaseImage (*) 35 | // - VideoObject 36 | // - Image 37 | // - DrmImage 38 | // - UriImage 39 | // 40 | 41 | /** 42 | * The interface of all image collections used in gallery. 43 | */ 44 | public interface IImageList { 45 | 46 | /** 47 | * Returns the count of image objects. 48 | * 49 | * @return the number of images 50 | */ 51 | public int getCount(); 52 | 53 | /** 54 | * Returns the image at the ith position. 55 | * 56 | * @param i the position 57 | * @return the image at the ith position 58 | */ 59 | public IImage getImageAt(int i); 60 | 61 | /** 62 | * Closes this list to release resources, no further operation is allowed. 63 | */ 64 | public void close(); 65 | } 66 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/gallery/Image.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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.lightbox.android.camera.gallery; 18 | 19 | import com.lightbox.android.camera.gallery.BaseImage; 20 | import com.lightbox.android.camera.gallery.IImage; 21 | 22 | import android.content.ContentResolver; 23 | import android.net.Uri; 24 | 25 | /** 26 | * The class for normal images in gallery. 27 | */ 28 | public class Image extends BaseImage implements IImage { 29 | private final int mRotation; 30 | 31 | public Image(ContentResolver cr, 32 | long id, Uri uri, long miniThumbMagic, 33 | long dateTaken, 34 | int rotation) { 35 | super(cr, id, uri, miniThumbMagic, 36 | dateTaken); 37 | mRotation = rotation; 38 | } 39 | 40 | @Override 41 | public int getDegreesRotated() { 42 | return mRotation; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/gallery/ImageList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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.lightbox.android.camera.gallery; 18 | 19 | import com.lightbox.android.camera.gallery.BaseImage; 20 | import com.lightbox.android.camera.gallery.BaseImageList; 21 | import com.lightbox.android.camera.gallery.IImageList; 22 | import com.lightbox.android.camera.gallery.Image; 23 | 24 | import android.content.ContentResolver; 25 | import android.database.Cursor; 26 | import android.net.Uri; 27 | import android.provider.MediaStore.Images.Media; 28 | 29 | /** 30 | * Represents an ordered collection of Image objects. Provides an API to add 31 | * and remove an image. 32 | */ 33 | public class ImageList extends BaseImageList implements IImageList { 34 | 35 | @SuppressWarnings("unused") 36 | private static final String TAG = "ImageList"; 37 | 38 | private static final String[] ACCEPTABLE_IMAGE_TYPES = 39 | new String[] { "image/jpeg", "image/png", "image/gif" }; 40 | 41 | /** 42 | * ImageList constructor. 43 | */ 44 | public ImageList(ContentResolver resolver, Uri imageUri, 45 | int sort, String bucketId) { 46 | super(resolver, imageUri, sort, bucketId); 47 | } 48 | 49 | private static final String WHERE_CLAUSE = 50 | "(" + Media.MIME_TYPE + " in (?, ?, ?))"; 51 | private static final String WHERE_CLAUSE_WITH_BUCKET_ID = 52 | WHERE_CLAUSE + " AND " + Media.BUCKET_ID + " = ?"; 53 | 54 | protected String whereClause() { 55 | return mBucketId == null ? WHERE_CLAUSE : WHERE_CLAUSE_WITH_BUCKET_ID; 56 | } 57 | 58 | protected String[] whereClauseArgs() { 59 | // TODO: Since mBucketId won't change, we should keep the array. 60 | if (mBucketId != null) { 61 | int count = ACCEPTABLE_IMAGE_TYPES.length; 62 | String[] result = new String[count + 1]; 63 | System.arraycopy(ACCEPTABLE_IMAGE_TYPES, 0, result, 0, count); 64 | result[count] = mBucketId; 65 | return result; 66 | } 67 | return ACCEPTABLE_IMAGE_TYPES; 68 | } 69 | 70 | @Override 71 | protected Cursor createCursor() { 72 | Cursor c = Media.query( 73 | mContentResolver, mBaseUri, IMAGE_PROJECTION, 74 | whereClause(), whereClauseArgs(), sortOrder()); 75 | return c; 76 | } 77 | 78 | static final String[] IMAGE_PROJECTION = new String[] { 79 | Media._ID, 80 | Media.DATE_TAKEN, 81 | Media.MINI_THUMB_MAGIC, 82 | Media.ORIENTATION, 83 | Media.DATE_MODIFIED}; 84 | 85 | private static final int INDEX_ID = 0; 86 | private static final int INDEX_DATE_TAKEN = 1; 87 | private static final int INDEX_MINI_THUMB_MAGIC = 2; 88 | private static final int INDEX_ORIENTATION = 3; 89 | private static final int INDEX_DATE_MODIFIED = 4; 90 | 91 | @Override 92 | protected BaseImage loadImageFromCursor(Cursor cursor) { 93 | long id = cursor.getLong(INDEX_ID); 94 | long dateTaken = cursor.getLong(INDEX_DATE_TAKEN); 95 | if (dateTaken == 0) { 96 | dateTaken = cursor.getLong(INDEX_DATE_MODIFIED) * 1000; 97 | } 98 | long miniThumbMagic = cursor.getLong(INDEX_MINI_THUMB_MAGIC); 99 | int orientation = cursor.getInt(INDEX_ORIENTATION); 100 | return new Image(mContentResolver, id, 101 | contentUri(id), miniThumbMagic, dateTaken, 102 | orientation); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/gallery/LruCache.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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.lightbox.android.camera.gallery; 18 | 19 | import java.lang.ref.ReferenceQueue; 20 | import java.lang.ref.WeakReference; 21 | import java.util.HashMap; 22 | import java.util.LinkedHashMap; 23 | import java.util.Map; 24 | 25 | /** 26 | * An LRU cache which stores recently inserted entries and all entries ever 27 | * inserted which still has a strong reference elsewhere. 28 | */ 29 | public class LruCache { 30 | 31 | private final HashMap mLruMap; 32 | private final HashMap> mWeakMap = 33 | new HashMap>(); 34 | private ReferenceQueue mQueue = new ReferenceQueue(); 35 | 36 | @SuppressWarnings("serial") 37 | public LruCache(final int capacity) { 38 | mLruMap = new LinkedHashMap(16, 0.75f, true) { 39 | @Override 40 | protected boolean removeEldestEntry(Map.Entry eldest) { 41 | return size() > capacity; 42 | } 43 | }; 44 | } 45 | 46 | private static class Entry extends WeakReference { 47 | K mKey; 48 | 49 | public Entry(K key, V value, ReferenceQueue queue) { 50 | super(value, queue); 51 | mKey = key; 52 | } 53 | } 54 | 55 | @SuppressWarnings("unchecked") 56 | private void cleanUpWeakMap() { 57 | Entry entry = (Entry) mQueue.poll(); 58 | while (entry != null) { 59 | mWeakMap.remove(entry.mKey); 60 | entry = (Entry) mQueue.poll(); 61 | } 62 | } 63 | 64 | public synchronized V put(K key, V value) { 65 | cleanUpWeakMap(); 66 | mLruMap.put(key, value); 67 | Entry entry = mWeakMap.put( 68 | key, new Entry(key, value, mQueue)); 69 | return entry == null ? null : entry.get(); 70 | } 71 | 72 | public synchronized V get(K key) { 73 | cleanUpWeakMap(); 74 | V value = mLruMap.get(key); 75 | if (value != null) return value; 76 | Entry entry = mWeakMap.get(key); 77 | return entry == null ? null : entry.get(); 78 | } 79 | 80 | public synchronized void clear() { 81 | mLruMap.clear(); 82 | mWeakMap.clear(); 83 | mQueue = new ReferenceQueue(); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/gallery/VideoList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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.lightbox.android.camera.gallery; 18 | 19 | import com.lightbox.android.camera.gallery.BaseImage; 20 | import com.lightbox.android.camera.gallery.BaseImageList; 21 | import com.lightbox.android.camera.gallery.VideoObject; 22 | 23 | import android.content.ContentResolver; 24 | import android.database.Cursor; 25 | import android.net.Uri; 26 | import android.provider.MediaStore.Images; 27 | import android.provider.MediaStore.Video.Media; 28 | 29 | /** 30 | * A collection of all the VideoObject in gallery. 31 | */ 32 | public class VideoList extends BaseImageList { 33 | 34 | @SuppressWarnings("unused") 35 | private static final String TAG = "BaseImageList"; 36 | 37 | private static final String[] VIDEO_PROJECTION = new String[] { 38 | Media._ID, 39 | Media.DATE_TAKEN, 40 | Media.MINI_THUMB_MAGIC, 41 | Media.DATE_MODIFIED}; 42 | 43 | private static final int INDEX_ID = 0; 44 | private static final int INDEX_DATE_TAKEN = 1; 45 | private static final int INDEX_MIMI_THUMB_MAGIC = 2; 46 | private static final int INDEX_DATE_MODIFIED = 3; 47 | 48 | @Override 49 | protected BaseImage loadImageFromCursor(Cursor cursor) { 50 | long id = cursor.getLong(INDEX_ID); 51 | long dateTaken = cursor.getLong(INDEX_DATE_TAKEN); 52 | if (dateTaken == 0) { 53 | dateTaken = cursor.getLong(INDEX_DATE_MODIFIED) * 1000; 54 | } 55 | long miniThumbMagic = cursor.getLong(INDEX_MIMI_THUMB_MAGIC); 56 | return new VideoObject(mContentResolver, 57 | id, contentUri(id), 58 | miniThumbMagic, dateTaken); 59 | } 60 | 61 | public VideoList(ContentResolver resolver, Uri uri, int sort, 62 | String bucketId) { 63 | super(resolver, uri, sort, bucketId); 64 | } 65 | 66 | protected String whereClause() { 67 | return mBucketId != null 68 | ? Images.Media.BUCKET_ID + " = '" + mBucketId + "'" 69 | : null; 70 | } 71 | 72 | protected String[] whereClauseArgs() { 73 | return null; 74 | } 75 | 76 | @Override 77 | protected Cursor createCursor() { 78 | Cursor c = Images.Media.query( 79 | mContentResolver, mBaseUri, VIDEO_PROJECTION, 80 | whereClause(), whereClauseArgs(), sortOrder()); 81 | return c; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/gallery/VideoObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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.lightbox.android.camera.gallery; 18 | 19 | import com.lightbox.android.camera.BitmapManager; 20 | import com.lightbox.android.camera.gallery.BaseImage; 21 | import com.lightbox.android.camera.gallery.IImage; 22 | import com.lightbox.android.camera.gallery.VideoObject; 23 | 24 | import android.content.ContentResolver; 25 | import android.graphics.Bitmap; 26 | import android.net.Uri; 27 | import android.provider.MediaStore.Images; 28 | import android.util.Log; 29 | 30 | /** 31 | * Represents a particular video and provides access to the underlying data and 32 | * two thumbnail bitmaps as well as other information such as the id, and the 33 | * path to the actual video data. 34 | */ 35 | public class VideoObject extends BaseImage implements IImage { 36 | private static final String TAG = "VideoObject"; 37 | /** 38 | * Constructor. 39 | * 40 | * @param id the image id of the image 41 | * @param cr the content resolver 42 | */ 43 | protected VideoObject(ContentResolver cr, 44 | long id, Uri uri, long miniThumbMagic, 45 | long dateTaken) { 46 | super(cr, id, uri, miniThumbMagic, 47 | dateTaken); 48 | } 49 | 50 | @Override 51 | public boolean equals(Object other) { 52 | if (other == null || !(other instanceof VideoObject)) return false; 53 | return fullSizeImageUri().equals( 54 | ((VideoObject) other).fullSizeImageUri()); 55 | } 56 | 57 | @Override 58 | public int hashCode() { 59 | return fullSizeImageUri().toString().hashCode(); 60 | } 61 | 62 | @Override 63 | public Bitmap miniThumbBitmap() { 64 | try { 65 | long id = mId; 66 | return BitmapManager.instance().getThumbnail(mContentResolver, 67 | id, Images.Thumbnails.MICRO_KIND, null, true); 68 | } catch (Throwable ex) { 69 | Log.e(TAG, "miniThumbBitmap got exception", ex); 70 | return null; 71 | } 72 | } 73 | 74 | @Override 75 | public String toString() { 76 | return new StringBuilder("VideoObject").append(mId).toString(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/AbstractIndicator.java: -------------------------------------------------------------------------------- 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.lightbox.android.camera.ui; 18 | 19 | import android.content.Context; 20 | import android.graphics.Matrix; 21 | import android.graphics.Rect; 22 | import android.view.animation.AlphaAnimation; 23 | import android.view.animation.Transformation; 24 | 25 | import javax.microedition.khronos.opengles.GL11; 26 | 27 | import com.lightbox.android.camera.ui.BitmapTexture; 28 | import com.lightbox.android.camera.ui.GLRootView; 29 | import com.lightbox.android.camera.ui.GLView; 30 | import com.lightbox.android.camera.ui.MeasureHelper; 31 | 32 | abstract class AbstractIndicator extends GLView { 33 | private static final int DEFAULT_PADDING = 3; 34 | private int mOrientation = 0; 35 | 36 | abstract protected BitmapTexture getIcon(); 37 | 38 | public AbstractIndicator(Context context) { 39 | int padding = GLRootView.dpToPixel(context, DEFAULT_PADDING); 40 | setPaddings(padding, 0, padding, 0); 41 | } 42 | 43 | @Override 44 | protected void onMeasure(int widthSpec, int heightSpec) { 45 | BitmapTexture icon = getIcon(); 46 | new MeasureHelper(this) 47 | .setPreferredContentSize(icon.getWidth(), icon.getHeight()) 48 | .measure(widthSpec, heightSpec); 49 | } 50 | 51 | @Override 52 | protected void render(GLRootView root, GL11 gl) { 53 | BitmapTexture icon = getIcon(); 54 | if (icon != null) { 55 | Rect p = mPaddings; 56 | int width = getWidth() - p.left - p.right; 57 | int height = getHeight() - p.top - p.bottom; 58 | if (mOrientation != 0) { 59 | Transformation trans = root.pushTransform(); 60 | Matrix matrix = trans.getMatrix(); 61 | matrix.preTranslate(p.left + width / 2, p.top + height / 2); 62 | matrix.preRotate(-mOrientation); 63 | icon.draw(root, -icon.getWidth() / 2, -icon.getHeight() / 2); 64 | root.popTransform(); 65 | } else { 66 | icon.draw(root, 67 | p.left + (width - icon.getWidth()) / 2, 68 | p.top + (height - icon.getHeight()) / 2); 69 | } 70 | } 71 | } 72 | 73 | public void setOrientation(int orientation) { 74 | if (orientation % 90 != 0) throw new IllegalArgumentException(); 75 | orientation = orientation % 360; 76 | if (orientation < 0) orientation += 360; 77 | 78 | if (mOrientation == orientation) return; 79 | mOrientation = orientation; 80 | 81 | if (getGLRootView() != null) { 82 | AlphaAnimation anim = new AlphaAnimation(0.2f, 1); 83 | anim.setDuration(200); 84 | startAnimation(anim); 85 | } 86 | } 87 | 88 | abstract public GLView getPopupContent(); 89 | 90 | abstract public void overrideSettings(String key, String settings); 91 | 92 | abstract public void reloadPreferences(); 93 | } 94 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/BasicIndicator.java: -------------------------------------------------------------------------------- 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.lightbox.android.camera.ui; 18 | 19 | import android.content.Context; 20 | 21 | import com.lightbox.android.camera.IconListPreference; 22 | import com.lightbox.android.camera.Util; 23 | import com.lightbox.android.camera.ui.AbstractIndicator; 24 | import com.lightbox.android.camera.ui.ColorTexture; 25 | import com.lightbox.android.camera.ui.GLListView; 26 | import com.lightbox.android.camera.ui.GLView; 27 | import com.lightbox.android.camera.ui.NinePatchTexture; 28 | import com.lightbox.android.camera.ui.PreferenceAdapter; 29 | import com.lightbox.android.camera.ui.ResourceTexture; 30 | import com.lightbox.android.camera.ui.GLListView.OnItemSelectedListener; 31 | import com.lightbox.android.camera.R; 32 | 33 | class BasicIndicator extends AbstractIndicator { 34 | private static final int COLOR_OPTION_ITEM_HIGHLIGHT = 0xFF181818; 35 | 36 | private final ResourceTexture mIcon[]; 37 | private final IconListPreference mPreference; 38 | protected int mIndex; 39 | private GLListView mPopupContent; 40 | private PreferenceAdapter mModel; 41 | private String mOverride; 42 | 43 | public BasicIndicator(Context context, IconListPreference preference) { 44 | super(context); 45 | mPreference = preference; 46 | mIcon = new ResourceTexture[preference.getLargeIconIds().length]; 47 | mIndex = preference.findIndexOfValue(preference.getValue()); 48 | } 49 | 50 | // Set the override and/or reload the value from preferences. 51 | private void updateContent(String override, boolean reloadValue) { 52 | if (!reloadValue && Util.equals(mOverride, override)) return; 53 | IconListPreference pref = mPreference; 54 | mOverride = override; 55 | int index = pref.findIndexOfValue( 56 | override == null ? pref.getValue() : override); 57 | if (mIndex != index) { 58 | mIndex = index; 59 | invalidate(); 60 | } 61 | } 62 | 63 | @Override 64 | public void overrideSettings(String key, String settings) { 65 | IconListPreference pref = mPreference; 66 | if (!pref.getKey().equals(key)) return; 67 | updateContent(settings, false); 68 | } 69 | 70 | @Override 71 | public void reloadPreferences() { 72 | if (mModel != null) mModel.reload(); 73 | updateContent(null, true); 74 | } 75 | 76 | @Override 77 | public GLView getPopupContent() { 78 | if (mPopupContent == null) { 79 | Context context = getGLRootView().getContext(); 80 | mPopupContent = new GLListView(context); 81 | mPopupContent.setHighLight( 82 | new ColorTexture(COLOR_OPTION_ITEM_HIGHLIGHT)); 83 | mPopupContent.setScroller(new NinePatchTexture( 84 | context, R.drawable.scrollbar_handle_vertical)); 85 | mModel = new PreferenceAdapter(context, mPreference); 86 | mPopupContent.setOnItemSelectedListener(new MyListener(mModel)); 87 | mPopupContent.setDataModel(mModel); 88 | } 89 | mModel.overrideSettings(mOverride); 90 | return mPopupContent; 91 | } 92 | 93 | protected void onPreferenceChanged(int newIndex) { 94 | if (newIndex == mIndex) return; 95 | mIndex = newIndex; 96 | invalidate(); 97 | } 98 | 99 | private class MyListener implements OnItemSelectedListener { 100 | 101 | private final PreferenceAdapter mAdapter; 102 | 103 | public MyListener(PreferenceAdapter adapter) { 104 | mAdapter = adapter; 105 | } 106 | 107 | public void onItemSelected(GLView view, int position) { 108 | mAdapter.onItemSelected(view, position); 109 | onPreferenceChanged(position - 1); 110 | } 111 | } 112 | 113 | @Override 114 | protected ResourceTexture getIcon() { 115 | int index = mIndex; 116 | if (mIcon[index] == null) { 117 | Context context = getGLRootView().getContext(); 118 | mIcon[index] = new ResourceTexture( 119 | context, mPreference.getLargeIconIds()[index]); 120 | } 121 | return mIcon[index]; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/BasicTexture.java: -------------------------------------------------------------------------------- 1 | package com.lightbox.android.camera.ui; 2 | 3 | import javax.microedition.khronos.opengles.GL11; 4 | 5 | import com.lightbox.android.camera.ui.GLRootView; 6 | import com.lightbox.android.camera.ui.Texture; 7 | 8 | abstract class BasicTexture implements Texture { 9 | 10 | protected static final int UNSPECIFIED = -1; 11 | 12 | public static final int STATE_UNLOADED = 0; 13 | public static final int STATE_LOADED = 1; 14 | public static final int STATE_ERROR = -1; 15 | 16 | protected GL11 mGL; 17 | 18 | protected int mId; 19 | protected int mState; 20 | 21 | protected int mWidth = UNSPECIFIED; 22 | protected int mHeight = UNSPECIFIED; 23 | 24 | protected int mTextureWidth; 25 | protected int mTextureHeight; 26 | 27 | protected BasicTexture(GL11 gl, int id, int state) { 28 | mGL = gl; 29 | mId = id; 30 | mState = state; 31 | } 32 | 33 | protected BasicTexture() { 34 | this(null, 0, STATE_UNLOADED); 35 | } 36 | 37 | protected void setSize(int width, int height) { 38 | mWidth = width; 39 | mHeight = height; 40 | } 41 | 42 | /** 43 | * Sets the size of the texture. Due to the limit of OpenGL, the texture 44 | * size must be of power of 2, the size of the content may not be the size 45 | * of the texture. 46 | */ 47 | protected void setTextureSize(int width, int height) { 48 | mTextureWidth = width; 49 | mTextureHeight = height; 50 | } 51 | 52 | public int getId() { 53 | return mId; 54 | } 55 | 56 | public int getWidth() { 57 | return mWidth; 58 | } 59 | 60 | public int getHeight() { 61 | return mHeight; 62 | } 63 | 64 | public void deleteFromGL() { 65 | if (mState == STATE_LOADED) { 66 | mGL.glDeleteTextures(1, new int[]{mId}, 0); 67 | } 68 | mState = STATE_UNLOADED; 69 | } 70 | 71 | public void draw(GLRootView root, int x, int y) { 72 | root.drawTexture(this, x, y, mWidth, mHeight); 73 | } 74 | 75 | public void draw(GLRootView root, int x, int y, int w, int h) { 76 | root.drawTexture(this, x, y, w, h); 77 | } 78 | 79 | abstract protected boolean bind(GLRootView root, GL11 gl); 80 | } 81 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/BitmapTexture.java: -------------------------------------------------------------------------------- 1 | package com.lightbox.android.camera.ui; 2 | 3 | import com.lightbox.android.camera.Util; 4 | import com.lightbox.android.camera.ui.BasicTexture; 5 | import com.lightbox.android.camera.ui.BitmapTexture; 6 | import com.lightbox.android.camera.ui.GLOutOfMemoryException; 7 | import com.lightbox.android.camera.ui.GLRootView; 8 | 9 | import android.graphics.Bitmap; 10 | import android.opengl.GLUtils; 11 | 12 | import javax.microedition.khronos.opengles.GL11; 13 | import javax.microedition.khronos.opengles.GL11Ext; 14 | 15 | abstract class BitmapTexture extends BasicTexture { 16 | 17 | @SuppressWarnings("unused") 18 | private static final String TAG = "Texture"; 19 | 20 | protected BitmapTexture() { 21 | super(null, 0, STATE_UNLOADED); 22 | } 23 | 24 | @Override 25 | public int getWidth() { 26 | if (mWidth == UNSPECIFIED) getBitmap(); 27 | return mWidth; 28 | } 29 | 30 | @Override 31 | public int getHeight() { 32 | if (mWidth == UNSPECIFIED) getBitmap(); 33 | return mHeight; 34 | } 35 | 36 | protected abstract Bitmap getBitmap(); 37 | 38 | protected abstract void freeBitmap(Bitmap bitmap); 39 | 40 | private void uploadToGL(GL11 gl) throws GLOutOfMemoryException { 41 | Bitmap bitmap = getBitmap(); 42 | int glError = GL11.GL_NO_ERROR; 43 | if (bitmap != null) { 44 | int[] textureId = new int[1]; 45 | try { 46 | // Define a vertically flipped crop rectangle for 47 | // OES_draw_texture. 48 | int width = bitmap.getWidth(); 49 | int height = bitmap.getHeight(); 50 | int[] cropRect = {0, height, width, -height}; 51 | 52 | // Upload the bitmap to a new texture. 53 | gl.glGenTextures(1, textureId, 0); 54 | gl.glBindTexture(GL11.GL_TEXTURE_2D, textureId[0]); 55 | gl.glTexParameteriv(GL11.GL_TEXTURE_2D, 56 | GL11Ext.GL_TEXTURE_CROP_RECT_OES, cropRect, 0); 57 | gl.glTexParameteri(GL11.GL_TEXTURE_2D, 58 | GL11.GL_TEXTURE_WRAP_S, GL11.GL_CLAMP_TO_EDGE); 59 | gl.glTexParameteri(GL11.GL_TEXTURE_2D, 60 | GL11.GL_TEXTURE_WRAP_T, GL11.GL_CLAMP_TO_EDGE); 61 | gl.glTexParameterf(GL11.GL_TEXTURE_2D, 62 | GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR); 63 | gl.glTexParameterf(GL11.GL_TEXTURE_2D, 64 | GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR); 65 | 66 | int widthExt = Util.nextPowerOf2(width); 67 | int heightExt = Util.nextPowerOf2(height); 68 | int format = GLUtils.getInternalFormat(bitmap); 69 | int type = GLUtils.getType(bitmap); 70 | 71 | mTextureWidth = widthExt; 72 | mTextureHeight = heightExt; 73 | gl.glTexImage2D(GL11.GL_TEXTURE_2D, 0, format, 74 | widthExt, heightExt, 0, format, type, null); 75 | GLUtils.texSubImage2D( 76 | GL11.GL_TEXTURE_2D, 0, 0, 0, bitmap, format, type); 77 | } finally { 78 | freeBitmap(bitmap); 79 | } 80 | if (glError == GL11.GL_OUT_OF_MEMORY) { 81 | throw new GLOutOfMemoryException(); 82 | } 83 | if (glError != GL11.GL_NO_ERROR) { 84 | mId = 0; 85 | mState = STATE_UNLOADED; 86 | throw new RuntimeException( 87 | "Texture upload fail, glError " + glError); 88 | } else { 89 | // Update texture state. 90 | mGL = gl; 91 | mId = textureId[0]; 92 | mState = BitmapTexture.STATE_LOADED; 93 | } 94 | } else { 95 | mState = STATE_ERROR; 96 | throw new RuntimeException("Texture load fail, no bitmap"); 97 | } 98 | } 99 | 100 | @Override 101 | protected boolean bind(GLRootView root, GL11 gl) { 102 | if (mState == BitmapTexture.STATE_UNLOADED || mGL != gl) { 103 | mState = BitmapTexture.STATE_UNLOADED; 104 | try { 105 | uploadToGL(gl); 106 | } catch (GLOutOfMemoryException e) { 107 | root.handleLowMemory(); 108 | return false; 109 | } 110 | } else { 111 | gl.glBindTexture(GL11.GL_TEXTURE_2D, getId()); 112 | } 113 | return true; 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/CameraEGLConfigChooser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2009 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 | package com.lightbox.android.camera.ui; 17 | 18 | import android.opengl.GLSurfaceView.EGLConfigChooser; 19 | import javax.microedition.khronos.egl.EGL10; 20 | import javax.microedition.khronos.egl.EGLConfig; 21 | import javax.microedition.khronos.egl.EGLDisplay; 22 | 23 | /* 24 | * The code is copied/adapted from 25 | * android.opengl.GLSurfaceView.BaseConfigChooser. Here we try to 26 | * choose a configuration that support RGBA_8888 format and if possible, 27 | * with stencil buffer, but is not required. 28 | */ 29 | class CameraEGLConfigChooser implements EGLConfigChooser { 30 | 31 | private static final int COLOR_BITS = 8; 32 | 33 | private int mStencilBits; 34 | 35 | private final int mConfigSpec[] = new int[] { 36 | EGL10.EGL_RED_SIZE, COLOR_BITS, 37 | EGL10.EGL_GREEN_SIZE, COLOR_BITS, 38 | EGL10.EGL_BLUE_SIZE, COLOR_BITS, 39 | EGL10.EGL_ALPHA_SIZE, COLOR_BITS, 40 | EGL10.EGL_NONE 41 | }; 42 | 43 | public int getStencilBits() { 44 | return mStencilBits; 45 | } 46 | 47 | public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) { 48 | int[] numConfig = new int[1]; 49 | if (!egl.eglChooseConfig(display, mConfigSpec, null, 0, numConfig)) { 50 | throw new RuntimeException("eglChooseConfig failed"); 51 | } 52 | 53 | if (numConfig[0] <= 0) { 54 | throw new RuntimeException("No configs match configSpec"); 55 | } 56 | 57 | EGLConfig[] configs = new EGLConfig[numConfig[0]]; 58 | if (!egl.eglChooseConfig(display, 59 | mConfigSpec, configs, configs.length, numConfig)) { 60 | throw new RuntimeException(); 61 | } 62 | 63 | return chooseConfig(egl, display, configs); 64 | } 65 | 66 | private EGLConfig chooseConfig( 67 | EGL10 egl, EGLDisplay display, EGLConfig configs[]) { 68 | 69 | EGLConfig result = null; 70 | int minStencil = Integer.MAX_VALUE; 71 | int value[] = new int[1]; 72 | 73 | // Because we need only one bit of stencil, try to choose a config that 74 | // has stencil support but with smallest number of stencil bits. If 75 | // none is found, choose any one. 76 | for (int i = 0, n = configs.length; i < n; ++i) { 77 | if (egl.eglGetConfigAttrib( 78 | display, configs[i], EGL10.EGL_STENCIL_SIZE, value)) { 79 | if (value[0] == 0) continue; 80 | if (value[0] < minStencil) { 81 | minStencil = value[0]; 82 | result = configs[i]; 83 | } 84 | } else { 85 | throw new RuntimeException( 86 | "eglGetConfigAttrib error: " + egl.eglGetError()); 87 | } 88 | } 89 | if (result == null) result = configs[0]; 90 | egl.eglGetConfigAttrib( 91 | display, result, EGL10.EGL_STENCIL_SIZE, value); 92 | mStencilBits = value[0]; 93 | return result; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/CameraHeadUpDisplay.java: -------------------------------------------------------------------------------- 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.lightbox.android.camera.ui; 18 | 19 | import android.content.Context; 20 | 21 | import com.lightbox.android.camera.CameraSettings; 22 | import com.lightbox.android.camera.ListPreference; 23 | import com.lightbox.android.camera.PreferenceGroup; 24 | 25 | public class CameraHeadUpDisplay extends HeadUpDisplay { 26 | 27 | @SuppressWarnings("unused") 28 | private static final String TAG = "CamcoderHeadUpDisplay"; 29 | 30 | private OtherSettingsIndicator mOtherSettings; 31 | private ZoomIndicator mZoomIndicator; 32 | private Context mContext; 33 | private float[] mInitialZoomRatios; 34 | private int mInitialOrientation; 35 | 36 | public CameraHeadUpDisplay(Context context) { 37 | super(context); 38 | mContext = context; 39 | } 40 | 41 | public void initialize(Context context, PreferenceGroup group, 42 | float[] initialZoomRatios, int initialOrientation) { 43 | mInitialZoomRatios = initialZoomRatios; 44 | mInitialOrientation = initialOrientation; 45 | super.initialize(context, group); 46 | } 47 | 48 | @Override 49 | protected void initializeIndicatorBar( 50 | Context context, PreferenceGroup group) { 51 | super.initializeIndicatorBar(context, group); 52 | 53 | ListPreference prefs[] = getListPreferences(group, 54 | CameraSettings.KEY_FOCUS_MODE, 55 | CameraSettings.KEY_WHITE_BALANCE, 56 | CameraSettings.KEY_EXPOSURE, 57 | CameraSettings.KEY_SCENE_MODE); 58 | 59 | mOtherSettings = new OtherSettingsIndicator(context, prefs); 60 | mOtherSettings.setOnRestorePreferencesClickedRunner(new Runnable() { 61 | public void run() { 62 | if (mListener != null) { 63 | mListener.onRestorePreferencesClicked(); 64 | } 65 | } 66 | }); 67 | mIndicatorBar.addComponent(mOtherSettings); 68 | 69 | if (mInitialZoomRatios != null) { 70 | mZoomIndicator = new ZoomIndicator(mContext); 71 | mZoomIndicator.setZoomRatios(mInitialZoomRatios); 72 | mIndicatorBar.addComponent(mZoomIndicator); 73 | } else { 74 | mZoomIndicator = null; 75 | } 76 | 77 | mIndicatorBar.setOrientation(mInitialOrientation); 78 | } 79 | 80 | public void setZoomListener(ZoomControllerListener listener) { 81 | // The rendering thread won't access listener variable, so we don't 82 | // need to do concurrency protection here 83 | mZoomIndicator.setZoomListener(listener); 84 | } 85 | 86 | public void setZoomIndex(int index) { 87 | if (mZoomIndicator != null) { 88 | GLRootView root = getGLRootView(); 89 | if (root != null) { 90 | synchronized (root) { 91 | mZoomIndicator.setZoomIndex(index); 92 | } 93 | } else { 94 | mZoomIndicator.setZoomIndex(index); 95 | } 96 | } 97 | } 98 | 99 | /** 100 | * Sets the zoom rations the camera driver provides. This methods must be 101 | * called before setZoomListener() and 102 | * setZoomIndex() 103 | */ 104 | public void setZoomRatios(float[] zoomRatios) { 105 | GLRootView root = getGLRootView(); 106 | if (root != null) { 107 | synchronized(root) { 108 | setZoomRatiosLocked(zoomRatios); 109 | } 110 | } else { 111 | setZoomRatiosLocked(zoomRatios); 112 | } 113 | } 114 | 115 | private void setZoomRatiosLocked(float[] zoomRatios) { 116 | mZoomIndicator.setZoomRatios(zoomRatios); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/CanvasTexture.java: -------------------------------------------------------------------------------- 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.lightbox.android.camera.ui; 18 | 19 | import com.lightbox.android.camera.ui.BitmapTexture; 20 | 21 | import android.graphics.Bitmap; 22 | import android.graphics.Canvas; 23 | import android.graphics.Bitmap.Config; 24 | 25 | /** Using a canvas to draw the texture */ 26 | abstract class CanvasTexture extends BitmapTexture { 27 | protected Canvas mCanvas; 28 | 29 | public CanvasTexture(int width, int height) { 30 | setSize(width, height); 31 | } 32 | 33 | @Override 34 | protected Bitmap getBitmap() { 35 | Bitmap bitmap = Bitmap.createBitmap(mWidth, mHeight, Config.ARGB_8888); 36 | mCanvas = new Canvas(bitmap); 37 | onDraw(mCanvas, bitmap); 38 | return bitmap; 39 | } 40 | 41 | @Override 42 | protected void freeBitmap(Bitmap bitmap) { 43 | bitmap.recycle(); 44 | } 45 | 46 | abstract protected void onDraw(Canvas canvas, Bitmap backing); 47 | } 48 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/ColorTexture.java: -------------------------------------------------------------------------------- 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.lightbox.android.camera.ui; 18 | 19 | import com.lightbox.android.camera.ui.GLRootView; 20 | import com.lightbox.android.camera.ui.Texture; 21 | 22 | class ColorTexture implements Texture { 23 | 24 | private int mColor; 25 | 26 | public ColorTexture(int color) { 27 | mColor = color; 28 | } 29 | 30 | public void draw(GLRootView root, int x, int y) { 31 | } 32 | 33 | public void draw(GLRootView root, int x, int y, int w, int h) { 34 | root.drawColor(x, y, w, h, mColor); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/GLOptionHeader.java: -------------------------------------------------------------------------------- 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.lightbox.android.camera.ui; 18 | 19 | import static com.lightbox.android.camera.ui.GLRootView.dpToPixel; 20 | import android.content.Context; 21 | import android.graphics.Rect; 22 | 23 | import javax.microedition.khronos.opengles.GL11; 24 | 25 | import com.lightbox.android.camera.ui.ColorTexture; 26 | import com.lightbox.android.camera.ui.GLRootView; 27 | import com.lightbox.android.camera.ui.GLView; 28 | import com.lightbox.android.camera.ui.MeasureHelper; 29 | import com.lightbox.android.camera.ui.StringTexture; 30 | import com.lightbox.android.camera.ui.Texture; 31 | 32 | class GLOptionHeader extends GLView { 33 | private static final int FONT_COLOR = 0xFF666666; 34 | private static final float FONT_SIZE = 12; 35 | private static final int HORIZONTAL_PADDINGS = 4; 36 | private static final int VERTICAL_PADDINGS = 2; 37 | private static final int COLOR_OPTION_HEADER = 0xFF1D1D1D; 38 | 39 | private static int sHorizontalPaddings = -1; 40 | private static int sVerticalPaddings; 41 | 42 | private final StringTexture mTitle; 43 | private Texture mBackground; 44 | 45 | private static void initializeStaticVariables(Context context) { 46 | if (sHorizontalPaddings >= 0) return; 47 | sHorizontalPaddings = dpToPixel(context, HORIZONTAL_PADDINGS); 48 | sVerticalPaddings = dpToPixel(context, VERTICAL_PADDINGS); 49 | } 50 | 51 | public GLOptionHeader(Context context, String title) { 52 | initializeStaticVariables(context); 53 | 54 | float fontSize = GLRootView.dpToPixel(context, FONT_SIZE); 55 | mTitle = StringTexture.newInstance(title, fontSize, FONT_COLOR); 56 | setBackground(new ColorTexture(COLOR_OPTION_HEADER)); 57 | setPaddings(sHorizontalPaddings, 58 | sVerticalPaddings, sHorizontalPaddings, sVerticalPaddings); 59 | } 60 | 61 | public void setBackground(Texture background) { 62 | if (mBackground == background) return; 63 | mBackground = background; 64 | invalidate(); 65 | } 66 | 67 | @Override 68 | protected void onMeasure(int widthSpec, int heightSpec) { 69 | new MeasureHelper(this) 70 | .setPreferredContentSize(mTitle.getWidth(), mTitle.getHeight()) 71 | .measure(widthSpec, heightSpec); 72 | } 73 | 74 | @Override 75 | protected void render(GLRootView root, GL11 gl) { 76 | if (mBackground != null) { 77 | mBackground.draw(root, 0, 0, getWidth(), getHeight()); 78 | } 79 | Rect p = mPaddings; 80 | mTitle.draw(root, p.left, p.top); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/GLOutOfMemoryException.java: -------------------------------------------------------------------------------- 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.lightbox.android.camera.ui; 18 | 19 | @SuppressWarnings("serial") 20 | public class GLOutOfMemoryException extends Exception { 21 | } 22 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/GpsIndicator.java: -------------------------------------------------------------------------------- 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.lightbox.android.camera.ui; 18 | 19 | import android.content.Context; 20 | 21 | import com.lightbox.android.camera.IconListPreference; 22 | import com.lightbox.android.camera.ui.BasicIndicator; 23 | import com.lightbox.android.camera.ui.ResourceTexture; 24 | import com.lightbox.android.camera.R; 25 | 26 | class GpsIndicator extends BasicIndicator { 27 | 28 | private static final int GPS_ON_INDEX = 1; 29 | 30 | private ResourceTexture mNoSignalIcon; 31 | private boolean mHasSignal = false; 32 | 33 | public GpsIndicator(Context context, IconListPreference preference) { 34 | super(context, preference); 35 | } 36 | 37 | @Override 38 | protected ResourceTexture getIcon() { 39 | if (mIndex == GPS_ON_INDEX && !mHasSignal) { 40 | if (mNoSignalIcon == null) { 41 | Context context = getGLRootView().getContext(); 42 | mNoSignalIcon = new ResourceTexture( 43 | context, R.drawable.ic_viewfinder_gps_no_signal); 44 | } 45 | return mNoSignalIcon; 46 | } 47 | return super.getIcon(); 48 | } 49 | 50 | public void setHasSignal(boolean hasSignal) { 51 | if (mHasSignal == hasSignal) return; 52 | mHasSignal = hasSignal; 53 | invalidate(); 54 | } 55 | 56 | @Override 57 | protected void onPreferenceChanged(int newIndex) { 58 | mHasSignal = false; 59 | super.onPreferenceChanged(newIndex); 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/LinearLayout.java: -------------------------------------------------------------------------------- 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.lightbox.android.camera.ui; 18 | 19 | import com.lightbox.android.camera.ui.GLView; 20 | import com.lightbox.android.camera.ui.MeasureHelper; 21 | 22 | import android.graphics.Rect; 23 | import android.view.View.MeasureSpec; 24 | 25 | class LinearLayout extends GLView { 26 | 27 | @Override 28 | protected void onMeasure(int widthSpec, int heightSpec) { 29 | int width = 0; 30 | int height = 0; 31 | for (int i = 0, n = getComponentCount(); i < n; ++i) { 32 | GLView view = getComponent(i); 33 | view.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); 34 | width = Math.max(width, view.getMeasuredWidth()); 35 | height += view.getMeasuredHeight(); 36 | } 37 | new MeasureHelper(this) 38 | .setPreferredContentSize(width, height) 39 | .measure(widthSpec, heightSpec); 40 | } 41 | 42 | @Override 43 | protected void onLayout(boolean changed, int l, int t, int r, int b) { 44 | Rect p = mPaddings; 45 | int offsetX = p.left; 46 | int width = (r - l) - p.left - p.right; 47 | int offsetY = p.top; 48 | for (int i = 0, n = getComponentCount(); i < n; ++i) { 49 | GLView view = getComponent(i); 50 | view.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); 51 | int nextOffsetY = offsetY + view.getMeasuredHeight(); 52 | view.layout(offsetX, offsetY, offsetX + width, nextOffsetY); 53 | offsetY = nextOffsetY; 54 | } 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/MeasureHelper.java: -------------------------------------------------------------------------------- 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.lightbox.android.camera.ui; 18 | 19 | import com.lightbox.android.camera.ui.GLView; 20 | import com.lightbox.android.camera.ui.MeasureHelper; 21 | 22 | import android.graphics.Rect; 23 | import android.view.View.MeasureSpec; 24 | 25 | class MeasureHelper { 26 | 27 | private final GLView mComponent; 28 | private int mPreferredWidth; 29 | private int mPreferredHeight; 30 | 31 | public MeasureHelper(GLView component) { 32 | mComponent = component; 33 | } 34 | 35 | public MeasureHelper setPreferredContentSize(int width, int height) { 36 | mPreferredWidth = width; 37 | mPreferredHeight = height; 38 | return this; 39 | } 40 | 41 | public void measure(int widthSpec, int heightSpec) { 42 | Rect p = mComponent.getPaddings(); 43 | setMeasuredSize( 44 | getLength(widthSpec, mPreferredWidth + p.left + p.right), 45 | getLength(heightSpec, mPreferredHeight + p.top + p.bottom)); 46 | } 47 | 48 | private static int getLength(int measureSpec, int prefered) { 49 | int specLength = MeasureSpec.getSize(measureSpec); 50 | switch(MeasureSpec.getMode(measureSpec)) { 51 | case MeasureSpec.EXACTLY: return specLength; 52 | case MeasureSpec.AT_MOST: return Math.min(prefered, specLength); 53 | default: return prefered; 54 | } 55 | } 56 | 57 | protected void setMeasuredSize(int width, int height) { 58 | mComponent.setMeasuredSize(width, height); 59 | } 60 | 61 | } 62 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/NinePatchChunk.java: -------------------------------------------------------------------------------- 1 | package com.lightbox.android.camera.ui; 2 | 3 | import android.graphics.Rect; 4 | 5 | import java.nio.ByteBuffer; 6 | import java.nio.ByteOrder; 7 | 8 | import com.lightbox.android.camera.ui.NinePatchChunk; 9 | 10 | // See "frameworks/base/include/utils/ResourceTypes.h" for the format of 11 | // NinePatch chunk. 12 | class NinePatchChunk { 13 | 14 | public static final int NO_COLOR = 0x00000001; 15 | public static final int TRANSPARENT_COLOR = 0x00000000; 16 | 17 | public Rect mPaddings = new Rect(); 18 | 19 | public int mDivX[]; 20 | public int mDivY[]; 21 | public int mColor[]; 22 | 23 | private static void readIntArray(int[] data, ByteBuffer buffer) { 24 | for (int i = 0, n = data.length; i < n; ++i) { 25 | data[i] = buffer.getInt(); 26 | } 27 | } 28 | 29 | private static void checkDivCount(int length) { 30 | if (length == 0 || (length & 0x01) != 0) { 31 | throw new RuntimeException("invalid nine-patch: " + length); 32 | } 33 | } 34 | 35 | public static NinePatchChunk deserialize(byte[] data) { 36 | ByteBuffer byteBuffer = 37 | ByteBuffer.wrap(data).order(ByteOrder.nativeOrder()); 38 | 39 | byte wasSerialized = byteBuffer.get(); 40 | if (wasSerialized == 0) return null; 41 | 42 | NinePatchChunk chunk = new NinePatchChunk(); 43 | chunk.mDivX = new int[byteBuffer.get()]; 44 | chunk.mDivY = new int[byteBuffer.get()]; 45 | chunk.mColor = new int[byteBuffer.get()]; 46 | 47 | checkDivCount(chunk.mDivX.length); 48 | checkDivCount(chunk.mDivY.length); 49 | 50 | // skip 8 bytes 51 | byteBuffer.getInt(); 52 | byteBuffer.getInt(); 53 | 54 | chunk.mPaddings.left = byteBuffer.getInt(); 55 | chunk.mPaddings.right = byteBuffer.getInt(); 56 | chunk.mPaddings.top = byteBuffer.getInt(); 57 | chunk.mPaddings.bottom = byteBuffer.getInt(); 58 | 59 | // skip 4 bytes 60 | byteBuffer.getInt(); 61 | 62 | readIntArray(chunk.mDivX, byteBuffer); 63 | readIntArray(chunk.mDivY, byteBuffer); 64 | readIntArray(chunk.mColor, byteBuffer); 65 | 66 | return chunk; 67 | } 68 | } -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/NinePatchTexture.java: -------------------------------------------------------------------------------- 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.lightbox.android.camera.ui; 18 | 19 | import com.lightbox.android.camera.ui.GLRootView; 20 | import com.lightbox.android.camera.ui.NinePatchChunk; 21 | import com.lightbox.android.camera.ui.ResourceTexture; 22 | 23 | import android.content.Context; 24 | import android.graphics.Bitmap; 25 | import android.graphics.BitmapFactory; 26 | import android.graphics.Rect; 27 | 28 | class NinePatchTexture extends ResourceTexture { 29 | private NinePatchChunk mChunk; 30 | 31 | public NinePatchTexture(Context context, int resId) { 32 | super(context, resId); 33 | } 34 | 35 | @Override 36 | protected Bitmap getBitmap() { 37 | if (mBitmap != null) return mBitmap; 38 | 39 | BitmapFactory.Options options = new BitmapFactory.Options(); 40 | options.inPreferredConfig = Bitmap.Config.ARGB_8888; 41 | Bitmap bitmap = BitmapFactory.decodeResource( 42 | mContext.getResources(), mResId, options); 43 | mBitmap = bitmap; 44 | setSize(bitmap.getWidth(), bitmap.getHeight()); 45 | mChunk = NinePatchChunk.deserialize(bitmap.getNinePatchChunk()); 46 | if (mChunk == null) { 47 | throw new RuntimeException("invalid nine-patch image: " + mResId); 48 | } 49 | return bitmap; 50 | } 51 | 52 | public Rect getPaddings() { 53 | // get the paddings from nine patch 54 | if (mChunk == null) getBitmap(); 55 | return mChunk.mPaddings; 56 | } 57 | 58 | public NinePatchChunk getNinePatchChunk() { 59 | if (mChunk == null) getBitmap(); 60 | return mChunk; 61 | } 62 | 63 | @Override 64 | public void draw(GLRootView root, int x, int y, int w, int h) { 65 | root.drawNinePatch(this, x, y, w, h); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/PreferenceAdapter.java: -------------------------------------------------------------------------------- 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.lightbox.android.camera.ui; 18 | 19 | import android.content.Context; 20 | 21 | import com.lightbox.android.camera.IconListPreference; 22 | import com.lightbox.android.camera.ListPreference; 23 | import com.lightbox.android.camera.Util; 24 | import com.lightbox.android.camera.ui.GLListView; 25 | import com.lightbox.android.camera.ui.GLOptionHeader; 26 | import com.lightbox.android.camera.ui.GLOptionItem; 27 | import com.lightbox.android.camera.ui.GLView; 28 | 29 | import java.util.ArrayList; 30 | 31 | class PreferenceAdapter 32 | implements GLListView.Model, GLListView.OnItemSelectedListener { 33 | 34 | private static final int ICON_NONE = 0; 35 | 36 | private final ArrayList mContent = new ArrayList(); 37 | private final ListPreference mPreference; 38 | private String mOverride; 39 | 40 | public PreferenceAdapter(Context context, ListPreference preference) { 41 | mPreference = preference; 42 | generateContent(context, preference); 43 | } 44 | 45 | public void reload() { 46 | updateContent(null, true); 47 | } 48 | 49 | public void overrideSettings(String settings) { 50 | updateContent(settings, false); 51 | } 52 | 53 | private void updateContent(String settings, boolean reloadValues) { 54 | if (!reloadValues && Util.equals(settings, mOverride)) return; 55 | mOverride = settings; 56 | 57 | CharSequence[] values = mPreference.getEntryValues(); 58 | String value = mPreference.getValue(); 59 | if (settings == null) { 60 | for (int i = 1, n = mContent.size(); i < n; ++i) { 61 | GLOptionItem item = (GLOptionItem) mContent.get(i); 62 | item.setChecked(values[i - 1].equals(value)); 63 | item.setEnabled(true); 64 | } 65 | } else { 66 | for (int i = 1, n = mContent.size(); i < n; ++i) { 67 | GLOptionItem item = (GLOptionItem) mContent.get(i); 68 | boolean checked = values[i - 1].equals(settings); 69 | item.setChecked(checked); 70 | item.setEnabled(checked); 71 | } 72 | } 73 | } 74 | 75 | private void generateContent(Context context, ListPreference preference) { 76 | GLOptionHeader header = 77 | new GLOptionHeader(context, preference.getTitle()); 78 | mContent.add(header); 79 | CharSequence[] entries = preference.getEntries(); 80 | CharSequence[] values = preference.getEntryValues(); 81 | String value = preference.getValue(); 82 | int [] icons = null; 83 | if (preference instanceof IconListPreference) { 84 | IconListPreference iPref = (IconListPreference) preference; 85 | icons = iPref.getIconIds(); 86 | } 87 | for (int i = 0, n = entries.length; i < n; ++i) { 88 | GLOptionItem item = new GLOptionItem( 89 | context, icons == null ? ICON_NONE : icons[i], 90 | entries[i].toString()); 91 | item.setChecked(values[i].equals(value)); 92 | mContent.add(item); 93 | } 94 | } 95 | 96 | public void onItemSelected(GLView view, int position) { 97 | if (mOverride != null) return; 98 | ListPreference pref = mPreference; 99 | CharSequence[] values = pref.getEntryValues(); 100 | if (position < values.length + 1) { 101 | int index = position - 1; 102 | int oldIndex = pref.findIndexOfValue(pref.getValue()); 103 | if (oldIndex != index) { 104 | synchronized (pref.getSharedPreferences()) { 105 | pref.setValueIndex(index); 106 | } 107 | ((GLOptionItem) mContent.get(1 + oldIndex)).setChecked(false); 108 | ((GLOptionItem) view).setChecked(true); 109 | } 110 | return; 111 | } 112 | } 113 | 114 | public GLView getView(int index) { 115 | return mContent.get(index); 116 | } 117 | 118 | public boolean isSelectable(int index) { 119 | return mContent.get(index) instanceof GLOptionItem; 120 | } 121 | 122 | public int size() { 123 | return mContent.size(); 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/RawTexture.java: -------------------------------------------------------------------------------- 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.lightbox.android.camera.ui; 18 | 19 | 20 | import javax.microedition.khronos.opengles.GL11; 21 | 22 | import com.lightbox.android.camera.ui.BasicTexture; 23 | import com.lightbox.android.camera.ui.GLRootView; 24 | import com.lightbox.android.camera.ui.RawTexture; 25 | 26 | class RawTexture extends BasicTexture { 27 | 28 | private RawTexture(GL11 gl, int id) { 29 | super(gl, id, STATE_LOADED); 30 | } 31 | 32 | public GL11 getBoundGL() { 33 | return mGL; 34 | } 35 | 36 | public static RawTexture newInstance(GL11 gl) { 37 | int[] textureId = new int[1]; 38 | gl.glGenTextures(1, textureId, 0); 39 | int glError = gl.glGetError(); 40 | if (glError != GL11.GL_NO_ERROR) { 41 | throw new RuntimeException("GL_ERROR: " + glError); 42 | } 43 | return new RawTexture(gl, textureId[0]); 44 | } 45 | 46 | @Override 47 | protected boolean bind(GLRootView glRootView, GL11 gl) { 48 | if (mGL == gl) { 49 | gl.glBindTexture(GL11.GL_TEXTURE_2D, getId()); 50 | return true; 51 | } 52 | return false; 53 | } 54 | 55 | public void drawBack(GLRootView root, int x, int y, int w, int h) { 56 | root.drawTexture(this, x, y, w, h, 1f); 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/ResourceTexture.java: -------------------------------------------------------------------------------- 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.lightbox.android.camera.ui; 18 | 19 | import com.lightbox.android.camera.Util; 20 | import com.lightbox.android.camera.ui.BitmapTexture; 21 | 22 | import android.content.Context; 23 | import android.graphics.Bitmap; 24 | import android.graphics.BitmapFactory; 25 | 26 | class ResourceTexture extends BitmapTexture { 27 | 28 | protected final Context mContext; 29 | protected final int mResId; 30 | protected Bitmap mBitmap; 31 | 32 | public ResourceTexture(Context context, int resId) { 33 | mContext = Util.checkNotNull(context); 34 | mResId = resId; 35 | } 36 | 37 | @Override 38 | protected Bitmap getBitmap() { 39 | if (mBitmap != null) return mBitmap; 40 | BitmapFactory.Options options = new BitmapFactory.Options(); 41 | options.inPreferredConfig = Bitmap.Config.ARGB_8888; 42 | mBitmap = BitmapFactory.decodeResource( 43 | mContext.getResources(), mResId, options); 44 | setSize(mBitmap.getWidth(), mBitmap.getHeight()); 45 | return mBitmap; 46 | } 47 | 48 | @Override 49 | protected void freeBitmap(Bitmap bitmap) { 50 | Util.Assert(bitmap == mBitmap); 51 | bitmap.recycle(); 52 | mBitmap = null; 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/RestoreSettingsItem.java: -------------------------------------------------------------------------------- 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.lightbox.android.camera.ui; 18 | 19 | import static com.lightbox.android.camera.ui.GLRootView.dpToPixel; 20 | import android.content.Context; 21 | import android.graphics.Color; 22 | import android.graphics.Rect; 23 | 24 | import javax.microedition.khronos.opengles.GL11; 25 | 26 | import com.lightbox.android.camera.ui.GLRootView; 27 | import com.lightbox.android.camera.ui.GLView; 28 | import com.lightbox.android.camera.ui.MeasureHelper; 29 | import com.lightbox.android.camera.ui.StringTexture; 30 | 31 | class RestoreSettingsItem extends GLView { 32 | private static final int FONT_COLOR = Color.WHITE; 33 | private static final float FONT_SIZE = 18; 34 | 35 | private static final int LEFT_PADDING = 20; 36 | private static final int RIGHT_PADDING = 4; 37 | private static final int TOP_PADDING = 2; 38 | private static final int BOTTOM_PADDING = 2; 39 | 40 | private static int sLeftPadding = -1; 41 | private static int sRightPadding; 42 | private static int sTopPadding; 43 | private static int sBottomPadding; 44 | private static float sFontSize; 45 | 46 | private final StringTexture mText; 47 | 48 | private static void initializeStaticVariables(Context context) { 49 | if (sLeftPadding >= 0) return; 50 | 51 | sLeftPadding = dpToPixel(context, LEFT_PADDING); 52 | sRightPadding = dpToPixel(context, RIGHT_PADDING); 53 | sTopPadding = dpToPixel(context, TOP_PADDING); 54 | sBottomPadding = dpToPixel(context, BOTTOM_PADDING); 55 | sFontSize = dpToPixel(context, FONT_SIZE); 56 | } 57 | 58 | public RestoreSettingsItem(Context context, String title) { 59 | initializeStaticVariables(context); 60 | mText = StringTexture.newInstance(title, sFontSize, FONT_COLOR); 61 | setPaddings(sLeftPadding, sTopPadding, sRightPadding, sBottomPadding); 62 | } 63 | 64 | @Override 65 | protected void onMeasure(int widthSpec, int heightSpec) { 66 | new MeasureHelper(this) 67 | .setPreferredContentSize(mText.getWidth(), mText.getHeight()) 68 | .measure(widthSpec, heightSpec); 69 | } 70 | 71 | @Override 72 | protected void render(GLRootView root, GL11 gl) { 73 | Rect p = mPaddings; 74 | int height = getHeight() - p.top - p.bottom; 75 | 76 | StringTexture title = mText; 77 | //TODO: cut the text if it is too long 78 | title.draw(root, p.left, p.top + (height - title.getHeight()) / 2); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/RotatePane.java: -------------------------------------------------------------------------------- 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.lightbox.android.camera.ui; 18 | 19 | import android.graphics.Matrix; 20 | import android.view.MotionEvent; 21 | 22 | import javax.microedition.khronos.opengles.GL11; 23 | 24 | import com.lightbox.android.camera.ui.GLRootView; 25 | import com.lightbox.android.camera.ui.GLView; 26 | 27 | 28 | class RotatePane extends GLView { 29 | 30 | public static final int UP = 0; 31 | public static final int RIGHT = 1; 32 | public static final int DOWN = 2; 33 | public static final int LEFT = 3; 34 | 35 | private int mOrientation = 0; 36 | 37 | private GLView mChild; 38 | 39 | @Override 40 | protected void onLayout( 41 | boolean change, int left, int top, int right, int bottom) { 42 | int width = right - left; 43 | int height = bottom - top; 44 | switch (mOrientation) { 45 | case UP: 46 | case DOWN: 47 | mChild.layout(0, 0, width, height); 48 | break; 49 | case LEFT: 50 | case RIGHT: 51 | mChild.layout(0, 0, height, width); 52 | break; 53 | } 54 | } 55 | 56 | @Override 57 | protected void onMeasure(int widthSpec, int heightSpec) { 58 | GLView c = mChild; 59 | switch(mOrientation) { 60 | case UP: 61 | case DOWN: 62 | c.measure(widthSpec, heightSpec); 63 | setMeasuredSize(c.getMeasuredWidth(), c.getMeasuredHeight()); 64 | break; 65 | case LEFT: 66 | case RIGHT: 67 | mChild.measure(heightSpec, widthSpec); 68 | setMeasuredSize(c.getMeasuredHeight(), c.getMeasuredWidth()); 69 | } 70 | } 71 | 72 | @Override 73 | protected void render(GLRootView view, GL11 gl) { 74 | 75 | if (mOrientation == UP) { 76 | mChild.render(view, gl); 77 | return; 78 | } 79 | 80 | view.pushTransform(); 81 | Matrix matrix = view.getTransformation().getMatrix(); 82 | float width = getWidth(); 83 | float height = getHeight(); 84 | switch (mOrientation) { 85 | case DOWN: 86 | matrix.preRotate(180, width / 2, height / 2); 87 | break; 88 | case LEFT: 89 | matrix.preRotate(270, height / 2, height / 2); 90 | break; 91 | case RIGHT: 92 | matrix.preRotate(90, width / 2, width / 2); 93 | break; 94 | } 95 | mChild.render(view, gl); 96 | view.popTransform(); 97 | } 98 | 99 | @Override 100 | protected boolean dispatchTouchEvent(MotionEvent event) { 101 | float x = event.getX(); 102 | float y = event.getY(); 103 | float width = getWidth(); 104 | float height = getHeight(); 105 | switch (mOrientation) { 106 | case DOWN: event.setLocation(width - x, height - y); break; 107 | case LEFT: event.setLocation(height - y, x); break; 108 | case RIGHT: event.setLocation(y, width - x); break; 109 | } 110 | boolean result = mChild.dispatchTouchEvent(event); 111 | event.setLocation(x, y); 112 | return result; 113 | } 114 | 115 | public void setOrientation(int orientation) { 116 | if (mOrientation == orientation) return; 117 | mOrientation = orientation; 118 | requestLayout(); 119 | } 120 | 121 | public void setContent(GLView view) { 122 | if (mChild == view) return; 123 | 124 | if (mChild != null) super.clearComponents(); 125 | mChild = view; 126 | if (view != null) super.addComponent(view); 127 | requestLayout(); 128 | } 129 | 130 | @Override 131 | public void addComponent(GLView view) { 132 | throw new UnsupportedOperationException("use setContent(GLView)"); 133 | } 134 | 135 | @Override 136 | public void clearComponents() { 137 | throw new UnsupportedOperationException("use setContent(null)"); 138 | } 139 | } 140 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/StringTexture.java: -------------------------------------------------------------------------------- 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.lightbox.android.camera.ui; 18 | 19 | import com.lightbox.android.camera.ui.CanvasTexture; 20 | import com.lightbox.android.camera.ui.StringTexture; 21 | 22 | import android.graphics.Bitmap; 23 | import android.graphics.Canvas; 24 | import android.graphics.Color; 25 | import android.graphics.Paint; 26 | import android.graphics.Paint.FontMetricsInt; 27 | 28 | class StringTexture extends CanvasTexture { 29 | private static int DEFAULT_PADDING = 2; 30 | 31 | private final String mText; 32 | private final Paint mPaint; 33 | private final FontMetricsInt mMetrics; 34 | 35 | public StringTexture(String text, Paint paint, 36 | FontMetricsInt metrics, int width, int height) { 37 | super(width, height); 38 | mText = text; 39 | mPaint = paint; 40 | mMetrics = metrics; 41 | } 42 | 43 | 44 | public static StringTexture newInstance(String text, Paint paint) { 45 | FontMetricsInt metrics = paint.getFontMetricsInt(); 46 | int width = (int) (.5f + paint.measureText(text)) + DEFAULT_PADDING * 2; 47 | int height = metrics.bottom - metrics.top + DEFAULT_PADDING * 2; 48 | return new StringTexture(text, paint, metrics, width, height); 49 | } 50 | 51 | public static StringTexture newInstance( 52 | String text, float textSize, int color) { 53 | Paint paint = new Paint(); 54 | paint.setTextSize(textSize); 55 | paint.setAntiAlias(true); 56 | paint.setColor(color); 57 | paint.setShadowLayer(1.5f, 0, 0, Color.BLACK); 58 | 59 | return newInstance(text, paint); 60 | } 61 | 62 | @Override 63 | protected void onDraw(Canvas canvas, Bitmap backing) { 64 | canvas.translate(DEFAULT_PADDING, DEFAULT_PADDING - mMetrics.ascent); 65 | canvas.drawText(mText, 0, 0, mPaint); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/Texture.java: -------------------------------------------------------------------------------- 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.lightbox.android.camera.ui; 18 | 19 | import com.lightbox.android.camera.ui.GLRootView; 20 | 21 | interface Texture { 22 | public void draw(GLRootView root, int x, int y); 23 | public void draw(GLRootView root, int x, int y, int w, int h); 24 | } 25 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/ZoomControllerListener.java: -------------------------------------------------------------------------------- 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.lightbox.android.camera.ui; 18 | 19 | public interface ZoomControllerListener { 20 | public void onZoomChanged(int index, float ratio, boolean isMoving); 21 | } 22 | 23 | -------------------------------------------------------------------------------- /Camera/src/com/lightbox/android/camera/ui/ZoomIndicator.java: -------------------------------------------------------------------------------- 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.lightbox.android.camera.ui; 18 | 19 | import java.text.DecimalFormat; 20 | 21 | import android.content.Context; 22 | 23 | import com.lightbox.android.camera.R; 24 | 25 | class ZoomIndicator extends AbstractIndicator { 26 | private static final DecimalFormat sZoomFormat = new DecimalFormat("#.#x"); 27 | private static final float FONT_SIZE = 18; 28 | private static final int FONT_COLOR = 0xA8FFFFFF; 29 | private static final int COLOR_OPTION_HEADER = 0xFF2B2B2B; 30 | 31 | protected static final String TAG = "ZoomIndicator"; 32 | 33 | private final float mFontSize; 34 | 35 | private ZoomController mZoomController; 36 | private LinearLayout mPopupContent; 37 | private ZoomControllerListener mZoomListener; 38 | private int mZoomIndex = 0; 39 | private int mDrawIndex = -1; 40 | private float mZoomRatios[]; 41 | 42 | private StringTexture mTitle; 43 | 44 | public ZoomIndicator(Context context) { 45 | super(context); 46 | mFontSize = GLRootView.dpToPixel(context, FONT_SIZE); 47 | } 48 | 49 | @Override 50 | protected void onMeasure(int widthSpec, int heightSpec) { 51 | int maxWidth = 0; 52 | int maxHeight = 0; 53 | int n = mZoomRatios == null ? 0: mZoomRatios.length; 54 | for (int i = 0; i < n; ++i) { 55 | float value = mZoomRatios[i]; 56 | BitmapTexture tex = StringTexture.newInstance( 57 | sZoomFormat.format(value), mFontSize, FONT_COLOR); 58 | if (maxWidth < tex.getWidth()) maxWidth = tex.getWidth(); 59 | if (maxHeight < tex.getHeight()) maxHeight = tex.getHeight(); 60 | } 61 | new MeasureHelper(this) 62 | .setPreferredContentSize(maxWidth, maxHeight) 63 | .measure(widthSpec, heightSpec); 64 | } 65 | 66 | @Override 67 | protected BitmapTexture getIcon() { 68 | if (mDrawIndex != mZoomIndex) { 69 | mDrawIndex = mZoomIndex; 70 | if (mTitle != null) mTitle.deleteFromGL(); 71 | float value = mZoomRatios[mZoomIndex]; 72 | mTitle = StringTexture.newInstance( 73 | sZoomFormat.format(value), mFontSize, FONT_COLOR); 74 | } 75 | return mTitle; 76 | } 77 | 78 | @Override 79 | public GLView getPopupContent() { 80 | if (mZoomController == null) { 81 | Context context = getGLRootView().getContext(); 82 | mZoomController = new ZoomController(context); 83 | mZoomController.setAvailableZoomRatios(mZoomRatios); 84 | mZoomController.setPaddings(15, 6, 15, 6); 85 | 86 | mPopupContent = new LinearLayout(); 87 | GLOptionHeader header = new GLOptionHeader(context, 88 | context.getString(R.string.zoom_control_title)); 89 | header.setBackground(new ColorTexture(COLOR_OPTION_HEADER)); 90 | header.setPaddings(6, 3, 6, 3); 91 | mPopupContent.addComponent(header); 92 | mPopupContent.addComponent(mZoomController); 93 | 94 | mZoomController.setZoomListener(new MyZoomListener()); 95 | mZoomController.setZoomIndex(mZoomIndex); 96 | } 97 | return mPopupContent; 98 | } 99 | 100 | @Override 101 | public void overrideSettings(String key, String settings) { 102 | // do nothing 103 | } 104 | 105 | @Override 106 | public void reloadPreferences() { 107 | // do nothing 108 | } 109 | 110 | public void setZoomRatios(float[] ratios) { 111 | mZoomRatios = ratios; 112 | mDrawIndex = -1; 113 | invalidate(); 114 | } 115 | 116 | private class MyZoomListener implements ZoomControllerListener { 117 | public void onZoomChanged(int index, float value, boolean isMoving) { 118 | if (mZoomListener != null) { 119 | mZoomListener.onZoomChanged(index, value, isMoving); 120 | } 121 | if (mZoomIndex != index) onZoomIndexChanged(index); 122 | } 123 | } 124 | 125 | private void onZoomIndexChanged(int index) { 126 | if (mZoomIndex == index) return; 127 | mZoomIndex = index; 128 | invalidate(); 129 | } 130 | 131 | public void setZoomListener(ZoomControllerListener listener) { 132 | mZoomListener = listener; 133 | } 134 | 135 | public void setZoomIndex(int index) { 136 | if (mZoomIndex == index) return; 137 | if (mZoomController != null) { 138 | mZoomController.setZoomIndex(index); 139 | } else { 140 | onZoomIndexChanged(index); 141 | } 142 | } 143 | } 144 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | QuickSnap 2 | ========= 3 | 4 | Android camera implementation based off the official Android Gingerbread camera app source code. 5 | 6 | Initially the Android Gingerbread camera source was forked, and then modified to become backwards compatible down to API level 7 (Eclair). The video functionality has also been removed. 7 | 8 | The code was then further modified to support the following devices that did not work correctly: 9 | * HTC Evo 10 | * HTC Desire S 11 | * Samsung Captivate 12 | * LG G2X 13 | * LG Optimus 2X 14 | These were primarily devices that had trouble with their front facing cameras. 15 | 16 | In the original Gingerbread stock camera app there was a second confirmation step after each photo was taken. This has been removed to make it easier and quicker to take several photos in quick succession. 17 | 18 | Additional work has been done to de-activiate the shutter sound and animate the preview, which can be selected via the settings. 19 | 20 | ## License 21 | Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0.html) 22 | -------------------------------------------------------------------------------- /README.md~: -------------------------------------------------------------------------------- 1 | QuickSnap 2 | ========= 3 | 4 | Android camera implementation based off the official Android Gingerbread camera app source code. 5 | 6 | Initially the Android Gingerbread camera source was forked, and then modified to become backwards compatible down to API level 7 (Eclair). The video functionality has also been removed. 7 | 8 | The code was then further modified to support specific devices that did not work correctly. Primarily devices that had trouble with their front facing cameras. 9 | 10 | In the original Gingerbread stock camera app there was a second confirmation step after each photo was taken. This has been removed to make it easier and quicker to take several photos in quick succession. 11 | 12 | Additional work has been done to de-activiate the shutter sound and animate the preview, which can be selected via the settings. 13 | 14 | ## License 15 | Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0.html) 16 | --------------------------------------------------------------------------------