Example usage for android.view Window getAttributes

List of usage examples for android.view Window getAttributes

Introduction

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

Prototype

public final WindowManager.LayoutParams getAttributes() 

Source Link

Document

Retrieve the current window attributes associated with this panel.

Usage

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

@Override
protected Dialog onCreateDialog(int id) {
    switch (id) {
    case GET_IMAGE_DIALOG:
        mGetImageDialog = new Dialog(CreateGroupActivity.this, R.style.TransparentDialogTheme);
        mGetImageDialog.getWindow().setGravity(Gravity.BOTTOM);
        mGetImageDialog.setContentView(R.layout.dialog_get_image);

        // Grab the window of the dialog, and change the width
        WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
        Window window = mGetImageDialog.getWindow();
        lp.copyFrom(window.getAttributes());
        // This makes the dialog take up the full width
        lp.width = WindowManager.LayoutParams.MATCH_PARENT;
        lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
        window.setAttributes(lp);//from  w  ww.  j  a  v a2s .  co m

        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(CreateGroupActivity.this, CameraCropActivity.class);
                galleryIntent.putExtra("type", "gallery");
                galleryIntent.putExtra("createGroup", true);
                CreateGroupActivity.this.startActivity(galleryIntent);
                mGetImageDialog.dismiss();

            }
        });

        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(CreateGroupActivity.this, CameraCropActivity.class);
                cameraIntent.putExtra("type", "camera");
                cameraIntent.putExtra("createGroup", true);
                CreateGroupActivity.this.startActivity(cameraIntent);
                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) {

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

            }
        });

        return mGetImageDialog;
    default:
        return null;
    }
}

From source file:ab.util.AbDialogUtil.java

/**
 * AlertDialog ??//  ww w .ja  v  a 2  s  .com
 */
public static AlertDialog getAlertDialogWithoutRemove(Context mContext, int layout, double showWidth) {
    final AlertDialog alerDialog = new AlertDialog.Builder(mContext).create();
    alerDialog.show();
    alerDialog.setCanceledOnTouchOutside(true);
    Window window = alerDialog.getWindow();
    // ??
    int height = ScreenUtils.getScreenHeight(mContext);
    int width = ScreenUtils.getScreenWidth(mContext);

    WindowManager.LayoutParams params = window.getAttributes();
    params.width = (int) (width * showWidth);
    params.gravity = Gravity.CENTER_HORIZONTAL;
    alerDialog.onWindowAttributesChanged(params);
    window.setContentView(layout);
    return alerDialog;
}

From source file:co.codecrunch.musicplayerlite.activities.MusicPlayerBaseActivity.java

private void setTranslucentStatus(boolean on) {
    Window win = getWindow();
    WindowManager.LayoutParams winParams = win.getAttributes();
    final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
    if (on) {//from   www  .  ja va  2  s .co m
        winParams.flags |= bits;
    } else {
        winParams.flags &= ~bits;
    }
    win.setAttributes(winParams);
}

From source file:org.getlantern.firetweet.activity.support.QuickSearchBarActivity.java

private void updateWindowAttributes() {
    final Window window = getWindow();
    final WindowManager.LayoutParams attributes = window.getAttributes();
    attributes.gravity = Gravity.TOP | Gravity.CENTER_HORIZONTAL;
    attributes.y = mSystemWindowsInsets.top;
    window.setAttributes(attributes);//from   w ww  .ja  v a  2  s .com
}

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 v  a  2 s  . c o m

    // 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: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);/*from ww w  .ja va  2  s .c  o m*/

    handler.postDelayed(runSetBrightness, 5000);
}

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

private void setScreenLock(int keepOn, int screenBrightness, int buttonBrightness) {
    Window window = getWindow();

    LayoutParams layoutParams = window.getAttributes();
    Field fButtonBrightness = null;
    try {//from   w ww . j  ava2 s  . c o m
        fButtonBrightness = layoutParams.getClass().getField("buttonBrightness");
    } catch (NoSuchFieldException e) {

    }

    if (keepOn > 0) {

        if (keepOn == 1) {
            // Auto-brightness
            layoutParams.screenBrightness = -1.0f;
            try {
                if (fButtonBrightness != null)
                    fButtonBrightness.set(layoutParams, -1.0f);
            } catch (IllegalAccessException e) {

            }
        } else if (keepOn == 2) {
            // Manual brightness

            // Setting to 0 turns the screen off, so dont allow that
            if (prefsScreenBrightness <= 100 && prefsScreenBrightness > 0)
                layoutParams.screenBrightness = (prefsScreenBrightness / 100.0f);
            if (prefsScreenBrightness < 1)
                layoutParams.screenBrightness = 0.01f;
            try {
                if (fButtonBrightness != null && prefsButtonBrightness <= 100 && prefsButtonBrightness >= 0)
                    fButtonBrightness.set(layoutParams, (prefsButtonBrightness / 100.0f));
            } catch (IllegalAccessException e) {

            }
        } else {
            Log.e(LOG_TAG, "Unknown keepOn value!");
            return;
        }
        window.setAttributes(layoutParams);
        window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        window.addFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    } else {
        // Disable KEEP_SCREEN_ON

        try {
            if (fButtonBrightness != null)
                fButtonBrightness.set(layoutParams, -1.0f);
        } catch (IllegalAccessException e) {

        }
        layoutParams.screenBrightness = -1.0f;
        window.setAttributes(layoutParams);
        window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
    }

}

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);
    //?// w  w  w .ja v a 2s  . c o m
    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.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);//from  w ww  . j  a va  2 s .c  o  m

        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();

            }
        });

        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);//from  w  w  w  . jav  a  2s.  c  om

        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();

            }
        });

        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;
    }
}