1/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.browser.view;
18
19import com.android.browser.R;
20
21import android.content.Context;
22import android.graphics.Canvas;
23import android.graphics.Paint;
24import android.view.View;
25
26/**
27 * shows views in a menu style list
28 */
29public class PieListView extends BasePieView {
30
31    private Paint mBgPaint;
32
33    public PieListView(Context ctx) {
34        mBgPaint = new Paint();
35        mBgPaint.setColor(ctx.getResources().getColor(R.color.qcMenuBackground));
36    }
37
38    /**
39     * this will be called before the first draw call
40     */
41    @Override
42    public void layout(int anchorX, int anchorY, boolean left, float angle) {
43        super.layout(anchorX, anchorY, left, angle);
44        buildViews();
45        mWidth = mChildWidth;
46        mHeight = mChildHeight * mAdapter.getCount();
47        mLeft = anchorX + (left ? 0 : - mChildWidth);
48        mTop = anchorY - mHeight / 2;
49        if (mViews != null) {
50            layoutChildrenLinear();
51        }
52    }
53
54    protected void layoutChildrenLinear() {
55        final int n = mViews.size();
56        int top = mTop;
57        for (View view : mViews) {
58            view.layout(mLeft, top, mLeft + mChildWidth, top + mChildHeight);
59            top += mChildHeight;
60        }
61    }
62
63    @Override
64    public void draw(Canvas canvas) {
65        canvas.drawRect(mLeft, mTop, mLeft + mWidth, mTop + mHeight, mBgPaint);
66        if (mViews != null) {
67            for (View view : mViews) {
68                drawView(view, canvas);
69            }
70        }
71    }
72
73    @Override
74    protected int findChildAt(int y) {
75        final int ix = (y - mTop) * mViews.size() / mHeight;
76        return ix;
77    }
78
79}
80