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.facebook.react.views.textinput.ReactTextInputManager.java

@ReactProp(name = ViewProps.TEXT_ALIGN)
public void setTextAlign(ReactEditText view, @Nullable String textAlign) {
    if (textAlign == null || "auto".equals(textAlign)) {
        view.setGravityHorizontal(Gravity.NO_GRAVITY);
    } else if ("left".equals(textAlign)) {
        view.setGravityHorizontal(Gravity.LEFT);
    } else if ("right".equals(textAlign)) {
        view.setGravityHorizontal(Gravity.RIGHT);
    } else if ("center".equals(textAlign)) {
        view.setGravityHorizontal(Gravity.CENTER_HORIZONTAL);
    } else if ("justify".equals(textAlign)) {
        // Fallback gracefully for cross-platform compat instead of error
        view.setGravityHorizontal(Gravity.LEFT);
    } else {//from   www  .ja va  2s  .  c  om
        throw new JSApplicationIllegalArgumentException("Invalid textAlign: " + textAlign);
    }
}

From source file:io.github.hidroh.materialistic.widget.StoryRecyclerViewAdapter.java

private void showMoreOptions(View v, final Item story, final ItemViewHolder holder) {
    mPopupMenu.create(mContext, v, Gravity.NO_GRAVITY).inflate(R.menu.menu_contextual_story)
            .setMenuItemTitle(R.id.menu_contextual_save, story.isFavorite() ? R.string.unsave : R.string.save)
            .setOnMenuItemClickListener(item -> {
                if (item.getItemId() == R.id.menu_contextual_save) {
                    toggleSave(story);//from  w ww  .j  a  v  a  2 s .  c o  m
                    return true;
                }
                if (item.getItemId() == R.id.menu_contextual_vote) {
                    vote(story, holder);
                    return true;
                }
                if (item.getItemId() == R.id.menu_contextual_comment) {
                    mContext.startActivity(new Intent(mContext, ComposeActivity.class)
                            .putExtra(ComposeActivity.EXTRA_PARENT_ID, story.getId())
                            .putExtra(ComposeActivity.EXTRA_PARENT_TEXT, story.getDisplayedTitle()));
                    return true;
                }
                if (item.getItemId() == R.id.menu_contextual_profile) {
                    mContext.startActivity(new Intent(mContext, UserActivity.class)
                            .putExtra(UserActivity.EXTRA_USERNAME, story.getBy()));
                    return true;
                }
                if (item.getItemId() == R.id.menu_contextual_share) {
                    mContext.startActivity(AppUtils.makeChooserShareIntent(mContext, story.getDisplayedTitle(),
                            story.getUrl()));
                    return true;
                }
                return false;
            }).show();
}

From source file:com.hippo.drawerlayout.DrawerLayout.java

@Override
protected void onFinishInflate() {
    super.onFinishInflate();

    final int childCount = getChildCount();
    for (int i = 0; i < childCount; i++) {
        final View child = getChildAt(i);
        final int absGravity = GravityCompat.getAbsoluteGravity(
                ((LayoutParams) child.getLayoutParams()).gravity, ViewCompat.getLayoutDirection(child));

        if (absGravity == Gravity.NO_GRAVITY) {
            if (mContentView != null)
                throw new IllegalStateException("There is more than one content view");
            mContentView = child;//from www. j a v  a  2  s.c o m
        } else if ((absGravity & Gravity.LEFT) == Gravity.LEFT) {
            if (mLeftDrawer != null)
                throw new IllegalStateException("There is more than one left menu");
            mLeftDrawer = child;
        } else if ((absGravity & Gravity.RIGHT) == Gravity.RIGHT) {
            if (mRightDrawer != null)
                throw new IllegalStateException("There is more than one right menu");
            mRightDrawer = child;
        } else {
            throw new IllegalStateException("Child " + child + " at index " + i
                    + " does not have a valid layout_gravity - must be Gravity.LEFT, "
                    + "Gravity.RIGHT or Gravity.NO_GRAVITY");
        }
    }

    if (mContentView == null) {
        throw new IllegalStateException("There is no content view");
    }
    // Material is solid.
    // Input events cannot pass through material.
    if (mLeftDrawer != null) {
        mLeftDrawer.setClickable(true);
    }
    if (mRightDrawer != null) {
        mRightDrawer.setClickable(true);
    }

    mShadow = new ShadowView(getContext());
    addView(mShadow, 1);
}

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

private void hSetMultiPopOverFrame(EBrwViewEntry entity) {
    ArrayList<EBrowserView> list = mMultiPopTable.get(entity.mViewName);
    if (null == list || list.size() == 0) {
        return;//from w ww  .  j a v a 2s .  c  o  m
    }
    View vParent = (View) list.get(0).getParent();
    LayoutParams lParam = new LayoutParams(entity.mWidth, entity.mHeight);
    lParam.gravity = Gravity.NO_GRAVITY;
    lParam.leftMargin = entity.mX;
    lParam.topMargin = entity.mY;
    vParent.setLayoutParams(lParam);
}

From source file:com.facebook.react.views.textinput.ReactTextInputManager.java

@ReactProp(name = ViewProps.TEXT_ALIGN_VERTICAL)
public void setTextAlignVertical(ReactEditText view, @Nullable String textAlignVertical) {
    if (textAlignVertical == null || "auto".equals(textAlignVertical)) {
        view.setGravityVertical(Gravity.NO_GRAVITY);
    } else if ("top".equals(textAlignVertical)) {
        view.setGravityVertical(Gravity.TOP);
    } else if ("bottom".equals(textAlignVertical)) {
        view.setGravityVertical(Gravity.BOTTOM);
    } else if ("center".equals(textAlignVertical)) {
        view.setGravityVertical(Gravity.CENTER_VERTICAL);
    } else {//from  w w w.j av a 2  s  .  c om
        throw new JSApplicationIllegalArgumentException("Invalid textAlignVertical: " + textAlignVertical);
    }
}

From source file:org.mariotaku.twidere.fragment.support.StatusFragment.java

@Override
public void onStatusMenuClick(StatusViewHolder holder, View menuView, int position) {
    //TODO show status menu
    if (mPopupMenu != null) {
        mPopupMenu.dismiss();//from  w ww  . j  a  v a2s .  c om
    }
    final PopupMenu popupMenu = new PopupMenu(mStatusAdapter.getContext(), menuView, Gravity.NO_GRAVITY,
            R.attr.actionOverflowMenuStyle, 0);
    popupMenu.setOnMenuItemClickListener(mOnStatusMenuItemClickListener);
    popupMenu.inflate(R.menu.action_status);
    final ParcelableStatus status = mStatusAdapter.getStatus(position);
    Utils.setMenuForStatus(mStatusAdapter.getContext(), popupMenu.getMenu(), status);
    popupMenu.show();
    mPopupMenu = popupMenu;
    mSelectedStatus = status;
}

From source file:org.getlantern.firetweet.fragment.support.StatusFragment.java

@Override
public void onStatusMenuClick(StatusViewHolder holder, View menuView, int position) {
    //TODO show status menu
    if (mPopupMenu != null) {
        mPopupMenu.dismiss();//from w  w  w  .j av  a2 s.c om
    }
    final PopupMenu popupMenu = new PopupMenu(mStatusAdapter.getContext(), menuView, Gravity.NO_GRAVITY,
            R.attr.actionOverflowMenuStyle, 0);
    popupMenu.setOnMenuItemClickListener(mOnStatusMenuItemClickListener);
    popupMenu.inflate(R.menu.action_status);
    final ParcelableStatus status = mStatusAdapter.getStatus(position);
    setMenuForStatus(mStatusAdapter.getContext(), popupMenu.getMenu(), status);
    popupMenu.show();
    mPopupMenu = popupMenu;
    mSelectedStatus = status;
}

From source file:com.lykj.weixun.ui.chat.ui.ContactListFragment.java

public void setPopuWindow(View view) {
    // //ww w.j a  v  a  2  s .  co m
    View inflateView = LayoutInflater.from(getContext()).inflate(R.layout.popu_meu, null);
    //
    window = new PopupWindow(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    window.setTouchable(true);
    window.setFocusable(true);
    window.setBackgroundDrawable(new BitmapDrawable());//??
    //
    window.setContentView(inflateView);
    // popWindow???true
    int[] location = new int[2];
    inflateView.getLocationOnScreen(location);
    window.setOutsideTouchable(true);
    window.showAsDropDown(view);//v?
    window.showAtLocation(inflateView, Gravity.NO_GRAVITY, location[0] + inflateView.getWidth() - 20,
            location[1]);
    inflateView.findViewById(R.id.popuMeu_group).setOnClickListener(this);
    inflateView.findViewById(R.id.popuMeu_friend).setOnClickListener(this);
    inflateView.findViewById(R.id.popuMeu_sweep).setOnClickListener(this);
    window.setTouchInterceptor(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // popupwindowpopupwindow
            // true?touch
            // ? PopupWindowonTouchEvent?dismiss
            if (event.getAction() == MotionEvent.ACTION_OUTSIDE) {
                window.dismiss();
                return true;
            }
            return false;
        }
    });

}

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

/**
 * Positions the overlays given an updated y position for the container.
 * @param y the current top position on screen
 * @param postAddView If {@code true}, posts all calls to
 *                    {@link #addViewInLayoutWrapper(android.view.View, boolean)}
 *                    to the UI thread rather than adding it immediately. If {@code false},
 *                    calls {@link #addViewInLayoutWrapper(android.view.View, boolean)}
 *                    immediately.//w  ww .ja  v  a  2s.  c om
 */
private void positionOverlays(int y, boolean postAddView) {
    mOffsetY = y;

    /*
     * The scale value that WebView reports is inaccurate when measured during WebView
     * initialization. This bug is present in ICS, so to work around it, we ignore all
     * reported values and use a calculated expected value from ConversationWebView instead.
     * Only when the user actually begins to touch the view (to, say, begin a zoom) do we begin
     * to pay attention to WebView-reported scale values.
     */
    if (mTouchInitialized) {
        mScale = mWebView.getScale();
    } else if (mScale == 0) {
        mScale = mWebView.getInitialScale();
    }
    traceLayout("in positionOverlays, raw scale=%f, effective scale=%f", mWebView.getScale(), mScale);

    if (mOverlayPositions == null || mOverlayAdapter == null) {
        return;
    }

    // recycle scrolled-off views and add newly visible views

    // we want consecutive spacers/overlays to stack towards the bottom
    // so iterate from the bottom of the conversation up
    // starting with the last spacer bottom and the last adapter item, position adapter views
    // in a single stack until you encounter a non-contiguous expanded message header,
    // then decrement to the next spacer.

    traceLayout("IN positionOverlays, spacerCount=%d overlayCount=%d", mOverlayPositions.length,
            mOverlayAdapter.getCount());

    mSnapIndex = -1;
    mAdditionalBottomBorderOverlayTop = 0;

    int adapterLoopIndex = mOverlayAdapter.getCount() - 1;
    int spacerIndex = mOverlayPositions.length - 1;
    while (spacerIndex >= 0 && adapterLoopIndex >= 0) {

        final int spacerTop = getOverlayTop(spacerIndex);
        final int spacerBottom = getOverlayBottom(spacerIndex);

        final boolean flip;
        final int flipOffset;
        final int forceGravity;
        // flip direction from bottom->top to top->bottom traversal on the very first spacer
        // to facilitate top-aligned headers at spacer index = 0
        if (spacerIndex == 0) {
            flip = true;
            flipOffset = adapterLoopIndex;
            forceGravity = Gravity.TOP;
        } else {
            flip = false;
            flipOffset = 0;
            forceGravity = Gravity.NO_GRAVITY;
        }

        int adapterIndex = flip ? flipOffset - adapterLoopIndex : adapterLoopIndex;

        // always place at least one overlay per spacer
        ConversationOverlayItem adapterItem = mOverlayAdapter.getItem(adapterIndex);

        OverlayPosition itemPos = calculatePosition(adapterItem, spacerTop, spacerBottom, forceGravity);

        traceLayout("in loop, spacer=%d overlay=%d t/b=%d/%d (%s)", spacerIndex, adapterIndex, itemPos.top,
                itemPos.bottom, adapterItem);
        positionOverlay(adapterIndex, itemPos.top, itemPos.bottom, postAddView);

        // and keep stacking overlays unconditionally if we are on the first spacer, or as long
        // as overlays are contiguous
        while (--adapterLoopIndex >= 0) {
            adapterIndex = flip ? flipOffset - adapterLoopIndex : adapterLoopIndex;
            adapterItem = mOverlayAdapter.getItem(adapterIndex);
            if (spacerIndex > 0 && !adapterItem.isContiguous()) {
                // advance to the next spacer, but stay on this adapter item
                break;
            }

            // place this overlay in the region of the spacer above or below the last item,
            // depending on direction of iteration
            final int regionTop = flip ? itemPos.bottom : spacerTop;
            final int regionBottom = flip ? spacerBottom : itemPos.top;
            itemPos = calculatePosition(adapterItem, regionTop, regionBottom, forceGravity);

            traceLayout("in contig loop, spacer=%d overlay=%d t/b=%d/%d (%s)", spacerIndex, adapterIndex,
                    itemPos.top, itemPos.bottom, adapterItem);
            positionOverlay(adapterIndex, itemPos.top, itemPos.bottom, postAddView);
        }

        spacerIndex--;
    }

    positionSnapHeader(mSnapIndex);
    positionAdditionalBottomBorder(postAddView);
}

From source file:com.vanisty.ui.MenuActivity.java

private void showPopup(final Activity context, Point p) {
    int popupWidth = 200;
    int popupHeight = 150;

    // Inflate the popup_layout.xml
    LinearLayout viewGroup = (LinearLayout) context.findViewById(R.id.popup);
    LayoutInflater layoutInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = layoutInflater.inflate(R.layout.popup_layout, viewGroup);

    // Creating the PopupWindow
    final PopupWindow popup = new PopupWindow(context);
    popup.setContentView(layout);/*from   ww  w . j  a va2 s . c  o  m*/
    popup.setWidth(popupWidth);
    popup.setHeight(popupHeight);
    popup.setFocusable(true);

    // Some offset to align the popup a bit to the right, and a bit down, relative to button's position.
    int OFFSET_X = 30;
    int OFFSET_Y = 30;

    // Clear the default translucent background
    popup.setBackgroundDrawable(new BitmapDrawable());

    // Displaying the popup at the specified location, + offsets.
    popup.showAtLocation(layout, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y);

    // Getting a reference to Close button, and close the popup when clicked.
    Button close = (Button) layout.findViewById(R.id.close);
    close.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            popup.dismiss();
        }
    });
}