Example usage for android.view Window setBackgroundDrawable

List of usage examples for android.view Window setBackgroundDrawable

Introduction

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

Prototype

public abstract void setBackgroundDrawable(Drawable drawable);

Source Link

Document

Change the background of this window to a custom Drawable.

Usage

From source file:com.xiangqin.app.dialog.AbSampleDialogFragment.java

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    Window window = getDialog().getWindow();
    WindowManager.LayoutParams attributes = window.getAttributes();
    attributes.gravity = mGravity;//from   ww w  . jav a2s .  com
    window.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
    window.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#88818181")));
    super.onActivityCreated(savedInstanceState);
}

From source file:org.mariotaku.twidere.util.ThemeUtils.java

public static void applyWindowBackground(@NonNull Context context, @NonNull Window window, int theme,
        String option, int alpha) {
    if (isWindowFloating(context, theme))
        return;/*from ww w.java  2  s.co  m*/
    final int normalTheme = getThemeResource(theme);
    if (VALUE_THEME_BACKGROUND_TRANSPARENT.equals(option)) {
        window.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WALLPAPER);
        window.setBackgroundDrawable(getWindowBackgroundFromThemeApplyAlpha(context, normalTheme, alpha));
    } else if (VALUE_THEME_BACKGROUND_SOLID.equals(option)) {
        window.setBackgroundDrawable(new ColorDrawable(isDarkTheme(normalTheme) ? Color.BLACK : Color.WHITE));
    } else {
        window.setBackgroundDrawable(getWindowBackgroundFromTheme(context, normalTheme));
    }
}

From source file:com.nextgis.ngm_clink_monitoring.dialogs.YesNoDialog.java

@NonNull
@Override//from w w w . j  a  va2s  .  c  o  m
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Idea from here
    // http://thanhcs.blogspot.ru/2014/10/android-custom-dialog-fragment.html
    Dialog dialog = new Dialog(getActivity());

    Window window = dialog.getWindow();
    window.requestFeature(Window.FEATURE_NO_TITLE);
    window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
    window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

    dialog.setContentView(R.layout.dialog_yes_no);

    mIcon = (ImageView) dialog.findViewById(R.id.title_icon);
    mTitle = (TextView) dialog.findViewById(R.id.title_text);

    mDialogBodyScroll = (ScrollView) dialog.findViewById(R.id.dialog_body_scroll);
    mDialogBodyLayoutScrolled = (LinearLayout) dialog.findViewById(R.id.dialog_body_scrolled);
    mDialogBodyLayout = (LinearLayout) dialog.findViewById(R.id.dialog_body);

    mButtons = (TableLayout) dialog.findViewById(R.id.dialog_buttons_yn);
    mBtnPositive = (Button) dialog.findViewById(R.id.dialog_btn_positive_yn);
    mBtnNegative = (Button) dialog.findViewById(R.id.dialog_btn_negative_yn);

    if (null != mIconId) {
        mIcon.setVisibility(View.VISIBLE);
        mIcon.setImageResource(mIconId);
    }

    if (null != mTitleId) {
        mTitle.setText(mTitleId);
    }
    if (null != mTitleText) {
        mTitle.setText(mTitleText);
    }

    if (null != mMessageId) {
        setMessageView();
        mMessage.setText(mMessageId);
    }
    if (null != mMessageText) {
        setMessageView();
        mMessage.setText(mMessageText);
    }

    if (null != mView) {
        if (mAddScrollForView) {
            mDialogBodyScroll.setVisibility(View.VISIBLE);
            mDialogBodyLayoutScrolled.addView(mView);
        } else {
            mDialogBodyLayout.setVisibility(View.VISIBLE);
            mDialogBodyLayout.addView(mView);
        }
    }

    if (null != mPositiveTextId) {
        mButtons.setVisibility(View.VISIBLE);
        mBtnPositive.setVisibility(View.VISIBLE);
        mBtnPositive.setText(mPositiveTextId);
    }
    if (null != mPositiveText) {
        mButtons.setVisibility(View.VISIBLE);
        mBtnPositive.setVisibility(View.VISIBLE);
        mBtnPositive.setText(mPositiveText);
    }

    if (null != mNegativeTextId) {
        mButtons.setVisibility(View.VISIBLE);
        mBtnNegative.setVisibility(View.VISIBLE);
        mBtnNegative.setText(mNegativeTextId);
    }
    if (null != mNegativeText) {
        mButtons.setVisibility(View.VISIBLE);
        mBtnNegative.setVisibility(View.VISIBLE);
        mBtnNegative.setText(mNegativeText);
    }

    if (null != mOnPositiveClickedListener) {
        mButtons.setVisibility(View.VISIBLE);
        mBtnPositive.setVisibility(View.VISIBLE);
        mBtnPositive.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != mOnPositiveClickedListener) {
                    mOnPositiveClickedListener.onPositiveClicked();
                }
                dismiss();
            }
        });
    }

    if (null != mOnNegativeClickedListener) {
        mButtons.setVisibility(View.VISIBLE);
        mBtnNegative.setVisibility(View.VISIBLE);
        mBtnNegative.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (null != mOnNegativeClickedListener) {
                    mOnNegativeClickedListener.onNegativeClicked();
                }
                dismiss();
            }
        });
    }

    return dialog;
}

From source file:com.nextgis.libngui.dialog.StyledDialogFragment.java

@NonNull
@Override/*from   w  w  w  .java  2 s. c  o  m*/
public Dialog onCreateDialog(Bundle savedInstanceState) {
    // Idea from here
    // http://thanhcs.blogspot.ru/2014/10/android-custom-dialog-fragment.html

    Dialog dialog = new Dialog(mContext);

    Window window = dialog.getWindow();
    window.requestFeature(Window.FEATURE_NO_TITLE);
    window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
            WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
    window.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

    return dialog;
}

From source file:com.imagine.BaseActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    Window win = getWindow();
    win.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
            | WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR);
    super.onCreate(savedInstanceState);
    win.setBackgroundDrawable(null);
    win.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED
            | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
    if (android.os.Build.VERSION.SDK_INT >= 11) {
        // NativeActivity explicitly sets the window format to RGB_565, this is fine in Android 2.3 since we default to that
        // and call setFormat ourselves, but in >= 3.0 we only use ANativeWindow_setBuffersGeometry so set the format back to
        // the default value to avoid a spurious surface destroy & create the next time the window flags are set since it may
        // cause the screen to flash
        win.setFormat(PixelFormat.UNKNOWN);
    }//w w w .  j  av  a 2s  .  c o  m
    // get rid of NativeActivity's view and layout listener, then add our custom view
    View nativeActivityView = findViewById(android.R.id.content);
    nativeActivityView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
    View contentView;
    if (android.os.Build.VERSION.SDK_INT >= 24)
        contentView = new ContentViewV24(this);
    else if (android.os.Build.VERSION.SDK_INT >= 16)
        contentView = new ContentViewV16(this);
    else
        contentView = new ContentViewV9(this);
    setContentView(contentView);
    contentView.requestFocus();
}

From source file:net.lp.actionbarpoirot.helpers.ActivityHelper.java

/**
 * On older devices, fix the background.
 * // w w w  . j a v  a  2s  .c  om
 * @param window
 */
public void fixBackground(Window window) {
    if (!UiUtilities.hasHoneycombOrUp()) {// BUGFIXED lp:791976: For
        // Honeycomb devices, if not
        // covered by UI elements, the
        // background would actually
        // become garbled and
        // transparent.
        window.setBackgroundDrawable(null);
    }
}

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

private void setupSlidingMenu() {
    if (mSlidingMenu == null)
        return;//from  w w w . j  a  v a 2 s .  c  o  m
    final Resources res = getResources();
    final int marginThreshold = res.getDimensionPixelSize(R.dimen.default_sliding_menu_margin_threshold);
    final boolean relativeBehindWidth = res.getBoolean(R.bool.relative_behind_width);
    mSlidingMenu.setMode(SlidingMenu.LEFT_RIGHT);
    mSlidingMenu.setShadowWidthRes(R.dimen.default_sliding_menu_shadow_width);
    mSlidingMenu.setShadowDrawable(R.drawable.shadow_left);
    mSlidingMenu.setSecondaryShadowDrawable(R.drawable.shadow_right);
    if (relativeBehindWidth) {
        mSlidingMenu.setBehindOffsetRes(R.dimen.drawer_offset_home);
    } else {
        mSlidingMenu.setBehindWidthRes(R.dimen.drawer_width_home);
    }
    mSlidingMenu.setTouchmodeMarginThreshold(marginThreshold);
    mSlidingMenu.setFadeDegree(0.5f);
    mSlidingMenu.setMenu(R.layout.drawer_home_accounts);
    mSlidingMenu.setSecondaryMenu(R.layout.drawer_home_quick_menu);
    mSlidingMenu.setOnOpenedListener(this);
    mSlidingMenu.setOnClosedListener(this);
    mLeftDrawerContainer = (LeftDrawerFrameLayout) mSlidingMenu.getMenu()
            .findViewById(R.id.left_drawer_container);
    mRightDrawerContainer = (RightDrawerFrameLayout) mSlidingMenu.getSecondaryMenu()
            .findViewById(R.id.right_drawer_container);
    final boolean isTransparentBackground = ThemeUtils.isTransparentBackground(this);
    mLeftDrawerContainer.setClipEnabled(isTransparentBackground);
    mLeftDrawerContainer.setScrollScale(mSlidingMenu.getBehindScrollScale());
    mRightDrawerContainer.setClipEnabled(isTransparentBackground);
    mRightDrawerContainer.setScrollScale(mSlidingMenu.getBehindScrollScale());
    mSlidingMenu.setBehindCanvasTransformer(new ListenerCanvasTransformer(this));
    final Window window = getWindow();
    final Drawable windowBackground = ThemeUtils.getWindowBackground(this, getCurrentThemeResourceId());
    ViewAccessor.setBackground(mSlidingMenu.getContent(), windowBackground);
    window.setBackgroundDrawable(new EmptyDrawable(windowBackground));
}

From source file:org.mariotaku.twidere.activity.support.HomeActivity.java

private void setupSlidingMenu() {
    if (mSlidingMenu == null)
        return;// w w w  .  ja  va 2 s .c  o  m
    final Resources res = getResources();
    final int marginThreshold = res.getDimensionPixelSize(R.dimen.default_sliding_menu_margin_threshold);
    final boolean relativeBehindWidth = res.getBoolean(R.bool.relative_behind_width);
    mSlidingMenu.setMode(SlidingMenu.LEFT);
    mSlidingMenu.setShadowWidthRes(R.dimen.default_sliding_menu_shadow_width);
    mSlidingMenu.setShadowDrawable(R.drawable.shadow_left);
    mSlidingMenu.setSecondaryShadowDrawable(R.drawable.shadow_right);
    if (relativeBehindWidth) {
        mSlidingMenu.setBehindOffsetRes(R.dimen.drawer_offset_home);
    } else {
        mSlidingMenu.setBehindWidthRes(R.dimen.drawer_width_home);
    }
    mSlidingMenu.setTouchmodeMarginThreshold(marginThreshold);
    mSlidingMenu.setFadeDegree(0.5f);
    mSlidingMenu.setMenu(R.layout.drawer_home_accounts);
    mSlidingMenu.setOnOpenedListener(this);
    mSlidingMenu.setOnClosedListener(this);
    mLeftDrawerContainer = (LeftDrawerFrameLayout) mSlidingMenu.getMenu()
            .findViewById(R.id.left_drawer_container);
    final boolean isTransparentBackground = ThemeUtils
            .isTransparentBackground(getCurrentThemeBackgroundOption());
    mLeftDrawerContainer.setClipEnabled(isTransparentBackground);
    mLeftDrawerContainer.setScrollScale(mSlidingMenu.getBehindScrollScale());
    mSlidingMenu.setBehindCanvasTransformer(new ListenerCanvasTransformer(this));
    final Window window = getWindow();
    ThemeUtils.applyWindowBackground(this, mSlidingMenu.getContent(), getCurrentThemeResourceId(),
            getThemeBackgroundOption(), getCurrentThemeBackgroundAlpha());
    window.setBackgroundDrawable(new EmptyDrawable());

    mSlidingMenu.addIgnoredView(mActionBarContainer);
}

From source file:de.vanita5.twittnuker.activity.support.HomeActivity.java

private void setupSlidingMenu() {
    if (mSlidingMenu == null)
        return;//from   w  w  w .  j a va2s .c  om
    final int marginThreshold = getResources()
            .getDimensionPixelSize(R.dimen.default_sliding_menu_margin_threshold);
    mSlidingMenu.setMode(SlidingMenu.LEFT_RIGHT);
    mSlidingMenu.setShadowWidthRes(R.dimen.default_sliding_menu_shadow_width);
    mSlidingMenu.setShadowDrawable(R.drawable.shadow_left);
    mSlidingMenu.setSecondaryShadowDrawable(R.drawable.shadow_right);
    mSlidingMenu.setBehindWidthRes(R.dimen.drawer_width_home);
    mSlidingMenu.setTouchmodeMarginThreshold(marginThreshold);
    mSlidingMenu.setFadeDegree(0.5f);
    mSlidingMenu.attachToActivity(this, SlidingMenu.SLIDING_WINDOW);
    mSlidingMenu.setMenu(R.layout.drawer_home_accounts);
    mSlidingMenu.setSecondaryMenu(R.layout.drawer_home_quick_menu);
    mSlidingMenu.setOnOpenedListener(this);
    mSlidingMenu.setOnClosedListener(this);
    mLeftDrawerContainer = (LeftDrawerFrameLayout) mSlidingMenu.getMenu()
            .findViewById(R.id.left_drawer_container);
    mRightDrawerContainer = (RightDrawerFrameLayout) mSlidingMenu.getSecondaryMenu()
            .findViewById(R.id.right_drawer_container);
    final boolean isTransparentBackground = ThemeUtils.isTransparentBackground(this);
    mLeftDrawerContainer.setClipEnabled(isTransparentBackground);
    mLeftDrawerContainer.setScrollScale(mSlidingMenu.getBehindScrollScale());
    mRightDrawerContainer.setClipEnabled(isTransparentBackground);
    mRightDrawerContainer.setScrollScale(mSlidingMenu.getBehindScrollScale());
    mSlidingMenu.setBehindCanvasTransformer(new ListenerCanvasTransformer(this));
    final Window window = getWindow();
    if (isTransparentBackground) {
        final Drawable windowBackground = ThemeUtils.getWindowBackground(this, getCurrentThemeResourceId());
        ViewAccessor.setBackground(mSlidingMenu.getContent(), windowBackground);
        window.setBackgroundDrawable(new EmptyDrawable());
    } else {
        window.setBackgroundDrawable(null);
    }
}

From source file:org.chromium.chrome.browser.payments.ui.PaymentRequestUI.java

/**
 * Builds the UI for PaymentRequest.//from w  w w . j  av  a 2 s  .  co  m
 *
 * @param activity        The activity on top of which the UI should be displayed.
 * @param client          The consumer of the PaymentRequest UI.
 * @param requestShipping Whether the UI should show the shipping address and option selection.
 * @param requestContact  Whether the UI should show the email address and phone number
 *                        selection.
 * @param canAddCards     Whether the UI should show the [+ADD CARD] button. This can be false,
 *                        for example, when the merchant does not accept credit cards, so
 *                        there's no point in adding cards within PaymentRequest UI.
 * @param title           The title to show at the top of the UI. This can be, for example, the
 *                        <title> of the merchant website. If the string is too long for
 *                        UI, it elides at the end.
 * @param origin          The origin (part of URL) to show under the title. For example,
 *                        "https://shop.momandpop.com". If the origin is too long for the UI, it
 *                        should elide according to:
 * https://www.chromium.org/Home/chromium-security/enamel#TOC-Eliding-Origin-Names-And-Hostnames
 */
public PaymentRequestUI(Activity activity, Client client, boolean requestShipping, boolean requestContact,
        boolean canAddCards, String title, String origin) {
    mContext = activity;
    mClient = client;
    mRequestShipping = requestShipping;
    mRequestContactDetails = requestContact;
    mAnimatorTranslation = activity.getResources().getDimensionPixelSize(R.dimen.payments_ui_translation);

    mErrorView = (PaymentRequestUiErrorView) LayoutInflater.from(mContext)
            .inflate(R.layout.payment_request_error, null);
    mErrorView.initialize(title, origin);

    mReadyToPayNotifierForTest = new NotifierForTest(new Runnable() {
        @Override
        public void run() {
            if (sObserverForTest != null && isAcceptingUserInput() && mPayButton.isEnabled()) {
                sObserverForTest.onPaymentRequestReadyToPay(PaymentRequestUI.this);
            }
        }
    });

    // This callback will be fired if mIsClientCheckingSelection is true.
    mUpdateSectionsCallback = new Callback<PaymentInformation>() {
        @Override
        public void onResult(PaymentInformation result) {
            mIsClientCheckingSelection = false;
            updateOrderSummarySection(result.getShoppingCart());
            if (mRequestShipping) {
                updateSection(TYPE_SHIPPING_ADDRESSES, result.getShippingAddresses());
                updateSection(TYPE_SHIPPING_OPTIONS, result.getShippingOptions());
            }
            if (mRequestContactDetails) {
                updateSection(TYPE_CONTACT_DETAILS, result.getContactDetails());
            }
            updateSection(TYPE_PAYMENT_METHODS, result.getPaymentMethods());
            if (mShippingAddressSectionInformation.getSelectedItem() == null) {
                expand(mShippingAddressSection);
            } else {
                expand(null);
            }
            updatePayButtonEnabled();
            notifySelectionChecked();
        }
    };

    mRequestView = (ViewGroup) LayoutInflater.from(mContext).inflate(R.layout.payment_request, null);
    prepareRequestView(activity, title, origin, canAddCards);

    // To handle the specced animations, the dialog is entirely contained within a translucent
    // FrameLayout.  This could eventually be converted to a real BottomSheetDialog, but that
    // requires exploration of how interactions would work when the dialog can be sent back and
    // forth between the peeking and expanded state.
    mFullContainer = new FrameLayout(mContext);
    mFullContainer.setBackgroundColor(
            ApiCompatibilityUtils.getColor(mContext.getResources(), R.color.payments_ui_scrim));
    FrameLayout.LayoutParams bottomSheetParams = new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    bottomSheetParams.gravity = Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM;
    mFullContainer.addView(mRequestView, bottomSheetParams);

    mEditorView = new EditorView(activity, sObserverForTest);
    mCardEditorView = new EditorView(activity, sObserverForTest);

    // Set up the dialog.
    mDialog = new AlwaysDismissedDialog(activity, R.style.DialogWhenLarge);
    mDialog.setOnDismissListener(this);
    mDialog.addContentView(mFullContainer,
            new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));

    Window dialogWindow = mDialog.getWindow();
    dialogWindow.setGravity(Gravity.CENTER);
    dialogWindow.setLayout(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
    dialogWindow.setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
}