blob: 112fcc313366c36025dd99c09c5166c6c4325bdb [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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
17package android.widget;
18
Tor Norbye7b9c9122013-05-30 16:48:33 -070019import android.annotation.DrawableRes;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080020import android.content.Context;
21import android.graphics.drawable.Drawable;
22import android.net.Uri;
23import android.util.AttributeSet;
24
Chet Haasedf103322016-08-25 08:47:20 -070025/**
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 Project9066cfe2009-03-03 19:31:44 -080030public class ImageSwitcher extends ViewSwitcher
31{
Chet Haasedf103322016-08-25 08:47:20 -070032 /**
33 * Creates a new empty ImageSwitcher.
34 *
35 * @param context the application's environment
36 */
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080037 public ImageSwitcher(Context context)
38 {
39 super(context);
40 }
Chet Haasedf103322016-08-25 08:47:20 -070041
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 Project9066cfe2009-03-03 19:31:44 -080049 public ImageSwitcher(Context context, AttributeSet attrs) {
50 super(context, attrs);
51 }
52
Chet Haasedf103322016-08-25 08:47:20 -070053 /**
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 Norbye7b9c9122013-05-30 16:48:33 -070062 public void setImageResource(@DrawableRes int resid)
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080063 {
64 ImageView image = (ImageView)this.getNextView();
65 image.setImageResource(resid);
66 showNext();
67 }
68
Chet Haasedf103322016-08-25 08:47:20 -070069 /**
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 Project9066cfe2009-03-03 19:31:44 -080078 public void setImageURI(Uri uri)
79 {
80 ImageView image = (ImageView)this.getNextView();
81 image.setImageURI(uri);
82 showNext();
83 }
84
Chet Haasedf103322016-08-25 08:47:20 -070085 /**
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 Project9066cfe2009-03-03 19:31:44 -080094 public void setImageDrawable(Drawable drawable)
95 {
96 ImageView image = (ImageView)this.getNextView();
97 image.setImageDrawable(drawable);
98 showNext();
99 }
The Android Open Source Project9066cfe2009-03-03 19:31:44 -0800100
Svetoslav Ganov8a78fd42012-01-17 14:36:46 -0800101 @Override
Dianne Hackborna7bb6fb2015-02-03 18:13:40 -0800102 public CharSequence getAccessibilityClassName() {
103 return ImageSwitcher.class.getName();
Svetoslav Ganov8a78fd42012-01-17 14:36:46 -0800104 }
105}