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