Android Open Source - mobilib Mbl Sequence Image






From Project

Back to project page mobilib.

License

The source code is released under:

MIT License

If you think the Android project mobilib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.datdo.mobilib.widget;
/* ww w.  j  a v a 2s.c  o  m*/
import com.datdo.mobilib.util.MblUtils;

import android.content.Context;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.widget.ImageView;

public class MblSequenceImage extends ImageView {
    private int mCurrentIndex;
    private int[] mImageResIds;
    private long mInterval;
    private boolean mRepeat;
    private MblSequenceImageCallback mCallback;
    private static Handler sHandler = new Handler(Looper.getMainLooper());

    private Runnable mOnTimerTask = new Runnable() {
        @Override
        public void run() {
            MblUtils.executeOnMainThread(new Runnable() {
                @Override
                public void run() {
                    setImageResource(mImageResIds[mCurrentIndex]);
                    if (mCallback != null) mCallback.onShow(mCurrentIndex);

                    if (mCurrentIndex == mImageResIds.length-1) {
                        if (mRepeat) {
                            if (mCallback != null) mCallback.onReset();
                        } else {
                            if (mCallback != null) mCallback.onFinish();
                            stop();
                            return;
                        }
                    }
                    mCurrentIndex = (mCurrentIndex+1) % mImageResIds.length;

                    sHandler.removeCallbacks(mOnTimerTask);
                    sHandler.postDelayed(mOnTimerTask, mInterval);
                }
            });
        }
    };

    public MblSequenceImage(Context context) {
        super(context);
    }

    public MblSequenceImage(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MblSequenceImage(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public void init(int[] imageResIds, long interval, boolean repeat, MblSequenceImageCallback callback) {
        mImageResIds = imageResIds;
        mInterval = interval;
        mCurrentIndex = 0;
        mRepeat = repeat;
        mCallback = callback;
    }

    public void start() {
        stop();
        mCurrentIndex = 0;
        mOnTimerTask.run();
    }

    public void showImageAtIndex(int index) {
        setImageResource(mImageResIds[index]);
        mCurrentIndex = index;
    }

    public void stop() {
        sHandler.removeCallbacks(mOnTimerTask);
    }

    public static interface MblSequenceImageCallback {
        public void onFinish();
        public void onReset();
        public void onShow(int index);
    }
}




Java Source Code List

com.datdo.mobilib.api.DBBase.java
com.datdo.mobilib.api.DBHelper.java
com.datdo.mobilib.api.MblApi.java
com.datdo.mobilib.api.MblCache.java
com.datdo.mobilib.api.MblException.java
com.datdo.mobilib.api.MblSSLCertificateUtils.java
com.datdo.mobilib.base.MblActivityPlugin.java
com.datdo.mobilib.base.MblBaseActionBarActivity.java
com.datdo.mobilib.base.MblBaseActivity.java
com.datdo.mobilib.base.MblBaseAdapter.java
com.datdo.mobilib.base.MblBaseApplication.java
com.datdo.mobilib.base.MblBaseFragmentActivity.java
com.datdo.mobilib.base.MblDecorView.java
com.datdo.mobilib.base.MblNetworkStatusChangedReceiver.java
com.datdo.mobilib.event.MblCommonEvents.java
com.datdo.mobilib.event.MblEventCenter.java
com.datdo.mobilib.event.MblEventListener.java
com.datdo.mobilib.event.MblStrongEventListener.java
com.datdo.mobilib.event.MblWeakArrayList.java
com.datdo.mobilib.imageinput.MblAutoResizeSquareImageView.java
com.datdo.mobilib.imageinput.MblDataInputActivity.java
com.datdo.mobilib.imageinput.MblImageFolderScanner.java
com.datdo.mobilib.imageinput.MblImageInput.java
com.datdo.mobilib.imageinput.MblImagePickingScanEngine.java
com.datdo.mobilib.imageinput.MblPickImageActivity.java
com.datdo.mobilib.imageinput.MblPickImageGridViewAdapter.java
com.datdo.mobilib.imageinput.MblTakeImageActivity.java
com.datdo.mobilib.util.MblAsyncTask.java
com.datdo.mobilib.util.MblImageLoader.java
com.datdo.mobilib.util.MblLinkMovementMethod.java
com.datdo.mobilib.util.MblUrlRecognizer.java
com.datdo.mobilib.util.MblUtils.java
com.datdo.mobilib.widget.MblHorizontalViewPager.java
com.datdo.mobilib.widget.MblListViewWithScrollableItems.java
com.datdo.mobilib.widget.MblSequenceImage.java
com.datdo.mobilib.widget.MblSideMenuEnabledLayout.java
com.datdo.mobilib.widget.MblTouchImageView.java