diff options
| -rw-r--r-- | res/drawable-mdpi/pie_bg_selected.png | bin | 1351 -> 0 bytes | |||
| -rw-r--r-- | res/drawable-mdpi/qc_background_normal.png | bin | 59066 -> 66290 bytes | |||
| -rw-r--r-- | res/drawable-mdpi/qc_background_selected.png | bin | 38353 -> 0 bytes | |||
| -rw-r--r-- | res/drawable/item_background_holo_dark.xm | 49 | ||||
| -rw-r--r-- | res/drawable/qc_item_selector.xml | 21 | ||||
| -rw-r--r-- | res/values/colors.xml | 2 | ||||
| -rw-r--r-- | res/values/dimensions.xml | 3 | ||||
| -rw-r--r-- | src/com/android/browser/PieControl.java | 6 | ||||
| -rw-r--r-- | src/com/android/browser/view/BasePieView.java | 2 | ||||
| -rw-r--r-- | src/com/android/browser/view/PieItem.java | 9 | ||||
| -rw-r--r-- | src/com/android/browser/view/PieListView.java | 4 | ||||
| -rw-r--r-- | src/com/android/browser/view/PieMenu.java | 91 | ||||
| -rw-r--r-- | src/com/android/browser/view/PieStackView.java | 7 |
13 files changed, 95 insertions, 99 deletions
diff --git a/res/drawable-mdpi/pie_bg_selected.png b/res/drawable-mdpi/pie_bg_selected.png Binary files differdeleted file mode 100644 index 787984a46..000000000 --- a/res/drawable-mdpi/pie_bg_selected.png +++ /dev/null diff --git a/res/drawable-mdpi/qc_background_normal.png b/res/drawable-mdpi/qc_background_normal.png Binary files differindex 947722d07..b9a16d163 100644 --- a/res/drawable-mdpi/qc_background_normal.png +++ b/res/drawable-mdpi/qc_background_normal.png diff --git a/res/drawable-mdpi/qc_background_selected.png b/res/drawable-mdpi/qc_background_selected.png Binary files differdeleted file mode 100644 index c0a6efc2a..000000000 --- a/res/drawable-mdpi/qc_background_selected.png +++ /dev/null diff --git a/res/drawable/item_background_holo_dark.xm b/res/drawable/item_background_holo_dark.xm deleted file mode 100644 index d5fa3c00f..000000000 --- a/res/drawable/item_background_holo_dark.xm +++ /dev/null @@ -1,49 +0,0 @@ -<?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. ---> - -<selector - xmlns:android="http://schemas.android.com/apk/res/android" - android:exitFadeDuration="@android:integer/config_mediumAnimTime"> - <item - android:state_window_focused="false" - android:drawable="@color/transparent" /> - <!-- - Even though these two point to the same resource, have two states so the - drawable will invalidate itself when coming out of pressed state. - --> - <item - android:state_focused="true" - android:state_enabled="false" - android:state_pressed="true" - android:drawable="@drawable/list_selector_disabled_holo_dark" /> - <item - android:state_focused="true" - android:state_enabled="false" - android:drawable="@drawable/list_selector_disabled_holo_dark" /> - <item - android:state_focused="true" - android:state_pressed="true" - android:drawable="@drawable/list_selector_background_transition_holo_dark" /> - <item - android:state_focused="false" - android:state_pressed="true" - android:drawable="@drawable/list_selector_background_transition_holo_dark" /> - <item - android:state_focused="true" - android:drawable="@drawable/list_focused_holo" /> - <item - android:drawable="@color/transparent" /> -</selector>
\ No newline at end of file diff --git a/res/drawable/qc_item_selector.xml b/res/drawable/qc_item_selector.xml deleted file mode 100644 index 77f802342..000000000 --- a/res/drawable/qc_item_selector.xml +++ /dev/null @@ -1,21 +0,0 @@ -<?xml version="1.0" encoding="utf-8"?> -<!-- 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. ---> - -<selector xmlns:android="http://schemas.android.com/apk/res/android"> - <item android:state_selected="true" - android:drawable="@drawable/pie_bg_selected" /> - <item android:state_selected="false" android:drawable="@drawable/clear" /> -</selector> diff --git a/res/values/colors.xml b/res/values/colors.xml index 73daa073c..6a7c578ce 100644 --- a/res/values/colors.xml +++ b/res/values/colors.xml @@ -34,4 +34,6 @@ <color name="tabFaviconBackground">#FF555555</color> <color name="tabFocusHighlight">#FF99CC00</color> <color name="qcMenuBackground">#C0000000</color> + <color name="qc_normal">#C02447B2</color> + <color name="qc_selected">#D0102052</color> </resources> diff --git a/res/values/dimensions.xml b/res/values/dimensions.xml index e92828e5f..99eb43e43 100644 --- a/res/values/dimensions.xml +++ b/res/values/dimensions.xml @@ -31,8 +31,9 @@ <dimen name="favicon_size">16dip</dimen> <dimen name="favicon_padded_size">20dip</dimen> <dimen name="qc_radius_start">50dip</dimen> - <dimen name="qc_radius_increment">60dip</dimen> + <dimen name="qc_radius_increment">70dip</dimen> <dimen name="qc_slop">15dip</dimen> + <dimen name="qc_touch_offset">15dip</dimen> <dimen name="qc_tab_title_height">30dip</dimen> <dimen name="qc_thumb_width">240dip</dimen> <dimen name="qc_thumb_height">160dip</dimen> diff --git a/src/com/android/browser/PieControl.java b/src/com/android/browser/PieControl.java index ed3e9600f..38ed1bbbd 100644 --- a/src/com/android/browser/PieControl.java +++ b/src/com/android/browser/PieControl.java @@ -26,8 +26,6 @@ import com.android.browser.view.PieStackView.OnCurrentListener; import android.app.Activity; import android.content.Context; import android.graphics.Bitmap; -import android.graphics.drawable.BitmapDrawable; -import android.os.Handler; import android.view.LayoutInflater; import android.view.Menu; import android.view.MenuItem; @@ -165,7 +163,6 @@ public class PieControl implements OnClickListener, PieMenu.PieController { image.setScaleType(ScaleType.CENTER); LayoutParams lp = new LayoutParams(mItemSize, mItemSize); v.setLayoutParams(lp); - v.setBackgroundResource(R.drawable.qc_item_selector); return v; } @@ -175,9 +172,8 @@ public class PieControl implements OnClickListener, PieMenu.PieController { view.setMinimumWidth(mItemSize); view.setMinimumHeight(mItemSize); view.setScaleType(ScaleType.CENTER); - LayoutParams lp = new LayoutParams(mItemSize,mItemSize); + LayoutParams lp = new LayoutParams(mItemSize, mItemSize); view.setLayoutParams(lp); - view.setBackgroundResource(R.drawable.qc_item_selector); return new PieItem(view, l); } diff --git a/src/com/android/browser/view/BasePieView.java b/src/com/android/browser/view/BasePieView.java index 212021566..ec02e3a68 100644 --- a/src/com/android/browser/view/BasePieView.java +++ b/src/com/android/browser/view/BasePieView.java @@ -109,7 +109,7 @@ public abstract class BasePieView implements PieMenu.PieView { * needs to set top, left, width, height */ @Override - public void layout(int anchorX, int anchorY, boolean left) { + public void layout(int anchorX, int anchorY, boolean left, float angle) { if (mListener != null) { mListener.onLayout(anchorX, anchorY, left); } diff --git a/src/com/android/browser/view/PieItem.java b/src/com/android/browser/view/PieItem.java index 84a6ac09e..36744472f 100644 --- a/src/com/android/browser/view/PieItem.java +++ b/src/com/android/browser/view/PieItem.java @@ -18,6 +18,7 @@ package com.android.browser.view; import com.android.browser.view.PieMenu.PieView; +import android.graphics.Path; import android.view.View; /** @@ -33,6 +34,7 @@ public class PieItem { private int inner; private int outer; private boolean mSelected; + private Path mPath; public PieItem(View view, int level) { mView = view; @@ -60,11 +62,12 @@ public class PieItem { return level; } - public void setGeometry(float st, float sw, int inside, int outside) { + public void setGeometry(float st, float sw, int inside, int outside, Path p) { start = st; sweep = sw; inner = inside; outer = outside; + mPath = p; } public float getStartAngle() { @@ -99,4 +102,8 @@ public class PieItem { return mPieView; } + public Path getPath() { + return mPath; + } + } diff --git a/src/com/android/browser/view/PieListView.java b/src/com/android/browser/view/PieListView.java index 8cd8a4e44..04b512b17 100644 --- a/src/com/android/browser/view/PieListView.java +++ b/src/com/android/browser/view/PieListView.java @@ -39,8 +39,8 @@ public class PieListView extends BasePieView { * this will be called before the first draw call */ @Override - public void layout(int anchorX, int anchorY, boolean left) { - super.layout(anchorX, anchorY, left); + public void layout(int anchorX, int anchorY, boolean left, float angle) { + super.layout(anchorX, anchorY, left, angle); buildViews(); mWidth = mChildWidth; mHeight = mChildHeight * mAdapter.getCount(); diff --git a/src/com/android/browser/view/PieMenu.java b/src/com/android/browser/view/PieMenu.java index e494d19a3..cded43552 100644 --- a/src/com/android/browser/view/PieMenu.java +++ b/src/com/android/browser/view/PieMenu.java @@ -21,8 +21,11 @@ import com.android.browser.R; import android.content.Context; import android.content.res.Resources; import android.graphics.Canvas; +import android.graphics.Paint; +import android.graphics.Path; import android.graphics.Point; import android.graphics.PointF; +import android.graphics.RectF; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.view.MotionEvent; @@ -57,7 +60,7 @@ public class PieMenu extends FrameLayout { public void setLayoutListener(OnLayoutListener l); - public void layout(int anchorX, int anchorY, boolean onleft); + public void layout(int anchorX, int anchorY, boolean onleft, float angle); public void draw(Canvas c); @@ -69,6 +72,7 @@ public class PieMenu extends FrameLayout { private int mRadius; private int mRadiusInc; private int mSlop; + private int mTouchOffset; private boolean mOpen; private PieController mController; @@ -79,6 +83,8 @@ public class PieMenu extends FrameLayout { private PieView mPieView = null; private Drawable mBackground; + private Paint mNormalPaint; + private Paint mSelectedPaint; // touch handling PieItem mCurrentItem; @@ -118,11 +124,18 @@ public class PieMenu extends FrameLayout { mRadius = (int) res.getDimension(R.dimen.qc_radius_start); mRadiusInc = (int) res.getDimension(R.dimen.qc_radius_increment); mSlop = (int) res.getDimension(R.dimen.qc_slop); + mTouchOffset = (int) res.getDimension(R.dimen.qc_touch_offset); mOpen = false; setWillNotDraw(false); setDrawingCacheEnabled(false); mCenter = new Point(0,0); mBackground = res.getDrawable(R.drawable.qc_background_normal); + mNormalPaint = new Paint(); + mNormalPaint.setColor(res.getColor(R.color.qc_normal)); + mNormalPaint.setAntiAlias(true); + mSelectedPaint = new Paint(); + mSelectedPaint.setColor(res.getColor(R.color.qc_selected)); + mSelectedPaint.setAntiAlias(true); } public void setController(PieController ctl) { @@ -178,13 +191,16 @@ public class PieMenu extends FrameLayout { } private void layoutPie() { - int inner = mRadius; - int outer = mRadius + mRadiusInc; + float emptyangle = (float) Math.PI / 16; + int rgap = 2; + int inner = mRadius + rgap; + int outer = mRadius + mRadiusInc - rgap; int radius = mRadius; + int gap = 1; for (int i = 0; i < mLevels; i++) { int level = i + 1; - float sweep = (float) Math.PI / (mCounts[level] + 1); - float angle = sweep; + float sweep = (float) (Math.PI - 2 * emptyangle) / mCounts[level]; + float angle = emptyangle + sweep / 2; for (PieItem item : mItems) { if (item.getLevel() == level) { View view = item.getView(); @@ -192,16 +208,20 @@ public class PieMenu extends FrameLayout { view.getLayoutParams().height); int w = view.getMeasuredWidth(); int h = view.getMeasuredHeight(); - int x = (int) (outer * Math.sin(angle)); - int y = mCenter.y - (int) (outer * Math.cos(angle)) - h / 2; + int r = inner + (outer - inner) * 2 / 3; + int x = (int) (r * Math.sin(angle)); + int y = mCenter.y - (int) (r * Math.cos(angle)) - h / 2; if (onTheLeft()) { - x = mCenter.x + x - w; + x = mCenter.x + x - w / 2; } else { - x = mCenter.x - x; + x = mCenter.x - x - w / 2; } view.layout(x, y, x + w, y + h); float itemstart = angle - sweep / 2; - item.setGeometry(itemstart, sweep, inner, outer); + Path slice = makeSlice(getDegrees(itemstart) - gap, + getDegrees(itemstart + sweep) + gap, + outer, inner, mCenter); + item.setGeometry(itemstart, sweep, inner, outer, slice); angle += sweep; } } @@ -210,6 +230,18 @@ public class PieMenu extends FrameLayout { } } + + /** + * converts a + * + * @param angle from 0..PI to Android degrees (clockwise starting at 3 + * o'clock) + * @return skia angle + */ + private float getDegrees(double angle) { + return (float) (270 - 180 * angle / Math.PI); + } + @Override protected void onDraw(Canvas canvas) { if (mOpen) { @@ -218,13 +250,21 @@ public class PieMenu extends FrameLayout { int left = mCenter.x - w; int top = mCenter.y - h / 2; mBackground.setBounds(left, top, left + w, top + h); - int state = canvas.save(); + int state; + state = canvas.save(); if (onTheLeft()) { canvas.scale(-1, 1); } mBackground.draw(canvas); canvas.restoreToCount(state); for (PieItem item : mItems) { + Paint p = item.isSelected() ? mSelectedPaint : mNormalPaint; + state = canvas.save(); + if (onTheLeft()) { + canvas.scale(-1, 1); + } + drawPath(canvas, item.getPath(), p); + canvas.restoreToCount(state); drawItem(canvas, item); } if (mPieView != null) { @@ -245,6 +285,24 @@ public class PieMenu extends FrameLayout { canvas.restoreToCount(state); } + private void drawPath(Canvas canvas, Path path, Paint paint) { + canvas.drawPath(path, paint); + } + + private Path makeSlice(float start, float end, int outer, int inner, Point center) { + RectF bb = + new RectF(center.x - outer, center.y - outer, center.x + outer, + center.y + outer); + RectF bbi = + new RectF(center.x - inner, center.y - inner, center.x + inner, + center.y + inner); + Path path = new Path(); + path.arcTo(bb, start, end - start, true); + path.arcTo(bbi, end, start - end); + path.close(); + return path; + } + // touch handling for pie @Override @@ -307,7 +365,8 @@ public class PieMenu extends FrameLayout { ? item.getView().getWidth() : 0); int cy = item.getView().getTop(); mPieView = item.getPieView(); - layoutPieView(mPieView, cx, cy); + layoutPieView(mPieView, cx, cy, + (item.getStartAngle() + item.getSweep()) / 2); } invalidate(); } @@ -316,8 +375,8 @@ public class PieMenu extends FrameLayout { return false; } - private void layoutPieView(PieView pv, int x, int y) { - pv.layout(x, y, onTheLeft()); + private void layoutPieView(PieView pv, int x, int y, float angle) { + pv.layout(x, y, onTheLeft(), angle); } /** @@ -373,8 +432,8 @@ public class PieMenu extends FrameLayout { private PieItem findItem(PointF polar) { // find the matching item: for (PieItem item : mItems) { - if ((item.getInnerRadius() < polar.y) - && (item.getOuterRadius() > polar.y) + if ((item.getInnerRadius() - mTouchOffset < polar.y) + && (item.getOuterRadius() - mTouchOffset > polar.y) && (item.getStartAngle() < polar.x) && (item.getStartAngle() + item.getSweep() > polar.x)) { return item; diff --git a/src/com/android/browser/view/PieStackView.java b/src/com/android/browser/view/PieStackView.java index df387ade0..ca641f9b4 100644 --- a/src/com/android/browser/view/PieStackView.java +++ b/src/com/android/browser/view/PieStackView.java @@ -59,8 +59,8 @@ public class PieStackView extends BasePieView { * this will be called before the first draw call */ @Override - public void layout(int anchorX, int anchorY, boolean left) { - super.layout(anchorX, anchorY, left); + public void layout(int anchorX, int anchorY, boolean left, float angle) { + super.layout(anchorX, anchorY, left, angle); buildViews(); mWidth = mChildWidth; mHeight = mChildHeight + (mViews.size() - 1) * mMinHeight; @@ -76,7 +76,8 @@ public class PieStackView extends BasePieView { int top = mTop; int dy = (n == 1) ? 0 : (mHeight - mChildHeight) / (n - 1); for (View view : mViews) { - view.layout(mLeft, top, mLeft + mChildWidth, top + mChildHeight); + int x = mLeft; + view.layout(x, top, x + mChildWidth, top + mChildHeight); top += dy; } } |
