Example usage for android.view Gravity NO_GRAVITY

List of usage examples for android.view Gravity NO_GRAVITY

Introduction

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

Prototype

int NO_GRAVITY

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

Click Source Link

Document

Constant indicating that no gravity has been set

Usage

From source file:com.actionbarsherlock.internal.view.menu.ActionMenuView.java

@Override
protected LayoutParams generateLayoutParams(ViewGroup.LayoutParams p) {
    if (p instanceof LayoutParams) {
        LayoutParams result = new LayoutParams((LayoutParams) p);
        if (result.gravity <= Gravity.NO_GRAVITY) {
            result.gravity = Gravity.CENTER_VERTICAL;
        }//w w  w  .  j  a  v a  2 s . c om
        return result;
    }
    return generateDefaultLayoutParams();
}

From source file:android.support.wear.widget.drawer.WearableDrawerLayout.java

@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
    super.addView(child, index, params);

    if (!(child instanceof WearableDrawerView)) {
        return;//from www .  j  av a  2s  .c o  m
    }

    WearableDrawerView drawerChild = (WearableDrawerView) child;
    drawerChild.setDrawerController(new WearableDrawerController(this, drawerChild));
    int childGravity = ((FrameLayout.LayoutParams) params).gravity;
    // Check for preferential gravity if no gravity is set in the layout.
    if (childGravity == Gravity.NO_GRAVITY || childGravity == GRAVITY_UNDEFINED) {
        ((FrameLayout.LayoutParams) params).gravity = drawerChild.preferGravity();
        childGravity = drawerChild.preferGravity();
        drawerChild.setLayoutParams(params);
    }
    WearableDrawerView drawerView;
    if (childGravity == Gravity.TOP) {
        mTopDrawerView = drawerChild;
        drawerView = mTopDrawerView;
    } else if (childGravity == Gravity.BOTTOM) {
        mBottomDrawerView = drawerChild;
        drawerView = mBottomDrawerView;
    } else {
        drawerView = null;
    }

    if (drawerView != null) {
        drawerView.addOnLayoutChangeListener(this);
    }
}

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

/**
 * @return the drawer view//from w  w w .j av a  2 s.  co m
 */
private View findDrawerView() {
    if (mDrawerView != null) {
        return mDrawerView;
    }

    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final int childAbsGravity = getDrawerViewAbsoluteGravity(child);
        if (childAbsGravity != Gravity.NO_GRAVITY) {
            mDrawerView = child;
            return child;
        }
    }
    throw new IllegalStateException("No drawer view found.");
}

From source file:com.luke.lukef.lukeapp.fragments.MapViewFragment.java

/**
 * Handles showing the Calendar pop up, fetching the selected date, calling to fetch
 * submissions again/*w w  w  .  j  a  v a 2s  .c om*/
 */
private void showCalendarPicker() {
    // Inflate the popup_layout.xml
    ConstraintLayout viewGroup = (ConstraintLayout) getMainActivity().findViewById(R.id.popup_calendar_root);
    LayoutInflater layoutInflater = (LayoutInflater) getMainActivity()
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    final View layout = layoutInflater.inflate(R.layout.popup_calendar, viewGroup);
    // Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
    //or if popup is on edge display it to the left of the circle
    Display display = getMainActivity().getWindowManager().getDefaultDisplay();
    Point size = new Point(0, 0);
    display.getSize(size);

    int OFFSET_X = 25;
    int OFFSET_Y = 25;

    final DatePicker dP = (DatePicker) layout.findViewById(R.id.popup_calendar_datepicker);

    // Creating the PopupWindow
    final PopupWindow popup = new PopupWindow(getMainActivity());
    popup.setAnimationStyle(android.R.style.Animation_Dialog);
    popup.setContentView(layout);

    popup.setWidth(ViewGroup.LayoutParams.WRAP_CONTENT);
    popup.setHeight(ViewGroup.LayoutParams.WRAP_CONTENT);

    popup.setFocusable(true);
    //gets rid of default background
    popup.setBackgroundDrawable(new BitmapDrawable(getMainActivity().getResources(), (Bitmap) null));
    //popup.setBackgroundDrawable(new BitmapDrawable(getMainActivity().getResources(), (Bitmap) nu));

    // Displaying the popup at the specified location, + offsets.
    popup.showAtLocation(layout, Gravity.NO_GRAVITY, 200 + OFFSET_X, 300 + OFFSET_Y);
    Calendar minDate;
    minDate = Calendar.getInstance();
    this.tempY = minDate.get(Calendar.YEAR);
    this.tempM = minDate.get(Calendar.MONTH);
    this.tempD = minDate.get(Calendar.DAY_OF_MONTH);
    dP.init(minDate.get(Calendar.YEAR), minDate.get(Calendar.MONTH), minDate.get(Calendar.DAY_OF_MONTH),
            new DatePicker.OnDateChangedListener() {
                @Override
                // Months start from 0, so January is month 0
                public void onDateChanged(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                    tempY = year;
                    tempM = monthOfYear;
                    tempD = dayOfMonth;
                    Log.e(TAG, "onDateChanged: selected " + tempD + " " + tempM + " " + tempY);
                }
            });
    ImageButton okButton = (ImageButton) layout.findViewById(R.id.popup_calendar_accept);
    ImageButton cancelButton = (ImageButton) layout.findViewById(R.id.popup_calendar_cancel);
    okButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Calendar calendar = Calendar.getInstance();
            calendar.set(tempY, tempM, tempD, 1, 0);
            Log.e(TAG, "onClick: calendar time in ms " + calendar.getTimeInMillis());
            // clear items from clustermanager and submissionMarkerList, as all new submissions
            // need to be fetched based on the selected date
            clusterManager.clearItems();
            submissionMarkerIdList.clear();
            addAdminMarkersToMap();
            setMinDateInMs(calendar.getTimeInMillis());
            popup.dismiss();
        }
    });

    cancelButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            setMinDateInMs(0);
            popup.dismiss();

        }
    });
}

From source file:com.android.mail.browse.ConversationContainer.java

private static OverlayPosition calculatePosition(final ConversationOverlayItem adapterItem, final int withinTop,
        final int withinBottom, final int forceGravity) {
    if (adapterItem.getHeight() == 0) {
        // "place" invisible items at the bottom of their region to stay consistent with the
        // stacking algorithm in positionOverlays(), unless gravity is forced to the top
        final int y = (forceGravity == Gravity.TOP) ? withinTop : withinBottom;
        return new OverlayPosition(y, y);
    }/*w  w w  . jav a 2s  .  com*/

    final int v = ((forceGravity != Gravity.NO_GRAVITY) ? forceGravity : adapterItem.getGravity())
            & Gravity.VERTICAL_GRAVITY_MASK;
    switch (v) {
    case Gravity.BOTTOM:
        return new OverlayPosition(withinBottom - adapterItem.getHeight(), withinBottom);
    case Gravity.TOP:
        return new OverlayPosition(withinTop, withinTop + adapterItem.getHeight());
    default:
        throw new UnsupportedOperationException("unsupported gravity: " + v);
    }
}

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

public int getDropDownGravity() {
    if (mDropDownGravity == Gravity.NO_GRAVITY) {
        return Gravity.TOP | GravityCompat.START;
    }/*  w  w  w. j  av  a  2  s.c  om*/
    return mDropDownGravity;
}

From source file:org.appcelerator.titanium.util.TiUIHelper.java

public static int getGravity(final String align, final boolean vertical) {
    if (align != null) {
        if ("left".equals(align)) {
            return Gravity.LEFT;
        } else if ("center".equals(align)) {
            return vertical ? Gravity.CENTER_VERTICAL : Gravity.CENTER_HORIZONTAL;
        } else if ("right".equals(align)) {
            return Gravity.RIGHT;
        } else if ("top".equals(align)) {
            return Gravity.TOP;
        } else if ("bottom".equals(align)) {
            return Gravity.BOTTOM;
        }//w  w w.ja  va2  s. c  om
    }
    return Gravity.NO_GRAVITY;
}

From source file:org.appcelerator.titanium.util.TiUIHelper.java

public static void setAlignment(final TextView tv, final String textAlign, final String verticalAlign) {
    int gravity = Gravity.NO_GRAVITY;

    if (textAlign != null) {
        if ("left".equals(textAlign)) {
            gravity |= Gravity.LEFT;/*from   w w w .ja  va2 s .c  o m*/
        } else if ("center".equals(textAlign) || "middle".equals(textAlign)) {
            gravity |= Gravity.CENTER_HORIZONTAL;
        } else if ("right".equals(textAlign)) {
            gravity |= Gravity.RIGHT;
        } else {
            Log.w(TAG, "Unsupported horizontal alignment: " + textAlign);
        }
    } else {
        // Nothing has been set - let's set if something was set previously
        // You can do this with shortcut syntax - but long term maint of code is easier if it's explicit
        //         Log.w(TAG,
        //            "No alignment set - old horizontal align was: " + (tv.getGravity() & Gravity.HORIZONTAL_GRAVITY_MASK),
        //            Log.DEBUG_MODE);

        if ((tv.getGravity() & Gravity.HORIZONTAL_GRAVITY_MASK) != Gravity.NO_GRAVITY) {
            // Something was set before - so let's use it
            gravity |= tv.getGravity() & Gravity.HORIZONTAL_GRAVITY_MASK;
        }
    }

    if (verticalAlign != null) {
        if ("top".equals(verticalAlign)) {
            gravity |= Gravity.TOP;
        } else if ("middle".equals(verticalAlign) || "center".equals(verticalAlign)) {
            gravity |= Gravity.CENTER_VERTICAL;
        } else if ("bottom".equals(verticalAlign)) {
            gravity |= Gravity.BOTTOM;
        } else {
            Log.w(TAG, "Unsupported vertical alignment: " + verticalAlign);
        }
    } else {
        // Nothing has been set - let's set if something was set previously
        // You can do this with shortcut syntax - but long term maint of code is easier if it's explicit
        //         Log.w(TAG, "No alignment set - old vertical align was: " + (tv.getGravity() & Gravity.VERTICAL_GRAVITY_MASK),
        //            Log.DEBUG_MODE);
        if ((tv.getGravity() & Gravity.VERTICAL_GRAVITY_MASK) != Gravity.NO_GRAVITY) {
            // Something was set before - so let's use it
            gravity |= tv.getGravity() & Gravity.VERTICAL_GRAVITY_MASK;
        }
    }

    tv.setGravity(gravity);
}

From source file:com.nickandjerry.dynamiclayoutinflator.DynamicLayoutInflator.java

private static int parseGravity(String value) {
    int gravity = Gravity.NO_GRAVITY;
    String[] parts = value.toLowerCase().split("[|]");
    for (String part : parts) {
        switch (part) {
        case "center":
            gravity = gravity | Gravity.CENTER;
            break;
        case "left":
        case "textStart":
            gravity = gravity | Gravity.LEFT;
            break;
        case "right":
        case "textEnd":
            gravity = gravity | Gravity.RIGHT;
            break;
        case "top":
            gravity = gravity | Gravity.TOP;
            break;
        case "bottom":
            gravity = gravity | Gravity.BOTTOM;
            break;
        case "center_horizontal":
            gravity = gravity | Gravity.CENTER_HORIZONTAL;
            break;
        case "center_vertical":
            gravity = gravity | Gravity.CENTER_VERTICAL;
            break;
        }//from ww w.  j  a  v a2  s .c o  m
    }
    return gravity;
}

From source file:org.zywx.wbpalmstar.engine.EBrowserWindow.java

public boolean checkPop(EBrwViewEntry entity) {
    EBrowserView child = mPopTable.get(entity.mViewName);
    if (child == null) {
        return false;
    }/*from w w w  .j  a v  a2  s.  c  o  m*/
    child.setDateType(entity.mDataType);
    child.setQuery(entity.mQuery);
    View parent = (View) child.getParent();
    boolean parentHasChanged = parent.getParent() != this;//View???removeadd?
    if (parentHasChanged) {
        removeView(parent);
    }
    LayoutParams popParm = new LayoutParams(entity.mWidth, entity.mHeight);
    popParm.gravity = Gravity.NO_GRAVITY;
    popParm.leftMargin = entity.mX;
    popParm.topMargin = entity.mY;
    popParm.bottomMargin = entity.mBottom;
    parent.setLayoutParams(popParm);
    if (entity.hasExtraInfo) {
        /**wanglei del 20151124*/
        //            child.setBrwViewBackground(entity.mOpaque, entity.mBgColor, "");
        /**wanglei add 20151124*/
        ((EBounceView) child.getParent()).setBounceViewBackground(entity.mOpaque, entity.mBgColor, "", child);
    }
    /**wanglei add 20151124*/
    child.setBackgroundColor(Color.TRANSPARENT);
    addView(parent);
    switch (entity.mDataType) {
    case EBrwViewEntry.WINDOW_DATA_TYPE_URL:
        //         if (entity.checkFlag(EBrwViewEntry.F_FLAG_OBFUSCATION)) {
        if ((getWidget().m_obfuscation == 1) && !entity.checkFlag(EBrwViewEntry.F_FLAG_WEBAPP)) {
            child.needToEncrypt(child, entity.mUrl, 0);
        } else {
            child.newLoadUrl(entity.mUrl);
        }
        mBrw.popCloseAnalytics(child.getRelativeUrl());
        mBrw.popOpenAnalytics(getRelativeUrl(), entity.mRelativeUrl);
        child.setRelativeUrl(entity.mRelativeUrl);
        break;
    case EBrwViewEntry.WINDOW_DATA_TYPE_DATA:
        child.newLoadData(entity.mData);
        break;
    case EBrwViewEntry.WINDOW_DATA_TYPE_DATA_URL:
        String data1 = ACEDes.decrypt(entity.mUrl, mContext, false, entity.mData);
        child.loadDataWithBaseURL(entity.mUrl, data1, EBrowserView.CONTENT_MIMETYPE_HTML,
                EBrowserView.CONTENT_DEFAULT_CODE, entity.mUrl);
        break;
    }
    return true;
}