diff options
Diffstat (limited to 'src/com/android/camera/ui/ListSubMenu.java')
-rw-r--r-- | src/com/android/camera/ui/ListSubMenu.java | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/src/com/android/camera/ui/ListSubMenu.java b/src/com/android/camera/ui/ListSubMenu.java index a425c7680..04da7bc49 100644 --- a/src/com/android/camera/ui/ListSubMenu.java +++ b/src/com/android/camera/ui/ListSubMenu.java @@ -29,11 +29,13 @@ import android.graphics.Rect; import android.util.AttributeSet; import android.util.Log; import android.view.View; +import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.SimpleAdapter; +import android.widget.Space; import com.android.camera.IconListPreference; import com.android.camera.ListPreference; @@ -45,10 +47,11 @@ import org.codeaurora.snapcam.R; // the entries will contain both text and icons. Otherwise, entries will be // shown in text. public class ListSubMenu extends ListView implements - AdapterView.OnItemClickListener { + RotateLayout.Child, AdapterView.OnItemClickListener { private static final String TAG = "ListPrefSettingPopup"; private ListPreference mPreference; private Listener mListener; + private View mHeader, mFooter; private int mY; static public interface Listener { @@ -121,7 +124,7 @@ public class ListSubMenu extends ListView implements public void reloadPreference() { int index = mPreference.findIndexOfValue(mPreference.getValue()); if (index != -1) { - setItemChecked(index, true); + setItemChecked(index + getHeaderViewsCount(), true); } else { Log.e(TAG, "Invalid preference value."); mPreference.print(); @@ -135,6 +138,10 @@ public class ListSubMenu extends ListView implements @Override public void onItemClick(AdapterView<?> parent, View view, int index, long id) { + index -= getHeaderViewsCount(); + if (index < 0 || index >= getAdapter().getCount()) { + return; + } mPreference.setValueIndex(index); if (mListener != null) { mListener.onListPrefChanged(mPreference); @@ -146,6 +153,33 @@ public class ListSubMenu extends ListView implements super.onFocusChanged(gainFocus, direction, previouslyFocusedRect); } + @Override + public void onApplyWindowInsets(Rect insets, int rootWidth, int rootHeight) { + if (mHeader == null) { + mHeader = new Space(getContext()); + addHeaderView(mHeader); + setHeaderDividersEnabled(false); + mFooter = new Space(getContext()); + addFooterView(mFooter); + setFooterDividersEnabled(false); + reloadPreference(); + } + + boolean largerThanRoot = + getPreCalculatedHeight() - insets.top - insets.bottom > rootHeight; + adjustViewHeight(mHeader, largerThanRoot ? insets.top : 0); + adjustViewHeight(mFooter, largerThanRoot ? insets.bottom : 0); + } + + private void adjustViewHeight(View view, int height) { + ViewGroup.LayoutParams lp = view.getLayoutParams(); + if (lp == null) { + lp = generateDefaultLayoutParams(); + } + lp.height = height; + view.setLayoutParams(lp); + } + public int getPreCalculatedHeight() { int count = getAdapter().getCount(); return count * (int) getContext().getResources().getDimension(R.dimen.setting_row_height) |