android.util.Property Java Examples

The following examples show how to use android.util.Property. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: Noyze   Author: Tombarr   File: SettingsHelper.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves the value stored in {@link android.content.SharedPreferences} for a
 * given {@link android.util.Property} associated with a VolumePanel.
 * @return The given value, {@code defVal} if none was set, or null is the
 * value could not be retrieved.
 * @throws ClassCastException If a type error occurred between SP and Property.
 */
@SuppressWarnings("unchecked")
public <T, E> E getProperty(Class<T> clazz, Property<T, E> property, E defVal)
        throws ClassCastException {
    Class<E> type = property.getType();
    String name = getName(clazz, property);

    // Handle all types supported by SharedPreferences.
    if (type.equals(Integer.TYPE) || type.equals(Integer.class))
        return (E) Integer.valueOf(mPreferences.getInt(name, (Integer) defVal));
    else if (type.equals(String.class) || type.equals(CharSequence.class))
        return (E) mPreferences.getString(name, ((defVal == null) ? (String) defVal : defVal.toString()));
    else if (type.equals(Boolean.TYPE) || type.equals(Boolean.class))
        return (E) Boolean.valueOf(mPreferences.getBoolean(name, (Boolean) defVal));
    else if (type.equals(Long.TYPE) || type.equals(Long.class))
        return (E) Long.valueOf(mPreferences.getLong(name, (Long) defVal));
    else if (type.equals(Float.TYPE) || type.equals(Float.class))
        return (E) Float.valueOf(mPreferences.getFloat(name, (Float) defVal));
    else if (type.getClass().isAssignableFrom(Set.class))
        return (E) mPreferences.getStringSet(name, (Set<String>) defVal);

    return defVal;
}
 
Example #2
Source Project: android_9.0.0_r45   Author: lulululbj   File: FastScroller.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs an animator for the specified property on a group of views.
 * See {@link ObjectAnimator#ofFloat(Object, String, float...)} for
 * implementation details.
 *
 * @param property The property being animated.
 * @param value The value to which that property should animate.
 * @param views The target views to animate.
 * @return An animator for all the specified views.
 */
private static Animator groupAnimatorOfFloat(
        Property<View, Float> property, float value, View... views) {
    AnimatorSet animSet = new AnimatorSet();
    AnimatorSet.Builder builder = null;

    for (int i = views.length - 1; i >= 0; i--) {
        final Animator anim = ObjectAnimator.ofFloat(views[i], property, value);
        if (builder == null) {
            builder = animSet.play(anim);
        } else {
            builder.with(anim);
        }
    }

    return animSet;
}
 
Example #3
Source Project: LaunchEnr   Author: enricocid   File: Workspace.java    License: GNU General Public License v3.0 6 votes vote down vote up
/**
 * Moves the workspace UI in the provided direction.
 * @param direction the direction to move the workspace
 * @param translation the amount of shift.
 * @param alpha the alpha for the workspace page
 */
private void setWorkspaceTranslationAndAlpha(Direction direction, float translation, float alpha) {
    Property<View, Float> property = direction.viewProperty;
    mPageAlpha[direction.ordinal()] = alpha;
    float finalAlpha = mPageAlpha[0] * mPageAlpha[1];

    View currentChild = getChildAt(getCurrentPage());
    if (currentChild != null) {
        property.set(currentChild, translation);
        currentChild.setAlpha(finalAlpha);
    }

    // When the animation finishes, reset all pages, just in case we missed a page.
    if (Float.compare(translation, 0) == 0) {
        for (int i = getChildCount() - 1; i >= 0; i--) {
            View child = getChildAt(i);
            property.set(child, translation);
            child.setAlpha(finalAlpha);
        }
    }
}
 
Example #4
Source Project: adt-leanback-support   Author: kingargyle   File: Slide.java    License: Apache License 2.0 6 votes vote down vote up
private Animator createAnimation(final View view, Property<View, Float> property,
        float start, float end, float terminalValue, TimeInterpolator interpolator,
        int finalVisibility) {
    float[] startPosition = (float[]) view.getTag(R.id.lb_slide_transition_value);
    if (startPosition != null) {
        start = View.TRANSLATION_Y == property ? startPosition[1] : startPosition[0];
        view.setTag(R.id.lb_slide_transition_value, null);
    }
    final ObjectAnimator anim = ObjectAnimator.ofFloat(view, property, start, end);

    SlideAnimatorListener listener = new SlideAnimatorListener(view, property, terminalValue, end,
            finalVisibility);
    anim.addListener(listener);
    anim.addPauseListener(listener);
    anim.setInterpolator(interpolator);
    return anim;
}
 
Example #5
Source Project: scene   Author: bytedance   File: ViewAnimationBuilder.java    License: Apache License 2.0 5 votes vote down vote up
protected void onProgress(float progress) {
    Set<Property<View, Float>> set = hashMap.keySet();
    for (Property<View, Float> property : set) {
        Pair<Float, Float> value = hashMap.get(property);
        property.set(mView, value.first + (value.second * progress));
    }
}
 
Example #6
Source Project: scene   Author: bytedance   File: DrawableAnimationBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public InteractionAnimation build() {
    return new InteractionAnimation(this.mEndProgress) {
        @Override
        public void onProgress(float progress) {
            Set<Property> set = hashMap.keySet();
            for (Property property : set) {
                Holder value = hashMap.get(property);
                property.set(mDrawable, value.typeEvaluator.evaluate(progress, value.fromValue, value.toValue));
            }
        }
    };
}
 
Example #7
Source Project: scene   Author: bytedance   File: InteractionAnimationBuilder.java    License: Apache License 2.0 5 votes vote down vote up
public InteractionAnimation build() {
    return new InteractionAnimation(mEndProgress) {
        @Override
        public void onProgress(float progress) {
            Set<Property<View, Float>> set = hashMap.keySet();
            for (Property<View, Float> property : set) {
                Pair<Float, Float> value = hashMap.get(property);
                property.set(mView, value.first + (value.second * progress));
            }
        }
    };
}
 
Example #8
Source Project: scene   Author: bytedance   File: ImageViewAnimationBuilder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
protected void onProgress(float progress) {
    super.onProgress(progress);

    Set<Property> set = hashMap.keySet();
    for (Property property : set) {
        Holder value = hashMap.get(property);
        property.set(mView, value.typeEvaluator.evaluate(progress, value.fromValue, value.toValue));
    }
}
 
Example #9
Source Project: RecyclerViewExtensions   Author: Doist   File: PinchZoomItemTouchListener.java    License: MIT License 5 votes vote down vote up
private Property<View, Float> getTranslateProperty() {
    if (mOrientation == LinearLayoutManager.VERTICAL) {
        return View.TRANSLATION_Y;
    } else {
        return View.TRANSLATION_X;
    }
}
 
Example #10
Source Project: butterknife   Author: JakeWharton   File: ViewCollections.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Apply the specified {@code value} across the {@code array} of views using the {@code property}.
 */
@UiThread
public static <T extends View, V> void set(@NonNull T[] array,
    @NonNull Property<? super T, V> setter, @Nullable V value) {
  //noinspection ForLoopReplaceableByForEach
  for (int i = 0, count = array.length; i < count; i++) {
    setter.set(array[i], value);
  }
}
 
Example #11
Source Project: android_9.0.0_r45   Author: lulululbj   File: PropertyValuesHolder.java    License: Apache License 2.0 5 votes vote down vote up
public IntPropertyValuesHolder(Property property, Keyframes.IntKeyframes keyframes) {
    super(property);
    mValueType = int.class;
    mKeyframes = keyframes;
    mIntKeyframes = keyframes;
    if (property instanceof  IntProperty) {
        mIntProperty = (IntProperty) mProperty;
    }
}
 
Example #12
Source Project: android_9.0.0_r45   Author: lulululbj   File: PropertyValuesHolder.java    License: Apache License 2.0 5 votes vote down vote up
public IntPropertyValuesHolder(Property property, int... values) {
    super(property);
    setIntValues(values);
    if (property instanceof  IntProperty) {
        mIntProperty = (IntProperty) mProperty;
    }
}
 
Example #13
Source Project: android_9.0.0_r45   Author: lulululbj   File: PropertyValuesHolder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setProperty(Property property) {
    if (property instanceof IntProperty) {
        mIntProperty = (IntProperty) property;
    } else {
        super.setProperty(property);
    }
}
 
Example #14
Source Project: osmdroid   Author: osmdroid   File: MarkerAnimation.java    License: Apache License 2.0 5 votes vote down vote up
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public static ObjectAnimator animateMarkerToICS(final MapView map, Marker marker, GeoPoint finalPosition, final GeoPointInterpolator GeoPointInterpolator) {
    TypeEvaluator<GeoPoint> typeEvaluator = new TypeEvaluator<GeoPoint>() {
        @Override
        public GeoPoint evaluate(float fraction, GeoPoint startValue, GeoPoint endValue) {
            return GeoPointInterpolator.interpolate(fraction, startValue, endValue);
        }
    };
    Property<Marker, GeoPoint> property = Property.of(Marker.class, GeoPoint.class, "position");
    ObjectAnimator animator = ObjectAnimator.ofObject(marker, property, typeEvaluator, finalPosition);
    animator.setDuration(3000);
    animator.start();
    return animator;
}
 
Example #15
Source Project: android_9.0.0_r45   Author: lulululbj   File: PropertyValuesHolder.java    License: Apache License 2.0 5 votes vote down vote up
public FloatPropertyValuesHolder(Property property, float... values) {
    super(property);
    setFloatValues(values);
    if (property instanceof  FloatProperty) {
        mFloatProperty = (FloatProperty) mProperty;
    }
}
 
Example #16
Source Project: android_9.0.0_r45   Author: lulululbj   File: PropertyValuesHolder.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void setProperty(Property property) {
    if (property instanceof FloatProperty) {
        mFloatProperty = (FloatProperty) property;
    } else {
        super.setProperty(property);
    }
}
 
Example #17
Source Project: LaunchEnr   Author: enricocid   File: LauncherAnimUtils.java    License: GNU General Public License v3.0 5 votes vote down vote up
public static ObjectAnimator ofFloat(View target, Property<View, Float> property,
        float... values) {
    ObjectAnimator anim = ObjectAnimator.ofFloat(target, property, values);
    cancelOnDestroyActivity(anim);
    new FirstFrameAnimatorHelper(anim, target);
    return anim;
}
 
Example #18
Source Project: LaunchEnr   Author: enricocid   File: Workspace.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Moves the Hotseat UI in the provided direction.
 * @param direction the direction to move the workspace
 * @param translation the amount of shift.
 * @param alpha the alpha for the hotseat page
 */
public void setHotseatTranslationAndAlpha(Direction direction, float translation, float alpha) {
    Property<View, Float> property = direction.viewProperty;
    // Skip the page indicator movement in the vertical bar layout
    if (direction != Direction.Y || !mLauncher.getDeviceProfile().isVerticalBarLayout()) {
        property.set(mPageIndicator, translation);
    }
    property.set(mLauncher.getHotseat(), translation);
    setHotseatAlphaAtIndex(alpha, direction.ordinal());
}
 
Example #19
Source Project: ucar-weex-core   Author: weexext   File: WXAnimationBean.java    License: Apache License 2.0 5 votes vote down vote up
private void initHolders(){
  for (Map.Entry<Property<View, Float>, Float> entry : transformMap.entrySet()) {
    holders.add(PropertyValuesHolder.ofFloat(entry.getKey(), entry.getValue()));
  }
  if (!TextUtils.isEmpty(opacity)) {
    holders.add(PropertyValuesHolder.ofFloat(View.ALPHA, WXUtils.fastGetFloat(opacity, 3)));
  }
}
 
Example #20
Source Project: magellan   Author: wealthfront   File: DefaultTransition.java    License: Apache License 2.0 5 votes vote down vote up
private AnimatorSet createAnimator(View from, View to, NavigationType navType, Direction direction) {
  Property<View, Float> axis;
  int fromTranslation;
  int toTranslation;
  int sign = direction.sign();

  switch (navType) {
    case GO:
      axis = View.TRANSLATION_X;
      fromTranslation = sign * -from.getWidth();
      toTranslation = sign * to.getWidth();
      break;
    case SHOW:
      axis = View.TRANSLATION_Y;
      fromTranslation = direction == FORWARD ? 0 : from.getHeight();
      toTranslation = direction == BACKWARD ? 0 : to.getHeight();
      break;
    default:
      axis = View.TRANSLATION_X;
      fromTranslation = 0;
      toTranslation = 0;
      break;
  }
  AnimatorSet set = new AnimatorSet();
  if (from != null) {
    set.play(ObjectAnimator.ofFloat(from, axis, 0, fromTranslation));
  }
  set.play(ObjectAnimator.ofFloat(to, axis, toTranslation, 0));
  return set;
}
 
Example #21
Source Project: android_additive_animations   Author: wirecube   File: AdditiveAnimation.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * The preferred constructor to use when animating properties. If you use this constructor, you
 * don't need to worry about the logic to apply the changes. This is taken care of by using the
 * Setter provided by `property`.
 */
public AdditiveAnimation(T target, Property<T, Float> property, float startValue, float targetValue) {
    mTarget = target;
    mProperty = property;
    mTargetValue = targetValue;
    mStartValue = startValue;
    setTag(property.getName());
}
 
Example #22
Source Project: android_additive_animations   Author: wirecube   File: AdditiveAnimation.java    License: Apache License 2.0 5 votes vote down vote up
public AdditiveAnimation(T target, Property<T, Float> property, float startValue, Path path, PathEvaluator.PathMode pathMode, PathEvaluator sharedEvaluator) {
    mTarget = target;
    mProperty = property;
    mStartValue = startValue;
    mPath = path;
    mSharedPathEvaluator = sharedEvaluator;
    mPathMode = pathMode;
    mTargetValue = evaluateAt(1f);
    setTag(property.getName());
}
 
Example #23
Source Project: adt-leanback-support   Author: kingargyle   File: Slide.java    License: Apache License 2.0 5 votes vote down vote up
public SlideAnimatorListener(View view, Property<View, Float> prop,
        float terminalValue, float endValue, int finalVisibility) {
    mProp = prop;
    mView = view;
    mTerminalValue = terminalValue;
    mEndValue = endValue;
    mFinalVisibility = finalVisibility;
    view.setVisibility(View.VISIBLE);
}
 
Example #24
Source Project: android_additive_animations   Author: wirecube   File: BaseAdditiveAnimator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * TODO: documentation of byValueCanBeUsedByParentAnimators
 */
protected final T animatePropertyBy(final Property<V, Float> property, final float by, final boolean byValueCanBeUsedByParentAnimators) {
    initValueAnimatorIfNeeded();
    float currentTarget = getTargetPropertyValue(property);
    if (getQueuedPropertyValue(property.getName()) != null) {
        currentTarget = getQueuedPropertyValue(property.getName());
    }
    AdditiveAnimation animation = createAnimation(property, currentTarget + by);
    initValueAnimatorIfNeeded();
    mRunningAnimationsManager.addAnimation(mAnimationAccumulator, animation);
    if (byValueCanBeUsedByParentAnimators) {
        runIfParentIsInSameAnimationGroup(() -> mParent.animatePropertyBy(property, by, true));
    }
    return self();
}
 
Example #25
Source Project: android_additive_animations   Author: wirecube   File: BaseAdditiveAnimator.java    License: Apache License 2.0 5 votes vote down vote up
protected final T animatePropertiesAlongPath(Property<V, Float> xProperty, Property<V, Float> yProperty, Property<V, Float> rotationProperty, Path path) {
    PathEvaluator sharedEvaluator = new PathEvaluator();
    if (xProperty != null) {
        animate(xProperty, path, PathEvaluator.PathMode.X, sharedEvaluator);
    }
    if (yProperty != null) {
        animate(yProperty, path, PathEvaluator.PathMode.Y, sharedEvaluator);
    }
    if (rotationProperty != null) {
        animate(rotationProperty, path, PathEvaluator.PathMode.ROTATION, sharedEvaluator);
    }
    return self();
}
 
Example #26
Source Project: android_additive_animations   Author: wirecube   File: RunningAnimationsManager.java    License: Apache License 2.0 5 votes vote down vote up
Float getActualPropertyValue(Property<T, Float> property) {
    Float lastTarget = getLastTargetValue(property.getName());
    if (lastTarget == null) {
        lastTarget = property.get(mAnimationTarget);
    }
    return lastTarget;
}
 
Example #27
Source Project: MaterialProgressBar   Author: zhanghai   File: ObjectAnimatorCompatLollipop.java    License: Apache License 2.0 5 votes vote down vote up
@NonNull
public static <T> ObjectAnimator ofFloat(@Nullable T target,
                                         @NonNull Property<T, Float> xProperty,
                                         @NonNull Property<T, Float> yProperty,
                                         @NonNull Path path) {
    return ObjectAnimator.ofFloat(target, xProperty, yProperty, path);
}
 
Example #28
Source Project: MaterialProgressBar   Author: zhanghai   File: ObjectAnimatorCompatLollipop.java    License: Apache License 2.0 5 votes vote down vote up
@NonNull
public static <T> ObjectAnimator ofInt(@Nullable T target,
                                       @NonNull Property<T, Integer> xProperty,
                                       @NonNull Property<T, Integer> yProperty,
                                       @NonNull Path path) {
    return ObjectAnimator.ofInt(target, xProperty, yProperty, path);
}
 
Example #29
Source Project: android-router   Author: trikita   File: ViewRouter.java    License: MIT License 5 votes vote down vote up
private <T extends View> T createView(Class<T> cls, Map<String, String> props) {
	try {
		T v = cls.getConstructor(Context.class).newInstance(mParent.getContext());
		// copy parsed uri params into the view properties 
		for (Map.Entry<String, String> p : props.entrySet()) {
			Property<T, String> property = Property.of(cls, String.class, p.getKey());
			property.set(v, p.getValue());
		}
		return v;
	} catch (NoSuchMethodException|InstantiationException|
			IllegalAccessException|InvocationTargetException e) {
		throw new RuntimeException(e);
	}
}
 
Example #30
Source Project: MaterialProgressBar   Author: zhanghai   File: ObjectAnimatorCompatBase.java    License: Apache License 2.0 5 votes vote down vote up
@NonNull
public static <T> ObjectAnimator ofArgb(@Nullable T target,
                                        @NonNull Property<T, Integer> property, int... values) {
    ObjectAnimator animator = ObjectAnimator.ofInt(target, property, values);
    animator.setEvaluator(new ArgbEvaluator());
    return animator;
}