List of usage examples for android.view ViewPropertyAnimator withEndAction
public ViewPropertyAnimator withEndAction(Runnable runnable)
From source file:br.marcha.jesus.youtube.VideoListActivity.java
@TargetApi(16) private void runOnAnimationEnd(ViewPropertyAnimator animator, final Runnable runnable) { if (Build.VERSION.SDK_INT >= 16) { animator.withEndAction(runnable); } else {//from w w w. j a va 2 s. c o m animator.setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { runnable.run(); } }); } }
From source file:test.hugo.ui.ImgShowActivity.java
@Override public void onBackPressed() { float screenWidth = getResources().getDisplayMetrics().widthPixels; float screenHeight = getResources().getDisplayMetrics().heightPixels; float endX = (screenWidth - mInit_width) / 2; float endY = (screenHeight - mInit_height) / 2; int currentItem = vp_data.getCurrentItem(); Pair<Float, Float> pair = pairs[currentItem]; ViewPropertyAnimator animator = vp_data.animate().setDuration(300).setInterpolator(interpolator) .scaleX(mInit_width / pair.first).scaleY(mInit_height / pair.second) .translationX(mLocation_left - endX).translationY(mLocation_top - endY); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { animator.withEndAction(new Runnable() { @Override/* w w w . ja va 2s.co m*/ public void run() { finish(); overridePendingTransition(0, 0); } }).start(); } else { animator.setListener(new Animator.AnimatorListener() { @Override public void onAnimationStart(Animator animation) { } @Override public void onAnimationEnd(Animator animation) { finish(); overridePendingTransition(0, 0); } @Override public void onAnimationCancel(Animator animation) { } @Override public void onAnimationRepeat(Animator animation) { } }).start(); } }
From source file:com.hybris.mobile.lib.ui.view.Alert.java
/** * Show the alert//w w w . java 2 s . com * * @param context application-specific resources * @param configuration describes all device configuration information * @param text message to be displayed * @param forceClearPreviousAlert true will clear previous alert else keep it */ @SuppressLint("NewApi") private static void showAlertOnScreen(final Activity context, final Configuration configuration, final String text, boolean forceClearPreviousAlert) { final ViewGroup mainView = ((ViewGroup) context.findViewById(android.R.id.content)); boolean currentlyDisplayed = false; int viewId = R.id.alert_view_top; final TextView textView; boolean alertAlreadyExists = false; if (configuration.getOrientation().equals(Configuration.Orientation.BOTTOM)) { viewId = R.id.alert_view_bottom; } // Retrieving the view RelativeLayout relativeLayout = (RelativeLayout) mainView.findViewById(viewId); if (forceClearPreviousAlert) { mainView.removeView(relativeLayout); relativeLayout = null; } // Creating the view if (relativeLayout == null) { // Main layout relativeLayout = new RelativeLayout(context); relativeLayout.setId(viewId); relativeLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, configuration.getHeight())); relativeLayout.setGravity(Gravity.CENTER); // Textview textView = new TextView(context); textView.setId(R.id.alert_view_text); textView.setGravity(Gravity.CENTER); textView.setLayoutParams( new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); relativeLayout.addView(textView); setIcon(context, configuration, relativeLayout, textView); if (configuration.getOrientation().equals(Configuration.Orientation.TOP)) { relativeLayout.setY(-configuration.getHeight()); } else { relativeLayout.setY(mainView.getHeight()); } // Adding the view to the global layout mainView.addView(relativeLayout, 0); relativeLayout.bringToFront(); relativeLayout.requestLayout(); relativeLayout.invalidate(); } // View already exists else { alertAlreadyExists = true; textView = (TextView) relativeLayout.findViewById(R.id.alert_view_text); if (configuration.getOrientation().equals(Configuration.Orientation.TOP)) { if (relativeLayout.getY() == 0) { currentlyDisplayed = true; } } else { if (relativeLayout.getY() < mainView.getHeight()) { currentlyDisplayed = true; } } // The view is currently shown to the user if (currentlyDisplayed) { // If the message is not the same, we hide the current message and display the new one if (!StringUtils.equals(text, textView.getText())) { // Anim out the current message ViewPropertyAnimator viewPropertyAnimator = animOut(configuration, mainView, relativeLayout); final RelativeLayout relativeLayoutFinal = relativeLayout; if (viewPropertyAnimator != null) { // Anim in the new message after the animation out has finished if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { viewPropertyAnimator.setListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { setIcon(context, configuration, relativeLayoutFinal, textView); animIn(configuration, relativeLayoutFinal, textView, mainView, text); } }); } else { viewPropertyAnimator.withEndAction(new Runnable() { @Override public void run() { setIcon(context, configuration, relativeLayoutFinal, textView); animIn(configuration, relativeLayoutFinal, textView, mainView, text); } }); } } else { setIcon(context, configuration, relativeLayoutFinal, textView); animIn(configuration, relativeLayoutFinal, textView, mainView, text); } } } } final RelativeLayout relativeLayoutFinal = relativeLayout; // Close the alert by clicking the layout if (configuration.isCloseable()) { relativeLayout.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { animOut(configuration, mainView, relativeLayoutFinal); v.performClick(); return true; } }); } if (!currentlyDisplayed) { // Set the icon in case the alert already exists but it's not currently displayed if (alertAlreadyExists) { setIcon(context, configuration, relativeLayoutFinal, textView); } // We anim in the alert animIn(configuration, relativeLayoutFinal, textView, mainView, text); } }