summaryrefslogtreecommitdiffstats
path: root/src/com/android/browser/view
diff options
context:
space:
mode:
authorMichael Kolb <kolby@google.com>2011-03-08 14:12:06 -0800
committerMichael Kolb <kolby@google.com>2011-03-09 09:37:22 -0800
commit1acef69ffc079d1bc029ff7eb1f5043f7efd7f36 (patch)
tree9e8daece975b283d9866d2c1915cbd86446bb16b /src/com/android/browser/view
parent66996bfa98bcf98f2ea944ddd27439f554f8f0b9 (diff)
downloadpackages_apps_browser-1acef69ffc079d1bc029ff7eb1f5043f7efd7f36.zip
packages_apps_browser-1acef69ffc079d1bc029ff7eb1f5043f7efd7f36.tar.gz
packages_apps_browser-1acef69ffc079d1bc029ff7eb1f5043f7efd7f36.tar.bz2
add menu options to qc
Bug 4071315 Use the standard menu items to popuplate a menu from within quick controls Change-Id: I80d483ab2ce054e9b70ff4c6b0d6e0d9be783dc4
Diffstat (limited to 'src/com/android/browser/view')
-rw-r--r--src/com/android/browser/view/BasePieView.java150
-rw-r--r--src/com/android/browser/view/PieItem.java21
-rw-r--r--src/com/android/browser/view/PieListView.java78
-rw-r--r--src/com/android/browser/view/PieMenu.java45
4 files changed, 293 insertions, 1 deletions
diff --git a/src/com/android/browser/view/BasePieView.java b/src/com/android/browser/view/BasePieView.java
new file mode 100644
index 0000000..515545a
--- /dev/null
+++ b/src/com/android/browser/view/BasePieView.java
@@ -0,0 +1,150 @@
+/*
+ * 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.browser.view;
+
+import android.database.DataSetObserver;
+import android.graphics.Canvas;
+import android.view.MotionEvent;
+import android.view.View;
+import android.widget.Adapter;
+
+import java.util.ArrayList;
+
+/**
+ * common code for pie views
+ */
+public abstract class BasePieView implements PieMenu.PieView {
+
+ protected Adapter mAdapter;
+ private DataSetObserver mObserver;
+ protected ArrayList<View> mViews;
+
+ protected int mCurrent;
+ protected int mChildWidth;
+ protected int mChildHeight;
+ protected int mWidth;
+ protected int mHeight;
+ protected int mLeft;
+ protected int mTop;
+
+ public BasePieView() {
+ }
+
+ public void setAdapter(Adapter adapter) {
+ mAdapter = adapter;
+ if (adapter == null) {
+ if (mAdapter != null) {
+ mAdapter.unregisterDataSetObserver(mObserver);
+ }
+ mViews = null;
+ mCurrent = -1;
+ } else {
+ mObserver = new DataSetObserver() {
+ @Override
+ public void onChanged() {
+ buildViews();
+ }
+
+ @Override
+ public void onInvalidated() {
+ mViews.clear();
+ }
+ };
+ mAdapter.registerDataSetObserver(mObserver);
+ setCurrent(0);
+ }
+ }
+
+ public void setCurrent(int ix) {
+ mCurrent = ix;
+ }
+
+ public Adapter getAdapter() {
+ return mAdapter;
+ }
+
+ protected void buildViews() {
+ if (mAdapter != null) {
+ final int n = mAdapter.getCount();
+ if (mViews == null) {
+ mViews = new ArrayList<View>(n);
+ } else {
+ mViews.clear();
+ }
+ mChildWidth = 0;
+ mChildHeight = 0;
+ for (int i = 0; i < n; i++) {
+ View view = mAdapter.getView(i, null, null);
+ view.measure(View.MeasureSpec.UNSPECIFIED,
+ View.MeasureSpec.UNSPECIFIED);
+ mChildWidth = Math.max(mChildWidth, view.getMeasuredWidth());
+ mChildHeight = Math.max(mChildHeight, view.getMeasuredHeight());
+ mViews.add(view);
+ }
+ }
+ }
+
+ /**
+ * this will be called before the first draw call
+ * needs to set top, left, width, height
+ */
+ @Override
+ public abstract void layout(int anchorX, int anchorY, boolean left);
+
+ @Override
+ public abstract void draw(Canvas canvas);
+
+ protected void drawView(View view, Canvas canvas) {
+ final int state = canvas.save();
+ canvas.translate(view.getLeft(), view.getTop());
+ view.draw(canvas);
+ canvas.restoreToCount(state);
+ }
+
+ protected abstract int findChildAt(int y);
+
+ @Override
+ public boolean onTouchEvent(MotionEvent evt) {
+ int action = evt.getActionMasked();
+ int evtx = (int) evt.getX();
+ int evty = (int) evt.getY();
+ if ((evtx < mLeft) || (evtx >= mLeft + mWidth)
+ || (evty < mTop) || (evty >= mTop + mHeight)) {
+ return false;
+ }
+ switch (action) {
+ case MotionEvent.ACTION_MOVE:
+ View v = mViews.get(mCurrent);
+ setCurrent(Math.max(0, Math.min(mViews.size() -1,
+ findChildAt(evty))));
+ View v1 = mViews.get(mCurrent);
+ if (v != v1) {
+ v.setPressed(false);
+ v1.setPressed(true);
+ }
+ break;
+ case MotionEvent.ACTION_UP:
+ mViews.get(mCurrent).performClick();
+ mViews.get(mCurrent).setPressed(false);
+ break;
+ default:
+ break;
+ }
+ return true;
+ }
+
+}
diff --git a/src/com/android/browser/view/PieItem.java b/src/com/android/browser/view/PieItem.java
index c09dba2..84a6ac0 100644
--- a/src/com/android/browser/view/PieItem.java
+++ b/src/com/android/browser/view/PieItem.java
@@ -16,6 +16,8 @@
package com.android.browser.view;
+import com.android.browser.view.PieMenu.PieView;
+
import android.view.View;
/**
@@ -24,6 +26,7 @@ import android.view.View;
public class PieItem {
private View mView;
+ private PieView mPieView;
private int level;
private float start;
private float sweep;
@@ -36,6 +39,12 @@ public class PieItem {
this.level = level;
}
+ public PieItem(View view, int level, PieView sym) {
+ mView = view;
+ this.level = level;
+ mPieView = sym;
+ }
+
public void setSelected(boolean s) {
mSelected = s;
if (mView != null) {
@@ -74,8 +83,20 @@ public class PieItem {
return outer;
}
+ public boolean isPieView() {
+ return (mPieView != null);
+ }
+
public View getView() {
return mView;
}
+ public void setPieView(PieView sym) {
+ mPieView = sym;
+ }
+
+ public PieView getPieView() {
+ return mPieView;
+ }
+
}
diff --git a/src/com/android/browser/view/PieListView.java b/src/com/android/browser/view/PieListView.java
new file mode 100644
index 0000000..5fee51d
--- /dev/null
+++ b/src/com/android/browser/view/PieListView.java
@@ -0,0 +1,78 @@
+/*
+ * 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.browser.view;
+
+import com.android.browser.R;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.graphics.Paint;
+import android.view.View;
+
+/**
+ * shows views in a menu style list
+ */
+public class PieListView extends BasePieView {
+
+ private Paint mBgPaint;
+
+ public PieListView(Context ctx) {
+ mBgPaint = new Paint();
+ mBgPaint.setColor(ctx.getResources().getColor(R.color.qcMenuBackground));
+ }
+
+ /**
+ * this will be called before the first draw call
+ */
+ @Override
+ public void layout(int anchorX, int anchorY, boolean left) {
+ buildViews();
+ mWidth = mChildWidth;
+ mHeight = mChildHeight * mAdapter.getCount();
+ mLeft = anchorX + (left ? 0 : - mChildWidth);
+ mTop = anchorY - mHeight / 2;
+ if (mViews != null) {
+ layoutChildrenLinear();
+ }
+ }
+
+ protected void layoutChildrenLinear() {
+ final int n = mViews.size();
+ int top = mTop;
+ for (View view : mViews) {
+ view.layout(mLeft, top, mLeft + mChildWidth, top + mChildHeight);
+ top += mChildHeight;
+ }
+ }
+
+ @Override
+ public void draw(Canvas canvas) {
+ canvas.drawRect(mLeft, mTop, mLeft + mWidth, mTop + mHeight, mBgPaint);
+ if (mViews != null) {
+ for (View view : mViews) {
+ drawView(view, canvas);
+ }
+ }
+ }
+
+ @Override
+ protected int findChildAt(int y) {
+ final int ix = (y - mTop) * mViews.size() / mHeight;
+ return ix;
+ }
+
+}
diff --git a/src/com/android/browser/view/PieMenu.java b/src/com/android/browser/view/PieMenu.java
index 98c0f59..22ebd18 100644
--- a/src/com/android/browser/view/PieMenu.java
+++ b/src/com/android/browser/view/PieMenu.java
@@ -46,6 +46,19 @@ public class PieMenu extends FrameLayout {
public boolean onOpen();
}
+ /**
+ * A view like object that lives off of the pie menu
+ */
+ public interface PieView {
+
+ public void layout(int anchorX, int anchorY, boolean onleft);
+
+ public void draw(Canvas c);
+
+ public boolean onTouchEvent(MotionEvent evt);
+
+ }
+
private Point mCenter;
private int mRadius;
private int mRadiusInc;
@@ -57,6 +70,7 @@ public class PieMenu extends FrameLayout {
private List<PieItem> mItems;
private int mLevels;
private int[] mCounts;
+ private PieView mPieView = null;
private Drawable mBackground;
@@ -143,6 +157,7 @@ public class PieMenu extends FrameLayout {
}
if (!show) {
mCurrentItem = null;
+ mPieView = null;
}
invalidate();
}
@@ -159,6 +174,7 @@ public class PieMenu extends FrameLayout {
private void layoutPie() {
int inner = mRadius;
int outer = mRadius + mRadiusInc;
+ int radius = mRadius;
for (int i = 0; i < mLevels; i++) {
int level = i + 1;
float sweep = (float) Math.PI / (mCounts[level] + 1);
@@ -205,6 +221,9 @@ public class PieMenu extends FrameLayout {
for (PieItem item : mItems) {
drawItem(canvas, item);
}
+ if (mPieView != null) {
+ mPieView.draw(canvas);
+ }
}
}
@@ -236,10 +255,14 @@ public class PieMenu extends FrameLayout {
}
} else if (MotionEvent.ACTION_UP == action) {
if (mOpen) {
+ boolean handled = false;
+ if (mPieView != null) {
+ handled = mPieView.onTouchEvent(evt);
+ }
PieItem item = mCurrentItem;
deselect();
show(false);
- if (item != null) {
+ if (!handled && (item != null)) {
item.getView().performClick();
}
return true;
@@ -254,6 +277,13 @@ public class PieMenu extends FrameLayout {
boolean handled = false;
PointF polar = getPolar(x, y);
int maxr = mRadius + mLevels * mRadiusInc + 50;
+ if (mPieView != null) {
+ handled = mPieView.onTouchEvent(evt);
+ }
+ if (handled) {
+ invalidate();
+ return false;
+ }
if (polar.y > maxr) {
deselect();
show(false);
@@ -266,6 +296,13 @@ public class PieMenu extends FrameLayout {
PieItem item = findItem(polar);
if (mCurrentItem != item) {
onEnter(item);
+ if ((item != null) && item.isPieView()) {
+ int cx = item.getView().getLeft() + (onTheLeft()
+ ? item.getView().getWidth() : 0);
+ int cy = item.getView().getTop();
+ mPieView = item.getPieView();
+ layoutPieView(mPieView, cx, cy);
+ }
invalidate();
}
}
@@ -273,6 +310,10 @@ public class PieMenu extends FrameLayout {
return false;
}
+ private void layoutPieView(PieView pv, int x, int y) {
+ pv.layout(x, y, onTheLeft());
+ }
+
/**
* enter a slice for a view
* updates model only
@@ -287,6 +328,7 @@ public class PieMenu extends FrameLayout {
// clear up stack
playSoundEffect(SoundEffectConstants.CLICK);
item.setSelected(true);
+ mPieView = null;
}
mCurrentItem = item;
}
@@ -296,6 +338,7 @@ public class PieMenu extends FrameLayout {
mCurrentItem.setSelected(false);
}
mCurrentItem = null;
+ mPieView = null;
}
private PointF getPolar(float x, float y) {