Example usage for android.view.animation AnimationUtils loadAnimation

List of usage examples for android.view.animation AnimationUtils loadAnimation

Introduction

In this page you can find the example usage for android.view.animation AnimationUtils loadAnimation.

Prototype

public static Animation loadAnimation(Context context, @AnimRes int id) throws NotFoundException 

Source Link

Document

Loads an Animation object from a resource

Usage

From source file:com.handmark.pulltorefresh.library.internal.LoadingLayout.java

public LoadingLayout(final Context context, final Mode mode, final TypedArray attrs) {
    super(context);
    final ViewGroup header = (ViewGroup) LayoutInflater.from(context).inflate(R.layout.pull_to_refresh_header,
            this);
    mMode = mode;//from  w w w . j  a  va  2 s.c o m
    mHeaderText = (TextView) header.findViewById(R.id.pull_to_refresh_text);
    mSubHeaderText = (TextView) header.findViewById(R.id.pull_to_refresh_sub_text);
    mHeaderProgress = (ProgressBar) header.findViewById(R.id.pull_to_refresh_progress);
    mHeaderArrow = (ImageView) header.findViewById(R.id.pull_to_refresh_arrow);
    mRotateAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.pull_to_refresh_rotate);
    audioManager = (AudioManager) context.getSystemService(Activity.AUDIO_SERVICE);
    mPreferences = context.getSharedPreferences(SHARED_PREFERENCES_NAME, Context.MODE_PRIVATE);
    mContext = context;

    switch (mode) {
    case PULL_UP_TO_REFRESH:
        // Load in labels
        mPullLabel = context.getString(R.string.pull_to_refresh_from_bottom_pull_label);
        mRefreshingLabel = context.getString(R.string.pull_to_refresh_from_bottom_refreshing_label);
        mReleaseLabel = context.getString(R.string.pull_to_refresh_from_bottom_release_label);
        rotateArrow();
        break;

    case PULL_DOWN_TO_REFRESH:
    default:
        // Load in labels
        mPullLabel = context.getString(R.string.pull_to_refresh_pull_label);
        mRefreshingLabel = context.getString(R.string.pull_to_refresh_refreshing_label);
        mReleaseLabel = context.getString(R.string.pull_to_refresh_release_label);
        break;
    }

    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderTextColor)) {
        final ColorStateList colors = attrs.getColorStateList(R.styleable.PullToRefresh_ptrHeaderTextColor);
        setTextColor(null != colors ? colors : ColorStateList.valueOf(0xFF000000));
    }
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderSubTextColor)) {
        final ColorStateList colors = attrs.getColorStateList(R.styleable.PullToRefresh_ptrHeaderSubTextColor);
        setSubTextColor(null != colors ? colors : ColorStateList.valueOf(0xFF000000));
    }
    if (attrs.hasValue(R.styleable.PullToRefresh_ptrHeaderBackground)) {
        final Drawable background = attrs.getDrawable(R.styleable.PullToRefresh_ptrHeaderBackground);
        if (null != background) {
            setBackgroundDrawable(background);
        }
    }

    reset();
}

From source file:com.koma.music.detail.DetailsActivity.java

public void init() {
    if (getIntent() != null) {
        mWhichPage = getIntent().getIntExtra(Constants.WHICH_DETAIL_PAGE, Constants.ALBUM_DETAIL);
    }//from   w w w  .  j a  va  2s.c  o m

    setSupportActionBar(mToolbar);

    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    }

    mToolbar.post(new Runnable() {
        @Override
        public void run() {
            Animation animation = AnimationUtils.loadAnimation(DetailsActivity.this, R.anim.toolbar_slide_in);
            animation.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                    mToolbar.setVisibility(View.VISIBLE);
                }

                @Override
                public void onAnimationEnd(Animation animation) {

                }

                @Override
                public void onAnimationRepeat(Animation animation) {

                }
            });
            mToolbar.startAnimation(animation);
        }
    });

    QuickControlFragment quickControlFragment = (QuickControlFragment) getSupportFragmentManager()
            .findFragmentById(R.id.fragment_playback_controls);

    new QuickControlPresenter(quickControlFragment);

    Fragment fragment = getSupportFragmentManager().findFragmentById(R.id.container);

    if (fragment != null) {
        return;
    }

    Bundle bundle;

    switch (mWhichPage) {

    case Constants.RECENTLY_ADDED:
        mTitle = getResources().getString(R.string.recently_add);
        collapsingToolbarLayout.setTitle(mTitle);

        fragment = new RecentlyAddedFragment();
        break;
    case Constants.RECENTLY_PLAYED:
        mTitle = getResources().getString(R.string.recently_play);
        collapsingToolbarLayout.setTitle(mTitle);

        fragment = new RecentlyPlayFragment();
        break;
    case Constants.MY_FAVORITE:
        mTitle = getResources().getString(R.string.my_favorite);
        collapsingToolbarLayout.setTitle(mTitle);

        fragment = new MyFavoriteFragment();
        break;
    case Constants.ALBUM_DETAIL:
        mTargetId = getIntent().getLongExtra(Constants.ALBUM_ID, -1);
        mTitle = getIntent().getStringExtra(Constants.ALBUM_NAME);
        collapsingToolbarLayout.setTitle(mTitle);
        fragment = new AlbumDetailsFragment();
        bundle = new Bundle();
        bundle.putLong(Constants.ALBUM_ID, mTargetId);
        fragment.setArguments(bundle);
        break;
    case Constants.ARTIST_DETAIL:
        mTargetId = getIntent().getLongExtra(Constants.ARTIST_ID, -1);
        mTitle = getIntent().getStringExtra(Constants.ARTIST_NAME);
        collapsingToolbarLayout.setTitle(mTitle);
        fragment = new ArtistDetailFragment();
        bundle = new Bundle();
        bundle.putLong(Constants.ARTIST_ID, mTargetId);
        fragment.setArguments(bundle);
        break;
    default:
        break;
    }

    getSupportFragmentManager().beginTransaction().replace(R.id.container, fragment).commit();
}

From source file:com.nxp.nfc_demo.fragments.LedFragment.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    anim = AnimationUtils.loadAnimation(getActivity(), R.anim.ntag);
    voltage = 0;/*w w  w.  j  av  a 2  s.c  o  m*/
    temperatureC = 0;
    temperatureF = 0;
    // We start with L2 so that Blue LED is switched on
    option = "L2";
    lastOption = "L2";
    isSwitchedOn = true;
    setRetainInstance(true);
}

From source file:com.iven.lfflfeedreader.mainact.fabscroll.java

private void animateOut(final FloatingActionButton button) {
    if (Build.VERSION.SDK_INT >= 14) {
        ViewCompat.animate(button).scaleX(0.0F).scaleY(0.0F).alpha(0.0F).setInterpolator(INTERPOLATOR)
                .withLayer().setListener(new ViewPropertyAnimatorListener() {
                    public void onAnimationStart(View view) {
                        fabscroll.this.mIsAnimatingOut = true;
                    }/* w  w w. ja v  a  2 s  . c om*/

                    public void onAnimationCancel(View view) {
                        fabscroll.this.mIsAnimatingOut = false;
                    }

                    public void onAnimationEnd(View view) {
                        fabscroll.this.mIsAnimatingOut = false;
                        view.setVisibility(View.GONE);
                    }
                }).start();
    } else {
        Animation anim = AnimationUtils.loadAnimation(button.getContext(), R.anim.fab_out);
        anim.setInterpolator(INTERPOLATOR);
        anim.setDuration(200L);
        anim.setAnimationListener(new Animation.AnimationListener() {
            public void onAnimationStart(Animation animation) {
                fabscroll.this.mIsAnimatingOut = true;
            }

            public void onAnimationEnd(Animation animation) {
                fabscroll.this.mIsAnimatingOut = false;
                button.setVisibility(View.GONE);
            }

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

From source file:com.yairkukielka.feedhungry.ListViewEntryArrayAdapter.java

public ListViewEntryArrayAdapter(Activity context, int textViewResourceId, List<ListEntry> objects,
        ImageLoader imageLoader) {/*  www.  jav  a 2  s.c o m*/
    super(context, textViewResourceId, objects);
    mImageLoader = imageLoader;
    this.context = context;
    animation = AnimationUtils.loadAnimation(context, R.anim.wave_scale);
    this.cards = PreferenceManager.getDefaultSharedPreferences(context)
            .getBoolean(PreferencesActivity.KEY_LIST_WITH_CARDS, false);
    layoutInflater = (LayoutInflater) this.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    imageHeight = getContext().getResources().getDimensionPixelSize(R.dimen.item_image_height);
    imageWidth = getContext().getResources().getDimensionPixelSize(R.dimen.item_image_width);
}

From source file:id.zelory.tanipedia.activity.TanyaActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_tanya);
    toolbar = (Toolbar) findViewById(R.id.anim_toolbar);
    setSupportActionBar(toolbar);//from   w  w w .jav  a 2  s . c om
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);

    CollapsingToolbarLayout collapsingToolbar = (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
    collapsingToolbar.setTitle("Tanya Tani");

    animation = AnimationUtils.loadAnimation(this, R.anim.simple_grow);
    fabMargin = getResources().getDimensionPixelSize(R.dimen.fab_margin);

    drawerLayout = (DrawerLayout) findViewById(R.id.nav_drawer);
    setUpNavDrawer();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.getMenu().getItem(2).setChecked(true);
    TextView nama = (TextView) navigationView.findViewById(R.id.nama);
    nama.setText(PrefUtils.ambilString(this, "nama"));
    TextView email = (TextView) navigationView.findViewById(R.id.email);
    email.setText(PrefUtils.ambilString(this, "email"));
    navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
        @Override
        public boolean onNavigationItemSelected(MenuItem menuItem) {
            menuItem.setChecked(true);
            drawerLayout.closeDrawers();
            Intent intent;
            switch (menuItem.getItemId()) {
            case R.id.cuaca:
                intent = new Intent(TanyaActivity.this, CuacaActivity.class);
                break;
            case R.id.berita:
                intent = new Intent(TanyaActivity.this, BeritaActivity.class);
                break;
            case R.id.tanya:
                return true;
            case R.id.harga:
                intent = new Intent(TanyaActivity.this, KomoditasActivity.class);
                break;
            case R.id.logout:
                PrefUtils.simpanString(TanyaActivity.this, "nama", null);
                intent = new Intent(TanyaActivity.this, LoginActivity.class);
                intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
                startActivity(intent);
                return true;
            case R.id.tentang:
                intent = new Intent(TanyaActivity.this, TentangActivity.class);
                startActivity(intent);
                return true;
            default:
                return true;
            }
            startActivity(intent);
            finish();
            return true;
        }
    });

    recyclerView = (RecyclerView) findViewById(R.id.scrollableview);
    recyclerView.setHasFixedSize(true);
    LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
    recyclerView.setLayoutManager(linearLayoutManager);
    recyclerView.addOnScrollListener(new MyRecyclerScroll() {
        @Override
        public void show() {
            fab.animate().translationY(0).setInterpolator(new DecelerateInterpolator(2)).start();
        }

        @Override
        public void hide() {
            fab.animate().translationY(fab.getHeight() + fabMargin)
                    .setInterpolator(new AccelerateInterpolator(2)).start();
        }
    });

    tanyaGambar = (ImageView) findViewById(R.id.tanya_gambar);
    tanyaGambar.setVisibility(View.GONE);
    fab = (FrameLayout) findViewById(R.id.myfab_main);
    fab.setVisibility(View.GONE);
    fabBtn = (ImageButton) findViewById(R.id.myfab_main_btn);
    View fabShadow = findViewById(R.id.myfab_shadow);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        fabShadow.setVisibility(View.GONE);
        fabBtn.setBackground(getDrawable(R.drawable.ripple_accent));
    }

    fabBtn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            new MaterialDialog.Builder(TanyaActivity.this).title("TaniPedia").content("Kirim Pertanyaan")
                    .inputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_CLASS_TEXT)
                    .input("Ketik pertanyaan anda disini!", null, false, new MaterialDialog.InputCallback() {
                        @Override
                        public void onInput(MaterialDialog dialog, CharSequence input) {
                            try {
                                pertanyaan = URLEncoder.encode(input.toString(), "UTF-8");
                                new KirimSoal().execute();
                            } catch (UnsupportedEncodingException e) {
                                Snackbar.make(fabBtn, "Terjadi kesalahan, silahkan coba lagi!",
                                        Snackbar.LENGTH_LONG).show();
                                e.printStackTrace();
                            }
                        }
                    }).positiveColorRes(R.color.primary_dark).positiveText("Kirim")
                    .cancelListener(new DialogInterface.OnCancelListener() {
                        @Override
                        public void onCancel(DialogInterface dialog) {

                        }
                    }).negativeColorRes(R.color.primary_dark).negativeText("Batal").show();
        }
    });

    fabButton = (FabButton) findViewById(R.id.determinate);
    fabButton.showProgress(true);
    new DownloadData().execute();
    fabButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            fabButton.showProgress(true);
            new DownloadData().execute();
        }
    });
}

From source file:com.lamcreations.scaffold.common.views.behaviors.FabBehavior.java

private void animateOut(final FloatingActionButton button) {
    if (Build.VERSION.SDK_INT >= 14) {
        ViewCompat.animate(button).scaleX(0.0F).scaleY(0.0F).alpha(0.0F).setInterpolator(INTERPOLATOR)
                .withLayer().setListener(new ViewPropertyAnimatorListener() {
                    public void onAnimationStart(View view) {
                        FabBehavior.this.mIsAnimatingOut = true;
                    }// ww  w. j  a va  2  s.  c  o  m

                    public void onAnimationCancel(View view) {
                        FabBehavior.this.mIsAnimatingOut = false;
                    }

                    public void onAnimationEnd(View view) {
                        FabBehavior.this.mIsAnimatingOut = false;
                        view.setVisibility(View.GONE);
                    }
                }).start();
    } else {
        Animation anim = AnimationUtils.loadAnimation(button.getContext(), R.anim.scaffold_fab_out);
        anim.setInterpolator(INTERPOLATOR);
        anim.setDuration(200L);
        anim.setAnimationListener(new Animation.AnimationListener() {
            public void onAnimationStart(Animation animation) {
                FabBehavior.this.mIsAnimatingOut = true;
            }

            public void onAnimationEnd(Animation animation) {
                FabBehavior.this.mIsAnimatingOut = false;
                button.setVisibility(View.GONE);
            }

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

From source file:com.letsdoitworld.wastemapper.utils.ImageDownloader.java

/**
 * Download the specified image from the Internet and binds it to the provided ImageView. The
 * binding is immediate if the image is found in the cache and will be done asynchronously
 * otherwise. A null bitmap will be associated to the ImageView if an error occurs.
 *
 * @param url The URL of the image to download.
 * @param imageView The ImageView to bind the downloaded image to.
 *//*from   www  . ja v  a2  s . c  o m*/
public void download(String url, ImageView imageView) {
    resetPurgeTimer();
    Bitmap bitmap = getBitmapFromCache(url);

    if (bitmap == null) {
        forceDownload(url, imageView);
    } else {
        cancelPotentialDownload(url, imageView);
        imageView.setImageBitmap(bitmap);
        if (mContext != null) {
            imageView.setAnimation(AnimationUtils.loadAnimation(mContext, R.anim.fadeout));
        }

    }
}

From source file:com.bluros.music.utils.FabAnimationUtils.java

public static void scaleOut(final View fab, long duration, final ScaleCallback callback) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
        ViewCompat.animate(fab).scaleX(0.0F).scaleY(0.0F).alpha(0.0F)
                .setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR).setDuration(duration).withLayer()
                .setListener(new ViewPropertyAnimatorListener() {
                    public void onAnimationStart(View view) {
                        if (callback != null)
                            callback.onAnimationStart();
                    }/*w w w. jav a  2  s .  c  o  m*/

                    public void onAnimationCancel(View view) {
                    }

                    public void onAnimationEnd(View view) {
                        view.setVisibility(View.INVISIBLE);
                        if (callback != null)
                            callback.onAnimationEnd();
                    }
                }).start();
    } else {
        Animation anim = AnimationUtils.loadAnimation(fab.getContext(), R.anim.design_fab_out);
        anim.setInterpolator(FAST_OUT_SLOW_IN_INTERPOLATOR);
        anim.setDuration(duration);
        anim.setAnimationListener(new Animation.AnimationListener() {
            public void onAnimationStart(Animation animation) {
                if (callback != null)
                    callback.onAnimationStart();
            }

            public void onAnimationEnd(Animation animation) {
                fab.setVisibility(View.INVISIBLE);
                if (callback != null)
                    callback.onAnimationEnd();
            }

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

From source file:com.chromium.fontinstaller.util.ViewUtils.java

public static void reveal(Activity activity, View view, View sourceView, int colorRes) {
    if (activity == null || view == null || sourceView == null)
        return;/* ww  w. ja v a 2s  . c om*/
    if (isLollipop()) {
        final ViewGroupOverlay groupOverlay = (ViewGroupOverlay) activity.getWindow().getDecorView()
                .getOverlay();

        final Rect displayRect = new Rect();
        view.getGlobalVisibleRect(displayRect);

        // Make reveal cover the display and status bar.
        final View revealView = new View(activity);
        revealView.setTop(displayRect.top);
        revealView.setBottom(displayRect.bottom);
        revealView.setLeft(displayRect.left);
        revealView.setRight(displayRect.right);
        revealView.setBackgroundColor(ContextCompat.getColor(activity, colorRes));
        groupOverlay.add(revealView);

        final int[] clearLocation = new int[2];
        sourceView.getLocationInWindow(clearLocation);
        clearLocation[0] += sourceView.getWidth() / 2;
        clearLocation[1] += sourceView.getHeight() / 2;

        final int revealCenterX = clearLocation[0] - revealView.getLeft();
        final int revealCenterY = clearLocation[1] - revealView.getTop();

        final double x1_2 = Math.pow(revealView.getLeft() - revealCenterX, 2);
        final double x2_2 = Math.pow(revealView.getRight() - revealCenterX, 2);
        final double y_2 = Math.pow(revealView.getTop() - revealCenterY, 2);
        final float revealRadius = (float) Math.max(Math.sqrt(x1_2 + y_2), Math.sqrt(x2_2 + y_2));

        try {
            final Animator revealAnimator = ViewAnimationUtils.createCircularReveal(revealView, revealCenterX,
                    revealCenterY, 0.0f, revealRadius);
            revealAnimator
                    .setDuration(activity.getResources().getInteger(android.R.integer.config_mediumAnimTime));

            final Animator alphaAnimator = ObjectAnimator.ofFloat(revealView, View.ALPHA, 0.0f);
            alphaAnimator
                    .setDuration(activity.getResources().getInteger(android.R.integer.config_shortAnimTime));
            alphaAnimator.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    super.onAnimationEnd(animation);
                    view.startAnimation(AnimationUtils.loadAnimation(activity, R.anim.abc_fade_in));
                    view.setVisibility(View.VISIBLE);
                }
            });

            final AnimatorSet animatorSet = new AnimatorSet();
            animatorSet.play(revealAnimator).before(alphaAnimator);
            animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
            animatorSet.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animator) {
                    groupOverlay.remove(revealView);
                }
            });

            animatorSet.start();
        } catch (IllegalStateException e) {
            Timber.i("View is detached - not animating");
        }
    } else {
        view.setVisibility(View.VISIBLE);
    }
}