blob: a12aee5d4bb3aefdd5fcf5797d2ff7b54d7e6ae4 [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -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 android.widget;
18
19import android.annotation.Widget;
20import android.content.Context;
21import android.util.AttributeSet;
22import android.view.LayoutInflater;
23import android.view.MotionEvent;
24import android.view.View;
25import android.view.animation.AlphaAnimation;
26
27import com.android.internal.R;
28
29
30/**
31 * The {@code ZoomControls} class displays a simple set of controls used for zooming and
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -070032 * provides callbacks to register for events. */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080033@Widget
34public class ZoomControls extends LinearLayout {
35
36 private final ZoomButton mZoomIn;
37 private final ZoomButton mZoomOut;
38
39 public ZoomControls(Context context) {
40 this(context, null);
41 }
42
43 public ZoomControls(Context context, AttributeSet attrs) {
44 super(context, attrs);
45 setFocusable(false);
46
47 LayoutInflater inflater = (LayoutInflater) context
48 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
49 inflater.inflate(R.layout.zoom_controls, this, // we are the parent
50 true);
51
52 mZoomIn = (ZoomButton) findViewById(R.id.zoomIn);
53 mZoomOut = (ZoomButton) findViewById(R.id.zoomOut);
54 }
55
56 public void setOnZoomInClickListener(OnClickListener listener) {
57 mZoomIn.setOnClickListener(listener);
58 }
59
60 public void setOnZoomOutClickListener(OnClickListener listener) {
61 mZoomOut.setOnClickListener(listener);
62 }
63
64 /*
65 * Sets how fast you get zoom events when the user holds down the
66 * zoom in/out buttons.
67 */
68 public void setZoomSpeed(long speed) {
69 mZoomIn.setZoomSpeed(speed);
70 mZoomOut.setZoomSpeed(speed);
71 }
72
73 @Override
74 public boolean onTouchEvent(MotionEvent event) {
75
76 /* Consume all touch events so they don't get dispatched to the view
77 * beneath this view.
78 */
79 return true;
80 }
81
82 public void show() {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -070083 fade(View.VISIBLE, 0.0f, 1.0f);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080084 }
85
86 public void hide() {
87 fade(View.GONE, 1.0f, 0.0f);
88 }
89
90 private void fade(int visibility, float startAlpha, float endAlpha) {
91 AlphaAnimation anim = new AlphaAnimation(startAlpha, endAlpha);
92 anim.setDuration(500);
93 startAnimation(anim);
94 setVisibility(visibility);
95 }
96
97 public void setIsZoomInEnabled(boolean isEnabled) {
98 mZoomIn.setEnabled(isEnabled);
99 }
100
101 public void setIsZoomOutEnabled(boolean isEnabled) {
102 mZoomOut.setEnabled(isEnabled);
103 }
104
105 @Override
106 public boolean hasFocus() {
107 return mZoomIn.hasFocus() || mZoomOut.hasFocus();
108 }
109}