From 7048972374474dfca142856583833d8168d3b1b6 Mon Sep 17 00:00:00 2001 From: Michael Kolb Date: Wed, 8 May 2013 11:14:35 -0700 Subject: Fix second level menu Bug: 8857098 Added Countdown timer and picture size items Change-Id: I73f3a5b22ab708e216729ed77fbd60041d40147d --- .../android/camera/CountDownTimerPreference.java | 19 +-- src/com/android/camera/PhotoMenu.java | 133 ++++++------------ src/com/android/camera/PhotoUI.java | 16 +-- src/com/android/camera/ui/CountdownTimerPopup.java | 145 +++++++++++++++++++ src/com/android/camera/ui/TimerSettingPopup.java | 153 --------------------- 5 files changed, 205 insertions(+), 261 deletions(-) create mode 100644 src/com/android/camera/ui/CountdownTimerPopup.java delete mode 100644 src/com/android/camera/ui/TimerSettingPopup.java (limited to 'src/com') diff --git a/src/com/android/camera/CountDownTimerPreference.java b/src/com/android/camera/CountDownTimerPreference.java index 0bbf6bc9d..9c66dda8c 100644 --- a/src/com/android/camera/CountDownTimerPreference.java +++ b/src/com/android/camera/CountDownTimerPreference.java @@ -21,25 +21,20 @@ import android.util.AttributeSet; import com.android.gallery3d.R; -import java.util.List; - -/* CountDownTimerPreference generates entries (i.e. what users see in the UI), - * and entry values (the actual value recorded in preference) in - * initCountDownTimeChoices(Context context), rather than reading the entries - * from a predefined list. When the entry values are a continuous list of numbers, - * (e.g. 0-60), it is more efficient to auto generate the list than to predefine it.*/ public class CountDownTimerPreference extends ListPreference { - private final static int MAX_DURATION = 60; + private static final int[] DURATIONS = { + 0, 1, 2, 3, 4, 5, 10, 15, 20, 30, 60 + }; public CountDownTimerPreference(Context context, AttributeSet attrs) { super(context, attrs); initCountDownDurationChoices(context); } private void initCountDownDurationChoices(Context context) { - CharSequence[] entryValues = new CharSequence[MAX_DURATION + 1]; - CharSequence[] entries = new CharSequence[MAX_DURATION + 1]; - for (int i = 0; i <= MAX_DURATION; i++) { - entryValues[i] = Integer.toString(i); + CharSequence[] entryValues = new CharSequence[DURATIONS.length]; + CharSequence[] entries = new CharSequence[DURATIONS.length]; + for (int i = 0; i < DURATIONS.length; i++) { + entryValues[i] = Integer.toString(DURATIONS[i]); if (i == 0) { entries[0] = context.getString(R.string.setting_off); // Off } else { diff --git a/src/com/android/camera/PhotoMenu.java b/src/com/android/camera/PhotoMenu.java index f29ed4a8b..d0f21ed68 100644 --- a/src/com/android/camera/PhotoMenu.java +++ b/src/com/android/camera/PhotoMenu.java @@ -16,34 +16,28 @@ package com.android.camera; -import android.content.Context; import android.content.res.Resources; import android.hardware.Camera.Parameters; -import android.view.LayoutInflater; import com.android.camera.ui.AbstractSettingPopup; +import com.android.camera.ui.CountdownTimerPopup; import com.android.camera.ui.ListPrefSettingPopup; -import com.android.camera.ui.MoreSettingPopup; import com.android.camera.ui.PieItem; import com.android.camera.ui.PieItem.OnClickListener; import com.android.camera.ui.PieRenderer; -import com.android.camera.ui.TimerSettingPopup; import com.android.gallery3d.R; +import java.util.Locale; + public class PhotoMenu extends PieController - implements MoreSettingPopup.Listener, - TimerSettingPopup.Listener, + implements CountdownTimerPopup.Listener, ListPrefSettingPopup.Listener { private static String TAG = "CAM_photomenu"; private final String mSettingOff; private PhotoUI mUI; - private String[] mOtherKeys; - // First level popup - private MoreSettingPopup mPopup; - // Second level popup - private AbstractSettingPopup mSecondPopup; + private AbstractSettingPopup mPopup; private CameraActivity mActivity; public PhotoMenu(CameraActivity activity, PhotoUI ui, PieRenderer pie) { @@ -56,9 +50,9 @@ public class PhotoMenu extends PieController public void initialize(PreferenceGroup group) { super.initialize(group); mPopup = null; - mSecondPopup = null; PieItem item = null; final Resources res = mActivity.getResources(); + Locale locale = res.getConfiguration().locale; // the order is from left to right in the menu // hdr @@ -108,22 +102,42 @@ public class PhotoMenu extends PieController if (group.findPreference(CameraSettings.KEY_RECORD_LOCATION) != null) { item = makeSwitchItem(CameraSettings.KEY_RECORD_LOCATION, true); more.addItem(item); + if (mActivity.isSecureCamera()) { + // Prevent location preference from getting changed in secure camera mode + item.setEnabled(false); + } } - // settings popup - mOtherKeys = new String[] { - CameraSettings.KEY_PICTURE_SIZE, - CameraSettings.KEY_FOCUS_MODE, - CameraSettings.KEY_TIMER, - CameraSettings.KEY_TIMER_SOUND_EFFECTS, - }; - item = makeItem(R.drawable.ic_settings_holo_light); - item.setLabel(res.getString(R.string.camera_menu_settings_label)); + // countdown timer + final ListPreference ctpref = group.findPreference(CameraSettings.KEY_TIMER); + final ListPreference beeppref = group.findPreference(CameraSettings.KEY_TIMER_SOUND_EFFECTS); + item = makeItem(R.drawable.ic_timer); + item.setLabel(res.getString(R.string.pref_camera_timer_title).toUpperCase(locale)); item.setOnClickListener(new OnClickListener() { @Override public void onClick(PieItem item) { - if (mPopup == null) { - initializePopup(); - } + CountdownTimerPopup timerPopup = (CountdownTimerPopup) mActivity.getLayoutInflater().inflate( + R.layout.countdown_setting_popup, null, false); + timerPopup.initialize(ctpref, beeppref); + timerPopup.setSettingChangedListener(PhotoMenu.this); + mUI.dismissPopup(); + mPopup = timerPopup; + mUI.showPopup(mPopup); + } + }); + more.addItem(item); + // image size + item = makeItem(R.drawable.ic_imagesize); + final ListPreference sizePref = group.findPreference(CameraSettings.KEY_PICTURE_SIZE); + item.setLabel(res.getString(R.string.pref_camera_picturesize_title).toUpperCase(locale)); + item.setOnClickListener(new OnClickListener() { + @Override + public void onClick(PieItem item) { + ListPrefSettingPopup popup = (ListPrefSettingPopup) mActivity.getLayoutInflater().inflate( + R.layout.list_pref_setting_popup, null, false); + popup.initialize(sizePref); + popup.setSettingChangedListener(PhotoMenu.this); + mUI.dismissPopup(); + mPopup = popup; mUI.showPopup(mPopup); } }); @@ -145,50 +159,18 @@ public class PhotoMenu extends PieController } @Override - public void reloadPreferences() { - super.reloadPreferences(); - if (mPopup != null) { - mPopup.reloadPreference(); - } - } - - @Override - // Hit when an item in the second-level popup gets selected + // Hit when an item in a popup gets selected public void onListPrefChanged(ListPreference pref) { - if (mPopup != null && mSecondPopup != null) { - mUI.dismissPopup(true); - mPopup.reloadPreference(); + if (mPopup != null) { + mUI.dismissPopup(); } onSettingChanged(pref); } - @Override - public void overrideSettings(final String ... keyvalues) { - super.overrideSettings(keyvalues); - if (mPopup == null) initializePopup(); - mPopup.overrideSettings(keyvalues); - } - - protected void initializePopup() { - LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService( - Context.LAYOUT_INFLATER_SERVICE); - - MoreSettingPopup popup = (MoreSettingPopup) inflater.inflate( - R.layout.more_setting_popup, null, false); - popup.setSettingChangedListener(this); - popup.initialize(mPreferenceGroup, mOtherKeys); - if (mActivity.isSecureCamera()) { - // Prevent location preference from getting changed in secure camera mode - popup.setPreferenceEnabled(CameraSettings.KEY_RECORD_LOCATION, false); - } - mPopup = popup; - } - - public void popupDismissed(boolean topPopupOnly) { - // if the 2nd level popup gets dismissed - if (mSecondPopup != null) { - mSecondPopup = null; - if (topPopupOnly) mUI.showPopup(mPopup); + public void popupDismissed() { + // the popup gets dismissed + if (mPopup != null) { + mPopup = null; } } @@ -217,29 +199,4 @@ public class PhotoMenu extends PieController super.onSettingChanged(pref); } - @Override - // Hit when an item in the first-level popup gets selected, then bring up - // the second-level popup - public void onPreferenceClicked(ListPreference pref) { - if (mSecondPopup != null) return; - - LayoutInflater inflater = (LayoutInflater) mActivity.getSystemService( - Context.LAYOUT_INFLATER_SERVICE); - if (CameraSettings.KEY_TIMER.equals(pref.getKey())) { - TimerSettingPopup timerPopup = (TimerSettingPopup) inflater.inflate( - R.layout.timer_setting_popup, null, false); - timerPopup.initialize(pref); - timerPopup.setSettingChangedListener(this); - mUI.dismissPopup(true); - mSecondPopup = timerPopup; - } else { - ListPrefSettingPopup basic = (ListPrefSettingPopup) inflater.inflate( - R.layout.list_pref_setting_popup, null, false); - basic.initialize(pref); - basic.setSettingChangedListener(this); - mUI.dismissPopup(true); - mSecondPopup = basic; - } - mUI.showPopup(mSecondPopup); - } } diff --git a/src/com/android/camera/PhotoUI.java b/src/com/android/camera/PhotoUI.java index 5475b98f6..5a7b5bfef 100644 --- a/src/com/android/camera/PhotoUI.java +++ b/src/com/android/camera/PhotoUI.java @@ -357,7 +357,7 @@ public class PhotoUI implements PieListener, mFaceView.setBlockDraw(!full); } if (mPopup != null) { - dismissPopup(false, full); + dismissPopup(full); } if (mGestures != null) { mGestures.setEnabled(full); @@ -389,7 +389,7 @@ public class PhotoUI implements PieListener, public boolean removeTopLevelPopup() { // Remove the top level popup or dialog box and return true if there's any if (mPopup != null) { - dismissPopup(true); + dismissPopup(); return true; } return false; @@ -408,11 +408,11 @@ public class PhotoUI implements PieListener, mGestures.addTouchReceiver(mPopup); } - public void dismissPopup(boolean topPopupOnly) { - dismissPopup(topPopupOnly, true); + public void dismissPopup() { + dismissPopup(true); } - private void dismissPopup(boolean topOnly, boolean fullScreen) { + private void dismissPopup(boolean fullScreen) { if (fullScreen) { mActivity.showUI(); mBlocker.setVisibility(View.VISIBLE); @@ -423,7 +423,7 @@ public class PhotoUI implements PieListener, ((FrameLayout) mRootView).removeView(mPopup); mPopup = null; } - mMenu.popupDismissed(topOnly); + mMenu.popupDismissed(); } public void onShowSwitcherPopup() { @@ -445,7 +445,7 @@ public class PhotoUI implements PieListener, // Remove all the popups/dialog boxes boolean ret = false; if (mPopup != null) { - dismissPopup(false); + dismissPopup(); ret = true; } return ret; @@ -508,7 +508,7 @@ public class PhotoUI implements PieListener, @Override public void onPieOpened(int centerX, int centerY) { - dismissPopup(false); + dismissPopup(); mActivity.cancelActivityTouchHandling(); mActivity.setSwipingEnabled(false); if (mFaceView != null) { diff --git a/src/com/android/camera/ui/CountdownTimerPopup.java b/src/com/android/camera/ui/CountdownTimerPopup.java new file mode 100644 index 000000000..7c3572b55 --- /dev/null +++ b/src/com/android/camera/ui/CountdownTimerPopup.java @@ -0,0 +1,145 @@ +/* + * Copyright (C) 2012 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.ui; + +import android.content.Context; +import android.util.AttributeSet; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.NumberPicker; +import android.widget.NumberPicker.OnValueChangeListener; + +import com.android.camera.ListPreference; +import com.android.gallery3d.R; + +import java.util.Locale; + +/** + * This is a popup window that allows users to specify a countdown timer + */ + +public class CountdownTimerPopup extends AbstractSettingPopup { + private static final String TAG = "TimerSettingPopup"; + private NumberPicker mNumberSpinner; + private String[] mDurations; + private ListPreference mTimer; + private ListPreference mBeep; + private Listener mListener; + private Button mConfirmButton; + private View mPickerTitle; + private CheckBox mTimerSound; + private View mSoundTitle; + + static public interface Listener { + public void onListPrefChanged(ListPreference pref); + } + + public void setSettingChangedListener(Listener listener) { + mListener = listener; + } + + public CountdownTimerPopup(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public void initialize(ListPreference timer, ListPreference beep) { + mTimer = timer; + mBeep = beep; + // Set title. + mTitle.setText(mTimer.getTitle()); + + // Duration + CharSequence[] entries = mTimer.getEntryValues(); + mDurations = new String[entries.length]; + Locale locale = getResources().getConfiguration().locale; + mDurations[0] = getResources().getString(R.string.setting_off); // Off + for (int i = 1; i < entries.length; i++) + mDurations[i] = String.format(locale, "%d", Integer.parseInt(entries[i].toString())); + int durationCount = mDurations.length; + mNumberSpinner = (NumberPicker) findViewById(R.id.duration); + mNumberSpinner.setMinValue(0); + mNumberSpinner.setMaxValue(durationCount - 1); + mNumberSpinner.setDisplayedValues(mDurations); + mNumberSpinner.setWrapSelectorWheel(false); + mNumberSpinner.setOnValueChangedListener(new OnValueChangeListener() { + @Override + public void onValueChange(NumberPicker picker, int oldValue, int newValue) { + setTimeSelectionEnabled(newValue != 0); + } + }); + mConfirmButton = (Button) findViewById(R.id.timer_set_button); + mPickerTitle = findViewById(R.id.set_time_interval_title); + + // Disable focus on the spinners to prevent keyboard from coming up + mNumberSpinner.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); + + mConfirmButton.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + updateInputState(); + } + }); + mTimerSound = (CheckBox) findViewById(R.id.sound_check_box); + mSoundTitle = findViewById(R.id.beep_title); + } + + private void restoreSetting() { + int index = mTimer.findIndexOfValue(mTimer.getValue()); + if (index == -1) { + Log.e(TAG, "Invalid preference value."); + mTimer.print(); + throw new IllegalArgumentException(); + } else { + setTimeSelectionEnabled(index != 0); + mNumberSpinner.setValue(index); + } + boolean checked = mBeep.findIndexOfValue(mBeep.getValue()) != 0; + mTimerSound.setChecked(checked); + } + + @Override + public void setVisibility(int visibility) { + if (visibility == View.VISIBLE) { + if (getVisibility() != View.VISIBLE) { + // Set the number pickers and on/off switch to be consistent + // with the preference + restoreSetting(); + } + } + super.setVisibility(visibility); + } + + protected void setTimeSelectionEnabled(boolean enabled) { + mPickerTitle.setVisibility(enabled ? VISIBLE : INVISIBLE); + mTimerSound.setEnabled(enabled); + mSoundTitle.setEnabled(enabled); + } + + @Override + public void reloadPreference() { + } + + private void updateInputState() { + mTimer.setValueIndex(mNumberSpinner.getValue()); + mBeep.setValueIndex(mTimerSound.isChecked() ? 1 : 0); + if (mListener != null) { + mListener.onListPrefChanged(mTimer); + mListener.onListPrefChanged(mBeep); + } + } +} diff --git a/src/com/android/camera/ui/TimerSettingPopup.java b/src/com/android/camera/ui/TimerSettingPopup.java deleted file mode 100644 index 983c7f21b..000000000 --- a/src/com/android/camera/ui/TimerSettingPopup.java +++ /dev/null @@ -1,153 +0,0 @@ -/* - * Copyright (C) 2012 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.ui; - -import java.util.Locale; - -import android.content.Context; -import android.content.res.Resources; -import android.util.AttributeSet; -import android.util.Log; -import android.view.View; -import android.widget.Button; -import android.widget.CompoundButton; -import android.widget.NumberPicker; -import android.widget.Switch; -import android.widget.TextView; - -import com.android.camera.ListPreference; -import com.android.gallery3d.R; - -/** - * This is a popup window that allows users to turn on/off time lapse feature, - * and to select a time interval for taking a time lapse video. - */ - -public class TimerSettingPopup extends AbstractSettingPopup { - private static final String TAG = "TimerSettingPopup"; - private NumberPicker mNumberSpinner; - private Switch mTimerSwitch; - private String[] mDurations; - private ListPreference mPreference; - private Listener mListener; - private Button mConfirmButton; - private TextView mHelpText; - private View mTimePicker; - - static public interface Listener { - public void onListPrefChanged(ListPreference pref); - } - - public void setSettingChangedListener(Listener listener) { - mListener = listener; - } - - public TimerSettingPopup(Context context, AttributeSet attrs) { - super(context, attrs); - } - - public void initialize(ListPreference preference) { - mPreference = preference; - - // Set title. - mTitle.setText(mPreference.getTitle()); - - // Duration - CharSequence[] entries = mPreference.getEntryValues(); - mDurations = new String[entries.length - 1]; - Locale locale = getResources().getConfiguration().locale; - for (int i = 1; i < entries.length; i++) - mDurations[i-1] = String.format(locale, "%d", - Integer.parseInt(entries[i].toString())); - int durationCount = mDurations.length; - mNumberSpinner = (NumberPicker) findViewById(R.id.duration); - mNumberSpinner.setMinValue(0); - mNumberSpinner.setMaxValue(durationCount - 1); - mNumberSpinner.setDisplayedValues(mDurations); - mNumberSpinner.setWrapSelectorWheel(false); - - mTimerSwitch = (Switch) findViewById(R.id.timer_setting_switch); - mHelpText = (TextView) findViewById(R.id.set_timer_help_text); - mConfirmButton = (Button) findViewById(R.id.timer_set_button); - mTimePicker = findViewById(R.id.time_duration_picker); - - // Disable focus on the spinners to prevent keyboard from coming up - mNumberSpinner.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS); - - mTimerSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { - public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { - setTimeSelectionEnabled(isChecked); - } - }); - mConfirmButton.setOnClickListener(new View.OnClickListener() { - public void onClick(View v) { - updateInputState(); - } - }); - } - - private void restoreSetting() { - int index = mPreference.findIndexOfValue(mPreference.getValue()); - if (index == -1) { - Log.e(TAG, "Invalid preference value."); - mPreference.print(); - throw new IllegalArgumentException(); - } else if (index == 0) { - // default choice: time lapse off - mTimerSwitch.setChecked(false); - setTimeSelectionEnabled(false); - } else { - mTimerSwitch.setChecked(true); - setTimeSelectionEnabled(true); - mNumberSpinner.setValue(index - 1); - } - } - - @Override - public void setVisibility(int visibility) { - if (visibility == View.VISIBLE) { - if (getVisibility() != View.VISIBLE) { - // Set the number pickers and on/off switch to be consistent - // with the preference - restoreSetting(); - } - } - super.setVisibility(visibility); - } - - protected void setTimeSelectionEnabled(boolean enabled) { - mHelpText.setVisibility(enabled ? GONE : VISIBLE); - mTimePicker.setVisibility(enabled ? VISIBLE : GONE); - } - - @Override - public void reloadPreference() { - } - - private void updateInputState() { - if (mTimerSwitch.isChecked()) { - int newId = mNumberSpinner.getValue() + 1; - mPreference.setValueIndex(newId); - } else { - mPreference.setValueIndex(0); - } - - if (mListener != null) { - mListener.onListPrefChanged(mPreference); - } - } -} -- cgit v1.2.3