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:info.hl.mediam.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);

    final Button btnGallery = (Button) imageDialog.findViewById(R.id.btnGallery);
    btnGallery.setTypeface(MediamApp.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();/*from   ww w. j  av a2  s .  c  om*/

        }
    });

    final Button btnCamera = (Button) imageDialog.findViewById(R.id.btnCamera);
    btnCamera.setTypeface(MediamApp.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(MediamApp.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();
}

From source file:com.heneryh.aquanotes.ui.livestock.ContentFragment.java

/** Toggle whether the system UI (status bar / system bar) is visible.
 *  This also toggles the action bar visibility.
 * @param show True to show the system UI, false to hide it.
 *//*from   w w  w . jav  a 2s  . c o m*/
void setSystemUiVisible(boolean show) {
    mSystemUiVisible = show;

    Window window = getActivity().getWindow();
    WindowManager.LayoutParams winParams = window.getAttributes();
    View view = getView();
    //        ActionBar actionBar = getActivity().getActionBar();

    if (show) {
        // Show status bar (remove fullscreen flag)
        window.setFlags(0, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        // Show system bar
        view.setSystemUiVisibility(View.STATUS_BAR_VISIBLE);
        // Show action bar
        //            actionBar.show();
    } else {
        // Add fullscreen flag (hide status bar)
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
        // Hide system bar
        view.setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
        // Hide action bar
        //            actionBar.hide();
    }
    window.setAttributes(winParams);
}

From source file:kz.qobyzbook.activities.DMPlayerBaseActivity.java

private void setTranslucentStatus(boolean on) {
    Log.d(TAG, "setTranslucentStatus()");
    Window win = getWindow();
    WindowManager.LayoutParams winParams = win.getAttributes();
    final int bits = WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
    if (on) {/*from   w  w  w .jav  a2 s .  c o  m*/
        winParams.flags |= bits;
    } else {
        winParams.flags &= ~bits;
    }
    win.setAttributes(winParams);
}

From source file:com.github.piasy.dialogfragmentanywhere.BaseDialogFragment.java

void anchorDialog() {
    final Bundle args = getArguments();
    if (args == null || getDialog() == null) {
        return;//  w  w w  .j av  a 2 s . com
    }

    final Window window = getDialog().getWindow();
    final WindowManager.LayoutParams params = window.getAttributes();

    int anchorX = args.getInt(ANCHOR_VIEW_X);
    int anchorY = args.getInt(ANCHOR_VIEW_Y);
    int anchorWidth = args.getInt(ANCHOR_VIEW_WIDTH);
    int anchorHeight = args.getInt(ANCHOR_VIEW_HEIGHT);
    int dialogWidth = window.getDecorView().getWidth();
    int dialogHeight = window.getDecorView().getHeight();
    int locate = args.getInt(LOCATE_TO_ANCHOR);
    int offsetX = args.getInt(OFFSET_X);
    int offsetY = args.getInt(OFFSET_Y);

    switch (locate) {
    case LOCATE_LEFT:
        params.x = anchorX - dialogWidth + offsetX;
        params.y = anchorY - Math.abs(dialogHeight - anchorHeight) / 2 - getStatusBarHeight() + offsetY;
        break;
    case LOCATE_RIGHT:
        params.x = anchorX + anchorWidth + offsetX;
        params.y = anchorY - Math.abs(dialogHeight - anchorHeight) / 2 - getStatusBarHeight() + offsetY;
        break;
    case LOCATE_BELOW:
        params.x = anchorX - Math.abs(dialogWidth - anchorWidth) / 2 + offsetX;
        params.y = anchorY + anchorHeight - getStatusBarHeight() + offsetY;
        break;
    case LOCATE_ABOVE:
        params.x = anchorX - Math.abs(dialogWidth - anchorWidth) / 2 + offsetX;
        params.y = anchorY - dialogHeight - getStatusBarHeight() + offsetY;
    default:
        break;
    }
    window.setAttributes(params);
}

From source file:com.github.shareme.gwsmaterialuikit.library.material.app.Dialog.java

/**
 * Set the dim amount of the region outside this Dialog.
 * @param amount The dim amount in [0..1].
 * @return The Dialog for chaining methods.
 *///from  w w w.j  av a  2s  . c o m
public Dialog dimAmount(float amount) {
    Window window = getWindow();
    if (amount > 0f) {
        window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
        WindowManager.LayoutParams lp = window.getAttributes();
        lp.dimAmount = amount;
        window.setAttributes(lp);
    } else
        window.clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);
    return this;
}

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 {/*www . j a va 2  s. co 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:com.mobiletin.inputmethod.indic.LatinIME.java

private void showOptionDialog(final AlertDialog dialog) {
    final IBinder windowToken = mKeyboardSwitcher.getMainKeyboardView().getWindowToken();
    if (windowToken == null) {
        return;//from   w ww .j a v a2s  .co  m
    }

    final Window window = dialog.getWindow();
    final WindowManager.LayoutParams lp = window.getAttributes();
    lp.token = windowToken;
    lp.type = WindowManager.LayoutParams.TYPE_APPLICATION_ATTACHED_DIALOG;
    window.setAttributes(lp);
    window.addFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);

    mOptionsDialog = dialog;
    dialog.show();
}

From source file:com.almalence.opencam.ApplicationScreen.java

public void setScreenBrightness(boolean setMax) {
    Window window = getWindow();
    WindowManager.LayoutParams layoutpars = window.getAttributes();

    // Set the brightness of this window
    if (setMax)/*  ww  w  .j a va  2  s  .  com*/
        layoutpars.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_FULL;
    else
        layoutpars.screenBrightness = WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE;

    // Apply attribute changes to this window
    window.setAttributes(layoutpars);
}

From source file:com.dish.browser.activity.BrowserActivity.java

/**
 * turns on fullscreen mode in the app// ww  w . j  a v a 2 s  .  c om
 *
 * @param enabled
 *            whether to enable fullscreen or not
 */
public void setFullscreen(boolean enabled) {
    Window win = getWindow();
    WindowManager.LayoutParams winParams = win.getAttributes();
    final int bits = WindowManager.LayoutParams.FLAG_FULLSCREEN;
    if (enabled) {
        winParams.flags |= bits;
    } else {
        winParams.flags &= ~bits;
        if (mCustomView != null) {
            mCustomView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
        } else {
            mBrowserFrame.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
        }
    }
    win.setAttributes(winParams);
}

From source file:com.android.calendar.EventInfoFragment.java

private void applyDialogParams() {
    Dialog dialog = getDialog();/*from   w  w w. j a  v a2  s .  c  om*/
    dialog.setCanceledOnTouchOutside(true);

    Window window = dialog.getWindow();
    window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND);

    WindowManager.LayoutParams a = window.getAttributes();
    a.dimAmount = .4f;

    a.width = mDialogWidth;
    a.height = mDialogHeight;

    // On tablets , do smart positioning of dialog
    // On phones , use the whole screen

    if (mX != -1 || mY != -1) {
        a.x = mX - mDialogWidth / 2;
        a.y = mY - mDialogHeight / 2;
        if (a.y < mMinTop) {
            a.y = mMinTop + DIALOG_TOP_MARGIN;
        }
        a.gravity = Gravity.LEFT | Gravity.TOP;
    }
    window.setAttributes(a);
}