Example usage for android.view.animation Animation setDuration

List of usage examples for android.view.animation Animation setDuration

Introduction

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

Prototype

public void setDuration(long durationMillis) 

Source Link

Document

How long this animation should last.

Usage

From source file:de.Maxr1998.xposed.maxlock.ui.settings.appslist.AppListAdapter.java

@Override
public void onBindViewHolder(final AppsListViewHolder hld, final int position) {
    final String sTitle = (String) mItemList.get(position).get("title");
    final String key = (String) mItemList.get(position).get("key");
    final Drawable dIcon = (Drawable) mItemList.get(position).get("icon");

    hld.appName.setText(sTitle);//from  w w w.j  av  a 2 s  .c  om
    hld.appIcon.setImageDrawable(dIcon);

    if (prefsPackages.getBoolean(key, false)) {
        hld.toggle.setChecked(true);
        hld.options.setVisibility(View.VISIBLE);
    } else {
        hld.toggle.setChecked(false);
        hld.options.setVisibility(View.GONE);
    }

    hld.appIcon.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (key.equals("com.android.packageinstaller"))
                return;
            Intent it = mContext.getPackageManager().getLaunchIntentForPackage(key);
            it.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
            mContext.startActivity(it);
        }
    });

    hld.options.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // AlertDialog View
            // Fake die checkbox
            View checkBoxView = View.inflate(mContext, R.layout.per_app_settings, null);
            CheckBox fakeDie = (CheckBox) checkBoxView.findViewById(R.id.cb_fake_die);
            fakeDie.setChecked(prefsPackages.getBoolean(key + "_fake", false));
            fakeDie.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    CheckBox cb = (CheckBox) v;
                    boolean value = cb.isChecked();
                    prefsPackages.edit().putBoolean(key + "_fake", value).commit();
                }
            });
            // Custom password checkbox
            CheckBox customPassword = (CheckBox) checkBoxView.findViewById(R.id.cb_custom_pw);
            customPassword.setChecked(prefsPerApp.contains(key));
            customPassword.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    CheckBox cb = (CheckBox) v;
                    boolean checked = cb.isChecked();
                    if (checked) {
                        dialog.dismiss();
                        final AlertDialog.Builder choose_lock = new AlertDialog.Builder(mContext);
                        CharSequence[] cs = new CharSequence[] {
                                mContext.getString(R.string.pref_locking_type_password),
                                mContext.getString(R.string.pref_locking_type_pin),
                                mContext.getString(R.string.pref_locking_type_knockcode),
                                mContext.getString(R.string.pref_locking_type_pattern) };
                        choose_lock.setItems(cs, new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialogInterface, int i) {
                                dialogInterface.dismiss();
                                Fragment frag = new Fragment();
                                switch (i) {
                                case 0:
                                    Util.setPassword(mContext, key);
                                    break;
                                case 1:
                                    frag = new PinSetupFragment();
                                    break;
                                case 2:
                                    frag = new KnockCodeSetupFragment();
                                    break;
                                case 3:
                                    Intent intent = new Intent(LockPatternActivity.ACTION_CREATE_PATTERN, null,
                                            mContext, LockPatternActivity.class);
                                    mFragment.startActivityForResult(intent, Util.getPatternCode(position));
                                    break;
                                }
                                if (i == 1 || i == 2) {
                                    Bundle b = new Bundle(1);
                                    b.putString(Common.INTENT_EXTRAS_CUSTOM_APP, key);
                                    frag.setArguments(b);
                                    ((SettingsActivity) mContext).getSupportFragmentManager().beginTransaction()
                                            .replace(R.id.frame_container, frag).addToBackStack(null).commit();
                                }
                            }
                        }).show();
                    } else
                        prefsPerApp.edit().remove(key).remove(key + Common.APP_KEY_PREFERENCE).apply();

                }
            });
            // Finish dialog
            dialog = new AlertDialog.Builder(mContext)
                    .setTitle(mContext.getString(R.string.dialog_title_settings)).setIcon(dIcon)
                    .setView(checkBoxView)
                    .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dlg, int id) {
                            dlg.dismiss();
                        }
                    }).setNeutralButton(R.string.dialog_button_exclude_activities,
                            new DialogInterface.OnClickListener() {
                                @Override
                                public void onClick(DialogInterface dialogInterface, int i) {
                                    new ActivityLoader().execute(key);
                                }
                            })
                    .show();
        }
    });
    hld.toggle.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            RadioButton rb = (RadioButton) v;
            boolean value = prefsPackages.getBoolean(key, false);

            if (!value) {
                prefsPackages.edit().putBoolean(key, true).commit();
                AnimationSet anim = new AnimationSet(true);
                anim.addAnimation(AnimationUtils.loadAnimation(mContext, R.anim.appslist_settings_rotate));
                anim.addAnimation(AnimationUtils.loadAnimation(mContext, R.anim.appslist_settings_translate));
                hld.options.startAnimation(anim);
                hld.options.setVisibility(View.VISIBLE);
                rb.setChecked(true);
            } else {
                prefsPackages.edit().remove(key).commit();
                rb.setChecked(true);

                AnimationSet animOut = new AnimationSet(true);
                animOut.addAnimation(
                        AnimationUtils.loadAnimation(mContext, R.anim.appslist_settings_rotate_out));
                animOut.addAnimation(
                        AnimationUtils.loadAnimation(mContext, R.anim.appslist_settings_translate_out));
                animOut.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        animation = new TranslateAnimation(0.0f, 0.0f, 0.0f, 0.0f);
                        animation.setDuration(1);
                        hld.options.startAnimation(animation);
                        hld.options.setVisibility(View.GONE);
                        hld.options.clearAnimation();
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });
                hld.options.startAnimation(animOut);
            }

            notifyDataSetChanged();
        }

    });
}

From source file:com.sohu.xzd.widget.SwipeRefresh.java

private void startAlphaInAnimation(AnimationListener listener) {
    mRefreshHeader.setVisibility(View.VISIBLE);
    Animation scaleAnimation = new Animation() {
        @Override/*from w  ww  .j  av a2  s  .c o  m*/
        public void applyTransformation(float interpolatedTime, Transformation t) {
            //                setAnimationProgress(interpolatedTime);
        }
    };
    scaleAnimation.setDuration(200L);
    if (listener != null) {
        mRefreshHeader.setAnimationListener(listener);
    }
    mRefreshHeader.clearAnimation();
    mRefreshHeader.startAnimation(scaleAnimation);
}

From source file:com.soomla.example.ExampleSocialActivity.java

private void showView(final View view, boolean show) {
    final Animation animation = show ? AnimationUtils.makeInAnimation(view.getContext(), true)
            : AnimationUtils.makeOutAnimation(view.getContext(), true);
    animation.setFillAfter(true);//w w w .j  av  a  2 s .  co m
    animation.setDuration(500);
    view.startAnimation(animation);
}

From source file:com.vaguehope.onosendai.widget.SidebarLayout.java

protected void animateSidebar(final boolean gotoOpen) {
    final View host = getHostView();
    if (host.getAnimation() != null)
        return;/*from  w  w w .ja va  2 s .  c  o  m*/

    final float deltaX;
    final Animation animation;
    if (gotoOpen) {
        deltaX = host.getTranslationX() > 0 ? -host.getTranslationX() : -this.sidebarWidth;
        animation = new TranslateAnimation(0, deltaX, 0, 0);
        animation.setAnimationListener(this.openListener);
    } else {
        deltaX = this.sidebarWidth - host.getTranslationX();
        animation = new TranslateAnimation(0, deltaX, 0, 0);
        animation.setAnimationListener(this.closeListener);
    }
    animation.setDuration((long) (SLIDE_DURATION * (Math.abs(deltaX) / this.sidebarWidth)));
    animation.setFillAfter(true);
    animation.setFillEnabled(true);
    host.startAnimation(animation);
}

From source file:com.pitchedapps.primenumbercalculator.Calculator.java

License:asdf

public Animation fadeOutAnimation() {
    Animation fadeOutAnimation = AnimationUtils.loadAnimation(this, android.R.anim.fade_out);
    fadeOutAnimation.setDuration(200);
    return fadeOutAnimation;
}

From source file:de.grobox.liberario.fragments.DirectionsFragment.java

private void swapLocations() {
    Animation slideUp = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
            0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, -1.0f);

    slideUp.setDuration(400);
    slideUp.setFillAfter(true);/*  w w w  .  j  a v  a2 s .  c o  m*/
    slideUp.setFillEnabled(true);
    ui.to.startAnimation(slideUp);

    Animation slideDown = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF,
            0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 1.0f);

    slideDown.setDuration(400);
    slideDown.setFillAfter(true);
    slideDown.setFillEnabled(true);
    ui.from.startAnimation(slideDown);

    slideUp.setAnimationListener(new Animation.AnimationListener() {

        @Override
        public void onAnimationStart(Animation animation) {
        }

        @Override
        public void onAnimationRepeat(Animation animation) {
        }

        @Override
        public void onAnimationEnd(Animation animation) {
            // swap location objects
            Location tmp = ui.to.getLocation();
            if (!ui.from.isSearching()) {
                ui.to.setLocation(ui.from.getLocation(),
                        getDrawableForLocation(getContext(), ui.from.getLocation()));
            } else {
                // TODO: GPS currently only supports from location, so don't swap it for now
                ui.to.clearLocation();
            }
            ui.from.setLocation(tmp, getDrawableForLocation(getContext(), tmp));

            ui.from.clearAnimation();
            ui.to.clearAnimation();
        }
    });
}

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  a  v  a  2s.c om*/
            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.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  w  w. j a v a  2 s.  co m
            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.example.haber.ui.activity.TabbedActivity.java

private void switchStatus() {
    if (currentStatus == COMMON_STATUS) {
        if (sensorManager != null)
            sensorManager.unregisterListener(sensorListener, sensor);
        if (tbDial.isChecked())
            tbDial.setChecked(false);/*from  w w  w.  j  a v a  2  s .c  om*/
        if (tbConsoleControl.isChecked())
            tbConsoleControl.setChecked(false);
        if (layoutDial.getVisibility() != View.GONE) {
            Animation animation = new TranslateAnimation(0, 0, 0,
                    200 * metrics.density + 0.5f + displayHeight * 0.32f);
            animation.setDuration(200);
            layoutDial.startAnimation(animation);
            layoutDial.setVisibility(View.GONE);
        }
        if (containConsoleControl.getVisibility() != View.GONE)
            containConsoleControl.setVisibility(View.GONE);
        if (containViewPager.getVisibility() == View.GONE)
            containViewPager.setVisibility(View.VISIBLE);
    } else if (currentStatus == DIAL_STATUS) {

        if (!tbDial.isChecked())
            tbDial.setChecked(true);
        if (tbConsoleControl.isChecked())
            tbConsoleControl.setChecked(false);
        if (containConsoleControl.getVisibility() != View.GONE)
            containConsoleControl.setVisibility(View.GONE);
        if (containViewPager.getVisibility() != View.VISIBLE)
            containViewPager.setVisibility(View.VISIBLE);
        if (layoutDial.getVisibility() == View.GONE) {
            layoutDial.setVisibility(View.VISIBLE);
            Animation animation = new TranslateAnimation(0, 0,
                    200 * metrics.density + 0.5f + displayHeight * 0.32f, 0);
            animation.setDuration(300);
            layoutDial.startAnimation(animation);
        }
        sensorManager.unregisterListener(sensorListener, sensor);

    } else {
        sensorManager.registerListener(sensorListener, sensor, SensorManager.SENSOR_DELAY_UI);
        if (tbDial.isChecked())
            tbDial.setChecked(false);
        if (!tbConsoleControl.isChecked())
            tbConsoleControl.setChecked(true);
        if (layoutDial.getVisibility() != View.GONE) {
            Animation animation = new TranslateAnimation(0, 0, 0,
                    200 * metrics.density + 0.5f + displayHeight * 0.32f);
            animation.setDuration(200);
            layoutDial.startAnimation(animation);
            layoutDial.setVisibility(View.GONE);
        }
        if (containViewPager.getVisibility() != View.GONE)
            containViewPager.setVisibility(View.GONE);
        if (containConsoleControl.getVisibility() == View.GONE)
            containConsoleControl.setVisibility(View.VISIBLE);
    }
}

From source file:de.grobox.liberario.DirectionsFragment.java

private void pressGpsButton() {
    List<String> providers = locationManager.getProviders(true);

    for (String provider : providers) {
        // Register the listener with the Location Manager to receive location updates
        locationManager.requestSingleUpdate(provider, this, null);

        Log.d(getClass().getSimpleName(), "Register provider for location updates: " + provider);
    }/* w w w.  j a v a2 s  . c  om*/

    // check if there is a non-passive provider available
    if (providers.size() == 0
            || (providers.size() == 1 && providers.get(0).equals(LocationManager.PASSIVE_PROVIDER))) {
        removeUpdates();
        Toast.makeText(getActivity(), getResources().getString(R.string.error_no_location_provider),
                Toast.LENGTH_LONG).show();

        return;
    }

    // show GPS button blinking
    final Animation animation = new AlphaAnimation(1, 0);
    animation.setDuration(500);
    animation.setInterpolator(new LinearInterpolator());
    animation.setRepeatCount(Animation.INFINITE);
    animation.setRepeatMode(Animation.REVERSE);
    mView.findViewById(R.id.fromStatusButton).setAnimation(animation);

    mGpsPressed = true;
    gps_loc = null;
}