diff options
author | Owen Lin <owenlin@google.com> | 2009-09-14 19:04:37 +0800 |
---|---|---|
committer | Owen Lin <owenlin@google.com> | 2009-09-17 16:46:55 +0800 |
commit | c1f2e3021bf7b12f2a33561e09bd0ab32530382e (patch) | |
tree | 3bdf5eb09893e3fd39d9af8e64dcefc1a41e7abf /src/com/android/camera | |
parent | 83c371d93f9513d317fcabb5783cce5091274c34 (diff) | |
download | LegacyCamera-c1f2e3021bf7b12f2a33561e09bd0ab32530382e.zip LegacyCamera-c1f2e3021bf7b12f2a33561e09bd0ab32530382e.tar.gz LegacyCamera-c1f2e3021bf7b12f2a33561e09bd0ab32530382e.tar.bz2 |
Implement the drawer UI. When user click on the drawer button, the
on-screen settings will show up.
Change-Id: I86a587969a9a01d62560e21d457d3639841ba6da
Diffstat (limited to 'src/com/android/camera')
-rw-r--r-- | src/com/android/camera/Camera.java | 47 | ||||
-rw-r--r-- | src/com/android/camera/OnScreenSettings.java | 89 | ||||
-rw-r--r-- | src/com/android/camera/Util.java | 6 | ||||
-rw-r--r-- | src/com/android/camera/VideoCamera.java | 44 |
4 files changed, 135 insertions, 51 deletions
diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index e037f39..7511d95 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -85,6 +85,7 @@ import java.util.List; public class Camera extends Activity implements View.OnClickListener, ShutterButton.OnShutterButtonListener, SurfaceHolder.Callback, Switcher.OnSwitchListener, FlashButton.ModeChangeListener, + OnScreenSettings.OnVisibilityChangedListener, OnSharedPreferenceChangeListener { private static final String TAG = "camera"; @@ -386,6 +387,13 @@ public class Camera extends Activity implements View.OnClickListener, }); } + public void onVisibilityChanged(boolean visible) { + // When the on-screen setting is not displayed, we show the gripper. + // When the on-screen setting is displayed, we hide the gripper. + findViewById(R.id.btn_gripper).setVisibility( + visible ? View.INVISIBLE : View.VISIBLE); + } + private void zoomToLevel(String type) { if (type == null) { Log.e(TAG, "Zoom type is null."); @@ -895,6 +903,8 @@ public class Camera extends Activity implements View.OnClickListener, mSwitcher.setOnSwitchListener(this); mSwitcher.addTouchView(findViewById(R.id.camera_switch_set)); } + findViewById(R.id.btn_gripper) + .setOnTouchListener(new GripperTouchListener()); // Make sure preview is started. try { @@ -911,6 +921,19 @@ public class Camera extends Activity implements View.OnClickListener, resizeForPreviewAspectRatio(mSurfaceView); } + private class GripperTouchListener implements View.OnTouchListener { + public boolean onTouch(View view, MotionEvent event) { + switch (event.getAction()) { + case MotionEvent.ACTION_DOWN: + return true; + case MotionEvent.ACTION_UP: + showOnScreenSettings(); + return true; + } + return false; + } + } + @Override public void onStart() { super.onStart(); @@ -928,6 +951,18 @@ public class Camera extends Activity implements View.OnClickListener, updateStorageHint(mPicturesRemaining); } + private void showOnScreenSettings() { + if (mSettings == null) { + mSettings = new OnScreenSettings( + findViewById(R.id.camera_preview)); + CameraSettings helper = new CameraSettings(this, mParameters); + mSettings.setPreferenceScreen(helper + .getPreferenceScreen(R.xml.camera_preferences)); + mSettings.setOnVisibilityChangedListener(this); + } + mSettings.expandPanel(); + } + public void onClick(View v) { switch (v.getId()) { case R.id.btn_retake: @@ -1043,7 +1078,7 @@ public class Camera extends Activity implements View.OnClickListener, } Intent cropIntent = new Intent(); - cropIntent.setClass(Camera.this, CropImage.class); + cropIntent.setClass(this, CropImage.class); cropIntent.setData(tempUri); cropIntent.putExtras(newExtras); @@ -1776,15 +1811,7 @@ public class Camera extends Activity implements View.OnClickListener, MenuHelper.POSITION_CAMERA_SETTING, R.string.settings) .setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { - if (mSettings == null) { - mSettings = new OnScreenSettings( - findViewById(R.id.camera_preview)); - CameraSettings helper = - new CameraSettings(Camera.this, mParameters); - mSettings.setPreferenceScreen(helper - .getPreferenceScreen(R.xml.camera_preferences)); - } - mSettings.setVisible(true); + showOnScreenSettings(); return true; } }); diff --git a/src/com/android/camera/OnScreenSettings.java b/src/com/android/camera/OnScreenSettings.java index b61e6a7..4107900 100644 --- a/src/com/android/camera/OnScreenSettings.java +++ b/src/com/android/camera/OnScreenSettings.java @@ -10,9 +10,12 @@ import android.preference.Preference; import android.preference.PreferenceGroup; import android.preference.PreferenceScreen; import android.util.Log; +import android.view.animation.Animation; +import android.view.animation.Animation.AnimationListener; import android.view.Gravity; import android.view.KeyEvent; import android.view.LayoutInflater; +import android.view.MotionEvent; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; @@ -32,7 +35,8 @@ import java.util.ArrayList; // information about adding window to WindowManager. public class OnScreenSettings { private static final String TAG = "OnScreenSettings"; - private static final int MSG_POST_SET_VISIBLE = 1; + private static final int MSG_POST_SET_HIDE = 1; + private static final int MSG_POST_SET_VISIBLE = 2; public interface OnVisibilityChangedListener { public void onVisibilityChanged(boolean visibility); @@ -45,26 +49,19 @@ public class OnScreenSettings { private final View mOwnerView; private ListView mMainMenu; private ListView mSubMenu; + private View mMainPanel; private boolean mIsVisible = false; private OnVisibilityChangedListener mVisibilityListener; private MainMenuAdapter mMainAdapter; - /** - * When showing the on-screen settings, we add the view as a new window. - * However, there is logic that needs to know the size of the zoom which - * is determined after it's laid out. Therefore, we must post this logic - * onto the UI thread so it will be exceuted AFTER the layout. This is - * the logic. - */ - private Runnable mPostedVisibleInitializer; private final LayoutInflater mInflater; private final Handler mHandler = new Handler() { @Override public void handleMessage(Message msg) { switch (msg.what) { - case MSG_POST_SET_VISIBLE: - setVisible(true); + case MSG_POST_SET_HIDE: + setVisible(false); break; } } @@ -91,6 +88,7 @@ public class OnScreenSettings { } public void setVisible(boolean visible) { + mHandler.removeMessages(MSG_POST_SET_VISIBLE); if (visible) { if (mOwnerView.getWindowToken() == null) { /* @@ -98,9 +96,7 @@ public class OnScreenSettings { * window hasn't been created yet but it will have been by the * time the looper is idle, so post the setVisible(true) call. */ - if (!mHandler.hasMessages(MSG_POST_SET_VISIBLE)) { - mHandler.sendEmptyMessage(MSG_POST_SET_VISIBLE); - } + mHandler.sendEmptyMessage(MSG_POST_SET_VISIBLE); return; } } @@ -116,15 +112,8 @@ public class OnScreenSettings { if (mContainerLayoutParams.token == null) { mContainerLayoutParams.token = mOwnerView.getWindowToken(); } - if (mPostedVisibleInitializer == null) { - mPostedVisibleInitializer = new Runnable() { - public void run() { - refreshPositioningVariables(); - } - }; - } mWindowManager.addView(mContainer, mContainerLayoutParams); - mHandler.post(mPostedVisibleInitializer); + refreshPositioningVariables(); } else { // Reset the two menus mSubMenu.setAdapter(null); @@ -132,13 +121,34 @@ public class OnScreenSettings { mMainMenu.setVisibility(View.VISIBLE); mWindowManager.removeView(mContainer); - mHandler.removeCallbacks(mPostedVisibleInitializer); } if (mVisibilityListener != null) { mVisibilityListener.onVisibilityChanged(mIsVisible); } } + public void expandPanel() { + setVisible(true); + Util.slideIn(mMainPanel, Util.DIRECTION_LEFT); + } + + public void collapsePanel() { + Util.slideOut(mMainPanel, Util.DIRECTION_LEFT) + .setAnimationListener(new AnimationListener() { + public void onAnimationEnd(Animation animation) { + // Cannot setVisible(false) here, GC will recycle something + // still in use and result in SEGFAULT in skia + mHandler.sendEmptyMessage(MSG_POST_SET_HIDE); + } + + public void onAnimationStart(Animation animation) { + } + + public void onAnimationRepeat(Animation animation) { + } + }); + } + private void refreshPositioningVariables() { // if the mOwnerView is detached from window then skip. if (mOwnerView.getWindowToken() == null) return; @@ -157,8 +167,8 @@ public class OnScreenSettings { mContainerLayoutParams.x = mOwnerViewRawLocation[0]; mContainerLayoutParams.y = mOwnerViewRawLocation[1]; - mContainerLayoutParams.width = ownerWidth * 4 / 5; - mContainerLayoutParams.height = ownerHeight - 10; + mContainerLayoutParams.width = ownerWidth * 2 / 3; + mContainerLayoutParams.height = ownerHeight; if (mIsVisible) { mWindowManager.updateViewLayout(mContainer, mContainerLayoutParams); @@ -193,16 +203,43 @@ public class OnScreenSettings { mInflater.inflate(R.layout.on_screen_menu, container); + mMainPanel = container.findViewById(R.id.main_panel); mMainMenu = (ListView) container.findViewById(R.id.menu_view); mSubMenu = (ListView) container.findViewById(R.id.sub_menu); + + container.findViewById(R.id.btn_gripper) + .setOnTouchListener(new GripperTouchListener()); + return container; } + private class GripperTouchListener implements View.OnTouchListener { + public boolean onTouch(View view, MotionEvent event) { + switch (event.getAction()) { + case MotionEvent.ACTION_DOWN: + return true; + case MotionEvent.ACTION_UP: + collapsePanel(); + return true; + } + return false; + } + } + private boolean onContainerKey(KeyEvent event) { switch (event.getKeyCode()) { case KeyEvent.KEYCODE_BACK: if (event.getAction() == KeyEvent.ACTION_UP) { - setVisible(false); + if (mSubMenu.getVisibility() == View.VISIBLE) { + closeSubMenu(); + } else { + collapsePanel(); + } + return true; + } + case KeyEvent.KEYCODE_MENU: + if (event.getAction() == KeyEvent.ACTION_UP) { + collapsePanel(); return true; } } diff --git a/src/com/android/camera/Util.java b/src/com/android/camera/Util.java index da9caf6..c4dff80 100644 --- a/src/com/android/camera/Util.java +++ b/src/com/android/camera/Util.java @@ -539,7 +539,7 @@ public class Util { .show(); } - public static void slideOut(View view, int to) { + public static Animation slideOut(View view, int to) { view.setVisibility(View.INVISIBLE); Animation anim; switch (to) { @@ -560,9 +560,10 @@ public class Util { } anim.setDuration(500); view.startAnimation(anim); + return anim; } - public static void slideIn(View view, int from) { + public static Animation slideIn(View view, int from) { view.setVisibility(View.VISIBLE); Animation anim; switch (from) { @@ -583,6 +584,7 @@ public class Util { } anim.setDuration(500); view.startAnimation(anim); + return anim; } public static <T> T checkNotNull(T object) { diff --git a/src/com/android/camera/VideoCamera.java b/src/com/android/camera/VideoCamera.java index 21affac..df106ff 100644 --- a/src/com/android/camera/VideoCamera.java +++ b/src/com/android/camera/VideoCamera.java @@ -50,6 +50,7 @@ import android.view.KeyEvent; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; +import android.view.MotionEvent; import android.view.SurfaceHolder; import android.view.View; import android.view.ViewGroup; @@ -298,6 +299,8 @@ public class VideoCamera extends Activity implements View.OnClickListener, mShutterButton.setImageResource(R.drawable.btn_ic_video_record); mShutterButton.setOnShutterButtonListener(this); mShutterButton.requestFocus(); + findViewById(R.id.btn_gripper) + .setOnTouchListener(new GripperTouchListener()); // Make sure preview is started. try { @@ -1018,25 +1021,40 @@ public class VideoCamera extends Activity implements View.OnClickListener, MenuHelper.POSITION_CAMERA_SETTING, R.string.settings) .setOnMenuItemClickListener(new OnMenuItemClickListener() { public boolean onMenuItemClick(MenuItem item) { - if (mSettings == null) { - mSettings = new OnScreenSettings( - findViewById(R.id.camera_preview)); - if (mParameters == null) { - mParameters = mCameraDevice.getParameters(); - } - CameraSettings helper = new CameraSettings( - VideoCamera.this, mParameters); - mSettings.setOnVisibilityChangedListener(VideoCamera.this); - mSettings.setPreferenceScreen(helper - .getPreferenceScreen(R.xml.video_preferences)); - } - mSettings.setVisible(true); + showOnScreenSettings(); return true; }}); item.setIcon(android.R.drawable.ic_menu_preferences); } + private void showOnScreenSettings() { + if (mSettings == null) { + mSettings = new OnScreenSettings( + findViewById(R.id.camera_preview)); + CameraSettings helper = new CameraSettings(this, mParameters); + mSettings.setPreferenceScreen(helper + .getPreferenceScreen(R.xml.camera_preferences)); + mSettings.setOnVisibilityChangedListener(this); + } + mSettings.expandPanel(); + } + + private class GripperTouchListener implements View.OnTouchListener { + public boolean onTouch(View view, MotionEvent event) { + switch (event.getAction()) { + case MotionEvent.ACTION_DOWN: + return true; + case MotionEvent.ACTION_UP: + showOnScreenSettings(); + return true; + } + return false; + } + } + public void onVisibilityChanged(boolean visible) { + findViewById(R.id.btn_gripper).setVisibility( + visible ? View.INVISIBLE : View.VISIBLE); if (visible) { releaseMediaRecorder(); } else { |