Example usage for android.view Gravity CENTER_HORIZONTAL

List of usage examples for android.view Gravity CENTER_HORIZONTAL

Introduction

In this page you can find the example usage for android.view Gravity CENTER_HORIZONTAL.

Prototype

int CENTER_HORIZONTAL

To view the source code for android.view Gravity CENTER_HORIZONTAL.

Click Source Link

Document

Place object in the horizontal center of its container, not changing its size.

Usage

From source file:org.bangbang.support.v4.widget.ViewPager.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;/*from w  ww.  ja  va  2  s . c  o m*/
    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 scrollX = getScrollX();

    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;
                }
                childLeft += scrollX;
                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) (width * ii.offset);
                int childLeft = paddingLeft + loff;
                int childTop = paddingTop;
                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(
                            (int) ((width - paddingLeft - paddingRight) * lp.widthFactor), MeasureSpec.EXACTLY);
                    final int heightSpec = MeasureSpec
                            .makeMeasureSpec((int) (height - paddingTop - paddingBottom), MeasureSpec.EXACTLY);
                    child.measure(widthSpec, heightSpec);
                }
                if (DEBUG) {
                    Log.v(TAG, "Positioning #" + i + " " + child + " f=" + ii.object + ":" + childLeft + ","
                            + childTop + " " + child.getMeasuredWidth() + "x" + child.getMeasuredHeight());
                    Log.d(TAG, "scrollx: " + getScrollX());
                }
                child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());
            }
        }
    }
    mTopPageBounds = paddingTop;
    mBottomPageBounds = height - paddingBottom;
    mDecorChildCount = decorCount;
    mFirstLayout = false;
}

From source file:com.albedinsky.android.ui.widget.SeekBarWidget.java

/**
 * Updates current indicator to the specified one. If this seek bar has discrete mode enabled
 * ({@link #isDiscrete()}), the given indicator will be updated to scaleable drawable if it is
 * not yet.//  ww  w.j a  va 2 s  .c  om
 *
 * @param indicator The new indicator to update to.
 */
private void updateDiscreteIndicator(Drawable indicator) {
    if (mDecorator.hasPrivateFlag(PFLAG_DISCRETE)) {
        indicator = mAnimations.makeDiscreteIndicatorScaleable(indicator,
                Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL);
    }
    if (mDiscreteIndicator != indicator) {
        final boolean needUpdate;
        if (mDiscreteIndicator != null) {
            mDiscreteIndicator.setCallback(null);
            unscheduleDrawable(mDiscreteIndicator);
            needUpdate = true;
        } else {
            needUpdate = false;
        }
        if (indicator != null) {
            indicator.setCallback(this);
            indicator.setVisible(getVisibility() == VISIBLE, false);

            if (indicator.getIntrinsicWidth() != mDiscreteIndicatorWidth
                    || indicator.getIntrinsicHeight() != mDiscreteIndicatorHeight) {
                this.mDiscreteIndicatorWidth = indicator.getIntrinsicWidth();
                this.mDiscreteIndicatorHeight = indicator.getIntrinsicHeight();
                requestLayout();
            }
        } else {
            this.mDiscreteIndicatorRes = 0;
            this.mDiscreteIndicatorWidth = mDiscreteIndicatorHeight = 0;
            requestLayout();
        }
        this.mDiscreteIndicator = indicator;
        this.applyDiscreteIndicatorTint();
        if (needUpdate) {
            this.updateDiscreteIndicatorPosition(getWidth(), getHeight());
            if (mDiscreteIndicator.isStateful()) {
                mDiscreteIndicator.setState(getDrawableState());
            }
            this.invalidateDiscreteIndicatorArea();
        }
    }
}

From source file:org.uguess.android.sysinfo.SiragonManager.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    final Activity ctx = getActivity();

    if (item.getItemId() == MI_PREFERENCE) {
        Intent it = new Intent(ctx, InfoSettings.class);

        it.putExtra(PREF_KEY_SHOW_INFO_ICON,
                Util.getBooleanOption(ctx, PSTORE_SYSINFOMANAGER, PREF_KEY_SHOW_INFO_ICON));
        it.putExtra(PREF_KEY_SHOW_TASK_ICON,
                Util.getBooleanOption(ctx, PSTORE_SYSINFOMANAGER, PREF_KEY_SHOW_TASK_ICON));
        it.putExtra(PREF_KEY_AUTO_START_ICON,
                Util.getBooleanOption(ctx, PSTORE_SYSINFOMANAGER, PREF_KEY_AUTO_START_ICON, false));
        it.putExtra(PREF_KEY_DEFAULT_SERVER,
                Util.getStringOption(ctx, PSTORE_SYSINFOMANAGER, PREF_KEY_DEFAULT_SERVER, null));
        it.putExtra(PREF_KEY_DEFAULT_EMAIL,
                Util.getStringOption(ctx, PSTORE_SYSINFOMANAGER, PREF_KEY_DEFAULT_EMAIL, null));
        it.putExtra(PREF_KEY_DEFAULT_TAB,
                Util.getIntOption(ctx, PSTORE_SYSINFOMANAGER, PREF_KEY_DEFAULT_TAB, 0));
        it.putExtra(PREF_KEY_WIDGET_DISABLED,
                Util.getStringOption(ctx, PSTORE_SYSINFOMANAGER, PREF_KEY_WIDGET_DISABLED, null));

        startActivityForResult(it, 2);/* w w  w .jav  a  2 s  . c  om*/

        return true;
    } else if (item.getItemId() == MI_HELP) {
        Intent it = new Intent(Intent.ACTION_VIEW);

        String target = "http://www.siragon.com.ve"; //$NON-NLS-1$

        ConnectivityManager cm = (ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE);

        NetworkInfo info = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

        if (info != null && info.isConnected()) {
            target = "http://www.siragon.com.ve"; //$NON-NLS-1$
        }

        it.setData(Uri.parse(target));

        it = Intent.createChooser(it, null);

        startActivity(it);

        return true;
    }
    ///////////////////////PATH SERVER///////////////////////////////////

    else if (item.getItemId() == MI_ABOUT) {
        ScrollView sv = new ScrollView(ctx);

        TextView txt = new TextView(ctx);
        txt.setGravity(Gravity.CENTER_HORIZONTAL);
        txt.setTextAppearance(ctx, android.R.style.TextAppearance_Medium);

        sv.addView(txt);

        String href = "http://www.google.com.ve"; //$NON-NLS-1$

        txt.setText(Html.fromHtml(getString(R.string.about_msg,
                getVersionName(ctx.getPackageManager(), ctx.getPackageName()), href)));
        txt.setMovementMethod(LinkMovementMethod.getInstance());

        new AlertDialog.Builder(ctx).setTitle(R.string.app_name).setIcon(R.drawable.logo2).setView(sv)
                .setNegativeButton(R.string.close, null).create().show();

        return true;
    } else if (item.getItemId() == MI_EXIT) {
        OnClickListener listener = new OnClickListener() {

            public void onClick(DialogInterface dialog, int which) {
                Util.killSelf(handler, ctx, (ActivityManager) ctx.getSystemService(Context.ACTIVITY_SERVICE),
                        ctx.getPackageName());
            }
        };

        new AlertDialog.Builder(ctx).setTitle(R.string.prompt).setMessage(R.string.exit_prompt)
                .setPositiveButton(android.R.string.yes, listener).setNegativeButton(android.R.string.no, null)
                .create().show();

        return true;
    } else if (item.getItemId() == MI_REFRESH) {
        updateInfo();
        return true;
    }

    return false;
}

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  w ww .  j  a  v  a2s . co  m*/
    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:org.videolan.vlc.gui.video.VideoPlayerActivity.java

private void changeSurfaceSize() {
    // get screen size
    int dw = getWindow().getDecorView().getWidth();
    int dh = getWindow().getDecorView().getHeight();

    // getWindow().getDecorView() doesn't always take orientation into account, we have to correct the values
    boolean isPortrait = getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT;
    if (dw > dh && isPortrait || dw < dh && !isPortrait) {
        int d = dw;
        dw = dh;/*from w ww .j a v  a  2 s.c o  m*/
        dh = d;
    }

    // sanity check
    if (dw * dh == 0 || mVideoWidth * mVideoHeight == 0) {
        Log.e(TAG, "Invalid surface size");
        return;
    }

    // compute the aspect ratio
    double ar, vw;
    double density = (double) mSarNum / (double) mSarDen;
    if (density == 1.0) {
        /* No indication about the density, assuming 1:1 */
        vw = mVideoWidth;
        ar = (double) mVideoWidth / (double) mVideoHeight;
    } else {
        /* Use the specified aspect ratio */
        vw = mVideoWidth * density;
        ar = vw / mVideoHeight;
    }

    // compute the display aspect ratio
    double dar = (double) dw / (double) dh;

    switch (mCurrentSize) {
    case SURFACE_BEST_FIT:
        if (dar < ar)
            dh = (int) (dw / ar);
        else
            dw = (int) (dh * ar);
        break;
    case SURFACE_FIT_HORIZONTAL:
        dh = (int) (dw / ar);
        break;
    case SURFACE_FIT_VERTICAL:
        dw = (int) (dh * ar);
        break;
    case SURFACE_FILL:
        break;
    case SURFACE_16_9:
        ar = 16.0 / 9.0;
        if (dar < ar)
            dh = (int) (dw / ar);
        else
            dw = (int) (dh * ar);
        break;
    case SURFACE_4_3:
        ar = 4.0 / 3.0;
        if (dar < ar)
            dh = (int) (dw / ar);
        else
            dw = (int) (dh * ar);
        break;
    case SURFACE_ORIGINAL:
        ar = 16.0 / 9.0;
        if (dar < ar)
            dh = (int) (dw / ar);
        else
            dw = (int) (dh * ar);
        break;
    }

    // align width on 16bytes
    int alignedWidth = (mVideoWidth + mSurfaceAlign) & ~mSurfaceAlign;

    // force surface buffer size
    mSurfaceHolder.setFixedSize(alignedWidth, mVideoHeight);

    // set display size
    LayoutParams lp = mSurface.getLayoutParams();
    lp.width = dw * alignedWidth / mVideoWidth;
    lp.height = dh;
    mSurface.setLayoutParams(lp);

    // set frame size (crop if necessary)
    //        lp = mSurfaceFrame.getLayoutParams();
    //        lp.width = dw;
    //        lp.height = dh;
    //        mSurfaceFrame.setLayoutParams(lp);
    FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) mSurfaceFrame.getLayoutParams();
    params.width = dw;
    params.height = dh;
    if (mCurrentSize == SURFACE_ORIGINAL) {
        params.topMargin = 0;
        params.gravity = Gravity.CENTER;
    } else {
        params.topMargin = (int) getResources().getDimension(R.dimen.video_padding_top);
        params.gravity = Gravity.CENTER_HORIZONTAL;
    }
    ;
    mSurfaceFrame.setLayoutParams(params);

    mSurface.invalidate();
}

From source file:com.zhima.ui.common.view.SpaceViewPager.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;/*from w w  w. j  ava 2 s .c  o  m*/
    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 scrollX = getScrollX();

    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;
                }
                childLeft += scrollX;
                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) (width * ii.offset);
                int childLeft = paddingLeft + loff;
                int childTop = paddingTop;
                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(
                            (int) ((width - paddingLeft - paddingRight) * lp.widthFactor), MeasureSpec.EXACTLY);
                    final int heightSpec = MeasureSpec
                            .makeMeasureSpec((int) (height - paddingTop - paddingBottom), MeasureSpec.EXACTLY);
                    child.measure(widthSpec, heightSpec);
                }
                if (DEBUG)
                    Log.i(TAG, "Positioning #" + i + " " + child + " f=" + ii.object + ":" + childLeft + ","
                            + childTop + " " + child.getMeasuredWidth() + "x" + child.getMeasuredHeight());
                child.layout(childLeft, childTop, childLeft + child.getMeasuredWidth(),
                        childTop + child.getMeasuredHeight());
            }
        }
    }
    mTopPageBounds = paddingTop;
    mBottomPageBounds = height - paddingBottom;
    mDecorChildCount = decorCount;
    mFirstLayout = false;
}

From source file:com.appunite.list.GridView.java

/**
 * Add a view as a child and make sure it is measured (if necessary) and
 * positioned properly.// w w w  . j a va  2 s  . c  o m
 *
 * @param child The view to add
 * @param position The position of the view
 * @param y The y position relative to which this view will be positioned
 * @param flow if true, align top edge to y. If false, align bottom edge
 *        to y.
 * @param childrenLeft Left edge where children should be positioned
 * @param selected Is this position selected?
 * @param recycled Has this view been pulled from the recycle bin? If so it
 *        does not need to be remeasured.
 * @param where Where to add the item in the list
 *
 */
private void setupChild(View child, int position, int y, boolean flow, int childrenLeft, boolean selected,
        boolean recycled, int where) {
    boolean isSelected = selected && shouldShowSelector();
    final boolean updateChildSelected = isSelected != child.isSelected();
    final int mode = mTouchMode;
    final boolean isPressed = mode > TOUCH_MODE_DOWN && mode < TOUCH_MODE_SCROLL && mMotionPosition == position;
    final boolean updateChildPressed = isPressed != child.isPressed();

    boolean needToMeasure = !recycled || updateChildSelected || child.isLayoutRequested();

    // Respect layout params that are already in the view. Otherwise make
    // some up...
    LayoutParams p = (LayoutParams) child.getLayoutParams();
    if (p == null) {
        p = (LayoutParams) generateDefaultLayoutParams();
    }
    p.viewType = mAdapter.getItemViewType(position);

    if (recycled && !p.forceAdd) {
        attachViewToParent(child, where, p);
    } else {
        p.forceAdd = false;
        addViewInLayout(child, where, p, true);
    }

    if (updateChildSelected) {
        child.setSelected(isSelected);
        if (isSelected) {
            requestFocus();
        }
    }

    if (updateChildPressed) {
        child.setPressed(isPressed);
    }

    if (mChoiceMode != CHOICE_MODE_NONE && mCheckStates != null) {
        if (child instanceof Checkable) {
            ((Checkable) child).setChecked(mCheckStates.get(position));
        } else if (getContext()
                .getApplicationInfo().targetSdkVersion >= android.os.Build.VERSION_CODES.HONEYCOMB) {
            Compat.setActivated(child, mCheckStates.get(position));
        }
    }

    if (needToMeasure) {
        int childHeightSpec = ViewGroup
                .getChildMeasureSpec(MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED), 0, p.height);

        int childWidthSpec = ViewGroup.getChildMeasureSpec(
                MeasureSpec.makeMeasureSpec(mColumnWidth, MeasureSpec.EXACTLY), 0, p.width);
        child.measure(childWidthSpec, childHeightSpec);
    } else {
        cleanupLayoutState(child);
    }

    final int w = child.getMeasuredWidth();
    final int h = child.getMeasuredHeight();

    int childLeft;
    final int childTop = flow ? y : y - h;

    final int layoutDirection = ViewCompat.getLayoutDirection(this);
    final int absoluteGravity = GravityCompat.getAbsoluteGravity(mGravity, layoutDirection);
    switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
    case Gravity.LEFT:
        childLeft = childrenLeft;
        break;
    case Gravity.CENTER_HORIZONTAL:
        childLeft = childrenLeft + ((mColumnWidth - w) / 2);
        break;
    case Gravity.RIGHT:
        childLeft = childrenLeft + mColumnWidth - w;
        break;
    default:
        childLeft = childrenLeft;
        break;
    }

    if (needToMeasure) {
        final int childRight = childLeft + w;
        final int childBottom = childTop + h;
        child.layout(childLeft, childTop, childRight, childBottom);
    } else {
        child.offsetLeftAndRight(childLeft - child.getLeft());
        child.offsetTopAndBottom(childTop - child.getTop());
    }

    if (mCachingStarted) {
        child.setDrawingCacheEnabled(true);
    }

    if (recycled && (((LayoutParams) child.getLayoutParams()).scrappedFromPosition) != position) {
        Compat.jumpDrawablesToCurrentState(child);
    }
}

From source file:lewa.support.v7.internal.widget.ActionBarView.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    int x = getPaddingLeft();
    final int y = getPaddingTop();
    final int contentHeight = b - t - getPaddingTop() - getPaddingBottom();

    if (contentHeight <= 0) {
        // Nothing to do if we can't see anything.
        return;// w  w  w . jav  a 2s .  com
    }

    HomeView homeLayout = mExpandedActionView != null ? mExpandedHomeLayout : mHomeLayout;
    if (homeLayout.getVisibility() != GONE) {
        final int leftOffset = homeLayout.getLeftOffset();
        x += positionChild(homeLayout, x + leftOffset, y, contentHeight) + leftOffset;
    }

    if (mExpandedActionView == null) {
        final boolean showTitle = mTitleLayout != null && mTitleLayout.getVisibility() != GONE
                && (mDisplayOptions & ActionBar.DISPLAY_SHOW_TITLE) != 0;
        if (showTitle) {
            x += positionChild(mTitleLayout, x, y, contentHeight);
        }

        switch (mNavigationMode) {
        case ActionBar.NAVIGATION_MODE_STANDARD:
            break;
        case ActionBar.NAVIGATION_MODE_LIST:
            if (mListNavLayout != null) {
                if (showTitle) {
                    x += mItemPadding;
                }
                x += positionChild(mListNavLayout, x, y, contentHeight) + mItemPadding;
            }
            break;
        case ActionBar.NAVIGATION_MODE_TABS:
            if (mTabScrollView != null) {
                if (showTitle) {
                    x += mItemPadding;
                }
                x += positionChild(mTabScrollView, x, y, contentHeight) + mItemPadding;
            }
            break;
        }
    }

    int menuLeft = r - l - getPaddingRight();
    if (mMenuView != null && mMenuView.getParent() == this) {
        positionChildInverse(mMenuView, menuLeft, y, contentHeight);
        menuLeft -= mMenuView.getMeasuredWidth();
    }

    if (mIndeterminateProgressView != null && mIndeterminateProgressView.getVisibility() != GONE) {
        positionChildInverse(mIndeterminateProgressView, menuLeft, y, contentHeight);
        menuLeft -= mIndeterminateProgressView.getMeasuredWidth();
    }

    View customView = null;
    if (mExpandedActionView != null) {
        customView = mExpandedActionView;
    } else if ((mDisplayOptions & ActionBar.DISPLAY_SHOW_CUSTOM) != 0 && mCustomNavView != null) {
        customView = mCustomNavView;
    }
    if (customView != null) {

        ViewGroup.LayoutParams lp = customView.getLayoutParams();
        final ActionBar.LayoutParams ablp = lp instanceof ActionBar.LayoutParams ? (ActionBar.LayoutParams) lp
                : null;

        final int gravity = ablp != null ? ablp.gravity : DEFAULT_CUSTOM_GRAVITY;
        final int navWidth = customView.getMeasuredWidth();

        int topMargin = 0;
        int bottomMargin = 0;
        if (ablp != null) {
            x += ablp.leftMargin;
            menuLeft -= ablp.rightMargin;
            topMargin = ablp.topMargin;
            bottomMargin = ablp.bottomMargin;
        }

        int hgravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
        // See if we actually have room to truly center; if not push against left or right.
        if (hgravity == Gravity.CENTER_HORIZONTAL) {
            final int centeredLeft = (getWidth() - navWidth) / 2;
            if (centeredLeft < x) {
                hgravity = Gravity.LEFT;
            } else if (centeredLeft + navWidth > menuLeft) {
                hgravity = Gravity.RIGHT;
            }
        } else if (gravity == -1) {
            hgravity = Gravity.LEFT;
        }

        int xpos = 0;
        switch (hgravity) {
        case Gravity.CENTER_HORIZONTAL:
            xpos = (getWidth() - navWidth) / 2;
            break;
        case Gravity.LEFT:
            xpos = x;
            break;
        case Gravity.RIGHT:
            xpos = menuLeft - navWidth;
            break;
        }

        int vgravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;

        if (gravity == -1) {
            vgravity = Gravity.CENTER_VERTICAL;
        }

        int ypos = 0;
        switch (vgravity) {
        case Gravity.CENTER_VERTICAL:
            final int paddedTop = getPaddingTop();
            final int paddedBottom = getHeight() - getPaddingBottom();
            ypos = ((paddedBottom - paddedTop + mStatusbarHeight) - customView.getMeasuredHeight()) / 2;
            break;
        case Gravity.TOP:
            ypos = getPaddingTop() + topMargin;
            break;
        case Gravity.BOTTOM:
            ypos = getHeight() - getPaddingBottom() - customView.getMeasuredHeight() - bottomMargin;
            break;
        }
        final int customWidth = customView.getMeasuredWidth();

        ///LEWA BEGIN
        //            ypos = Injector.resetCustomViewTop(getContext(), customView, mStatusbarHeight, ypos);
        ///LEWA END

        customView.layout(xpos, ypos, xpos + customWidth, ypos + customView.getMeasuredHeight());
        x += customWidth;
    }

    if (mProgressView != null) {
        mProgressView.bringToFront();
        final int halfProgressHeight = mProgressView.getMeasuredHeight() / 2;
        mProgressView.layout(mProgressBarPadding, -halfProgressHeight,
                mProgressBarPadding + mProgressView.getMeasuredWidth(), halfProgressHeight);
    }

    ///LEWA BEGIN
    Injector.relayoutTitleView(getContext(), this);
    ///LEWA END
}

From source file:com.view.linkedviewpager.LinkedViewPager.LinkedViewPager.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;/*from   ww  w.j  a  va2s . c  o m*/
    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 scrollX = getScrollX();

    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;
                }
                childLeft += scrollX;
                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) (width * ii.offset);
                int childLeft = paddingLeft + loff;
                int childTop = paddingTop;
                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(
                            (int) ((width - paddingLeft - paddingRight) * lp.widthFactor), MeasureSpec.EXACTLY);
                    final int heightSpec = MeasureSpec
                            .makeMeasureSpec((int) (height - paddingTop - paddingBottom), 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());
            }
        }
    }
    mTopPageBounds = paddingTop;
    mBottomPageBounds = height - paddingBottom;
    mDecorChildCount = decorCount;
    mFirstLayout = false;
}

From source file:at.ac.tuwien.caa.docscan.ui.CameraActivity.java

private void showToastText(int id) {

    String msg = getResources().getString(id);

    if (mToast != null)
        mToast.cancel();//from   w w  w . j ava 2  s  . co  m

    mToast = Toast.makeText(getApplicationContext(), msg, Toast.LENGTH_SHORT);
    mToast.setGravity(Gravity.CENTER_VERTICAL | Gravity.CENTER_HORIZONTAL, 0, 0);
    mToast.show();
}