blob: eb8d493473216a93cbfb2caac025f847040aa7cd [file] [log] [blame]
The Android Open Source Project0c908882009-03-03 19:32:16 -08001/*
2 * Copyright (C) 2008 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;
18
19import android.content.Context;
20import android.util.AttributeSet;
21import android.view.Gravity;
22import android.widget.ImageView;
23import android.widget.LinearLayout;
24
25import java.util.Map;
26
27/**
28 * Displays a series of dots. The selected one is highlighted.
29 * No animations yet. Nothing fancy.
30 */
31class Dots extends LinearLayout {
32
33 private static final int MAX_DOTS = 8;
34 private int mSelected = -1;
35
36 public Dots(Context context) {
37 this(context, null);
38 }
39
40 public Dots(Context context, AttributeSet attrs) {
41 super(context, attrs);
42
43 setGravity(Gravity.CENTER);
44 setPadding(0, 4, 0, 4);
45
46 LayoutParams lp =
47 new LayoutParams(LayoutParams.WRAP_CONTENT,
48 LayoutParams.WRAP_CONTENT);
49
50 for (int i = 0; i < MAX_DOTS; i++) {
51 ImageView dotView = new ImageView(mContext);
52 dotView.setImageResource(R.drawable.page_indicator_unselected2);
53 addView(dotView, lp);
54 }
55 }
56
57 /**
58 * @param dotCount if less than 1 or greater than MAX_DOTS, Dots
59 * disappears
60 */
61 public void setDotCount(int dotCount) {
62 if (dotCount > 1 && dotCount <= MAX_DOTS) {
63 setVisibility(VISIBLE);
64 for (int i = 0; i < MAX_DOTS; i++) {
65 getChildAt(i).setVisibility(i < dotCount? VISIBLE : GONE);
66 }
67 } else {
68 setVisibility(GONE);
69 }
70 }
71
72 public void setSelected(int index) {
73 if (index < 0 || index >= MAX_DOTS) return;
74
75 if (mSelected >= 0) {
76 // Unselect old
77 ((ImageView)getChildAt(mSelected)).setImageResource(
78 R.drawable.page_indicator_unselected2);
79 }
80 ((ImageView)getChildAt(index)).setImageResource(R.drawable.page_indicator);
81 mSelected = index;
82 }
83}