diff options
author | Wu-cheng Li <wuchengli@google.com> | 2010-11-04 17:00:10 +0800 |
---|---|---|
committer | Wu-cheng Li <wuchengli@google.com> | 2010-11-12 18:02:20 +0800 |
commit | 02ec7c0880ded5863d73d6f173ef35ab5c888dcd (patch) | |
tree | c00359850092e801bc3d0f593fd0ae5c934b2dcd /src/com/android/camera/ui | |
parent | 819a9652eecc729dcc6d642fd59ff0a1b7908c3e (diff) | |
download | LegacyCamera-02ec7c0880ded5863d73d6f173ef35ab5c888dcd.zip LegacyCamera-02ec7c0880ded5863d73d6f173ef35ab5c888dcd.tar.gz LegacyCamera-02ec7c0880ded5863d73d6f173ef35ab5c888dcd.tar.bz2 |
Change setting picker to popup window.
UI was re-designed.
bug:3156666
Change-Id: Id40fab084f59cdeca8e2991dc8b3768fcac8e0bf
Diffstat (limited to 'src/com/android/camera/ui')
-rw-r--r-- | src/com/android/camera/ui/BasicSettingPopup.java (renamed from src/com/android/camera/ui/BasicSettingPicker.java) | 53 | ||||
-rw-r--r-- | src/com/android/camera/ui/ControlPanel.java | 115 | ||||
-rw-r--r-- | src/com/android/camera/ui/OtherSettingsPopup.java | 19 |
3 files changed, 84 insertions, 103 deletions
diff --git a/src/com/android/camera/ui/BasicSettingPicker.java b/src/com/android/camera/ui/BasicSettingPopup.java index 4f2011d..6f1a834 100644 --- a/src/com/android/camera/ui/BasicSettingPicker.java +++ b/src/com/android/camera/ui/BasicSettingPopup.java @@ -25,6 +25,7 @@ import android.view.MotionEvent; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.PopupWindow; import android.widget.TextView; import com.android.camera.IconListPreference; @@ -32,8 +33,8 @@ import com.android.camera.R; import com.android.camera.Util; import com.android.camera.ui.GLListView.OnItemSelectedListener; -public class BasicSettingPicker extends LinearLayout { - private static final String TAG = "BasicSettingPicker"; +public class BasicSettingPopup extends LinearLayout { + private static final String TAG = "BasicSettingPopup"; private IconListPreference mPreference; private final Context mContext; private Listener mListener; @@ -42,7 +43,7 @@ public class BasicSettingPicker extends LinearLayout { public void onSettingChanged(); } - public BasicSettingPicker(Context context, AttributeSet attrs) { + public BasicSettingPopup(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; } @@ -58,30 +59,21 @@ public class BasicSettingPicker extends LinearLayout { int pos = 0; for (int i = 0, n = entries.length; i < n; ++i) { - // Add the image. - ImageView image; - Drawable drawable = mContext.getResources().getDrawable(imageIds[i]); - // Sacle the image if it is too small. - if (drawable.getIntrinsicWidth() >= getLayoutParams().width) { - image = (ImageView) inflater.inflate( - R.layout.setting_image_item, null); - } else { - image = (ImageView) inflater.inflate( - R.layout.setting_scale_image_item, null); - } - image.setImageDrawable(drawable); - image.setClickable(false); - addView(image, pos++); - - // Add the text. - TextView text = (TextView) inflater.inflate( - R.layout.setting_text_item, null); + LinearLayout row = (LinearLayout) inflater.inflate( + R.layout.setting_item, this, false); + // Initialize the text. + TextView text = (TextView) row.findViewById(R.id.text); text.setText(entries[i].toString()); text.setClickable(false); if (index == i) text.setPressed(true); - addView(text, pos++); + + // Initialize the image. + Drawable drawable = mContext.getResources().getDrawable(imageIds[i]); + ImageView image = (ImageView) row.findViewById(R.id.image); + image.setImageDrawable(drawable); + image.setClickable(false); + addView(row); } - requestLayout(); } public void setSettingChangedListener(Listener listener) { @@ -95,18 +87,15 @@ public class BasicSettingPicker extends LinearLayout { || action == MotionEvent.ACTION_DOWN) { int y = (int) event.getY(); // Check which child is pressed. - for (int i = 0; i < getChildCount() - 1; i++) { + for (int i = 0; i < getChildCount(); i++) { View v = getChildAt(i); if (y >= v.getTop() && y <= v.getBottom()) { - int index = i / 2; - CharSequence[] values = mPreference.getEntryValues(); int oldIndex = mPreference.findIndexOfValue(mPreference.getValue()); - if (oldIndex != index) { - View oldText = getChildAt(oldIndex * 2 + 1); - oldText.setPressed(false); - View text = getChildAt(index * 2 + 1); - text.setPressed(true); - mPreference.setValueIndex(index); + if (oldIndex != i) { + View oldRow = getChildAt(oldIndex); + oldRow.findViewById(R.id.text).setPressed(false); + v.findViewById(R.id.text).setPressed(true); + mPreference.setValueIndex(i); if (mListener != null) { mListener.onSettingChanged(); } diff --git a/src/com/android/camera/ui/ControlPanel.java b/src/com/android/camera/ui/ControlPanel.java index cdd00d9..9718074 100644 --- a/src/com/android/camera/ui/ControlPanel.java +++ b/src/com/android/camera/ui/ControlPanel.java @@ -30,15 +30,16 @@ import android.view.Gravity; import android.view.LayoutInflater; import android.view.KeyEvent; import android.view.View; +import android.view.ViewGroup; import android.widget.Button; +import android.widget.LinearLayout; import android.widget.ListView; import android.widget.PopupWindow; import android.widget.RelativeLayout; public class ControlPanel extends RelativeLayout - implements BasicSettingPicker.Listener, IndicatorWheel.Listener, - View.OnClickListener, OtherSettingsPopup.Listener, - PopupWindow.OnDismissListener { + implements BasicSettingPopup.Listener, IndicatorWheel.Listener, + OtherSettingsPopup.Listener, PopupWindow.OnDismissListener { private static final String TAG = "ControlPanel"; private Context mContext; private ComboPreferences mSharedPrefs; @@ -46,11 +47,10 @@ public class ControlPanel extends RelativeLayout private String[] mPreferenceKeys; private Listener mListener; private IndicatorWheel mIndicatorWheel; - private BasicSettingPicker[] mSettingPickers; + private BasicSettingPopup[] mBasicSettingPopups; private OtherSettingsPopup mOtherSettingsPopup; private int mActiveIndicator = -1; private boolean mEnabled = true; - private ListView mThumbnailList; static public interface Listener { @@ -84,19 +84,18 @@ public class ControlPanel extends RelativeLayout public void initialize(Context context, PreferenceGroup group, String[] keys, boolean enableOtherSettings) { // Reset the variables and states. - hideSettingPicker(); + dismissSettingPopup(); if (mIndicatorWheel != null) { // The first view is the shutter button. mIndicatorWheel.removeViews(1, mIndicatorWheel.getChildCount() - 1); } mOtherSettingsPopup = null; - mSettingPickers = null; mActiveIndicator = -1; // Initialize all variables and icons. mPreferenceGroup = group; mPreferenceKeys = keys; - mSettingPickers = new BasicSettingPicker[mPreferenceKeys.length]; + mBasicSettingPopups = new BasicSettingPopup[mPreferenceKeys.length]; mIndicatorWheel = (IndicatorWheel) findViewById(R.id.indicator_wheel); mThumbnailList = (ListView) findViewById(R.id.thumbnail_list); mSharedPrefs = ComboPreferences.get(context); @@ -123,84 +122,66 @@ public class ControlPanel extends RelativeLayout } } - @Override - public void onClick(View v) { - if (!mEnabled) return; - switch (v.getId()) { - case R.id.setting_exit: - hideSettingPicker(); - break; - } - } - public void onIndicatorClicked(int index) { if (!mEnabled) return; - if (index < mSettingPickers.length) { - if (mSettingPickers[index] == null) { - initializeSettingPicker(index); + if (index < mBasicSettingPopups.length) { + if (mBasicSettingPopups[index] == null) { + initializeSettingPopup(index); } } else if (mOtherSettingsPopup == null) { - initializeOtherSettingPicker(); - } - if (!showSettingPicker(index)) { - hideSettingPicker(); + initializeOtherSettingPopup(); } + showSettingPopup(index); } - private void initializeSettingPicker(int index) { + private void initializeSettingPopup(int index) { IconListPreference pref = (IconListPreference) mPreferenceGroup.findPreference(mPreferenceKeys[index]); LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( Context.LAYOUT_INFLATER_SERVICE); - inflater.inflate(R.layout.basic_setting_picker, this); - mSettingPickers[index] = (BasicSettingPicker) getChildAt( - getChildCount() - 1); - mSettingPickers[index].setSettingChangedListener(this); - mSettingPickers[index].initialize(pref); - View v = mSettingPickers[index].findViewById(R.id.setting_exit); - v.setOnClickListener(this); - } - - private void initializeOtherSettingPicker() { + ViewGroup root = (ViewGroup) getRootView().findViewById(R.id.frame); + BasicSettingPopup popup = (BasicSettingPopup) inflater.inflate( + R.layout.basic_setting_popup, root, false); + mBasicSettingPopups[index] = popup; + popup.setSettingChangedListener(this); + popup.initialize(pref); + RelativeLayout.LayoutParams params = + (RelativeLayout.LayoutParams) popup.getLayoutParams(); + params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); + params.addRule(RelativeLayout.CENTER_VERTICAL); + popup.setLayoutParams(params); + root.addView(popup); + } + + private void initializeOtherSettingPopup() { LayoutInflater inflater = (LayoutInflater) mContext.getSystemService( Context.LAYOUT_INFLATER_SERVICE); - View view = inflater.inflate(R.layout.other_setting_popup, null); - // Framework has a bug so WRAP_CONTENT does not work. Hardcode the - // dimension for now. - mOtherSettingsPopup = new OtherSettingsPopup(view, 420, 410, true); - Drawable border = getResources().getDrawable(R.drawable.menu_popup); - mOtherSettingsPopup.setBackgroundDrawable(border); + ViewGroup root = (ViewGroup) getRootView().findViewById(R.id.frame); + mOtherSettingsPopup = (OtherSettingsPopup) inflater.inflate( + R.layout.other_setting_popup, root, false); mOtherSettingsPopup.setOtherSettingChangedListener(this); - mOtherSettingsPopup.setOnDismissListener(this); - mOtherSettingsPopup.setFocusable(true); mOtherSettingsPopup.initialize(mPreferenceGroup); + root.addView(mOtherSettingsPopup); } - private boolean showSettingPicker(int index) { - for (int i = 0; i < mSettingPickers.length; i++) { - if (i != index && mSettingPickers[i] != null) { - mSettingPickers[i].setVisibility(View.INVISIBLE); - } - } - if (index == mSettingPickers.length) { - mOtherSettingsPopup.showAtLocation(this, Gravity.CENTER, 0, 0); - mThumbnailList.setVisibility(View.VISIBLE); + private void showSettingPopup(int index) { + if (mActiveIndicator == index) return; + dismissSettingPopup(); + if (index == mBasicSettingPopups.length) { + mOtherSettingsPopup.setVisibility(View.VISIBLE); } else { - mSettingPickers[index].setVisibility(View.VISIBLE); - mThumbnailList.setVisibility(View.INVISIBLE); + mBasicSettingPopups[index].setVisibility(View.VISIBLE); } mActiveIndicator = index; - return true; } - public boolean hideSettingPicker() { + public boolean dismissSettingPopup() { if (mActiveIndicator >= 0) { - if (mActiveIndicator == mSettingPickers.length) { - mOtherSettingsPopup.dismiss(); + if (mActiveIndicator == mBasicSettingPopups.length) { + mOtherSettingsPopup.setVisibility(View.INVISIBLE); } else { - mSettingPickers[mActiveIndicator].setVisibility(View.INVISIBLE); - mThumbnailList.setVisibility(View.VISIBLE); + mBasicSettingPopups[mActiveIndicator].setVisibility(View.INVISIBLE); } mActiveIndicator = -1; return true; @@ -217,4 +198,16 @@ public class ControlPanel extends RelativeLayout public void onDismiss() { mActiveIndicator = -1; } + + public View getActivePopupWindow() { + if (mActiveIndicator >= 0) { + if (mActiveIndicator == mBasicSettingPopups.length) { + return mOtherSettingsPopup; + } else { + return mBasicSettingPopups[mActiveIndicator]; + } + } else { + return null; + } + } } diff --git a/src/com/android/camera/ui/OtherSettingsPopup.java b/src/com/android/camera/ui/OtherSettingsPopup.java index feacb6b..862645e 100644 --- a/src/com/android/camera/ui/OtherSettingsPopup.java +++ b/src/com/android/camera/ui/OtherSettingsPopup.java @@ -19,14 +19,15 @@ package com.android.camera.ui; import com.android.camera.ListPreference; import com.android.camera.PreferenceGroup; +import android.content.Context; +import android.util.AttributeSet; import android.util.Log; import android.view.View; -import android.widget.PopupWindow; +import android.view.ViewGroup; import android.widget.TableLayout; -import android.widget.TableRow; /* A popup window that contains several camera settings. */ -public class OtherSettingsPopup extends PopupWindow +public class OtherSettingsPopup extends TableLayout implements InLineSettingPicker.Listener { private static final String TAG = "OtherSettingsPopup"; private Listener mListener; @@ -39,23 +40,21 @@ public class OtherSettingsPopup extends PopupWindow mListener = listener; } - public OtherSettingsPopup(View contentView, int width, int height, - boolean focusable) { - super(contentView, width, height, focusable); + public OtherSettingsPopup(Context context, AttributeSet attrs) { + super(context, attrs); } public void initialize(PreferenceGroup group) { - TableLayout table = (TableLayout) getContentView(); // Initialize each camera setting. - for (int i = table.getChildCount() - 1; i >= 0 ; i--) { - TableRow row = (TableRow) table.getChildAt(i); + for (int i = getChildCount() - 1; i >= 0 ; i--) { + ViewGroup row = (ViewGroup) getChildAt(i); InLineSettingPicker picker = (InLineSettingPicker) row.getChildAt(1); ListPreference pref = group.findPreference(picker.getKey()); if (pref != null) { picker.setSettingChangedListener(this); picker.initialize(pref); } else { // remove the row if the preference is not supported - table.removeViewAt(i); + removeViewAt(i); } } } |