The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
| 17 | package android.widget; |
| 18 | |
Mathew Inwood | 978c6e2 | 2018-08-21 15:58:55 +0100 | [diff] [blame] | 19 | import android.annotation.UnsupportedAppUsage; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import android.annotation.Widget; |
| 21 | import android.content.Context; |
| 22 | import android.util.AttributeSet; |
| 23 | import android.view.LayoutInflater; |
| 24 | import android.view.MotionEvent; |
| 25 | import android.view.View; |
| 26 | import android.view.animation.AlphaAnimation; |
| 27 | |
| 28 | import com.android.internal.R; |
| 29 | |
| 30 | |
| 31 | /** |
| 32 | * The {@code ZoomControls} class displays a simple set of controls used for zooming and |
Aurimas Liutikas | f3fb34c | 2019-02-27 16:52:33 -0800 | [diff] [blame] | 33 | * 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 Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 38 | @Widget |
| 39 | public class ZoomControls extends LinearLayout { |
| 40 | |
Mathew Inwood | 978c6e2 | 2018-08-21 15:58:55 +0100 | [diff] [blame] | 41 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 42 | private final ZoomButton mZoomIn; |
Mathew Inwood | 978c6e2 | 2018-08-21 15:58:55 +0100 | [diff] [blame] | 43 | @UnsupportedAppUsage |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 44 | 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 Project | ba87e3e | 2009-03-13 13:04:22 -0700 | [diff] [blame] | 90 | fade(View.VISIBLE, 0.0f, 1.0f); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 91 | } |
| 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 Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 116 | |
| 117 | @Override |
Dianne Hackborn | a7bb6fb | 2015-02-03 18:13:40 -0800 | [diff] [blame] | 118 | public CharSequence getAccessibilityClassName() { |
| 119 | return ZoomControls.class.getName(); |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 120 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 121 | } |