diff options
author | Danesh M <daneshm90@gmail.com> | 2015-02-03 20:05:13 -0800 |
---|---|---|
committer | Michael Bestas <mikeioannina@gmail.com> | 2016-12-30 17:17:51 +0200 |
commit | 3fb9cb68995d21f1763ed6b8a8928473b60aee95 (patch) | |
tree | cb6707746235a595bdcd4131cd8caf587c7cbb8f /src | |
parent | 05c789c87a4204e11a1a70654cfaf382e2f7dc6b (diff) | |
download | android_packages_apps_Camera2-3fb9cb68995d21f1763ed6b8a8928473b60aee95.tar.gz android_packages_apps_Camera2-3fb9cb68995d21f1763ed6b8a8928473b60aee95.tar.bz2 android_packages_apps_Camera2-3fb9cb68995d21f1763ed6b8a8928473b60aee95.zip |
Camera: Powerkey shutter (2/2)
Change-Id: I70c5cd4dad547e2a9a96541b3104d52af5b5dd5c
Diffstat (limited to 'src')
-rw-r--r-- | src/android/util/Pools.java | 165 | ||||
-rw-r--r-- | src/com/android/camera/CameraActivity.java | 35 | ||||
-rw-r--r-- | src/com/android/camera/settings/AppUpgrader.java | 24 | ||||
-rw-r--r-- | src/com/android/camera/settings/Keys.java | 9 |
4 files changed, 66 insertions, 167 deletions
diff --git a/src/android/util/Pools.java b/src/android/util/Pools.java deleted file mode 100644 index 40bab1eae..000000000 --- a/src/android/util/Pools.java +++ /dev/null @@ -1,165 +0,0 @@ -/* - * Copyright (C) 2009 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.util; - -/** - * Helper class for crating pools of objects. An example use looks like this: - * <pre> - * public class MyPooledClass { - * - * private static final SynchronizedPool<MyPooledClass> sPool = - * new SynchronizedPool<MyPooledClass>(10); - * - * public static MyPooledClass obtain() { - * MyPooledClass instance = sPool.acquire(); - * return (instance != null) ? instance : new MyPooledClass(); - * } - * - * public void recycle() { - * // Clear state if needed. - * sPool.release(this); - * } - * - * . . . - * } - * </pre> - * - * @hide - */ -public final class Pools { - - /** - * Interface for managing a pool of objects. - * - * @param <T> The pooled type. - */ - public static interface Pool<T> { - - /** - * @return An instance from the pool if such, null otherwise. - */ - public T acquire(); - - /** - * Release an instance to the pool. - * - * @param instance The instance to release. - * @return Whether the instance was put in the pool. - * - * @throws IllegalStateException If the instance is already in the pool. - */ - public boolean release(T instance); - } - - private Pools() { - /* do nothing - hiding constructor */ - } - - /** - * Simple (non-synchronized) pool of objects. - * - * @param <T> The pooled type. - */ - public static class SimplePool<T> implements Pool<T> { - private final Object[] mPool; - - private int mPoolSize; - - /** - * Creates a new instance. - * - * @param maxPoolSize The max pool size. - * - * @throws IllegalArgumentException If the max pool size is less than zero. - */ - public SimplePool(int maxPoolSize) { - if (maxPoolSize <= 0) { - throw new IllegalArgumentException("The max pool size must be > 0"); - } - mPool = new Object[maxPoolSize]; - } - - @Override - @SuppressWarnings("unchecked") - public T acquire() { - if (mPoolSize > 0) { - final int lastPooledIndex = mPoolSize - 1; - T instance = (T) mPool[lastPooledIndex]; - mPool[lastPooledIndex] = null; - mPoolSize--; - return instance; - } - return null; - } - - @Override - public boolean release(T instance) { - if (isInPool(instance)) { - throw new IllegalStateException("Already in the pool!"); - } - if (mPoolSize < mPool.length) { - mPool[mPoolSize] = instance; - mPoolSize++; - return true; - } - return false; - } - - private boolean isInPool(T instance) { - for (int i = 0; i < mPoolSize; i++) { - if (mPool[i] == instance) { - return true; - } - } - return false; - } - } - - /** - * Synchronized) pool of objects. - * - * @param <T> The pooled type. - */ - public static class SynchronizedPool<T> extends SimplePool<T> { - private final Object mLock = new Object(); - - /** - * Creates a new instance. - * - * @param maxPoolSize The max pool size. - * - * @throws IllegalArgumentException If the max pool size is less than zero. - */ - public SynchronizedPool(int maxPoolSize) { - super(maxPoolSize); - } - - @Override - public T acquire() { - synchronized (mLock) { - return super.acquire(); - } - } - - @Override - public boolean release(T element) { - synchronized (mLock) { - return super.release(element); - } - } - } -}
\ No newline at end of file diff --git a/src/com/android/camera/CameraActivity.java b/src/com/android/camera/CameraActivity.java index d797aa7b2..a1357b49c 100644 --- a/src/com/android/camera/CameraActivity.java +++ b/src/com/android/camera/CameraActivity.java @@ -173,7 +173,8 @@ import java.util.List; public class CameraActivity extends QuickActivity implements AppController, CameraAgent.CameraOpenCallback, - ShareActionProvider.OnShareTargetSelectedListener { + ShareActionProvider.OnShareTargetSelectedListener, + SettingsManager.OnSettingChangedListener { private static final Log.Tag TAG = new Log.Tag("CameraActivity"); @@ -293,6 +294,9 @@ public class CameraActivity extends QuickActivity /** First run dialog */ private FirstRunDialog mFirstRunDialog; + // Keep track of powershutter state + public boolean mPowerShutter; + @Override public CameraAppUI getCameraAppUI() { return mCameraAppUI; @@ -565,6 +569,13 @@ public class CameraActivity extends QuickActivity mFatalErrorHandler.onCameraReconnectFailure(); } + @Override + public void onSettingChanged(SettingsManager settingsManager, String key) { + if (key.equals(Keys.KEY_POWER_SHUTTER)) { + initPowerShutter(); + } + } + private static class MainHandler extends Handler { final WeakReference<CameraActivity> mActivity; @@ -1496,6 +1507,8 @@ public class CameraActivity extends QuickActivity ModulesInfo.setupModules(mAppContext, mModuleManager, mFeatureConfig); + initPowerShutter(); + AppUpgrader appUpgrader = new AppUpgrader(this); appUpgrader.upgrade(mSettingsManager); @@ -2209,9 +2222,25 @@ public class CameraActivity extends QuickActivity } } + protected void initPowerShutter() { + mPowerShutter = Keys.isPowerShutterOn(mSettingsManager); + if (mPowerShutter) { + getWindow().addPrivateFlags( + WindowManager.LayoutParams.PRIVATE_FLAG_PREVENT_POWER_KEY); + } else { + getWindow().clearPrivateFlags( + WindowManager.LayoutParams.PRIVATE_FLAG_PREVENT_POWER_KEY); + } + } + @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (!mFilmstripVisible) { + if (mPowerShutter && keyCode == KeyEvent.KEYCODE_POWER && + event.getRepeatCount() == 0) { + mCurrentModule.onShutterButtonFocus(true); + return true; + } if (mCurrentModule.onKeyDown(keyCode, event)) { return true; } @@ -2230,6 +2259,10 @@ public class CameraActivity extends QuickActivity @Override public boolean onKeyUp(int keyCode, KeyEvent event) { if (!mFilmstripVisible) { + if (mPowerShutter && keyCode == KeyEvent.KEYCODE_POWER) { + mCurrentModule.onShutterButtonClick(); + return true; + } // If a module is in the middle of capture, it should // consume the key event. if (mCurrentModule.onKeyUp(keyCode, event)) { diff --git a/src/com/android/camera/settings/AppUpgrader.java b/src/com/android/camera/settings/AppUpgrader.java index 92bd953d1..113f4d23b 100644 --- a/src/com/android/camera/settings/AppUpgrader.java +++ b/src/com/android/camera/settings/AppUpgrader.java @@ -85,10 +85,16 @@ public class AppUpgrader extends SettingsUpgrader { * resolution size on the N5 since we stored it with a swapped width/height. */ public static final int NEEDS_N5_16by9_RESOLUTION_SWAP = 7; + + /** + * With this version, port over power shutter settings. + */ + private static final int CAMERA_SETTINGS_POWER_SHUTTER = 8; + /** * Increment this value whenever new AOSP UpgradeSteps need to be executed. */ - public static final int APP_UPGRADE_VERSION = 7; + public static final int APP_UPGRADE_VERSION = 8; private final AppController mAppController; @@ -160,6 +166,10 @@ public class AppUpgrader extends SettingsUpgrader { if (lastVersion < NEEDS_N5_16by9_RESOLUTION_SWAP) { updateN516by9ResolutionIfNeeded(settingsManager); } + + if (lastVersion < CAMERA_SETTINGS_POWER_SHUTTER) { + upgradePowerShutter(settingsManager); + } } /** @@ -431,6 +441,18 @@ public class AppUpgrader extends SettingsUpgrader { } } + private void upgradePowerShutter(SettingsManager settingsManager) { + SharedPreferences oldGlobalPreferences = + settingsManager.openPreferences(OLD_GLOBAL_PREFERENCES_FILENAME); + if (oldGlobalPreferences.contains(Keys.KEY_POWER_SHUTTER)) { + String powerShutter = removeString(oldGlobalPreferences, Keys.KEY_POWER_SHUTTER); + if (OLD_SETTINGS_VALUE_ON.equals(powerShutter)) { + settingsManager.set(SettingsManager.SCOPE_GLOBAL, Keys.KEY_POWER_SHUTTER, + true); + } + } + } + /** * The R.integer.camera_mode_* indices were cleaned up, resulting in * removals and renaming of certain values. In particular camera_mode_gcam diff --git a/src/com/android/camera/settings/Keys.java b/src/com/android/camera/settings/Keys.java index 0339ea6c7..31200b30d 100644 --- a/src/com/android/camera/settings/Keys.java +++ b/src/com/android/camera/settings/Keys.java @@ -81,6 +81,7 @@ public class Keys { public static final String KEY_SHOULD_SHOW_SETTINGS_BUTTON_CLING = "pref_should_show_settings_button_cling"; public static final String KEY_HAS_SEEN_PERMISSIONS_DIALOGS = "pref_has_seen_permissions_dialogs"; + public static final String KEY_POWER_SHUTTER = "pref_power_shutter"; /** * Set some number of defaults for the defined keys. @@ -223,5 +224,13 @@ public class Keys { return settingsManager.getBoolean(SettingsManager.SCOPE_GLOBAL, KEY_CAMERA_GRID_LINES); } + + /** + * Returns whether power shutter is set on. + */ + public static boolean isPowerShutterOn(SettingsManager settingsManager) { + return settingsManager.getBoolean(SettingsManager.SCOPE_GLOBAL, + KEY_POWER_SHUTTER); + } } |