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