Example usage for android.animation ValueAnimator setDuration

List of usage examples for android.animation ValueAnimator setDuration

Introduction

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

Prototype

@Override
public ValueAnimator setDuration(long duration) 

Source Link

Document

Sets the length of the animation.

Usage

From source file:com.commonsware.cwac.crossport.design.widget.BaseTransientBottomBar.java

void animateViewIn() {
    if (Build.VERSION.SDK_INT >= 12) {
        final int viewHeight = mView.getHeight();
        if (USE_OFFSET_API) {
            ViewCompat.offsetTopAndBottom(mView, viewHeight);
        } else {/*from w ww . jav a2 s .c om*/
            mView.setTranslationY(viewHeight);
        }
        final ValueAnimator animator = new ValueAnimator();
        animator.setIntValues(viewHeight, 0);
        animator.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR);
        animator.setDuration(ANIMATION_DURATION);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animator) {
                mContentViewCallback.animateContentIn(ANIMATION_DURATION - ANIMATION_FADE_DURATION,
                        ANIMATION_FADE_DURATION);
            }

            @Override
            public void onAnimationEnd(Animator animator) {
                onViewShown();
            }
        });
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            private int mPreviousAnimatedIntValue = viewHeight;

            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                int currentAnimatedIntValue = (int) animator.getAnimatedValue();
                if (USE_OFFSET_API) {
                    ViewCompat.offsetTopAndBottom(mView, currentAnimatedIntValue - mPreviousAnimatedIntValue);
                } else {
                    mView.setTranslationY(currentAnimatedIntValue);
                }
                mPreviousAnimatedIntValue = currentAnimatedIntValue;
            }
        });
        animator.start();
    } else {
        final Animation anim = AnimationUtils.loadAnimation(mView.getContext(), R.anim.design_snackbar_in);
        anim.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR);
        anim.setDuration(ANIMATION_DURATION);
        anim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationEnd(Animation animation) {
                onViewShown();
            }

            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        mView.startAnimation(anim);
    }
}

From source file:com.commonsware.cwac.crossport.design.widget.BaseTransientBottomBar.java

private void animateViewOut(final int event) {
    if (Build.VERSION.SDK_INT >= 12) {
        final ValueAnimator animator = new ValueAnimator();
        animator.setIntValues(0, mView.getHeight());
        animator.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR);
        animator.setDuration(ANIMATION_DURATION);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override//from w ww . j av  a 2 s  .  c  o  m
            public void onAnimationStart(Animator animator) {
                mContentViewCallback.animateContentOut(0, ANIMATION_FADE_DURATION);
            }

            @Override
            public void onAnimationEnd(Animator animator) {
                onViewHidden(event);
            }
        });
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            private int mPreviousAnimatedIntValue = 0;

            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                int currentAnimatedIntValue = (int) animator.getAnimatedValue();
                if (USE_OFFSET_API) {
                    ViewCompat.offsetTopAndBottom(mView, currentAnimatedIntValue - mPreviousAnimatedIntValue);
                } else {
                    mView.setTranslationY(currentAnimatedIntValue);
                }
                mPreviousAnimatedIntValue = currentAnimatedIntValue;
            }
        });
        animator.start();
    } else {
        final Animation anim = AnimationUtils.loadAnimation(mView.getContext(), R.anim.design_snackbar_out);
        anim.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR);
        anim.setDuration(ANIMATION_DURATION);
        anim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationEnd(Animation animation) {
                onViewHidden(event);
            }

            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        mView.startAnimation(anim);
    }
}

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);/*  w w w .j av a2s  .co 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:xyz.klinker.android.article.ArticleScrollListener.java

private void animateBackgroundColor(int from, int to, Interpolator interpolator) {
    final ValueAnimator anim = new ValueAnimator();
    anim.setIntValues(from, to);// ww  w  .  j av a2s.c  o  m
    anim.setEvaluator(new ArgbEvaluator());
    anim.setInterpolator(interpolator);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            toolbar.setBackgroundColor((Integer) valueAnimator.getAnimatedValue());
            statusBar.setBackgroundColor((Integer) valueAnimator.getAnimatedValue());
        }
    });
    anim.addListener(new AnimatorListenerAdapter() {
        @Override
        public void onAnimationEnd(Animator animation) {
            super.onAnimationEnd(animation);
            isUpdatingBackground = false;
        }
    });

    anim.setDuration(ANIMATION_DURATION);
    anim.start();
    isUpdatingBackground = true;
}

From source file:org.xbmc.kore.ui.generic.NavigationDrawerFragment.java

/**
 * Animates the drawerToggle from the hamburger to an arrow or vice versa
 * @param toArrow True, hamburger to arrow, false arrow to hamburger
 *///ww  w  .  ja  va 2s.  co m
public void animateDrawerToggle(final boolean toArrow) {
    float start = toArrow ? 0.0f : 1.0f, end = 1.0f - start;

    ValueAnimator anim = ValueAnimator.ofFloat(start, end);
    anim.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            float slideOffset = (Float) valueAnimator.getAnimatedValue();
            mDrawerToggle.onDrawerSlide(mDrawerLayout, slideOffset);
        }
    });
    anim.setInterpolator(new DecelerateInterpolator());
    anim.setDuration(500);
    anim.start();
}

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

/**
 * perform a fade in animation for showing node content
 *
 * @param node active node/* w w  w. ja va 2 s.  co  m*/
 */
private void fadeIn(final Node<?> node) {
    ValueAnimator animator = ValueAnimator.ofFloat(1);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator animation) {
            for (int i = getChildCount()
                    - (node.hasChildren() ? node.getChildCount() : 1); i < getChildCount(); ++i) {
                getChildAt(i).setAlpha(((Float) animation.getAnimatedValue()));
            }
        }
    });
    animator.setDuration(duration);
    animator.setInterpolator(new FastOutSlowInInterpolator());
    animator.start();
}

From source file:com.android.contacts.activities.ActionBarAdapter.java

private void animateTabHeightChange(int start, int end) {
    if (mPortraitTabs == null) {
        return;/*from   w w w .  j  a  v  a  2s .  c  o m*/
    }
    final ValueAnimator animator = ValueAnimator.ofInt(start, end);
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
        @Override
        public void onAnimationUpdate(ValueAnimator valueAnimator) {
            int value = (Integer) valueAnimator.getAnimatedValue();
            setPortraitTabHeight(value);
        }
    });
    animator.setDuration(100).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 .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:nl.eduvpn.app.fragment.HomeFragment.java

/**
 * Checks if the loading has finished.//from  w  w w  . j  av a2 s .  co m
 * 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.mark.quick.ui.view.snackbar.BaseTransientBottomBar.java

void animateViewIn() {
    if (Build.VERSION.SDK_INT >= 12) {
        //TODO CHANGE ?
        final int viewHeight = -mView.getHeight();
        if (USE_OFFSET_API) {
            ViewCompat.offsetTopAndBottom(mView, viewHeight);
        } else {/*ww  w. j  a va  2 s .c om*/
            mView.setTranslationY(viewHeight);
        }

        final ValueAnimator animator = new ValueAnimator();
        animator.setIntValues(viewHeight, 0);
        animator.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
        animator.setDuration(ANIMATION_DURATION);
        animator.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationStart(Animator animator) {
                mContentViewCallback.animateContentIn(ANIMATION_DURATION - ANIMATION_FADE_DURATION,
                        ANIMATION_FADE_DURATION);
            }

            @Override
            public void onAnimationEnd(Animator animator) {
                onViewShown();
            }
        });
        animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
            private int mPreviousAnimatedIntValue = viewHeight;

            @Override
            public void onAnimationUpdate(ValueAnimator animator) {
                int currentAnimatedIntValue = (int) animator.getAnimatedValue();
                if (USE_OFFSET_API) {
                    ViewCompat.offsetTopAndBottom(mView, currentAnimatedIntValue - mPreviousAnimatedIntValue);
                } else {
                    mView.setTranslationY(currentAnimatedIntValue);
                }
                mPreviousAnimatedIntValue = currentAnimatedIntValue;
            }
        });
        animator.start();
    } else {
        final Animation anim = android.view.animation.AnimationUtils.loadAnimation(mView.getContext(),
                R.anim.design_snackbar_in);
        anim.setInterpolator(AnimationUtils.FAST_OUT_SLOW_IN_INTERPOLATOR);
        anim.setDuration(ANIMATION_DURATION);
        anim.setAnimationListener(new Animation.AnimationListener() {
            @Override
            public void onAnimationEnd(Animation animation) {
                onViewShown();
            }

            @Override
            public void onAnimationStart(Animation animation) {
            }

            @Override
            public void onAnimationRepeat(Animation animation) {
            }
        });
        mView.startAnimation(anim);
    }
}