Example usage for android.view View getVisibility

List of usage examples for android.view View getVisibility

Introduction

In this page you can find the example usage for android.view View getVisibility.

Prototype

@ViewDebug.ExportedProperty(mapping = { @ViewDebug.IntToString(from = VISIBLE, to = "VISIBLE"),
        @ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"),
        @ViewDebug.IntToString(from = GONE, to = "GONE") })
@Visibility
public int getVisibility() 

Source Link

Document

Returns the visibility status for this view.

Usage

From source file:com.jackie.sample.custom_view.CustomViewPagerInternal.java

/**
 * We only want the current page that is being shown to be focusable.
 *//*from w  w  w .jav a  2 s.  c om*/
@Override
public void addFocusables(ArrayList<View> views, int direction, int focusableMode) {
    final int focusableCount = views.size();

    final int descendantFocusability = getDescendantFocusability();

    if (descendantFocusability != FOCUS_BLOCK_DESCENDANTS) {
        for (int i = 0; i < getChildCount(); i++) {
            final View child = getChildAt(i);
            if (child.getVisibility() == VISIBLE) {
                ItemInfo ii = infoForChild(child);
                if (ii != null && ii.position == mCurItem) {
                    child.addFocusables(views, direction, focusableMode);
                }
            }
        }
    }

    // we add ourselves (if focusable) in all cases except for when we are
    // FOCUS_AFTER_DESCENDANTS and there are some descendants focusable. this is
    // to avoid the focus search finding layouts when a more precise search
    // among the focusable children would be more interesting.
    if (descendantFocusability != FOCUS_AFTER_DESCENDANTS ||
    // No focusable descendants
            (focusableCount == views.size())) {
        // Note that we can't call the superclass here, because it will
        // add all views in. So we need to do the same thing View does.
        if (!isFocusable()) {
            return;
        }
        if ((focusableMode & FOCUSABLES_TOUCH_MODE) == FOCUSABLES_TOUCH_MODE && isInTouchMode()
                && !isFocusableInTouchMode()) {
            return;
        }
        if (views != null) {
            views.add(this);
        }
    }
}

From source file:com.gome.ecmall.custom.VerticalViewPager.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;/*from w  w  w .  j a va  2 s.c om*/
    populate();
    mInLayout = false;

    final int count = getChildCount();
    int width = r - l;
    int height = b - t;
    int paddingLeft = getPaddingLeft();
    int paddingTop = getPaddingTop();
    int paddingRight = getPaddingRight();
    int paddingBottom = getPaddingBottom();
    final int scrollY = getScrollY();

    int decorCount = 0;

    // First pass - decor views. We need to do this in two passes so that
    // we have the proper offsets for non-decor views later.
    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            int childLeft = 0;
            int childTop = 0;
            if (lp.isDecor) {
                final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                switch (hgrav) {
                default:
                    childLeft = paddingLeft;
                    break;
                case Gravity.LEFT:
                    childLeft = paddingLeft;
                    paddingLeft += child.getMeasuredWidth();
                    break;
                case Gravity.CENTER_HORIZONTAL:
                    childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft);
                    break;
                case Gravity.RIGHT:
                    childLeft = width - paddingRight - child.getMeasuredWidth();
                    paddingRight += child.getMeasuredWidth();
                    break;
                }
                switch (vgrav) {
                default:
                    childTop = paddingTop;
                    break;
                case Gravity.TOP:
                    childTop = paddingTop;
                    paddingTop += child.getMeasuredHeight();
                    break;
                case Gravity.CENTER_VERTICAL:
                    childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop);
                    break;
                case Gravity.BOTTOM:
                    childTop = height - paddingBottom - child.getMeasuredHeight();
                    paddingBottom += child.getMeasuredHeight();
                    break;
                }
                childTop += scrollY;
                child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());
                decorCount++;
            }
        }
    }

    // Page views. Do this once we have the right padding offsets from
    // above.
    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            ItemInfo ii;
            if (!lp.isDecor && (ii = infoForChild(child)) != null) {
                int loff = (int) (height * ii.offset);
                int childTop = paddingTop + loff;
                int childLeft = paddingLeft;
                if (lp.needsMeasure) {
                    // This was added during layout and needs measurement.
                    // Do it now that we know what we're working with.
                    lp.needsMeasure = false;

                    final int widthSpec = MeasureSpec.makeMeasureSpec(width - paddingLeft - paddingRight,
                            MeasureSpec.EXACTLY);
                    final int heightSpec = MeasureSpec.makeMeasureSpec(
                            (height - paddingTop - paddingBottom) * lp.height, MeasureSpec.EXACTLY);
                    child.measure(widthSpec, heightSpec);
                }
                if (DEBUG)
                    Log.v(TAG, "Positioning #" + i + " " + child + " f=" + ii.object + ":" + childLeft + ","
                            + childTop + " " + child.getMeasuredWidth() + "x" + child.getMeasuredHeight());
                child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());
            }
        }
    }
    mLeftPageBounds = paddingLeft;
    mRightPageBounds = width - paddingRight;
    mDecorChildCount = decorCount;
    mFirstLayout = false;
}

From source file:android.support.designox.widget.CoordinatorLayout.java

/**
 * Get the position rect for the given child. If the child has currently requested layout
 * or has a visibility of GONE./*from   w  ww.  ja v  a 2  s.com*/
 *
 * @param child child view to check
 * @param transform true to include transformation in the output rect, false to
 *                        only account for the base position
 * @param out rect to set to the output values
 */
void getChildRect(View child, boolean transform, Rect out) {
    if (child.isLayoutRequested() || child.getVisibility() == View.GONE) {
        out.set(0, 0, 0, 0);
        return;
    }
    if (transform) {
        getDescendantRect(child, out);
    } else {
        out.set(child.getLeft(), child.getTop(), child.getRight(), child.getBottom());
    }
}

From source file:cgeo.geocaching.CacheDetailActivity.java

/**
 * Hide the short description, if it is contained somewhere at the start of the long description.
 *//*w  w  w  . ja  v a2s. c o m*/
public void potentiallyHideShortDescription() {
    final View shortView = ButterKnife.findById(this, R.id.description);
    if (shortView == null) {
        return;
    }
    if (shortView.getVisibility() == View.GONE) {
        return;
    }
    final String shortDescription = cache.getShortDescription();
    if (StringUtils.isNotBlank(shortDescription)) {
        final int index = StringUtils.indexOf(cache.getDescription(), shortDescription);
        // allow up to 200 characters of HTML formatting
        if (index >= 0 && index < 200) {
            shortView.setVisibility(View.GONE);
        }
    }
}

From source file:chan.android.app.bitwise.util.StaggeredGridView.java

/**
 * Maps a point to a position in the list.
 *
 * @param x X in local coordinate//  ww w  .ja  v  a  2 s .  c  om
 * @param y Y in local coordinate
 * @return The position of the item which contains the specified point, or
 *         {@link #INVALID_POSITION} if the point does not intersect an item.
 */
public int pointToPosition(int x, int y) {
    Rect frame = mTouchFrame;
    if (frame == null) {
        mTouchFrame = new Rect();
        frame = mTouchFrame;
    }

    final int count = getChildCount();
    for (int i = count - 1; i >= 0; i--) {
        final View child = getChildAt(i);
        if (child.getVisibility() == View.VISIBLE) {
            child.getHitRect(frame);
            if (frame.contains(x, y)) {
                return mFirstPosition + i;
            }
        }
    }
    return INVALID_POSITION;
}

From source file:com.get_started.adapters.ViewPager.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // For simple implementation, or internal size is always 0.
    // We depend on the container to specify the layout size of
    // our view.  We can't really know what it is since we will be
    // adding and removing different arbitrary views and do not
    // want the layout to change as this happens.
    setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec));

    final int measuredWidth = getMeasuredWidth();
    final int maxGutterSize = measuredWidth / 10;
    mGutterSize = Math.min(maxGutterSize, mDefaultGutterSize);

    // Children are just made to fill our space.
    int childWidthSize = measuredWidth - getPaddingLeft() - getPaddingRight();
    int childHeightSize = getMeasuredHeight() - getPaddingTop() - getPaddingBottom();

    /*//from   w w w  .  j a  va2s.  c  o  m
     * Make sure all children have been properly measured. Decor views first.
     * Right now we cheat and make this less complicated by assuming decor
     * views won't intersect. We will pin to edges based on gravity.
     */
    int size = getChildCount();
    for (int i = 0; i < size; ++i) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp != null && lp.isDecor) {
                final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                int widthMode = MeasureSpec.AT_MOST;
                int heightMode = MeasureSpec.AT_MOST;
                boolean consumeVertical = vgrav == Gravity.TOP || vgrav == Gravity.BOTTOM;
                boolean consumeHorizontal = hgrav == Gravity.LEFT || hgrav == Gravity.RIGHT;

                if (consumeVertical) {
                    widthMode = MeasureSpec.EXACTLY;
                } else if (consumeHorizontal) {
                    heightMode = MeasureSpec.EXACTLY;
                }

                int widthSize = childWidthSize;
                int heightSize = childHeightSize;
                if (lp.width != LayoutParams.WRAP_CONTENT) {
                    widthMode = MeasureSpec.EXACTLY;
                    if (lp.width != LayoutParams.MATCH_PARENT) {
                        widthSize = lp.width;
                    }
                }
                if (lp.height != LayoutParams.WRAP_CONTENT) {
                    heightMode = MeasureSpec.EXACTLY;
                    if (lp.height != LayoutParams.MATCH_PARENT) {
                        heightSize = lp.height;
                    }
                }
                final int widthSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode);
                final int heightSpec = MeasureSpec.makeMeasureSpec(heightSize, heightMode);
                child.measure(widthSpec, heightSpec);

                if (consumeVertical) {
                    childHeightSize -= child.getMeasuredHeight();
                } else if (consumeHorizontal) {
                    childWidthSize -= child.getMeasuredWidth();
                }
            }
        }
    }

    mChildWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);
    mChildHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeightSize, MeasureSpec.EXACTLY);

    // Make sure we have created all fragments that we need to have shown.
    mInLayout = true;
    populate();
    mInLayout = false;

    // Page views next.
    size = getChildCount();
    for (int i = 0; i < size; ++i) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            if (DEBUG)
                Log.v(TAG, "Measuring #" + i + " " + child + ": " + mChildWidthMeasureSpec);

            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp == null || !lp.isDecor) {
                final int widthSpec = MeasureSpec.makeMeasureSpec((int) (childWidthSize * lp.widthFactor),
                        MeasureSpec.EXACTLY);
                child.measure(widthSpec, mChildHeightMeasureSpec);
            }
        }
    }
}

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);
    }//from   w w w .j av  a2 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();
    }
}

From source file:com.brantapps.viewpagerindicator.vertical.VerticalViewPager.java

@SuppressWarnings("deprecation")
@Override//from w  w  w. ja  v  a 2s  . c  o m
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // For simple implementation, or internal size is always 0.
    // We depend on the container to specify the layout size of
    // our view.  We can't really know what it is since we will be
    // adding and removing different arbitrary views and do not
    // want the layout to change as this happens.
    setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec));

    final int measuredWidth = getMeasuredWidth();
    final int maxGutterSize = measuredWidth / 10;
    mGutterSize = Math.min(maxGutterSize, mDefaultGutterSize);

    // Children are just made to fill our space.
    int childWidthSize = measuredWidth - getPaddingLeft() - getPaddingRight();
    int childHeightSize = getMeasuredHeight() - getPaddingTop() - getPaddingBottom();

    /*
     * Make sure all children have been properly measured. Decor views first.
     * Right now we cheat and make this less complicated by assuming decor
     * views won't intersect. We will pin to edges based on gravity.
     */
    int size = getChildCount();
    for (int i = 0; i < size; ++i) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp != null && lp.isDecor) {
                final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                int widthMode = MeasureSpec.AT_MOST;
                int heightMode = MeasureSpec.AT_MOST;
                boolean consumeVertical = vgrav == Gravity.TOP || vgrav == Gravity.BOTTOM;
                boolean consumeHorizontal = hgrav == Gravity.LEFT || hgrav == Gravity.RIGHT;

                if (consumeVertical) {
                    widthMode = MeasureSpec.EXACTLY;
                } else if (consumeHorizontal) {
                    heightMode = MeasureSpec.EXACTLY;
                }

                int widthSize = childWidthSize;
                int heightSize = childHeightSize;
                if (lp.width != LayoutParams.WRAP_CONTENT) {
                    widthMode = MeasureSpec.EXACTLY;
                    if (lp.width != LayoutParams.FILL_PARENT) {
                        widthSize = lp.width;
                    }
                }
                if (lp.height != LayoutParams.WRAP_CONTENT) {
                    heightMode = MeasureSpec.EXACTLY;
                    if (lp.height != LayoutParams.FILL_PARENT) {
                        heightSize = lp.height;
                    }
                }
                final int widthSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode);
                final int heightSpec = MeasureSpec.makeMeasureSpec(heightSize, heightMode);
                child.measure(widthSpec, heightSpec);

                if (consumeVertical) {
                    childHeightSize -= child.getMeasuredHeight();
                } else if (consumeHorizontal) {
                    childWidthSize -= child.getMeasuredWidth();
                }
            }
        }
    }

    mChildWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);
    mChildHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeightSize, MeasureSpec.EXACTLY);

    // Make sure we have created all fragments that we need to have shown.
    mInLayout = true;
    populate();
    mInLayout = false;

    // Page views next.
    size = getChildCount();
    for (int i = 0; i < size; ++i) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            if (DEBUG)
                Log.v(TAG, "Measuring #" + i + " " + child + ": " + mChildHeightMeasureSpec);

            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp == null || !lp.isDecor) {
                // BrantApps Change: Renamed widthSpec to heightSpec
                final int heightSpec = MeasureSpec.makeMeasureSpec((int) (childHeightSize * lp.heightFactor),
                        MeasureSpec.EXACTLY);
                // BrantApps Change: Was child.measure(widthSpec, mChildHeightMeasureSpec);
                child.measure(mChildWidthMeasureSpec, heightSpec);
            }
        }
    }
}

From source file:com.brantapps.viewpagerindicator.vertical.VerticalViewPager.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;/*from  ww  w  . j a  va  2s  .  com*/
    populate();
    mInLayout = false;

    final int count = getChildCount();
    int width = r - l;
    int height = b - t;
    int paddingLeft = getPaddingLeft();
    int paddingTop = getPaddingTop();
    int paddingRight = getPaddingRight();
    int paddingBottom = getPaddingBottom();
    // BrantApps Change: Renamed scrollX to scrollY and changed method call to get value
    final int scrollY = getScrollY();

    int decorCount = 0;

    // First pass - decor views. We need to do this in two passes so that
    // we have the proper offsets for non-decor views later.
    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            int childLeft = 0;
            int childTop = 0;
            if (lp.isDecor) {
                final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                switch (hgrav) {
                default:
                    childLeft = paddingLeft;
                    break;
                case Gravity.LEFT:
                    childLeft = paddingLeft;
                    paddingLeft += child.getMeasuredWidth();
                    break;
                case Gravity.CENTER_HORIZONTAL:
                    childLeft = Math.max((width - child.getMeasuredWidth()) / 2, paddingLeft);
                    break;
                case Gravity.RIGHT:
                    childLeft = width - paddingRight - child.getMeasuredWidth();
                    paddingRight += child.getMeasuredWidth();
                    break;
                }
                switch (vgrav) {
                default:
                    childTop = paddingTop;
                    break;
                case Gravity.TOP:
                    childTop = paddingTop;
                    paddingTop += child.getMeasuredHeight();
                    break;
                case Gravity.CENTER_VERTICAL:
                    childTop = Math.max((height - child.getMeasuredHeight()) / 2, paddingTop);
                    break;
                case Gravity.BOTTOM:
                    childTop = height - paddingBottom - child.getMeasuredHeight();
                    paddingBottom += child.getMeasuredHeight();
                    break;
                }
                // BrantApps Change: Was childLeft += scrollX;
                childTop += scrollY;
                child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());
                decorCount++;
            }
        }
    }

    // Page views. Do this once we have the right padding offsets from above.
    for (int i = 0; i < count; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            ItemInfo ii;
            if (!lp.isDecor && (ii = infoForChild(child)) != null) {
                // BrantApps Change: Was int loff = (int) (width * ii.offset);
                int loff = (int) (height * ii.offset);
                // BrantApps Change: Was int childLeft = paddingLeft + loff;
                int childLeft = paddingLeft;
                // BrantApps Change: Was int childTop = paddingTop;
                int childTop = paddingTop + loff;
                if (lp.needsMeasure) {
                    // This was added during layout and needs measurement.
                    // Do it now that we know what we're working with.
                    lp.needsMeasure = false;
                    // BrantApps Change: lp.heightFactor applied to heightSpec not widthSpec
                    final int widthSpec = MeasureSpec.makeMeasureSpec(width - paddingLeft - paddingRight,
                            MeasureSpec.EXACTLY);
                    final int heightSpec = MeasureSpec.makeMeasureSpec(
                            (int) ((height - paddingTop - paddingBottom) * lp.heightFactor),
                            MeasureSpec.EXACTLY);
                    child.measure(widthSpec, heightSpec);
                }
                if (DEBUG)
                    Log.v(TAG, "Positioning #" + i + " " + child + " f=" + ii.object + ":" + childLeft + ","
                            + childTop + " " + child.getMeasuredWidth() + "x" + child.getMeasuredHeight());
                child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());
            }
        }
    }
    // BrantApps Change: Was mTopPageBounds = paddingTop;
    mLeftPageBounds = paddingLeft;
    // BrantApps Change: Was mBottomPageBounds = height - paddingBottom;
    mRightPageBounds = width - paddingLeft;
    mDecorChildCount = decorCount;
    mFirstLayout = false;
}

From source file:com.jackie.sample.custom_view.CustomViewPagerInternal.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    // For simple implementation, or internal size is always 0.
    // We depend on the container to specify the layout size of
    // our view. We can't really know what it is since we will be
    // adding and removing different arbitrary views and do not
    // want the layout to change as this happens.
    setMeasuredDimension(getDefaultSize(0, widthMeasureSpec), getDefaultSize(0, heightMeasureSpec));

    final int measuredWidth = getMeasuredWidth();
    final int maxGutterSize = measuredWidth / 10;
    mGutterSize = Math.min(maxGutterSize, mDefaultGutterSize);

    // ChildrenBean are just made to fill our space.
    int childWidthSize = measuredWidth - getPaddingLeft() - getPaddingRight();
    int childHeightSize = getMeasuredHeight() - getPaddingTop() - getPaddingBottom();

    /*//  w  ww .  j a  v  a2  s.c o  m
     * Make sure all children have been properly measured. Decor views first.
     * Right now we cheat and make this less complicated by assuming decor
     * views won't intersect. We will pin to edges based on gravity.
     */
    int size = getChildCount();
    for (int i = 0; i < size; ++i) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp != null && lp.isDecor) {
                final int hgrav = lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
                int widthMode = MeasureSpec.AT_MOST;
                int heightMode = MeasureSpec.AT_MOST;
                boolean consumeVertical = vgrav == Gravity.TOP || vgrav == Gravity.BOTTOM;
                boolean consumeHorizontal = hgrav == Gravity.LEFT || hgrav == Gravity.RIGHT;

                if (consumeVertical) {
                    widthMode = MeasureSpec.EXACTLY;
                } else if (consumeHorizontal) {
                    heightMode = MeasureSpec.EXACTLY;
                }

                int widthSize = childWidthSize;
                int heightSize = childHeightSize;
                if (lp.width != LayoutParams.WRAP_CONTENT) {
                    widthMode = MeasureSpec.EXACTLY;
                    if (lp.width != LayoutParams.FILL_PARENT) {
                        widthSize = lp.width;
                    }
                }
                if (lp.height != LayoutParams.WRAP_CONTENT) {
                    heightMode = MeasureSpec.EXACTLY;
                    if (lp.height != LayoutParams.FILL_PARENT) {
                        heightSize = lp.height;
                    }
                }
                final int widthSpec = MeasureSpec.makeMeasureSpec(widthSize, widthMode);
                final int heightSpec = MeasureSpec.makeMeasureSpec(heightSize, heightMode);
                child.measure(widthSpec, heightSpec);

                if (consumeVertical) {
                    childHeightSize -= child.getMeasuredHeight();
                } else if (consumeHorizontal) {
                    childWidthSize -= child.getMeasuredWidth();
                }
            }
        }
    }

    mChildWidthMeasureSpec = MeasureSpec.makeMeasureSpec(childWidthSize, MeasureSpec.EXACTLY);
    mChildHeightMeasureSpec = MeasureSpec.makeMeasureSpec(childHeightSize, MeasureSpec.EXACTLY);

    // Make sure we have created all fragments that we need to have shown.
    mInLayout = true;
    populate();
    mInLayout = false;

    // Page views next.
    size = getChildCount();
    for (int i = 0; i < size; ++i) {
        final View child = getChildAt(i);
        if (child.getVisibility() != GONE) {
            if (DEBUG)
                Log.v(TAG, "Measuring #" + i + " " + child + ": " + mChildWidthMeasureSpec);

            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
            if (lp == null || !lp.isDecor) {
                final int widthSpec = MeasureSpec.makeMeasureSpec((int) (childWidthSize * lp.widthFactor),
                        MeasureSpec.EXACTLY);
                child.measure(widthSpec, mChildHeightMeasureSpec);
            }
        }
    }
}