116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount/* 216d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * Copyright (C) 2013 The Android Open Source Project 316d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * 416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * Licensed under the Apache License, Version 2.0 (the "License"); 516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * you may not use this file except in compliance with the License. 616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * You may obtain a copy of the License at 716d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * 816d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * http://www.apache.org/licenses/LICENSE-2.0 916d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * 1016d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * Unless required by applicable law or agreed to in writing, software 1116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * distributed under the License is distributed on an "AS IS" BASIS, 1216d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1316d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * See the License for the specific language governing permissions and 1416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * limitations under the License. 1516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount */ 1616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount 1716d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mountpackage android.animation; 1816d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount 1916d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount/** 2016d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * Abstract base class used convert type T to another type V. This 2116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * is necessary when the value types of in animation are different 2216d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * from the property type. 2316d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * @see PropertyValuesHolder#setConverter(TypeConverter) 2416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount */ 2516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mountpublic abstract class TypeConverter<T, V> { 2616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount private Class<T> mFromClass; 2716d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount private Class<V> mToClass; 2816d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount 2916d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount public TypeConverter(Class<T> fromClass, Class<V> toClass) { 3016d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount mFromClass = fromClass; 3116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount mToClass = toClass; 3216d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount } 3316d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount 3416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount /** 3516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * Returns the target converted type. Used by the animation system to determine 3616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * the proper setter function to call. 3716d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * @return The Class to convert the input to. 3816d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount */ 3916d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount Class<V> getTargetType() { 4016d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount return mToClass; 4116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount } 4216d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount 4316d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount /** 4416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * Returns the source conversion type. 4516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount */ 4616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount Class<T> getSourceType() { 4716d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount return mFromClass; 4816d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount } 4916d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount 5016d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount /** 5116d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * Converts a value from one type to another. 5216d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * @param value The Object to convert. 5316d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount * @return A value of type V, converted from <code>value</code>. 5416d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount */ 5516d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount public abstract V convert(T value); 5616d2c9cc6bd67131d9921fbc14a69d88f48f48caGeorge Mount} 57