blob: 183566add3745147061a150dfa81e5f2cb7bbf13 [file] [log] [blame]
Michael Kolbc7485ae2010-09-03 10:10:58 -07001
2/*
3 * Copyright (C) 2010 The Android Open Source Project
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17package com.android.browser;
18
19import android.content.Context;
20import android.graphics.Canvas;
21import android.graphics.Rect;
22import android.graphics.drawable.Drawable;
23import android.util.AttributeSet;
24import android.widget.ImageView;
25
26/**
27 *
28 */
29public class PageProgressView extends ImageView {
30
31 private int mProgress;
32 private int mMaxProgress;
33 private Rect mBounds;
34
35 /**
36 * @param context
37 * @param attrs
38 * @param defStyle
39 */
40 public PageProgressView(Context context, AttributeSet attrs, int defStyle) {
41 super(context, attrs, defStyle);
42 init(context);
43 }
44
45 /**
46 * @param context
47 * @param attrs
48 */
49 public PageProgressView(Context context, AttributeSet attrs) {
50 super(context, attrs);
51 init(context);
52 }
53
54 /**
55 * @param context
56 */
57 public PageProgressView(Context context) {
58 super(context);
59 init(context);
60 }
61
62 private void init(Context ctx) {
63 mMaxProgress = 10000;
64 mBounds = new Rect(0,0,0,0);
65 mProgress = 0;
66 }
67
68 @Override
69 public void onLayout(boolean f, int l, int t, int r, int b) {
70 mBounds.left = 0;
71 mBounds.right = (r - l) * mProgress / mMaxProgress;
72 mBounds.top = 0;
73 mBounds.bottom = b-t;
74 }
75
76 void setMaxProgress(int max) {
77 mMaxProgress = max;
78 }
79
80 void setProgress(int progress) {
81 mProgress = progress;
82 mBounds.right = getWidth()*mProgress/mMaxProgress;
83 invalidate();
84 }
85
86 @Override
87 public void onDraw(Canvas canvas) {
88// super.onDraw(canvas);
89 Drawable d = getDrawable();
90 d.setBounds(mBounds);
91 d.draw(canvas);
92 }
93
94}