Java Code Examples for android.view.WindowManager#LayoutParams

The following examples show how to use android.view.WindowManager#LayoutParams . 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: WindowManage.java    From QSVideoPlayer with Apache License 2.0 8 votes vote down vote up
public WindowManager.LayoutParams creatParams(int type, FloatParams floatParams) {
    //系统浮窗不能超出边界,更新xy
    int ww = (w - floatParams.w) / 2;
    int hh = (h - floatParams.h) / 2;
    if (Math.abs(floatParams.x) > ww)
        floatParams.x = floatParams.x > 0 ? ww : -ww;
    if (Math.abs(floatParams.y) > hh)
        floatParams.y = floatParams.y > 0 ? hh : -hh;

    LayoutParams smallWindowParams = new LayoutParams();
    smallWindowParams.type = type;
    smallWindowParams.format = PixelFormat.RGBA_8888;
    smallWindowParams.flags = LayoutParams.FLAG_NOT_TOUCH_MODAL
            | LayoutParams.FLAG_NOT_FOCUSABLE;
    //smallWindowParams.gravity = Gravity.LEFT | Gravity.TOP;
    smallWindowParams.width = floatParams.w;
    smallWindowParams.height = floatParams.h;
    smallWindowParams.x = floatParams.x;
    smallWindowParams.y = floatParams.y;
    return smallWindowParams;
}
 
Example 2
Source File: UserSwitchingDialog.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
public UserSwitchingDialog(ActivityManagerService service, Context context, UserInfo oldUser,
        UserInfo newUser, boolean aboveSystem, String switchingFromSystemUserMessage,
        String switchingToSystemUserMessage) {
    super(context);

    mContext = context;
    mService = service;
    mUserId = newUser.id;
    mOldUser = oldUser;
    mNewUser = newUser;
    mSwitchingFromSystemUserMessage = switchingFromSystemUserMessage;
    mSwitchingToSystemUserMessage = switchingToSystemUserMessage;

    inflateContent();

    if (aboveSystem) {
        getWindow().setType(WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
    }

    WindowManager.LayoutParams attrs = getWindow().getAttributes();
    attrs.privateFlags = WindowManager.LayoutParams.PRIVATE_FLAG_SYSTEM_ERROR |
        WindowManager.LayoutParams.PRIVATE_FLAG_SHOW_FOR_ALL_USERS;
    getWindow().setAttributes(attrs);
}
 
Example 3
Source File: PopupMenuDialog.java    From FileTransfer with GNU General Public License v3.0 6 votes vote down vote up
public PopupMenuDialog builder() {
    View view = LayoutInflater.from(context).inflate(
            R.layout.layout_popup_menu_dialog, null);

    view.setMinimumWidth(display.getWidth());

    dialog = new Dialog(context, R.style.PopupMenuDialogStyle);
    dialog.setContentView(view);
    mUnbinder = ButterKnife.bind(this, dialog);
    dialog.setOnDismissListener(this::onDialogDismiss);

    Window dialogWindow = dialog.getWindow();
    dialogWindow.setGravity(Gravity.LEFT | Gravity.BOTTOM);
    WindowManager.LayoutParams lp = dialogWindow.getAttributes();
    lp.x = 0;
    lp.y = 0;
    dialogWindow.setAttributes(lp);

    return this;
}
 
Example 4
Source File: PopupWindow.java    From android_9.0.0_r45 with Apache License 2.0 6 votes vote down vote up
/**
 * Displays the content view in a popup window anchored to the corner of
 * another view. The window is positioned according to the specified
 * gravity and offset by the specified x and y coordinates.
 * <p>
 * If there is not enough room on screen to show the popup in its entirety,
 * this method tries to find a parent scroll view to scroll. If no parent
 * view can be scrolled, the specified vertical gravity will be ignored and
 * the popup will anchor itself such that it is visible.
 * <p>
 * If the view later scrolls to move <code>anchor</code> to a different
 * location, the popup will be moved correspondingly.
 *
 * @param anchor the view on which to pin the popup window
 * @param xoff A horizontal offset from the anchor in pixels
 * @param yoff A vertical offset from the anchor in pixels
 * @param gravity Alignment of the popup relative to the anchor
 *
 * @see #dismiss()
 */
public void showAsDropDown(View anchor, int xoff, int yoff, int gravity) {
    if (isShowing() || !hasContentView()) {
        return;
    }

    TransitionManager.endTransitions(mDecorView);

    attachToAnchor(anchor, xoff, yoff, gravity);

    mIsShowing = true;
    mIsDropdown = true;

    final WindowManager.LayoutParams p =
            createPopupLayoutParams(anchor.getApplicationWindowToken());
    preparePopup(p);

    final boolean aboveAnchor = findDropDownPosition(anchor, p, xoff, yoff,
            p.width, p.height, gravity, mAllowScrollingAnchorParent);
    updateAboveAnchor(aboveAnchor);
    p.accessibilityIdOfAnchor = (anchor != null) ? anchor.getAccessibilityViewId() : -1;

    invokePopup(p);
}
 
Example 5
Source File: GalleryActivity.java    From MHViewer with Apache License 2.0 6 votes vote down vote up
/**
 * @param lightness 0 - 200
 */
private void setScreenLightness(boolean enable, int lightness) {
    if (null == mMaskView) {
        return;
    }

    Window w = getWindow();
    WindowManager.LayoutParams lp = w.getAttributes();
    if (enable) {
        lightness = MathUtils.clamp(lightness, 0, 200);
        if (lightness > 100) {
            mMaskView.setColor(0);
            // Avoid BRIGHTNESS_OVERRIDE_OFF,
            // screen may be off when lp.screenBrightness is 0.0f
            lp.screenBrightness = Math.max((lightness - 100) / 100.0f, 0.01f);
        } else {
            mMaskView.setColor(MathUtils.lerp(0xde, 0x00, lightness / 100.0f) << 24);
            lp.screenBrightness = 0.01f;
        }
    } else {
        mMaskView.setColor(0);
        lp.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;
    }
    w.setAttributes(lp);
}
 
Example 6
Source File: FloatWindowManager.java    From ArgusAPM with Apache License 2.0 6 votes vote down vote up
/**
 * 显示小悬浮窗
 */
public void showSmallFloatWin() {
    if (DEBUG) {
        LogX.d(TAG, SUB_TAG, "showSmallFloatWin:创建悬浮窗口");
    }
    if (smallView == null) {
        smallView = new SmallFloatWindowView(Manager.getContext(), dm.density);
        smallParams = new WindowManager.LayoutParams(WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.WRAP_CONTENT,
                FloatWindowUtils.getType(),
                FLAG_NOT_FOCUSABLE | FLAG_ALT_FOCUSABLE_IM, PixelFormat.TRANSLUCENT);
        smallParams.gravity = Gravity.LEFT | Gravity.TOP;
        smallParams.x = (int) xPosition;
        smallParams.y = (int) (dm.heightPixels / 4 - yPosition);
        smallView.setWindowsParams(smallParams);
        smallView.setOnSmallCallback(this);
    }
    removeOldFloatWindow();
    getWindowManager().addView(smallView, smallParams);
    currentState = FloatWindowState.SMALL_WINDOW;
}
 
Example 7
Source File: PullMenuAttacher.java    From AndroidPullMenu with Apache License 2.0 6 votes vote down vote up
protected void updateHeaderViewPosition(View headerView) {
    // Refresh the Display Rect of the Decor View
    mActivity.getWindow().getDecorView().getWindowVisibleDisplayFrame(mRect);

    WindowManager.LayoutParams wlp = null;
    if (headerView.getLayoutParams() instanceof WindowManager.LayoutParams) {
        wlp = (WindowManager.LayoutParams) headerView.getLayoutParams();
    } else if (headerView.getTag() instanceof  WindowManager.LayoutParams) {
        wlp = (WindowManager.LayoutParams) headerView.getTag();
    }

    if (wlp != null && wlp.y != mRect.top) {
        wlp.y = mRect.top;
        mActivity.getWindowManager().updateViewLayout(headerView, wlp);
    }
}
 
Example 8
Source File: InfoOperationActivity.java    From timecat with Apache License 2.0 5 votes vote down vote up
/**
 * 设置窗口样式
 */
private void setWindow() {
    //窗口对齐屏幕宽度
    Window win = this.getWindow();
    win.getDecorView().setPadding(0, 0, 0, 0);
    WindowManager.LayoutParams lp = win.getAttributes();
    lp.width = WindowManager.LayoutParams.MATCH_PARENT;
    lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
    lp.gravity = Gravity.BOTTOM;//设置对话框置顶显示
    win.setAttributes(lp);
}
 
Example 9
Source File: BaseActivity.java    From fangzhuishushenqi with Apache License 2.0 5 votes vote down vote up
protected void showStatusBar() {
    WindowManager.LayoutParams attrs = getWindow().getAttributes();
    attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
    getWindow().setAttributes(attrs);
    if(statusBarView != null){
        statusBarView.setBackgroundColor(statusBarColor);
    }
}
 
Example 10
Source File: OBBrightnessManager.java    From GLEXP-Team-onebillion with Apache License 2.0 5 votes vote down vote up
public String printStatus ()
{
    WindowManager.LayoutParams layoutpars = MainActivity.mainActivity.getWindow().getAttributes();
    float brightness = Math.abs(layoutpars.screenBrightness);
    String result = String.format("%.1f%%", brightness * 100);
    return result;
}
 
Example 11
Source File: FlymeOSStatusBarFontUtils.java    From MyBookshelf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * 设置状态栏颜色
 *
 * @param window
 * @param color
 */
private static void setStatusBarColor(Window window, int color) {
    WindowManager.LayoutParams winParams = window.getAttributes();
    if (mStatusBarColorFiled != null) {
        try {
            int oldColor = mStatusBarColorFiled.getInt(winParams);
            if (oldColor != color) {
                mStatusBarColorFiled.set(winParams, color);
                window.setAttributes(winParams);
            }
        } catch (IllegalAccessException e) {
            e.printStackTrace();
        }
    }
}
 
Example 12
Source File: ScrollingActivity.java    From MyBlogDemo with Apache License 2.0 5 votes vote down vote up
private void full(boolean enable) {
    if (enable) {
        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
        getWindow().setAttributes(lp);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    } else {
        WindowManager.LayoutParams attr = getWindow().getAttributes();
        attr.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().setAttributes(attr);
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    }
}
 
Example 13
Source File: MenuDialog.java    From retrowatch with Apache License 2.0 5 votes vote down vote up
/*****************************************************
*		Overrided methods
******************************************************/
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
       
  	//----- Set title
  	if(mDialogTitle != null) {
  		setTitle(mDialogTitle);
  	} else {
  		this.requestWindowFeature(Window.FEATURE_NO_TITLE);
  	}
      
      WindowManager.LayoutParams lpWindow = new WindowManager.LayoutParams();    
      lpWindow.flags = WindowManager.LayoutParams.FLAG_DIM_BEHIND;
      lpWindow.dimAmount = 0.8f;
      getWindow().setAttributes(lpWindow);

      setContentView(R.layout.dialog_filter_list);
      mClickListener = new OnClickListener(this);
      
      mBtnDisablePackage = (Button) findViewById(R.id.btn_disable_package);
      mBtnDisablePackage.setOnClickListener(mClickListener);
      mBtnEdit = (Button) findViewById(R.id.btn_edit);
      mBtnEdit.setOnClickListener(mClickListener);
      
      setContent();
  }
 
Example 14
Source File: AudioWidget.java    From MusicBobber with MIT License 5 votes vote down vote up
private boolean isReadyToRemove() {
    WindowManager.LayoutParams removeParams = (WindowManager.LayoutParams) removeWidgetView.getLayoutParams();
    removeBounds.set(removeParams.x, removeParams.y, removeParams.x + widgetHeight, removeParams.y + widgetHeight);
    WindowManager.LayoutParams params = (WindowManager.LayoutParams) playPauseButton.getLayoutParams();
    float cx = params.x + widgetHeight;
    float cy = params.y + widgetHeight;
    return removeBounds.contains(cx, cy);
}
 
Example 15
Source File: OppoVolumePanel.java    From Noyze with Apache License 2.0 5 votes vote down vote up
@Override public WindowManager.LayoutParams getWindowLayoutParams() {
    WindowManager.LayoutParams WPARAMS = super.getWindowLayoutParams();
    WPARAMS.flags &= ~WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
    WPARAMS.flags &= ~WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR;
    WPARAMS.y = getResources().getDimensionPixelSize(R.dimen.volume_panel_top);
    return WPARAMS;
}
 
Example 16
Source File: MLAlertDialog.java    From NewXmPluginSDK with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link android.app.AlertDialog} with the arguments supplied
 * to this builder and {@link Dialog#show()}'s the dialog.
 */
public MLAlertDialog show() {
    MLAlertDialog dialog = create();
    dialog.show();
    WindowManager.LayoutParams lp = dialog.getWindow().getAttributes();
    lp.width = WindowManager.LayoutParams.FILL_PARENT;
    lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
    dialog.getWindow().setAttributes(lp);
    return dialog;
}
 
Example 17
Source File: DialogProgressBar.java    From android-project-wo2b with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState)
{
	super.onCreate(savedInstanceState);
	setContentView(R.layout.global_dialog_progress_loading);

	if (mAutoWidth)
	{
		setMinimumWidth(0);
	}
	
	mLoadingAnimation = AnimationUtils.loadAnimation(getContext(), R.anim.progress_dialog_loading);

	mImageView = (ImageView) findViewById(R.id.image);
	mTextView = (TextView) findViewById(R.id.text);
	// mTextView.setGravity(Gravity.LEFT);
	mTextView.setText("");

	Window dialogWindow = this.getWindow();
	WindowManager.LayoutParams lp = dialogWindow.getAttributes();
	// lp.x = 100; // 新位置X坐标
	// lp.y = 100; // 新位置Y坐标
	lp.width = WindowManager.LayoutParams.WRAP_CONTENT; // 宽度
	// lp.width = WindowManager.LayoutParams.MATCH_PARENT; // 宽度
	lp.height = ViewUtils.dip2px(getContext(), 80); // 高度
	lp.alpha = 1.0f; // 透明度

	// 当Window的Attributes改变时系统会调用此函数,可以直接调用以应用上面对窗口参数的更改,也可以用setAttributes
	// dialog.onWindowAttributesChanged(lp);
	dialogWindow.setAttributes(lp);
}
 
Example 18
Source File: Overlays.java    From oversec with GNU General Public License v3.0 4 votes vote down vote up
private void addOverlayView(OverlayView overlayView, WindowManager.LayoutParams layoutParams) {
    mWm.addView(overlayView, layoutParams);
}
 
Example 19
Source File: ClickableToast.java    From Overchan-Android with GNU General Public License v3.0 4 votes vote down vote up
public void show(){
    WindowManager.LayoutParams params = getWmParams();
    this.windowManager.addView(this, params);
    getContext().registerReceiver(dismissReceiver, new IntentFilter(Intent.ACTION_CLOSE_SYSTEM_DIALOGS));
}
 
Example 20
Source File: ActivityCall.java    From iGap-Android with GNU Affero General Public License v3.0 3 votes vote down vote up
private void screenOff() {

        if (ActivityCallViewModel.isConnected) {

            WindowManager.LayoutParams params = this.getWindow().getAttributes();

            params.screenBrightness = 0;
            this.getWindow().setAttributes(params);

            enableDisableViewGroup((ViewGroup) activityCallBinding.acLayoutCallRoot, false);
        }
    }