Code example for LinkedList

Methods: isEmpty, offer

0
    class Flipper implements Runnable {
        @Override 
        public void run() { 
            maybeLoadMore(); 
 
            if (mBitmapQueue.isEmpty()) {
                mSpinner.setVisibility(View.VISIBLE);
            } else { 
                mSpinner.setVisibility(View.GONE);
            } 
 
            long now = System.currentTimeMillis();
            long elapsed = now - mLastFlipTime;
 
            if (elapsed < mDropPeriod) {
                scheduleNext((int) mDropPeriod - elapsed);
            } else { 
                scheduleNext(mDropPeriod);
                if (changePhoto() || 
                        (elapsed > (5 * mDropPeriod) && canFlip())) {
                    flip(1f); 
                    mLastFlipTime = now;
                } 
            } 
        } 
 
        private void scheduleNext(long delay) {
            removeCallbacks(mFlipper);
            postDelayed(mFlipper, delay);
        } 
    } 
 
    public PhotoCarousel(Context context, AttributeSet as) {
        super(context, as);
        final Resources resources = getResources();
        mDropPeriod = resources.getInteger(R.integer.carousel_drop_period);
        mBitmapQueueLimit = resources.getInteger(R.integer.num_images_to_preload);
        mFlipDuration = resources.getInteger(R.integer.flip_duration);
        mPhotoSource = new PhotoSourcePlexor(getContext(),
                getContext().getSharedPreferences(FlipperDreamSettings.PREFS_NAME, 0));
        mBitmapStore = new HashMap<View, Bitmap>();
        mBitmapQueue = new LinkedList<Bitmap>();
        mBitmapLoaders = new LinkedList<PhotoLoadTask>();
 
        mPanel = new View[2];
        mFlipper = new Flipper();
        // this is dead code if the dream calls setInteractive(false) 
        mGestureDetector = new GestureDetector(context,
                new GestureDetector.SimpleOnGestureListener() {
                    @Override 
                    public boolean onFling(MotionEvent e1, MotionEvent e2, float vX, float vY) {
                        log("fling with " + vX);
                        flip(Math.signum(vX));
                        return true; 
                    } 
                }); 
    } 
 
    private float lockTo180(float a) {
        return 180f * (float) Math.floor(a / 180f);
    } 
 
    private float wrap360(float a) {
        return a - 360f * (float) Math.floor(a / 360f);
    } 
 
    private class PhotoLoadTask extends AsyncTask<Void, Void, Bitmap> {
        private final BitmapFactory.Options mOptions;
 
        public PhotoLoadTask () { 
            mOptions = new BitmapFactory.Options();
            mOptions.inTempStorage = new byte[32768];
        } 
 
        @Override 
        public Bitmap doInBackground(Void... unused) {
            Bitmap decodedPhoto;
            if (mLongSide == 0 || mShortSide == 0) {
                return null; 
            } 
            decodedPhoto = mPhotoSource.next(mOptions, mLongSide, mShortSide);
            return decodedPhoto;
        } 
 
        @Override 
        public void onPostExecute(Bitmap photo) {
            if (photo != null) {
                mBitmapQueue.offer(photo);
            } 
            mFlipper.run();
        } 
    };