Java Code Examples for android.view.Gravity#NO_GRAVITY

The following examples show how to use android.view.Gravity#NO_GRAVITY . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdvancedOptionsDialogFragment.java    From reflow-animator with Apache License 2.0 6 votes vote down vote up
@OnCheckedChanged({ R.id.target_align_start, R.id.target_align_center, R.id.target_align_end })
void onTargetAlignmentChanged(RadioButton button, boolean isChecked) {
    if (isChecked) {
        int alignment = Gravity.NO_GRAVITY;
        switch (button.getId()) {
            case R.id.target_align_start:
                alignment = Gravity.START;
                break;
            case R.id.target_align_center:
                alignment = Gravity.CENTER_HORIZONTAL;
                break;
            case R.id.target_align_end:
                alignment = Gravity.END;
                break;
        }
        onUpdateListener.updateTargetTextAlignment(alignment);
    }
}
 
Example 2
Source File: ReactBaseTextShadowNode.java    From react-native-GPay with MIT License 6 votes vote down vote up
@ReactProp(name = ViewProps.TEXT_ALIGN)
public void setTextAlign(@Nullable String textAlign) {
  if (textAlign == null || "auto".equals(textAlign)) {
    mTextAlign = Gravity.NO_GRAVITY;
  } else if ("left".equals(textAlign)) {
    mTextAlign = Gravity.LEFT;
  } else if ("right".equals(textAlign)) {
    mTextAlign = Gravity.RIGHT;
  } else if ("center".equals(textAlign)) {
    mTextAlign = Gravity.CENTER_HORIZONTAL;
  } else if ("justify".equals(textAlign)) {
    // Fallback gracefully for cross-platform compat instead of error
    mTextAlign = Gravity.LEFT;
  } else {
    throw new JSApplicationIllegalArgumentException("Invalid textAlign: " + textAlign);
  }
  markUpdated();
}
 
Example 3
Source File: FloatingNavigationView.java    From Floating-Navigation-View with Apache License 2.0 6 votes vote down vote up
private void attachNavigationView() {

        CoordinatorLayout.LayoutParams layoutParams = (CoordinatorLayout.LayoutParams) getLayoutParams();
        int gravity = Gravity.LEFT;
        if (layoutParams.getAnchorId() != View.NO_ID && layoutParams.anchorGravity != Gravity.NO_GRAVITY) {
            if (Gravity.isHorizontal(layoutParams.anchorGravity)) {
                gravity = layoutParams.anchorGravity;
            }
        } else if (layoutParams.gravity != Gravity.NO_GRAVITY) {
            if (Gravity.isHorizontal(layoutParams.gravity)) {
                gravity = layoutParams.gravity;
            }
        }

        // Gravity.START and Gravity.END don't work for views added in WindowManager with RTL.
        // We need to convert script specific gravity to absolute horizontal value
        // If horizontal direction is LTR, then START will set LEFT and END will set RIGHT.
        // If horizontal direction is RTL, then START will set RIGHT and END will set LEFT.
        gravity = Gravity.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this));

        mWindowManager.addView(mNavigationView, createLayoutParams(gravity));
    }
 
Example 4
Source File: ActionMenuView.java    From zen4android with MIT License 5 votes vote down vote up
@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;
        }
        return result;
    }
    return generateDefaultLayoutParams();
}
 
Example 5
Source File: BadgeShapeTest.java    From Badger with Apache License 2.0 5 votes vote down vote up
@Test
public void draw_scale() {
    region.set(16, 16, 48, 48);

    TestBadgeShape badgeShape = new TestBadgeShape(0.5f, 1, Gravity.NO_GRAVITY);
    badgeShape.draw(canvas, bounds, paint, 0);

    badgeShape.assertRegion(region);
}
 
Example 6
Source File: ActionMenuView.java    From zhangshangwuda with Apache License 2.0 5 votes vote down vote up
@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;
        }
        return result;
    }
    return generateDefaultLayoutParams();
}
 
Example 7
Source File: UiHandler.java    From bee with Apache License 2.0 5 votes vote down vote up
@Override public boolean onTouch(View v, MotionEvent event) {
  if (gestureDetector.onTouchEvent(event)) {
    return true;
  }
  switch (event.getAction()) {
    case MotionEvent.ACTION_DOWN:
      touchTime = SystemClock.uptimeMillis();
      touchPos.set(event.getX(), event.getY());
      break;
    case MotionEvent.ACTION_MOVE:
      int x = (int) event.getRawX();
      int y = (int) event.getRawY();

      if (!isMoveable(x, y)) {
        break;
      }
      if (!isInBoundaries(x, y)) {
        break;
      }

      FrameLayout.LayoutParams params = (FrameLayout.LayoutParams) v.getLayoutParams();
      params.topMargin = y - v.getHeight() / 2;
      params.leftMargin = x - v.getWidth() / 2;
      params.gravity = Gravity.NO_GRAVITY;
      v.setLayoutParams(params);
      break;
    default:
      break;
  }
  return SystemClock.uptimeMillis() - touchTime > 200;
}
 
Example 8
Source File: XToast.java    From XToast with Apache License 2.0 5 votes vote down vote up
public X setView(View view) {
    mRootView = view;

    ViewGroup.LayoutParams params = mRootView.getLayoutParams();
    if (params != null && mWindowParams.width == WindowManager.LayoutParams.WRAP_CONTENT &&
            mWindowParams.height == WindowManager.LayoutParams.WRAP_CONTENT) {
        // 如果当前 Dialog 的宽高设置了自适应,就以布局中设置的宽高为主
        setWidth(params.width);
        setHeight(params.height);
    }

    // 如果当前没有设置重心,就自动获取布局重心
    if (mWindowParams.gravity == Gravity.NO_GRAVITY) {
        if (params instanceof FrameLayout.LayoutParams) {
            setGravity(((FrameLayout.LayoutParams) params).gravity);
        } else if (params instanceof LinearLayout.LayoutParams) {
            setGravity(((LinearLayout.LayoutParams) params).gravity);
        } else {
            // 默认重心是居中
            setGravity(Gravity.CENTER);
        }
    }

    if (isShow()) {
        update();
    }
    return (X) this;
}
 
Example 9
Source File: ActionMenuView.java    From Libraries-for-Android-Developers with MIT License 5 votes vote down vote up
@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;
        }
        return result;
    }
    return generateDefaultLayoutParams();
}
 
Example 10
Source File: DrawerLayout.java    From Dashchan with Apache License 2.0 5 votes vote down vote up
@Override
protected void onRestoreInstanceState(Parcelable state) {
	if (!(state instanceof SavedState)) {
		super.onRestoreInstanceState(state);
		return;
	}

	final SavedState ss = (SavedState) state;
	super.onRestoreInstanceState(ss.getSuperState());

	if (ss.openDrawerGravity != Gravity.NO_GRAVITY) {
		final View toOpen = findDrawerWithGravity(ss.openDrawerGravity);
		if (toOpen != null) {
			openDrawer(toOpen);
		}
	}

	if (ss.lockModeLeft != LOCK_MODE_UNDEFINED) {
		setDrawerLockMode(ss.lockModeLeft, Gravity.LEFT);
	}
	if (ss.lockModeRight != LOCK_MODE_UNDEFINED) {
		setDrawerLockMode(ss.lockModeRight, Gravity.RIGHT);
	}
	if (ss.lockModeStart != LOCK_MODE_UNDEFINED) {
		setDrawerLockMode(ss.lockModeStart, Gravity.START);
	}
	if (ss.lockModeEnd != LOCK_MODE_UNDEFINED) {
		setDrawerLockMode(ss.lockModeEnd, Gravity.END);
	}
}
 
Example 11
Source File: SwipeLayout.java    From AndroidSwipeLayout with MIT License 5 votes vote down vote up
@Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
    if (child == null) return;
    int gravity = Gravity.NO_GRAVITY;
    try {
        gravity = (Integer) params.getClass().getField("gravity").get(params);
    } catch (Exception e) {
        e.printStackTrace();
    }

    if (gravity > 0) {
        gravity = GravityCompat.getAbsoluteGravity(gravity, ViewCompat.getLayoutDirection(this));

        if ((gravity & Gravity.LEFT) == Gravity.LEFT) {
            mDragEdges.put(DragEdge.Left, child);
        }
        if ((gravity & Gravity.RIGHT) == Gravity.RIGHT) {
            mDragEdges.put(DragEdge.Right, child);
        }
        if ((gravity & Gravity.TOP) == Gravity.TOP) {
            mDragEdges.put(DragEdge.Top, child);
        }
        if ((gravity & Gravity.BOTTOM) == Gravity.BOTTOM) {
            mDragEdges.put(DragEdge.Bottom, child);
        }
    } else {
        for (Map.Entry<DragEdge, View> entry : mDragEdges.entrySet()) {
            if (entry.getValue() == null) {
                //means used the drag_edge attr, the no gravity child should be use set
                mDragEdges.put(entry.getKey(), child);
                break;
            }
        }
    }
    if (child.getParent() == this) {
        return;
    }
    super.addView(child, index, params);
}
 
Example 12
Source File: FloatingActionButton.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onAttachedToLayoutParams(@NonNull CoordinatorLayout.LayoutParams lp) {
  if (lp.dodgeInsetEdges == Gravity.NO_GRAVITY) {
    // If the developer hasn't set dodgeInsetEdges, lets set it to BOTTOM so that
    // we dodge any Snackbars
    lp.dodgeInsetEdges = Gravity.BOTTOM;
  }
}
 
Example 13
Source File: BaseDialog.java    From AndroidProject with Apache License 2.0 4 votes vote down vote up
/**
 * 创建
 */
@SuppressLint("RtlHardcoded")
public BaseDialog create() {

    // 判断布局是否为空
    if (mContentView == null) {
        throw new IllegalArgumentException("are you ok?");
    }

    // 如果当前没有设置重心,就设置一个默认的重心
    if (mGravity == Gravity.NO_GRAVITY) {
        mGravity = Gravity.CENTER;
    }

    // 如果当前没有设置动画效果,就设置一个默认的动画效果
    if (mAnimations == AnimAction.NO_ANIM) {
        switch (mGravity) {
            case Gravity.TOP:
                mAnimations = AnimAction.TOP;
                break;
            case Gravity.BOTTOM:
                mAnimations = AnimAction.BOTTOM;
                break;
            case Gravity.LEFT:
                mAnimations = AnimAction.LEFT;
                break;
            case Gravity.RIGHT:
                mAnimations = AnimAction.RIGHT;
                break;
            default:
                mAnimations = AnimAction.DEFAULT;
                break;
        }
    }

    mDialog = createDialog(mContext, mThemeId);

    mDialog.setContentView(mContentView);
    mDialog.setCancelable(mCancelable);
    if (mCancelable) {
        mDialog.setCanceledOnTouchOutside(mCanceledOnTouchOutside);
    }

    // 设置参数
    Window window = mDialog.getWindow();
    if (window != null) {
        WindowManager.LayoutParams params = window.getAttributes();
        params.width = mWidth;
        params.height = mHeight;
        params.gravity = mGravity;
        params.windowAnimations = mAnimations;
        window.setAttributes(params);
        if (mBackgroundDimEnabled) {
            window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
            window.setDimAmount(mBackgroundDimAmount);
        } else {
            window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        }
    }

    if (mOnShowListeners != null) {
        mDialog.setOnShowListeners(mOnShowListeners);
    }

    if (mOnCancelListeners != null) {
        mDialog.setOnCancelListeners(mOnCancelListeners);
    }

    if (mOnDismissListeners != null) {
        mDialog.setOnDismissListeners(mOnDismissListeners);
    }

    if (mOnKeyListener != null) {
        mDialog.setOnKeyListener(mOnKeyListener);
    }

    for (int i = 0; mClickArray != null && i < mClickArray.size(); i++) {
        mContentView.findViewById(mClickArray.keyAt(i)).setOnClickListener(new ViewClickWrapper(mDialog, mClickArray.valueAt(i)));
    }

    Activity activity = getActivity();
    if (activity != null) {
        DialogLifecycle.with(activity, mDialog);
    }

    return mDialog;
}
 
Example 14
Source File: HeaderScrollingViewBehavior.java    From CoordinatorLayoutExample with Apache License 2.0 4 votes vote down vote up
private static int resolveGravity(int gravity) {
    return gravity == Gravity.NO_GRAVITY ? GravityCompat.START | Gravity.TOP : gravity;
}
 
Example 15
Source File: MarginDrawerLayout.java    From something.apk with MIT License 4 votes vote down vote up
boolean isContentView(View child) {
    return ((LayoutParams) child.getLayoutParams()).gravity == Gravity.NO_GRAVITY;
}
 
Example 16
Source File: LineDrawable.java    From ProjectX with Apache License 2.0 4 votes vote down vote up
public LineDrawable(int backgroundColor, int lineColor, float lineSize) {
    this(backgroundColor, lineColor, lineSize, Gravity.NO_GRAVITY);
}
 
Example 17
Source File: BottomDrawerLayout.java    From 920-text-editor-v2 with Apache License 2.0 4 votes vote down vote up
void layoutChildren(int left, int top, int right, int bottom,
                                  boolean forceLeftGravity) {
        final int count = getChildCount();

        final int parentLeft = getPaddingLeftWithForeground();
        final int parentRight = right - left - getPaddingRightWithForeground();

        final int parentTop = getPaddingTopWithForeground();
        final int parentBottom = bottom - top - getPaddingBottomWithForeground();
        int symbolHeight = 0;
        // 尽可能先找到Bottom View
        for (int i = count - 1; i >= 0; i--) {
            final View child = getChildAt(i);
            if (child.getVisibility() != GONE) {
                final LayoutParams lp = (LayoutParams) child.getLayoutParams();

                final int width = child.getMeasuredWidth();
                final int height = child.getMeasuredHeight();

                int childLeft;
                int childTop;

                int gravity = lp.gravity;
                if (gravity == -1) {
                    gravity = Gravity.NO_GRAVITY;
                }

                final int layoutDirection = ViewCompat.getLayoutDirection(this);
                final int absoluteGravity = Gravity.getAbsoluteGravity(gravity, layoutDirection);
                final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;

                switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
                    case Gravity.CENTER_HORIZONTAL:
                        childLeft = parentLeft + (parentRight - parentLeft - width) / 2 +
                        lp.leftMargin - lp.rightMargin;
                        break;
                    case Gravity.RIGHT:
                    case Gravity.END:
                        if (!forceLeftGravity) {
                            childLeft = parentRight - width - lp.rightMargin;
                            break;
                        }
                    case Gravity.LEFT:
                    case Gravity.START:
                    default:
                        childLeft = parentLeft + lp.leftMargin;
                }

                switch (verticalGravity) {
                    case Gravity.TOP:
                        childTop = parentTop + lp.topMargin;
                        break;
                    case Gravity.CENTER_VERTICAL:
                        childTop = parentTop + (parentBottom - parentTop - height) / 2 +
                        lp.topMargin - lp.bottomMargin;
                        break;
                    case Gravity.BOTTOM:
                        symbolHeight = ((ViewGroup)child).getChildCount() > 0 ? ((ViewGroup)child).getChildAt(0).getMeasuredHeight() : 0;
                        float offset = mSlideOffset == 0 ? (symbolHeight == 0 ? 0.3f : symbolHeight / (float)height) : mSlideOffset;
                        childTop = parentBottom - (int) (height * offset);
//                        childTop = parentBottom - height - lp.bottomMargin;
                        break;
                    default:
                        childTop = parentTop + lp.topMargin;
                }

                child.layout(childLeft, childTop, childLeft + width, childTop + height);
            }
        }

    }
 
Example 18
Source File: EBrowserWindow.java    From appcan-android with GNU Lesser General Public License v3.0 4 votes vote down vote up
private void hPopOverOpen(EBrwViewEntry entity) {
        if (checkPop(entity)) {
            return;
        }
        EBrowserView eView = new EBrowserView(mContext, entity.mType, this);
//		eView.setVisibility(INVISIBLE);
        eView.setName(entity.mViewName);
        eView.setRelativeUrl(entity.mRelativeUrl);
        eView.setDateType(entity.mDataType);
        LayoutParams newParm = new LayoutParams(entity.mWidth, entity.mHeight);
        newParm.gravity = Gravity.NO_GRAVITY;
        newParm.leftMargin = entity.mX;
        newParm.topMargin = entity.mY;
        newParm.bottomMargin = entity.mBottom;
        EBounceView bounceView = new EBounceView(mContext);
        EUtil.viewBaseSetting(bounceView);
        bounceView.setLayoutParams(newParm);
        bounceView.addView(eView);
        addView(bounceView);
        eView.setHWEnable(entity.mHardware);
        if (entity.checkFlag(EBrwViewEntry.F_FLAG_SHOULD_OP_SYS)) {
            eView.setShouldOpenInSystem(true);
        }
        if (!entity.hasExtraInfo) {
            if (entity.checkFlag(EBrwViewEntry.F_FLAG_OPAQUE)) {
                eView.setOpaque(true);
            } else {
                eView.setOpaque(false);
            }
        }
        if (entity.hasExtraInfo) {
            /** wanglei del 20151124*/
//            eView.setBrwViewBackground(entity.mOpaque, entity.mBgColor, "");
            /** wanglei add 20151124*/
            bounceView.setBounceViewBackground(entity.mOpaque, entity.mBgColor, "", eView);
        }
        /** wanglei add 20151124*/
        eView.setBackgroundColor(Color.TRANSPARENT);
        if (entity.checkFlag(EBrwViewEntry.F_FLAG_OAUTH)) {
            eView.setOAuth(true);
        }
        if (entity.checkFlag(EBrwViewEntry.F_FLAG_WEBAPP)) {
            eView.setWebApp(true);
        }
        eView.setQuery(entity.mQuery);
        eView.init();
        eView.setDownloadCallback(entity.mDownloadCallback);
        eView.setUserAgent(entity.mUserAgent);
        eView.setExeJS(entity.mExeJS);
        if (entity.mExeScale!=-1) eView.setInitialScale(entity.mExeScale);

        if (entity.checkFlag(EBrwViewEntry.F_FLAG_GESTURE)) {
            eView.setSupportZoom();
        }
        if (entity.mFontSize > 0) {
            eView.setDefaultFontSize(entity.mFontSize);
        }
        mPopTable.put(entity.mViewName, eView);
        if (checkFlag(EBrowserWindow.F_WINDOW_FLAG_OPPOP)) {
            mPreQueue.add(entity.mViewName);
        }
        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)) {
                    eView.needToEncrypt(eView, entity.mUrl, 0);
                } else {
                    eView.newLoadUrl(entity.mUrl);
                }
                break;
            case EBrwViewEntry.WINDOW_DATA_TYPE_DATA:
                eView.newLoadData(entity.mData);
                break;
            case EBrwViewEntry.WINDOW_DATA_TYPE_DATA_URL:
                String date1 = ACEDes.decrypt(entity.mUrl, mContext, false,
                        entity.mData);
                eView.loadDataWithBaseURL(entity.mUrl, date1,
                        EBrowserView.CONTENT_MIMETYPE_HTML,
                        EBrowserView.CONTENT_DEFAULT_CODE, entity.mUrl);
                break;
        }
    }
 
Example 19
Source File: SwipeLayout.java    From PocketEOS-Android with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * 判断child是不是ContentView
 *
 * @param view child
 * @return 判断是不是没有设置Gravity
 */
boolean isContentView(View view) {
    final LayoutParams lp = (LayoutParams) view.getLayoutParams();
    final int gravity = lp.gravity;
    return gravity == Gravity.NO_GRAVITY;
}
 
Example 20
Source File: CoordinatorLayout.java    From ticdesign with Apache License 2.0 2 votes vote down vote up
/**
 * 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.
 */
private static int resolveGravity(int gravity) {
    return gravity == Gravity.NO_GRAVITY ? GravityCompat.START | Gravity.TOP : gravity;
}