Java Code Examples for android.view.Window#setDimAmount()

The following examples show how to use android.view.Window#setDimAmount() . 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: BDialog.java    From BaldPhone with Apache License 2.0 6 votes vote down vote up
public static BDialog newInstance(final @NonNull Context context,
                                  final @NonNull CharSequence title,
                                  final @NonNull CharSequence subText,
                                  final @Nullable CharSequence[] options,
                                  final @Nullable DialogBoxListener positive,
                                  final @Nullable DialogBoxListener negative,
                                  final int inputType,
                                  final StartingIndexChooser startingIndexChooser,
                                  final @Nullable View extraView,
                                  final @Nullable CharSequence negativeCustomText,
                                  final @Nullable CharSequence positiveCustomText,
                                  final int flags
) {
    final BDialog baldDialogBox = new BDialog(context, title, subText, options, positive, negative, inputType, startingIndexChooser, extraView, negativeCustomText, positiveCustomText, flags);
    baldDialogBox.show();
    Window window = baldDialogBox.getWindow();
    window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    window.setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); // This flag is required to set otherwise the setDimAmount method will not show any effect
    window.setDimAmount(DIM_LEVEL);
    return baldDialogBox;
}
 
Example 2
Source File: TextEditorDialogFragment.java    From MotionViews-Android with MIT License 6 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    Dialog dialog = getDialog();
    if (dialog != null) {
        Window window = dialog.getWindow();
        if (window != null) {
            // remove background
            window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
            window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT);

            // remove dim
            WindowManager.LayoutParams windowParams = window.getAttributes();
            window.setDimAmount(0.0F);
            window.setAttributes(windowParams);
        }
    }
}
 
Example 3
Source File: WindowHelper.java    From android-auto-call-recorder with MIT License 5 votes vote down vote up
/**
 * Enhance the window by setting a custom dim amout and
 * a background!
 *
 * @param window - the current used window (getDialog.getwindow....)
 */
public static void init(Window window) {
    if (window != null) {
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.setDimAmount(0.9f);
    }
    //window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
}
 
Example 4
Source File: BaseDialog.java    From AndroidProject with Apache License 2.0 5 votes vote down vote up
/**
 * 设置背景遮盖层的透明度(前提条件是背景遮盖层开关必须是为开启状态)
 */
public void setBackgroundDimAmount(@FloatRange(from = 0, to = 1) float dimAmount) {
    Window window = getWindow();
    if (window != null) {
        window.setDimAmount(dimAmount);
    }
}
 
Example 5
Source File: Tutors.java    From Tutors with Apache License 2.0 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    final Window window = getDialog().getWindow();
    if (window != null) {
        window.setBackgroundDrawableResource(android.R.color.transparent);
        window.setDimAmount(0f);
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    }
}
 
Example 6
Source File: ProgressDialogFragment.java    From mvvm-template with GNU General Public License v3.0 5 votes vote down vote up
@NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog dialog = super.onCreateDialog(savedInstanceState);
    dialog.setCancelable(false);
    setCancelable(false);
    Window window = dialog.getWindow();
    if (window != null) {
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
        window.setDimAmount(0);
    }
    return dialog;
}
 
Example 7
Source File: WindowAdjuster.java    From DialogUtil with Apache License 2.0 5 votes vote down vote up
private static void setDimBehind(Window window, ConfigBean bean) {
    if(bean.dimBehind){
        window.setDimAmount(0.6f);
    }else {
        window.setDimAmount(0f);
    }

    
}
 
Example 8
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 9
Source File: ProgressDialog.java    From HaoReader with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onDialogAttachWindow(@NonNull Window window) {
    window.setGravity(Gravity.CENTER);
    window.setLayout(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
    window.setDimAmount(0f);
}
 
Example 10
Source File: BaseMessageDialog.java    From Leanplum-Android-SDK with Apache License 2.0 4 votes vote down vote up
protected BaseMessageDialog(Activity activity, boolean fullscreen, BaseMessageOptions options,
    WebInterstitialOptions webOptions, HTMLOptions htmlOptions) {
  super(activity, getTheme(activity));

  SizeUtil.init(activity);
  this.activity = activity;
  this.options = options;
  this.webOptions = webOptions;
  this.htmlOptions = htmlOptions;
  if (webOptions != null) {
    isWeb = true;
  }
  if (htmlOptions != null) {
    isHtml = true;
  }
  dialogView = new RelativeLayout(activity);
  RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(
      LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
  dialogView.setBackgroundColor(Color.TRANSPARENT);
  dialogView.setLayoutParams(layoutParams);

  RelativeLayout view = createContainerView(activity, fullscreen);
  view.setId(R.id.container_view);
  dialogView.addView(view, view.getLayoutParams());

  if ((!isWeb || (webOptions != null && webOptions.hasDismissButton())) && !isHtml) {
    CloseButton closeButton = createCloseButton(activity, fullscreen, view);
    dialogView.addView(closeButton, closeButton.getLayoutParams());
  }
  setContentView(dialogView, dialogView.getLayoutParams());

  dialogView.setAnimation(createFadeInAnimation());

  if (!fullscreen) {
    Window window = getWindow();
    if (window == null) {
      return;
    }
    if (!isHtml) {
      window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
      if (Build.VERSION.SDK_INT >= 14) {
        window.setDimAmount(0.7f);
      }
    } else {
      window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

      if (htmlOptions != null && isBannerWithTapOutsideFalse(htmlOptions)) {
        // banners need to be positioned at the top manually
        // (unless they get repositioned to the bottom later)
        window.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
        window.setGravity(Gravity.TOP);

        // use the html y offset to determine the y location of the window; this is different
        // from non-banners because we don't want to make the window too big (e.g. via a margin
        // in the layout) and block other things on the screen (e.g. dialogs)
        WindowManager.LayoutParams windowLayoutParams = window.getAttributes();
        windowLayoutParams.y = htmlOptions.getHtmlYOffset(activity);
        window.setAttributes(windowLayoutParams);

        window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE);
      } else {
        window.setFlags(WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
            WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL);
      }

      if (htmlOptions != null &&
          MessageTemplates.Args.HTML_ALIGN_BOTTOM.equals(htmlOptions.getHtmlAlign())) {
        if (isBannerWithTapOutsideFalse(htmlOptions)) {
          window.setGravity(Gravity.BOTTOM);
        } else {
          dialogView.setGravity(Gravity.BOTTOM);
        }
      }
    }
  }
}
 
Example 11
Source File: Tool.java    From DialogUtil with Apache License 2.0 4 votes vote down vote up
public static void adjustStyle(final ConfigBean bean) {
    /*if (bean.alertDialog!= null){
        //setMdBtnStytle(bean);
        //setListItemsStyle(bean);
       // adjustStyle(bean.context,bean.dialog,bean.viewHeight,bean);

    }else {
        adjustWH(bean.context,bean.dialog,bean.viewHeight,bean);
    }*/

    setBg(bean);
   // bean.isTransparentBehind = true;
    setDim(bean);
    Dialog dialog = bean.dialog ==null ? bean.alertDialog : bean.dialog;
    Window window = dialog.getWindow();
    window.setGravity(bean.gravity);
    if(bean.context instanceof Activity){
        //setHomeKeyListener(window,bean);
    }else {
        window.setType(WindowManager.LayoutParams.TYPE_TOAST);
        WindowManager.LayoutParams params = window.getAttributes();
        if(params==null){
            params = new WindowManager.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
        }
        params.format = PixelFormat.RGBA_8888;
        params.flags =
           // WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL  |
            WindowManager.LayoutParams.FLAG_LOCAL_FOCUS_MODE  |
            WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
            WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD;
        params.dimAmount = 0.2f;
        //params.alpha = 0.5f;//the alpha of window

        window.setAttributes(params);

        // back key pressed
        window.getDecorView().setOnKeyListener(new View.OnKeyListener() {
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (keyCode == KeyEvent.KEYCODE_BACK || event.getKeyCode() == KeyEvent.KEYCODE_SETTINGS) {
                    StyledDialog.dismiss(bean.alertDialog,bean.dialog);
                    return true;
                }
                return false;
            }
        });
        // home key pressed
        setHomeKeyListener(window,bean);

        //todo outside not touchable

        //todo dim behind
        window.setDimAmount(0.2f);

    }

}
 
Example 12
Source File: CompatibilityImpl.java    From Overchan-Android with GNU General Public License v3.0 4 votes vote down vote up
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
public static void setDimAmount(Window window, float f) {
    window.setDimAmount(f);
}