List of usage examples for android.view.animation Animation setInterpolator
public void setInterpolator(Interpolator i)
From source file:com.oginotihiro.snackbar.Snackbar.java
private void animateViewIn() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) { ViewPropertyAnimatorCompat vpac = ViewCompat.animate(mView); if (mDirection == LEFT_RIGHT) { ViewCompat.setTranslationX(mView, -mView.getWidth()); vpac.translationX(0f);/*from w ww .ja v a 2s . c o m*/ } else if (mDirection == TOP_BOTTOM) { ViewCompat.setTranslationY(mView, -mView.getHeight()); vpac.translationY(0f); } else if (mDirection == RIGHT_LEFT) { ViewCompat.setTranslationX(mView, mView.getWidth()); vpac.translationX(0f); } else if (mDirection == BOTTOM_TOP) { ViewCompat.setTranslationY(mView, mView.getHeight()); vpac.translationY(0f); } vpac.setInterpolator(new FastOutSlowInInterpolator()).setDuration(mAnimDuration) .setListener(new ViewPropertyAnimatorListenerAdapter() { @Override public void onAnimationStart(View view) { mView.animateChildrenIn(mAnimDuration - mAnimFadeDuration, mAnimFadeDuration); } @Override public void onAnimationEnd(View view) { if (mCallback != null) { mCallback.onShow(Snackbar.this); } SnackbarManager.getInstance().onShown(mManagerCallback); } }).start(); } else { Animation anim = null; if (mDirection == LEFT_RIGHT) { anim = AnimationUtils.loadAnimation(mView.getContext(), R.anim.oginotihiro_snackbar_left_in); } else if (mDirection == TOP_BOTTOM) { anim = AnimationUtils.loadAnimation(mView.getContext(), R.anim.oginotihiro_snackbar_top_in); } else if (mDirection == RIGHT_LEFT) { anim = AnimationUtils.loadAnimation(mView.getContext(), R.anim.oginotihiro_snackbar_right_in); } else if (mDirection == BOTTOM_TOP) { anim = AnimationUtils.loadAnimation(mView.getContext(), R.anim.oginotihiro_snackbar_bottom_in); } if (anim == null) return; anim.setInterpolator(new FastOutSlowInInterpolator()); anim.setDuration(mAnimDuration); anim.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { if (mCallback != null) { mCallback.onShow(Snackbar.this); } SnackbarManager.getInstance().onShown(mManagerCallback); } @Override public void onAnimationRepeat(Animation animation) { } }); mView.setAnimation(anim); } }
From source file:it.chefacile.app.MainActivity.java
protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mContext = this; chefacileDb = new DatabaseHelper(this); // FilterButton = (ImageButton) findViewById(R.id.buttonfilter); TutorialButton = (ImageButton) findViewById(R.id.button); // AddButton = (ImageButton) findViewById(R.id.button2); responseView = (TextView) findViewById(R.id.responseView); editText = (EditText) findViewById(R.id.ingredientText); progressBar = (ProgressBar) findViewById(R.id.progressBar); //Show = (ImageButton) findViewById(R.id.buttonShow); //Show2 = (ImageButton) findViewById(R.id.buttonShow2); materialAnimatedSwitch = (MaterialAnimatedSwitch) findViewById(R.id.pin); //buttoncuisine = (ImageButton) findViewById(R.id.btn_cuisine); //buttondiet = (ImageButton) findViewById(R.id.btn_diet); //buttonintol = (ImageButton) findViewById(R.id.btn_intoll); //Mostra = (Button) findViewById(R.id.btn_mostra); final Animation animation = new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible animation.setDuration(1000); // duration - half a second animation.setInterpolator(new LinearInterpolator()); // do not alter animation rate animation.setRepeatCount(5); // Repeat animation infinitely animation.setRepeatMode(Animation.REVERSE); ImageView icon = new ImageView(this); // Create an icon icon.setImageDrawable(getResources().getDrawable(R.drawable.logo)); final com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton actionButton = new com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton.Builder( this).setPosition( com.oguzdev.circularfloatingactionmenu.library.FloatingActionButton.POSITION_RIGHT_CENTER) .setContentView(icon).build(); SubActionButton.Builder itemBuilder = new SubActionButton.Builder(this); // repeat many times: ImageView dietIcon = new ImageView(this); dietIcon.setImageDrawable(getResources().getDrawable(R.drawable.diet)); SubActionButton button1 = itemBuilder.setContentView(dietIcon).build(); button1.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { showSingleChoiceDialogDiet(v); }/* ww w. ja va 2 s. c om*/ }); ImageView intolIcon = new ImageView(this); intolIcon.setImageDrawable(getResources().getDrawable(R.drawable.intoll)); SubActionButton button2 = itemBuilder.setContentView(intolIcon).build(); button2.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { showMultiChoiceDialogIntol(v); } }); ImageView cuisineIcon = new ImageView(this); cuisineIcon.setImageDrawable(getResources().getDrawable(R.drawable.cook12)); SubActionButton button3 = itemBuilder.setContentView(cuisineIcon).build(); button3.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { showMultiChoiceDialogCuisine(v); } }); ImageView favouriteIcon = new ImageView(this); favouriteIcon.setImageDrawable(getResources().getDrawable(R.drawable.favorite)); SubActionButton button4 = itemBuilder.setContentView(favouriteIcon).build(); button4.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { showSimpleListDialogFav(v); } }); ImageView wandIcon = new ImageView(this); wandIcon.setImageDrawable(getResources().getDrawable(R.drawable.wand)); SubActionButton button5 = itemBuilder.setContentView(wandIcon).build(); button5.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { sugg = getSuggestion(); suggOccurrences = getCount(); showSimpleListDialogSuggestions(v); } }); final FloatingActionButton actionABC = (FloatingActionButton) findViewById(R.id.action_abc); actionABC.bringToFront(); actionABC.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (ingredients.length() < 2) { Snackbar.make(responseView, "Insert at least one ingredient", Snackbar.LENGTH_LONG) .setAction("Action", null).show(); } else { new RetrieveFeedTask().execute(); } } // Snackbar.make(view, "Non disponibile, mangia l'aria", Snackbar.LENGTH_LONG) // .setAction("Action", null).show(); }); FloatingActionMenu actionMenu = new FloatingActionMenu.Builder(this).setStartAngle(90).setEndAngle(270) .addSubActionView(button1).addSubActionView(button2).addSubActionView(button3) .addSubActionView(button4).addSubActionView(button5).attachTo(actionButton).build(); startDatabase(chefacileDb); for (int j = 0; j < cuisineItems.length; j++) { cuisineItems[j] = cuisineItems[j].substring(0, 1).toUpperCase() + cuisineItems[j].substring(1); } Arrays.sort(cuisineItems); for (int i = 0; i < 24; i++) { cuisineBool[i] = false; } Arrays.sort(intolItems); for (int i = 0; i < 11; i++) { intolBool[i] = false; } mListView = (MaterialListView) findViewById(R.id.material_listview); adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1); TutorialButton.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { startActivity(new Intent(MainActivity.this, IntroScreenActivity.class)); overridePendingTransition(android.R.anim.fade_in, android.R.anim.fade_out); } }); iv = (ImageView) findViewById(R.id.imageView); iv.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { clicks++; Log.d("CLICKS", String.valueOf(clicks)); if (clicks == 15) { Log.d("IMAGE SHOWN", "mai vero"); setBackground(iv); } } }); materialAnimatedSwitch.setOnCheckedChangeListener(new MaterialAnimatedSwitch.OnCheckedChangeListener() { @Override public void onCheckedChanged(boolean isChecked) { if (isChecked == true) { ranking = 2; Toast.makeText(getApplicationContext(), "Minimize missing ingredients", Toast.LENGTH_SHORT) .show(); } else { ranking = 1; Toast.makeText(getApplicationContext(), "Maximize used ingredients", Toast.LENGTH_SHORT).show(); } Log.d("Ranking", String.valueOf(ranking)); } }); final CharSequence[] items = { "Maximize used ingredients", "Minimize missing ingredients" }; editText.setOnKeyListener(new View.OnKeyListener() { public boolean onKey(View v, int keyCode, KeyEvent event) { if (event.getAction() == KeyEvent.ACTION_DOWN) { switch (keyCode) { case KeyEvent.KEYCODE_DPAD_CENTER: case KeyEvent.KEYCODE_ENTER: if (!(editText.getText().toString().trim().equals(""))) { String input; String s1 = editText.getText().toString().substring(0, 1).toUpperCase(); String s2 = editText.getText().toString().substring(1); input = s1 + s2; Log.d("INPUT: ", input); searchedIngredients.add(input); Log.d("SEARCHED INGR LIST", searchedIngredients.toString()); if (!chefacileDb.findIngredientPREF(input)) { if (chefacileDb.findIngredient(input)) { chefacileDb.updateCount(input); mapIngredients = chefacileDb.getDataInMapIngredient(); Map<String, Integer> map2; map2 = sortByValue(mapIngredients); Log.d("MAPPACOUNT: ", map2.toString()); } else { if (chefacileDb.occursExceeded()) { //chefacileDb.deleteMinimum(input); // chefacileDb.insertDataIngredient(input); mapIngredients = chefacileDb.getDataInMapIngredient(); Map<String, Integer> map3; map3 = sortByValue(mapIngredients); Log.d("MAPPAINGREDIENTE: ", map3.toString()); } else { chefacileDb.insertDataIngredient(input); mapIngredients = chefacileDb.getDataInMapIngredient(); Map<String, Integer> map3; map3 = sortByValue(mapIngredients); Log.d("MAPPAINGREDIENTE: ", map3.toString()); } } } } if (editText.getText().toString().trim().equals("")) { ingredients += editText.getText().toString().trim() + ""; editText.getText().clear(); } else { ingredients += editText.getText().toString().replaceAll(" ", "+").trim().toLowerCase() + ","; singleIngredient = editText.getText().toString().trim().toLowerCase(); currentIngredient = singleIngredient; new RetrieveIngredientTask().execute(); //adapter.add(singleIngredient.substring(0,1).toUpperCase() + singleIngredient.substring(1)); } InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); in.hideSoftInputFromWindow(editText.getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS); actionABC.startAnimation(animation); return true; default: break; } } return false; } }); responseView = (TextView) findViewById(R.id.responseView); editText = (EditText) findViewById(R.id.ingredientText); progressBar = (ProgressBar) findViewById(R.id.progressBar); }
From source file:com.money.manager.ex.home.MainActivity.java
private void startSyncIconRotation(MenuItem item) { if (item == null) return;/*from w ww .j av a 2 s . c om*/ // define the animation for rotation Animation animation = new RotateAnimation(360.0f, 0.0f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); animation.setInterpolator(new LinearInterpolator()); animation.setDuration(1200); // animRotate = AnimationUtils.loadAnimation(this, R.anim.rotation); animation.setRepeatCount(Animation.INFINITE); ImageView imageView = new ImageView(this); UIHelper uiHelper = new UIHelper(this); imageView.setImageDrawable( uiHelper.getIcon(GoogleMaterial.Icon.gmd_cached).color(uiHelper.getToolbarItemColor())); imageView.setPadding(8, 8, 8, 8); // imageView.setLayoutParams(new Toolbar.LayoutParams()); imageView.startAnimation(animation); item.setActionView(imageView); }
From source file:android.wuliqing.com.mylibrary.header.MaterialProgressDrawable.java
private void setupAnimators() { final Ring ring = mRing; final Animation finishRingAnimation = new Animation() { public void applyTransformation(float interpolatedTime, Transformation t) { // shrink back down and complete a full rotation before starting other circles // Rotation goes between [0..1]. float targetRotation = (float) (Math.floor(ring.getStartingRotation() / MAX_PROGRESS_ARC) + 1f); final float startTrim = ring.getStartingStartTrim() + (ring.getStartingEndTrim() - ring.getStartingStartTrim()) * interpolatedTime; ring.setStartTrim(startTrim); final float rotation = ring.getStartingRotation() + ((targetRotation - ring.getStartingRotation()) * interpolatedTime); ring.setRotation(rotation);/*w w w.j ava2 s . c o m*/ ring.setArrowScale(1 - interpolatedTime); } }; finishRingAnimation.setInterpolator(EASE_INTERPOLATOR); finishRingAnimation.setDuration(ANIMATION_DURATION / 2); finishRingAnimation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { ring.goToNextColor(); ring.storeOriginals(); ring.setShowArrow(false); mParent.startAnimation(mAnimation); } @Override public void onAnimationRepeat(Animation animation) { } }); final Animation animation = new Animation() { @Override public void applyTransformation(float interpolatedTime, Transformation t) { // The minProgressArc is calculated from 0 to create an angle that // matches the stroke width. final float minProgressArc = (float) Math .toRadians(ring.getStrokeWidth() / (2 * Math.PI * ring.getCenterRadius())); final float startingEndTrim = ring.getStartingEndTrim(); final float startingTrim = ring.getStartingStartTrim(); final float startingRotation = ring.getStartingRotation(); // Offset the minProgressArc to where the endTrim is located. final float minArc = MAX_PROGRESS_ARC - minProgressArc; final float endTrim = startingEndTrim + (minArc * START_CURVE_INTERPOLATOR.getInterpolation(interpolatedTime)); ring.setEndTrim(endTrim); final float startTrim = startingTrim + (MAX_PROGRESS_ARC * END_CURVE_INTERPOLATOR.getInterpolation(interpolatedTime)); ring.setStartTrim(startTrim); final float rotation = startingRotation + (0.25f * interpolatedTime); ring.setRotation(rotation); float groupRotation = ((720.0f / NUM_POINTS) * interpolatedTime) + (720.0f * (mRotationCount / NUM_POINTS)); setRotation(groupRotation); } }; animation.setRepeatCount(Animation.INFINITE); animation.setRepeatMode(Animation.RESTART); animation.setInterpolator(LINEAR_INTERPOLATOR); animation.setDuration(ANIMATION_DURATION); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { mRotationCount = 0; } @Override public void onAnimationEnd(Animation animation) { // do nothing } @Override public void onAnimationRepeat(Animation animation) { ring.storeOriginals(); ring.goToNextColor(); ring.setStartTrim(ring.getEndTrim()); mRotationCount = (mRotationCount + 1) % (NUM_POINTS); } }); mFinishAnimation = finishRingAnimation; mAnimation = animation; }
From source file:eu.thedarken.rootvalidator.ValidatorFragment.java
private void animateFAB(boolean out) { Animation animation; if (out) {// w ww .j a v a 2s . com animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1.0f); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { mFab.setVisibility(View.INVISIBLE); } @Override public void onAnimationRepeat(Animation animation) { } }); } else { animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 0, Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { mFab.setVisibility(View.VISIBLE); } @Override public void onAnimationEnd(Animation animation) { } @Override public void onAnimationRepeat(Animation animation) { } }); } animation.setDuration(600); animation.setInterpolator(new AnticipateOvershootInterpolator(1.2f)); mFab.startAnimation(animation); }
From source file:com.google.android.apps.gutenberg.widget.TabLayout.java
private void animateToTab(int newPosition) { clearAnimation();//from w ww . ja v a 2s .c o m if (newPosition == Tab.INVALID_POSITION) { return; } if (getWindowToken() == null || !isViewLaidOut(this)) { // If we don't have a window token, or we haven't been laid out yet just draw the new // position now setScrollPosition(newPosition, 0f); return; } final int startScrollX = getScrollX(); final int targetScrollX = calculateScrollXForTab(newPosition, 0); final int duration = ANIMATION_DURATION; if (startScrollX != targetScrollX) { final Animation animation = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { final float value = lerp(startScrollX, targetScrollX, interpolatedTime); scrollTo((int) value, 0); } }; animation.setInterpolator(INTERPOLATOR); animation.setDuration(duration); startAnimation(animation); } // Now animate the indicator mTabStrip.animateIndicatorToPosition(newPosition, duration); }
From source file:com.brandroidtools.filemanager.fragments.NavigationFragment.java
/** * Method that changes the current directory of the view. * * @param newDir The new directory location * @param addToHistory Add the directory to history * @param reload Force the reload of the data * @param useCurrent If this method must use the actual data (for back actions) * @param searchInfo The search information (if calling activity is {@link "SearchActivity"}) * @param scrollTo If not null, then listview must scroll to this item *///w w w. j ava 2s .c om private void changeCurrentDir(final String newDir, final boolean addToHistory, final boolean reload, final boolean useCurrent, final SearchInfoParcelable searchInfo, final FileSystemObject scrollTo) { // Check navigation security (don't allow to go outside the ChRooted environment if one // is created) final String fNewDir = checkChRootedNavigation(newDir); synchronized (this.mSync) { //Check that it is really necessary change the directory if (!reload && this.mCurrentDir != null && this.mCurrentDir.compareTo(fNewDir) == 0) { return; } final boolean hasChanged = !(this.mCurrentDir != null && this.mCurrentDir.compareTo(fNewDir) == 0); final boolean isNewHistory = (this.mCurrentDir != null); //Execute the listing in a background process AsyncTask<String, Integer, List<FileSystemObject>> task = new AsyncTask<String, Integer, List<FileSystemObject>>() { /** * {@inheritDoc} */ @Override protected List<FileSystemObject> doInBackground(String... params) { try { //Reset the custom title view and returns to breadcrumb if (NavigationFragment.this.mTitle != null) { NavigationFragment.this.mTitle.post(new Runnable() { @Override public void run() { try { NavigationFragment.this.mTitle.restoreView(); } catch (Exception e) { e.printStackTrace(); } } }); } //Start of loading data if (NavigationFragment.this.mBreadcrumb != null) { try { NavigationFragment.this.mBreadcrumb.startLoading(); } catch (Throwable ex) { /**NON BLOCK**/ } } //Get the files, resolve links and apply configuration //(sort, hidden, ...) List<FileSystemObject> files = NavigationFragment.this.mFiles; if (!useCurrent) { files = CommandHelper.listFiles(mActivity, fNewDir, null); } return files; } catch (final ConsoleAllocException e) { //Show exception and exists mNavigationViewHolder.post(new Runnable() { @Override public void run() { Log.e(TAG, mActivity.getString(R.string.msgs_cant_create_console), e); DialogHelper.showToast(mActivity, R.string.msgs_cant_create_console, Toast.LENGTH_LONG); mActivity.finish(); } }); return null; } catch (Exception ex) { //End of loading data if (NavigationFragment.this.mBreadcrumb != null) { try { NavigationFragment.this.mBreadcrumb.endLoading(); } catch (Throwable ex2) { /**NON BLOCK**/ } } //Capture exception (attach task, and use listener to do the anim) ExceptionUtil.attachAsyncTask(ex, new AsyncTask<Object, Integer, Boolean>() { private List<FileSystemObject> mTaskFiles = null; @Override @SuppressWarnings({ "unchecked", "unqualified-field-access" }) protected Boolean doInBackground(Object... taskParams) { mTaskFiles = (List<FileSystemObject>) taskParams[0]; return Boolean.TRUE; } @Override @SuppressWarnings("unqualified-field-access") protected void onPostExecute(Boolean result) { if (!result.booleanValue()) { return; } onPostExecuteTask(mTaskFiles, addToHistory, isNewHistory, hasChanged, searchInfo, fNewDir, scrollTo); } }); final ExceptionUtil.OnRelaunchCommandResult exListener = new ExceptionUtil.OnRelaunchCommandResult() { @Override public void onSuccess() { // Do animation fadeEfect(false); } @Override public void onFailed(Throwable cause) { // Do animation fadeEfect(false); } @Override public void onCancelled() { // Do animation fadeEfect(false); } }; ExceptionUtil.translateException(mActivity, ex, false, true, exListener); } return null; } /** * {@inheritDoc} */ @Override protected void onPreExecute() { // Do animation fadeEfect(true); } /** * {@inheritDoc} */ @Override protected void onPostExecute(List<FileSystemObject> files) { if (files != null) { onPostExecuteTask(files, addToHistory, isNewHistory, hasChanged, searchInfo, fNewDir, scrollTo); // Do animation fadeEfect(false); } } /** * Method that performs a fade animation. * * @param out Fade out (true); Fade in (false) */ void fadeEfect(final boolean out) { mActivity.runOnUiThread(new Runnable() { @Override public void run() { Animation fadeAnim = out ? new AlphaAnimation(1, 0) : new AlphaAnimation(0, 1); fadeAnim.setDuration(50L); fadeAnim.setFillAfter(true); fadeAnim.setInterpolator(new AccelerateInterpolator()); mNavigationViewHolder.startAnimation(fadeAnim); } }); } }; task.execute(fNewDir); } }
From source file:android.support.v7.app.MediaRouteControllerDialog.java
private void animateLayoutHeight(final View view, int targetHeight) { final int startValue = getLayoutHeight(view); final int endValue = targetHeight; Animation anim = new Animation() { @Override//from w w w . j a va 2 s . co m protected void applyTransformation(float interpolatedTime, Transformation t) { int height = startValue - (int) ((startValue - endValue) * interpolatedTime); setLayoutHeight(view, height); } }; anim.setDuration(mGroupListAnimationDurationMs); if (android.os.Build.VERSION.SDK_INT >= 21) { anim.setInterpolator(mInterpolator); } view.startAnimation(anim); }
From source file:cn.xiaocool.hongyunschool.view.MaterialProgressDrawable.java
private void setupAnimators() { final Ring ring = mRing; final Animation finishRingAnimation = new Animation() { public void applyTransformation(float interpolatedTime, Transformation t) { // shrink back down and complete a full rotation before starting // other circles // Rotation goes between [0..1]. float targetRotation = (float) (Math.floor(ring.getStartingRotation() / MAX_PROGRESS_ARC) + 1f); final float startTrim = ring.getStartingStartTrim() + (ring.getStartingEndTrim() - ring.getStartingStartTrim()) * interpolatedTime; ring.setStartTrim(startTrim); final float rotation = ring.getStartingRotation() + ((targetRotation - ring.getStartingRotation()) * interpolatedTime); ring.setRotation(rotation);//from w w w . ja v a 2 s . com ring.setArrowScale(1 - interpolatedTime); } }; finishRingAnimation.setInterpolator(EASE_INTERPOLATOR); finishRingAnimation.setDuration(ANIMATION_DURATION / 2); finishRingAnimation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { } @Override public void onAnimationEnd(Animation animation) { ring.goToNextColor(); ring.storeOriginals(); ring.setShowArrow(false); mParent.startAnimation(mAnimation); } @Override public void onAnimationRepeat(Animation animation) { } }); final Animation animation = new Animation() { @Override public void applyTransformation(float interpolatedTime, Transformation t) { // The minProgressArc is calculated from 0 to create an angle // that // matches the stroke width. final float minProgressArc = (float) Math .toRadians(ring.getStrokeWidth() / (2 * Math.PI * ring.getCenterRadius())); final float startingEndTrim = ring.getStartingEndTrim(); final float startingTrim = ring.getStartingStartTrim(); final float startingRotation = ring.getStartingRotation(); // Offset the minProgressArc to where the endTrim is located. final float minArc = MAX_PROGRESS_ARC - minProgressArc; final float endTrim = startingEndTrim + (minArc * START_CURVE_INTERPOLATOR.getInterpolation(interpolatedTime)); ring.setEndTrim(endTrim); final float startTrim = startingTrim + (MAX_PROGRESS_ARC * END_CURVE_INTERPOLATOR.getInterpolation(interpolatedTime)); ring.setStartTrim(startTrim); final float rotation = startingRotation + (0.25f * interpolatedTime); ring.setRotation(rotation); float groupRotation = ((720.0f / NUM_POINTS) * interpolatedTime) + (720.0f * (mRotationCount / NUM_POINTS)); setRotation(groupRotation); } }; animation.setRepeatCount(Animation.INFINITE); animation.setRepeatMode(Animation.RESTART); animation.setInterpolator(LINEAR_INTERPOLATOR); animation.setDuration(ANIMATION_DURATION); animation.setAnimationListener(new Animation.AnimationListener() { @Override public void onAnimationStart(Animation animation) { mRotationCount = 0; } @Override public void onAnimationEnd(Animation animation) { // do nothing } @Override public void onAnimationRepeat(Animation animation) { ring.storeOriginals(); ring.goToNextColor(); ring.setStartTrim(ring.getEndTrim()); mRotationCount = (mRotationCount + 1) % (NUM_POINTS); } }); mFinishAnimation = finishRingAnimation; mAnimation = animation; }
From source file:net.rossharper.coloredtablayout.TabLayout.java
private void animateToTab(int newPosition) { clearAnimation();//from www .ja v a2s . c o m if (newPosition == Tab.INVALID_POSITION) { return; } if (getWindowToken() == null || !ViewCompat.isLaidOut(this)) { // If we don't have a window token, or we haven't been laid out yet just draw the new // position now setScrollPosition(newPosition, 0f); return; } final int startScrollX = getScrollX(); final int targetScrollX = calculateScrollXForTab(newPosition, 0); final int duration = ANIMATION_DURATION; if (startScrollX != targetScrollX) { final Animation animation = new Animation() { @Override protected void applyTransformation(float interpolatedTime, Transformation t) { final float value = lerp(startScrollX, targetScrollX, interpolatedTime); scrollTo((int) value, 0); } }; animation.setInterpolator(INTERPOLATOR); animation.setDuration(duration); startAnimation(animation); } // Now animate the indicator mTabStrip.animateIndicatorToPosition(newPosition, duration); }