Example usage for android.animation ValueAnimator getAnimatedValue

List of usage examples for android.animation ValueAnimator getAnimatedValue

Introduction

In this page you can find the example usage for android.animation ValueAnimator getAnimatedValue.

Prototype

public Object getAnimatedValue() 

Source Link

Document

The most recent value calculated by this ValueAnimator when there is just one property being animated.

Usage

From source file:com.example.waitou.rxjava.LoadingView.java

private void buildAnimator() {
    final ValueAnimator valueAnimator = ValueAnimator.ofFloat(0f, 1f).setDuration(ANIMATOR_DURATION);
    valueAnimator.setRepeatCount(-1);// w  w w  .  j  av  a 2  s  .  c om
    valueAnimator.setInterpolator(new LinearInterpolator());
    valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mRotation = (float) valueAnimator.getAnimatedValue();
            invalidate();
        }
    });
    animator = valueAnimator;
    animatorSet = buildFlexibleAnimation();
    animatorSet.addListener(animatorListener);
}

From source file:com.awt.supark.LayoutHandler.java

public void pullDown(final MainActivity act) {
    act.animInProgress = true;/*  w  w  w  .j  a  va  2 s  .co  m*/
    act.CarHandler.updateLicense(act);

    // ****** BUTTON AND LAYOUT PULL DOWN ANIMATION
    // Declaring animator
    ValueAnimator animation = ValueAnimator.ofFloat(0f, 1f);

    // Sets the animation properties
    animation.setDuration(act.layoutPullUpDuration);
    animation.setInterpolator(new AccelerateDecelerateInterpolator());
    animation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float value = (float) animation.getAnimatedValue();
            act.tableRowTopHalf.setLayoutParams(new TableRow.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT, value));
            act.btnMap.setAlpha(value);
            act.btnCars.setAlpha(value);
            act.btnStatistics.setAlpha(value);
            act.btnEtc.setAlpha(value);
        }
    });

    animation.addListener(new Animator.AnimatorListener() {
        @Override
        public void onAnimationStart(Animator animation) {
            // Starts layout pull down and fade out animation
            act.otherContent.startAnimation(act.anim_slide_down_fade_out);
            act.anim_slide_down_fade_out.setFillAfter(true);

            // Makes layout invisible
            act.otherContent.setVisibility(View.GONE);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            act.contentLinear.setVisibility(View.VISIBLE);

            // ****** UI ELEMENTS FADE IN ANIMATION ******
            // Declaring animator
            ValueAnimator nextAnimation = ValueAnimator.ofFloat(0.17f, 1f);

            // Sets the animation properties
            nextAnimation.setDuration(act.layoutFadeInDuration);
            nextAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    float value = (float) animation.getAnimatedValue();
                    act.contentLinear.setAlpha(value);
                }
            });
            nextAnimation.start();

            act.pullUp = false;
            act.openedLayout = 0;
            act.animInProgress = false;
            FragmentTransaction transaction = act.fragmentManager.beginTransaction();
            transaction.remove(act.fragmentManager.findFragmentById(R.id.otherContent));
            transaction.commit();
        }

        @Override
        public void onAnimationCancel(Animator animation) {

        }

        @Override
        public void onAnimationRepeat(Animator animation) {

        }
    });
    animation.start();
}

From source file:com.grarak.kerneladiutor.fragments.RecyclerViewFragment.java

public void dismissForeground() {
    float translation = mForegroundParent.getTranslationY();
    mForegroundAnimator = ValueAnimator.ofFloat(translation, mForegroundHeight);
    mForegroundAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*w ww.  j a  v  a 2 s . c  om*/
        public void onAnimationUpdate(ValueAnimator animation) {
            mForegroundParent.setTranslationY((float) animation.getAnimatedValue());
        }
    });
    mForegroundAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            mForegroundParent.setVisibility(View.GONE);
            mForegroundVisible = false;
            mForegroundAnimator = null;
        }
    });
    mForegroundAnimator.start();
}

From source file:com.example.android.tryanimationt.TryAnimationFragment.java

@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mCardView = (CardView) view.findViewById(R.id.cardview);

    fab1st = (android.widget.ImageButton) view.findViewById(R.id.fabBt);
    fab2nd = (android.widget.ImageButton) view.findViewById(R.id.fabBt2);
    fab3rd = (android.widget.ImageButton) view.findViewById(R.id.fab3);

    footer = view.findViewById(R.id.footer);

    animButtons(fab1st, true, 2500, 0);//from  www  .j ava2  s . co m
    animButtons(fab2nd, true, 1000, 150);
    animButtons(fab3rd, true, 2000, 250);

    fab1st.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            AnimatorSet animSet = new AnimatorSet();
            ObjectAnimator anim2 = ObjectAnimator.ofFloat(fab1st, "rotationX", 0, 359);
            anim2.setDuration(1500);

            ObjectAnimator anim3 = ObjectAnimator.ofFloat(fab1st, "rotationY", 0, 359);
            anim3.setDuration(1500);

            ObjectAnimator animTrx = ObjectAnimator.ofFloat(fab1st, "translationX", 0, -20);
            animTrx.setDuration(2500);
            ObjectAnimator animTry = ObjectAnimator.ofFloat(fab1st, "translationY", 0, -20);
            animTry.setDuration(2500);

            animSet.setInterpolator(new BounceInterpolator());
            animSet.playTogether(anim2, anim3, animTry, animTrx);

            animSet.start();

        }
    });

    fab1st.setOutlineProvider(new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            int size = getResources().getDimensionPixelSize(R.dimen.fab_size);
            outline.setOval(0, 0, size, size);
            outline.setRoundRect(0, 0, size, size, size / 2);
        }
    });

    fab1st.setClipToOutline(true);

    final View vImage = view.findViewById(R.id.image);
    final View vCard = view.findViewById(R.id.cardview);
    final View vCardTextPart = view.findViewById(R.id.cardview_textpart2);
    final View vCardContentContainer = view.findViewById(R.id.cardContentContainer);

    vCard.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(getActivity(),

                    // Now we provide a list of Pair items which contain the view we can transitioning
                    // from, and the name of the view it is transitioning to, in the launched activity

                    android.support.v4.util.Pair.create(vImage, "photo_hero"),
                    android.support.v4.util.Pair.create(vCardTextPart, "sharedSceneTrasintionText"));

            Intent intent = new Intent(getActivity(), sceneTransitionActivity.class);
            intent.putExtra("photo_hero", R.drawable.image1);
            ActivityCompat.startActivity(getActivity(), intent, options.toBundle());
        }
    });

    fab2nd.setOutlineProvider(new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            int size = getResources().getDimensionPixelSize(R.dimen.fab_size);
            outline.setOval(0, 0, size, size);
            outline.setRoundRect(0, 0, size, size, size / 2);
        }
    });

    fab2nd.setClipToOutline(true);

    final AnimationDrawable[] animDrawables = new AnimationDrawable[2];
    animDrawables[0] = (AnimationDrawable) getResources().getDrawable(R.drawable.anim_off_to_on);
    animDrawables[1] = (AnimationDrawable) getResources().getDrawable(R.drawable.anim_on_to_off);
    animDrawables[0].setOneShot(true);
    animDrawables[1].setOneShot(true);

    fab2nd.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            final int fab2InconIndex = mAnimationStateIndex;
            mAnimationStateIndex = (mAnimationStateIndex + 1) % 2;

            /*****************************************************/
            // animate the card

            //final Animation myRotation = AnimationUtils.loadAnimation(getActivity(), R.anim.rotate_anim);
            //mCardView.startAnimation(myRotation);

            int start;
            int end;
            if (mAnimationStateIndex == 0) {
                start = Color.rgb(0x71, 0xc3, 0xde);
                end = Color.rgb(0x68, 0xe8, 0xee);
            } else {
                start = Color.rgb(0x68, 0xe8, 0xee);
                end = Color.rgb(0x71, 0xc3, 0xde);
            }

            AnimatorSet animSet = new AnimatorSet();

            ValueAnimator valueAnimator = ObjectAnimator.ofInt(vCardContentContainer, "backgroundColor", start,
                    end);
            valueAnimator.setInterpolator(new BounceInterpolator());
            valueAnimator.setDuration(2000);
            valueAnimator.setEvaluator(new ArgbEvaluator());

            valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                @Override
                public void onAnimationUpdate(ValueAnimator animation) {
                    int animProgress = (Integer) animation.getAnimatedValue();

                }
            });
            valueAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    mCardView.setRadius(8);
                    //mCardView.setElevation(0);
                }
            });

            float rotateStart, rotateEnd;
            float scaleXStart, scaleXEnd;
            float rotateXStart, rotateXEnd;
            float rotateYStart, rotateYEnd;
            float transitionXStart, transitionXEnd;
            float transitionYStart, transitionYEnd;

            if (mAnimationStateIndex == 0) {
                rotateStart = 0f;
                rotateEnd = 80f;
                scaleXStart = 1f;
                scaleXEnd = 0.66f;
                rotateXStart = 0f;
                rotateXEnd = 30f;
                rotateYStart = 0f;
                rotateYEnd = 30f;
                transitionYStart = 0f;
                transitionYEnd = -100f;
                transitionXStart = 0f;
                transitionXEnd = 100f;
            } else {
                rotateStart = 80f;
                rotateEnd = 0f;
                scaleXStart = 0.66f;
                scaleXEnd = 1;
                rotateXStart = 30;
                rotateXEnd = 0f;
                rotateYStart = 30f;
                rotateYEnd = 0f;
                transitionYStart = -100f;
                transitionYEnd = 0f;
                transitionXStart = 100f;
                transitionXEnd = 0f;
            }

            ObjectAnimator anim = ObjectAnimator.ofFloat(mCardView, "rotation", rotateStart, rotateEnd);
            anim.setDuration(2000);

            ObjectAnimator anim1 = ObjectAnimator.ofFloat(mCardView, "scaleX", scaleXStart, scaleXEnd);
            anim1.setDuration(2000);

            ObjectAnimator anim2 = ObjectAnimator.ofFloat(mCardView, "rotationX", rotateXStart, rotateXEnd);
            anim2.setDuration(2000);

            ObjectAnimator anim3 = ObjectAnimator.ofFloat(mCardView, "rotationY", rotateYStart, rotateYEnd);
            anim3.setDuration(2000);

            ObjectAnimator animTry = ObjectAnimator.ofFloat(mCardView, "translationY", transitionYStart,
                    transitionYEnd);
            animTry.setDuration(2000);
            ObjectAnimator animTrx = ObjectAnimator.ofFloat(mCardView, "translationX", transitionXStart,
                    transitionXEnd);
            animTrx.setDuration(2000);
            animSet.setInterpolator(new BounceInterpolator());
            animSet.playTogether(valueAnimator, anim, anim2, anim3, anim1, animTry, animTrx);

            float controlX1, controlY1, controlX2, controlY2;
            if (mAnimationStateIndex == 0) {
                controlX1 = 0f;
                controlY1 = 0.25f;
                controlX2 = 1;
                controlY2 = 1;
            } else {
                controlX1 = 1;
                controlY1 = 1;
                controlX2 = 0.25f;
                controlY2 = 1;
            }

            PathInterpolator pathInterpolator = new PathInterpolator(controlX1, controlY1, controlX2,
                    controlY2);
            animTrx.setInterpolator(pathInterpolator);

            animSet.start();

            /*****************************************************/
            // animate rotate white button

            RotateAnimation r = new RotateAnimation(0, 359, Animation.RELATIVE_TO_SELF, 0.5f,
                    Animation.RELATIVE_TO_SELF, 0.5f);
            r.setDuration(2000);
            r.setFillAfter(true);

            r.setInterpolator(new BounceInterpolator());

            fab2nd.startAnimation(r);

            // change 2nd button image
            fab2nd.setImageDrawable(animDrawables[fab2InconIndex]);
            animDrawables[fab2InconIndex].start();

            /*****************************************************/
            // animate changing 3rd button image
            fab3rd.setImageDrawable(animDrawables[mAnimationStateIndex]);
            animDrawables[mAnimationStateIndex].start();

            /*****************************************************/
            // using AnimatedStateListDrawable to animate the 1st button image by its state
            {
                Drawable drawable = getActivity().getResources().getDrawable(R.drawable.icon_anim);
                fab1st.setImageDrawable(drawable);

                final int[] STATE_CHECKED = new int[] { android.R.attr.state_checked };
                final int[] STATE_UNCHECKED = new int[] {};

                // set state
                fab1st.setImageState((mAnimationStateIndex != 0) ? STATE_UNCHECKED : STATE_CHECKED, false);
                drawable.jumpToCurrentState();
                // change to state
                fab1st.setImageState((mAnimationStateIndex != 0) ? STATE_CHECKED : STATE_UNCHECKED, false);
            }

        }
    });

    fab3rd.setOutlineProvider(new ViewOutlineProvider() {
        @Override
        public void getOutline(View view, Outline outline) {
            int size = getResources().getDimensionPixelSize(R.dimen.fab_size);
            outline.setOval(0, 0, size, size);
            outline.setRoundRect(0, 0, size, size, size / 2);
        }
    });

    fab3rd.setClipToOutline(true);
    final CheckBox circleFadeout = (CheckBox) view.findViewById(R.id.circleFadeout);

    circleFadeout.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (((CheckBox) v).isChecked()) {
            }
        }
    });

    final ImageButton vLogoBt = fab3rd;
    vLogoBt.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            animButtons(fab1st, false, 2000, 0);
            animButtons(fab2nd, false, 600, 150);
            animButtons(fab3rd, false, 1500, 250);

            Handler delayHandler = new Handler();
            delayHandler.postDelayed(new Runnable() {

                @Override
                public void run() {

                    Intent logoIntent = new Intent(getActivity(), LogoActivity.class);

                    logoIntent.putExtra(LogoActivity.LOGO_VIEW_IMAGE_FADEOUT,
                            (circleFadeout.isChecked() ? 1 : 0));
                    logoIntent.putExtra(LogoActivity.LOGO_VIEW_TRANSTION_TYPE, logoActivityTransitionType);

                    startActivityForResult(logoIntent, mRequestCode,
                            ActivityOptions.makeSceneTransitionAnimation(getActivity()).toBundle());

                }
            }, 1000);

            // footer slide down
            slideView(footer, false);
        }
    });

    mRadioGrp = (RadioGroup) view.findViewById(R.id.radioGroup);
    mRadioGrp.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {

            int selectedId = mRadioGrp.getCheckedRadioButtonId();

            String transitionType = "using";
            switch (selectedId) {
            case R.id.radioFade:
                logoActivityTransitionType = 0;
                transitionType = transitionType + " Fade";
                break;
            case R.id.radioExplode:
                logoActivityTransitionType = 1;
                transitionType = transitionType + " Explode";
                break;
            default:
                logoActivityTransitionType = 2;
                transitionType = transitionType + " Slide";
            }
            mSwitcher.setText(transitionType + " transition");
        }
    });

    mSwitcher = (TextSwitcher) view.findViewById(R.id.textSwitcher);
    mSwitcher.setFactory(mFactory);

    Animation in = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_in_top);
    Animation out = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_out_top);
    mSwitcher.setInAnimation(in);
    mSwitcher.setOutAnimation(out);
    mSwitcher.setCurrentText("using Fade transition");

    // footer slide up
    slideView(footer, true);
}

From source file:nl.thehyve.transmartclient.MainActivity.java

private void animateToArrow(boolean toArrow) {
    int start, stop;
    if (toArrow) {
        start = 0;//from   ww w.j a  v a2 s  . co m
        stop = 1;
    } else {
        start = 1;
        stop = 0;
    }
    ValueAnimator anim = ValueAnimator.ofFloat(start, stop);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float slideOffset = (Float) valueAnimator.getAnimatedValue();
            toggle.onDrawerSlide(drawer, slideOffset);
        }
    });
    anim.setInterpolator(new DecelerateInterpolator());
    anim.setDuration(300);
    anim.start();
}

From source file:com.gu.swiperefresh.ProgressDrawable.java

private void setupAnimators() {
    final Ring ring = mRing;
    final ValueAnimator animator = ObjectAnimator.ofFloat(0f, 1f);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override//w  w  w.  ja v a 2s  . c o  m
        public void onAnimationUpdate(ValueAnimator animation) {
            float interpolatedTime = Float.valueOf(animation.getAnimatedValue().toString());
            if (mFinishing) {
                applyFinishTranslation(interpolatedTime, ring);
            } else {
                // The minProgressArc is calculated from 0 to create an
                // angle that matches the stroke width.
                final float minProgressArc = getMinProgressArc(ring);
                final float startingEndTrim = ring.getStartingEndTrim();
                final float startingTrim = ring.getStartingStartTrim();
                final float startingRotation = ring.getStartingRotation();

                updateRingColor(interpolatedTime, ring);

                // Moving the start trim only occurs in the first 50% of a
                // single ring animation
                if (interpolatedTime <= START_TRIM_DURATION_OFFSET) {
                    // scale the interpolatedTime so that the full
                    // transformation from 0 - 1 takes place in the
                    // remaining time
                    final float scaledTime = (interpolatedTime) / (1.0f - START_TRIM_DURATION_OFFSET);
                    final float startTrim = startingTrim + ((MAX_PROGRESS_ARC - minProgressArc)
                            * MATERIAL_INTERPOLATOR.getInterpolation(scaledTime));
                    ring.setStartTrim(startTrim);
                }

                // Moving the end trim starts after 50% of a single ring
                // animation completes
                if (interpolatedTime > END_TRIM_START_DELAY_OFFSET) {
                    // scale the interpolatedTime so that the full
                    // transformation from 0 - 1 takes place in the
                    // remaining time
                    final float minArc = MAX_PROGRESS_ARC - minProgressArc;
                    float scaledTime = (interpolatedTime - START_TRIM_DURATION_OFFSET)
                            / (1.0f - START_TRIM_DURATION_OFFSET);
                    final float endTrim = startingEndTrim
                            + (minArc * MATERIAL_INTERPOLATOR.getInterpolation(scaledTime));
                    ring.setEndTrim(endTrim);
                }

                final float rotation = startingRotation + (0.25f * interpolatedTime);
                ring.setRotation(rotation);

                float groupRotation = ((FULL_ROTATION / NUM_POINTS) * interpolatedTime)
                        + (FULL_ROTATION * (mRotationCount / NUM_POINTS));
                setRotation(groupRotation);
            }
        }
    });
    animator.setRepeatCount(Animation.INFINITE);
    animator.setRepeatMode(ValueAnimator.RESTART);
    animator.setInterpolator(LINEAR_INTERPOLATOR);
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {

        }

        @Override
        public void onAnimationStart(Animator animation) {
            mRotationCount = 0;
        }

        @Override
        public void onAnimationRepeat(Animator animation) {
            ring.storeOriginals();
            ring.goToNextColor();
            ring.setStartTrim(ring.getEndTrim());
            if (mFinishing) {
                // finished closing the last ring from the swipe gesture; go
                // into progress mode
                mFinishing = false;
                animation.setDuration(ANIMATION_DURATION);
                ring.setShowArrow(false);
            } else {
                mRotationCount = (mRotationCount + 1) % (NUM_POINTS);
            }
        }
    });
    mAnimation = animator;
}

From source file:com.grarak.kerneladiutor.fragments.RecyclerViewFragment.java

public void showForeground() {
    if (mForegroundStrText != null) {
        mForegroundText.setText(mForegroundStrText);
    }/*from   www.j av  a2 s .c o m*/
    if (mForegroundAnimator != null)
        mForegroundAnimator.cancel();
    mForegroundAnimator = ValueAnimator.ofFloat(mForegroundHeight, 0f);
    mForegroundAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            mForegroundParent.setTranslationY((float) animation.getAnimatedValue());
        }
    });
    mForegroundAnimator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
            mForegroundParent.setVisibility(View.VISIBLE);
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            mForegroundVisible = true;
            mForegroundAnimator = null;
        }
    });
    mForegroundAnimator.start();
}

From source file:io.github.trulyfree.easyaspi.MainActivity.java

@Override
public boolean setup() {
    downloadHandler = new DownloadHandler(this);
    fileHandler = new FileHandler(this);
    moduleHandler = new ModuleHandler(this);
    executorService = Executors.newCachedThreadPool();

    setContentView(R.layout.activity_main);
    BottomNavigationView navigation = (BottomNavigationView) findViewById(R.id.navigation);
    navigation.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {

        @Override//w  w w  .  ja  v a  2  s . co  m
        public boolean onNavigationItemSelected(@NonNull MenuItem item) {
            ViewSwitcher viewGroup = (ViewSwitcher) findViewById(R.id.content);
            int id = item.getItemId();
            if ((id == R.id.navigation_home || id == R.id.navigation_modules) && id != currentID) {
                currentID = item.getItemId();
                viewGroup.showNext();
                return true;
            }
            return false;
        }

    });

    ViewSwitcher viewSwitcher = (ViewSwitcher) findViewById(R.id.content);
    Animation in = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);
    Animation out = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right);
    viewSwitcher.setInAnimation(in);
    viewSwitcher.setOutAnimation(out);

    resetConfigReturned();

    Button getNewModule = (Button) findViewById(R.id.new_module_config_confirm);
    getNewModule.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            EditText editText = (EditText) findViewById(R.id.new_module_config_configurl);
            final String url = editText.getText().toString();
            Toast.makeText(MainActivity.this, "Requested config from: " + url, Toast.LENGTH_SHORT).show();
            executorService.submit(new Callable<Boolean>() {
                @Override
                public Boolean call() {
                    ModuleConfig config;
                    try {
                        config = moduleHandler.getModuleConfig(url);
                    } catch (MalformedURLException e) {
                        e.printStackTrace();
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(MainActivity.this, "Invalid URL. :(", Toast.LENGTH_LONG).show();
                            }
                        });
                        return false;
                    } catch (IOException e) {
                        e.printStackTrace();
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(MainActivity.this, "Failed to get module config. :(",
                                        Toast.LENGTH_LONG).show();
                            }
                        });
                        return false;
                    } catch (JsonParseException e) {
                        e.printStackTrace();
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Toast.makeText(MainActivity.this, "Config loaded was invalid. :(",
                                        Toast.LENGTH_LONG).show();
                            }
                        });
                        return false;
                    }

                    final ModuleConfig finalConfig = config;
                    final ImageView configResponseBlock = (ImageView) findViewById(R.id.block_module_returned);
                    final int colorFrom = ContextCompat.getColor(MainActivity.this, R.color.colorFillingTint);
                    final int colorTo = ContextCompat.getColor(MainActivity.this, R.color.colorClear);
                    final ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom,
                            colorTo);
                    colorAnimation.setDuration(ANIMATION_DURATION);
                    colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                        @Override
                        public void onAnimationUpdate(ValueAnimator animator) {
                            configResponseBlock.setBackgroundColor((Integer) animator.getAnimatedValue());
                        }
                    });
                    colorAnimation.addListener(new Animator.AnimatorListener() {
                        @Override
                        public void onAnimationStart(Animator animator) {
                        }

                        @Override
                        public void onAnimationEnd(Animator animator) {
                            LinearLayout layout = (LinearLayout) findViewById(R.id.module_returned_config);
                            EditText moduleName = (EditText) findViewById(R.id.module_returned_configname);
                            EditText moduleVersion = (EditText) findViewById(
                                    R.id.module_returned_configversion);
                            EditText moduleConfigUrl = (EditText) findViewById(R.id.module_returned_configurl);
                            EditText moduleJarUrl = (EditText) findViewById(R.id.module_returned_jarurl);
                            LinearLayout moduleDependencies = (LinearLayout) findViewById(
                                    R.id.module_returned_dependencies);
                            moduleDependencies.removeAllViewsInLayout();
                            try {
                                configResponseBlock.setVisibility(View.GONE);
                                moduleName.setText(finalConfig.getName());
                                moduleVersion.setText(finalConfig.getVersion());
                                moduleConfigUrl.setText(finalConfig.getConfUrl());
                                moduleJarUrl.setText(finalConfig.getJarUrl());
                                Config[] dependencies = finalConfig.getDependencies();
                                for (Config dependency : dependencies) {
                                    LinearLayout dependencyLayout = new LinearLayout(MainActivity.this);
                                    dependencyLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
                                            LayoutParams.WRAP_CONTENT));
                                    dependencyLayout.setOrientation(LinearLayout.HORIZONTAL);
                                    EditText name = new EditText(MainActivity.this);
                                    EditText jarUrl = new EditText(MainActivity.this);
                                    EditText[] loopThrough = { name, jarUrl };
                                    LayoutParams params = new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1.0f);
                                    for (EditText item : loopThrough) {
                                        item.setLayoutParams(params);
                                        item.setClickable(false);
                                        item.setInputType(InputType.TYPE_NULL);
                                        item.setCursorVisible(false);
                                        item.setFocusable(false);
                                        item.setFocusableInTouchMode(false);
                                    }
                                    name.setText(dependency.getName());
                                    jarUrl.setText(dependency.getJarUrl());
                                    dependencyLayout.addView(name);
                                    dependencyLayout.addView(jarUrl);
                                    moduleDependencies.addView(dependencyLayout);
                                }
                                layout.setClickable(true);
                                Button validate = (Button) findViewById(R.id.module_returned_validate);
                                Button cancel = (Button) findViewById(R.id.module_returned_cancel);
                                validate.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        Toast.makeText(MainActivity.this, "Requesting jars...",
                                                Toast.LENGTH_SHORT).show();
                                        executorService.submit(new Callable<Boolean>() {
                                            @Override
                                            public Boolean call() {
                                                try {
                                                    boolean success = true, refreshAllModification = true;
                                                    Button refreshAll = null,
                                                            getNewModule = (Button) findViewById(
                                                                    R.id.new_module_config_confirm);
                                                    try {
                                                        refreshAll = (Button) findViewById(R.id.refresh_all);
                                                        refreshAll.setClickable(false);
                                                    } catch (Throwable e) {
                                                        refreshAllModification = false;
                                                    }
                                                    getNewModule.setClickable(false);
                                                    final TextView stager = (TextView) findViewById(
                                                            R.id.new_module_config_downloadstage);
                                                    final ProgressBar progressBar = (ProgressBar) findViewById(
                                                            R.id.new_module_config_downloadprogress);
                                                    try {
                                                        runOnUiThread(new Runnable() {
                                                            @Override
                                                            public void run() {
                                                                resetConfigReturned();
                                                            }
                                                        });
                                                        moduleHandler.getNewModule(
                                                                makeModuleCallback(stager, progressBar),
                                                                finalConfig, null, true);
                                                    } catch (IOException e) {
                                                        e.printStackTrace();
                                                        runOnUiThread(new Runnable() {
                                                            @Override
                                                            public void run() {
                                                                stager.setText("");
                                                                progressBar.setProgress(0);
                                                            }
                                                        });
                                                        success = false;
                                                    }
                                                    getNewModule.setClickable(true);
                                                    if (refreshAllModification) {
                                                        refreshAll.setClickable(true);
                                                    }
                                                    return success;
                                                } catch (Throwable throwable) {
                                                    throwable.printStackTrace();
                                                    return false;
                                                }
                                            }
                                        });
                                    }
                                });
                                cancel.setOnClickListener(new View.OnClickListener() {
                                    @Override
                                    public void onClick(View view) {
                                        Toast.makeText(MainActivity.this, "Cancelling request...",
                                                Toast.LENGTH_SHORT).show();
                                        resetConfigReturned();
                                    }
                                });
                            } catch (Exception e) {
                                e.printStackTrace();
                                Toast.makeText(MainActivity.this, "Module config invalid. :(",
                                        Toast.LENGTH_LONG).show();
                                layout.setClickable(false);
                                final int colorFrom = ContextCompat.getColor(MainActivity.this,
                                        R.color.colorClear);
                                final int colorTo = ContextCompat.getColor(MainActivity.this,
                                        R.color.colorFillingTint);
                                ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(),
                                        colorFrom, colorTo);
                                colorAnimation.setDuration(ANIMATION_DURATION);
                                colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
                                    @Override
                                    public void onAnimationUpdate(ValueAnimator animator) {
                                        configResponseBlock
                                                .setBackgroundColor((Integer) animator.getAnimatedValue());
                                    }
                                });
                            }
                        }

                        @Override
                        public void onAnimationCancel(Animator animator) {
                        }

                        @Override
                        public void onAnimationRepeat(Animator animator) {
                        }
                    });
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            colorAnimation.start();
                        }
                    });
                    return true;
                }
            });
        }
    });

    moduleHandler.setup();
    refreshFilling();
    return true;
}

From source file:com.commit451.inkpageindicator.InkPageIndicator.java

private ValueAnimator createMoveSelectedAnimator(final float moveTo, int was, int now, int steps) {

    // create the actual move animator
    ValueAnimator moveSelected = ValueAnimator.ofFloat(selectedDotX, moveTo);

    // also set up a pending retreat anim  this starts when the move is 75% complete
    retreatAnimation = new PendingRetreatAnimator(was, now, steps,
            now > was ? new RightwardStartPredicate(moveTo - ((moveTo - selectedDotX) * 0.25f))
                    : new LeftwardStartPredicate(moveTo + ((selectedDotX - moveTo) * 0.25f)));
    retreatAnimation.addListener(new AnimatorListenerAdapter() {
        @Override/*from  w w w  .j  a  v a2s.  c om*/
        public void onAnimationEnd(Animator animation) {
            resetState();
            pageChanging = false;
        }
    });
    moveSelected.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            // todo avoid autoboxing
            selectedDotX = (Float) valueAnimator.getAnimatedValue();
            retreatAnimation.startIfNecessary(selectedDotX);
            ViewCompat.postInvalidateOnAnimation(InkPageIndicator.this);
        }
    });
    moveSelected.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            // set a flag so that we continue to draw the unselected dot in the target position
            // until the selected dot has finished moving into place
            selectedDotInPosition = false;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            // set a flag when anim finishes so that we don't draw both selected & unselected
            // page dots
            selectedDotInPosition = true;
        }
    });
    // slightly delay the start to give the joins a chance to run
    // unless dot isn't in position yet  then don't delay!
    moveSelected.setStartDelay(selectedDotInPosition ? animDuration / 4l : 0l);
    moveSelected.setDuration(animDuration * 3l / 4l);
    moveSelected.setInterpolator(interpolator);
    return moveSelected;
}

From source file:com.amaze.filemanager.ui.views.Indicator.java

private ValueAnimator createMoveSelectedAnimator(final float moveTo, int was, int now, int steps) {

    // create the actual move animator
    ValueAnimator moveSelected = ValueAnimator.ofFloat(selectedDotX, moveTo);

    // also set up a pending retreat anim  this starts when the move is 75% complete
    retreatAnimation = new PendingRetreatAnimator(was, now, steps,
            now > was ? new RightwardStartPredicate(moveTo - ((moveTo - selectedDotX) * 0.25f))
                    : new LeftwardStartPredicate(moveTo + ((selectedDotX - moveTo) * 0.25f)));
    retreatAnimation.addListener(new AnimatorListenerAdapter() {
        @Override//ww  w  .j a  va  2  s  . c  o  m
        public void onAnimationEnd(Animator animation) {
            resetState();
            pageChanging = false;
        }
    });
    moveSelected.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            // todo avoid autoboxing
            selectedDotX = (Float) valueAnimator.getAnimatedValue();
            retreatAnimation.startIfNecessary(selectedDotX);
            postInvalidateOnAnimation();
        }
    });
    moveSelected.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            // set a flag so that we continue to draw the unselected dot in the target position
            // until the selected dot has finished moving into place
            selectedDotInPosition = false;
        }

        @Override
        public void onAnimationEnd(Animator animation) {
            // set a flag when anim finishes so that we don't draw both selected & unselected
            // page dots
            selectedDotInPosition = true;
        }
    });
    // slightly delay the start to give the joins a chance to run
    // unless dot isn't in position yet  then don't delay!
    moveSelected.setStartDelay(selectedDotInPosition ? animDuration / 4l : 0l);
    moveSelected.setDuration(animDuration * 3l / 4l);
    moveSelected.setInterpolator(interpolator);
    return moveSelected;
}