Example usage for android.view ViewGroup.LayoutParams getClass

List of usage examples for android.view ViewGroup.LayoutParams getClass

Introduction

In this page you can find the example usage for android.view ViewGroup.LayoutParams getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:self.philbrown.droidQuery.$.java

/**
 * Animate multiple view properties at the same time. For example:
 * <pre>/*from  www. j a  va 2 s . c  o m*/
 * $.with(myView).animate(new QuickMap(QuickEntry.qe("alpha", .8f), QuickEntry.qe("width", 50%)), new AnimationOptions());
 * </pre>
 * @param properties mapping of property names and final values to animate
 * @param options the options for setting the duration, easing, etc of the animation
 * @return this
 */
public $ animate(Map<String, Object> properties, final AnimationOptions options) {
    List<Animator> animations = new ArrayList<Animator>();
    for (Entry<String, Object> entry : properties.entrySet()) {
        final String key = entry.getKey();
        //Java sometimes will interpret these Strings as Numbers, so some trickery is needed below
        Object value = entry.getValue();

        for (final View view : this.views) {
            ValueAnimator anim = null;
            if (value instanceof String)
                value = getAnimationValue(view, key, (String) value);
            if (value != null) {
                final ViewGroup.LayoutParams params = view.getLayoutParams();
                try {
                    final Field field = params.getClass().getField(key);
                    if (field != null) {
                        if (value instanceof Integer || value.getClass() == int.class)
                            anim = ValueAnimator.ofInt((Integer) field.get(params), (Integer) value);
                        else if (value instanceof Float || value.getClass() == float.class)
                            anim = ValueAnimator.ofFloat((Float) field.get(params), (Float) value);
                        else if (value instanceof Long || value.getClass() == long.class)
                            anim = ValueAnimator.ofFloat((Float) field.get(params), new Float((Long) value));
                        else if (value instanceof Double || value.getClass() == double.class)
                            anim = ValueAnimator.ofFloat((Float) field.get(params), new Float((Double) value));
                        anim.addUpdateListener(new AnimatorUpdateListener() {

                            @Override
                            public void onAnimationUpdate(ValueAnimator animation) {
                                try {
                                    field.set(params, animation.getAnimatedValue());
                                    view.requestLayout();
                                } catch (Throwable t) {
                                    if (options.debug())
                                        t.printStackTrace();
                                }
                                if (options.progress() != null) {
                                    options.progress().invoke($.with(view), key, animation.getAnimatedValue(),
                                            animation.getDuration() - animation.getCurrentPlayTime());
                                }

                            }

                        });
                    }

                } catch (Throwable t) {

                    if (options.debug())
                        Log.w("$", String.format(Locale.US, "%s is not a LayoutParams attribute.", key));
                }

                if (anim == null) {
                    if (value instanceof Integer || value.getClass() == int.class)
                        anim = ObjectAnimator.ofInt(view, key, (Integer) value);
                    else if (value instanceof Float || value.getClass() == float.class)
                        anim = ObjectAnimator.ofFloat(view, key, (Float) value);
                    else if (value instanceof Long || value.getClass() == long.class)
                        anim = ObjectAnimator.ofFloat(view, key, new Float((Long) value));
                    else if (value instanceof Double || value.getClass() == double.class)
                        anim = ObjectAnimator.ofFloat(view, key, new Float((Double) value));

                    if (options.progress() != null) {
                        anim.addUpdateListener(new AnimatorUpdateListener() {

                            @Override
                            public void onAnimationUpdate(ValueAnimator animation) {
                                options.progress().invoke($.with(view), key, animation.getAnimatedValue(),
                                        animation.getDuration() - animation.getCurrentPlayTime());
                            }

                        });
                    }
                }

                anim.setRepeatCount(options.repeatCount());
                if (options.reverse())
                    anim.setRepeatMode(ValueAnimator.REVERSE);
                animations.add(anim);
            }

        }
    }
    AnimatorSet animation = animationWithOptions(options, animations);
    animation.start();

    return this;
}