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.litho.widget.TextSpec.java

private static void resolveStyleAttrsForTypedArray(TypedArray a, Output<TruncateAt> ellipsize,
        Output<Boolean> shouldIncludeFontPadding, Output<Float> spacingMultiplier, Output<Integer> minLines,
        Output<Integer> maxLines, Output<Integer> minEms, Output<Integer> maxEms, Output<Integer> minWidth,
        Output<Integer> maxWidth, Output<Boolean> isSingleLine, Output<CharSequence> text,
        Output<ColorStateList> textColorStateList, Output<Integer> linkColor, Output<Integer> highlightColor,
        Output<Integer> textSize, Output<Alignment> textAlignment, Output<Integer> textStyle,
        Output<Float> shadowRadius, Output<Float> shadowDx, Output<Float> shadowDy, Output<Integer> shadowColor,
        Output<VerticalGravity> verticalGravity) {
    int viewTextAlignment = View.TEXT_ALIGNMENT_GRAVITY;
    int gravity = Gravity.NO_GRAVITY;

    for (int i = 0, size = a.getIndexCount(); i < size; i++) {
        final int attr = a.getIndex(i);

        if (attr == R.styleable.Text_android_text) {
            text.set(a.getString(attr));
        } else if (attr == R.styleable.Text_android_textColor) {
            textColorStateList.set(a.getColorStateList(attr));
        } else if (attr == R.styleable.Text_android_textSize) {
            textSize.set(a.getDimensionPixelSize(attr, 0));
        } else if (attr == R.styleable.Text_android_ellipsize) {
            final int index = a.getInteger(attr, 0);
            if (index > 0) {
                ellipsize.set(TRUNCATE_AT[index - 1]);
            }//from www . ja  v  a 2s .c  o  m
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1
                && attr == R.styleable.Text_android_textAlignment) {
            viewTextAlignment = a.getInt(attr, -1);
            textAlignment.set(getAlignment(viewTextAlignment, gravity));
        } else if (attr == R.styleable.Text_android_gravity) {
            gravity = a.getInt(attr, -1);
            textAlignment.set(getAlignment(viewTextAlignment, gravity));
            verticalGravity.set(getVerticalGravity(gravity));
        } else if (attr == R.styleable.Text_android_includeFontPadding) {
            shouldIncludeFontPadding.set(a.getBoolean(attr, false));
        } else if (attr == R.styleable.Text_android_minLines) {
            minLines.set(a.getInteger(attr, -1));
        } else if (attr == R.styleable.Text_android_maxLines) {
            maxLines.set(a.getInteger(attr, -1));
        } else if (attr == R.styleable.Text_android_singleLine) {
            isSingleLine.set(a.getBoolean(attr, false));
        } else if (attr == R.styleable.Text_android_textColorLink) {
            linkColor.set(a.getColor(attr, 0));
        } else if (attr == R.styleable.Text_android_textColorHighlight) {
            highlightColor.set(a.getColor(attr, 0));
        } else if (attr == R.styleable.Text_android_textStyle) {
            textStyle.set(a.getInteger(attr, 0));
        } else if (attr == R.styleable.Text_android_lineSpacingMultiplier) {
            spacingMultiplier.set(a.getFloat(attr, 0));
        } else if (attr == R.styleable.Text_android_shadowDx) {
            shadowDx.set(a.getFloat(attr, 0));
        } else if (attr == R.styleable.Text_android_shadowDy) {
            shadowDy.set(a.getFloat(attr, 0));
        } else if (attr == R.styleable.Text_android_shadowRadius) {
            shadowRadius.set(a.getFloat(attr, 0));
        } else if (attr == R.styleable.Text_android_shadowColor) {
            shadowColor.set(a.getColor(attr, 0));
        } else if (attr == R.styleable.Text_android_minEms) {
            minEms.set(a.getInteger(attr, DEFAULT_EMS));
        } else if (attr == R.styleable.Text_android_maxEms) {
            maxEms.set(a.getInteger(attr, DEFAULT_EMS));
        } else if (attr == R.styleable.Text_android_minWidth) {
            minWidth.set(a.getDimensionPixelSize(attr, DEFAULT_MIN_WIDTH));
        } else if (attr == R.styleable.Text_android_maxWidth) {
            maxWidth.set(a.getDimensionPixelSize(attr, DEFAULT_MAX_WIDTH));
        }
    }
}

From source file:com.quran.labs.androidquran.widgets.SlidingUpPanelLayout.java

public SlidingUpPanelLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    if (isInEditMode()) {
        mShadowDrawable = null;/*from   w w  w.jav a 2 s  .  c  o m*/
        mScrollTouchSlop = 0;
        mDragHelper = null;
        return;
    }

    if (attrs != null) {
        TypedArray defAttrs = context.obtainStyledAttributes(attrs, DEFAULT_ATTRS);

        if (defAttrs != null) {
            int gravity = defAttrs.getInt(0, Gravity.NO_GRAVITY);
            if (gravity != Gravity.TOP && gravity != Gravity.BOTTOM) {
                throw new IllegalArgumentException("gravity must be set to either top or bottom");
            }
            mIsSlidingUp = gravity == Gravity.BOTTOM;
        }

        defAttrs.recycle();

        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.SlidingUpPanelLayout);

        if (ta != null) {
            mPanelHeight = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_panelHeight, -1);
            mShadowHeight = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_shadowHeight, -1);
            mParallaxOffset = ta.getDimensionPixelSize(R.styleable.SlidingUpPanelLayout_parallaxOffset, -1);

            mMinFlingVelocity = ta.getInt(R.styleable.SlidingUpPanelLayout_flingVelocity,
                    DEFAULT_MIN_FLING_VELOCITY);
            mCoveredFadeColor = ta.getColor(R.styleable.SlidingUpPanelLayout_fadeColor, DEFAULT_FADE_COLOR);

            mDragViewResId = ta.getResourceId(R.styleable.SlidingUpPanelLayout_dragView, -1);

            mOverlayContent = ta.getBoolean(R.styleable.SlidingUpPanelLayout_overlay, DEFAULT_OVERLAY_FLAG);

            mArbitraryPositionEnabled = ta.getBoolean(R.styleable.SlidingUpPanelLayout_arbitraryPosition,
                    DEFAULT_ARBITRARY_POS_FLAG);
        }

        ta.recycle();
    }

    final float density = context.getResources().getDisplayMetrics().density;
    if (mPanelHeight == -1) {
        mPanelHeight = (int) (DEFAULT_PANEL_HEIGHT * density + 0.5f);
    }
    if (mShadowHeight == -1) {
        mShadowHeight = (int) (DEFAULT_SHADOW_HEIGHT * density + 0.5f);
    }
    if (mParallaxOffset == -1) {
        mParallaxOffset = (int) (DEFAULT_PARALLAX_OFFSET * density);
    }
    // If the shadow height is zero, don't show the shadow
    if (mShadowHeight > 0) {
        if (mIsSlidingUp) {
            mShadowDrawable = ContextCompat.getDrawable(context, R.drawable.sliding_panel_above_shadow);
        } else {
            mShadowDrawable = ContextCompat.getDrawable(context, R.drawable.sliding_panel_below_shadow);
        }

    } else {
        mShadowDrawable = null;
    }

    setWillNotDraw(false);

    mDragHelper = ViewDragHelper.create(this, 1.0f, new DragHelperCallback());
    mDragHelper.setMinVelocity(mMinFlingVelocity * density);

    mCanSlide = true;
    mIsSlidingEnabled = true;

    ViewConfiguration vc = ViewConfiguration.get(context);
    mScrollTouchSlop = vc.getScaledTouchSlop();
}

From source file:io.github.hidroh.materialistic.BaseWebFragment.java

private void setUpWebControls(View view) {
    view.findViewById(R.id.toolbar_web).setOnClickListener(v -> scrollToTop());
    view.findViewById(R.id.button_back).setOnClickListener(v -> mWebView.goBack());
    view.findViewById(R.id.button_forward).setOnClickListener(v -> mWebView.goForward());
    view.findViewById(R.id.button_clear).setOnClickListener(v -> {
        mSystemUiHelper.setFullscreen(true);
        reset();/*from  w  w  w  .j  a v a2  s  .  c  o m*/
        mControls.showNext();
    });
    view.findViewById(R.id.button_find).setOnClickListener(v -> {
        mEditText.requestFocus();
        toggleSoftKeyboard(true);
        mControls.showNext();
    });
    mButtonRefresh.setOnClickListener(v -> {
        if (mWebView.getProgress() == 100) {
            mWebView.loadUrl("about:blank");
            load();
        } else {
            mWebView.stopLoading();
        }
    });
    view.findViewById(R.id.button_exit).setOnClickListener(v -> LocalBroadcastManager.getInstance(getActivity())
            .sendBroadcast(new Intent(BaseWebFragment.ACTION_FULLSCREEN).putExtra(EXTRA_FULLSCREEN, false)));
    mButtonNext.setOnClickListener(v -> mWebView.findNext(true));
    mButtonMore.setOnClickListener(v -> mPopupMenu.create(getActivity(), mButtonMore, Gravity.NO_GRAVITY)
            .inflate(R.menu.menu_web).setOnMenuItemClickListener(item -> {
                if (item.getItemId() == R.id.menu_font_options) {
                    showPreferences();
                    return true;
                }
                if (item.getItemId() == R.id.menu_zoom_in) {
                    mWebView.zoomIn();
                    return true;
                }
                if (item.getItemId() == R.id.menu_zoom_out) {
                    mWebView.zoomOut();
                    return true;
                }
                return false;
            }).setMenuItemVisible(R.id.menu_font_options, !TextUtils.isEmpty(mContent)).show());
    mEditText.setOnEditorActionListener((v, actionId, event) -> {
        findInPage();
        return true;
    });
}

From source file:com.landenlabs.all_UiDemo.frag.ImageScalesFrag.java

private Bitmap setScaledImage(final Drawable bgImage, View view, Bitmap prevScaled) {
    if (bgImage != null) {
        if (prevScaled != null)
            prevScaled.recycle();/*  w w w. j  a v  a2s.c  o  m*/

        int screenWidthPx = Resources.getSystem().getDisplayMetrics().widthPixels;
        int viewHeightPx = view.getMeasuredHeight();

        // view.setBackgroundResource(bgImage);
        if (bgImage instanceof BitmapDrawable) {
            BitmapDrawable bmDrawable = (BitmapDrawable) bgImage;
            Bitmap bmImage = bmDrawable.getBitmap();

            prevScaled = scaleCenterCrop(bmImage, screenWidthPx, viewHeightPx);
            view.setBackgroundDrawable(new BitmapDrawable(prevScaled));
        } else {

            // TODO - compute scale factor from screenWidthPx and viewHeightx
            Drawable scaleDrawable = new ScaleDrawable(bgImage, Gravity.NO_GRAVITY, 1.0f, 0.1f);
            view.setBackgroundDrawable(scaleDrawable);
        }
    }

    return prevScaled;
}

From source file:org.zywx.wbpalmstar.engine.universalex.EUExBase.java

/**
 * view?window./*from   w w  w .j a v a2 s.c  om*/
 *
 * @param child
 * @param parms
 */
public final void addViewToCurrentWindow(View child, RelativeLayout.LayoutParams parms) {
    if (null == mBrwView) {
        return;
    }

    float sc = mBrwView.getScaleWrap();
    int l = (int) (parms.leftMargin * sc);
    int t = (int) (parms.topMargin * sc);
    int w = parms.width;
    int h = parms.height;
    if (w > 0) {
        w = (int) (parms.width * sc);
    }
    if (h > 0) {
        h = (int) (parms.height * sc);
    }
    FrameLayout.LayoutParams lp = new FrameLayout.LayoutParams(w, h);
    lp.gravity = Gravity.NO_GRAVITY;
    lp.leftMargin = l;
    lp.topMargin = t;
    adptLayoutParams(parms, lp);
    mBrwView.addViewToCurrentWindow(child, lp);
}

From source file:com.acbelter.directionalcarousel.CarouselViewPager.java

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
    final int width = MeasureSpec.getSize(widthMeasureSpec);
    final int height = MeasureSpec.getSize(heightMeasureSpec);

    int widthMode = MeasureSpec.getMode(widthMeasureSpec);
    int heightMode = MeasureSpec.getMode(heightMeasureSpec);

    if (DEBUG) {//from  www .  ja  v a  2  s  .  c  o  m
        Log.d(TAG, "w=" + width + " h=" + height);
        Log.d(TAG, "wMode=" + getModeDescription(widthMode) + " hMode=" + getModeDescription(heightMode));
    }

    // FIXME Supported only match_parent and wrap_content attributes
    if (mConfig.orientation == CarouselConfig.VERTICAL) {
        int pageContentWidth = getPageContentWidth();
        int newWidth = width;
        if (widthMode == MeasureSpec.AT_MOST || pageContentWidth + 2 * mWrapPadding > width) {

            newWidth = pageContentWidth + 2 * mWrapPadding;
            widthMeasureSpec = MeasureSpec.makeMeasureSpec(newWidth, widthMode);
        }

        ViewGroup.LayoutParams lp = getLayoutParams();
        // FIXME Supported only FrameLayout as parent
        if (lp instanceof FrameLayout.LayoutParams) {
            if (!parentHasExactDimensions()) {
                throw new UnsupportedOperationException("Parent layout should have exact " + "dimensions.");
            }

            FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) lp;
            if (!mSizeChanged) {
                gravityOffset = 0.0f;
                int hGrav = params.gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                if (hGrav == Gravity.CENTER_HORIZONTAL || hGrav == Gravity.CENTER) {
                    gravityOffset = (width - newWidth) * 0.5f;
                }
                if (hGrav == Gravity.RIGHT) {
                    gravityOffset = width - newWidth;
                }
            }

            setRotation(90);
            setTranslationX((newWidth - height) * 0.5f + gravityOffset);
            setTranslationY(-(newWidth - height) * 0.5f);
            params.gravity = Gravity.NO_GRAVITY;
            setLayoutParams(params);
        } else {
            throw new UnsupportedOperationException("Parent layout should be instance of " + "FrameLayout.");
        }

        mSizeChanged = true;
        super.onMeasure(heightMeasureSpec, widthMeasureSpec);
    } else {
        int pageContentHeight = getPageContentHeight();
        if (heightMode == MeasureSpec.AT_MOST || pageContentHeight + 2 * mWrapPadding > height) {

            int newHeight = pageContentHeight + 2 * mWrapPadding;
            heightMeasureSpec = MeasureSpec.makeMeasureSpec(newHeight, heightMode);
        }

        // FIXME Supported only FrameLayout as parent
        if (!(getLayoutParams() instanceof FrameLayout.LayoutParams)) {
            throw new UnsupportedOperationException("Parent layout should be instance of " + "FrameLayout.");
        } else {
            if (!parentHasExactDimensions()) {
                throw new UnsupportedOperationException("Parent layout should have exact " + "dimensions.");
            }
        }

        mSizeChanged = true;
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
    }

    mViewPagerWidth = getMeasuredWidth();
    mViewPagerHeight = getMeasuredHeight();

    if (calculatePageLimitAndMargin()) {
        setOffscreenPageLimit(mConfig.pageLimit);
        setPageMargin(mConfig.pageMargin);
    }

    if (DEBUG) {
        Log.d(TAG, mConfig.toString());
    }
}

From source file:de.vanita5.twittnuker.fragment.support.AbsStatusesFragment.java

@Override
public void onStatusMenuClick(StatusViewHolder holder, View menuView, int position) {
    if (mPopupMenu != null) {
        mPopupMenu.dismiss();//  w  w w  . ja  va 2  s .co  m
    }
    final PopupMenu popupMenu = new PopupMenu(mAdapter.getContext(), menuView, Gravity.NO_GRAVITY,
            R.attr.actionOverflowMenuStyle, 0);
    popupMenu.inflate(R.menu.action_status);
    setMenuForStatus(mAdapter.getContext(), popupMenu.getMenu(), mAdapter.getStatus(position));
    popupMenu.show();
    mPopupMenu = popupMenu;
}

From source file:com.duy.pascal.ui.debug.activities.DebugActivity.java

@WorkerThread
private void showPopupAt(final LineNumber lineNumber, final String msg) {
    mHandler.post(new Runnable() {
        @Override// w ww .  ja v  a  2s .  co  m
        public void run() {
            if (isFinishing())
                return;
            //get relative position of expression at edittext
            Point position = mCodeView.getDebugPosition(lineNumber.getLine(), lineNumber.getColumn(),
                    Gravity.TOP);
            DLog.d(TAG, "generate: " + position);
            dismissPopup();
            //create new popup
            PopupWindow window = new PopupWindow(DebugActivity.this);
            LayoutInflater inflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
            View container = inflater.inflate(R.layout.popup_expr_result, null);
            container.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
                    View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
            int windowHeight = container.getMeasuredHeight();
            int windowWidth = container.getMeasuredWidth();

            window.setContentView(container);
            window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            window.setTouchable(true);
            window.setSplitTouchEnabled(true);
            window.setOutsideTouchable(true);

            window.showAtLocation(mCodeView, Gravity.NO_GRAVITY, position.x - windowWidth / 3,
                    position.y + toolbar.getHeight() - windowHeight);

            TextView txtResult = container.findViewById(R.id.txt_result);
            txtResult.setText(msg);
            AlphaAnimation alphaAnimation = new AlphaAnimation(1.0f, 0.5f);
            alphaAnimation.setDuration(1000);
            alphaAnimation.setRepeatMode(Animation.REVERSE);
            alphaAnimation.setRepeatCount(Animation.INFINITE);
            txtResult.startAnimation(alphaAnimation);
            DebugActivity.this.mPopupWindow = window;
        }
    });
}

From source file:co.lujun.popmenulayout.PopMenuLayout.java

private void expandMenu(int level1Index, int level2Index, int level3Index) {
    // Set menus data first and then show this menu
    mMenuShow[1] = true;//from   w w w. j  a  v  a  2s.com
    int[] location = new int[2];
    recyclerView.getLocationOnScreen(location);
    List<MenuBean> menus = mMenus.get(level1Index).getChild();
    popMenuView.setAnimStyle(mLevel2MenuAnimStyle);
    popMenuView.setMenus(menus);
    popMenuView.showAtLocation(recyclerView, Gravity.NO_GRAVITY,
            mWidth / mMenus.size() * level1Index + (mWidth / mMenus.size() - popMenuView.getWidth()) / 2,
            location[1] - (menus.size() <= mMaxMenuItemCount ? menus.size() : mMaxMenuItemCount)
                    * (int) mChildMenuItemHeight);
}

From source file:com.hippo.widget.slidingdrawerlayout.SlidingDrawerLayout.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  w w  w. j ava2  s  .c  om*/
        } 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);
}