Java Code Examples for android.view.Gravity#START

The following examples show how to use android.view.Gravity#START . 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: AnimatedEditText.java    From AnimatedEditText with Apache License 2.0 6 votes vote down vote up
@Override
protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    if (!mAnimated) {
        return;
    }

    updateColorsForState();

    boolean rightAligned = (getGravity() & Gravity.RIGHT) == Gravity.RIGHT || (getGravity() & Gravity.END) == Gravity.END;
    boolean leftAligned = (getGravity() & Gravity.LEFT) == Gravity.LEFT || (getGravity() & Gravity.START) == Gravity.START;

    if (rightAligned) {
        drawGravityRight(canvas);
    } else if (leftAligned) {
        drawGravityLeft(canvas);
    } else {
        drawGravityCenterHorizontal(canvas);
    }

}
 
Example 2
Source File: DragGridView.java    From LiuAGeAndroid with MIT License 6 votes vote down vote up
/**
 * 创建窗口对象、添加我们要移动的View
 *
 * @param dragBitmap
 * @param x
 * @param y
 */
public void startDrag(Bitmap dragBitmap, int x, int y) {
    stopDrag();
    // 获取window界面的Params
    windowParams = new WindowManager.LayoutParams();
    // Gravity.TOP|Gravity.START;这个必须加
    windowParams.gravity = Gravity.TOP | Gravity.START;
    // 得到要移动的View左上角相对于屏幕的坐标
    windowParams.x = x - win_view_x;
    windowParams.y = y - win_view_y;
    // 设置拖拽item的宽和高
    windowParams.width = (int) (dragScale * dragBitmap.getWidth());   // 放大dragScale倍,可以设置拖动后的倍数
    windowParams.height = (int) (dragScale * dragBitmap.getHeight()); // 放大dragScale倍,可以设置拖动后的倍数
    this.windowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
            | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
    this.windowParams.format = PixelFormat.TRANSLUCENT;
    this.windowParams.windowAnimations = 0;
    ImageView iv = new ImageView(getContext());
    iv.setImageBitmap(dragBitmap);
    windowManager = (WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE);
    windowManager.addView(iv, windowParams);
    dragImageView = iv;
}
 
Example 3
Source File: SlideDistanceProvider.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private static Animator createTranslationDisappearAnimator(
    View sceneRoot, View view, @GravityFlag int slideEdge, @Px int slideDistance) {
  switch (slideEdge) {
    case Gravity.LEFT:
      return createTranslationXAnimator(view, 0, -slideDistance);
    case Gravity.TOP:
      return createTranslationYAnimator(view, 0, slideDistance);
    case Gravity.RIGHT:
      return createTranslationXAnimator(view, 0, slideDistance);
    case Gravity.BOTTOM:
      return createTranslationYAnimator(view, 0, -slideDistance);
    case Gravity.START:
      return createTranslationXAnimator(
          view, 0, isRtl(sceneRoot) ? -slideDistance : slideDistance);
    case Gravity.END:
      return createTranslationXAnimator(
          view, 0, isRtl(sceneRoot) ? slideDistance : -slideDistance);
    default:
      throw new IllegalArgumentException("Invalid slide direction: " + slideEdge);
  }
}
 
Example 4
Source File: SlideDistanceProvider.java    From material-components-android with Apache License 2.0 6 votes vote down vote up
private static Animator createTranslationAppearAnimator(
    View sceneRoot, View view, @GravityFlag int slideEdge, @Px int slideDistance) {
  switch (slideEdge) {
    case Gravity.LEFT:
      return createTranslationXAnimator(view, slideDistance, 0);
    case Gravity.TOP:
      return createTranslationYAnimator(view, -slideDistance, 0);
    case Gravity.RIGHT:
      return createTranslationXAnimator(view, -slideDistance, 0);
    case Gravity.BOTTOM:
      return createTranslationYAnimator(view, slideDistance, 0);
    case Gravity.START:
      return createTranslationXAnimator(
          view, isRtl(sceneRoot) ? slideDistance : -slideDistance, 0);
    case Gravity.END:
      return createTranslationXAnimator(
          view, isRtl(sceneRoot) ? -slideDistance : slideDistance, 0);
    default:
      throw new IllegalArgumentException("Invalid slide direction: " + slideEdge);
  }
}
 
Example 5
Source File: LinearLayout.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Describes how the child views are positioned. Defaults to GRAVITY_TOP. If
 * this layout has a VERTICAL orientation, this controls where all the child
 * views are placed if there is extra vertical space. If this layout has a
 * HORIZONTAL orientation, this controls the alignment of the children.
 *
 * @param gravity See {@link android.view.Gravity}
 *
 * @attr ref android.R.styleable#LinearLayout_gravity
 */
@android.view.RemotableViewMethod
public void setGravity(int gravity) {
    if (mGravity != gravity) {
        if ((gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) {
            gravity |= Gravity.START;
        }

        if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) {
            gravity |= Gravity.TOP;
        }

        mGravity = gravity;
        requestLayout();
    }
}
 
Example 6
Source File: CarlProgressbar.java    From YCProgress with Apache License 2.0 6 votes vote down vote up
private void initView(Context context) {
    mWindowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    mLayoutParams = new WindowManager.LayoutParams();
    mLayoutParams.gravity = Gravity.START | Gravity.TOP;
    mLayoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
    mLayoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
    mLayoutParams.format = PixelFormat.TRANSLUCENT;
    mLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
            | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        mLayoutParams.type = WindowManager.LayoutParams.TYPE_APPLICATION;
    } else {
        mLayoutParams.type = WindowManager.LayoutParams.TYPE_TOAST;
    }
}
 
Example 7
Source File: GravitySnapHelper.java    From GravitySnapHelper with Apache License 2.0 5 votes vote down vote up
@Nullable
public View findSnapView(@NonNull RecyclerView.LayoutManager lm, boolean checkEdgeOfList) {
    View snapView = null;

    switch (gravity) {
        case Gravity.START:
            snapView = findView(lm, getHorizontalHelper(lm), Gravity.START, checkEdgeOfList);
            break;
        case Gravity.END:
            snapView = findView(lm, getHorizontalHelper(lm), Gravity.END, checkEdgeOfList);
            break;
        case Gravity.TOP:
            snapView = findView(lm, getVerticalHelper(lm), Gravity.START, checkEdgeOfList);
            break;
        case Gravity.BOTTOM:
            snapView = findView(lm, getVerticalHelper(lm), Gravity.END, checkEdgeOfList);
            break;
        case Gravity.CENTER:
            if (lm.canScrollHorizontally()) {
                snapView = findView(lm, getHorizontalHelper(lm), Gravity.CENTER,
                        checkEdgeOfList);
            } else {
                snapView = findView(lm, getVerticalHelper(lm), Gravity.CENTER,
                        checkEdgeOfList);
            }
            break;
    }
    if (snapView != null) {
        nextSnapPosition = recyclerView.getChildAdapterPosition(snapView);
    } else {
        nextSnapPosition = RecyclerView.NO_POSITION;
    }
    return snapView;
}
 
Example 8
Source File: SimpleTooltip.java    From SlickForm with MIT License 5 votes vote down vote up
private PointF calculePopupLocation() {
    PointF location = new PointF();

    final RectF anchorRect = SimpleTooltipUtils.calculeRectInWindow(mAnchorView);
    final PointF anchorCenter = new PointF(anchorRect.centerX(), anchorRect.centerY());

    switch (mGravity) {
        case Gravity.START:
            location.x = anchorRect.left - mPopupWindow.getContentView().getWidth() - mMargin;
            location.y = anchorCenter.y - mPopupWindow.getContentView().getHeight() / 2f;
            break;
        case Gravity.END:
            location.x = anchorRect.right + mMargin;
            location.y = anchorCenter.y - mPopupWindow.getContentView().getHeight() / 2f;
            break;
        case Gravity.TOP:
            location.x = anchorCenter.x - mPopupWindow.getContentView().getWidth() / 2f;
            location.y = anchorRect.top - mPopupWindow.getContentView().getHeight() - mMargin;
            break;
        case Gravity.BOTTOM:
            location.x = anchorCenter.x - mPopupWindow.getContentView().getWidth() / 2f;
            location.y = anchorRect.bottom + mMargin;
            break;
        default:
            throw new IllegalArgumentException("Gravity must have be START, END, TOP or BOTTOM.");
    }

    return location;
}
 
Example 9
Source File: TopicListFragment.java    From NGA-CLIENT-VER-OPEN-SOURCE with GNU General Public License v2.0 5 votes vote down vote up
private void updateFloatingMenu() {
    if (mConfig.isLeftHandMode()) {
        CoordinatorLayout.LayoutParams lp = (CoordinatorLayout.LayoutParams) mFam.getLayoutParams();
        lp.gravity = Gravity.START | Gravity.BOTTOM;
        mFam.setExpandDirection(FloatingActionsMenu.EXPAND_UP, FloatingActionsMenu.LABELS_ON_RIGHT_SIDE);
        mFam.setLayoutParams(lp);
    }
}
 
Example 10
Source File: SidePropagation.java    From Transitions-Everywhere with Apache License 2.0 5 votes vote down vote up
@SuppressLint("RtlHardcoded")
private int getMaxDistance(@NonNull ViewGroup sceneRoot) {
    switch (mSide) {
        case Gravity.LEFT:
        case Gravity.RIGHT:
        case Gravity.START:
        case Gravity.END:
            return sceneRoot.getWidth();
        default:
            return sceneRoot.getHeight();
    }
}
 
Example 11
Source File: Spinner.java    From material with Apache License 2.0 5 votes vote down vote up
/**
 * Describes how the selected item view is positioned.
 *
 * @param gravity See {@link Gravity}
 *
 * @attr ref android.R.styleable#Spinner_gravity
 */
public void setGravity(int gravity) {
    if (mGravity != gravity) {
        if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == 0)
            gravity |= Gravity.START;
        mGravity = gravity;
        requestLayout();
    }
}
 
Example 12
Source File: PopupIndicator.java    From AndroidSweetBehavior with Apache License 2.0 5 votes vote down vote up
private WindowManager.LayoutParams createPopupLayout(IBinder token) {
    WindowManager.LayoutParams p = new WindowManager.LayoutParams();
    p.gravity = Gravity.START | Gravity.TOP;
    p.width = ViewGroup.LayoutParams.MATCH_PARENT;
    p.height = ViewGroup.LayoutParams.MATCH_PARENT;
    p.format = PixelFormat.TRANSLUCENT;
    p.flags = computeFlags(p.flags);
    p.type = WindowManager.LayoutParams.TYPE_APPLICATION_PANEL;
    p.token = token;
    p.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN;
    return p;
}
 
Example 13
Source File: AboutPage.java    From GotoSleep with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Add a new group that will display a header in this AboutPage
 * <p>
 * A header will be displayed in the order it was added. For e.g:
 * <p>
 * <code>
 * new AboutPage(this)
 * .addItem(firstItem)
 * .addGroup("Header")
 * .addItem(secondItem)
 * .create();
 * </code>
 * <p>
 * Will display the following
 * [First item]
 * [Header]
 * [Second item]
 *
 * @param name the title for this group
 * @return this AboutPage instance for builder pattern support
 */
public AboutPage addGroup(String name) {

    TextView textView = new TextView(mContext);
    textView.setText(name);
    TextViewCompat.setTextAppearance(textView, R.style.about_groupTextAppearance);
    LinearLayout.LayoutParams textParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);

    if (mCustomFont != null) {
        textView.setTypeface(mCustomFont);
    }

    int padding = mContext.getResources().getDimensionPixelSize(R.dimen.about_group_text_padding);
    textView.setPadding(padding, padding, padding, padding);


    if (mIsRTL) {
        textView.setGravity(Gravity.END | Gravity.CENTER_VERTICAL);
        textParams.gravity = Gravity.END | Gravity.CENTER_VERTICAL;
    } else {
        textView.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
        textParams.gravity = Gravity.START | Gravity.CENTER_VERTICAL;
    }
    textView.setLayoutParams(textParams);

    ((LinearLayout) mView.findViewById(R.id.about_providers)).addView(textView);
    return this;
}
 
Example 14
Source File: TouchInterceptor.java    From GravityBox with Apache License 2.0 5 votes vote down vote up
private void startDragging(Bitmap bm, int x, int y) {
      stopDragging();

      mWindowParams = new WindowManager.LayoutParams();
      mWindowParams.gravity = Gravity.TOP | Gravity.START;
      mWindowParams.x = x;
      mWindowParams.y = y - mDragPoint + mCoordOffset;

      mWindowParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
      mWindowParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
      mWindowParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
              | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE
              | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
              | WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
              | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
      mWindowParams.format = PixelFormat.TRANSLUCENT;
      mWindowParams.windowAnimations = 0;

      Context context = getContext();
      ImageView v = new ImageView(context);
      int backGroundColor = context.getResources().getColor(R.color.dragndrop_background);
v.setAlpha((float) 0.7);
      v.setBackgroundColor(backGroundColor);
      v.setImageBitmap(bm);
      mDragBitmap = bm;

      mWindowManager = (WindowManager) context.getSystemService("window");
      mWindowManager.addView(v, mWindowParams);
      mDragView = v;
  }
 
Example 15
Source File: RelativeLayout.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
/**
 * Describes how the child views are positioned. Defaults to
 * <code>Gravity.START | Gravity.TOP</code>.
 *
 * <p>Note that since RelativeLayout considers the positioning of each child
 * relative to one another to be significant, setting gravity will affect
 * the positioning of all children as a single unit within the parent.
 * This happens after children have been relatively positioned.</p>
 *
 * @param gravity See {@link android.view.Gravity}
 *
 * @see #setHorizontalGravity(int)
 * @see #setVerticalGravity(int)
 *
 * @attr ref android.R.styleable#RelativeLayout_gravity
 */
@android.view.RemotableViewMethod
public void setGravity(int gravity) {
    if (mGravity != gravity) {
        if ((gravity & Gravity.RELATIVE_HORIZONTAL_GRAVITY_MASK) == 0) {
            gravity |= Gravity.START;
        }

        if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == 0) {
            gravity |= Gravity.TOP;
        }

        mGravity = gravity;
        requestLayout();
    }
}
 
Example 16
Source File: KcaMapHpPopupService.java    From kcanotify_h5-master with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    active = true;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
            && !Settings.canDrawOverlays(getApplicationContext())) {
        // Can not draw overlays: pass
        stopSelf();
    } else {
        broadcaster = LocalBroadcastManager.getInstance(this);
        dbHelper = new KcaDBHelper(getApplicationContext(), null, KCANOTIFY_DB_VERSION);
        data_receiver = new BroadcastReceiver() {
            @Override
            public void onReceive(Context context, Intent intent) {
                //String s = intent.getStringExtra(KCA_MSG_DATA);
                String s = dbHelper.getValue(DB_KEY_BATTLEINFO);
                broadcaster.sendBroadcast(new Intent(KCA_MSG_BATTLE_VIEW_REFRESH));
                Log.e("KCA", "KCA_MSG_BATTLE_INFO Received: \n".concat(s));
            }
        };

        LocalBroadcastManager.getInstance(this).registerReceiver((data_receiver), new IntentFilter(KCA_MSG_BATTLE_INFO));

        LayoutInflater mInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        notificationManager = NotificationManagerCompat.from(getApplicationContext());
        mView = mInflater.inflate(R.layout.view_map_hp, null);
        mView.setOnTouchListener(mViewTouchListener);
        ((TextView) mView.findViewById(R.id.view_hp_title)).setText(getStringWithLocale(R.string.viewmenu_maphp_title));

        mView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        popupWidth = mView.getMeasuredWidth();
        popupHeight = mView.getMeasuredHeight();

        hp_info = (TextView) mView.findViewById(R.id.hp_info);

        mParams = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                getWindowLayoutType(),
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSLUCENT);

        mParams.gravity = Gravity.TOP | Gravity.START;
        Display display = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        screenWidth = size.x;
        screenHeight = size.y;
        Log.e("KCA", "w/h: " + String.valueOf(screenWidth) + " " + String.valueOf(screenHeight));

        mParams.x = (screenWidth - popupWidth) / 2;
        mParams.y = (screenHeight - popupHeight) / 2;
        mManager = (WindowManager) getSystemService(WINDOW_SERVICE);
        mManager.addView(mView, mParams);
    }
}
 
Example 17
Source File: FabToolbar.java    From fab-toolbar with MIT License 4 votes vote down vote up
private int getGravity(int gravityEnum) {
	return (gravityEnum == 0 ? Gravity.START : gravityEnum == 1 ? Gravity.CENTER_HORIZONTAL : Gravity.END)
			| Gravity.CENTER_VERTICAL;
}
 
Example 18
Source File: KcaFleetCheckPopupService.java    From kcanotify with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    active = true;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M
            && !Settings.canDrawOverlays(getApplicationContext())) {
        // Can not draw overlays: pass
        stopSelf();
    } else {
        dbHelper = new KcaDBHelper(getApplicationContext(), null, KCANOTIFY_DB_VERSION);
        deckInfoCalc = new KcaDeckInfo(getApplicationContext(), getBaseContext());

        contextWithLocale = getContextWithLocale(getApplicationContext(), getBaseContext());

        mInflater = LayoutInflater.from(contextWithLocale);
        notificationManager = NotificationManagerCompat.from(getApplicationContext());
        mView = mInflater.inflate(R.layout.view_fleet_check, null);
        mView.setOnTouchListener(mViewTouchListener);
        mView.findViewById(R.id.view_fchk_head).setOnTouchListener(mViewTouchListener);
        ((TextView) mView.findViewById(R.id.view_fchk_title)).setText(getStringWithLocale(R.string.fleetcheckview_title));

        for (int fchk_id: FCHK_BTN_LIST) {
            mView.findViewById(fchk_id).setOnTouchListener(mViewTouchListener);
        }
        for (int fleet_id: FCHK_FLEET_LIST) {
            mView.findViewById(fleet_id).setOnTouchListener(mViewTouchListener);
        }

        mView.measure(View.MeasureSpec.UNSPECIFIED, View.MeasureSpec.UNSPECIFIED);
        popupWidth = mView.getMeasuredWidth();
        popupHeight = mView.getMeasuredHeight();

        fchk_info = mView.findViewById(R.id.fchk_value);

        mParams = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                getWindowLayoutType(),
                WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.TRANSLUCENT);

        mParams.gravity = Gravity.TOP | Gravity.START;
        Display display = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
        Point size = new Point();
        display.getSize(size);
        screenWidth = size.x;
        screenHeight = size.y;
        Log.e("KCA", "w/h: " + String.valueOf(screenWidth) + " " + String.valueOf(screenHeight));

        mParams.x = (screenWidth - popupWidth) / 2;
        mParams.y = (screenHeight - popupHeight) / 2;
        mManager = (WindowManager) getSystemService(WINDOW_SERVICE);
        mManager.addView(mView, mParams);
    }
}
 
Example 19
Source File: QBadgeView.java    From BottomNavigationBar with Apache License 2.0 4 votes vote down vote up
private void findBadgeCenter() {
    float rectWidth = mBadgeTextRect.height() > mBadgeTextRect.width() ?
            mBadgeTextRect.height() : mBadgeTextRect.width();
    switch (mBadgeGravity) {
        case Gravity.START | Gravity.TOP:
            mBadgeCenter.x = mGravityOffsetX + mBadgePadding + rectWidth / 2f;
            mBadgeCenter.y = mGravityOffsetY + mBadgePadding + mBadgeTextRect.height() / 2f;
            break;
        case Gravity.START | Gravity.BOTTOM:
            mBadgeCenter.x = mGravityOffsetX + mBadgePadding + rectWidth / 2f;
            mBadgeCenter.y = mHeight - (mGravityOffsetY + mBadgePadding + mBadgeTextRect.height() / 2f);
            break;
        case Gravity.END | Gravity.TOP:
            mBadgeCenter.x = mWidth - (mGravityOffsetX + mBadgePadding + rectWidth / 2f);
            mBadgeCenter.y = mGravityOffsetY + mBadgePadding + mBadgeTextRect.height() / 2f;
            break;
        case Gravity.END | Gravity.BOTTOM:
            mBadgeCenter.x = mWidth - (mGravityOffsetX + mBadgePadding + rectWidth / 2f);
            mBadgeCenter.y = mHeight - (mGravityOffsetY + mBadgePadding + mBadgeTextRect.height() / 2f);
            break;
        case Gravity.CENTER:
            mBadgeCenter.x = mWidth / 2f;
            mBadgeCenter.y = mHeight / 2f;
            break;
        case Gravity.CENTER | Gravity.TOP:
            mBadgeCenter.x = mWidth / 2f;
            mBadgeCenter.y = mGravityOffsetY + mBadgePadding + mBadgeTextRect.height() / 2f;
            break;
        case Gravity.CENTER | Gravity.BOTTOM:
            mBadgeCenter.x = mWidth / 2f;
            mBadgeCenter.y = mHeight - (mGravityOffsetY + mBadgePadding + mBadgeTextRect.height() / 2f);
            break;
        case Gravity.CENTER | Gravity.START:
            mBadgeCenter.x = mGravityOffsetX + mBadgePadding + rectWidth / 2f;
            mBadgeCenter.y = mHeight / 2f;
            break;
        case Gravity.CENTER | Gravity.END:
            mBadgeCenter.x = mWidth - (mGravityOffsetX + mBadgePadding + rectWidth / 2f);
            mBadgeCenter.y = mHeight / 2f;
            break;
    }
    initRowBadgeCenter();
}
 
Example 20
Source File: ShowcaseViewBuilder.java    From ShowcaseView with Apache License 2.0 4 votes vote down vote up
private void addCustomView(Canvas canvas) {
    if (mCustomView.size() != 0) {
        for (int i = 0; i < mCustomView.size(); i++) {
            float cy = mCustomView.get(i).getMeasuredHeight() / 2, cx = mCustomView.get(i).getMeasuredWidth() / 2;
            float diffY, diffX;
            float marginTop = mCustomViewTopMargins.get(i);
            float marginLeft = mCustomViewLeftMargins.get(i);
            float marginRight = mCustomViewRightMargins.get(i);
            float marginBottom = mCustomViewBottomMargins.get(i);
            mTargetViewGlobalRect = new Rect();
            mTargetView.getGlobalVisibleRect(mTargetViewGlobalRect);
            View view = mCustomView.get(i);
            switch (mCustomViewGravity.get(i)) {
                case Gravity.START:
                case Gravity.LEFT:
                    diffY = mCenterY - cy;
                    diffX = mCenterX - cx;
                    if (diffX < 0) {
                        view.layout(0, 0, (int) (mCenterX - view.getMeasuredWidth() - 2 * marginRight),
                                (int) (mCustomView.get(i).getMeasuredHeight() + 2 * (diffY + marginTop)));
                    } else {
                        view.layout((int) diffX, 0, (int) (view.getMeasuredWidth() - diffX - 2 * marginRight),
                                (int) (mCustomView.get(i).getMeasuredHeight() + 2 * (diffY + marginTop)));
                    }
                    break;

                case Gravity.TOP:
                    diffY = mCenterY - cy - 2 * mTargetView.getMeasuredHeight();
                    view.layout((int) (-marginLeft), 0, (int) (view.getMeasuredWidth() + marginLeft),
                            (int) (mCustomView.get(i).getMeasuredHeight() + 2 * (diffY + marginTop)));
                    break;

                case Gravity.END:
                case Gravity.RIGHT:
                    diffY = mCenterY - cy;
                    view.layout(-2 * mTargetViewGlobalRect.right, 0,
                            (int) (view.getMeasuredWidth() + 4 * marginLeft), (int) (mCustomView.get(i).getMeasuredHeight() + 2 * (diffY + marginTop)));
                    break;

                case Gravity.BOTTOM:
                    diffY = mCenterY - cy + 2 * mTargetView.getMeasuredHeight();
                    view.layout((int) (-marginLeft), 0, (int) (view.getMeasuredWidth() + marginLeft),
                            (int) (mCustomView.get(i).getMeasuredHeight() + 2 * (diffY + marginTop)));
                    break;

                default:
                    mCustomView.get(i).layout(0, 0, mCustomView.get(i).getMeasuredWidth(), mCustomView.get(i).getMeasuredHeight());
            }
            mCustomView.get(i).draw(canvas);
        }
    } else {
        Log.d(TAG, "No Custom View defined");
    }
}