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:net.toload.main.hd.candidate.CandidateView.java

/**
 * Update composing to correct location with a delay after setComposing.
 *//*from  w  ww  .j  ava 2s . c  o  m*/

public void doUpdateComposing() {
    if (DEBUG)
        Log.i(TAG, "doUpdateComposing(): this.isShown()" + this.isShown() + "; embeddedComposing is null:"
                + (embeddedComposing == null));

    if (embeddedComposing != null)
        return; //Jeremy '15,6, 4 bypass updating popup when composing view is embedded in candidate container

    //mComposingTextView.measure(
    //MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED),
    //MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED));
    //final int popupWidth = mComposingTextView.getMeasuredWidth();  //Jeremy '12,6,2 use getWidth and getHeight instead
    //final int popupHeight = mComposingTextView.getMeasuredHeight();
    // getMeasuredWidth cannot get correct width of textVIEW in android 6 Jeremy '16,7,16
    String composingText = String.valueOf(mComposingTextView.getText());
    if (composingText == null)
        return; // avoid measureText on null object.  Jeremy '16/7/26

    Paint paint = mComposingTextView.getPaint();
    Paint.FontMetrics metrics = paint.getFontMetrics();
    final int popupWidth = (int) paint.measureText(composingText);
    final int popupHeight = (int) (metrics.bottom - metrics.top);

    int[] offsetInWindow = new int[2];
    this.getLocationInWindow(offsetInWindow);
    int mPopupComposingY = offsetInWindow[1];
    int mPopupComposingX = 0;

    mPopupComposingY -= popupHeight;

    if (DEBUG)
        Log.i(TAG,
                "doUpdateComposing():mPopupComposingX:" + mPopupComposingX + ". mPopupComposingY:"
                        + mPopupComposingY + ". popupWidth = " + popupWidth + ". popupHeight = " + popupHeight
                        + ". mComposingTextPopup.isShowing()=" + mComposingTextPopup.isShowing());

    try {
        if (mComposingTextPopup.isShowing()) {
            mComposingTextPopup.update(mPopupComposingX, mPopupComposingY, popupWidth, popupHeight);
        } else {
            mComposingTextPopup.setWidth(popupWidth);
            mComposingTextPopup.setHeight(popupHeight);
            mComposingTextPopup.showAtLocation(this, Gravity.NO_GRAVITY, mPopupComposingX, mPopupComposingY);
        }
    } catch (Exception e) {
        // ignore candidate construct error
        e.printStackTrace();
    }

}

From source file:com.huofu.RestaurantOS.ui.splash.activate.java

/**
 * ?/*from w ww .j av a 2s  . c  om*/
 */
public void showLoadingDialog(String text) {

    LayoutInflater inflater = (LayoutInflater) ctxt.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View grid = inflater.inflate(R.layout.loading_layout, null);

    TextView tv = (TextView) grid.findViewById(R.id.textview_loading_content);
    tv.setText(text);

    ImageView iv = (ImageView) grid.findViewById(R.id.imageview_loading_pic);
    iv.startAnimation(AnimationUtils.loadAnimation(ctxt, R.anim.rotate_loading));

    int width = CommonUtils.getScreenWidth(ctxt);
    int height = CommonUtils.getScreenHeight(ctxt);

    if (dialog_loading == null) {
        dialog_loading = new PopupWindow(grid, width, height, true);
    } else {
        dialog_loading.setContentView(grid);
    }

    dialog_loading.setFocusable(true);
    dialog_loading.setOutsideTouchable(true);
    dialog_loading.setAnimationStyle(R.style.AutoDialogAnimation);
    dialog_loading.setBackgroundDrawable(new BitmapDrawable());
    if (hasFocus) {
        dialog_loading.showAtLocation(rl_activate, Gravity.NO_GRAVITY, 0, 0);
    }

}

From source file:net.smartpager.android.activity.MainActivity.java

private void showPopup(View view) {
    int[] location = new int[2];
    view.getLocationOnScreen(location);/*from ww  w  .j a va 2s  .  c  om*/
    Point p = new Point();
    p.x = location[0];
    p.y = location[1];

    int popupWidth = (int) (140 * getResources().getDisplayMetrics().density);
    int popupHeight = (int) (110 * getResources().getDisplayMetrics().density);

    // Inflate the popup_layout.xml
    LinearLayout viewGroup = (LinearLayout) this.findViewById(R.id.popup_container);
    LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View layout = layoutInflater.inflate(R.layout.popup_status, viewGroup);
    // Creating the PopupWindow
    mPopup = new PopupWindow(this);
    mPopup.setBackgroundDrawable(getResources().getDrawable(R.drawable.def_bg_popup_attachment_static));
    mPopup.setContentView(layout);
    mPopup.setWidth(popupWidth);
    mPopup.setHeight(popupHeight);
    mPopup.setFocusable(true);

    int OFFSET_X = 30;
    int OFFSET_Y = -popupHeight;

    layout.findViewById(R.id.popup_set_offline_layout).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (!NetworkUtils.isInternetConnectedAsync()) {
                mPopup.dismiss();
                showDialogUnableToChangeStatus();
            } else {
                setStatusService(ContactStatus.DO_NOT_DISTURB, true);
            }
        }
    });

    layout.findViewById(R.id.popup_set_online_layout).setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (!NetworkUtils.isInternetConnectedAsync()) {
                mPopup.dismiss();
                showDialogUnableToChangeStatus();
            } else if (SmartPagerApplication.getInstance().getPreferences()
                    .getSyncState() != SyncState.Syncronized) {
                mPopup.dismiss();
                startSyncronization();
                showSyncInProgressDialog();
            } else {
                setStatusService(ContactStatus.ONLINE, true);
            }
        }
    });

    mPopup.showAtLocation(layout, Gravity.NO_GRAVITY, p.x + OFFSET_X, p.y + OFFSET_Y);
}

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

/**
 * Peeks the given drawer if it is not {@code null} and has a peek view.
 *//*from   w w w  . ja va 2s .c  o m*/
private void maybePeekDrawer(WearableDrawerView drawerView) {
    if (drawerView == null) {
        return;
    }
    View peekView = drawerView.getPeekContainer();
    if (peekView == null) {
        return;
    }

    View drawerContent = drawerView.getDrawerContent();
    int layoutGravity = ((FrameLayout.LayoutParams) drawerView.getLayoutParams()).gravity;
    int gravity = layoutGravity == Gravity.NO_GRAVITY ? drawerView.preferGravity() : layoutGravity;

    drawerView.setIsPeeking(true);
    peekView.setAlpha(1);
    peekView.setScaleX(1);
    peekView.setScaleY(1);
    peekView.setVisibility(VISIBLE);
    if (drawerContent != null) {
        drawerContent.setAlpha(0);
        drawerContent.setVisibility(GONE);
    }

    if (gravity == Gravity.BOTTOM) {
        mBottomDrawerDragger.smoothSlideViewTo(drawerView, 0 /* finalLeft */,
                getHeight() - peekView.getHeight());
    } else if (gravity == Gravity.TOP) {
        mTopDrawerDragger.smoothSlideViewTo(drawerView, 0 /* finalLeft */,
                -(drawerView.getHeight() - peekView.getHeight()));
        if (!mIsAccessibilityEnabled) {
            // Don't automatically close the top drawer when in accessibility mode.
            closeDrawerDelayed(gravity, PEEK_AUTO_CLOSE_DELAY_MS);
        }
    }

    invalidate();
}

From source file:com.huofu.RestaurantOS.ui.splash.activate.java

/**
 * ?/*from   w ww.j  a va 2  s .  c o m*/
 *
 * @param msg:
 * @param result:-1->? 0-???
 */
public void showDialogError(String msg, final int result) {
    LayoutInflater inflater = (LayoutInflater) ctxt.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    View grid = inflater.inflate(R.layout.dialog_show_error_one_option, null);

    TextView tvContent = (TextView) grid.findViewById(R.id.tv_dialog_error_content);
    final Button btn_close = (Button) grid.findViewById(R.id.btn_dialog_error_close);

    tvContent.setText(msg);

    OnClickListener ocl = new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            if (v.getId() == btn_close.getId()) {
                if (dialog_show_error != null) {
                    if (dialog_show_error.isShowing()) {
                        dialog_show_error.dismiss();
                    }
                }
                if (result == -1) {
                    finishWithNextActivity(LoginActivity.class);
                }
            }
        }
    };
    btn_close.setOnClickListener(ocl);

    int width = CommonUtils.getScreenWidth(ctxt);
    int height = CommonUtils.getScreenHeight(ctxt);

    if (dialog_show_error == null) {
        dialog_show_error = new PopupWindow(grid, width, height, true);
    }

    dialog_show_error.setBackgroundDrawable(new BitmapDrawable());
    dialog_show_error.setContentView(grid);
    dialog_show_error.setFocusable(true);
    dialog_show_error.setOutsideTouchable(true);
    dialog_show_error.setAnimationStyle(R.style.AutoDialogAnimation);
    try {
        dialog_show_error.showAtLocation(rl_activate, Gravity.NO_GRAVITY, 0, 0);
    } catch (Exception e) {

    }

}

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

@Override
protected void onRestoreInstanceState(Parcelable state) {
    Bundle saved = (Bundle) state;/*from  ww w  . ja  v  a 2 s.co  m*/
    setDrawerLockMode(saved.getInt(KEY_LEFT_LOCK_MODER, LOCK_MODE_UNLOCKED), Gravity.LEFT);
    setDrawerLockMode(saved.getInt(KEY_RIGHT_LOCK_MODER, LOCK_MODE_UNLOCKED), Gravity.RIGHT);
    openDrawer(saved.getInt(KEY_OPENED_DRAWER, Gravity.NO_GRAVITY));
    super.onRestoreInstanceState(saved.getParcelable(KEY_SUPER));
}

From source file:de.mrapp.android.preference.activity.PreferenceActivity.java

/**
 * Adapts the GUI, depending on whether the navigation is currently hidden or not.
 *
 * @param navigationHidden/* w w  w . ja  va2 s  . c  o m*/
 *         True, if the navigation is currently hidden, false otherwise
 */
private void adaptNavigation(final boolean navigationHidden) {
    if (isSplitScreen()) {
        getPreferenceHeaderParentView().setVisibility(navigationHidden ? View.GONE : View.VISIBLE);
        FrameLayout.LayoutParams preferenceScreenLayoutParams = (FrameLayout.LayoutParams) getPreferenceScreenContainer()
                .getLayoutParams();
        preferenceScreenLayoutParams.leftMargin = (navigationHidden
                ? getResources().getDimensionPixelSize(R.dimen.preference_screen_horizontal_margin)
                : dpToPixels(this, getNavigationWidth()))
                - getResources().getDimensionPixelSize(R.dimen.card_view_intrinsic_margin);
        preferenceScreenLayoutParams.rightMargin = getResources()
                .getDimensionPixelSize(navigationHidden ? R.dimen.preference_screen_horizontal_margin
                        : R.dimen.preference_screen_margin_right)
                - getResources().getDimensionPixelSize(R.dimen.card_view_intrinsic_margin);
        preferenceScreenLayoutParams.gravity = navigationHidden ? Gravity.CENTER_HORIZONTAL
                : Gravity.NO_GRAVITY;
        getPreferenceScreenContainer().requestLayout();
        toolbarLarge.hideNavigation(navigationHidden);
    } else {
        if (isPreferenceHeaderSelected()) {
            if (navigationHidden) {
                hideToolbarNavigationIcon();
            } else {
                showToolbarNavigationIcon();
            }
        } else if (navigationHidden) {
            if (getListAdapter() != null && !getListAdapter().isEmpty()) {
                showPreferenceScreen(getListAdapter().getItem(0), null, false);
            } else if (getListAdapter() != null) {
                finish();
            }
        }
    }
}

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   w  w  w. ja va  2  s. c o m*/
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:ca.co.rufus.androidboilerplate.ui.DebugDrawerLayout.java

boolean isContentView(View child) {
    return ((LayoutParams) child.getLayoutParams()).gravity == Gravity.NO_GRAVITY;
}

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

/**
 * Return the given gravity value or the default if the passed value is NO_GRAVITY.
 * This should be used for children that are not anchored to another view or a keyline.
 *//*  w ww.j  a  v a 2 s.  c  o m*/
private static int resolveGravity(int gravity) {
    return gravity == Gravity.NO_GRAVITY ? GravityCompat.START | Gravity.TOP : gravity;
}