blob: 7a5b7e8058f39dd4b8526d10d2998cb2f2d2f717 [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
Aurimas Liutikasf3fb34c2019-02-27 16:52:33 -080033 * provides callbacks to register for events.
34 * @deprecated This functionality and UI is better handled with custom views and layouts
35 * rather than a dedicated zoom-control widget
36 */
37@Deprecated
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080038@Widget
39public class ZoomControls extends LinearLayout {
40
Mathew Inwood978c6e22018-08-21 15:58:55 +010041 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080042 private final ZoomButton mZoomIn;
Mathew Inwood978c6e22018-08-21 15:58:55 +010043 @UnsupportedAppUsage
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044 private final ZoomButton mZoomOut;
45
46 public ZoomControls(Context context) {
47 this(context, null);
48 }
49
50 public ZoomControls(Context context, AttributeSet attrs) {
51 super(context, attrs);
52 setFocusable(false);
53
54 LayoutInflater inflater = (LayoutInflater) context
55 .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
56 inflater.inflate(R.layout.zoom_controls, this, // we are the parent
57 true);
58
59 mZoomIn = (ZoomButton) findViewById(R.id.zoomIn);
60 mZoomOut = (ZoomButton) findViewById(R.id.zoomOut);
61 }
62
63 public void setOnZoomInClickListener(OnClickListener listener) {
64 mZoomIn.setOnClickListener(listener);
65 }
66
67 public void setOnZoomOutClickListener(OnClickListener listener) {
68 mZoomOut.setOnClickListener(listener);
69 }
70
71 /*
72 * Sets how fast you get zoom events when the user holds down the
73 * zoom in/out buttons.
74 */
75 public void setZoomSpeed(long speed) {
76 mZoomIn.setZoomSpeed(speed);
77 mZoomOut.setZoomSpeed(speed);
78 }
79
80 @Override
81 public boolean onTouchEvent(MotionEvent event) {
82
83 /* Consume all touch events so they don't get dispatched to the view
84 * beneath this view.
85 */
86 return true;
87 }
88
89 public void show() {
The Android Open Source Projectba87e3e2009-03-13 13:04:22 -070090 fade(View.VISIBLE, 0.0f, 1.0f);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080091 }
92
93 public void hide() {
94 fade(View.GONE, 1.0f, 0.0f);
95 }
96
97 private void fade(int visibility, float startAlpha, float endAlpha) {
98 AlphaAnimation anim = new AlphaAnimation(startAlpha, endAlpha);
99 anim.setDuration(500);
100 startAnimation(anim);
101 setVisibility(visibility);
102 }
103
104 public void setIsZoomInEnabled(boolean isEnabled) {
105 mZoomIn.setEnabled(isEnabled);
106 }
107
108 public void setIsZoomOutEnabled(boolean isEnabled) {
109 mZoomOut.setEnabled(isEnabled);
110 }
111
112 @Override
113 public boolean hasFocus() {
114 return mZoomIn.hasFocus() || mZoomOut.hasFocus();
115 }
Svetoslav Ganov8a78fd42012-01-17 14:36:46 -0800116
117 @Override
Dianne Hackborna7bb6fb2015-02-03 18:13:40 -0800118 public CharSequence getAccessibilityClassName() {
119 return ZoomControls.class.getName();
Svetoslav Ganov8a78fd42012-01-17 14:36:46 -0800120 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800121}