android.graphics.drawable.Animatable Java Examples

The following examples show how to use android.graphics.drawable.Animatable. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: AnimationHelper.java    From ListItemView with Apache License 2.0 6 votes vote down vote up
public void toggleCheckBoxMenu(ListItemView listItemView, boolean toggle) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
        Drawable drawable = listItemView.isChecked() ?
                AnimatedVectorDrawableCompat
                        .create(mContext, R.drawable.avd_checkbox_checked_to_unchecked) :
                AnimatedVectorDrawableCompat
                        .create(mContext, R.drawable.avd_checkbox_unchecked_to_checked);
        ImageView imageView =
                (ImageView) listItemView.findMenuItem(R.id.action_checkable).getActionView();
        imageView.setImageDrawable(drawable);
        ((Animatable) drawable).start();
    }
    if (toggle) {
        listItemView.toggle();
    }
}
 
Example #2
Source File: MovieDetailActivity.java    From Material-Movies with Apache License 2.0 6 votes vote down vote up
/**
     * Starts an animation provided by a <animation-drawable> on Lollipop &
     * higher versions, in lower versions a simple set with a scale and a rotate
     * animation is shown
     */
    @Override
    public void animateConfirmationView() {

        Drawable drawable = mConfirmationView.getDrawable();

        // Animated drawables are supported on Lollipop and higher
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

            if (drawable instanceof Animatable)
                ((Animatable) drawable).start();
//
        } else {

            mConfirmationView.startAnimation(AnimationUtils.loadAnimation(this,
                R.anim.appear_rotate));
        }
    }
 
Example #3
Source File: SwirlView.java    From swirl with Apache License 2.0 6 votes vote down vote up
public void setState(State state, boolean animate) {
  if (state == this.state) return;

  @DrawableRes int resId = getDrawable(this.state, state, animate);
  if (resId == 0) {
    setImageDrawable(null);
  } else {
    Drawable icon = null;
    if (animate) {
      icon = AnimatedVectorDrawableCompat.create(getContext(), resId);
    }
    if (icon == null) {
      icon = VectorDrawableCompat.create(getResources(), resId, getContext().getTheme());
    }
    setImageDrawable(icon);

    if (icon instanceof Animatable) {
      ((Animatable) icon).start();
    }
  }

  this.state = state;
}
 
Example #4
Source File: PictureMultiCuttingActivity.java    From Matisse-Kotlin with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    getMenuInflater().inflate(R.menu.ucrop_menu_activity, menu);
    // Change crop & loader menu icons color to match the rest of the UI colors
    MenuItem menuItemLoader = menu.findItem(R.id.menu_loader);
    Drawable menuItemLoaderIcon = menuItemLoader.getIcon();
    if (menuItemLoaderIcon != null) {
        try {
            menuItemLoaderIcon.mutate();
            menuItemLoaderIcon.setColorFilter(mToolbarWidgetColor, PorterDuff.Mode.SRC_ATOP);
            menuItemLoader.setIcon(menuItemLoaderIcon);
        } catch (IllegalStateException e) {
            Log.i(TAG, String.format("%s - %s", e.getMessage(), getString(R.string.ucrop_mutate_exception_hint)));
        }
        ((Animatable) menuItemLoader.getIcon()).start();
    }

    MenuItem menuItemCrop = menu.findItem(R.id.menu_crop);
    Drawable menuItemCropIcon = ContextCompat.getDrawable(this, mToolbarCropDrawable);
    if (menuItemCropIcon != null) {
        menuItemCropIcon.mutate();
        menuItemCropIcon.setColorFilter(mToolbarWidgetColor, PorterDuff.Mode.SRC_ATOP);
        menuItemCrop.setIcon(menuItemCropIcon);
    }
    return true;
}
 
Example #5
Source File: ViewPagerActivity.java    From PhotoDraweeView with Apache License 2.0 6 votes vote down vote up
@Override public Object instantiateItem(ViewGroup viewGroup, int position) {
    final PhotoDraweeView photoDraweeView = new PhotoDraweeView(viewGroup.getContext());
    PipelineDraweeControllerBuilder controller = Fresco.newDraweeControllerBuilder();
    controller.setUri(Uri.parse("res:///" + mDrawables[position]));
    controller.setOldController(photoDraweeView.getController());
    controller.setControllerListener(new BaseControllerListener<ImageInfo>() {
        @Override
        public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
            super.onFinalImageSet(id, imageInfo, animatable);
            if (imageInfo == null) {
                return;
            }
            photoDraweeView.update(imageInfo.getWidth(), imageInfo.getHeight());
        }
    });
    photoDraweeView.setController(controller.build());

    try {
        viewGroup.addView(photoDraweeView, ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return photoDraweeView;
}
 
Example #6
Source File: MainActivity.java    From android-animated-menu-items with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    setTitle("Anim Items");

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (menu != null) {
                for (int i = 0; i < menu.size(); i++) {
                    Drawable drawable = menu.getItem(i).getIcon();
                    if (drawable instanceof Animatable) {
                        ((Animatable) drawable).start();
                    }
                }
            }
        }
    });
}
 
Example #7
Source File: PrayerFragment.java    From android with Apache License 2.0 6 votes vote down vote up
@Override
public void onViewCreated(View view, Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    mPresenter.setView(this);
    refresh(false);

    SwipeRefreshLayout.OnRefreshListener refreshListener = new SwipeRefreshLayout.OnRefreshListener() {
        @Override
        public void onRefresh() {
            refresh(true);
        }
    };

    mRefreshLayout.setColorSchemeResources(R.color.colorAccent);
    mRefreshLayout.setOnRefreshListener(refreshListener);

    Drawable drawable = mProgressView.getDrawable();
    if (drawable instanceof Animatable) {
        ((Animatable) drawable).start();
    }

    mAnalytics.trackViewedPrayerTimes();
}
 
Example #8
Source File: TapBarMenu.java    From TapBarMenu with Apache License 2.0 6 votes vote down vote up
/**
 * Close the menu.
 */
public void close() {
  updateDimensions(width, height);
  state = State.CLOSED;
  showIcons(false);

  animator[LEFT].setFloatValues(0, button[LEFT]);
  animator[RIGHT].setFloatValues(width, button[RIGHT]);
  animator[RADIUS].setFloatValues(0, button[RADIUS]);
  animator[TOP].setFloatValues(0, button[TOP]);
  animator[BOTTOM].setFloatValues(height, button[BOTTOM]);

  animatorSet.cancel();
  animatorSet.start();
  if (iconClosedDrawable instanceof Animatable) {
    ((Animatable) iconClosedDrawable).start();
  }
  this.animate()
          .y(yPosition)
          .setDuration(animationDuration)
          .setInterpolator(DECELERATE_INTERPOLATOR)
          .start();
}
 
Example #9
Source File: AnimatedCompoundDrawableActivity.java    From advanced-textview with Apache License 2.0 6 votes vote down vote up
private void changeAnimation(Operation operation) {
  Drawable[] drawables = textView.getCompoundDrawables();
  for (Drawable drawable : drawables) {
    if (drawable != null && drawable instanceof Animatable) {
      Animatable animatable = ((Animatable) drawable);
      switch (operation) {
        case START:
          animatable.start();
          break;
        case STOP:
          animatable.stop();
          break;
      }
    }
  }
}
 
Example #10
Source File: SecondaryChooserFragment.java    From storage-chooser with Mozilla Public License 2.0 6 votes vote down vote up
private void hideAddFolderView() {
        Animation anim = AnimationUtils.loadAnimation(mContext, R.anim.anim_close_folder_view);
        mNewFolderView.startAnimation(anim);
        mNewFolderView.setVisibility(View.INVISIBLE);

        if (DiskUtil.isLollipopAndAbove()) {
            mNewFolderImageView.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.drawable_close_to_plus));
            // image button animation
            Animatable animatable = (Animatable) mNewFolderImageView.getDrawable();
            animatable.start();
        }
        mNewFolderImageView.setOnClickListener(mNewFolderButtonClickListener);

        //listview should be clickable
        SecondaryChooserAdapter.shouldEnable = true;

        mInactiveGradient.startAnimation(anim);
        mInactiveGradient.setVisibility(View.INVISIBLE);

//        mNewFolderButton.setImageDrawable(ContextCompat.getDrawable(mContext, R.drawable.plus));
    }
 
Example #11
Source File: IntroView.java    From ElasticProgressBar with Apache License 2.0 6 votes vote down vote up
public void startAnimation() {

        Drawable drawable = getDrawable();
        Animatable animatable = (Animatable) drawable;

        AVDWrapper.Callback callback = new AVDWrapper.Callback() {
            @Override
            public void onAnimationDone() {
                Log.d(LOG_TAG, "Enter animation finished");
                mListener.onEnterAnimationFinished();
            }

            @Override
            public void onAnimationStopped() {

            }
        };

        AVDWrapper wrapper = new AVDWrapper(animatable, new Handler(), callback);
        wrapper.start(getContext().getResources().getInteger(R.integer.enter_animation_duration));
    }
 
Example #12
Source File: ForwardingControllerListener.java    From fresco with MIT License 6 votes vote down vote up
@Override
public synchronized void onFinalImageSet(
    String id, @Nullable INFO imageInfo, @Nullable Animatable animatable) {
  final int numberOfListeners = mListeners.size();
  for (int i = 0; i < numberOfListeners; ++i) {
    try {
      ControllerListener<? super INFO> listener = mListeners.get(i);
      if (listener != null) {
        listener.onFinalImageSet(id, imageInfo, animatable);
      }
    } catch (Exception exception) {
      // Don't punish the other listeners if we're given a bad one.
      onException("InternalListener exception in onFinalImageSet", exception);
    }
  }
}
 
Example #13
Source File: SplashActivity.java    From RunMap with Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_splash);
    GradleButterKnife.bind(this);
    Uri uri = Uri.parse("asset:///splash.webp");
    mSplashPresenter = new SplashPresenterImpl(this);
    DraweeController controller = Fresco.newDraweeControllerBuilder()
            .setUri(uri)
            .setAutoPlayAnimations(true)
            .setControllerListener(new BaseControllerListener<ImageInfo>(){
                @Override
                public void onFinalImageSet(String id, @Nullable ImageInfo imageInfo, @Nullable Animatable animatable) {
                    super.onFinalImageSet(id, imageInfo, animatable);
                    mSplashPresenter.startCountDown(1);
                }
            })
            .build();
    splashDraweee.setController(controller);
}
 
Example #14
Source File: ZxingForegroundView.java    From ProjectX with Apache License 2.0 6 votes vote down vote up
/**
 * 设置开启图片
 *
 * @param drawable 开启图片
 */
public void setOpenDrawable(Drawable drawable) {
    if (mOpenDrawable == drawable)
        return;
    if (mOpenDrawable != null) {
        if (mOpenDrawable instanceof Animatable)
            ((Animatable) mOpenDrawable).stop();
        mOpenDrawable.setCallback(null);
    }
    mOpenDrawable = drawable;
    if (mOpenDrawable != null) {
        mOpenDrawable.setCallback(this);
        if (mOpenDrawable instanceof Animatable) {
            Animatable animatable = (Animatable) mOpenDrawable;
            if (!animatable.isRunning())
                animatable.start();
        }
    }
    invalidate();
}
 
Example #15
Source File: MainActivity.java    From android-mvp-interactor-architecture with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Drawable drawable = item.getIcon();
    if (drawable instanceof Animatable) {
        ((Animatable) drawable).start();
    }
    switch (item.getItemId()) {
        case R.id.action_cut:
            return true;
        case R.id.action_copy:
            return true;
        case R.id.action_share:
            return true;
        case R.id.action_delete:
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example #16
Source File: MainActivity.java    From android-animated-menu-items with Apache License 2.0 6 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    setTitle("Anim Items");

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    findViewById(R.id.fab).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (menu != null) {
                for (int i = 0; i < menu.size(); i++) {
                    Drawable drawable = menu.getItem(i).getIcon();
                    if (drawable instanceof Animatable) {
                        ((Animatable) drawable).start();
                    }
                }
            }
        }
    });
}
 
Example #17
Source File: MainActivity.java    From Camera-Roll-Android-App with Apache License 2.0 6 votes vote down vote up
public void fabClicked(View v) {
    if (v instanceof FloatingActionButton) {
        FloatingActionButton fab = (FloatingActionButton) v;
        Drawable drawable = fab.getDrawable();
        if (drawable instanceof Animatable) {
            ((Animatable) drawable).start();
        }
    }
    new Handler().postDelayed(new Runnable() {
        @Override
        public void run() {
            Intent i = new Intent();
            i.setAction(MediaStore.INTENT_ACTION_STILL_IMAGE_CAMERA);
            if (i.resolveActivity(getPackageManager()) != null) {
                startActivity(i);
            } else {
                Toast.makeText(MainActivity.this, getString(R.string.error), Toast.LENGTH_SHORT).show();
            }
        }
    }, (int) (500 * Util.getAnimatorSpeed(this)));
}
 
Example #18
Source File: MainActivity.java    From android-mvvm-architecture with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Drawable drawable = item.getIcon();
    if (drawable instanceof Animatable) {
        ((Animatable) drawable).start();
    }
    switch (item.getItemId()) {
        case R.id.action_cut:
            return true;
        case R.id.action_copy:
            return true;
        case R.id.action_share:
            return true;
        case R.id.action_delete:
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example #19
Source File: GenericDraweeHierarchy.java    From fresco with MIT License 6 votes vote down vote up
private void setProgress(float progress) {
  Drawable progressBarDrawable = mFadeDrawable.getDrawable(PROGRESS_BAR_IMAGE_INDEX);
  if (progressBarDrawable == null) {
    return;
  }

  // display progressbar when not fully loaded, hide otherwise
  if (progress >= 0.999f) {
    if (progressBarDrawable instanceof Animatable) {
      ((Animatable) progressBarDrawable).stop();
    }
    fadeOutLayer(PROGRESS_BAR_IMAGE_INDEX);
  } else {
    if (progressBarDrawable instanceof Animatable) {
      ((Animatable) progressBarDrawable).start();
    }
    fadeInLayer(PROGRESS_BAR_IMAGE_INDEX);
  }
  // set drawable level, scaled to [0, 10000] per drawable specification
  progressBarDrawable.setLevel(Math.round(progress * 10000));
}
 
Example #20
Source File: DraweeSpan.java    From drawee-text-view with Apache License 2.0 6 votes vote down vote up
public void onAttach(@NonNull DraweeTextView view) {
    mIsAttached = true;
    if (mAttachedView != view) {
        mActualDrawable.setCallback(null);
        if (mAttachedView != null) {
            throw new IllegalStateException("has been attached to view:" + mAttachedView);
        }
        mAttachedView = view;
        setDrawableInner(mDrawable);
        mActualDrawable.setCallback(mAttachedView);
    }
    mDeferredReleaser.cancelDeferredRelease(this);
    if (!mIsRequestSubmitted) {
        submitRequest();
    } else if (mShouldShowAnim && mDrawable instanceof Animatable) {
        ((Animatable) mDrawable).start();
    }
}
 
Example #21
Source File: MainActivity.java    From android-mvp-architecture with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Drawable drawable = item.getIcon();
    if (drawable instanceof Animatable) {
        ((Animatable) drawable).start();
    }
    switch (item.getItemId()) {
        case R.id.action_cut:
            return true;
        case R.id.action_copy:
            return true;
        case R.id.action_share:
            return true;
        case R.id.action_delete:
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example #22
Source File: ZxingForegroundView.java    From ProjectX with Apache License 2.0 6 votes vote down vote up
/**
 * 设置错误图片
 *
 * @param drawable 错误图片
 */
public void setErrorDrawable(Drawable drawable) {
    if (mErrorDrawable == drawable)
        return;
    if (mErrorDrawable != null) {
        if (mErrorDrawable instanceof Animatable)
            ((Animatable) mErrorDrawable).stop();
        mErrorDrawable.setCallback(null);
    }
    mErrorDrawable = drawable;
    if (mErrorDrawable != null) {
        mErrorDrawable.setCallback(this);
        if (mErrorDrawable instanceof Animatable) {
            Animatable animatable = (Animatable) mErrorDrawable;
            if (!animatable.isRunning())
                animatable.start();
        }
    }
    invalidate();
}
 
Example #23
Source File: MainActivity.java    From android-list-to-grid with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.action_list_to_grid) {
        if (!((Animatable) item.getIcon()).isRunning()) {
            if (gridLayoutManager.getSpanCount() == 1) {
                item.setIcon(AnimatedVectorDrawableCompat.create(MainActivity.this, R.drawable.avd_list_to_grid));
                gridLayoutManager.setSpanCount(3);
            } else {
                item.setIcon(AnimatedVectorDrawableCompat.create(MainActivity.this, R.drawable.avd_grid_to_list));
                gridLayoutManager.setSpanCount(1);
            }
            ((Animatable) item.getIcon()).start();
            simpleAdapter.notifyItemRangeChanged(0, simpleAdapter.getItemCount());
        }
        return true;
    }

    return super.onOptionsItemSelected(item);
}
 
Example #24
Source File: MorphButton.java    From CanDialog with Apache License 2.0 5 votes vote down vote up
private boolean endStartAnimation() {
    if (mStartDrawable != null && mStartCanMorph) {
        ((Animatable) mStartDrawable).stop();
        return true;
    }
    return false;
}
 
Example #25
Source File: IcsProgressBar.java    From Libraries-for-Android-Developers with MIT License 5 votes vote down vote up
@Override
protected synchronized void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    Drawable d = mCurrentDrawable;
    if (d != null) {
        // Translate canvas so a indeterminate circular progress bar with padding
        // rotates properly in its animation
        canvas.save();
        canvas.translate(getPaddingLeft() + mIndeterminateRealLeft, getPaddingTop() + mIndeterminateRealTop);
        long time = getDrawingTime();
        if (mAnimation != null) {
            mAnimation.getTransformation(time, mTransformation);
            float scale = mTransformation.getAlpha();
            try {
                mInDrawing = true;
                d.setLevel((int) (scale * MAX_LEVEL));
            } finally {
                mInDrawing = false;
            }
            if (SystemClock.uptimeMillis() - mLastDrawTime >= mAnimationResolution) {
                mLastDrawTime = SystemClock.uptimeMillis();
                postInvalidateDelayed(mAnimationResolution);
            }
        }
        d.draw(canvas);
        canvas.restore();
        if (mShouldStartAnimationDrawable && d instanceof Animatable) {
            ((Animatable) d).start();
            mShouldStartAnimationDrawable = false;
        }
    }
}
 
Example #26
Source File: BookDetailActivity.java    From MaterialHome with Apache License 2.0 5 votes vote down vote up
@Override
public void hideProgress() {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        if (mFab.getDrawable() instanceof Animatable) {
            ((Animatable) mFab.getDrawable()).stop();
        }
    } else {
        //低于5.0,显示其他动画
    }
}
 
Example #27
Source File: IcsProgressBar.java    From zen4android with MIT License 5 votes vote down vote up
@Override
protected synchronized void onDraw(Canvas canvas) {
    super.onDraw(canvas);

    Drawable d = mCurrentDrawable;
    if (d != null) {
        // Translate canvas so a indeterminate circular progress bar with padding
        // rotates properly in its animation
        canvas.save();
        canvas.translate(getPaddingLeft() + mIndeterminateRealLeft, getPaddingTop() + mIndeterminateRealTop);
        long time = getDrawingTime();
        if (mAnimation != null) {
            mAnimation.getTransformation(time, mTransformation);
            float scale = mTransformation.getAlpha();
            try {
                mInDrawing = true;
                d.setLevel((int) (scale * MAX_LEVEL));
            } finally {
                mInDrawing = false;
            }
            if (SystemClock.uptimeMillis() - mLastDrawTime >= mAnimationResolution) {
                mLastDrawTime = SystemClock.uptimeMillis();
                postInvalidateDelayed(mAnimationResolution);
            }
        }
        d.draw(canvas);
        canvas.restore();
        if (mShouldStartAnimationDrawable && d instanceof Animatable) {
            ((Animatable) d).start();
            mShouldStartAnimationDrawable = false;
        }
    }
}
 
Example #28
Source File: MainActivity.java    From android-animated-menu-items with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Drawable drawable = item.getIcon();
    if (drawable instanceof Animatable) {
        ((Animatable) drawable).start();
    }
    return super.onOptionsItemSelected(item);
}
 
Example #29
Source File: PostItemImageView.java    From redgram-for-reddit with GNU General Public License v3.0 5 votes vote down vote up
private ControllerListener<? super ImageInfo> getControllerListener() {
    ControllerListener controllerListener = new BaseControllerListener<ImageInfo>(){

        @Override
        public void onFinalImageSet(String id, ImageInfo imageInfo, Animatable animatable) {
            imageLoaded = true;
        }

    };
    return controllerListener;
}
 
Example #30
Source File: MorphButton.java    From CanDialog with Apache License 2.0 5 votes vote down vote up
private boolean endEndAnimation() {
    if (mEndDrawable != null && mEndCanMorph) {
        ((Animatable) mEndDrawable).stop();
        return true;
    }
    return false;
}