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 19 import android.annotation.UnsupportedAppUsage; 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 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 38 @Widget 39 public class ZoomControls extends LinearLayout { 40 41 @UnsupportedAppUsage 42 private final ZoomButton mZoomIn; 43 @UnsupportedAppUsage 44 private final ZoomButton mZoomOut; 45 ZoomControls(Context context)46 public ZoomControls(Context context) { 47 this(context, null); 48 } 49 ZoomControls(Context context, AttributeSet attrs)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 setOnZoomInClickListener(OnClickListener listener)63 public void setOnZoomInClickListener(OnClickListener listener) { 64 mZoomIn.setOnClickListener(listener); 65 } 66 setOnZoomOutClickListener(OnClickListener listener)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 */ setZoomSpeed(long speed)75 public void setZoomSpeed(long speed) { 76 mZoomIn.setZoomSpeed(speed); 77 mZoomOut.setZoomSpeed(speed); 78 } 79 80 @Override onTouchEvent(MotionEvent event)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 show()89 public void show() { 90 fade(View.VISIBLE, 0.0f, 1.0f); 91 } 92 hide()93 public void hide() { 94 fade(View.GONE, 1.0f, 0.0f); 95 } 96 fade(int visibility, float startAlpha, float endAlpha)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 setIsZoomInEnabled(boolean isEnabled)104 public void setIsZoomInEnabled(boolean isEnabled) { 105 mZoomIn.setEnabled(isEnabled); 106 } 107 setIsZoomOutEnabled(boolean isEnabled)108 public void setIsZoomOutEnabled(boolean isEnabled) { 109 mZoomOut.setEnabled(isEnabled); 110 } 111 112 @Override hasFocus()113 public boolean hasFocus() { 114 return mZoomIn.hasFocus() || mZoomOut.hasFocus(); 115 } 116 117 @Override getAccessibilityClassName()118 public CharSequence getAccessibilityClassName() { 119 return ZoomControls.class.getName(); 120 } 121 } 122