Example usage for android.widget FrameLayout getChildAt

List of usage examples for android.widget FrameLayout getChildAt

Introduction

In this page you can find the example usage for android.widget FrameLayout getChildAt.

Prototype

public View getChildAt(int index) 

Source Link

Document

Returns the view at the specified position in the group.

Usage

From source file:dk.nordfalk.aktivitetsliste.PagerSlidingTabStrip.java

private void fadeTekstOgIkoner(int position) {
    //fadeInd.reset();
    //fadeUd.reset();
    Object t = tabsContainer.getChildAt(forrigePosition);
    if (t instanceof FrameLayout) {
        final FrameLayout fl = (FrameLayout) t;
        fl.getChildAt(0).clearAnimation();
        fl.getChildAt(1).clearAnimation();
        fl.getChildAt(0).setVisibility(View.INVISIBLE);
        fl.getChildAt(1).setVisibility(View.VISIBLE);
        /*//  www  . j a  v  a 2s .co  m
        fl.getChildAt(0).startAnimation(fadeUd);
        fl.getChildAt(1).startAnimation(fadeInd);
        fadeInd.setAnimationListener(new AnimationAdapter() {
          @Override
          public void onAnimationEnd(Animation animation) {
            fl.getChildAt(0).setVisibility(View.INVISIBLE);
            fl.getChildAt(1).setVisibility(View.VISIBLE);
          }
        });
        */
    }
    t = tabsContainer.getChildAt(position);
    /*
    if (t instanceof FrameLayout) {
      final FrameLayout fl = (FrameLayout) t;
      fl.getChildAt(0).startAnimation(fadeInd);
      fl.getChildAt(1).startAnimation(fadeUd);
      fadeUd.setAnimationListener(new AnimationAdapter() {
        @Override
        public void onAnimationEnd(Animation animation) {
          fl.getChildAt(0).setVisibility(View.VISIBLE);
          fl.getChildAt(1).setVisibility(View.INVISIBLE);
        }
      });
    }
    */
    forrigePosition = position;
}

From source file:arefin.dialogs.core.BaseDialogFragment.java

@Override
public void onShow(DialogInterface dialog) {
    if (getView() != null) {
        ScrollView vMessageScrollView = (ScrollView) getView().findViewById(R.id.sdl_message_scrollview);
        ListView vListView = (ListView) getView().findViewById(R.id.sdl_list);
        FrameLayout vCustomViewNoScrollView = (FrameLayout) getView().findViewById(R.id.sdl_custom);
        boolean customViewNoScrollViewScrollable = false;
        if (vCustomViewNoScrollView.getChildCount() > 0) {
            View firstChild = vCustomViewNoScrollView.getChildAt(0);
            if (firstChild instanceof ViewGroup) {
                customViewNoScrollViewScrollable = isScrollable((ViewGroup) firstChild);
            }//from   www .j  a  v  a 2 s. c o  m
        }
        boolean listViewScrollable = isScrollable(vListView);
        boolean messageScrollable = isScrollable(vMessageScrollView);
        boolean scrollable = listViewScrollable || messageScrollable || customViewNoScrollViewScrollable;
        modifyButtonsBasedOnScrollableContent(scrollable);
    }
}

From source file:dk.dr.radio.diverse.PagerSlidingTabStrip.java

private void fadeTekstOgIkoner(int position) {
      //fadeInd.reset();
      //fadeUd.reset();
      Object t = tabsContainer.getChildAt(forrigePosition);
      if (t instanceof FrameLayout) {
          final FrameLayout fl = (FrameLayout) t;
          fl.getChildAt(0).clearAnimation();
          fl.getChildAt(1).clearAnimation();
          fl.getChildAt(0).setVisibility(View.INVISIBLE);
          fl.getChildAt(1).setVisibility(View.VISIBLE);
          /*//from   w  w w.ja  va 2 s.com
          fl.getChildAt(0).startAnimation(fadeUd);
          fl.getChildAt(1).startAnimation(fadeInd);
          fadeInd.setAnimationListener(new AnimationAdapter() {
            @Override
            public void onAnimationEnd(Animation animation) {
              fl.getChildAt(0).setVisibility(View.INVISIBLE);
              fl.getChildAt(1).setVisibility(View.VISIBLE);
            }
          });
          */
      }
      t = tabsContainer.getChildAt(position);
      if (t instanceof FrameLayout) {
          final FrameLayout fl = (FrameLayout) t;
          fl.getChildAt(0).startAnimation(fadeInd);
          fl.getChildAt(1).startAnimation(fadeUd);
          fadeUd.setAnimationListener(new AnimationAdapter() {
              @Override
              public void onAnimationEnd(Animation animation) {
                  fl.getChildAt(0).setVisibility(View.VISIBLE);
                  fl.getChildAt(1).setVisibility(View.INVISIBLE);
              }
          });
      }
      forrigePosition = position;
  }

From source file:com.example.guxiuzhong.pagerslidingtab_lib.PagerSlidingTabStrip.java

private void updateTabStyles() {
    for (int i = 0; i < tabCount; i++) {
        FrameLayout frameLayout = (FrameLayout) tabsContainer.getChildAt(i);
        frameLayout.setBackgroundResource(tabBackgroundResId);

        for (int j = 0; j < frameLayout.getChildCount(); j++) {
            View v = frameLayout.getChildAt(j);
            if (v instanceof TextView) {
                TextView tab = (TextView) v;
                tab.setTextSize(TypedValue.COMPLEX_UNIT_PX, tabTextSize);
                tab.setTypeface(tabTypeface, tabTypefaceStyle);
                if (j == 0) {
                    tab.setTextColor(tabTextColor);
                } else {
                    tab.setTextColor(selectedTabTextColor);
                }/* www  . j  a  v  a2  s. c o  m*/
                ViewHelper.setAlpha(tabViews.get(i).get("normal"), 1);
                ViewHelper.setAlpha(tabViews.get(i).get("selected"), 0);

                //set normal  Scale
                ViewHelper.setPivotX(frameLayout, frameLayout.getMeasuredWidth() * 0.5f);
                ViewHelper.setPivotY(frameLayout, frameLayout.getMeasuredHeight() * 0.5f);
                ViewHelper.setScaleX(frameLayout, 1f);
                ViewHelper.setScaleY(frameLayout, 1f);

                // setAllCaps() is only available from API 14, so the upper case is made manually if we are on a
                // pre-ICS-build
                if (textAllCaps) {
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
                        tab.setAllCaps(true);
                    } else {
                        tab.setText(tab.getText().toString().toUpperCase(locale));
                    }
                }
                if (i == selectedPosition) {
                    ViewHelper.setAlpha(tabViews.get(i).get("normal"), 0);
                    ViewHelper.setAlpha(tabViews.get(i).get("selected"), 1);

                    //set select  Scale
                    ViewHelper.setPivotX(frameLayout, frameLayout.getMeasuredWidth() * 0.5f);
                    ViewHelper.setPivotY(frameLayout, frameLayout.getMeasuredHeight() * 0.5f);
                    ViewHelper.setScaleX(frameLayout, 1 + zoomMax);
                    ViewHelper.setScaleY(frameLayout, 1 + zoomMax);
                }
            }
        }
    }
}

From source file:info.tellmetime.TellmetimeActivity.java

@Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
    // Delay hiding the panel. This is to prevent the jarring behavior of
    // controls going away while interacting with UI.
    mHider.delayedHide(4000);/*from   w w  w.ja v a 2 s  .c om*/

    FrameLayout frameBackgroundMode = (FrameLayout) findViewById(R.id.frameBackgroundMode);
    for (int i = 0; i < frameBackgroundMode.getChildCount(); i++)
        frameBackgroundMode.getChildAt(i).setVisibility(View.GONE);
    frameBackgroundMode.getChildAt(position).setVisibility(View.VISIBLE);

    mBackgroundMode = position;

    switchBackgroundMode(position);
}

From source file:com.frostwire.android.gui.fragments.SearchFragment.java

private void switchView(View v, int id) {
    if (v != null) {
        FrameLayout frameLayout = findView(v, R.id.fragment_search_framelayout);
        int childCount = frameLayout.getChildCount();
        for (int i = 0; i < childCount; i++) {
            View childAt = frameLayout.getChildAt(i);
            childAt.setVisibility((childAt.getId() == id) ? View.VISIBLE : View.INVISIBLE);
        }//from  w w w  .j a  v a  2 s  . c om
    }
}

From source file:com.andreadec.musicplayer.MainActivity.java

@SuppressLint({ "InlinedApi", "NewApi" })
@Override// www.java2  s.  c  om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setVolumeControlStream(AudioManager.STREAM_MUSIC);

    preferences = PreferenceManager.getDefaultSharedPreferences(this);
    if (preferences.getBoolean(Constants.PREFERENCE_DISABLELOCKSCREEN, Constants.DEFAULT_DISABLELOCKSCREEN)) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD); // Disable lock screen for this activity
    }

    requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS);

    if (preferences.getBoolean(Constants.PREFERENCE_SHOWHELPOVERLAYMAINACTIVITY, true)) {
        final FrameLayout frameLayout = new FrameLayout(this);
        LayoutInflater layoutInflater = getLayoutInflater();
        layoutInflater.inflate(R.layout.layout_main, frameLayout);
        layoutInflater.inflate(R.layout.layout_helpoverlay_main, frameLayout);
        final View overlayView = frameLayout.getChildAt(1);
        overlayView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                frameLayout.removeView(overlayView);
                SharedPreferences.Editor editor = preferences.edit();
                editor.putBoolean(Constants.PREFERENCE_SHOWHELPOVERLAYMAINACTIVITY, false);
                editor.commit();
            }
        });
        setContentView(frameLayout);
    } else {
        setContentView(R.layout.layout_main);
    }

    pages = new String[4];
    pages[PAGE_BROWSER] = getResources().getString(R.string.browser);
    pages[PAGE_PLAYLISTS] = getResources().getString(R.string.playlist);
    pages[PAGE_RADIOS] = getResources().getString(R.string.radio);
    pages[PAGE_PODCASTS] = getResources().getString(R.string.podcasts);
    fragmentManager = getSupportFragmentManager();
    setTitle(pages[currentPage]);

    /* NAVIGATION DRAWER */
    drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
    drawerToggle = new ActionBarDrawerToggle(this, drawerLayout, R.drawable.ic_drawer, R.string.drawer_open,
            R.string.drawer_close) {
        public void onDrawerClosed(View view) {
            super.onDrawerClosed(view);
            setTitle(pages[currentPage]);
        }

        public void onDrawerOpened(View drawerView) {
            super.onDrawerOpened(drawerView);
            setTitle(getResources().getString(R.string.app_name));
        }
    };
    drawerLayout.setDrawerListener(drawerToggle);
    if (Build.VERSION.SDK_INT >= 11)
        getActionBar().setDisplayHomeAsUpEnabled(true);
    drawerContainer = (RelativeLayout) findViewById(R.id.navigation_container);
    drawerList = (ListView) findViewById(R.id.navigation_list);
    navigationAdapter = new NavigationDrawerArrayAdapter(this, pages);
    drawerList.setAdapter(navigationAdapter);
    drawerList.setOnItemClickListener(new ListView.OnItemClickListener() {
        @Override
        public void onItemClick(@SuppressWarnings("rawtypes") AdapterView parent, View view, int position,
                long id) {
            openPage(position);
            drawerLayout.closeDrawer(drawerContainer);
        }
    });
    buttonQuit = findViewById(R.id.navigation_buttonQuit);
    buttonQuit.setOnClickListener(this);

    if (Build.VERSION.SDK_INT >= 19) {
        // Android 4.4+ only
        boolean translucentStatus = preferences.getBoolean(Constants.PREFERENCE_TRANSLUCENTSTATUSBAR,
                Constants.DEFAULT_TRANSLUCENTSTATUSBAR);
        boolean translucentNavigation = preferences.getBoolean(Constants.PREFERENCE_TRANSLUCENTNAVIGATIONBAR,
                Constants.DEFAULT_TRANSLUCENTNAVIGATIONBAR);

        if (translucentStatus)
            getWindow().addFlags(LayoutParams.FLAG_TRANSLUCENT_STATUS);
        if (translucentNavigation)
            getWindow().addFlags(LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);

        SystemBarTintManager tintManager = new SystemBarTintManager(this);
        if (translucentStatus) {
            tintManager.setStatusBarTintEnabled(true);
            tintManager.setStatusBarTintResource(R.color.actionBarBackground);
        }
    }

    textViewArtist = (TextView) findViewById(R.id.textViewArtist);
    textViewTitle = (TextView) findViewById(R.id.textViewTitle);
    textViewTime = (TextView) findViewById(R.id.textViewTime);
    imageViewSongImage = (ImageView) findViewById(R.id.imageViewSongImage);
    imageButtonPrevious = (ImageButton) findViewById(R.id.imageButtonPrevious);
    imageButtonPlayPause = (ImageButton) findViewById(R.id.imageButtonPlayPause);
    imageButtonNext = (ImageButton) findViewById(R.id.imageButtonNext);
    seekBar1 = (SeekBar) findViewById(R.id.seekBar1);
    seekBar2 = (SeekBar) findViewById(R.id.seekBar2);
    imageButtonShowSeekbar2 = (ImageButton) findViewById(R.id.imageButtonShowSeekbar2);
    imageButtonShuffle = (ImageButton) findViewById(R.id.imageButtonShuffle);
    imageButtonRepeat = (ImageButton) findViewById(R.id.imageButtonRepeat);
    imageButtonRepeatAll = (ImageButton) findViewById(R.id.imageButtonRepeatAll);
    buttonBassBoost = (Button) findViewById(R.id.buttonBassBoost);
    buttonEqualizer = (Button) findViewById(R.id.buttonEqualizer);
    buttonShake = (Button) findViewById(R.id.buttonShake);

    imageButtonShuffle.setOnClickListener(this);
    imageButtonRepeat.setOnClickListener(this);
    imageButtonRepeatAll.setOnClickListener(this);
    buttonBassBoost.setOnClickListener(this);
    buttonEqualizer.setOnClickListener(this);
    buttonShake.setOnClickListener(this);

    imageButtonShowSeekbar2.setOnClickListener(this);
    imageButtonPrevious.setOnClickListener(this);
    imageButtonPlayPause.setOnClickListener(this);
    imageButtonNext.setOnClickListener(this);
    seekBar1.setOnSeekBarChangeListener(this);
    seekBar1.setClickable(false);
    seekBar2.setOnSeekBarChangeListener(this);
    textViewTime.setOnClickListener(this);

    showSongImage = preferences.getBoolean(Constants.PREFERENCE_SHOWSONGIMAGE, Constants.DEFAULT_SHOWSONGIMAGE);
    imagesCache = new LruCache<String, Bitmap>(Constants.IMAGES_CACHE_SIZE);

    serviceIntent = new Intent(this, MusicService.class);
    startService(serviceIntent); // Starts the service if it is not running

    if (preferences.getBoolean(Constants.PREFERENCE_OPENLASTPAGEONSTART,
            Constants.DEFAULT_OPENLASTPAGEONSTART)) {
        openPage(preferences.getInt(Constants.PREFERENCE_LASTPAGE, Constants.DEFAULT_LASTPAGE));
    } else {
        openPage(PAGE_BROWSER);
    }
    loadSongFromIntent();

    layoutPlaybackControls = findViewById(R.id.layoutPlaybackControls);
    if (preferences.getBoolean(Constants.PREFERENCE_ENABLEGESTURES, Constants.DEFAULT_ENABLEGESTURES)) {
        final GestureDetectorCompat gestureDetector = new GestureDetectorCompat(this,
                new PlayerGestureListener());
        View layoutTop = findViewById(R.id.layoutTop);
        layoutTop.setOnTouchListener(new OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return gestureDetector.onTouchEvent(event);
            }
        });
        if (preferences.getBoolean(Constants.PREFERENCE_SHOWPLAYBACKCONTROLS,
                Constants.DEFAULT_SHOWPLAYBACKCONTROLS)) {
            layoutPlaybackControls.setVisibility(View.VISIBLE);
        }
    } else {
        layoutPlaybackControls.setVisibility(View.VISIBLE);
    }
}

From source file:com.google.android.apps.santatracker.rocketsleigh.RocketSleighActivity.java

private void processFrame() {
    long newTime = System.currentTimeMillis();
    long time = newTime - mLastTime;

    boolean end = false;

    if (time > 60) {
        Log.e("LONG", "Frame time took too long! Time: " + time + " Last process frame: " + mLastFrameTime
                + " Count: " + mBackgroundCount + " Level: " + mLevel);
    }//  w  ww .j  a  v  a 2  s  .c o m

    // We don't want to jump too far so, if real time is > 60 treat it as 33.  On screen will seem to slow
    // down instaead of "jump"
    if (time > 60) {
        time = 33;
    }

    // Score is based on time + presents.  Right now 100 point per second played.  No presents yet
    if (mLevel < 6) {
        mScore += time;
    }

    if (mIsTv) {
        mScoreText.setText(mScoreLabel + ": " + NumberFormat.getNumberInstance().format((mScore / 10)));
    } else {
        mScoreText.setText(NumberFormat.getNumberInstance().format((mScore / 10)));
    }

    float scroll = mElfVelX * time;

    // Do collision detection first...
    // The elf can't collide if it is within 2 seconds of colliding previously.
    if (mElfIsHit) {
        if ((newTime - mElfHitTime) > 2000) {
            // Move to next state.
            if (mElfState < 4) {
                mElfState++;
                AnalyticsManager.sendEvent(getString(R.string.analytics_screen_rocket),
                        getString(R.string.analytics_action_rocket_hit), null, mElfState);
                if (mElfState == 4) {
                    mSoundPool.play(mGameOverSound, 1.0f, 1.0f, 2, 0, 1.0f);
                    // No more control...
                    mControlView.setOnTouchListener(null);
                    mElfAccelY = 0.0f;
                    if (mJetThrustStream != 0) {
                        mSoundPool.stop(mJetThrustStream);
                    }
                }
            }
            updateElf(false);
            mElfIsHit = false;
        }
    } else if (mElfState == 4) {
        // Don't do any collision detection for parachute elf.  Just let him fall...
    } else {
        // Find the obstacle(s) we might be colliding with.  It can only be one of the first 3 obstacles.
        for (int i = 0; i < 3; i++) {
            View view = mObstacleLayout.getChildAt(i);
            if (view == null) {
                // No more obstacles...
                break;
            }

            int[] tmp = new int[2];
            view.getLocationOnScreen(tmp);

            // If the start of this view is past the center of the elf, we are done
            if (tmp[0] > mElfPosX) {
                break;
            }

            if (RelativeLayout.class.isInstance(view)) {
                // this is an obstacle layout.
                View topView = view.findViewById(R.id.top_view);
                View bottomView = view.findViewById(R.id.bottom_view);
                if ((topView != null) && topView.getVisibility() == View.VISIBLE) {
                    topView.getLocationOnScreen(tmp);
                    Rect obsRect = new Rect(tmp[0], tmp[1], tmp[0] + topView.getWidth(),
                            tmp[1] + topView.getHeight());
                    if (obsRect.contains((int) mElfPosX, (int) mElfPosY + mElfBitmap.getHeight() / 2)) {
                        handleCollision();
                    }
                }
                if (!mElfIsHit) {
                    if ((bottomView != null) && bottomView.getVisibility() == View.VISIBLE) {
                        bottomView.getLocationOnScreen(tmp);
                        Rect obsRect = new Rect(tmp[0], tmp[1], tmp[0] + bottomView.getWidth(),
                                tmp[1] + bottomView.getHeight());
                        if (obsRect.contains((int) mElfPosX, (int) mElfPosY + mElfBitmap.getHeight() / 2)) {
                            // Special case for the mammoth obstacle...
                            if (bottomView.getTag() != null) {
                                if (((mElfPosX - tmp[0]) / (float) bottomView.getWidth()) > 0.25f) {
                                    // We are over the mammoth not the spike.  lower the top of the rect and test again.
                                    obsRect.top = (int) (tmp[1] + ((float) bottomView.getHeight() * 0.18f));
                                    if (obsRect.contains((int) mElfPosX,
                                            (int) mElfPosY + mElfBitmap.getHeight() / 2)) {
                                        handleCollision();
                                    }
                                }
                            } else {
                                handleCollision();
                            }
                        }
                    }
                }
            } else if (FrameLayout.class.isInstance(view)) {
                // Present view
                FrameLayout frame = (FrameLayout) view;
                if (frame.getChildCount() > 0) {
                    ImageView presentView = (ImageView) frame.getChildAt(0);
                    presentView.getLocationOnScreen(tmp);
                    Rect presentRect = new Rect(tmp[0], tmp[1], tmp[0] + presentView.getWidth(),
                            tmp[1] + presentView.getHeight());
                    mElfLayout.getLocationOnScreen(tmp);
                    Rect elfRect = new Rect(tmp[0], tmp[1], tmp[0] + mElfLayout.getWidth(),
                            tmp[1] + mElfLayout.getHeight());
                    if (elfRect.intersect(presentRect)) {
                        // We got a present!
                        mPresentCount++;
                        if (mPresentCount < 4) {
                            mSoundPool.play(mScoreSmallSound, 1.0f, 1.0f, 2, 0, 1.0f);
                            mScore += 1000; // 100 points.  Score is 10x displayed score.
                            mPlus100.setVisibility(View.VISIBLE);
                            if (mElfPosY > (mScreenHeight / 2)) {
                                mPlus100.setY(mElfPosY - (mElfLayout.getHeight() + mPlus100.getHeight()));
                            } else {
                                mPlus100.setY(mElfPosY + mElfLayout.getHeight());
                            }
                            mPlus100.setX(mElfPosX);
                            if (m100Anim.hasStarted()) {
                                m100Anim.reset();
                            }
                            mPlus100.startAnimation(m100Anim);
                        } else {
                            mSoundPool.play(mScoreBigSound, 1.0f, 1.0f, 2, 0, 1.0f);
                            mScore += 5000; // 500 points.  Score is 10x displayed score.
                            if (!mRainingPresents) {
                                mPresentCount = 0;
                            }
                            mPlus500.setVisibility(View.VISIBLE);
                            if (mElfPosY > (mScreenHeight / 2)) {
                                mPlus500.setY(mElfPosY - (mElfLayout.getHeight() + mPlus100.getHeight()));
                            } else {
                                mPlus500.setY(mElfPosY + mElfLayout.getHeight());
                            }
                            mPlus500.setX(mElfPosX);
                            if (m500Anim.hasStarted()) {
                                m500Anim.reset();
                            }
                            mPlus500.startAnimation(m500Anim);
                            mPresentBonus = true;
                        }
                        frame.removeView(presentView);
                    } else if (elfRect.left > presentRect.right) {
                        mPresentCount = 0;
                    }
                }
            }
        }
    }

    if (mForegroundLayout.getChildCount() > 0) {
        int currentX = mForegroundScroll.getScrollX();
        View view = mForegroundLayout.getChildAt(0);
        int newX = currentX + (int) scroll;
        if (newX > view.getWidth()) {
            newX -= view.getWidth();
            mForegroundLayout.removeViewAt(0);
        }
        mForegroundScroll.setScrollX(newX);
    }

    // Scroll obstacle views
    if (mObstacleLayout.getChildCount() > 0) {
        int currentX = mObstacleScroll.getScrollX();
        View view = mObstacleLayout.getChildAt(0);
        int newX = currentX + (int) scroll;
        if (newX > view.getWidth()) {
            newX -= view.getWidth();
            mObstacleLayout.removeViewAt(0);
        }
        mObstacleScroll.setScrollX(newX);
    }

    // Scroll the background and foreground
    if (mBackgroundLayout.getChildCount() > 0) {
        int currentX = mBackgroundScroll.getScrollX();
        View view = mBackgroundLayout.getChildAt(0);
        int newX = currentX + (int) scroll;
        if (newX > view.getWidth()) {
            newX -= view.getWidth();
            mBackgroundLayout.removeViewAt(0);
            if (view.getTag() != null) {
                Pair<Integer, Integer> pair = (Pair<Integer, Integer>) view.getTag();
                int type = pair.first;
                int level = pair.second;
                if (type == 0) {
                    if (mBackgrounds[level] != null) {
                        mBackgrounds[level].recycle();
                        mBackgrounds[level] = null;
                    } else if (mBackgrounds2[level] != null) {
                        mBackgrounds2[level].recycle();
                        mBackgrounds2[level] = null;
                    }
                } else if (type == 1) {
                    if (mExitTransitions[level] != null) {
                        mExitTransitions[level].recycle();
                        mExitTransitions[level] = null;
                    }
                } else if (type == 2) {
                    if (mEntryTransitions[level] != null) {
                        mEntryTransitions[level].recycle();
                        mEntryTransitions[level] = null;
                    }
                }
            }
            if (mBackgroundCount == 5) {
                if (mLevel < 6) {
                    // Pre-fetch next levels backgrounds
                    // end level uses the index 1 background...
                    int level = (mLevel == 5) ? 1 : (mLevel + 1);
                    BackgroundLoadTask task = new BackgroundLoadTask(getResources(), mLevel + 1,
                            BACKGROUNDS[level], EXIT_TRANSITIONS[mLevel],
                            // Exit transitions are for the current level...
                            ENTRY_TRANSITIONS[level], mScaleX, mScaleY, mBackgrounds, mBackgrounds2,
                            mExitTransitions, mEntryTransitions, mScreenWidth, mScreenHeight);
                    task.execute();
                    addNextImages(mLevel, true);
                    addNextObstacles(mLevel, 2);
                }
                // Fetch first set of obstacles if the next level changes from woods to cave or cave to factory
                if (mLevel == 1) {
                    // Next level will be caves.  Get bitmaps for the first 20 obstacles.
                    ObstacleLoadTask task = new ObstacleLoadTask(getResources(), CAVE_OBSTACLES, mCaveObstacles,
                            mCaveObstacleList, 0, 2, mScaleX, mScaleY);
                    task.execute();
                } else if (mLevel == 3) {
                    // Next level will be factory.  Get bitmaps for the first 20 obstacles.
                    ObstacleLoadTask task = new ObstacleLoadTask(getResources(), FACTORY_OBSTACLES,
                            mFactoryObstacles, mFactoryObstacleList, 0, 2, mScaleX, mScaleY);
                    task.execute();
                }
                mBackgroundCount++;
            } else if (mBackgroundCount == 7) {
                // Add transitions and/or next level
                if (mLevel < 5) {
                    addNextTransitionImages(mLevel + 1);
                    if (mTransitionImagesCount > 0) {
                        addNextObstacleSpacer(mTransitionImagesCount);
                    }
                    addNextImages(mLevel + 1);
                    // First screen of each new level has no obstacles
                    if ((mLevel % 2) == 1) {
                        addNextObstacleSpacer(1);
                        addNextObstacles(mLevel + 1, 1);
                    } else {
                        addNextObstacles(mLevel + 1, 2);
                    }
                } else if (mLevel == 5) {
                    addNextTransitionImages(mLevel + 1);
                    if (mTransitionImagesCount > 0) {
                        addNextObstacleSpacer(mTransitionImagesCount);
                    }
                    addFinalImages();
                }
                mBackgroundCount++;
            } else if (mBackgroundCount == 9) {
                // Either the transition or the next level is showing
                if (this.mTransitionImagesCount > 0) {
                    mTransitionImagesCount--;
                } else {
                    if (mLevel == 1) {
                        // Destroy the wood obstacle bitmaps
                        Thread thread = new Thread(new Runnable() {
                            @Override
                            public void run() {
                                synchronized (mWoodObstacles) {
                                    for (Bitmap bmp : mWoodObstacles.values()) {
                                        bmp.recycle();
                                    }
                                    mWoodObstacles.clear();
                                }
                            }
                        });
                        thread.start();
                    } else if (mLevel == 3) {
                        // Destroy the cave obstacle bitmaps
                        Thread thread = new Thread(new Runnable() {
                            @Override
                            public void run() {
                                synchronized (mCaveObstacles) {
                                    for (Bitmap bmp : mCaveObstacles.values()) {
                                        bmp.recycle();
                                    }
                                    mCaveObstacles.clear();
                                }
                            }
                        });
                        thread.start();
                    } else if (mLevel == 5) {
                        // Destroy the factory obstacle bitmaps
                        Thread thread = new Thread(new Runnable() {
                            @Override
                            public void run() {
                                synchronized (mFactoryObstacles) {
                                    for (Bitmap bmp : mFactoryObstacles.values()) {
                                        bmp.recycle();
                                    }
                                    mFactoryObstacles.clear();
                                }
                            }
                        });
                        thread.start();
                    }
                    mLevel++;

                    // Add an event for clearing this level - note we don't increment mLevel as
                    // it's 0-based and we're tracking the previous level.
                    AnalyticsManager.sendEvent(getString(R.string.analytics_screen_rocket),
                            getString(R.string.analytics_action_rocket_level), null, mLevel);

                    // Achievements
                    if (!mHitLevel) {
                        mCleanLevel = true;
                    }
                    mHitLevel = false;
                    if (mLevel == 5) {
                        mPlus100.setSelected(true);
                        mPlus500.setSelected(true);
                    } else if (mLevel == 6) {
                        mPlus100.setSelected(false);
                        mPlus500.setSelected(false);
                    }
                    if (mLevel < 6) {
                        mSoundPool.play(mLevelUpSound, 1.0f, 1.0f, 2, 0, 1.0f);
                        addNextImages(mLevel);
                        addNextObstacles(mLevel, 2);
                    }
                    mBackgroundCount = 0;
                }
            } else {
                if ((mBackgroundCount % 2) == 1) {
                    if (mLevel < 6) {
                        addNextImages(mLevel);
                        addNextObstacles(mLevel, 2);
                    }
                }
                mBackgroundCount++;
            }
        }
        int current = mBackgroundScroll.getScrollX();
        mBackgroundScroll.setScrollX(newX);
        if ((mLevel == 6) && (mBackgroundScroll.getScrollX() == current)) {
            end = true;
        }
    }

    // Check on the elf
    boolean hitBottom = false;
    boolean hitTop = false;

    float deltaY = mElfVelY * time;
    mElfPosY = mElfLayout.getY() + deltaY;
    if (mElfPosY < 0.0f) {
        mElfPosY = 0.0f;
        mElfVelY = 0.0f;
        hitTop = true;
    } else if (mElfPosY > (mScreenHeight - mElfLayout.getHeight())) {
        mElfPosY = mScreenHeight - mElfLayout.getHeight();
        mElfVelY = 0.0f;
        hitBottom = true;
    } else {
        // Remember -Y is up!
        mElfVelY += (mGravityAccelY * time - mElfAccelY * time);
    }
    mElfLayout.setY(mElfPosY);

    // Rotate the elf to indicate thrust, dive.
    float rot = (float) (Math.atan(mElfVelY / mElfVelX) * 120.0 / Math.PI);
    mElfLayout.setRotation(rot);

    mElf.invalidate();

    // Update the time and spawn the next call to processFrame.
    mLastTime = newTime;
    mLastFrameTime = System.currentTimeMillis() - newTime;
    if (!end) {
        if ((mElfState < 4) || !hitBottom) {
            if (mLastFrameTime < 16) {
                mHandler.postDelayed(mGameLoop, 16 - mLastFrameTime);
            } else {
                mHandler.post(mGameLoop);
            }
        } else {
            endGame();
        }
    } else {
        // Whatever the final stuff is, do it here.
        mPlayPauseButton.setEnabled(false);
        mPlayPauseButton.setVisibility(View.INVISIBLE);
        endGame();
    }
}