PageRenderTime 26ms CodeModel.GetById 15ms app.highlight 6ms RepoModel.GetById 2ms app.codeStats 0ms

/WebVox/src/com/marvin/webvox/Dots.java

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