Home | History | Annotate | Download | only in view
      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 
     17 package com.android.browser.view;
     18 
     19 import com.android.browser.R;
     20 
     21 import android.content.Context;
     22 import android.graphics.Canvas;
     23 import android.graphics.Paint;
     24 import android.view.View;
     25 
     26 /**
     27  * shows views in a menu style list
     28  */
     29 public 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             int pHeight) {
     44         super.layout(anchorX, anchorY, left, angle, pHeight);
     45         buildViews();
     46         mWidth = mChildWidth;
     47         mHeight = mChildHeight * mAdapter.getCount();
     48         mLeft = anchorX + (left ? 0 : - mChildWidth);
     49         mTop = Math.max(anchorY - mHeight / 2, 0);
     50         if (mTop + mHeight > pHeight) {
     51             mTop = pHeight - mHeight;
     52         }
     53         if (mViews != null) {
     54             layoutChildrenLinear();
     55         }
     56     }
     57 
     58     protected void layoutChildrenLinear() {
     59         final int n = mViews.size();
     60         int top = mTop;
     61         for (View view : mViews) {
     62             view.layout(mLeft, top, mLeft + mChildWidth, top + mChildHeight);
     63             top += mChildHeight;
     64         }
     65     }
     66 
     67     @Override
     68     public void draw(Canvas canvas) {
     69         canvas.drawRect(mLeft, mTop, mLeft + mWidth, mTop + mHeight, mBgPaint);
     70         if (mViews != null) {
     71             for (View view : mViews) {
     72                 drawView(view, canvas);
     73             }
     74         }
     75     }
     76 
     77     @Override
     78     protected int findChildAt(int y) {
     79         final int ix = (y - mTop) * mViews.size() / mHeight;
     80         return ix;
     81     }
     82 
     83 }
     84