diff options
Diffstat (limited to 'src/com/android/camera/CameraActivity.java')
-rwxr-xr-x | src/com/android/camera/CameraActivity.java | 151 |
1 files changed, 124 insertions, 27 deletions
diff --git a/src/com/android/camera/CameraActivity.java b/src/com/android/camera/CameraActivity.java index 9e1855ff3..2933ed4e5 100755 --- a/src/com/android/camera/CameraActivity.java +++ b/src/com/android/camera/CameraActivity.java @@ -1,5 +1,6 @@ /* * Copyright (C) 2012 The Android Open Source Project + * Copyright (C) 2013-2015 The CyanogenMod Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -120,6 +121,8 @@ import com.android.camera.util.PhotoSphereHelper.PanoramaViewHelper; import com.android.camera.util.UsageStatistics; import org.codeaurora.snapcam.R; +import org.lineageos.quickreader.ScannerActivity; + import java.io.File; import java.io.IOException; @@ -169,7 +172,7 @@ public class CameraActivity extends Activity private static final int SWITCH_SAVE_PATH = 2; /** Permission request code */ - private static final int PERMISSIONS_REQUEST_ACCESS_COARSE_LOCATION = 1; + private static final int PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION = 1; /** Whether onResume should reset the view to the preview. */ private boolean mResetToPreviewOnResume = true; @@ -192,11 +195,15 @@ public class CameraActivity extends Activity private static boolean PIE_MENU_ENABLED = false; private boolean mDeveloperMenuEnabled = false; + private boolean mCamera2supported = false; + private boolean mCamera2enabled = false; + /** This data adapter is used by FilmStripView. */ private LocalDataAdapter mDataAdapter; /** This data adapter represents the real local camera data. */ private LocalDataAdapter mWrappedDataAdapter; + private Context mContext; private PanoramaStitchingManager mPanoramaManager; private PlaceholderManager mPlaceholderManager; private int mCurrentModuleIndex; @@ -221,6 +228,11 @@ public class CameraActivity extends Activity private final Object mStorageSpaceLock = new Object(); private long mStorageSpaceBytes = Storage.LOW_STORAGE_THRESHOLD_BYTES; private boolean mSecureCamera; + private boolean mInCameraApp = true; + // Keep track of powershutter state + public static boolean mPowerShutter = false; + // Keep track of max brightness state + public static boolean mMaxBrightness = false; private int mLastRawOrientation; private MyOrientationEventListener mOrientationListener; private Handler mMainHandler; @@ -390,6 +402,10 @@ public class CameraActivity extends Activity mDeveloperMenuEnabled = true; } + public void disableDeveloperMenu() { + mDeveloperMenuEnabled = false; + } + private String fileNameFromDataID(int dataID) { final LocalData localData = mDataAdapter.getLocalData(dataID); @@ -610,14 +626,36 @@ public class CameraActivity extends Activity intent.putExtra(KEY_TOTAL_NUMBER, (adapter.getTotalNumber() -1)); startActivity(intent); } catch (ActivityNotFoundException ex) { - try { - Log.w(TAG, "Gallery not found"); - Intent intent = new Intent(Intent.ACTION_VIEW, uri); - intent.putExtra(KEY_FROM_SNAPCAM, true); - startActivity(intent); - } catch (ActivityNotFoundException e) { - Log.w(TAG, "No Activity could be found to open image or video"); - } + gotoReviewPhoto(uri); + } catch (IllegalArgumentException ex) { + gotoReviewPhoto(uri); + } + } + + private void gotoReviewPhoto(Uri uri) { + try { + Log.w(TAG, "Gallery not found"); + Intent intent = new Intent(CameraUtil.REVIEW_ACTION, uri); + startActivity(intent); + intent.putExtra(KEY_FROM_SNAPCAM, true); + intent.putExtra(KEY_TOTAL_NUMBER, getDataAdapter().getTotalNumber() - 1); + } catch (ActivityNotFoundException e) { + gotoViewPhoto(uri); + } catch (IllegalArgumentException e) { + gotoViewPhoto(uri); + } + } + + private void gotoViewPhoto(Uri uri) { + try { + Log.w(TAG, "Gallery not found"); + Intent intent = new Intent(Intent.ACTION_VIEW, uri); + intent.putExtra(KEY_FROM_SNAPCAM, true); + startActivity(intent); + } catch (ActivityNotFoundException e) { + Log.w(TAG, "No Activity could be found to open image or video"); + } catch (IllegalArgumentException e) { + Log.w(TAG, "No Activity could be found to open image or video"); } } @@ -1343,14 +1381,8 @@ public class CameraActivity extends Activity // Handle presses on the action bar items switch (item.getItemId()) { case android.R.id.home: - // ActionBar's Up/Home button was clicked - try { - startActivity(IntentHelper.getGalleryIntent(this)); - return true; - } catch (ActivityNotFoundException e) { - Log.w(TAG, "Failed to launch gallery activity, closing"); - finish(); - } + onBackPressed(); + return true; case R.id.action_delete: UsageStatistics.onEvent(UsageStatistics.COMPONENT_CAMERA, UsageStatistics.ACTION_DELETE, null, 0, @@ -1465,6 +1497,9 @@ public class CameraActivity extends Activity } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); } + + mContext = getApplicationContext(); + // Check if this is in the secure camera mode. Intent intent = getIntent(); String action = intent.getAction(); @@ -1541,9 +1576,16 @@ public class CameraActivity extends Activity } } - boolean cam2on = PersistUtil.getCamera2Mode(); - CameraHolder.setCamera2Mode(this, cam2on); - if (cam2on && (moduleIndex == ModuleSwitcher.PHOTO_MODULE_INDEX || + // Check if the device supports Camera API 2 + mCamera2supported = CameraUtil.isCamera2Supported(mContext); + Log.d(TAG, "Camera API 2 supported: " + mCamera2supported); + + mCamera2enabled = mCamera2supported && + mContext.getResources().getBoolean(R.bool.support_camera_api_v2); + Log.d(TAG, "Camera API 2 enabled: " + mCamera2enabled); + + CameraHolder.setCamera2Mode(this, mCamera2enabled); + if (mCamera2enabled && (moduleIndex == ModuleSwitcher.PHOTO_MODULE_INDEX || moduleIndex == ModuleSwitcher.VIDEO_MODULE_INDEX)) moduleIndex = ModuleSwitcher.CAPTURE_MODULE_INDEX; @@ -1899,6 +1941,9 @@ public class CameraActivity extends Activity mCursor.close(); mCursor=null; } + if (mDataAdapter != null) { + mDataAdapter.stopLoading(); + } if (mAutoTestEnabled) { unregisterReceiver(mAutoTestReceiver); } @@ -1949,7 +1994,9 @@ public class CameraActivity extends Activity } public void setPreviewGestures(PreviewGestures previewGestures) { - mFilmStripView.setPreviewGestures(previewGestures); + if (mFilmStripView != null) { + mFilmStripView.setPreviewGestures(previewGestures); + } } protected long updateStorageSpace() { @@ -2024,6 +2071,39 @@ public class CameraActivity extends Activity } } + protected void initPowerShutter(ComboPreferences prefs) { + String val = prefs.getString(CameraSettings.KEY_POWER_SHUTTER, + getResources().getString(R.string.pref_camera_power_shutter_default)); + if (!CameraUtil.hasCameraKey()) { + mPowerShutter = val.equals(CameraSettings.VALUE_ON); + } + if (mPowerShutter && mInCameraApp) { + getWindow().addPrivateFlags( + WindowManager.LayoutParams.PRIVATE_FLAG_PREVENT_POWER_KEY); + } else { + getWindow().clearPrivateFlags( + WindowManager.LayoutParams.PRIVATE_FLAG_PREVENT_POWER_KEY); + } + } + + protected void initMaxBrightness(ComboPreferences prefs) { + String val = prefs.getString(CameraSettings.KEY_MAX_BRIGHTNESS, + getResources().getString(R.string.pref_camera_max_brightness_default)); + + Window win = getWindow(); + WindowManager.LayoutParams params = win.getAttributes(); + + mMaxBrightness = val.equals(CameraSettings.VALUE_ON); + + if (mMaxBrightness && mInCameraApp) { + params.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_FULL; + } else { + params.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE; + } + + win.setAttributes(params); + } + protected void setResultEx(int resultCode) { mResultCodeForTesting = resultCode; setResult(resultCode); @@ -2048,13 +2128,13 @@ public class CameraActivity extends Activity } public void requestLocationPermission() { - if (checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) + if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) { Log.v(TAG, "Request Location permission"); mCurrentModule.waitingLocationPermissionResult(true); requestPermissions( - new String[]{Manifest.permission.ACCESS_COARSE_LOCATION}, - PERMISSIONS_REQUEST_ACCESS_COARSE_LOCATION); + new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, + PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION); } } @@ -2062,7 +2142,7 @@ public class CameraActivity extends Activity public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) { switch (requestCode) { - case PERMISSIONS_REQUEST_ACCESS_COARSE_LOCATION: { + case PERMISSIONS_REQUEST_ACCESS_FINE_LOCATION: { // If request is cancelled, the result arrays are empty. mCurrentModule.waitingLocationPermissionResult(false); if (grantResults.length > 0 @@ -2082,11 +2162,21 @@ public class CameraActivity extends Activity return mForceReleaseCamera; } + public boolean isInCameraApp() { + return mInCameraApp; + } + @Override public void onModuleSelected(int moduleIndex) { - boolean cam2on = PersistUtil.getCamera2Mode(); + if (moduleIndex == ModuleSwitcher.QR_MODULE_INDEX) { + Intent intent = new Intent(this, ScannerActivity.class); + intent.putExtra(SECURE_CAMERA_EXTRA, mSecureCamera); + startActivity(intent); + return; + } + mForceReleaseCamera = moduleIndex == ModuleSwitcher.CAPTURE_MODULE_INDEX || - (cam2on && moduleIndex == ModuleSwitcher.PHOTO_MODULE_INDEX); + (mCamera2enabled && moduleIndex == ModuleSwitcher.PHOTO_MODULE_INDEX); if (mForceReleaseCamera) { moduleIndex = ModuleSwitcher.CAPTURE_MODULE_INDEX; } @@ -2358,6 +2448,9 @@ public class CameraActivity extends Activity * @return whether controls are visible. */ private boolean arePreviewControlsVisible() { + if (mCurrentModule == null) { + return false; + } return mCurrentModule.arePreviewControlsVisible(); } @@ -2369,6 +2462,10 @@ public class CameraActivity extends Activity */ private void setPreviewControlsVisibility(boolean showControls) { mCurrentModule.onPreviewFocusChanged(showControls); + + // controls are only shown when the camera app is active + // so we can assume to fetch this information from here + mInCameraApp = showControls; } // Accessor methods for getting latency times used in performance testing |