Example usage for android.view Gravity RIGHT

List of usage examples for android.view Gravity RIGHT

Introduction

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

Prototype

int RIGHT

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

Click Source Link

Document

Push object to the right of its container, not changing its size.

Usage

From source file:com.example.emachine.FXcalcActivity.java

private void EspressoMachine_CrashlyticsFAB() {
    if (getPrefBugIssue(getBaseContext()))
        Crashlytics.log(Log.ERROR, TAG, "onResume ...");
    FloatingActionButton btn_BugFAB = new FloatingActionButton.Builder(this)
            .withDrawable(getResources().getDrawable(R.drawable.bug)).withButtonColor(Color.RED)
            .withGravity(Gravity.BOTTOM | Gravity.RIGHT).withMargins(0, 0, 16, 16).create();
    btn_BugFAB.setOnClickListener(new View.OnClickListener() {

        @Override/*from  w  ww  .j  av  a  2 s . c  om*/
        public void onClick(View v) {
            EspressoMachine_MakeItCrashException();

        }
    });
    if (getPrefBugIssue(getBaseContext())) {
        btn_BugFAB.setVisibility(View.VISIBLE);
    } else {
        btn_BugFAB.setVisibility(View.INVISIBLE);
    }
}

From source file:org.csp.everyaware.offline.Map.java

/****************** OTTIENE RIFERIMENTO AI BOTTONI *********************************/

public void getButtonRefs() {
    mZoomControls = (LinearLayout) findViewById(R.id.zoomLinearLayout);
    mZoomControls.setVisibility(View.GONE);

    mTrackLengthBtn = (Button) findViewById(R.id.trackLengthBtn);
    mFollowCamBtn = (Button) findViewById(R.id.followCameraBtn);
    mZoomOutBtn = (Button) findViewById(R.id.zoomOutBtn);
    mZoomInBtn = (Button) findViewById(R.id.zoomInBtn);
    mInsertAnnBtn = (Button) findViewById(R.id.insertAnnBtn);
    mShareBtn = (Button) findViewById(R.id.shareBtn);

    mTrackLengthBtn.setVisibility(View.GONE);
    mInsertAnnBtn.setVisibility(View.GONE);

    mZoomOutBtn.setOnClickListener(new OnClickListener() {
        @Override/*from  ww  w. ja va2  s  .c o  m*/
        public void onClick(View arg0) {
            // Zoom out
            try {
                mGoogleMap.moveCamera(CameraUpdateFactory.zoomBy(-1f));
            } catch (NullPointerException e) {
                e.printStackTrace();
            }
            //read and save actual zoom level
            mZoom = mGoogleMap.getCameraPosition().zoom;
        }
    });

    mZoomInBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            // Zoom in
            try {
                mGoogleMap.moveCamera(CameraUpdateFactory.zoomBy(1f));
            } catch (NullPointerException e) {
                e.printStackTrace();
            }
            //read and save actual zoom level
            mZoom = mGoogleMap.getCameraPosition().zoom;
        }
    });

    mShareBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            mFacebookManager = FacebookManager.getInstance(Map.this, mFacebookHandler);
            mTwitterManager = TwitterManager.getInstance(Map.this);

            final Dialog dialog = new Dialog(Map.this);
            dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
            dialog.setContentView(R.layout.share_dialog);
            //dialog.setTitle("Activate login on...");

            getShareButtonsRef(dialog);

            dialog.show();
        }
    });

    mFollowCamBtn.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View arg0) {
            //mCameraTrackOn = !mCameraTrackOn;
            setCameraTracking();

            if (mCameraTrackOn) {
                try {
                    if (Utils.lastPhoneLocation != null)
                        mGoogleMap.animateCamera(
                                CameraUpdateFactory.newLatLng(new LatLng(Utils.lastPhoneLocation.getLatitude(),
                                        Utils.lastPhoneLocation.getLongitude())));
                    else if (Utils.lastNetworkLocation != null)
                        mGoogleMap.animateCamera(CameraUpdateFactory
                                .newLatLng(new LatLng(Utils.lastNetworkLocation.getLatitude(),
                                        Utils.lastNetworkLocation.getLongitude())));
                } catch (NullPointerException e) {
                    e.printStackTrace();
                }
            }
        }
    });

    mShareBtn.setOnLongClickListener(new OnLongClickListener() {
        @Override
        public boolean onLongClick(View arg0) {
            Toast toast = Toast.makeText(getApplicationContext(),
                    getResources().getString(R.string.share_btn_text), Toast.LENGTH_LONG);
            toast.setGravity(Gravity.TOP | Gravity.RIGHT, 0, 250); //250 from top on a 480x800 screen
            toast.show();
            return false;
        }
    });

    //status icons references
    mGpsStatus = (ImageView) findViewById(R.id.gpsStatusIv);
    mInterUplStatus = (ImageView) findViewById(R.id.interUplStatusIv);

    //gps status icon initialization
    mGpsStatus.setBackgroundResource(R.drawable.gps_off);

    //read network type index on which upload data is allowed: 0 - only wifi; 1 - both wifi and mobile
    int networkTypeIndex = Utils.getUploadNetworkTypeIndex(getApplicationContext());

    //1 - is internet connection available? 
    boolean[] connectivity = Utils.haveNetworkConnection(getApplicationContext());

    //if user wants to upload only on wifi networks, connectivity[0] (network connectivity) must be true
    if (networkTypeIndex == 0) {
        if (connectivity[0])
            mConnectivityOn = true;
        else
            mConnectivityOn = false;
    } else //if user wants to upload both on wifi/mobile networks
        mConnectivityOn = connectivity[0] || connectivity[1];

    //network status icon initialization
    if (mConnectivityOn) {
        mInterUplStatus.setBackgroundResource(R.drawable.internet_on);
        Utils.uploadOn = Constants.INTERNET_ON_INT;
    } else {
        mInterUplStatus.setBackgroundResource(R.drawable.internet_off);
        Utils.uploadOn = Constants.INTERNET_OFF_INT;
    }

    //button to get from server black carbon levels around user
    mGetBcLevelsBtn = (Button) findViewById(R.id.getBcLevelsBtn);
    mGetBcLevelsBtn.setVisibility(View.VISIBLE);
    mGetBcLevelsBtn.setOnClickListener(mGetBcLevelsOnClickListener);

    //bcLayout.addView(mGetBcLevelsBtn);
    mSpectrum = (LinearLayout) findViewById(R.id.spectrumLinearLayout);
    mSpectrum.setVisibility(View.VISIBLE);
}

From source file:com.example.verticaldrawerlayout.VerticalDrawerLayout.java

@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    mInLayout = true;// w w  w.  j  a v a  2  s  . co  m
    final int height = b - t;
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);

        if (child.getVisibility() == GONE) {
            continue;
        }

        final LayoutParams lp = (LayoutParams) child.getLayoutParams();

        if (isContentView(child)) {
            child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(),
                    lp.topMargin + child.getMeasuredHeight());
        } else { // Drawer, if it wasn't onMeasure would have thrown an
                 // exception.
            final int childWidth = child.getMeasuredWidth();
            final int childHeight = child.getMeasuredHeight();
            int childTop;

            final float newOffset;
            if (checkDrawerViewAbsoluteGravity(child, Gravity.TOP)) {
                childTop = -childHeight + (int) (childHeight * lp.onScreen);
                newOffset = (float) (childHeight + childTop) / childHeight;
            } else { // Right; onMeasure checked for us.
                childTop = height - (int) (childHeight * lp.onScreen);
                newOffset = (float) (height - childTop) / childHeight;
            }

            final boolean changeOffset = newOffset != lp.onScreen;

            final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;

            switch (vgrav) {
            default:
            case Gravity.LEFT: {
                child.layout(lp.leftMargin, childTop, lp.leftMargin + childWidth, childTop + childHeight);
                break;
            }

            case Gravity.RIGHT: {
                final int width = r - l;
                child.layout(width - lp.rightMargin - childWidth, childTop, width - lp.rightMargin,
                        childTop + childHeight);
                break;
            }

            case Gravity.CENTER_HORIZONTAL: {
                final int width = r - l;
                int childLeft = (width - childWidth) / 2;

                // Offset for margins. If things don't fit right because of
                // bad measurement before, oh well.
                if (childLeft < lp.leftMargin) {
                    childLeft = lp.leftMargin;
                } else if (childLeft + childWidth > width - lp.rightMargin) {
                    childLeft = width - lp.rightMargin - childWidth;
                }
                child.layout(childLeft, childTop, childLeft + childWidth, childTop + childHeight);
                break;
            }
            }

            if (changeOffset) {
                setDrawerViewOffset(child, newOffset);
            }

            final int newVisibility = lp.onScreen > 0 ? VISIBLE : INVISIBLE;
            if (child.getVisibility() != newVisibility) {
                child.setVisibility(newVisibility);
            }
        }
    }
    mInLayout = false;
    mFirstLayout = false;
}

From source file:android.support.v7.widget.AbstractXpListPopupWindow.java

/**
 * Show the popup list. If the list is already showing, this method
 * will recalculate the popup's size and position.
 *//*from   ww  w.  j a  v a 2 s. c om*/
public void show() {
    final int height = buildDropDown();
    final int widthSpec = getListWidthSpec();

    boolean noInputMethod = isInputMethodNotNeeded();
    PopupWindowCompat.setWindowLayoutType(mPopup, mDropDownWindowLayoutType);

    final int marginsLeft = mMargins.left;
    final int marginsTop = mMargins.top;
    final int marginsBottom = mMargins.bottom;
    final int marginsRight = mMargins.right;

    getBackgroundPadding(mTempRect);
    final int backgroundLeft = mTempRect.left;
    final int backgroundTop = mTempRect.top;
    final int backgroundBottom = mTempRect.bottom;
    final int backgroundRight = mTempRect.right;

    int verticalOffset = mDropDownVerticalOffset;
    int horizontalOffset = mDropDownHorizontalOffset;

    final int anchorWidth = mDropDownAnchorView.getWidth();
    final int anchorHeight = mDropDownAnchorView.getHeight();

    getLocationInWindow(mDropDownAnchorView, mTempLocation);
    final int anchorLeft = mTempLocation[0];
    final int anchorRight = anchorLeft + anchorWidth;
    final int anchorTop = mTempLocation[1];
    final int anchorBottom = anchorTop + anchorHeight;

    final boolean rightAligned = GravityCompat.getAbsoluteGravity(
            getDropDownGravity() & GravityCompat.RELATIVE_HORIZONTAL_GRAVITY_MASK,
            mLayoutDirection) == Gravity.RIGHT;
    if (rightAligned) {
        horizontalOffset += anchorWidth - widthSpec - (marginsRight - backgroundRight);
    } else {
        horizontalOffset += (marginsLeft - backgroundLeft);
    }

    final int bottomDecorations = getWindowFrame(mDropDownAnchorView, noInputMethod, mTempRect);
    final int windowLeft = mTempRect.left;
    final int windowRight = mTempRect.right;
    final int windowTop = mTempRect.top;
    final int windowBottom = mTempRect.bottom;

    final int windowWidth = windowRight - windowLeft;
    final int windowHeight = windowBottom - windowTop;

    getBoundsInWindow(mTempRect);
    final int boundsTop = mTempRect.top;
    final int boundsRight = mTempRect.right;
    final int boundsLeft = mTempRect.left;
    final int boundsBottom = mTempRect.bottom;

    final int screenRight = windowRight - (marginsRight - backgroundRight) - boundsRight;
    final int screenLeft = windowLeft + (marginsLeft - backgroundLeft) + boundsLeft;
    final int screenWidth = screenRight - screenLeft;

    if (!rightAligned && windowWidth < anchorLeft + horizontalOffset + widthSpec) {
        // When right aligned due to insufficient space ignore negative horizontal offset.
        horizontalOffset = mDropDownHorizontalOffset < 0 ? 0 : mDropDownHorizontalOffset;
        horizontalOffset -= widthSpec - (windowWidth - anchorLeft);
        horizontalOffset -= marginsRight - backgroundRight;
    } else if (rightAligned && 0 > anchorLeft + horizontalOffset) {
        // When left aligned due to insufficient space ignore positive horizontal offset.
        horizontalOffset = mDropDownHorizontalOffset > 0 ? 0 : mDropDownHorizontalOffset;
        horizontalOffset -= anchorLeft;
        horizontalOffset += marginsLeft - backgroundLeft;
    }

    // Width spec should always be resolved to concrete value. widthSpec > 0;
    if (windowWidth < widthSpec + horizontalOffset + anchorLeft) {
        int diff = Math.abs(windowWidth - (widthSpec + horizontalOffset + anchorLeft));
        horizontalOffset -= diff;
    } else if (0 > anchorLeft + horizontalOffset) {
        int diff = Math.abs(horizontalOffset + anchorLeft);
        horizontalOffset += diff;
    }

    int maxHeight = getMaxAvailableHeight(mDropDownAnchorView, noInputMethod) + backgroundTop
            + backgroundBottom;
    int availableHeight = maxHeight;
    //        availableHeight -= Math.max(0, marginsTop - backgroundTop);
    //        availableHeight -= Math.max(0, marginsBottom - backgroundBottom);
    availableHeight -= marginsTop - backgroundTop;
    availableHeight -= marginsBottom - backgroundBottom;

    int limitHeight = Math.min(windowHeight, availableHeight);

    final int heightSpec;
    if (mPopup.isShowing()) {
        if (mDropDownHeight == ViewGroup.LayoutParams.MATCH_PARENT) {
            // The call to PopupWindow's update method below can accept -1 for any
            // value you do not want to update.
            //                heightSpec = noInputMethod ? height : ViewGroup.LayoutParams.MATCH_PARENT;
            //                if (noInputMethod) {
            //                    mPopup.setWidth(mDropDownWidth == ViewGroup.LayoutParams.MATCH_PARENT ?
            //                        ViewGroup.LayoutParams.MATCH_PARENT : 0);
            //                    mPopup.setHeight(0);
            //                } else {
            //                    mPopup.setWidth(mDropDownWidth == ViewGroup.LayoutParams.MATCH_PARENT ?
            //                        ViewGroup.LayoutParams.MATCH_PARENT : 0);
            //                    mPopup.setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
            //                }
            heightSpec = limitHeight;
        } else if (mDropDownHeight == ViewGroup.LayoutParams.WRAP_CONTENT) {
            heightSpec = Math.min(height, limitHeight);
        } else {
            heightSpec = Math.min(mDropDownHeight, limitHeight);
        }
    } else {
        if (mDropDownHeight == ViewGroup.LayoutParams.MATCH_PARENT) {
            //                heightSpec = ViewGroup.LayoutParams.MATCH_PARENT;
            heightSpec = limitHeight;
        } else if (mDropDownHeight == ViewGroup.LayoutParams.WRAP_CONTENT) {
            heightSpec = Math.min(height, limitHeight);
        } else {
            heightSpec = Math.min(mDropDownHeight, limitHeight);
        }
    }

    final int screenBottom = windowBottom - (marginsBottom - backgroundBottom) - boundsBottom;
    final int screenTop = windowTop + (marginsTop - backgroundTop) + boundsTop;

    {
        // Position within bounds.

        final int popupTop = anchorBottom + verticalOffset;
        final int popupBottom = popupTop + heightSpec;
        final int popupHeight = popupBottom - popupTop;

        if (popupBottom > screenBottom) {
            verticalOffset -= (popupBottom - screenBottom);
        } else if (popupTop < screenTop) {
            verticalOffset += (screenTop - popupTop);
        }
    }

    {
        // Account for background padding.

        final int popupTop = anchorBottom + verticalOffset;
        final int popupBottom = popupTop + heightSpec;
        final int popupHeight = popupBottom - popupTop;

        if (windowBottom < popupBottom) {
            int diff = Math.abs(windowBottom - popupBottom);
            verticalOffset -= diff;
        } else if (windowTop > popupTop) {
            int diff = Math.abs(windowTop - popupTop);
            verticalOffset += diff;
        }
    }

    //        verticalOffset -= bottomDecorations;
    //        verticalOffset += Util.dpToPxOffset(mContext, 8);

    if (mPopup.isShowing()) {
        mPopup.setOutsideTouchable(!mForceIgnoreOutsideTouch && !mDropDownAlwaysVisible);

        mPopup.update(getAnchorView(), horizontalOffset, verticalOffset, (widthSpec < 0) ? -1 : widthSpec,
                (heightSpec < 0) ? -1 : heightSpec);
    } else {

        mPopup.setWidth(widthSpec);
        mPopup.setHeight(heightSpec);
        setPopupClipToScreenEnabled(true);

        // use outside touchable to dismiss drop down when touching outside of it, so
        // only set this if the dropdown is not always visible
        mPopup.setOutsideTouchable(!mForceIgnoreOutsideTouch && !mDropDownAlwaysVisible);
        mPopup.setTouchInterceptor(mTouchInterceptor);
        if (sSetEpicenterBoundsMethod != null) {
            try {
                sSetEpicenterBoundsMethod.invoke(mPopup, mEpicenterBounds);
            } catch (Exception e) {
                Log.e(TAG, "Could not invoke setEpicenterBounds on PopupWindow", e);
            }
        }
        // We handle gravity manually. Just as everything else.
        PopupWindowCompat.showAsDropDown(mPopup, getAnchorView(), horizontalOffset, verticalOffset,
                Gravity.NO_GRAVITY);
        mDropDownList.setSelection(ListView.INVALID_POSITION);

        if (DEBUG)
            Log.e(TAG, "isAboveAnchor=" + mPopup.isAboveAnchor());

        if (!mModal || mDropDownList.isInTouchMode()) {
            clearListSelection();
        }
        if (!mModal) {
            mHandler.post(mHideSelector);
        }
    }
}

From source file:com.abewy.android.apps.klyph.widget.KlyphDrawerLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    final int height = getHeight();
    final boolean drawingContent = isContentView(child);
    int clipLeft = 0, clipRight = getWidth();

    final int restoreCount = canvas.save();
    if (drawingContent) {
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View v = getChildAt(i);
            if (v == child || v.getVisibility() != VISIBLE || !hasOpaqueBackground(v) || !isDrawerView(v)
                    || v.getHeight() < height) {
                continue;
            }// www.  java  2 s  . c o m

            if (checkDrawerViewGravity(v, Gravity.LEFT)) {
                final int vright = v.getRight();
                if (vright > clipLeft)
                    clipLeft = vright;
            } else {
                final int vleft = v.getLeft();
                if (vleft < clipRight)
                    clipRight = vleft;
            }
        }
        canvas.clipRect(clipLeft, 0, clipRight, getHeight());
    }
    final boolean result = super.drawChild(canvas, child, drawingTime);
    canvas.restoreToCount(restoreCount);

    if (mScrimOpacity > 0 && drawingContent) {
        final int baseAlpha = (mScrimColor & 0xff000000) >>> 24;
        final int imag = (int) (baseAlpha * mScrimOpacity);
        final int color = imag << 24 | (mScrimColor & 0xffffff);
        mScrimPaint.setColor(color);

        canvas.drawRect(clipLeft, 0, clipRight, getHeight(), mScrimPaint);
    } else if (mShadowLeft != null && checkDrawerViewGravity(child, Gravity.LEFT)) {
        final int shadowWidth = mShadowLeft.getIntrinsicWidth();
        final int childRight = child.getRight();
        final int drawerPeekDistance = mLeftDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) childRight / drawerPeekDistance, 1.f));
        mShadowLeft.setBounds(childRight, child.getTop(), childRight + shadowWidth, child.getBottom());
        mShadowLeft.setAlpha((int) (0xff * alpha));
        mShadowLeft.draw(canvas);
    } else if (mShadowRight != null && checkDrawerViewGravity(child, Gravity.RIGHT)) {
        final int shadowWidth = mShadowRight.getIntrinsicWidth();
        final int childLeft = child.getLeft();
        final int showing = getWidth() - childLeft;
        final int drawerPeekDistance = mRightDragger.getEdgeSize();
        final float alpha = Math.max(0, Math.min((float) showing / drawerPeekDistance, 1.f));
        mShadowRight.setBounds(childLeft - shadowWidth, child.getTop(), childLeft, child.getBottom());
        mShadowRight.setAlpha((int) (0xff * alpha));
        mShadowRight.draw(canvas);
    }
    return result;
}

From source file:android.car.ui.provider.CarDrawerLayout.java

@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
    final int height = getHeight();
    final boolean drawingContent = isContentView(child);
    int clipLeft = findContentView().getLeft();
    int clipRight = findContentView().getRight();
    final int baseAlpha = (mScrimColor & 0xff000000) >>> 24;

    final int restoreCount = canvas.save();
    if (drawingContent) {
        final int childCount = getChildCount();
        for (int i = 0; i < childCount; i++) {
            final View v = getChildAt(i);
            if (v == child || v.getVisibility() != VISIBLE || !hasOpaqueBackground(v) || !isDrawerView(v)
                    || v.getHeight() < height) {
                continue;
            }//w  w  w. ja v a 2s .c  o m

            if (checkDrawerViewAbsoluteGravity(v, Gravity.LEFT)) {
                final int vright = v.getRight();
                if (vright > clipLeft) {
                    clipLeft = vright;
                }
            } else {
                final int vleft = v.getLeft();
                if (vleft < clipRight) {
                    clipRight = vleft;
                }
            }
        }
        canvas.clipRect(clipLeft, 0, clipRight, getHeight());
    }
    final boolean result = super.drawChild(canvas, child, drawingTime);
    canvas.restoreToCount(restoreCount);

    if (drawingContent) {
        int scrimAlpha = SCRIM_ENABLED
                ? (int) (baseAlpha * Math.max(0, Math.min(1, onScreen())) * MAX_SCRIM_ALPHA)
                : 0;

        if (scrimAlpha > 0) {
            int color = scrimAlpha << 24 | (mScrimColor & 0xffffff);
            mScrimPaint.setColor(color);

            canvas.drawRect(clipLeft, 0, clipRight, getHeight(), mScrimPaint);

            canvas.drawRect(clipLeft - 1, 0, clipLeft, getHeight(), mEdgeHighlightPaint);
        }

        LayoutParams drawerLp = (LayoutParams) findDrawerView().getLayoutParams();
        if (mShadow != null && checkDrawerViewAbsoluteGravity(findDrawerView(), Gravity.LEFT)) {
            final int offScreen = (int) ((1 - drawerLp.onScreen) * findDrawerView().getWidth());
            final int drawerRight = getWidth() - drawerLp.getMarginEnd() - offScreen;
            final int shadowWidth = mShadow.getIntrinsicWidth();
            final float alpha = Math.max(0, Math.min((float) drawerRight / mDragger.getEdgeSize(), 1.f));
            mShadow.setBounds(drawerRight, child.getTop(), drawerRight + shadowWidth, child.getBottom());
            mShadow.setAlpha((int) (255 * alpha * alpha * alpha));
            mShadow.draw(canvas);
        } else if (mShadow != null && checkDrawerViewAbsoluteGravity(findDrawerView(), Gravity.RIGHT)) {
            final int onScreen = (int) (findDrawerView().getWidth() * drawerLp.onScreen);
            final int drawerLeft = drawerLp.getMarginStart() + getWidth() - onScreen;
            final int shadowWidth = mShadow.getIntrinsicWidth();
            final float alpha = Math.max(0, Math.min((float) onScreen / mDragger.getEdgeSize(), 1.f));
            canvas.save();
            canvas.translate(2 * drawerLeft - shadowWidth, 0);
            canvas.scale(-1.0f, 1.0f);
            mShadow.setBounds(drawerLeft - shadowWidth, child.getTop(), drawerLeft, child.getBottom());
            mShadow.setAlpha((int) (255 * alpha * alpha * alpha * alpha));
            mShadow.draw(canvas);
            canvas.restore();
        }
    }
    return result;
}

From source file:com.doubleTwist.drawerlib.ADrawerLayout.java

private void readViews() {
    mContent = getChildAt(0);//from   w w w .j a  v a2s .  c om
    for (int i = 1, count = getChildCount(); i < count; i++) {
        View v = getChildAt(i);
        if (v.getId() == DIMMER_VIEW_ID)
            continue;
        LayoutParams params = (LayoutParams) v.getLayoutParams();
        switch (params.gravity) {
        case Gravity.LEFT: // left
            mLeft = v;
            mDrawerState.mLeftEnabled = true;
            break;
        case Gravity.RIGHT: // right
            mRight = v;
            mDrawerState.mRightEnabled = true;
            break;
        case Gravity.TOP: // top
            mTop = v;
            mDrawerState.mTopEnabled = true;
            break;
        case Gravity.BOTTOM: // bottom
            mBottom = v;
            mDrawerState.mBottomEnabled = true;
            break;
        default:
            mLeft = v;
            break;
        }
    }
}

From source file:com.daiv.android.twitter.manipulations.widgets.NotificationDrawerLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);

    // "|" used deliberately here; both methods should be invoked.
    try {/*  w  ww.ja  v a  2  s . co  m*/
        final boolean interceptForDrag = isDrawerOpen(Gravity.RIGHT)
                ? mRightDragger.shouldInterceptTouchEvent(ev)
                : mLeftDragger.shouldInterceptTouchEvent(ev) | mRightDragger.shouldInterceptTouchEvent(ev);

        boolean interceptForTap = false;

        switch (action) {
        case MotionEvent.ACTION_DOWN: {
            final float x = ev.getX();
            final float y = ev.getY();
            mInitialMotionX = x;
            mInitialMotionY = y;
            if (mScrimOpacity > 0 && isContentView(mLeftDragger.findTopChildUnder((int) x, (int) y))) {
                interceptForTap = true;
            }
            mDisallowInterceptRequested = false;
            mChildrenCanceledTouch = false;
            break;
        }

        case MotionEvent.ACTION_MOVE: {
            // If we cross the touch slop, don't perform the delayed peek for an edge touch.
            if (mLeftDragger.checkTouchSlop(ViewDragHelper.DIRECTION_ALL)) {
                mLeftCallback.removeCallbacks();
                mRightCallback.removeCallbacks();
            }
            break;
        }

        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP: {
            closeDrawers(true);
            mDisallowInterceptRequested = false;
            mChildrenCanceledTouch = false;
        }
        }

        return interceptForDrag || interceptForTap || hasPeekingDrawer() || mChildrenCanceledTouch;
    } catch (Exception e) {
        return false;
    }
}

From source file:com.aidy.bottomdrawerlayout.AllDrawerLayout.java

/**
 * 12-03 22:59:19.686: I/BottomDrawerLayout(12480): onLayout() -- left = 0
 * -- top = 0 -- right = 1080 -- b = 1675 12-03 22:59:19.686:
 * I/BottomDrawerLayout(12480): onLayout() -- childWidth = 750 --
 * childHeight = 1675 -- lp.onScreen = 0.0 12-03 22:59:19.686:
 * I/BottomDrawerLayout(12480): onLayout() -- childLeft = -750 -- newOffset
 * = 0.0 12-03 22:59:19.686: I/BottomDrawerLayout(12480): onLayout() --
 * childWidth = 750 -- childHeight = 1675 -- lp.onScreen = 0.0 12-03
 * 22:59:19.686: I/BottomDrawerLayout(12480): onLayout() -- childLeft = 1080
 * -- newOffset = 0.0//from w  w w . j  a  va2 s  . c om
 */
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
    Log.i(TAG, "onLayout() -- left = " + l + " -- top = " + t + " -- right = " + r + " -- b = " + b);
    mInLayout = true;
    final int width = r - l;// 
    final int height = b - t;// 
    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        if (child.getVisibility() == GONE) {
            continue;
        }
        final LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (isContentView(child)) {
            child.layout(lp.leftMargin, lp.topMargin, lp.leftMargin + child.getMeasuredWidth(),
                    lp.topMargin + child.getMeasuredHeight());
        } else {
            // ?view
            final int childWidth = child.getMeasuredWidth();
            final int childHeight = child.getMeasuredHeight();
            // Log.i(TAG, "onLayout() -- childWidth = " + childWidth +
            // " -- childHeight = " + childHeight
            // + " -- lp.onScreen = " + lp.onScreen);
            int childLeft = 0;// 
            int childTop = 0;// 
            float newOffset = 0;// 

            switch (getDrawerViewAbsoluteGravity(child)) {
            case Gravity.LEFT:
                if (checkDrawerViewAbsoluteGravity(child, Gravity.LEFT)) {
                    // Log.i(TAG, "onLayout() -- 1");
                    childLeft = -childWidth + (int) (childWidth * lp.onScreen);
                    newOffset = (float) (childWidth + childLeft) / childWidth;// ?
                }
                break;
            case Gravity.RIGHT:
                if (checkDrawerViewAbsoluteGravity(child, Gravity.RIGHT)) {
                    // Log.i(TAG, "onLayout() -- 2");
                    childLeft = width - (int) (childWidth * lp.onScreen);
                    newOffset = (float) (width - childLeft) / childWidth;// ?
                }
                break;
            case Gravity.TOP:
                if (checkDrawerViewAbsoluteGravity(child, Gravity.TOP)) {
                    // Log.i(TAG, "onLayout() -- 3");
                    childTop = -childHeight + (int) (childHeight * lp.onScreen);
                    newOffset = (float) (childHeight + childTop) / childHeight;// ?
                }
                break;
            case Gravity.BOTTOM:
                if (checkDrawerViewAbsoluteGravity(child, Gravity.BOTTOM)) {
                    // Log.i(TAG, "onLayout() -- 4");
                    childTop = height - (int) (childHeight * lp.onScreen);
                    newOffset = (float) (height - childTop) / childHeight;// ?
                }
                break;
            default:
                childTop = height - (int) (childHeight * lp.onScreen);
                newOffset = (float) (height - childTop) / childHeight;// ?
                break;
            }
            // /////////////////////////////////////////
            // Log.i(TAG, "onLayout() -- childLeft = " + childLeft +
            // " -- newOffset = " + newOffset);
            final boolean changeOffset = newOffset != lp.onScreen;
            final int vgrav = lp.gravity & Gravity.VERTICAL_GRAVITY_MASK;
            switch (vgrav) {
            // case Gravity.TOP: {
            // Log.i(TAG, "onLayout() -- Gravity.TOP");
            // child.layout(childLeft, lp.topMargin, childLeft + childWidth,
            // lp.topMargin + childHeight);
            // break;
            // }
            // case Gravity.BOTTOM: {
            // Log.i(TAG, "onLayout() -- Gravity.BOTTOM");
            // child.layout(childLeft, height - lp.bottomMargin -
            // child.getMeasuredHeight(), childLeft
            // + childWidth, height - lp.bottomMargin);
            // break;
            // }
            case Gravity.CENTER_VERTICAL: {
                // Log.i(TAG, "onLayout() -- Gravity.CENTER_VERTICAL");
                int childTop_cv = (height - childHeight) / 2;

                // Offset for margins. If things don't fit right because of
                // bad measurement before, oh well.
                if (childTop_cv < lp.topMargin) {
                    childTop_cv = lp.topMargin;
                } else if (childTop_cv + childHeight > height - lp.bottomMargin) {
                    childTop_cv = height - lp.bottomMargin - childHeight;
                }
                child.layout(childLeft, childTop_cv, childLeft + childWidth, childTop_cv + childHeight);
                break;
            }
            }

            // /////////////////////////////////////////

            if (changeOffset) {
                setDrawerViewOffset(child, newOffset);
            }

            final int newVisibility = lp.onScreen > 0 ? VISIBLE : INVISIBLE;
            if (child.getVisibility() != newVisibility) {
                child.setVisibility(newVisibility);
            }
        }
    }
    mInLayout = false;
    mFirstLayout = false;
}

From source file:com.cyanogenmod.filemanager.ui.widgets.DrawerLayout.java

boolean isDrawerView(View child) {
    final int gravity = ((LayoutParams) child.getLayoutParams()).gravity;
    final int absGravity = Gravity.getAbsoluteGravity(gravity, child.getLayoutDirection());
    return (absGravity & (Gravity.LEFT | Gravity.RIGHT)) != 0;
}