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 android.widget;
19 import android.annotation.Widget;
20 import android.content.Context;
21 import android.util.AttributeSet;
22 import android.view.LayoutInflater;
23 import android.view.MotionEvent;
24 import android.view.View;
25 import android.view.animation.AlphaAnimation;
27 import com.android.internal.R;
31 * The {@code ZoomControls} class displays a simple set of controls used for zooming and
32 * provides callbacks to register for events. */
34 public class ZoomControls extends LinearLayout {
36 private final ZoomButton mZoomIn;
37 private final ZoomButton mZoomOut;
39 public ZoomControls(Context context) {
43 public ZoomControls(Context context, AttributeSet attrs) {
44 super(context, attrs);
47 LayoutInflater inflater = (LayoutInflater) context
48 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
49 inflater.inflate(R.layout.zoom_controls, this, // we are the parent
52 mZoomIn = (ZoomButton) findViewById(R.id.zoomIn);
53 mZoomOut = (ZoomButton) findViewById(R.id.zoomOut);
56 public void setOnZoomInClickListener(OnClickListener listener) {
57 mZoomIn.setOnClickListener(listener);
60 public void setOnZoomOutClickListener(OnClickListener listener) {
61 mZoomOut.setOnClickListener(listener);
65 * Sets how fast you get zoom events when the user holds down the
66 * zoom in/out buttons.
68 public void setZoomSpeed(long speed) {
69 mZoomIn.setZoomSpeed(speed);
70 mZoomOut.setZoomSpeed(speed);
74 public boolean onTouchEvent(MotionEvent event) {
76 /* Consume all touch events so they don't get dispatched to the view
83 fade(View.VISIBLE, 0.0f, 1.0f);
87 fade(View.GONE, 1.0f, 0.0f);
90 private void fade(int visibility, float startAlpha, float endAlpha) {
91 AlphaAnimation anim = new AlphaAnimation(startAlpha, endAlpha);
92 anim.setDuration(500);
94 setVisibility(visibility);
97 public void setIsZoomInEnabled(boolean isEnabled) {
98 mZoomIn.setEnabled(isEnabled);
101 public void setIsZoomOutEnabled(boolean isEnabled) {
102 mZoomOut.setEnabled(isEnabled);
106 public boolean hasFocus() {
107 return mZoomIn.hasFocus() || mZoomOut.hasFocus();