Java Code Examples for android.graphics.drawable.AnimationDrawable#isRunning()

The following examples show how to use android.graphics.drawable.AnimationDrawable#isRunning() . 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: BaseFragment.java    From CloudReader with Apache License 2.0 6 votes vote down vote up
/**
 * 显示加载中状态
 */
protected void showLoading() {
    ViewStub viewStub = getView(R.id.vs_loading);
    if (viewStub != null) {
        loadingView = viewStub.inflate();
        ImageView img = loadingView.findViewById(R.id.img_progress);
        mAnimationDrawable = (AnimationDrawable) img.getDrawable();
    }
    if (loadingView != null && loadingView.getVisibility() != View.VISIBLE) {
        loadingView.setVisibility(View.VISIBLE);
    }
    // 开始动画
    if (mAnimationDrawable != null && !mAnimationDrawable.isRunning()) {
        mAnimationDrawable.start();
    }
    if (bindingView.getRoot().getVisibility() != View.GONE) {
        bindingView.getRoot().setVisibility(View.GONE);
    }
    if (errorView != null) {
        errorView.setVisibility(View.GONE);
    }
    if (emptyView != null && emptyView.getVisibility() != View.GONE) {
        emptyView.setVisibility(View.GONE);
    }
}
 
Example 2
Source File: MediaRouteButton.java    From android_9.0.0_r45 with Apache License 2.0 5 votes vote down vote up
private void refreshRoute() {
    final MediaRouter.RouteInfo route = mRouter.getSelectedRoute();
    final boolean isRemote = !route.isDefault() && route.matchesTypes(mRouteTypes);
    final boolean isConnecting = isRemote && route.isConnecting();
    boolean needsRefresh = false;
    if (mRemoteActive != isRemote) {
        mRemoteActive = isRemote;
        needsRefresh = true;
    }
    if (mIsConnecting != isConnecting) {
        mIsConnecting = isConnecting;
        needsRefresh = true;
    }

    if (needsRefresh) {
        refreshDrawableState();
    }
    if (mAttachedToWindow) {
        setEnabled(mRouter.isRouteAvailable(mRouteTypes,
                MediaRouter.AVAILABILITY_FLAG_IGNORE_DEFAULT_ROUTE));
    }
    if (mRemoteIndicator != null
            && mRemoteIndicator.getCurrent() instanceof AnimationDrawable) {
        AnimationDrawable curDrawable = (AnimationDrawable) mRemoteIndicator.getCurrent();
        if (mAttachedToWindow) {
            if ((needsRefresh || isConnecting) && !curDrawable.isRunning()) {
                curDrawable.start();
            }
        } else if (isRemote && !isConnecting) {
            // When the route is already connected before the view is attached, show the last
            // frame of the connected animation immediately.
            if (curDrawable.isRunning()) {
                curDrawable.stop();
            }
            curDrawable.selectDrawable(curDrawable.getNumberOfFrames() - 1);
        }
    }
}
 
Example 3
Source File: DrawableAnimationActivity.java    From Android-Animation-Set with Apache License 2.0 5 votes vote down vote up
private void doAnimation(AnimationDrawable animationDrawable, boolean doIt) {
    if (animationDrawable.isRunning()) {
        animationDrawable.stop();
    }

    //When you want to restart the animation, stop the animation first.
    if (doIt) {
        animationDrawable.start();
    }
}
 
Example 4
Source File: BaseActivity.java    From Meteorite with Apache License 2.0 5 votes vote down vote up
@Override
public void setContentView(@LayoutRes int layoutResID) {
    inflate = LayoutInflater.from(this);
    activity_base = inflate.inflate(R.layout.activity_base, null, false);
    activity = inflate.inflate(layoutResID, null, false);

    // content
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    activity.setLayoutParams(params);
    RelativeLayout mContainer = activity_base.findViewById(R.id.container);
    mContainer.addView(activity);
    getWindow().setContentView(activity_base);

    llProgressBar = getView(R.id.ll_progress_bar);
    refresh = getView(R.id.ll_error_refresh);
    ImageView img = getView(R.id.img_progress);

    // 加载动画
    mAnimationDrawable = (AnimationDrawable) img.getDrawable();
    // 默认进入页面就开启动画
    if (!mAnimationDrawable.isRunning()) {
        mAnimationDrawable.start();
    }

    if(mIsSupportToolBar){
        setToolBar();
    }else{
        toolBar = getView(R.id.tool_bar);
        toolBar.setVisibility(View.GONE);
    }

    // 点击加载失败布局
    refresh.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showLoading();
            onRefresh();
        }
    });
}
 
Example 5
Source File: BaseFragment.java    From Meteorite with Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    mViews = new SparseArray<>();

    mLlProgressBar = getView(R.id.ll_progress_bar);
    ImageView img = getView(R.id.img_progress);
    mRefresh = getView(R.id.ll_error_refresh);
    // 加载动画
    mAnimationDrawable = (AnimationDrawable) img.getDrawable();

    initView();
    isInit = true;
    isCanLoadData();

    Log.d("Meteorite","onActivityCreated   mAnimationDrawable.isRunning() = "+mAnimationDrawable.isRunning());

    // 默认进入页面就开启动画
    if (!mAnimationDrawable.isRunning()) {
        mAnimationDrawable.start();
    }
    // 点击加载失败布局
    mRefresh.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            showLoading();
            onRefresh();
        }
    });
    //contentView.setVisibility(View.GONE);
}
 
Example 6
Source File: RspMsgItemView.java    From AssistantBySDK with Apache License 2.0 5 votes vote down vote up
public void startAnimation() {
    try {
        if (mListDrawable.getLevel() == 0) {
            mListDrawable.setLevel(1);
            animation = (AnimationDrawable) mListDrawable.getCurrent();
            if (!animation.isRunning())
                animation.start();
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 7
Source File: LoadingImageView.java    From qvod with MIT License 5 votes vote down vote up
public LoadingImageView(Context context, @Nullable AttributeSet attrs) {
    super(context, attrs);
    setImageResource(R.drawable.anim_yun);
    // 加载动画
    AnimationDrawable mAnimationDrawable = (AnimationDrawable) getDrawable();
    // 默认进入页面就开启动画
    if (!mAnimationDrawable.isRunning()) {
        mAnimationDrawable.start();
    }
}
 
Example 8
Source File: PointViewAnimObject.java    From DragPointView with Apache License 2.0 5 votes vote down vote up
private void start(AnimationDrawable object, final OnPointDragListener removeListener) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
        int duration = 0;
        for (int i = 0; i < object.getNumberOfFrames(); i++) {
            duration += object.getDuration(i);
        }
        view.postDelayed(new Runnable() {
            @Override
            public void run() {
                if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                    view.setBackground(background);
                }
                end(removeListener);
            }
        }, duration + 5);
        view.setText("");
        int drawableL = (view.getWidth() + view.getHeight()) / 2;
        ViewGroup.LayoutParams lp = view.getLayoutParams();
        lp.height = lp.width = drawableL;
        view.setLayoutParams(lp);
        view.setBackground(object);
        if (object.isRunning())
            object.stop();
        object.start();
    } else {
        end(removeListener);
    }
}
 
Example 9
Source File: WordDetailsAdapter.java    From allenglish with Apache License 2.0 5 votes vote down vote up
public void stopAnimation() {
    for (AnimationDrawable animation :
            mSentenceHornAnimations) {
        if (animation.isRunning()) {
            animation.selectDrawable(0); // 选择当前动画的第一帧,然后停止
            animation.stop();
        }
    }
}
 
Example 10
Source File: AudioRenderView.java    From sctalk with Apache License 2.0 5 votes vote down vote up
public void stopAnimation(){
    AnimationDrawable animationDrawable = (AnimationDrawable) audioAnttView.getBackground();
    if (animationDrawable.isRunning()) {
            animationDrawable.stop();
            animationDrawable.selectDrawable(0);
    }
}
 
Example 11
Source File: DrawableAnimationActivity.java    From Study_Android_Demo with Apache License 2.0 5 votes vote down vote up
private void doAnimation(AnimationDrawable animationDrawable, boolean doIt) {
    if (animationDrawable.isRunning()) {
        animationDrawable.stop();
    }

    //When you want to restart the animation, stop the animation first.
    if (doIt) {
        animationDrawable.start();
    }
}
 
Example 12
Source File: BaseActivity.java    From CloudReader with Apache License 2.0 5 votes vote down vote up
@Override
public void setContentView(@LayoutRes int layoutResID) {

    mBaseBinding = DataBindingUtil.inflate(LayoutInflater.from(this), R.layout.activity_base, null, false);
    bindingView = DataBindingUtil.inflate(LayoutInflater.from(this), layoutResID, null, false);

    // content
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    bindingView.getRoot().setLayoutParams(params);
    RelativeLayout mContainer = (RelativeLayout) mBaseBinding.getRoot().findViewById(R.id.container);
    mContainer.addView(bindingView.getRoot());
    getWindow().setContentView(mBaseBinding.getRoot());

    loadingView = ((ViewStub) findViewById(R.id.vs_loading)).inflate();
    ImageView img = loadingView.findViewById(R.id.img_progress);

    // 加载动画
    mAnimationDrawable = (AnimationDrawable) img.getDrawable();
    // 默认进入页面就开启动画
    if (!mAnimationDrawable.isRunning()) {
        mAnimationDrawable.start();
    }

    setToolBar(mBaseBinding.toolBar);
    bindingView.getRoot().setVisibility(View.GONE);
    initStatusBar();
    initViewModel();
}
 
Example 13
Source File: JdRefreshHeader.java    From LbaizxfPulltoRefresh with Apache License 2.0 5 votes vote down vote up
@Override
public void onUIRefreshBegin(PtrFrameLayout frame) {
    // 开始刷新
    mState = STATE_BEGIN;
    // 隐藏商品logo
    mGoodsIv.setVisibility(View.GONE);
    // 开启跑步动画
    mManIv.setBackgroundResource(R.drawable.jd_refresh_header_anim);
    mAnimation = (AnimationDrawable) mManIv.getBackground();
    if (!mAnimation.isRunning()) {
        mAnimation.start();
    }
}
 
Example 14
Source File: PullToRefreshBase.java    From Alibaba-Android-Certification with MIT License 4 votes vote down vote up
/**
 * Helper method which just calls scrollTo() in the correct scrolling
 * direction.
 *
 * @param value - New Scroll value
 */
protected final void setHeaderScroll(int value) {
	if (DEBUG) {//TODO 刷新值
		Log.d(LOG_TAG, "setHeaderScroll: " + value);
	}
	if(onScrollListener!=null){
		onScrollListener.OnScroll(mRefreshableView, value);
	}
	if(mHeaderLayout.custem_healthy_app){
		if(refreshView.getDrawable() instanceof AnimationDrawable){
			AnimationDrawable animationDrawable=(AnimationDrawable) refreshView.getDrawable();
			if(!animationDrawable.isRunning()){
				custemAnimator(value);
			}
		}else{
			custemAnimator(value);
		}

	}
	// Clamp value to with pull scroll range
	final int maximumPullScroll = getMaximumPullScroll();
	value = Math.min(maximumPullScroll, Math.max(-maximumPullScroll, value));

	if (mLayoutVisibilityChangesEnabled) {
		if (value < 0) {
			mHeaderLayout.setVisibility(View.VISIBLE);
		} else if (value > 0) {
			mFooterLayout.setVisibility(View.VISIBLE);
		} else {
			mHeaderLayout.setVisibility(View.INVISIBLE);
			mFooterLayout.setVisibility(View.INVISIBLE);
		}
	}

	if (USE_HW_LAYERS) {
		/**
		 * Use a Hardware Layer on the Refreshable View if we've scrolled at
		 * all. We don't use them on the Header/Footer Views as they change
		 * often, which would negate any HW layer performance boost.
		 */
		ViewCompat.setLayerType(mRefreshableViewWrapper, value != 0 ? View.LAYER_TYPE_HARDWARE
				: View.LAYER_TYPE_NONE);
	}

	switch (getPullToRefreshScrollDirection()) {
		case VERTICAL:
			scrollTo(0, value);
			break;
		case HORIZONTAL:
			scrollTo(value, 0);
			break;
	}
}
 
Example 15
Source File: BaseHeaderActivity.java    From CloudReader with Apache License 2.0 4 votes vote down vote up
@Override
    public void setContentView(@LayoutRes int layoutResID) {
        View ll = getLayoutInflater().inflate(R.layout.activity_header_base, null);

        // 内容
        bindingContentView = DataBindingUtil.inflate(getLayoutInflater(), layoutResID, null, false);
        // 头部
        bindingHeaderView = DataBindingUtil.inflate(getLayoutInflater(), setHeaderLayout(), null, false);
        // 标题
        bindingTitleView = DataBindingUtil.inflate(getLayoutInflater(), R.layout.base_header_title_bar, null, false);

        // title (如自定义很强可以拿出去)
        RelativeLayout.LayoutParams titleParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        bindingTitleView.getRoot().setLayoutParams(titleParams);
        RelativeLayout mTitleContainer = (RelativeLayout) ll.findViewById(R.id.title_container);
        mTitleContainer.addView(bindingTitleView.getRoot());

        // header
        RelativeLayout.LayoutParams headerParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        bindingHeaderView.getRoot().setLayoutParams(headerParams);
        RelativeLayout mHeaderContainer = (RelativeLayout) ll.findViewById(R.id.header_container);
        mHeaderContainer.addView(bindingHeaderView.getRoot());

        // content
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        bindingContentView.getRoot().setLayoutParams(params);
        RelativeLayout mContainer = ll.findViewById(R.id.container);
        mContainer.addView(bindingContentView.getRoot());
        getWindow().setContentView(ll);

        loadingView = ((ViewStub) getView(R.id.vs_loading)).inflate();

        // 设置自定义元素共享切换动画
//        setMotion(setHeaderPicView(), false);

        // 初始化滑动渐变
//        initSlideShapeTheme(setHeaderImgUrl(), setHeaderImageView());

        // 设置toolbar
        setToolBar();

        ImageView img = loadingView.findViewById(R.id.img_progress);
        // 加载动画
        mAnimationDrawable = (AnimationDrawable) img.getDrawable();
        // 默认进入页面就开启动画
        if (!mAnimationDrawable.isRunning()) {
            mAnimationDrawable.start();
        }
        bindingContentView.getRoot().setVisibility(View.GONE);
    }