11acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb/* 21acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb * Copyright (C) 2011 The Android Open Source Project 31acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb * 41acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb * Licensed under the Apache License, Version 2.0 (the "License"); 51acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb * you may not use this file except in compliance with the License. 61acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb * You may obtain a copy of the License at 71acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb * 81acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb * http://www.apache.org/licenses/LICENSE-2.0 91acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb * 101acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb * Unless required by applicable law or agreed to in writing, software 111acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb * distributed under the License is distributed on an "AS IS" BASIS, 121acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb * See the License for the specific language governing permissions and 141acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb * limitations under the License. 151acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb */ 161acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb 171acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolbpackage com.android.browser.view; 181acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb 191acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolbimport com.android.browser.R; 201acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb 211acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolbimport android.content.Context; 221acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolbimport android.graphics.Canvas; 231acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolbimport android.graphics.Paint; 241acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolbimport android.view.View; 251acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb 261acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb/** 271acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb * shows views in a menu style list 281acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb */ 291acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolbpublic class PieListView extends BasePieView { 301acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb 311acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb private Paint mBgPaint; 321acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb 331acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb public PieListView(Context ctx) { 341acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb mBgPaint = new Paint(); 351acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb mBgPaint.setColor(ctx.getResources().getColor(R.color.qcMenuBackground)); 361acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb } 371acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb 381acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb /** 391acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb * this will be called before the first draw call 401acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb */ 411acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb @Override 42a4befac241ec69791fd30e11355ed3dc10d7fb37Michael Kolb public void layout(int anchorX, int anchorY, boolean left, float angle, 43a4befac241ec69791fd30e11355ed3dc10d7fb37Michael Kolb int pHeight) { 44a4befac241ec69791fd30e11355ed3dc10d7fb37Michael Kolb super.layout(anchorX, anchorY, left, angle, pHeight); 451acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb buildViews(); 461acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb mWidth = mChildWidth; 471acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb mHeight = mChildHeight * mAdapter.getCount(); 481acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb mLeft = anchorX + (left ? 0 : - mChildWidth); 49a4befac241ec69791fd30e11355ed3dc10d7fb37Michael Kolb mTop = Math.max(anchorY - mHeight / 2, 0); 50a4befac241ec69791fd30e11355ed3dc10d7fb37Michael Kolb if (mTop + mHeight > pHeight) { 51a4befac241ec69791fd30e11355ed3dc10d7fb37Michael Kolb mTop = pHeight - mHeight; 52a4befac241ec69791fd30e11355ed3dc10d7fb37Michael Kolb } 531acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb if (mViews != null) { 541acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb layoutChildrenLinear(); 551acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb } 561acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb } 571acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb 581acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb protected void layoutChildrenLinear() { 591acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb final int n = mViews.size(); 601acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb int top = mTop; 611acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb for (View view : mViews) { 621acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb view.layout(mLeft, top, mLeft + mChildWidth, top + mChildHeight); 631acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb top += mChildHeight; 641acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb } 651acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb } 661acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb 671acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb @Override 681acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb public void draw(Canvas canvas) { 691acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb canvas.drawRect(mLeft, mTop, mLeft + mWidth, mTop + mHeight, mBgPaint); 701acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb if (mViews != null) { 711acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb for (View view : mViews) { 721acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb drawView(view, canvas); 731acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb } 741acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb } 751acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb } 761acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb 771acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb @Override 781acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb protected int findChildAt(int y) { 791acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb final int ix = (y - mTop) * mViews.size() / mHeight; 801acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb return ix; 811acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb } 821acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb 831acef69ffc079d1bc029ff7eb1f5043f7efd7f36Michael Kolb} 84