Java Code Examples for android.app.Dialog#getWindow()

The following examples show how to use android.app.Dialog#getWindow() . 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: DialogSearching.java    From BigApp_WordPress_Android with Apache License 2.0 6 votes vote down vote up
private void init(Context context) {
    View view = LayoutInflater.from(context).inflate(
            R.layout.z_dialog_searching, null);
    mEt_content = (TextView) view.findViewById(R.id.tv_content);
    dialog = new Dialog(context, R.style.DialogStyle);
    dialog.setCancelable(false);
    dialog.setCanceledOnTouchOutside(false);
    dialog.setContentView(view);

    Window window = dialog.getWindow();
    WindowManager.LayoutParams lp = window.getAttributes();
    lp.width = ScreenTools.getScreenParams(context).width / 3;
    lp.height = lp.width;
    window.setBackgroundDrawableResource(R.drawable.z_shape_searching);
    window.setWindowAnimations(R.style.AnimEnterExit);
}
 
Example 2
Source File: ProgressDialogUtils.java    From BaseProject with Apache License 2.0 6 votes vote down vote up
@SuppressLint("InflateParams")
    public ProgressDialogUtils(Context context, int style) {
        mDialog = new Dialog(context, style);
        mDialogContentView = LayoutInflater.from(context).inflate(R.layout.dialog_loading, null);
        tv_loadText = (TextView) mDialogContentView.findViewById(R.id.tv_loading_text);
        iv_loadImage = (ImageView) mDialogContentView.findViewById(R.id.iv_load_image);
        pb_loadProgress = (ProgressBar) mDialogContentView.findViewById(R.id.pb_load_progress);
        mDialog.setCanceledOnTouchOutside(false);
        mDialog.setContentView(mDialogContentView);
        Window window = mDialog.getWindow();
        if (null != window) {
//            window.getAttributes().width = (int) (UIUtils.getScreenWidth() * 0.5);
//            window.getAttributes().height = (int) (UIUtils.getScreenHegith() * 0.2);
            window.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
        }
    }
 
Example 3
Source File: DialogImgMode.java    From BigApp_WordPress_Android with Apache License 2.0 6 votes vote down vote up
private void init(Context context) {
    View view = LayoutInflater.from(context).inflate(
            R.layout.z_dialog_img_mode, null);
    dialog = new Dialog(context, R.style.Dialog_General);
    dialog.setCancelable(true);
    dialog.setCanceledOnTouchOutside(true);
    dialog.setContentView(view);

    Window window = dialog.getWindow();
    WindowManager.LayoutParams lp = window.getAttributes();
    lp.gravity = Gravity.BOTTOM;
    lp.width = LayoutParams.MATCH_PARENT;
    window.setWindowAnimations(R.style.AnimUpDown);

    view.findViewById(R.id.btn_cancel).setOnClickListener(this);
    view.findViewById(R.id.tv_high).setOnClickListener(this);
    view.findViewById(R.id.tv_low).setOnClickListener(this);
    view.findViewById(R.id.tv_none).setOnClickListener(this);
}
 
Example 4
Source File: ItemChooserDialog.java    From delion with Apache License 2.0 6 votes vote down vote up
private void showDialogForView(View view) {
    mDialog = new Dialog(mActivity);
    mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    mDialog.addContentView(view,
            new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                                          LinearLayout.LayoutParams.MATCH_PARENT));
    mDialog.setOnDismissListener(new DialogInterface.OnDismissListener() {
        @Override
        public void onDismiss(DialogInterface dialog) {
            mItemSelectedCallback.onItemSelected("");
        }
    });

    Window window = mDialog.getWindow();
    if (!DeviceFormFactor.isTablet(mActivity)) {
        // On smaller screens, make the dialog fill the width of the screen,
        // and appear at the top.
        window.setBackgroundDrawable(new ColorDrawable(Color.WHITE));
        window.setGravity(Gravity.TOP);
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT,
                         ViewGroup.LayoutParams.WRAP_CONTENT);
    }

    mDialog.show();
}
 
Example 5
Source File: DialogDescriptor.java    From stetho with MIT License 6 votes vote down vote up
@Nullable
@Override
public Object getElementToHighlightAtPosition(Dialog element, int x, int y, Rect bounds) {
  final Descriptor.Host host = getHost();
  Window window = null;
  HighlightableDescriptor descriptor = null;

  if (host instanceof AndroidDescriptorHost) {
    window = element.getWindow();
    descriptor = ((AndroidDescriptorHost) host).getHighlightableDescriptor(window);
  }

  return descriptor == null
      ? null
      : descriptor.getElementToHighlightAtPosition(window, x, y, bounds);
}
 
Example 6
Source File: DynamicDialogUtils.java    From dynamic-support with Apache License 2.0 6 votes vote down vote up
/**
 * Bind the dialog with a window token.
 * <p>Useful to display it from a service.
 *
 * @param view The view to bind the dialog.
 * @param dialog The dialog to be displayed.
 * @param type The dialog type.
 * @param windowAnimations The custom animation used for the window.
 *
 * @return The bound dialog with the supplied view.
 */
public static Dialog bindDialog(@Nullable View view,
        @NonNull Dialog dialog, int type, @StyleRes int windowAnimations) {
    Window window = dialog.getWindow();

    if (window != null) {
        if (view != null && view.getWindowToken() != null) {
            window.getAttributes().token = view.getWindowToken();
        }

        window.setType(type);
        window.setWindowAnimations(windowAnimations);
        window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
    }

    return dialog;
}
 
Example 7
Source File: DialogRunConfig.java    From javaide with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    Dialog dialog = getDialog();
    if (dialog != null) {
        Window window = dialog.getWindow();
        if (window != null) {
            window.setLayout(WindowManager.LayoutParams.MATCH_PARENT,
                    WindowManager.LayoutParams.WRAP_CONTENT);
        }
    }
}
 
Example 8
Source File: EnsureDialog.java    From CustomDialog with Apache License 2.0 5 votes vote down vote up
public EnsureDialog(Context context) {
    this.context = context;
    final WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
    display = windowManager.getDefaultDisplay();
    dialog = new Dialog(context, R.style.Custom_Dialog_Style);
    dialogWindow = dialog.getWindow();

}
 
Example 9
Source File: KeyboardUtil.java    From TitleBarView with Apache License 2.0 5 votes vote down vote up
private KeyboardUtil(Activity activity, Dialog dialog, String tag, View contentView) {
    this.mActivity = activity;
    this.mWindow = dialog != null ? dialog.getWindow() : activity.getWindow();
    this.mDecorView = activity.getWindow().getDecorView();
    this.mContentView = contentView != null ? contentView
            : mWindow.getDecorView().findViewById(android.R.id.content);
    if (!mContentView.equals(mDecorView.findViewById(android.R.id.content)))
        this.mFlag = true;
}
 
Example 10
Source File: DialogNewFolder.java    From java-n-IDE-for-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    Dialog dialog = getDialog();
    if (dialog != null && dialog.getWindow() != null) {
        Window window = dialog.getWindow();
        window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    }
}
 
Example 11
Source File: StatusBarUtils.java    From ShareBox with Apache License 2.0 5 votes vote down vote up
public static void setWindowStatusBarColorWithColor(Dialog dialog, int color) {
    try {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = dialog.getWindow();
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
            window.setStatusBarColor(color);

            // 底部导航栏
            //window.setNavigationBarColor(activity.getResources().getColor(colorResId));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 12
Source File: KeyboardFragment.java    From AndroidMathKeyboard with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // 使用不带Theme的构造器, 获得的dialog边框距离屏幕仍有几毫米的缝隙。
    Dialog dialog = new Dialog(getActivity(), R.style.MathBottomDialog);

    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE); // 设置Content前设定
    dialog.setContentView(R.layout.layout_keybord_dialog_fragment);
    dialog.setCanceledOnTouchOutside(false); // 外部点击取消

    findView(dialog);

    initList();

    initLatex();

    // 设置宽度为屏宽, 靠近屏幕底部。
    Window window = dialog.getWindow();
    WindowManager.LayoutParams lp = window.getAttributes();
    lp.gravity = Gravity.BOTTOM; // 紧贴底部
    lp.width = WindowManager.LayoutParams.MATCH_PARENT; // 宽度持平
    window.setAttributes(lp);

    parseOriginCotent();

    return dialog;
}
 
Example 13
Source File: DialogUtils.java    From Bluefruit_LE_Connect_Android_V2 with MIT License 5 votes vote down vote up
public static void keepDialogOnOrientationChanges(@NonNull Dialog dialog) {
    WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
    Window window = dialog.getWindow();
    if (window != null) {
        WindowManager.LayoutParams attributes = window.getAttributes();
        if (attributes != null) {
            lp.copyFrom(attributes);
            lp.width = WindowManager.LayoutParams.WRAP_CONTENT;
            lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
            dialog.getWindow().setAttributes(lp);
        }
    }
}
 
Example 14
Source File: TimePickerDialog.java    From material-components-android with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public final Dialog onCreateDialog(@Nullable Bundle bundle) {
  Dialog dialog = super.onCreateDialog(bundle);
  Context context = dialog.getContext();
  int surfaceColor =
      MaterialAttributes.resolveOrThrow(
          context, R.attr.colorSurface, TimePickerDialog.class.getCanonicalName());

  MaterialShapeDrawable background =
      new MaterialShapeDrawable(
          context,
          null,
          0,
          R.style.Widget_MaterialComponents_TimePicker);

  background.initializeElevationOverlay(context);
  background.setFillColor(ColorStateList.valueOf(surfaceColor));
  Window window = dialog.getWindow();
  window.setBackgroundDrawable(background);
  window.requestFeature(Window.FEATURE_NO_TITLE);
  // On some Android APIs the dialog won't wrap content by default. Explicitly update here.
  window.setLayout(
      ViewGroup.LayoutParams.WRAP_CONTENT,
      ViewGroup.LayoutParams.WRAP_CONTENT);
  return dialog;
}
 
Example 15
Source File: GuideViewFragment.java    From GuideView with MIT License 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    Dialog dialog = getDialog();
    Window window = dialog == null ? null : dialog.getWindow();
    if (window == null) {
        return;
    }
    window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
    if (!isShowing){
        isShowing=true;
        showGuideView();
    }
}
 
Example 16
Source File: StytledDialog.java    From DialogUtils with Apache License 2.0 5 votes vote down vote up
private static void setDialogStyle(Context activity, Dialog dialog,int measuredHeight ) {
        Window window = dialog.getWindow();

        //window.setWindowAnimations(R.style.dialog_center);
        window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));//todo keycode to show round corner


        WindowManager.LayoutParams wl = window.getAttributes();
       /* wl.x = 0;
        wl.y = getWindowManager().getDefaultDisplay().getHeight();*/
// 以下这两句是为了保证按钮可以水平满屏
        int width = ((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getWidth();

        int height = (int) (((WindowManager) activity.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay().getHeight() * 0.9);

        // wl.width = ViewGroup.LayoutParams.MATCH_PARENT;
        wl.width = (int) (width * 0.94);  // todo keycode to keep gap
        wl.height = ViewGroup.LayoutParams.WRAP_CONTENT;  //TODO  一般情况下为wrapcontent,最大值为height*0.9
       /* ViewUtils.measureView(contentView);
        int meHeight = contentView.getMeasuredHeight();//height 为0,weight为1时,控件计算所得height就是0
        View textview = contentView.findViewById(R.id.tv_msg);
        ViewUtils.measureView(textview);
        int textHeight = textview.getMeasuredHeight();*/
        if (measuredHeight > height){
            wl.height = height;
        }



        //wl.horizontalMargin= 0.2f;
// 设置显示位置
        // wl.gravity = Gravity.CENTER_HORIZONTAL;

        if (!(activity instanceof Activity)){
            wl.type = WindowManager.LayoutParams.TYPE_TOAST;//todo keycode to improve window level
        }

        dialog.onWindowAttributesChanged(wl);
    }
 
Example 17
Source File: BaseFUDialogFrag.java    From sealrtc-android with MIT License 5 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    Dialog dialog = getDialog();
    if (dialog == null) return;
    Window window = dialog.getWindow();
    window.setLayout(MATCH_PARENT, WRAP_CONTENT);
    window.setGravity(Gravity.BOTTOM);
    window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}
 
Example 18
Source File: ActionSheet.java    From smart-farmer-android with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
    Dialog dialog = super.onCreateDialog(savedInstanceState);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = dialog.getWindow();
        if (window != null) {
            //解决状态栏变纯黑的问题
            window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        }
    }
    return dialog;
}
 
Example 19
Source File: LoginDialogFragment.java    From openshop.io-android with MIT License 4 votes vote down vote up
@Override
public void onStart() {
    super.onStart();
    Dialog d = getDialog();
    if (d != null) {
        int width = ViewGroup.LayoutParams.MATCH_PARENT;
        int height = ViewGroup.LayoutParams.MATCH_PARENT;
        Window window = d.getWindow();
        window.setLayout(width, height);
        window.setWindowAnimations(R.style.dialogFragmentAnimation);
        d.setOnKeyListener(new DialogInterface.OnKeyListener() {
            @Override
            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
                if (BuildConfig.DEBUG)
                    Timber.d("onKey: %d (Back=%d). Event:%d (Down:%d, Up:%d)", keyCode, KeyEvent.KEYCODE_BACK, event.getAction(),
                            KeyEvent.ACTION_DOWN, KeyEvent.ACTION_UP);
                if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
                    switch (actualFormState) {
                        case REGISTRATION:
                            if (event.getAction() == KeyEvent.ACTION_UP) {
                                setVisibilityOfRegistrationForm(false);
                            }
                            return true;
                        case FORGOTTEN_PASSWORD:
                            if (event.getAction() == KeyEvent.ACTION_UP) {
                                setVisibilityOfEmailForgottenForm(false);
                            }
                            return true;
                        case EMAIL:
                            if (event.getAction() == KeyEvent.ACTION_UP) {
                                setVisibilityOfEmailForm(false);
                            }
                            return true;
                        default:
                            return false;
                    }
                }
                return false;
            }
        });
    }
}
 
Example 20
Source File: DialogPreference.java    From MaterialPreferenceLibrary with Apache License 2.0 4 votes vote down vote up
/**
 * Sets the required flags on the dialog window to enable input method window to show up.
 */
private void requestInputMethod(Dialog dialog) {
    Window window = dialog.getWindow();
    window.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
}