Example usage for android.animation ValueAnimator addListener

List of usage examples for android.animation ValueAnimator addListener

Introduction

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

Prototype

public void addListener(AnimatorListener listener) 

Source Link

Document

Adds a listener to the set of listeners that are sent events through the life of an animation, such as start, repeat, and end.

Usage

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

public void pullDown(final MainActivity act) {
    act.animInProgress = true;// w w  w .j av  a 2s. c  om
    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.taobao.weex.ui.view.refresh.core.WXSwipeLayout.java

/**
 * Start Refresh//from  w w  w  .j  a va  2 s  .co m
 * @param headerViewHeight
 */
private void startRefresh(int headerViewHeight) {
    mRefreshing = true;
    ValueAnimator animator = ValueAnimator.ofFloat(headerViewHeight, refreshViewHeight);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            LayoutParams lp = (LayoutParams) headerView.getLayoutParams();
            lp.height = (int) ((Float) animation.getAnimatedValue()).floatValue();
            headerView.setLayoutParams(lp);
            moveTargetView(lp.height);
        }
    });
    animator.addListener(new WXRefreshAnimatorListener() {
        @Override
        public void onAnimationEnd(Animator animation) {
            headerView.startAnimation();
            //TODO updateLoadText
            if (onRefreshListener != null) {
                onRefreshListener.onRefresh();
            }
        }
    });
    animator.setDuration(300);
    animator.start();
}

From source file:com.taobao.weex.ui.view.refresh.core.WXSwipeLayout.java

/**
 * Start loadmore//w  w w. j a v  a 2  s. co m
 * @param headerViewHeight
 */
private void startLoadmore(int headerViewHeight) {
    mRefreshing = true;
    ValueAnimator animator = ValueAnimator.ofFloat(headerViewHeight, loadingViewHeight);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            LayoutParams lp = (LayoutParams) footerView.getLayoutParams();
            lp.height = (int) ((Float) animation.getAnimatedValue()).floatValue();
            footerView.setLayoutParams(lp);
            moveTargetView(-lp.height);
        }
    });
    animator.addListener(new WXRefreshAnimatorListener() {
        @Override
        public void onAnimationEnd(Animator animation) {
            footerView.startAnimation();
            //TODO updateLoadText
            if (onLoadingListener != null) {
                onLoadingListener.onLoading();
            }
        }
    });
    animator.setDuration(300);
    animator.start();
}

From source file:com.lovejjfg.powerrefresh.PowerRefreshLayout.java

private void performAnim(int start, int end, final AnimListener listener) {
    ValueAnimator animator = ValueAnimator.ofInt(start, end);
    animator.setDuration(ANIMATION_DURATION).start();
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override/*from   w  w w.ja  v  a2  s  . c  om*/
        public void onAnimationUpdate(ValueAnimator animation) {
            int value = (int) animation.getAnimatedValue();
            scrollTo(0, value);
            postInvalidate();
            listener.onGoing();
        }
    });
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            listener.onEnd();
        }
    });
}

From source file:com.shalzz.attendance.fragment.AttendanceListFragment.java

@Override
public void onItemExpanded(final View view) {
    final int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    final ExpandableListAdapter.GenericViewHolder viewHolder = (ExpandableListAdapter.GenericViewHolder) view
            .getTag();/* www. jav a2  s  .  c  o  m*/
    final RelativeLayout childView = viewHolder.childView;
    childView.measure(spec, spec);
    final int startingHeight = view.getHeight();
    final ViewTreeObserver observer = mRecyclerView.getViewTreeObserver();
    observer.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
        @Override
        public boolean onPreDraw() {
            // We don'mTracker want to continue getting called for every draw.
            if (observer.isAlive()) {
                observer.removeOnPreDrawListener(this);
            }
            // Calculate some values to help with the animation.
            final int endingHeight = view.getHeight();
            final int distance = Math.abs(endingHeight - startingHeight);
            final int baseHeight = Math.min(endingHeight, startingHeight);
            final boolean isExpanded = endingHeight > startingHeight;

            // Set the views back to the start state of the animation
            view.getLayoutParams().height = startingHeight;
            if (!isExpanded) {
                viewHolder.childView.setVisibility(View.VISIBLE);
            }

            // Set up the fade effect for the action buttons.
            if (isExpanded) {
                // Start the fade in after the expansion has partly completed, otherwise it
                // will be mostly over before the expansion completes.
                viewHolder.childView.setAlpha(0f);
                viewHolder.childView.animate().alpha(1f).setStartDelay(mFadeInStartDelay)
                        .setDuration(mFadeInDuration).start();
            } else {
                viewHolder.childView.setAlpha(1f);
                viewHolder.childView.animate().alpha(0f).setDuration(mFadeOutDuration).start();
            }
            view.requestLayout();

            // Set up the animator to animate the expansion and shadow depth.
            ValueAnimator animator = isExpanded ? ValueAnimator.ofFloat(0f, 1f) : ValueAnimator.ofFloat(1f, 0f);

            // scroll to make the view fully visible.
            mRecyclerView.smoothScrollToPosition(viewHolder.position);

            animator.addUpdateListener(animator1 -> {
                Float value = (Float) animator1.getAnimatedValue();

                // For each value from 0 to 1, animate the various parts of the layout.
                view.getLayoutParams().height = (int) (value * distance + baseHeight);
                float z = mExpandedItemTranslationZ * value;
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
                    view.setTranslationZ(z);
                }
                view.requestLayout();
            });

            // Set everything to their final values when the animation's done.
            animator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    view.getLayoutParams().height = ViewGroup.LayoutParams.WRAP_CONTENT;

                    if (!isExpanded) {
                        viewHolder.childView.setVisibility(View.GONE);
                    } else {
                        // This seems like it should be unnecessary, but without this, after
                        // navigating out of the activity and then back, the action view alpha
                        // is defaulting to the value (0) at the start of the expand animation.
                        viewHolder.childView.setAlpha(1);
                    }
                }
            });

            animator.setDuration(mExpandCollapseDuration);
            animator.start();

            // Return false so this draw does not occur to prevent the final frame from
            // being drawn for the single frame before the animations start.
            return false;
        }
    });
}

From source file:net.margaritov.preference.colorpicker.ColorPickerDialog.java

private ValueAnimator createColorTransitionAnimator(float start, float end) {
    ValueAnimator animator = ValueAnimator.ofFloat(start, end);

    animator.setDuration(500);/*ww w.j  a va  2  s . com*/
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            float position = animation.getAnimatedFraction();
            if (mIsPanelButtons) {
                int[] blended = new int[8];
                for (int i = 0; i < mPanelViewButtons.length; i++) {
                    blended[i] = blendColors(mPanelViewButtons[i].getColor(), mPaletteColors[mPalette][i],
                            position);
                    mPanelViewButtons[i].setColor(blended[i]);
                }
            } else {
                int blended = blendColors(mNewColor.getColor(), mNewColorValue, position);
                mNewColor.setColor(blended);
            }
        }
    });
    animator.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (!mIsPanelButtons) {
                mIsPanelButtons = true;
            }
        }
    });
    return animator;
}

From source file:com.test.slidebutton.SlideButton.java

/**
 * max_leftmin_left(moveToboolean toRight)
 * @param toRight//from   w  ww  .j a  v a 2  s .c o m
 */
@Deprecated
private void moveToDest(final boolean toRight) {
    ValueAnimator toDestAnim = ValueAnimator.ofInt(sliderCurrentLeft, toRight ? max_left : min_left);
    toDestAnim.setDuration(200);
    toDestAnim.setInterpolator(new AccelerateDecelerateInterpolator());
    //      toDestAnim.setInterpolator(new OvershootInterpolator());
    toDestAnim.start();
    toDestAnim.addUpdateListener(new AnimatorUpdateListener() {

        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            sliderCurrentLeft = (Integer) animation.getAnimatedValue();
            alpha = (int) (255 * (float) sliderCurrentLeft / (float) max_left);
            if (alpha < 0)
                alpha = 0;
            if (alpha > 255)
                alpha = 255;
            caculateColor();
            invalidateView();
        }
    });
    toDestAnim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            if (toRight) {
                isOpen = true;
                if (listener != null) {
                    listener.open();
                }
                sliderCurrentLeft = sliderMoveStartLeft = max_left;
                alpha = 255;
            } else {
                isOpen = false;
                if (listener != null) {
                    listener.close();
                }
                sliderCurrentLeft = sliderMoveStartLeft = min_left;
                alpha = 0;
            }
            invalidateView();
        }
    });
}

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 ww . j  av a2s.  c o  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:org.protocoderrunner.apprunner.api.PUI.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@ProtocoderScript/*  ww  w  .j  a  v  a2  s. co  m*/
@APIParam(params = { "View" })
public void reveal(final View v) {
    // previously invisible view

    // get the center for the clipping circle
    int cx = (v.getLeft() + v.getRight()) / 2;
    int cy = (v.getTop() + v.getBottom()) / 2;

    // get the final radius for the clipping circle
    int finalRadius = v.getWidth();

    // create and start the animator for this view
    // (the start radius is zero)
    ValueAnimator anim = (ValueAnimator) ViewAnimationUtils.createCircularReveal(v, cx, cy, 0, finalRadius);

    anim.setDuration(1000);
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationStart(Animator animation) {
            super.onAnimationStart(animation);
            v.setVisibility(View.VISIBLE);
        }
    });
    anim.start();
}

From source file:com.telenav.nodeflow.NodeFlowLayout.java

/**
 * perform opening animation for the specified node
 *
 * @param node node to be animated/*from  ww w .  j  a va  2  s . co m*/
 */
private void animateDrillIn(final Node<?> node) {
    final int index = activeNode.getIndex() + (activeNode.getDepth() > 1 ? 1 : 0);
    ValueAnimator animator = ValueAnimator.ofFloat(1);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {

            for (int i = 0; i < getChildCount(); ++i) {
                if (i < index) {
                    getChildAt(i).setTranslationY(
                            headerHeight * i - ((Float) animation.getAnimatedValue()) * headerHeight * index);
                } else if (i > index) {
                    getChildAt(i).setTranslationY(headerHeight * i
                            + ((Float) animation.getAnimatedValue()) * (getHeight() - headerHeight * index));
                } else {
                    getChildAt(i).setTranslationY(
                            headerHeight * i - ((Float) animation.getAnimatedValue()) * headerHeight * index); // move active item
                }
            }
        }
    });
    animator.addListener(new CustomAnimationListener() {
        @Override
        public void onAnimationEnd(Animator animator) {
            updateViews(node, true);
        }
    });
    animator.setDuration(duration);
    animator.setInterpolator(new FastOutSlowInInterpolator());
    animator.start();
    animateDrillAlpha(index + 1, getChildCount(), 0);
}