2 * Copyright (C) 2008 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package com.android.browser;
19 import android.content.Context;
20 import android.util.AttributeSet;
21 import android.view.Gravity;
22 import android.widget.ImageView;
23 import android.widget.LinearLayout;
28 * Displays a series of dots. The selected one is highlighted.
29 * No animations yet. Nothing fancy.
31 class Dots extends LinearLayout {
33 private static final int MAX_DOTS = 8;
34 private int mSelected = -1;
36 public Dots(Context context) {
40 public Dots(Context context, AttributeSet attrs) {
41 super(context, attrs);
43 setGravity(Gravity.CENTER);
44 setPadding(0, 4, 0, 4);
47 new LayoutParams(LayoutParams.WRAP_CONTENT,
48 LayoutParams.WRAP_CONTENT);
50 for (int i = 0; i < MAX_DOTS; i++) {
51 ImageView dotView = new ImageView(mContext);
52 dotView.setImageResource(R.drawable.page_indicator_unselected2);
58 * @param dotCount if less than 1 or greater than MAX_DOTS, Dots
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);
72 public void setSelected(int index) {
73 if (index < 0 || index >= MAX_DOTS) return;
77 ((ImageView)getChildAt(mSelected)).setImageResource(
78 R.drawable.page_indicator_unselected2);
80 ((ImageView)getChildAt(index)).setImageResource(R.drawable.page_indicator);