diff options
-rw-r--r-- | res/layout-xlarge/in_line_setting_picker.xml | 20 | ||||
-rw-r--r-- | res/layout-xlarge/other_setting_popup.xml | 36 | ||||
-rw-r--r-- | src/com/android/camera/ui/InLineSettingPicker.java | 20 | ||||
-rw-r--r-- | src/com/android/camera/ui/OtherSettingsPopup.java | 126 |
4 files changed, 120 insertions, 82 deletions
diff --git a/res/layout-xlarge/in_line_setting_picker.xml b/res/layout-xlarge/in_line_setting_picker.xml index 9b05e56..47cd024 100644 --- a/res/layout-xlarge/in_line_setting_picker.xml +++ b/res/layout-xlarge/in_line_setting_picker.xml @@ -17,15 +17,11 @@ */ --> -<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" +<com.android.camera.ui.InLineSettingPicker xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:orientation="vertical"> - <ImageView android:layout_width="match_parent" - android:layout_height="wrap_content" - android:src="@drawable/divider_horizontal_holo_dark" - android:scaleType="fitXY" /> - <LinearLayout android:orientation="horizontal" + android:layout_height="wrap_content"> + <LinearLayout android:id="@+id/setting_item" + android:orientation="horizontal" style="@style/SettingRow"> <TextView android:id="@+id/title" style="@style/SettingPickerText" /> @@ -61,4 +57,10 @@ android:textStyle="bold" android:background="@android:color/transparent" /> </LinearLayout> -</LinearLayout> + <!-- To have the same View(InLineSettingPicker) as the listview's components and also show the restore setting line, we have the relativelayout and control the visibilities of the restore and the setting_item component to achieve the goal. --> + <TextView android:id="@+id/restore" + android:gravity="center" + android:textSize="22dp" + style="@style/SettingRow"> + </TextView> +</com.android.camera.ui.InLineSettingPicker> diff --git a/res/layout-xlarge/other_setting_popup.xml b/res/layout-xlarge/other_setting_popup.xml index 7b9e6a7..f1bd1ed 100644 --- a/res/layout-xlarge/other_setting_popup.xml +++ b/res/layout-xlarge/other_setting_popup.xml @@ -37,42 +37,16 @@ style="@style/SettingTitleText" /> </FrameLayout> - <FrameLayout android:paddingTop="10dp" - android:layout_width="match_parent" + <FrameLayout android:layout_width="570dp" android:layout_height="wrap_content" android:background="@drawable/dialog_bottom_holo_dark"> - <ScrollView android:orientation="vertical" + <ListView android:id="@+id/contentPanel" + android:orientation="vertical" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" + android:paddingBottom="3dp" android:layout_gravity="center" android:layout_width="match_parent" - android:layout_height="wrap_content"> - <LinearLayout android:id="@+id/contentPanel" - android:layout_width="wrap_content" - android:layout_height="wrap_content" - android:orientation="vertical"> - <com.android.camera.ui.InLineSettingPicker camera:prefKey="pref_camera_recordlocation_key" - android:layout_width="wrap_content" android:layout_height="wrap_content" /> - <com.android.camera.ui.InLineSettingPicker camera:prefKey="pref_camera_focusmode_key" - android:layout_width="wrap_content" android:layout_height="wrap_content" /> - <com.android.camera.ui.InLineSettingPicker camera:prefKey="pref_camera_exposure_key" - android:layout_width="wrap_content" android:layout_height="wrap_content" /> - <com.android.camera.ui.InLineSettingPicker camera:prefKey="pref_camera_picturesize_key" - android:layout_width="wrap_content" android:layout_height="wrap_content" /> - <com.android.camera.ui.InLineSettingPicker camera:prefKey="pref_camera_jpegquality_key" - android:layout_width="wrap_content" android:layout_height="wrap_content" /> - <ImageView android:layout_width="match_parent" - android:layout_height="wrap_content" - android:src="@drawable/divider_horizontal_holo_dark" - android:scaleType="fitXY" /> - <TextView - android:text="@string/pref_restore_detail" - android:gravity="center" - android:textSize="21dp" - android:textColor="@android:color/white" - style="@style/SettingRow"> - </TextView> - </LinearLayout> - </ScrollView> + android:layout_height="wrap_content" /> </FrameLayout> </com.android.camera.ui.OtherSettingsPopup> diff --git a/src/com/android/camera/ui/InLineSettingPicker.java b/src/com/android/camera/ui/InLineSettingPicker.java index adc0e89..3eebc6c 100644 --- a/src/com/android/camera/ui/InLineSettingPicker.java +++ b/src/com/android/camera/ui/InLineSettingPicker.java @@ -26,7 +26,7 @@ import android.view.LayoutInflater; import android.view.View; import android.view.View.OnTouchListener; import android.widget.Button; -import android.widget.LinearLayout; +import android.widget.RelativeLayout; import android.widget.TextView; import com.android.camera.R; @@ -37,7 +37,7 @@ import java.util.Formatter; /* A one-line camera setting that includes a title (ex: Picture size), a previous button, the current value (ex: 5MP), and a next button. Other setting popup window includes several InLineSettingPicker. */ -public class InLineSettingPicker extends LinearLayout { +public class InLineSettingPicker extends RelativeLayout { private final String TAG = "InLineSettingPicker"; // The view that shows the name of the setting. Ex: Picture size private TextView mTitle; @@ -73,11 +73,12 @@ public class InLineSettingPicker extends LinearLayout { public InLineSettingPicker(Context context, AttributeSet attrs) { super(context, attrs); - LayoutInflater inflater = - (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); - inflater.inflate(R.layout.in_line_setting_picker, this, true); mHandler = new Handler(); + } + @Override + public void onFinishInflate() { + super.onFinishInflate(); OnTouchListener nextTouchListener = new OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (mOverrideValue != null) return true; @@ -120,20 +121,11 @@ public class InLineSettingPicker extends LinearLayout { mPrevButton.setOnTouchListener(previousTouchListener); mEntry = (TextView) findViewById(R.id.current_setting); mTitle = (TextView) findViewById(R.id.title); - - TypedArray a = context.obtainStyledAttributes( - attrs, R.styleable.InLineSettingPicker, 0, 0); - mKey = a.getString(R.styleable.InLineSettingPicker_prefKey); - } - - public String getKey() { - return mKey; } public void initialize(ListPreference preference) { mPreference = preference; mIndex = mPreference.findIndexOfValue(mPreference.getValue()); - mTitle.setText(mPreference.getTitle()); updateView(); } diff --git a/src/com/android/camera/ui/OtherSettingsPopup.java b/src/com/android/camera/ui/OtherSettingsPopup.java index c0935c2..c521ed9 100644 --- a/src/com/android/camera/ui/OtherSettingsPopup.java +++ b/src/com/android/camera/ui/OtherSettingsPopup.java @@ -16,55 +16,126 @@ package com.android.camera.ui; +import com.android.camera.CameraSettings; import com.android.camera.ListPreference; import com.android.camera.PreferenceGroup; +import com.android.camera.R; import android.content.Context; -import android.content.res.Resources.Theme; -import android.content.res.TypedArray; import android.util.AttributeSet; import android.util.Log; import android.view.View; import android.view.ViewGroup; -import android.widget.LinearLayout; +import android.widget.AdapterView; +import android.widget.ListView; +import android.widget.SimpleAdapter; +import android.widget.TextView; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; /* A popup window that contains several camera settings. */ public class OtherSettingsPopup extends AbstractSettingPopup - implements InLineSettingPicker.Listener, View.OnClickListener { + implements InLineSettingPicker.Listener, + AdapterView.OnItemClickListener { private static final String TAG = "OtherSettingsPopup"; + private static final String[] OTHER_SETTING_KEYS = { + CameraSettings.KEY_RECORD_LOCATION, + CameraSettings.KEY_FOCUS_MODE, + CameraSettings.KEY_EXPOSURE, + CameraSettings.KEY_PICTURE_SIZE, + CameraSettings.KEY_JPEG_QUALITY}; + private static final String ITEM_KEY = "key"; + private static final String ITEM_TITLE = "text"; + private static final String ITEM_VALUE = "value"; + private static final String ITEM_RESTORE = "reset"; + + private Context mContext; private Listener mListener; + private PreferenceGroup mPreferenceGroup; + private ArrayList<HashMap<String, Object>> mListItem = + new ArrayList<HashMap<String, Object>>(); static public interface Listener { public void onOtherSettingChanged(); public void onRestorePreferencesClicked(); } + private class OtherSettingsAdapter extends SimpleAdapter { + + OtherSettingsAdapter(Context context, + List<? extends Map<String, ?>> data, + int resource, String[] from, int[] to) { + super(context, data, resource, from, to); + } + + @Override + public View getView(int position, View convertView, ViewGroup parent) { + if (convertView != null) return convertView; + + InLineSettingPicker view = (InLineSettingPicker) + super.getView(position, convertView, parent); + TextView restoreSettings = + (TextView) view.findViewById(R.id.restore); + View settingItem = view.findViewById(R.id.setting_item); + + // We apply the same View(InLineSettingPicker) as the listview's + // components. To show the restore setting line, we control the + // visibilities of components in InLineSettingPicker. + boolean isRestoreItem = (position == mListItem.size() - 1); + settingItem.setVisibility( + isRestoreItem ? View.GONE : View.VISIBLE); + restoreSettings.setVisibility( + isRestoreItem ? View.VISIBLE : View.GONE); + + if (!isRestoreItem) { + HashMap map = (HashMap) mListItem.get(position); + ListPreference pref = (ListPreference) map.get(ITEM_KEY); + view.initialize(pref); + view.setSettingChangedListener(OtherSettingsPopup.this); + } + return view; + } + } + public void setOtherSettingChangedListener(Listener listener) { mListener = listener; } public OtherSettingsPopup(Context context, AttributeSet attrs) { super(context, attrs); + mContext = context; } public void initialize(PreferenceGroup group) { - // Initialize each camera setting. - for (int i = mContentPanel.getChildCount() - 1; i >= 0; i--) { - View v = mContentPanel.getChildAt(i); - if (v instanceof InLineSettingPicker) { - InLineSettingPicker picker = (InLineSettingPicker) v; - 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 - mContentPanel.removeViewAt(i); - } - } else { // This row is restore defaults. - v.setOnClickListener(this); + mPreferenceGroup = group; + // Prepare the setting items. + for (int i = 0; i < OTHER_SETTING_KEYS.length; ++i) { + HashMap<String, Object> map = new HashMap<String, Object>(); + ListPreference pref = group.findPreference(OTHER_SETTING_KEYS[i]); + if (pref != null) { + map.put(ITEM_KEY, pref); + map.put(ITEM_TITLE, pref.getTitle()); + map.put(ITEM_VALUE, pref.getEntry()); + mListItem.add(map); } - } - requestLayout(); + } + + // Prepare the restore setting line. + HashMap<String, Object> map = new HashMap<String, Object>(); + map.put(ITEM_RESTORE, mContext.getString(R.string.pref_restore_detail)); + mListItem.add(map); + + SimpleAdapter mListItemAdapter = new OtherSettingsAdapter(mContext, + mListItem, + R.layout.in_line_setting_picker, + new String[] {ITEM_TITLE, ITEM_VALUE, ITEM_RESTORE}, + new int[] {R.id.title, R.id.current_setting, R.id.restore}); + ((ListView) mContentPanel).setAdapter(mListItemAdapter); + ((ListView) mContentPanel).setOnItemClickListener(this); + ((ListView) mContentPanel).setSelector(android.R.color.transparent); } public void onSettingChanged() { @@ -77,19 +148,18 @@ public class OtherSettingsPopup extends AbstractSettingPopup public void overrideSettings(String key, String value) { int count = mContentPanel.getChildCount(); for (int i = 0; i < count; i++) { - View v = mContentPanel.getChildAt(i); - if (v instanceof InLineSettingPicker) { - InLineSettingPicker picker = (InLineSettingPicker) v; - if (key.equals(picker.getKey())) { - picker.overrideSettings(value); - } + if (key.equals(mListItem.get(i).get(ITEM_KEY))) { + InLineSettingPicker picker = + (InLineSettingPicker) mContentPanel.getChildAt(i); + picker.overrideSettings(value); } } } @Override - public void onClick(View v) { - if (mListener != null) { + public void onItemClick(AdapterView<?> parent, View view, int position, + long id) { + if ((position == mListItem.size() - 1) && (mListener != null)) { mListener.onRestorePreferencesClicked(); } } |