Sets the vertical/horizontal location of this view relative to its top/left position. This effectively positions the object post-layout, in addition to wherever the object’s layout placed it.
/** * This method is called with the elapsed fraction of the animation during every * animation frame. This function turns the elapsed fraction into an interpolated fraction * and then into an animated value (from the evaluator. The function is called mostly during * animation updates, but it is also called when the <code>end()</code> * function is called, to set the final value on the property. * * <p>Overrides of this method must call the superclass to perform the calculation * of the animated value.</p> * * @param fraction The elapsed fraction of the animation. */ @CallSuper @Override voidanimateValue(float fraction) { finalObjecttarget= getTarget(); if (mTarget != null && target == null) { // We lost the target reference, cancel and clean up. Note: we allow null target if the /// target has never been set. cancel(); return; }
super.animateValue(fraction); intnumValues= mValues.length; for (inti=0; i < numValues; ++i) { mValues[i].setAnimatedValue(target); } }
/** * Internal function to set the value on the target object, using the setter set up * earlier on this PropertyValuesHolder object. This function is called by ObjectAnimator * to handle turning the value calculated by ValueAnimator into a value set on the object * according to the name of the property. * @param target The target object on which the value is set */ voidsetAnimatedValue(Object target) { if (mProperty != null) { mProperty.set(target, getAnimatedValue()); } if (mSetter != null) { try { mTmpValueArray[0] = getAnimatedValue(); mSetter.invoke(target, mTmpValueArray); } catch (InvocationTargetException e) { Log.e("PropertyValuesHolder", e.toString()); } catch (IllegalAccessException e) { Log.e("PropertyValuesHolder", e.toString()); } } }
/** * Utility function to get the setter from targetClass * @param targetClass The Class on which the requested method should exist. */ voidsetupSetter(Class targetClass) { Class<?> propertyType = mConverter == null ? mValueType : mConverter.getTargetType(); mSetter = setupSetterOrGetter(targetClass, sSetterPropertyMap, "set", propertyType); }
/** * Returns the setter or getter requested. This utility function checks whether the * requested method exists in the propertyMapMap cache. If not, it calls another * utility function to request the Method from the targetClass directly. * @param targetClass The Class on which the requested method should exist. * @param propertyMapMap The cache of setters/getters derived so far. * @param prefix "set" or "get", for the setter or getter. * @param valueType The type of parameter passed into the method (null for getter). * @return Method the method associated with mPropertyName. */ private Method setupSetterOrGetter(Class targetClass, HashMap<Class, HashMap<String, Method>> propertyMapMap, String prefix, Class valueType) { MethodsetterOrGetter=null; synchronized(propertyMapMap) { // Have to lock property map prior to reading it, to guard against // another thread putting something in there after we've checked it // but before we've added an entry to it HashMap<String, Method> propertyMap = propertyMapMap.get(targetClass); booleanwasInMap=false; if (propertyMap != null) { wasInMap = propertyMap.containsKey(mPropertyName); if (wasInMap) { setterOrGetter = propertyMap.get(mPropertyName); } } if (!wasInMap) { setterOrGetter = getPropertyFunction(targetClass, prefix, valueType); if (propertyMap == null) { propertyMap = newHashMap<String, Method>(); propertyMapMap.put(targetClass, propertyMap); } propertyMap.put(mPropertyName, setterOrGetter); } } return setterOrGetter; }
/** * Determine the setter or getter function using the JavaBeans convention of setFoo or * getFoo for a property named 'foo'. This function figures out what the name of the * function should be and uses reflection to find the Method with that name on the * target object. * * @param targetClass The class to search for the method * @param prefix "set" or "get", depending on whether we need a setter or getter. * @param valueType The type of the parameter (in the case of a setter). This type * is derived from the values set on this PropertyValuesHolder. This type is used as * a first guess at the parameter type, but we check for methods with several different * types to avoid problems with slight mis-matches between supplied values and actual * value types used on the setter. * @return Method the method associated with mPropertyName. */ private Method getPropertyFunction(Class targetClass, String prefix, Class valueType) { // TODO: faster implementation... MethodreturnVal=null; StringmethodName= getMethodName(prefix, mPropertyName); Class args[] = null; if (valueType == null) { try { returnVal = targetClass.getMethod(methodName, args); } catch (NoSuchMethodException e) { // Swallow the error, log it later } } else { args = newClass[1]; Class typeVariants[]; if (valueType.equals(Float.class)) { typeVariants = FLOAT_VARIANTS; } elseif (valueType.equals(Integer.class)) { typeVariants = INTEGER_VARIANTS; } elseif (valueType.equals(Double.class)) { typeVariants = DOUBLE_VARIANTS; } else { typeVariants = newClass[1]; typeVariants[0] = valueType; } for (Class typeVariant : typeVariants) { args[0] = typeVariant; try { returnVal = targetClass.getMethod(methodName, args); if (mConverter == null) { // change the value type to suit mValueType = typeVariant; } return returnVal; } catch (NoSuchMethodException e) { // Swallow the error and keep trying other variants } } // If we got here, then no appropriate function was found }
if (returnVal == null) { Log.w("PropertyValuesHolder", "Method " + getMethodName(prefix, mPropertyName) + "() with type " + valueType + " not found on target class " + targetClass); }