The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2006 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 | |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 19 | import android.annotation.DrawableRes; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 20 | import android.content.Context; |
| 21 | import android.graphics.drawable.Drawable; |
| 22 | import android.net.Uri; |
| 23 | import android.util.AttributeSet; |
| 24 | |
Chet Haase | df10332 | 2016-08-25 08:47:20 -0700 | [diff] [blame] | 25 | /** |
| 26 | * {@link ViewSwitcher} that switches between two ImageViews when a new |
| 27 | * image is set on it. The views added to an ImageSwitcher must all be |
| 28 | * {@link ImageView ImageViews}. |
| 29 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 30 | public class ImageSwitcher extends ViewSwitcher |
| 31 | { |
Chet Haase | df10332 | 2016-08-25 08:47:20 -0700 | [diff] [blame] | 32 | /** |
| 33 | * Creates a new empty ImageSwitcher. |
| 34 | * |
| 35 | * @param context the application's environment |
| 36 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 37 | public ImageSwitcher(Context context) |
| 38 | { |
| 39 | super(context); |
| 40 | } |
Chet Haase | df10332 | 2016-08-25 08:47:20 -0700 | [diff] [blame] | 41 | |
| 42 | /** |
| 43 | * Creates a new empty ImageSwitcher for the given context and with the |
| 44 | * specified set attributes. |
| 45 | * |
| 46 | * @param context the application environment |
| 47 | * @param attrs a collection of attributes |
| 48 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 49 | public ImageSwitcher(Context context, AttributeSet attrs) { |
| 50 | super(context, attrs); |
| 51 | } |
| 52 | |
Chet Haase | df10332 | 2016-08-25 08:47:20 -0700 | [diff] [blame] | 53 | /** |
| 54 | * Sets a new image on the ImageSwitcher with the given resource id. |
| 55 | * This will set that image resource on the next ImageView in the switcher and will |
| 56 | * then switch to that view. |
| 57 | * |
| 58 | * @param resid a Drawable resource id |
| 59 | * |
| 60 | * @see ImageView#setImageResource(int) |
| 61 | */ |
Tor Norbye | 7b9c912 | 2013-05-30 16:48:33 -0700 | [diff] [blame] | 62 | public void setImageResource(@DrawableRes int resid) |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 63 | { |
| 64 | ImageView image = (ImageView)this.getNextView(); |
| 65 | image.setImageResource(resid); |
| 66 | showNext(); |
| 67 | } |
| 68 | |
Chet Haase | df10332 | 2016-08-25 08:47:20 -0700 | [diff] [blame] | 69 | /** |
| 70 | * Sets a new image on the ImageSwitcher with the given Uri. |
| 71 | * This will set that image on the next ImageView in the switcher and will |
| 72 | * then switch to that view. |
| 73 | * |
| 74 | * @param uri the Uri of an image |
| 75 | * |
| 76 | * @see ImageView#setImageURI(Uri) |
| 77 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 78 | public void setImageURI(Uri uri) |
| 79 | { |
| 80 | ImageView image = (ImageView)this.getNextView(); |
| 81 | image.setImageURI(uri); |
| 82 | showNext(); |
| 83 | } |
| 84 | |
Chet Haase | df10332 | 2016-08-25 08:47:20 -0700 | [diff] [blame] | 85 | /** |
| 86 | * Sets a new drawable on the ImageSwitcher. |
| 87 | * This will set that drawable on the next ImageView in the switcher and will |
| 88 | * then switch to that view. |
| 89 | * |
| 90 | * @param drawable the drawable to be set or {@code null} to clear the content |
| 91 | * |
| 92 | * @see ImageView#setImageDrawable(Drawable) |
| 93 | */ |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 94 | public void setImageDrawable(Drawable drawable) |
| 95 | { |
| 96 | ImageView image = (ImageView)this.getNextView(); |
| 97 | image.setImageDrawable(drawable); |
| 98 | showNext(); |
| 99 | } |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 100 | |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 101 | @Override |
Dianne Hackborn | a7bb6fb | 2015-02-03 18:13:40 -0800 | [diff] [blame] | 102 | public CharSequence getAccessibilityClassName() { |
| 103 | return ImageSwitcher.class.getName(); |
Svetoslav Ganov | 8a78fd4 | 2012-01-17 14:36:46 -0800 | [diff] [blame] | 104 | } |
| 105 | } |