blob: 9ead2ad090f4900d46f2af5dcb3ffd62ca08aebb [file] [log] [blame]
George Mount16d2c9c2013-09-17 09:07:48 -07001/*
2 * Copyright (C) 2013 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.animation;
18
19/**
20 * Abstract base class used convert type T to another type V. This
21 * is necessary when the value types of in animation are different
22 * from the property type.
23 * @see PropertyValuesHolder#setConverter(TypeConverter)
24 */
25public abstract class TypeConverter<T, V> {
26 private Class<T> mFromClass;
27 private Class<V> mToClass;
28
29 public TypeConverter(Class<T> fromClass, Class<V> toClass) {
30 mFromClass = fromClass;
31 mToClass = toClass;
32 }
33
34 /**
35 * Returns the target converted type. Used by the animation system to determine
36 * the proper setter function to call.
37 * @return The Class to convert the input to.
38 */
39 Class<V> getTargetType() {
40 return mToClass;
41 }
42
43 /**
44 * Returns the source conversion type.
45 */
46 Class<T> getSourceType() {
47 return mFromClass;
48 }
49
50 /**
51 * Converts a value from one type to another.
52 * @param value The Object to convert.
53 * @return A value of type V, converted from <code>value</code>.
54 */
55 public abstract V convert(T value);
George Mount16d2c9c2013-09-17 09:07:48 -070056}