Java Code Examples for android.view.Gravity#FILL_VERTICAL

The following examples show how to use android.view.Gravity#FILL_VERTICAL . 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: ViewHelper.java    From tns-core-modules-widgets with Apache License 2.0 6 votes vote down vote up
public static String getVerticalAlignment(android.view.View view) {
    ViewGroup.LayoutParams params = view.getLayoutParams();
    if (params instanceof FrameLayout.LayoutParams) {
        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) params;
        if (Gravity.isHorizontal(lp.gravity)) {
            switch (lp.gravity & Gravity.VERTICAL_GRAVITY_MASK) {
                case Gravity.TOP:
                    return "top";
                case Gravity.CENTER:
                    return "center";
                case Gravity.BOTTOM:
                    return "bottom";
                case Gravity.FILL_VERTICAL:
                    return "stretch";

            }
        }
    }

    return "stretch";
}
 
Example 2
Source File: ToastUtils.java    From AndroidUtilCode with Apache License 2.0 6 votes vote down vote up
private void setToastParams() {
    mParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
    mParams.width = WindowManager.LayoutParams.WRAP_CONTENT;
    mParams.format = PixelFormat.TRANSLUCENT;
    mParams.windowAnimations = android.R.style.Animation_Toast;
    mParams.setTitle("ToastWithoutNotification");
    mParams.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
            | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
            | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
    mParams.packageName = Utils.getApp().getPackageName();

    mParams.gravity = mToast.getGravity();
    if ((mParams.gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) {
        mParams.horizontalWeight = 1.0f;
    }
    if ((mParams.gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) {
        mParams.verticalWeight = 1.0f;
    }

    mParams.x = mToast.getXOffset();
    mParams.y = mToast.getYOffset();
    mParams.horizontalMargin = mToast.getHorizontalMargin();
    mParams.verticalMargin = mToast.getVerticalMargin();
}
 
Example 3
Source File: ChromeFullscreenManager.java    From delion with Apache License 2.0 6 votes vote down vote up
private boolean shouldShowAndroidControls() {
    if (mTopControlsAndroidViewHidden) return false;

    boolean showControls = getControlOffset() == 0;
    ContentViewCore contentViewCore = getActiveContentViewCore();
    if (contentViewCore == null) return showControls;
    ViewGroup contentView = contentViewCore.getContainerView();

    for (int i = 0; i < contentView.getChildCount(); i++) {
        View child = contentView.getChildAt(i);
        if (!(child.getLayoutParams() instanceof FrameLayout.LayoutParams)) continue;

        FrameLayout.LayoutParams layoutParams =
                (FrameLayout.LayoutParams) child.getLayoutParams();
        if (Gravity.TOP == (layoutParams.gravity & Gravity.FILL_VERTICAL)) {
            showControls = true;
            break;
        }
    }

    showControls |= !mPersistentControlTokens.isEmpty();

    return showControls;
}
 
Example 4
Source File: ChromeFullscreenManager.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private boolean shouldShowAndroidControls() {
    if (mBrowserControlsAndroidViewHidden) return false;

    boolean showControls = !drawControlsAsTexture();
    ContentViewCore contentViewCore = getActiveContentViewCore();
    if (contentViewCore == null) return showControls;
    ViewGroup contentView = contentViewCore.getContainerView();

    for (int i = 0; i < contentView.getChildCount(); i++) {
        View child = contentView.getChildAt(i);
        if (!(child.getLayoutParams() instanceof FrameLayout.LayoutParams)) continue;

        FrameLayout.LayoutParams layoutParams =
                (FrameLayout.LayoutParams) child.getLayoutParams();
        if (Gravity.TOP == (layoutParams.gravity & Gravity.FILL_VERTICAL)) {
            showControls = true;
            break;
        }
    }

    return showControls;
}
 
Example 5
Source File: TextViewParser.java    From pandora with Apache License 2.0 5 votes vote down vote up
private static String gravityToStr(int gravity) {
    switch (gravity) {
        case Gravity.NO_GRAVITY:
            return "NO_GRAVITY";
        case Gravity.LEFT:
            return "LEFT";
        case Gravity.TOP:
            return "TOP";
        case Gravity.RIGHT:
            return "RIGHT";
        case Gravity.BOTTOM:
            return "BOTTOM";
        case Gravity.CENTER:
            return "CENTER";
        case Gravity.CENTER_HORIZONTAL:
            return "CENTER_HORIZONTAL";
        case Gravity.CENTER_VERTICAL:
            return "CENTER_VERTICAL";
        case Gravity.START:
            return "START";
        case Gravity.END:
            return "END";
        case Gravity.CLIP_HORIZONTAL:
            return "CLIP_HORIZONTAL";
        case Gravity.CLIP_VERTICAL:
            return "CLIP_VERTICAL";
        case Gravity.FILL:
            return "FILL";
        case Gravity.FILL_HORIZONTAL:
            return "FILL_HORIZONTAL";
        case Gravity.FILL_VERTICAL:
            return "FILL_VERTICAL";
        default:
            return "OTHER";
    }
}
 
Example 6
Source File: FullscreenPopupWindow.java    From Noyze with Apache License 2.0 5 votes vote down vote up
@Override
public WindowManager.LayoutParams getWindowParams() {
    int flags = (WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE		|
                 WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE      |
                 WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED	);
    WindowManager.LayoutParams WPARAMS = new WindowManager.LayoutParams(
            1, WindowManager.LayoutParams.MATCH_PARENT, 0, 0,
            WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, flags, PixelFormat.TRANSPARENT);
    WPARAMS.packageName = getContext().getPackageName();
    WPARAMS.setTitle(getName());
    WPARAMS.gravity = (Gravity.FILL_VERTICAL | Gravity.START);
    WPARAMS.screenBrightness = WPARAMS.buttonBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
    return WPARAMS;
}
 
Example 7
Source File: ViewHelper.java    From tns-core-modules-widgets with Apache License 2.0 5 votes vote down vote up
public static void setVerticalAlignment(android.view.View view, String value) {
    ViewGroup.LayoutParams params = view.getLayoutParams();
    // Initialize if empty.
    if (params == null) {
        params = new CommonLayoutParams();
    }

    // Set margins only if params are of the correct type.
    if (params instanceof FrameLayout.LayoutParams) {
        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) params;
        switch (value) {
            case "top":
                lp.gravity = Gravity.TOP | (lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK);
                break;
            case "center":
            case "middle":
                lp.gravity = Gravity.CENTER_VERTICAL | (lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK);
                break;
            case "bottom":
                lp.gravity = Gravity.BOTTOM | (lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK);
                break;
            case "stretch":
                lp.gravity = Gravity.FILL_VERTICAL | (lp.gravity & Gravity.HORIZONTAL_GRAVITY_MASK);
                break;
        }
        view.setLayoutParams(params);
    }
}
 
Example 8
Source File: ViewHelper.java    From tns-core-modules-widgets with Apache License 2.0 5 votes vote down vote up
public static void setHeightPercent(android.view.View view, float value) {
    ViewGroup.LayoutParams params = view.getLayoutParams();
    if (params == null) {
        params = new CommonLayoutParams();
    }

    if (params instanceof CommonLayoutParams) {
        CommonLayoutParams lp = (CommonLayoutParams) params;
        lp.heightPercent = value;
        lp.height = (lp.gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL ? ViewGroup.LayoutParams.MATCH_PARENT : ViewGroup.LayoutParams.WRAP_CONTENT;
        view.setLayoutParams(params);
    }
}
 
Example 9
Source File: Mixture.java    From frenchtoast with Apache License 2.0 5 votes vote down vote up
@MainThread public void show() {
  assertMainThread();
  View view = toast.getView();
  if (view == null) {
    throw new IllegalStateException("Can't show a Toast with no View.");
  }

  Context context = toast.getView().getContext();

  WindowManager windowManager = (WindowManager) context.getSystemService(WINDOW_SERVICE);

  // We can resolve the Gravity here by using the Locale for getting
  // the layout direction
  Configuration config = view.getContext().getResources().getConfiguration();
  int gravity = toast.getGravity();
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
    gravity = Gravity.getAbsoluteGravity(gravity, config.getLayoutDirection());
  }
  params.gravity = gravity;
  if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) {
    params.horizontalWeight = 1.0f;
  }
  if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) {
    params.verticalWeight = 1.0f;
  }
  params.x = toast.getXOffset();
  params.y = toast.getYOffset();
  params.verticalMargin = toast.getVerticalMargin();
  params.horizontalMargin = toast.getHorizontalMargin();
  params.packageName = context.getPackageName();
  if (view.getParent() != null) {
    windowManager.removeView(view);
  }
  windowManager.addView(view, params);
  trySendAccessibilityEvent(view);
}
 
Example 10
Source File: LayerDrawable.java    From Carbon with Apache License 2.0 5 votes vote down vote up
/**
 * Resolves layer gravity given explicit gravity and dimensions.
 * <p/>
 * If the client hasn't specified a gravity but has specified an explicit dimension, defaults to
 * START or TOP. Otherwise, defaults to FILL to preserve legacy behavior.
 *
 * @param gravity layer gravity
 * @param width   width of the layer if set, -1 otherwise
 * @param height  height of the layer if set, -1 otherwise
 * @return the default gravity for the layer
 */
private static int resolveGravity(int gravity, int width, int height,
                                  int intrinsicWidth, int intrinsicHeight) {
    if (!Gravity.isHorizontal(gravity)) {
        if (width < 0) {
            gravity |= Gravity.FILL_HORIZONTAL;
        } else {
            gravity |= Gravity.START;
        }
    }

    if (!Gravity.isVertical(gravity)) {
        if (height < 0) {
            gravity |= Gravity.FILL_VERTICAL;
        } else {
            gravity |= Gravity.TOP;
        }
    }

    // If a dimension if not specified, either implicitly or explicitly,
    // force FILL for that dimension's gravity. This ensures that colors
    // are handled correctly and ensures backward compatibility.
    if (width < 0 && intrinsicWidth < 0) {
        gravity |= Gravity.FILL_HORIZONTAL;
    }

    if (height < 0 && intrinsicHeight < 0) {
        gravity |= Gravity.FILL_VERTICAL;
    }

    return gravity;
}
 
Example 11
Source File: ChromeFullscreenManager.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void applyTranslationToTopChildViews(ViewGroup contentView, float translation) {
    for (int i = 0; i < contentView.getChildCount(); i++) {
        View child = contentView.getChildAt(i);
        if (!(child.getLayoutParams() instanceof FrameLayout.LayoutParams)) continue;

        FrameLayout.LayoutParams layoutParams =
                (FrameLayout.LayoutParams) child.getLayoutParams();
        if (Gravity.TOP == (layoutParams.gravity & Gravity.FILL_VERTICAL)) {
            child.setTranslationY(translation);
            TraceEvent.instant("FullscreenManager:child.setTranslationY()");
        }
    }
}
 
Example 12
Source File: ChromeFullscreenManager.java    From delion with Apache License 2.0 5 votes vote down vote up
private void applyTranslationToTopChildViews(ViewGroup contentView, float translation) {
    for (int i = 0; i < contentView.getChildCount(); i++) {
        View child = contentView.getChildAt(i);
        if (!(child.getLayoutParams() instanceof FrameLayout.LayoutParams)) continue;

        FrameLayout.LayoutParams layoutParams =
                (FrameLayout.LayoutParams) child.getLayoutParams();
        if (Gravity.TOP == (layoutParams.gravity & Gravity.FILL_VERTICAL)) {
            child.setTranslationY(translation);
            TraceEvent.instant("FullscreenManager:child.setTranslationY()");
        }
    }
}
 
Example 13
Source File: ChromeFullscreenManager.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void applyTranslationToTopChildViews(ViewGroup contentView, float translation) {
    for (int i = 0; i < contentView.getChildCount(); i++) {
        View child = contentView.getChildAt(i);
        if (!(child.getLayoutParams() instanceof FrameLayout.LayoutParams)) continue;

        FrameLayout.LayoutParams layoutParams =
                (FrameLayout.LayoutParams) child.getLayoutParams();
        if (Gravity.TOP == (layoutParams.gravity & Gravity.FILL_VERTICAL)) {
            child.setTranslationY(translation);
            TraceEvent.instant("FullscreenManager:child.setTranslationY()");
        }
    }
}
 
Example 14
Source File: SweetToast.java    From SweetTips with Apache License 2.0 4 votes vote down vote up
/**
     * 初始化
     * @param sweetToast
     * @param duration  自定义显示时间
     */
    private static void initConfiguration(SweetToast sweetToast,int duration){
        try {
            if(duration < 0){
                throw new RuntimeException("显示时长必须>=0!");
            }
            //1:初始化mWindowManager
            sweetToast.mWindowManager = (WindowManager) sweetToast.getContentView().getContext().getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
            //2:初始化mConfiguration
            SweetToastConfiguration mConfiguration = new SweetToastConfiguration();
            mConfiguration.setDuration(duration);
            WindowManager.LayoutParams params = new WindowManager.LayoutParams();
            final Configuration config = sweetToast.getContentView().getContext().getResources().getConfiguration();
            final int gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
            params.gravity = gravity;
            if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) {
                params.horizontalWeight = 1.0f;
            }
            if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) {
                params.verticalWeight = 1.0f;
            }
            params.x = 0;
            params.y = sweetToast.getContentView().getContext().getResources().getDimensionPixelSize(R.dimen.toast_y_offset);
            params.verticalMargin = 0.0f;
            params.horizontalMargin = 0.0f;
            params.height = WindowManager.LayoutParams.WRAP_CONTENT;
            params.width = WindowManager.LayoutParams.WRAP_CONTENT;
            params.format = PixelFormat.TRANSLUCENT;
//            params.windowAnimations = R.style.Anim_SweetToast;
//            params.type = WindowManager.LayoutParams.TYPE_TOAST;
//            params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
            params.type = WindowManager.LayoutParams.TYPE_PHONE;
            params.setTitle("Toast");
            params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
            mConfiguration.setParams(params);
            sweetToast.setConfiguration(mConfiguration);
        }catch (Exception e){
            Log.e("幻海流心","e:"+e.getLocalizedMessage());
        }
    }
 
Example 15
Source File: SimpleArgumentsBundle.java    From Rhythm with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc} Does a quick and rough parsing of the raw string for containing constant words like
 * <code>top</code> or <code>center_vertical</code>
 */
@Override
@SuppressLint("RtlHardcoded")
public int getGravity(String key, int defaultValue) {
    String gravityArg = resolveArgument(key);
    if (gravityArg == null) {
        return defaultValue;
    } else if (gravityArg.equals("center")) {
        return Gravity.CENTER;
    } else if (gravityArg.equals("fill")) {
        return Gravity.FILL;
    } else {
        // supported options
        int gravity = 0;
        if (gravityArg.contains("top")) {
            gravity |= Gravity.TOP;
        }
        if (gravityArg.contains("bottom")) {
            gravity |= Gravity.BOTTOM;
        }
        if (gravityArg.contains("center_vertical")) {
            gravity |= Gravity.CENTER_VERTICAL;
        }
        if (gravityArg.contains("fill_vertical")) {
            gravity |= Gravity.FILL_VERTICAL;
        }
        if (gravityArg.contains("left")) {
            gravity |= Gravity.LEFT;
        }
        if (gravityArg.contains("right")) {
            gravity |= Gravity.RIGHT;
        }
        if (gravityArg.contains("center_horizontal")) {
            gravity |= Gravity.CENTER_HORIZONTAL;
        }
        if (gravityArg.contains("fill_horizontal")) {
            gravity |= Gravity.FILL_HORIZONTAL;
        }
        return gravity;
    }
}
 
Example 16
Source File: SweetToast.java    From SweetTips with Apache License 2.0 4 votes vote down vote up
/**
     * 初始化
     * @param sweetToast
     * @param duration  自定义显示时间
     */
    private static void initConfiguration(SweetToast sweetToast,int duration){
        try {
            if(duration < 0){
                throw new RuntimeException("显示时长必须>=0!");
            }
            //1:初始化mWindowManager
            sweetToast.mWindowManager = (WindowManager) sweetToast.getContentView().getContext().getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
            //2:初始化mConfiguration
            SweetToastConfiguration mConfiguration = new SweetToastConfiguration();
            mConfiguration.setDuration(duration);
            WindowManager.LayoutParams params = new WindowManager.LayoutParams();
            final Configuration config = sweetToast.getContentView().getContext().getResources().getConfiguration();
            final int gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
            params.gravity = gravity;
            if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) {
                params.horizontalWeight = 1.0f;
            }
            if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) {
                params.verticalWeight = 1.0f;
            }
            params.x = 0;
            params.y = sweetToast.getContentView().getContext().getResources().getDimensionPixelSize(R.dimen.toast_y_offset);
            params.verticalMargin = 0.0f;
            params.horizontalMargin = 0.0f;
            params.height = WindowManager.LayoutParams.WRAP_CONTENT;
            params.width = WindowManager.LayoutParams.WRAP_CONTENT;
            params.format = PixelFormat.TRANSLUCENT;
//            params.windowAnimations = R.style.Anim_SweetToast;
//            params.type = WindowManager.LayoutParams.TYPE_TOAST;
//            params.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
            params.type = WindowManager.LayoutParams.TYPE_PHONE;
            params.setTitle("Toast");
            params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;
            mConfiguration.setParams(params);
            sweetToast.setConfiguration(mConfiguration);
        }catch (Exception e){
            Log.e("幻海流心","e:"+e.getLocalizedMessage());
        }
    }
 
Example 17
Source File: ToastFactory.java    From DevUtils with Apache License 2.0 4 votes vote down vote up
/***
 * 显示 Toast 弹窗
 */
void show() {
    if (!mShow) {
        try {
            if (mToast == null) {
                return;
            }
            // 获取 View
            View view = mToast.getView();
            // 防止 View 为 null
            if (view == null) {
                return;
            }
            // 获取 Context
            Context context = view.getContext().getApplicationContext();
            if (context == null) {
                context = view.getContext();
            }
            // 获取包名
            String packageName = context.getPackageName();

            // =

            WindowManager.LayoutParams params = new WindowManager.LayoutParams();
            // 设置参数
            if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) {
                params.type = WindowManager.LayoutParams.TYPE_TOAST;
            } else if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N_MR1) {
                params.type = WindowManager.LayoutParams.LAST_APPLICATION_WINDOW;
            } else {
                params.type = WindowManager.LayoutParams.FIRST_SYSTEM_WINDOW + 37;
            }

            params.height = WindowManager.LayoutParams.WRAP_CONTENT;
            params.width = WindowManager.LayoutParams.WRAP_CONTENT;
            params.format = PixelFormat.TRANSLUCENT;
            params.windowAnimations = android.R.style.Animation_Toast;
            params.setTitle(Toast.class.getSimpleName());
            params.flags = WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                    | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
                    | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE;

            // Toast 的重心
            int gravity = mToast.getGravity();
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
                Configuration config = context.getResources().getConfiguration();
                gravity = Gravity.getAbsoluteGravity(gravity, config.getLayoutDirection());
            }
            if (gravity != 0) {
                params.gravity = gravity;
                // 判断是否铺满整个方向
                if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) {
                    params.horizontalWeight = 1.0f;
                }
                if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) {
                    params.verticalWeight = 1.0f;
                }
            }
            // 设置 X、Y 轴偏移
            params.x = mToast.getXOffset();
            params.y = mToast.getYOffset();
            // 设置水平边距、垂直边距
            params.verticalMargin = mToast.getVerticalMargin();
            params.horizontalMargin = mToast.getHorizontalMargin();
            // 设置包名
            params.packageName = packageName;

            // View 对象不能重复添加, 否则会抛出异常
            getWindowManager(DevUtils.getTopActivity()).addView(mToast.getView(), params);
            // 当前已经显示
            mShow = true;
            // 添加一个移除 Toast 的任务
            sendEmptyMessageDelayed(0, mToast.getDuration() == Toast.LENGTH_LONG ? 3500 : 2000);
        } catch (Exception e) {
            LogPrintUtils.eTag(TAG, e, "ToastHelper - show");
        }
    }
}
 
Example 18
Source File: StackLayout.java    From tns-core-modules-widgets with Apache License 2.0 4 votes vote down vote up
private void layoutVertical(int left, int top, int right, int bottom) {

        int paddingLeft = this.getPaddingLeft();
        int paddingRight = this.getPaddingRight();
        int paddingTop = this.getPaddingTop();
        int paddingBottom = this.getPaddingBottom();

        int childTop = 0;
        int childLeft = paddingLeft;
        int childRight = right - left - paddingRight;
        
        int gravity = LayoutBase.getGravity(this);
        final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
        
        switch (verticalGravity) {
            case Gravity.CENTER_VERTICAL:
                childTop = (bottom - top - this._totalLength) / 2 + paddingTop - paddingBottom;
                break;

            case Gravity.BOTTOM:
                childTop = bottom - top - this._totalLength + paddingTop - paddingBottom;
                break;

            case Gravity.TOP:
            case Gravity.FILL_VERTICAL:
            default:
                childTop = paddingTop;
                break;
        }

        for (int i = 0, count = this.getChildCount(); i < count; i++) {
            View child = this.getChildAt(i);
            if (child.getVisibility() == View.GONE) {
                continue;
            }

            int childHeight = CommonLayoutParams.getDesiredHeight(child);
            CommonLayoutParams.layoutChild(child, childLeft, childTop, childRight, childTop + childHeight);
            childTop += childHeight;
        }
    }
 
Example 19
Source File: CommonLayoutParams.java    From tns-core-modules-widgets with Apache License 2.0 4 votes vote down vote up
private static int getMeasureSpec(View view, int parentMeasureSpec, boolean horizontal) {

        int parentLength = MeasureSpec.getSize(parentMeasureSpec);
        int parentSpecMode = MeasureSpec.getMode(parentMeasureSpec);

        CommonLayoutParams lp = (CommonLayoutParams) view.getLayoutParams();
        final int margins = horizontal ? lp.leftMargin + lp.rightMargin : lp.topMargin + lp.bottomMargin;

        int resultSize = 0;
        int resultMode = MeasureSpec.UNSPECIFIED;

        int measureLength = Math.max(0, parentLength - margins);
        int childLength = horizontal ? lp.width : lp.height;

        // We want a specific size... let be it.
        if (childLength >= 0) {
            if (parentSpecMode != MeasureSpec.UNSPECIFIED) {
                resultSize = Math.min(parentLength, childLength);
            } else {
                resultSize = childLength;
            }

            resultMode = MeasureSpec.EXACTLY;
        } else {
            switch (parentSpecMode) {
                // Parent has imposed an exact size on us
                case MeasureSpec.EXACTLY:
                    resultSize = measureLength;
                    int gravity = LayoutBase.getGravity(view);
                    boolean stretched;
                    if (horizontal) {
                        final int horizontalGravity = Gravity.getAbsoluteGravity(gravity, view.getLayoutDirection()) & Gravity.HORIZONTAL_GRAVITY_MASK;
                        stretched = horizontalGravity == Gravity.FILL_HORIZONTAL;
                    } else {
                        final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
                        stretched = verticalGravity == Gravity.FILL_VERTICAL;
                    }

                    // if stretched - view wants to be our size. So be it.
                    // else - view wants to determine its own size. It can't be bigger than us.
                    resultMode = stretched ? MeasureSpec.EXACTLY : MeasureSpec.AT_MOST;
                    break;

                // Parent has imposed a maximum size on us
                case MeasureSpec.AT_MOST:
                    resultSize = measureLength;
                    resultMode = MeasureSpec.AT_MOST;
                    break;

                case MeasureSpec.UNSPECIFIED:
                    resultSize = 0;
                    resultMode = MeasureSpec.UNSPECIFIED;
                    break;
            }
        }

        return MeasureSpec.makeMeasureSpec(resultSize, resultMode);
    }
 
Example 20
Source File: Toast.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
public void handleShow(IBinder windowToken) {
    if (localLOGV) Log.v(TAG, "HANDLE SHOW: " + this + " mView=" + mView
            + " mNextView=" + mNextView);
    // If a cancel/hide is pending - no need to show - at this point
    // the window token is already invalid and no need to do any work.
    if (mHandler.hasMessages(CANCEL) || mHandler.hasMessages(HIDE)) {
        return;
    }
    if (mView != mNextView) {
        // remove the old view if necessary
        handleHide();
        mView = mNextView;
        Context context = mView.getContext().getApplicationContext();
        String packageName = mView.getContext().getOpPackageName();
        if (context == null) {
            context = mView.getContext();
        }
        mWM = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
        // We can resolve the Gravity here by using the Locale for getting
        // the layout direction
        final Configuration config = mView.getContext().getResources().getConfiguration();
        final int gravity = Gravity.getAbsoluteGravity(mGravity, config.getLayoutDirection());
        mParams.gravity = gravity;
        if ((gravity & Gravity.HORIZONTAL_GRAVITY_MASK) == Gravity.FILL_HORIZONTAL) {
            mParams.horizontalWeight = 1.0f;
        }
        if ((gravity & Gravity.VERTICAL_GRAVITY_MASK) == Gravity.FILL_VERTICAL) {
            mParams.verticalWeight = 1.0f;
        }
        mParams.x = mX;
        mParams.y = mY;
        mParams.verticalMargin = mVerticalMargin;
        mParams.horizontalMargin = mHorizontalMargin;
        mParams.packageName = packageName;
        mParams.hideTimeoutMilliseconds = mDuration ==
            Toast.LENGTH_LONG ? LONG_DURATION_TIMEOUT : SHORT_DURATION_TIMEOUT;
        mParams.token = windowToken;
        if (mView.getParent() != null) {
            if (localLOGV) Log.v(TAG, "REMOVE! " + mView + " in " + this);
            mWM.removeView(mView);
        }
        if (localLOGV) Log.v(TAG, "ADD! " + mView + " in " + this);
        // Since the notification manager service cancels the token right
        // after it notifies us to cancel the toast there is an inherent
        // race and we may attempt to add a window after the token has been
        // invalidated. Let us hedge against that.
        try {
            mWM.addView(mView, mParams);
            trySendAccessibilityEvent();
        } catch (WindowManager.BadTokenException e) {
            /* ignore */
        }
    }
}