List of usage examples for android.animation ValueAnimator addUpdateListener
public void addUpdateListener(AnimatorUpdateListener listener)
From source file:com.tiancaicc.springfloatingactionmenu.SpringFloatingActionMenu.java
private void fadeIn() { int colorFrom = Color.parseColor("#00000000"); int colorTo = Color.parseColor("#40000000"); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(250); // milliseconds colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override//w ww . j a v a 2s . c o m public void onAnimationUpdate(ValueAnimator animator) { setBackgroundColor((int) animator.getAnimatedValue()); } }); colorAnimation.start(); }
From source file:com.tiancaicc.springfloatingactionmenu.SpringFloatingActionMenu.java
public void fadeOut() { int colorFrom = Color.parseColor("#40000000"); int colorTo = Color.parseColor("#00000000"); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), colorFrom, colorTo); colorAnimation.setDuration(250); // milliseconds colorAnimation.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override//from w w w . j a v a 2 s. co m public void onAnimationUpdate(ValueAnimator animator) { setBackgroundColor((int) animator.getAnimatedValue()); } }); colorAnimation.start(); }
From source file:com.rks.musicx.ui.fragments.PlayingViews.Playing1Fragment.java
@Override protected void playingView() { if (getMusicXService() != null) { String title = getMusicXService().getsongTitle(); String artist = getMusicXService().getsongArtistName(); SongTitle.setText(title);/*from www . j a v a2 s .c om*/ SongTitle.setSelected(true); SongTitle.setEllipsize(TextUtils.TruncateAt.MARQUEE); SongArtist.setText(artist); Helper.rotationAnim(playpausebutton); Helper.rotationAnim(mAlbumCoverView); mSeekBar.setOnSeekBarChangeListener(new CircularSeekBar.OnCircularSeekBarChangeListener() { @Override public void onProgressChanged(CircularSeekBar circularSeekBar, int progress, boolean fromUser) { if (fromUser && getMusicXService() != null && (getMusicXService().isPlaying() || getMusicXService().isPaused())) { getMusicXService().seekto(circularSeekBar.getProgress()); } } @Override public void onStopTrackingTouch(CircularSeekBar seekBar) { } @Override public void onStartTrackingTouch(CircularSeekBar seekBar) { } }); int duration = getMusicXService().getDuration(); if (duration != -1) { mSeekBar.setMax(duration); TotalDur.setText(Helper.durationCalculator(duration)); } LyricsHelper.LoadLyrics(getContext(), title, artist, getMusicXService().getsongAlbumName(), getMusicXService().getsongData(), lrcView); // NetworkHelper.absolutesLyrics(getContext(),artist, title, getMusicXService().getsongAlbumName(), getMusicXService().getsongData(), lrcView); updateQueuePos(getMusicXService().returnpos()); bitmap = new bitmap() { @Override public void bitmapwork(Bitmap bitmap) { ArtworkUtils.blurPreferances(getContext(), bitmap, blur_artowrk); mAlbumCoverView.setImageBitmap(bitmap); } @Override public void bitmapfailed(Bitmap bitmap) { ArtworkUtils.blurPreferances(getContext(), bitmap, blur_artowrk); mAlbumCoverView.setImageBitmap(bitmap); } }; palette = new palette() { @Override public void palettework(Palette palette) { final int[] colors = Helper.getAvailableColor(getContext(), palette); if (getActivity() == null || getActivity().getWindow() == null) { return; } getActivity().getWindow().setStatusBarColor(colors[0]); getActivity().getWindow().setNavigationBarColor(colors[0]); ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), ((ColorDrawable) Playing3view.getBackground()).getColor(), colors[0]); colorAnimation.setDuration(250); // milliseconds colorAnimation.addUpdateListener( animator -> Playing3view.setBackgroundColor((int) animator.getAnimatedValue())); colorAnimation.start(); if (Extras.getInstance().artworkColor()) { colorMode(colors[0]); } else { colorMode(accentColor); } } }; } }
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// w w w.ja v a 2 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:nl.eduvpn.app.fragment.HomeFragment.java
/** * Checks if the loading has finished.//from w w w .j a va 2 s . com * If yes, it hides the loading animation. * If there were any errors, it will display a warning bar as well. * * @param adapter The adapter which the items are being loaded into. */ private synchronized void _checkLoadingFinished(final ProfileAdapter adapter) { _pendingInstanceCount--; if (_pendingInstanceCount <= 0 && _problematicInstances.size() == 0) { if (_loadingBar == null) { Log.d(TAG, "Layout has been destroyed already."); return; } float startHeight = _loadingBar.getHeight(); ValueAnimator animator = ValueAnimator.ofFloat(startHeight, 0); animator.setDuration(600); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator animation) { float fraction = animation.getAnimatedFraction(); float alpha = 1f - fraction; float height = (Float) animation.getAnimatedValue(); if (_loadingBar != null) { _loadingBar.setAlpha(alpha); _loadingBar.getLayoutParams().height = (int) height; _loadingBar.requestLayout(); } } }); animator.start(); } else if (_pendingInstanceCount <= 0) { if (_displayText == null) { Log.d(TAG, "Layout has been destroyed already."); return; } // There are some warnings _displayText.setText(R.string.could_not_fetch_all_profiles); _warningIcon.setVisibility(View.VISIBLE); _progressBar.setVisibility(View.GONE); _loadingBar.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Display a dialog with all the warnings _currentDialog = ErrorDialog.show(getContext(), getString(R.string.warnings_list), getString(R.string.instance_access_warning_message), new ErrorDialog.InstanceWarningHandler() { @Override public List<Instance> getInstances() { return _problematicInstances; } @Override public void retryInstance(Instance instance) { _warningIcon.setVisibility(View.GONE); _progressBar.setVisibility(View.VISIBLE); _displayText.setText(R.string.loading_available_profiles); SavedAuthState savedAuthState = _historyService.getSavedToken(instance); if (savedAuthState == null) { // Should never happen _currentDialog = ErrorDialog.show(getContext(), R.string.error_dialog_title, R.string.data_removed); } else { // Retry _problematicInstances.remove(instance); _fillList(adapter, Collections.singletonList(savedAuthState)); } } @Override public void loginInstance(final Instance instance) { // Find the auth state for the instance and then retry AuthState authState = _historyService.getCachedAuthState(instance); _apiService.getJSON( instance.getSanitizedBaseURI() + Constants.API_DISCOVERY_POSTFIX, authState, new APIService.Callback<JSONObject>() { @Override public void onSuccess(JSONObject result) { try { DiscoveredAPI discoveredAPI = _serializerService .deserializeDiscoveredAPI(result); // Cache the result _historyService.cacheDiscoveredAPI( instance.getSanitizedBaseURI(), discoveredAPI); _problematicInstances.remove(instance); Activity activity = getActivity(); if (activity != null && !activity.isFinishing()) { _connectionService.initiateConnection(getActivity(), instance, discoveredAPI); } } catch (SerializerService.UnknownFormatException ex) { Log.e(TAG, "Error parsing discovered API!", ex); _currentDialog = ErrorDialog.show(getContext(), R.string.error_dialog_title, R.string.provider_incorrect_format); } } @Override public void onError(String errorMessage) { Log.e(TAG, "Error while fetching discovered API: " + errorMessage); DiscoveredAPI discoveredAPI = _historyService .getCachedDiscoveredAPI(instance.getSanitizedBaseURI()); Activity activity = getActivity(); if (discoveredAPI != null && activity != null && !activity.isFinishing()) { _connectionService.initiateConnection(activity, instance, discoveredAPI); } else { _currentDialog = ErrorDialog.show(getContext(), R.string.error_dialog_title, R.string.provider_not_found_retry); } } }); } @Override public void removeInstance(Instance instance) { _historyService.removeAllDataForInstance(instance); _problematicInstances.remove(instance); getActivity().runOnUiThread(() -> _checkLoadingFinished(adapter)); } }); } }); } }
From source file:com.rks.musicx.ui.fragments.PlayingViews.Playing4Fragment.java
@Override protected void playingView() { if (getMusicXService() != null) { String title = getMusicXService().getsongTitle(); String artist = getMusicXService().getsongArtistName(); songTitle.setText(title);//from ww w . ja v a 2 s . c o m songTitle.setSelected(true); songTitle.setEllipsize(TextUtils.TruncateAt.MARQUEE); songArtist.setText(artist); Helper.rotationAnim(albumArtwork); Helper.rotationAnim(playpausebutton); int dur = getMusicXService().getDuration(); seekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() { @Override public void onProgressChanged(SeekBar seekBar, int i, boolean b) { if (b && getMusicXService() != null && (getMusicXService().isPlaying() || getMusicXService().isPaused())) { getMusicXService().seekto(seekBar.getProgress()); } } @Override public void onStartTrackingTouch(SeekBar seekBar) { } @Override public void onStopTrackingTouch(SeekBar seekBar) { } }); if (dur != -1) { seekbar.setMax(dur); totalDur.setText(Helper.durationCalculator(dur)); } updateQueuePos(getMusicXService().returnpos()); LyricsHelper.LoadLyrics(getContext(), title, artist, getMusicXService().getsongAlbumName(), getMusicXService().getsongData(), lrcview); bitmap = new bitmap() { @Override public void bitmapwork(Bitmap bitmap) { albumArtwork.setImageBitmap(bitmap); ArtworkUtils.blurPreferances(getContext(), bitmap, blurArtwork); ArtworkUtils.blurPreferances(getContext(), bitmap, blurQArtwork); } @Override public void bitmapfailed(Bitmap bitmap) { albumArtwork.setImageBitmap(bitmap); ArtworkUtils.blurPreferances(getContext(), bitmap, blurArtwork); ArtworkUtils.blurPreferances(getContext(), bitmap, blurQArtwork); } }; palette = new palette() { @Override public void palettework(Palette palette) { final int[] colors = Helper.getAvailableColor(getContext(), palette); if (Extras.getInstance().artworkColor()) { colorMode(colors[0]); } else { colorMode(accentColor); } ValueAnimator colorAnimation = ValueAnimator.ofObject(new ArgbEvaluator(), ((ColorDrawable) controlsBg.getBackground()).getColor(), colors[0]); colorAnimation.setDuration(250); // milliseconds colorAnimation.addUpdateListener( animator -> controlsBg.setBackgroundColor((int) animator.getAnimatedValue())); colorAnimation.start(); } }; if (mVisualizer != null) { if (vizualview != null) { vizualview.setEnabled(true); } mVisualizer.setEnabled(true); } } }
From source file:com.justplay1.shoppist.features.search.widget.FloatingSearchView.java
private void fadeIn(boolean enter) { ValueAnimator backgroundAnim; if (Build.VERSION.SDK_INT >= 19) { backgroundAnim = ObjectAnimator.ofInt(backgroundDrawable, "alpha", enter ? 255 : 0); } else {//from w ww .ja v a 2s. c o m backgroundAnim = ValueAnimator.ofInt(enter ? 0 : 255, enter ? 255 : 0); backgroundAnim.addUpdateListener(animation -> { int value = (Integer) animation.getAnimatedValue(); backgroundDrawable.setAlpha(value); }); } backgroundAnim.setDuration(enter ? DEFAULT_DURATION_ENTER : DEFAULT_DURATION_EXIT); backgroundAnim.setInterpolator(enter ? DECELERATE : ACCELERATE); backgroundAnim.start(); Drawable icon = unwrap(getIcon()); if (icon != null) { ObjectAnimator iconAnim = ObjectAnimator.ofFloat(icon, "progress", enter ? 1 : 0); iconAnim.setDuration(backgroundAnim.getDuration()); iconAnim.setInterpolator(backgroundAnim.getInterpolator()); iconAnim.start(); } }
From source file:com.pitchedapps.primenumbercalculator.Calculator.java
License:asdf
private void onResult(final String result) { // Calculate the values needed to perform the scale and translation animations, // accounting for how the scale will affect the final position of the text. final float resultScale = mInputEditText.getVariableTextSize(result) / mResultEditText.getTextSize(); final float resultTranslationX = (1.0f - resultScale) * (mResultEditText.getWidth() / 2.0f - mResultEditText.getPaddingEnd()); final float resultTranslationY = (1.0f - resultScale) * //TODO delete unnecessary lines for animation (mResultEditText.getHeight() / 2.0f - mResultEditText.getPaddingBottom()) + (mInputEditText.getBottom() - mResultEditText.getBottom()) + (mResultEditText.getPaddingBottom() - mInputEditText.getPaddingBottom()); final float inputTranslationY = -mInputEditText.getBottom(); // Use a value animator to fade to the final text color over the course of the animation. final int resultTextColor = mResultEditText.getCurrentTextColor(); final int inputEditText = mInputEditText.getCurrentTextColor(); final ValueAnimator textColorAnimator = ValueAnimator.ofObject(new ArgbEvaluator(), resultTextColor, inputEditText);//from www . j a v a 2 s . co m textColorAnimator.addUpdateListener(new AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { mResultEditText.setTextColor((int) valueAnimator.getAnimatedValue()); } }); final AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(textColorAnimator, ObjectAnimator.ofFloat(mResultEditText, View.SCALE_X, resultScale), ObjectAnimator.ofFloat(mResultEditText, View.SCALE_Y, resultScale), ObjectAnimator.ofFloat(mResultEditText, View.TRANSLATION_X, resultTranslationX), ObjectAnimator.ofFloat(mResultEditText, View.TRANSLATION_Y, resultTranslationY), ObjectAnimator.ofFloat(mInputEditText, View.TRANSLATION_Y, inputTranslationY)); animatorSet.setDuration(getResources().getInteger(android.R.integer.config_longAnimTime)); animatorSet.setInterpolator(new AccelerateDecelerateInterpolator()); animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationStart(Animator animation) { mResultEditText.setText(result); } @Override public void onAnimationEnd(Animator animation) { // Reset all of the values modified during the animation. mResultEditText.setTextColor(resultTextColor); mResultEditText.setScaleX(1.0f); mResultEditText.setScaleY(1.0f); mResultEditText.setTranslationX(0.0f); mResultEditText.setTranslationY(0.0f); mInputEditText.setTranslationY(0.0f); // Finally update the input to use the current result. mInputEditText.setText(result); //TODO figure out how to reset after equal sign without changing input text mResultEditText.getEditableText().clear(); setState(CalculatorState.RESULT); mCurrentAnimator = null; } }); mCurrentAnimator = animatorSet; animatorSet.start(); }
From source file:co.ceryle.segmentedbutton.SegmentedButtonGroup.java
private void expand(final View v, Interpolator interpolator, int duration, int targetWidth) { int prevWidth = v.getWidth(); ValueAnimator valueAnimator = ValueAnimator.ofInt(prevWidth, targetWidth); valueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override/*from w w w . j ava 2 s .c om*/ public void onAnimationUpdate(ValueAnimator animation) { v.getLayoutParams().width = (int) animation.getAnimatedValue(); v.requestLayout(); } }); valueAnimator.setInterpolator(interpolator); valueAnimator.setDuration(duration); valueAnimator.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/*from w w w. j av a 2s. 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; }