Example usage for android.view Window setAttributes

List of usage examples for android.view Window setAttributes

Introduction

In this page you can find the example usage for android.view Window setAttributes.

Prototype

public void setAttributes(WindowManager.LayoutParams a) 

Source Link

Document

Specify custom window attributes.

Usage

From source file:com.orange.ocara.ui.dialog.AudioPlayerDialog.java

@Override
public void onStart() {
    super.onStart();

    // safety check
    if (getDialog() == null)
        return;//from   w  w  w  . j a va2  s . com

    // set dialog width

    Window window = getDialog().getWindow();

    // set "origin" to top left corner
    window.setGravity(Gravity.TOP); //| Gravity.LEFT);

    int width = getResources().getDimensionPixelSize(R.dimen.audioPlayerDialogWidth);
    window.setLayout(width, WindowManager.LayoutParams.WRAP_CONTENT);

    WindowManager.LayoutParams attributes = window.getAttributes();

    Integer argX = getArguments().getInt("x");
    Integer argY = getArguments().getInt("y");
    if (argX != null && argX >= 0) {
        attributes.x = argX;
    }
    if (argY != null && argY >= 0) {
        attributes.y = argY;
    }

    window.setAttributes(attributes);

}

From source file:lvge.com.myapp.modules.shop_management.NotAuthenticationFragment.java

public void show(View view) {
    //        ShopTakePhoto shopTakePhoto = new ShopTakePhoto(ctx);
    dialog = new Dialog(ctx, R.style.ActionSheetDialogStyle);
    //?//from  ww w.  j  av  a 2s.c  om
    inflate = LayoutInflater.from(ctx).inflate(R.layout.layout_menu_shop_manage_img_dialog, null);
    //?
    choosePhoto = (TextView) inflate.findViewById(R.id.from_phone_photo);
    takePhoto = (TextView) inflate.findViewById(R.id.take_photo);
    cancelPhoto = (TextView) inflate.findViewById(R.id.cancel);

    choosePhoto.setOnClickListener(this);
    takePhoto.setOnClickListener(this);
    cancelPhoto.setOnClickListener(this);

    //Dialog
    dialog.setContentView(inflate);
    //??Activity
    Window dialogWindow = dialog.getWindow();
    //Dialog
    dialogWindow.setGravity(Gravity.BOTTOM);
    //
    WindowManager.LayoutParams lp = dialogWindow.getAttributes();
    lp.y = 20;//Dialog??
    //       
    dialogWindow.setAttributes(lp);
    dialog.show();//?
}

From source file:com.xuejian.client.lxp.module.toolbox.im.IMMainActivity.java

private void showActionDialog() {
    final Activity act = this;
    final AlertDialog dialog = new AlertDialog.Builder(act).create();
    View contentView = View.inflate(act, R.layout.dialog_city_detail_action, null);
    Button btn = (Button) contentView.findViewById(R.id.btn_go_plan);
    btn.setText("Talk");
    btn.setOnClickListener(new View.OnClickListener() {
        @Override/*from www .  java  2 s .  c o m*/
        public void onClick(View view) {
            MobclickAgent.onEvent(mContext, "event_create_new_talk");
            startActivityForResult(new Intent(IMMainActivity.this, PickContactsWithCheckboxActivity.class)
                    .putExtra("request", NEW_CHAT_REQUEST_CODE), NEW_CHAT_REQUEST_CODE);
            dialog.dismiss();
        }
    });
    Button btn1 = (Button) contentView.findViewById(R.id.btn_go_share);
    btn1.setText("?");
    btn1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            MobclickAgent.onEvent(mContext, "event_add_new_friend");
            startActivity(new Intent(IMMainActivity.this, AddContactActivity.class));
            dialog.dismiss();
        }
    });
    contentView.findViewById(R.id.btn_cancle).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            dialog.dismiss();
        }
    });
    dialog.show();
    WindowManager windowManager = act.getWindowManager();
    Window window = dialog.getWindow();
    window.setContentView(contentView);
    Display display = windowManager.getDefaultDisplay();
    WindowManager.LayoutParams lp = window.getAttributes();
    lp.width = (int) (display.getWidth()); // 
    window.setAttributes(lp);
    window.setGravity(Gravity.BOTTOM); // ?dialog?
    window.setWindowAnimations(R.style.SelectPicDialog); // 
}

From source file:com.z299studio.pb.Snackbar.java

@Override
public void onStart() {
    super.onStart();
    if (getDialog() != null) {
        Window window = getDialog().getWindow();
        window.setWindowAnimations(R.style.SnackbarAnimation);
        Resources res = getResources();
        int height = (int) (res.getDimension(R.dimen.snackbar_height_single) + 0.5f);
        boolean leftAlign = res.getBoolean(R.bool.snackbar_left_align);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.gravity = Gravity.BOTTOM | Gravity.START;
        lp.x = 0;/* w w w.  j  a  v  a 2  s  .  c om*/
        lp.y = 0;
        lp.height = height;
        if (!leftAlign) {
            Point windowSize = new Point();
            ((WindowManager) getActivity().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay()
                    .getSize(windowSize);
            lp.width = windowSize.x;
        } else {
            lp.height += (int) (res.getDimension(R.dimen.snackbar_horizontal_margin) + 0.5f);
        }
        window.setAttributes(lp);
    }
}

From source file:com.cloverstudio.spika.MyProfileActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case GET_IMAGE_DIALOG:
        mGetImageDialog = new Dialog(MyProfileActivity.this, R.style.TransparentDialogTheme);
        mGetImageDialog.getWindow().setGravity(Gravity.BOTTOM);
        mGetImageDialog.setContentView(R.layout.dialog_get_image);
        WindowManager.LayoutParams params = new WindowManager.LayoutParams();
        Window window = mGetImageDialog.getWindow();
        params.copyFrom(window.getAttributes());
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(params);

        final Button btnGallery = (Button) mGetImageDialog.findViewById(R.id.btnGallery);
        btnGallery.setTypeface(SpikaApp.getTfMyriadProBold(), Typeface.BOLD);
        btnGallery.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                Intent galleryIntent = new Intent(MyProfileActivity.this, CameraCropActivity.class);
                galleryIntent.putExtra("type", "gallery");
                galleryIntent.putExtra("profile", true);
                MyProfileActivity.this.startActivityForResult(galleryIntent, UPDATE_IMAGE_REQUEST_CODE);
                mGetImageDialog.dismiss();

            }/*w  ww  . ja  v a 2s  .  co  m*/
        });

        final Button btnCamera = (Button) mGetImageDialog.findViewById(R.id.btnCamera);
        btnCamera.setTypeface(SpikaApp.getTfMyriadProBold(), Typeface.BOLD);
        btnCamera.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                Intent cameraIntent = new Intent(MyProfileActivity.this, CameraCropActivity.class);
                cameraIntent.putExtra("type", "camera");
                cameraIntent.putExtra("profile", true);
                MyProfileActivity.this.startActivityForResult(cameraIntent, UPDATE_IMAGE_REQUEST_CODE);
                mGetImageDialog.dismiss();

            }
        });

        final Button btnRemovePhoto = (Button) mGetImageDialog.findViewById(R.id.btnRemovePhoto);
        btnRemovePhoto.setTypeface(SpikaApp.getTfMyriadProBold(), Typeface.BOLD);
        btnRemovePhoto.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                mNewAvatarId = "";
                gProfileImage = null;
                Utils.displayImage(mNewAvatarId, mIvProfileImage, mPbLoading, ImageLoader.LARGE,
                        R.drawable.user_stub_large, false);
                mGetImageDialog.dismiss();

            }
        });

        return mGetImageDialog;
    case GET_BIRTHDAY_DIALOG:

        int intMaxYear = Calendar.getInstance().get(Calendar.YEAR);
        int intMaxMonth = Calendar.getInstance().get(Calendar.MONTH);
        int intMaxDay = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);

        mGetBirthdayDialog = new DatePickerDialogWithRange(this, new DatePickerDialog.OnDateSetListener() {
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                Time chosenDate = new Time();
                chosenDate.set(dayOfMonth, monthOfYear, year);
                mNewBirthday = chosenDate.toMillis(true) / 1000;
                CharSequence stringDate = DateFormat.format(getString(R.string.hookup_date_format),
                        chosenDate.toMillis(true));
                mEtUserBirthday.setText(stringDate.toString());
            }
        }, intMaxYear, intMaxMonth, intMaxDay);
        mGetBirthdayDialog.setMessage(getString(R.string.when_is_your_birthday));
        return mGetBirthdayDialog;
    default:
        return null;
    }
}

From source file:info.hl.mediam.MyProfileActivity.java

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case GET_IMAGE_DIALOG:
        mGetImageDialog = new Dialog(MyProfileActivity.this, R.style.TransparentDialogTheme);
        mGetImageDialog.getWindow().setGravity(Gravity.BOTTOM);
        mGetImageDialog.setContentView(R.layout.dialog_get_image);
        WindowManager.LayoutParams params = new WindowManager.LayoutParams();
        Window window = mGetImageDialog.getWindow();
        params.copyFrom(window.getAttributes());
        params.width = WindowManager.LayoutParams.MATCH_PARENT;
        params.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(params);

        final Button btnGallery = (Button) mGetImageDialog.findViewById(R.id.btnGallery);
        btnGallery.setTypeface(MediamApp.getTfMyriadProBold(), Typeface.BOLD);
        btnGallery.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                Intent galleryIntent = new Intent(MyProfileActivity.this, CameraCropActivity.class);
                galleryIntent.putExtra("type", "gallery");
                galleryIntent.putExtra("profile", true);
                MyProfileActivity.this.startActivityForResult(galleryIntent, UPDATE_IMAGE_REQUEST_CODE);
                mGetImageDialog.dismiss();

            }/*from   w  ww . j a v a 2 s . com*/
        });

        final Button btnCamera = (Button) mGetImageDialog.findViewById(R.id.btnCamera);
        btnCamera.setTypeface(MediamApp.getTfMyriadProBold(), Typeface.BOLD);
        btnCamera.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                Intent cameraIntent = new Intent(MyProfileActivity.this, CameraCropActivity.class);
                cameraIntent.putExtra("type", "camera");
                cameraIntent.putExtra("profile", true);
                MyProfileActivity.this.startActivityForResult(cameraIntent, UPDATE_IMAGE_REQUEST_CODE);
                mGetImageDialog.dismiss();

            }
        });

        final Button btnRemovePhoto = (Button) mGetImageDialog.findViewById(R.id.btnRemovePhoto);
        btnRemovePhoto.setTypeface(MediamApp.getTfMyriadProBold(), Typeface.BOLD);
        btnRemovePhoto.setOnClickListener(new OnClickListener() {

            public void onClick(View v) {

                mNewAvatarId = "";
                gProfileImage = null;
                Utils.displayImage(mNewAvatarId, mIvProfileImage, mPbLoading, ImageLoader.LARGE,
                        R.drawable.user_stub_large, false);
                mGetImageDialog.dismiss();

            }
        });

        return mGetImageDialog;
    case GET_BIRTHDAY_DIALOG:

        int intMaxYear = Calendar.getInstance().get(Calendar.YEAR);
        int intMaxMonth = Calendar.getInstance().get(Calendar.MONTH);
        int intMaxDay = Calendar.getInstance().get(Calendar.DAY_OF_MONTH);

        mGetBirthdayDialog = new DatePickerDialogWithRange(this, new DatePickerDialog.OnDateSetListener() {
            public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                Time chosenDate = new Time();
                chosenDate.set(dayOfMonth, monthOfYear, year);
                mNewBirthday = chosenDate.toMillis(true) / 1000;
                CharSequence stringDate = DateFormat.format(getString(R.string.hookup_date_format),
                        chosenDate.toMillis(true));
                mEtUserBirthday.setText(stringDate.toString());
            }
        }, intMaxYear, intMaxMonth, intMaxDay);
        mGetBirthdayDialog.setMessage(getString(R.string.when_is_your_birthday));
        return mGetBirthdayDialog;
    default:
        return null;
    }
}

From source file:com.slushpupie.deskclock.DeskClock.java

@Override
public void onClick(View v) {
    handler.removeCallbacks(runSetBrightness);

    Window window = getWindow();

    LayoutParams layoutParams = window.getAttributes();
    // Setting to 0 turns the screen off, so dont allow that
    if (prefsTempScreenBrightness <= 100 && prefsTempScreenBrightness > 0)
        layoutParams.screenBrightness = (prefsTempScreenBrightness / 100.0f);
    if (prefsTempScreenBrightness < 1)
        layoutParams.screenBrightness = 0.01f;
    window.setAttributes(layoutParams);

    handler.postDelayed(runSetBrightness, 5000);
}

From source file:com.mci.firstidol.activity.MainActivity.java

@TargetApi(19)
private void setTranslucentStatus(boolean on) {
    Window win = getWindow();
    WindowManager.LayoutParams winParams = win.getAttributes();
    final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
    if (on) {//from w ww. j a v a 2 s. c o  m
        winParams.flags |= bits;
    } else {
        winParams.flags &= ~bits;
    }
    win.setAttributes(winParams);
}

From source file:com.example.levelup.core.app.PaymentCodeFragment.java

/**
 * Forces the screen to be full-brightness and not dim.
 * //  w  w  w  .  ja v  a  2  s  . c o m
 * @param isFullBrightness if true, sets the flags that force the screen to be fully bright and
 *        kept on. False clears the flags.
 */
private void setForceFullBrightness(boolean isFullBrightness) {
    Window window = getActivity().getWindow();

    // Bail if the window has gone away.
    if (window == null) {
        return;
    }

    if (isFullBrightness) {
        window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    } else {
        window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
    }

    LayoutParams attributes = window.getAttributes();

    if (isFullBrightness) {
        attributes.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_FULL;
    } else {
        attributes.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_OFF;
    }

    window.setAttributes(attributes);
}

From source file:com.cloverstudio.spika.GroupProfileActivity.java

private void getImageDialog() {
    final Dialog imageDialog = new Dialog(GroupProfileActivity.this, R.style.TransparentDialogTheme);
    imageDialog.getWindow().setGravity(Gravity.BOTTOM);
    imageDialog.setContentView(R.layout.dialog_get_image);
    WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();
    Window window = imageDialog.getWindow();
    layoutParams.copyFrom(window.getAttributes());
    layoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
    layoutParams.height = WindowManager.LayoutParams.WRAP_CONTENT;
    window.setAttributes(layoutParams);//from   w w w.  j  ava  2s  . c  o m

    final Button btnGallery = (Button) imageDialog.findViewById(R.id.btnGallery);
    btnGallery.setTypeface(SpikaApp.getTfMyriadProBold(), Typeface.BOLD);
    btnGallery.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            Intent galleryIntent = new Intent(GroupProfileActivity.this, CameraCropActivity.class);
            galleryIntent.putExtra("type", "gallery");
            galleryIntent.putExtra("groupUpdate", true);
            GroupProfileActivity.this.startActivityForResult(galleryIntent, UPDATE_IMAGE_REQUEST_CODE);
            imageDialog.dismiss();

        }
    });

    final Button btnCamera = (Button) imageDialog.findViewById(R.id.btnCamera);
    btnCamera.setTypeface(SpikaApp.getTfMyriadProBold(), Typeface.BOLD);
    btnCamera.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            Intent cameraIntent = new Intent(GroupProfileActivity.this, CameraCropActivity.class);
            cameraIntent.putExtra("type", "camera");
            cameraIntent.putExtra("groupUpdate", true);
            GroupProfileActivity.this.startActivityForResult(cameraIntent, UPDATE_IMAGE_REQUEST_CODE);
            imageDialog.dismiss();

        }
    });

    final Button btnRemovePhoto = (Button) imageDialog.findViewById(R.id.btnRemovePhoto);
    btnRemovePhoto.setTypeface(SpikaApp.getTfMyriadProBold(), Typeface.BOLD);
    btnRemovePhoto.setOnClickListener(new OnClickListener() {

        public void onClick(View v) {

            mGroupAvatarId = "";
            gGroupImage = null;
            Utils.displayImage(mGroupAvatarId, mIvGroupImage, mPbLoading, ImageLoader.LARGE,
                    R.drawable.group_stub_large, false);
            imageDialog.dismiss();

        }
    });

    imageDialog.show();
}