diff options
-rwxr-xr-x | res/drawable-hdpi/ic_viewfinder_flash_auto.png | bin | 0 -> 2288 bytes | |||
-rwxr-xr-x | res/drawable-hdpi/ic_viewfinder_flash_on.png | bin | 0 -> 1596 bytes | |||
-rwxr-xr-x | res/drawable-mdpi/ic_viewfinder_flash_auto.png | bin | 0 -> 1473 bytes | |||
-rwxr-xr-x | res/drawable-mdpi/ic_viewfinder_flash_on.png | bin | 0 -> 1038 bytes | |||
-rw-r--r-- | res/layout/camera.xml | 32 | ||||
-rw-r--r-- | res/values/arrays.xml | 16 | ||||
-rw-r--r-- | res/values/attrs.xml | 27 | ||||
-rw-r--r-- | src/com/android/camera/Camera.java | 33 | ||||
-rw-r--r-- | src/com/android/camera/EvenlySpacedLayout.java | 59 | ||||
-rw-r--r-- | src/com/android/camera/IconIndicator.java | 84 |
10 files changed, 229 insertions, 22 deletions
diff --git a/res/drawable-hdpi/ic_viewfinder_flash_auto.png b/res/drawable-hdpi/ic_viewfinder_flash_auto.png Binary files differnew file mode 100755 index 0000000..27968e7 --- /dev/null +++ b/res/drawable-hdpi/ic_viewfinder_flash_auto.png diff --git a/res/drawable-hdpi/ic_viewfinder_flash_on.png b/res/drawable-hdpi/ic_viewfinder_flash_on.png Binary files differnew file mode 100755 index 0000000..71ee867 --- /dev/null +++ b/res/drawable-hdpi/ic_viewfinder_flash_on.png diff --git a/res/drawable-mdpi/ic_viewfinder_flash_auto.png b/res/drawable-mdpi/ic_viewfinder_flash_auto.png Binary files differnew file mode 100755 index 0000000..79e36b7 --- /dev/null +++ b/res/drawable-mdpi/ic_viewfinder_flash_auto.png diff --git a/res/drawable-mdpi/ic_viewfinder_flash_on.png b/res/drawable-mdpi/ic_viewfinder_flash_on.png Binary files differnew file mode 100755 index 0000000..91dfe24 --- /dev/null +++ b/res/drawable-mdpi/ic_viewfinder_flash_on.png diff --git a/res/layout/camera.xml b/res/layout/camera.xml index 64ad273..a07b6c4 100644 --- a/res/layout/camera.xml +++ b/res/layout/camera.xml @@ -15,6 +15,7 @@ --> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + xmlns:camera="http://schemas.android.com/apk/res/com.android.camera" android:background="@drawable/camera_background" android:id="@+id/camera" android:orientation="horizontal" @@ -48,15 +49,30 @@ android:id="@+id/focus_rectangle" android:layout_width="384dp" android:layout_height="288dp"/> - <ImageView - android:id="@+id/gps_indicator" + <com.android.camera.EvenlySpacedLayout + camera:orientation="vertical" + android:visibility="visible" + android:layout_gravity="left|fill_vertical" + android:id="@+id/action_icon_panel" + android:layout_marginTop="20dp" + android:layout_marginLeft="10dp" android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:visibility="invisible" - android:clickable="false" - android:focusable="false" - android:layout_marginLeft="5dp" - android:layout_marginTop="5dp"/> + android:layout_height="288dp"> + <com.android.camera.IconIndicator + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:id="@+id/gps_icon" + camera:modes="@array/gps_modes" + camera:icons="@array/gps_icons" + android:visibility="visible"/> + <com.android.camera.IconIndicator + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:id="@+id/flash_icon" + camera:modes="@array/pref_camera_flashmode_entryvalues" + camera:icons="@array/flash_icons" + android:visibility="visible"/> + </com.android.camera.EvenlySpacedLayout> </FrameLayout> </LinearLayout> </RelativeLayout> diff --git a/res/values/arrays.xml b/res/values/arrays.xml index 4687088..7498936 100644 --- a/res/values/arrays.xml +++ b/res/values/arrays.xml @@ -94,6 +94,22 @@ <item>off</item> </string-array> + <array name="flash_icons"> + <item>@drawable/ic_viewfinder_flash_auto</item> + <item>@drawable/ic_viewfinder_flash_on</item> + <item>0</item> + </array> + + <string-array name="gps_modes" translatable="false"> + <item>off</item> + <item>on</item> + </string-array> + + <array name="gps_icons"> + <item>0</item> + <item>@drawable/ic_camera_sym_gps</item> + </array> + <!-- Camera Preferences White Balance dialog box entries --> <string-array name="pref_camera_whitebalance_entries" translatable="false"> <item>@string/pref_camera_whitebalance_entry_auto</item> diff --git a/res/values/attrs.xml b/res/values/attrs.xml new file mode 100644 index 0000000..e66693a --- /dev/null +++ b/res/values/attrs.xml @@ -0,0 +1,27 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- 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. +--> +<resources> + <declare-styleable name="IconIndicator"> + <attr name="icons" format="reference" /> + <attr name="modes" format="reference" /> + </declare-styleable> + <declare-styleable name="EvenlySpacedLayout"> + <attr name="orientation"> + <enum name="horizontal" value="0" /> + <enum name="vertical" value="1" /> + </attr> + </declare-styleable> +</resources> diff --git a/src/com/android/camera/Camera.java b/src/com/android/camera/Camera.java index 20301f0..e77a34c 100644 --- a/src/com/android/camera/Camera.java +++ b/src/com/android/camera/Camera.java @@ -94,6 +94,9 @@ public class Camera extends Activity implements View.OnClickListener, private static final int RESTART_PREVIEW = 3; private static final int CLEAR_SCREEN_DELAY = 4; + private static final String GPS_MODE_ON = "on"; + private static final String GPS_MODE_OFF = "off"; + private static final int SCREEN_DELAY = 2 * 60 * 1000; private static final int FOCUS_BEEP_VOLUME = 100; @@ -134,7 +137,8 @@ public class Camera extends Activity implements View.OnClickListener, private SurfaceHolder mSurfaceHolder = null; private ShutterButton mShutterButton; private FocusRectangle mFocusRectangle; - private ImageView mGpsIndicator; + private IconIndicator mGpsIndicator; + private IconIndicator mFlashIndicator; private ToneGenerator mFocusToneGenerator; private ZoomButtonsController mZoomButtons; private GestureDetector mGestureDetector; @@ -287,8 +291,7 @@ public class Camera extends Activity implements View.OnClickListener, updateFocusIndicator(); // Initialize GPS indicator. - mGpsIndicator = (ImageView) findViewById(R.id.gps_indicator); - mGpsIndicator.setImageResource(R.drawable.ic_camera_sym_gps); + mGpsIndicator = (IconIndicator) findViewById(R.id.gps_icon); ImageManager.ensureOSXCompatibleFolder(); @@ -512,7 +515,7 @@ public class Camera extends Activity implements View.OnClickListener, // update so update GPS indicator when we receive data. if (mRecordLocation && LocationManager.GPS_PROVIDER.equals(mProvider)) { - mGpsIndicator.setVisibility(View.VISIBLE); + mGpsIndicator.setMode(GPS_MODE_ON); } mLastLocation.set(newLocation); mValid = true; @@ -533,7 +536,7 @@ public class Camera extends Activity implements View.OnClickListener, mValid = false; if (mRecordLocation && LocationManager.GPS_PROVIDER.equals(provider)) { - mGpsIndicator.setVisibility(View.INVISIBLE); + mGpsIndicator.setMode(GPS_MODE_OFF); } break; } @@ -895,6 +898,8 @@ public class Camera extends Activity implements View.OnClickListener, findViewById(R.id.btn_gripper) .setOnTouchListener(new GripperTouchListener()); + mFlashIndicator = (IconIndicator) findViewById(R.id.flash_icon); + // Make sure preview is started. try { startPreviewThread.join(); @@ -1212,7 +1217,7 @@ public class Camera extends Activity implements View.OnClickListener, if (mFirstTimeInitialized) { mOrientationListener.disable(); - mGpsIndicator.setVisibility(View.INVISIBLE); + mGpsIndicator.setMode(GPS_MODE_OFF); if (!mIsImageCaptureIntent) { mThumbController.storeData( ImageManager.getLastImageThumbPath()); @@ -1630,10 +1635,24 @@ public class Camera extends Activity implements View.OnClickListener, String flashMode = mPreferences.getString( CameraSettings.KEY_FLASH_MODE, getString(R.string.pref_camera_flashmode_default)); - if (isSupported(flashMode, mParameters.getSupportedFlashModes())) { + List<String> supportedFlash = mParameters.getSupportedFlashModes(); + if (isSupported(flashMode, supportedFlash)) { mParameters.setFlashMode(flashMode); + } else { + // If the current flashMode is not support, show the + // FLASH_MODE_OFF icon. + flashMode = Parameters.FLASH_MODE_OFF; } + // We post the runner because this function can be called from + // non-UI thread (i.e., startPreviewThread). + final String finalFlashMode = flashMode; + mHandler.post(new Runnable() { + public void run() { + mFlashIndicator.setMode(finalFlashMode); + } + }); + // Set white balance parameter. String whiteBalance = mPreferences.getString( CameraSettings.KEY_WHITE_BALANCE, diff --git a/src/com/android/camera/EvenlySpacedLayout.java b/src/com/android/camera/EvenlySpacedLayout.java index 9a2399c..502b41a 100644 --- a/src/com/android/camera/EvenlySpacedLayout.java +++ b/src/com/android/camera/EvenlySpacedLayout.java @@ -17,19 +17,25 @@ package com.android.camera; import android.content.Context; +import android.content.res.TypedArray; import android.util.AttributeSet; import android.view.View; import android.view.ViewGroup; // // This is a layout which makes the children even spaced. -// Currently it only supports putting children horizontally, and it does not -// consider the padding parameters. +// Currently it does not consider the padding parameters. // public class EvenlySpacedLayout extends ViewGroup { + private boolean mHorizontal; public EvenlySpacedLayout(Context context, AttributeSet attrs) { super(context, attrs); + TypedArray a = context.obtainStyledAttributes( + attrs, R.styleable.EvenlySpacedLayout, 0, 0); + mHorizontal = (0 == a.getInt( + R.styleable.EvenlySpacedLayout_orientation, 0)); + a.recycle(); } @Override @@ -41,15 +47,19 @@ public class EvenlySpacedLayout extends ViewGroup { View child = getChildAt(i); if (child.getVisibility() == GONE) continue; measureChild(child, widthMeasureSpec, heightMeasureSpec); - width += child.getMeasuredWidth(); - height = Math.max(height, child.getMeasuredHeight()); + if (mHorizontal) { + width += child.getMeasuredWidth(); + height = Math.max(height, child.getMeasuredHeight()); + } else { + height += child.getMeasuredHeight(); + width = Math.max(width, child.getMeasuredWidth()); + } } setMeasuredDimension(resolveSize(width, widthMeasureSpec), resolveSize(height, heightMeasureSpec)); } - @Override - protected void onLayout(boolean changed, int l, int t, int r, int b) { + private void layoutHorizontal(boolean changed, int l, int t, int r, int b) { int count = getChildCount(); int usedWidth = 0; @@ -58,7 +68,7 @@ public class EvenlySpacedLayout extends ViewGroup { View child = getChildAt(i); if (child.getVisibility() == GONE) continue; usedWidth += child.getMeasuredWidth(); - usedChildren += 1; + ++usedChildren; } int spacing = (r - l - usedWidth) / (usedChildren + 1); @@ -74,4 +84,39 @@ public class EvenlySpacedLayout extends ViewGroup { left += spacing; } } + + private void layoutVertical(boolean changed, int l, int t, int r, int b) { + int count = getChildCount(); + + int usedHeight = 0; + int usedChildren = 0; + for (int i = 0; i < count; i++) { + View child = getChildAt(i); + if (child.getVisibility() == GONE) continue; + usedHeight += child.getMeasuredHeight(); + ++usedChildren; + } + + int spacing = (b - t - usedHeight) / (usedChildren + 1); + int top = spacing; + int left = 0; + for (int i = 0; i < count; i++) { + View child = getChildAt(i); + if (child.getVisibility() == GONE) continue; + int w = child.getMeasuredWidth(); + int h = child.getMeasuredHeight(); + child.layout(left, top, left + w, top + h); + top += h; + top += spacing; + } + } + + @Override + protected void onLayout(boolean changed, int l, int t, int r, int b) { + if (mHorizontal) { + layoutHorizontal(changed, l, t, r, b); + } else { + layoutVertical(changed, l, t, r, b); + } + } } diff --git a/src/com/android/camera/IconIndicator.java b/src/com/android/camera/IconIndicator.java new file mode 100644 index 0000000..d179c9f --- /dev/null +++ b/src/com/android/camera/IconIndicator.java @@ -0,0 +1,84 @@ +/* + * 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 com.android.camera; + + +import android.content.Context; +import android.content.res.Resources; +import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.RectF; +import android.graphics.drawable.Drawable; +import android.text.Layout; +import android.util.AttributeSet; +import android.widget.ImageView; + + +public class IconIndicator extends ImageView { + + private Drawable[] mIcons; + private CharSequence[] mModes; + + public IconIndicator(Context context, AttributeSet attrs, int defStyle) { + super(context, attrs, defStyle); + TypedArray a = context.obtainStyledAttributes( + attrs, R.styleable.IconIndicator, defStyle, 0); + Drawable icons[] = loadIcons(context.getResources(), + a.getResourceId(R.styleable.IconIndicator_icons, 0)); + CharSequence modes[] = + a.getTextArray(R.styleable.IconIndicator_modes); + a.recycle(); + + setModesAndIcons(modes, icons); + setImageDrawable(mIcons.length > 0 ? mIcons[0]: null); + } + + public IconIndicator(Context context, AttributeSet attrs) { + this(context, attrs, 0); + } + + private Drawable[] loadIcons(Resources resources, int iconsId) { + TypedArray array = resources.obtainTypedArray(iconsId); + int n = array.length(); + Drawable drawable[] = new Drawable[n]; + for (int i = 0; i < n; ++i) { + int id = array.getResourceId(i, 0); + drawable[i] = id == 0 ? null : resources.getDrawable(id); + } + array.recycle(); + return drawable; + } + + private void setModesAndIcons(CharSequence[] modes, Drawable icons[]) { + if (modes.length != icons.length || icons.length == 0) { + throw new IllegalArgumentException(); + } + mIcons = icons; + mModes = modes; + } + + public void setMode(String mode) { + for (int i = 0, n = mModes.length; i < n; ++i) { + if (mModes[i].equals(mode)) { + setImageDrawable(mIcons[i]); + return; + } + } + throw new IllegalArgumentException("unknown mode: " + mode); + } +} |