diff options
author | Evan Millar <emillar@google.com> | 2011-09-30 09:57:14 -0700 |
---|---|---|
committer | Evan Millar <emillar@google.com> | 2011-09-30 16:18:57 -0700 |
commit | a29127be09f74782dee7d6c18cf6dd50728652aa (patch) | |
tree | 17889976b48d952de19c64ddcb181484cfe76b2d | |
parent | 75ebc879150db8ebe77e95217d0b4d1a132d40b6 (diff) | |
download | android_packages_apps_Gallery2-a29127be09f74782dee7d6c18cf6dd50728652aa.tar.gz android_packages_apps_Gallery2-a29127be09f74782dee7d6c18cf6dd50728652aa.tar.bz2 android_packages_apps_Gallery2-a29127be09f74782dee7d6c18cf6dd50728652aa.zip |
Various UI fixes in Gallery
-New assets for grid and strip selection borders.
-Fix spacing in details dialog.
-New scrollbar asset in the strip view.
-Deleted unused ScrollView.java and GlDetailsView.java
bug:5327238
Change-Id: I147b8f8069f42e345110f7ae86c47d331551f089
20 files changed, 34 insertions, 455 deletions
diff --git a/res/drawable-hdpi/grid_pressed.9.png b/res/drawable-hdpi/grid_pressed.9.png Binary files differindex 41cd9aa58..5e1d2e369 100644 --- a/res/drawable-hdpi/grid_pressed.9.png +++ b/res/drawable-hdpi/grid_pressed.9.png diff --git a/res/drawable-hdpi/grid_selected.9.png b/res/drawable-hdpi/grid_selected.9.png Binary files differindex 0d8d2f51e..24a78d2a9 100644 --- a/res/drawable-hdpi/grid_selected.9.png +++ b/res/drawable-hdpi/grid_selected.9.png diff --git a/res/drawable-hdpi/scrollbar_handle_holo_dark.9.png b/res/drawable-hdpi/scrollbar_handle_holo_dark.9.png Binary files differdeleted file mode 100644 index 575edee14..000000000 --- a/res/drawable-hdpi/scrollbar_handle_holo_dark.9.png +++ /dev/null diff --git a/res/drawable-hdpi/thumb_selected.9.png b/res/drawable-hdpi/thumb_selected.9.png Binary files differnew file mode 100644 index 000000000..3e762f230 --- /dev/null +++ b/res/drawable-hdpi/thumb_selected.9.png diff --git a/res/drawable-mdpi/grid_pressed.9.png b/res/drawable-mdpi/grid_pressed.9.png Binary files differindex b26bc8816..74ba39c0e 100644 --- a/res/drawable-mdpi/grid_pressed.9.png +++ b/res/drawable-mdpi/grid_pressed.9.png diff --git a/res/drawable-mdpi/grid_selected.9.png b/res/drawable-mdpi/grid_selected.9.png Binary files differindex a8f7e191c..0310273aa 100644 --- a/res/drawable-mdpi/grid_selected.9.png +++ b/res/drawable-mdpi/grid_selected.9.png diff --git a/res/drawable-mdpi/scrollbar_handle_holo_dark.9.png b/res/drawable-mdpi/scrollbar_handle_holo_dark.9.png Binary files differdeleted file mode 100644 index e039c4bca..000000000 --- a/res/drawable-mdpi/scrollbar_handle_holo_dark.9.png +++ /dev/null diff --git a/res/drawable-mdpi/thumb_selected.9.png b/res/drawable-mdpi/thumb_selected.9.png Binary files differnew file mode 100644 index 000000000..b1c8fac7f --- /dev/null +++ b/res/drawable-mdpi/thumb_selected.9.png diff --git a/res/drawable-xhdpi/grid_pressed.9.png b/res/drawable-xhdpi/grid_pressed.9.png Binary files differindex 339d1eb74..4e505322a 100644 --- a/res/drawable-xhdpi/grid_pressed.9.png +++ b/res/drawable-xhdpi/grid_pressed.9.png diff --git a/res/drawable-xhdpi/grid_selected.9.png b/res/drawable-xhdpi/grid_selected.9.png Binary files differindex 31777a1cc..5609df051 100644 --- a/res/drawable-xhdpi/grid_selected.9.png +++ b/res/drawable-xhdpi/grid_selected.9.png diff --git a/res/drawable-xhdpi/thumb_selected.9.png b/res/drawable-xhdpi/thumb_selected.9.png Binary files differnew file mode 100644 index 000000000..9ddbd05f9 --- /dev/null +++ b/res/drawable-xhdpi/thumb_selected.9.png diff --git a/res/layout/details_list.xml b/res/layout/details_list.xml new file mode 100644 index 000000000..b80ab6ca8 --- /dev/null +++ b/res/layout/details_list.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="utf-8"?> +<!-- Copyright (C) 2011 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. +--> + +<ListView xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:padding="16dp" + android:dividerHeight="8dp" +/> diff --git a/res/values-xlarge/bool.xml b/res/values-xlarge/bool.xml deleted file mode 100644 index cffa691fc..000000000 --- a/res/values-xlarge/bool.xml +++ /dev/null @@ -1,4 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<resources> - <bool name="dialog_details_view">false</bool> -</resources>
\ No newline at end of file diff --git a/res/values/bool.xml b/res/values/bool.xml index 7b7ead20f..464842ab4 100644 --- a/res/values/bool.xml +++ b/res/values/bool.xml @@ -14,6 +14,5 @@ limitations under the License. --> <resources> - <bool name="dialog_details_view">true</bool> <bool name="show_action_bar_title">false</bool> </resources>
\ No newline at end of file diff --git a/src/com/android/gallery3d/ui/DetailsHelper.java b/src/com/android/gallery3d/ui/DetailsHelper.java index 0ff01e6f3..8f1cd0c3f 100644 --- a/src/com/android/gallery3d/ui/DetailsHelper.java +++ b/src/com/android/gallery3d/ui/DetailsHelper.java @@ -46,14 +46,7 @@ public class DetailsHelper { } public DetailsHelper(GalleryActivity activity, GLView rootPane, DetailsSource source) { - boolean useDialog = activity.getAndroidContext().getResources().getBoolean( - R.bool.dialog_details_view); - if (useDialog) { - mContainer = new DialogDetailsView(activity, source); - } else { - mContainer = new GLDetailsView(activity, source); - rootPane.addComponent((GLView) mContainer); - } + mContainer = new DialogDetailsView(activity, source); } public void layout(int left, int top, int right, int bottom) { diff --git a/src/com/android/gallery3d/ui/DialogDetailsView.java b/src/com/android/gallery3d/ui/DialogDetailsView.java index adc9de11d..58b15eb24 100644 --- a/src/com/android/gallery3d/ui/DialogDetailsView.java +++ b/src/com/android/gallery3d/ui/DialogDetailsView.java @@ -57,6 +57,7 @@ import android.view.View; import android.view.ViewGroup; import android.view.View.MeasureSpec; import android.widget.BaseAdapter; +import android.widget.ListView; import android.widget.TextView; import java.util.ArrayList; @@ -110,8 +111,11 @@ public class DialogDetailsView implements DetailsViewContainer { String title = String.format( mContext.getAndroidContext().getString(R.string.details_title), mIndex + 1, mSource.size()); + ListView detailsList = (ListView) LayoutInflater.from(mContext.getAndroidContext()).inflate( + R.layout.details_list, null, false); + detailsList.setAdapter(mAdapter); mDialog = new AlertDialog.Builder((Activity) mContext) - .setAdapter(mAdapter, null) + .setView(detailsList) .setTitle(title) .setPositiveButton(R.string.close, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { diff --git a/src/com/android/gallery3d/ui/GLDetailsView.java b/src/com/android/gallery3d/ui/GLDetailsView.java deleted file mode 100644 index c0542e1c9..000000000 --- a/src/com/android/gallery3d/ui/GLDetailsView.java +++ /dev/null @@ -1,328 +0,0 @@ -/* - * Copyright (C) 2010 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.gallery3d.ui; - -import static com.android.gallery3d.ui.DetailsWindowConfig.FONT_SIZE; -import static com.android.gallery3d.ui.DetailsWindowConfig.LEFT_RIGHT_EXTRA_PADDING; -import static com.android.gallery3d.ui.DetailsWindowConfig.LINE_SPACING; -import static com.android.gallery3d.ui.DetailsWindowConfig.PREFERRED_WIDTH; -import static com.android.gallery3d.ui.DetailsWindowConfig.TOP_BOTTOM_EXTRA_PADDING; - -import com.android.gallery3d.R; -import com.android.gallery3d.app.GalleryActivity; -import com.android.gallery3d.common.Utils; -import com.android.gallery3d.data.MediaDetails; -import com.android.gallery3d.ui.DetailsAddressResolver.AddressResolvingListener; -import com.android.gallery3d.ui.DetailsHelper.DetailsSource; -import com.android.gallery3d.ui.DetailsHelper.DetailsViewContainer; -import com.android.gallery3d.ui.DetailsHelper.CloseListener; - -import android.content.Context; -import android.graphics.Color; -import android.graphics.Rect; -import android.text.Layout; -import android.text.format.Formatter; -import android.view.MotionEvent; -import android.view.View.MeasureSpec; - -import java.util.ArrayList; -import java.util.Map.Entry; - -public class GLDetailsView extends GLView implements DetailsViewContainer { - @SuppressWarnings("unused") - private static final String TAG = "GLDetailsView"; - private static final int FONT_COLOR = Color.WHITE; - private static final int CLOSE_BUTTON_SIZE = 32; - - private GalleryActivity mContext; - protected Texture mBackground; - private StringTexture mTitle; - private MyDataModel mModel; - private MediaDetails mDetails; - private DetailsSource mSource; - private int mIndex; - private int mLocationIndex; - private Icon mCloseButton; - private int mMaxDetailLength; - private CloseListener mListener; - - private ScrollView mScrollView; - private DetailsPanel mDetailPanel = new DetailsPanel(); - - public GLDetailsView(GalleryActivity activity, DetailsSource source) { - mContext = activity; - mSource = source; - - Context context = activity.getAndroidContext(); - ResourceTexture icon = new ResourceTexture(context, R.drawable.ic_lockscreen_chevron_up); - setBackground(new NinePatchTexture(context, R.drawable.popup_full_dark)); - - mCloseButton = new Icon(context, icon, CLOSE_BUTTON_SIZE, CLOSE_BUTTON_SIZE) { - @Override - protected boolean onTouch(MotionEvent event) { - switch (event.getActionMasked()) { - case MotionEvent.ACTION_UP: - if (mListener != null) mListener.onClose(); - } - return true; - } - }; - mScrollView = new ScrollView(context); - mScrollView.addComponent(mDetailPanel); - - super.addComponent(mScrollView); - super.addComponent(mCloseButton); - } - - public void setCloseListener(CloseListener listener) { - mListener = listener; - } - - public void setBackground(Texture background) { - if (background == mBackground) return; - mBackground = background; - if (background != null && background instanceof NinePatchTexture) { - Rect p = ((NinePatchTexture) mBackground).getPaddings(); - p.left += LEFT_RIGHT_EXTRA_PADDING; - p.right += LEFT_RIGHT_EXTRA_PADDING; - p.top += TOP_BOTTOM_EXTRA_PADDING; - p.bottom += TOP_BOTTOM_EXTRA_PADDING; - setPaddings(p); - } else { - setPaddings(0, 0, 0, 0); - } - Rect p = getPaddings(); - mMaxDetailLength = PREFERRED_WIDTH - p.left - p.right; - invalidate(); - } - - public void setTitle(String title) { - mTitle = StringTexture.newInstance(title, FONT_SIZE, FONT_COLOR); - } - - @Override - protected void renderBackground(GLCanvas canvas) { - if (mBackground == null) return; - int width = getWidth(); - int height = getHeight(); - - //TODO: change alpha in the background image. - canvas.save(GLCanvas.SAVE_FLAG_ALPHA); - canvas.setAlpha(0.7f); - mBackground.draw(canvas, 0, 0, width, height); - canvas.restore(); - - Rect p = getPaddings(); - if (mTitle != null) mTitle.draw(canvas, p.left, p.top); - } - - @Override - protected void onMeasure(int widthSpec, int heightSpec) { - mScrollView.measure(widthSpec, heightSpec); - mCloseButton.measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); - int height = mScrollView.getMeasuredHeight() + mCloseButton.getMeasuredHeight(); - MeasureHelper.getInstance(this) - .setPreferredContentSize(mScrollView.getMeasuredWidth(), height) - .measure(widthSpec, heightSpec); - } - - @Override - protected void onLayout(boolean sizeChange, int l, int t, int r, int b) { - int bWidth = mCloseButton.getMeasuredWidth(); - int bHeight = mCloseButton.getMeasuredHeight(); - int width = getWidth(); - int height = getHeight(); - - Rect p = getPaddings(); - mCloseButton.layout(width - p.right - bWidth, p.top, - width - p.right, p.top + bHeight); - mScrollView.layout(p.left, p.top + bHeight, width - p.right, - height - p.bottom); - } - - public void show() { - reloadDetails(mSource.getIndex()); - setVisibility(GLView.VISIBLE); - requestLayout(); - } - - public void hide() { - setVisibility(GLView.INVISIBLE); - requestLayout(); - } - - public void reloadDetails(int indexHint) { - int index = mSource.findIndex(indexHint); - if (index == -1) return; - MediaDetails details = mSource.getDetails(); - if (details != null) { - if (mIndex == index && mDetails == details) return; - mIndex = index; - mDetails = details; - setDetails(details); - } - mDetailPanel.requestLayout(); - } - - private void setDetails(MediaDetails details) { - mModel = new MyDataModel(details); - invalidate(); - } - - private class MyDataModel implements AddressResolvingListener { - ArrayList<Texture> mItems; - - public MyDataModel(MediaDetails details) { - Context context = mContext.getAndroidContext(); - mLocationIndex = -1; - mItems = new ArrayList<Texture>(details.size()); - setTitle(String.format(context.getString(R.string.sequence_in_set), - mIndex + 1, mSource.size())); - setDetails(context, details); - } - - private void setDetails(Context context, MediaDetails details) { - for (Entry<Integer, Object> detail : details) { - String value; - switch (detail.getKey()) { - case MediaDetails.INDEX_LOCATION: { - double[] latlng = (double[]) detail.getValue(); - mLocationIndex = mItems.size(); - value = DetailsHelper.resolveAddress(mContext, latlng, this); - break; - } - case MediaDetails.INDEX_SIZE: { - value = Formatter.formatFileSize( - context, (Long) detail.getValue()); - break; - } - case MediaDetails.INDEX_WHITE_BALANCE: { - value = "1".equals(detail.getValue()) - ? context.getString(R.string.manual) - : context.getString(R.string.auto); - break; - } - case MediaDetails.INDEX_FLASH: { - MediaDetails.FlashState flash = - (MediaDetails.FlashState) detail.getValue(); - // TODO: camera doesn't fill in the complete values, show more information - // when it is fixed. - if (flash.isFlashFired()) { - value = context.getString(R.string.flash_on); - } else { - value = context.getString(R.string.flash_off); - } - break; - } - case MediaDetails.INDEX_EXPOSURE_TIME: { - value = (String) detail.getValue(); - double time = Double.valueOf(value); - if (time < 1.0f) { - value = String.format("1/%d", (int) (0.5f + 1 / time)); - } else { - int integer = (int) time; - time -= integer; - value = String.valueOf(integer) + "''"; - if (time > 0.0001) { - value += String.format(" 1/%d", (int) (0.5f + 1 / time)); - } - } - break; - } - default: { - Object valueObj = detail.getValue(); - // This shouldn't happen, log its key to help us diagnose the problem. - Utils.assertTrue(valueObj != null, "%s's value is Null", - DetailsHelper.getDetailsName(context, detail.getKey())); - value = valueObj.toString(); - } - } - int key = detail.getKey(); - if (details.hasUnit(key)) { - value = String.format("%s : %s %s", DetailsHelper.getDetailsName( - context, key), value, context.getString(details.getUnit(key))); - } else { - value = String.format("%s : %s", DetailsHelper.getDetailsName( - context, key), value); - } - Texture label = MultiLineTexture.newInstance( - value, mMaxDetailLength, FONT_SIZE, FONT_COLOR, - Layout.Alignment.ALIGN_NORMAL); - mItems.add(label); - } - } - - public Texture getView(int index) { - return mItems.get(index); - } - - public int size() { - return mItems.size(); - } - - public void onAddressAvailable(String address) { - mItems.set(mLocationIndex, MultiLineTexture.newInstance( - address, mMaxDetailLength, FONT_SIZE, FONT_COLOR, - Layout.Alignment.ALIGN_NORMAL)); - GLDetailsView.this.invalidate(); - } - } - - private class DetailsPanel extends GLView { - - @Override - public void onMeasure(int widthSpec, int heightSpec) { - if (mTitle == null || mModel == null) { - MeasureHelper.getInstance(this) - .setPreferredContentSize(PREFERRED_WIDTH, 0) - .measure(widthSpec, heightSpec); - return; - } - - Rect p = getPaddings(); - int h = p.top + LINE_SPACING; - for (int i = 0, n = mModel.size(); i < n; ++i) { - h += mModel.getView(i).getHeight() + LINE_SPACING; - } - h += p.bottom; - - MeasureHelper.getInstance(this) - .setPreferredContentSize(PREFERRED_WIDTH, h) - .measure(widthSpec, heightSpec); - } - - @Override - protected void render(GLCanvas canvas) { - super.render(canvas); - - if (mTitle == null || mModel == null) { - return; - } - Rect p = getPaddings(); - int x = p.left, y = p.top + LINE_SPACING; - for (int i = 0, n = mModel.size(); i < n ; i++) { - Texture t = mModel.getView(i); - t.draw(canvas, x, y); - y += t.getHeight() + LINE_SPACING; - } - } - } - - public GLView getGLView() { - return this; - } -} diff --git a/src/com/android/gallery3d/ui/ScrollBarView.java b/src/com/android/gallery3d/ui/ScrollBarView.java index 7e375c9f7..b33f03b07 100644 --- a/src/com/android/gallery3d/ui/ScrollBarView.java +++ b/src/com/android/gallery3d/ui/ScrollBarView.java @@ -20,6 +20,7 @@ import com.android.gallery3d.R; import android.content.Context; import android.graphics.Rect; +import android.util.TypedValue; public class ScrollBarView extends GLView { @SuppressWarnings("unused") @@ -43,8 +44,11 @@ public class ScrollBarView extends GLView { private NinePatchTexture mScrollBarTexture; public ScrollBarView(Context context, int gripHeight, int gripWidth) { + TypedValue outValue = new TypedValue(); + context.getTheme().resolveAttribute( + android.R.attr.scrollbarThumbHorizontal, outValue, true); mScrollBarTexture = new NinePatchTexture( - context, R.drawable.scrollbar_handle_holo_dark); + context, outValue.resourceId); mGripPosition = 0; mGripWidth = 0; mGivenGripWidth = gripWidth; diff --git a/src/com/android/gallery3d/ui/ScrollView.java b/src/com/android/gallery3d/ui/ScrollView.java deleted file mode 100644 index 23a8bb5bf..000000000 --- a/src/com/android/gallery3d/ui/ScrollView.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright (C) 2011 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.gallery3d.ui; - -import com.android.gallery3d.R; -import com.android.gallery3d.common.Utils; - -import android.content.Context; -import android.view.GestureDetector; -import android.view.MotionEvent; -import android.view.View.MeasureSpec; - -// The current implementation can only scroll vertically. -public class ScrollView extends GLView { - - private static final int MIN_SCROLLER_HEIGHT = 20; - - private NinePatchTexture mScroller; - private int mScrollLimit = 0; - private int mScrollerHeight = MIN_SCROLLER_HEIGHT; - private GestureDetector mGestureDetector; - - public ScrollView(Context context) { - mScroller = new NinePatchTexture(context, R.drawable.scrollbar_handle_holo_dark); - mGestureDetector = new GestureDetector(context, new MyGestureListener()); - } - - private GLView getContentView() { - return getComponentCount() == 0 ? null : getComponent(0); - } - - @Override - protected void onMeasure(int widthSpec, int heightSpec) { - GLView view = getContentView(); - if (view != null) { - view.measure(widthSpec, heightSpec); - MeasureHelper.getInstance(this) - .setPreferredContentSize(view.getMeasuredWidth(), - view.getMeasuredHeight()) - .measure(widthSpec, heightSpec); - } - } - - @Override - public void onLayout(boolean sizeChange, int l, int t, int r, int b) { - GLView content = getContentView(); - int width = getWidth(); - int height = getHeight(); - content.measure(MeasureSpec.makeMeasureSpec(width, MeasureSpec.EXACTLY), - MeasureSpec.UNSPECIFIED); - int contentHeight = content.getMeasuredHeight(); - content.layout(0, 0, width, contentHeight); - if (height < contentHeight) { - mScrollLimit = contentHeight - height; - mScrollerHeight = Math.max(MIN_SCROLLER_HEIGHT, - height * height / contentHeight); - } else { - mScrollLimit = 0; - } - mScrollY = Utils.clamp(mScrollY, 0, mScrollLimit); - } - - @Override - public void render(GLCanvas canvas) { - GLView content = getContentView(); - if (content == null) return; - int width = getWidth(); - int height = getHeight(); - - canvas.save(GLCanvas.SAVE_FLAG_CLIP); - canvas.clipRect(0, 0, width, height); - super.render(canvas); - if (mScrollLimit > 0) { - int x = getWidth() - mScroller.getWidth(); - int y = (height - mScrollerHeight) * mScrollY / mScrollLimit; - mScroller.draw(canvas, x, y, mScroller.getWidth(), mScrollerHeight); - } - canvas.restore(); - } - - @Override - public boolean onTouch(MotionEvent event) { - mGestureDetector.onTouchEvent(event); - return true; - } - - private class MyGestureListener - extends GestureDetector.SimpleOnGestureListener { - @Override - public boolean onScroll(MotionEvent e1, - MotionEvent e2, float distanceX, float distanceY) { - mScrollY = Utils.clamp(mScrollY + (int) distanceY, 0, mScrollLimit); - invalidate(); - return true; - } - } -} diff --git a/src/com/android/gallery3d/ui/StripDrawer.java b/src/com/android/gallery3d/ui/StripDrawer.java index 5c67ee458..5941392c5 100644 --- a/src/com/android/gallery3d/ui/StripDrawer.java +++ b/src/com/android/gallery3d/ui/StripDrawer.java @@ -30,7 +30,7 @@ public class StripDrawer extends SelectionDrawer { public StripDrawer(Context context) { mFramePressed = new NinePatchTexture(context, R.drawable.grid_pressed); - mFocusBox = new NinePatchTexture(context, R.drawable.focus_box); + mFocusBox = new NinePatchTexture(context, R.drawable.thumb_selected); mFocusBoxPadding = mFocusBox.getPaddings(); } |