Example usage for android.view Window setGravity

List of usage examples for android.view Window setGravity

Introduction

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

Prototype

public void setGravity(int gravity) 

Source Link

Document

Set the gravity of the window, as per the Gravity constants.

Usage

From source file:com.daxstudio.sa.base.android.BaseDialogFragment.java

@Override
public void onStart() {
    super.onStart();
    // Less dimmed background; see http://stackoverflow.com/q/13822842/56285
    final Window window = getDialog().getWindow();
    final WindowManager.LayoutParams params = window.getAttributes();
    params.dimAmount = getDimAmount(); // dim only a little bit
    window.setAttributes(params);/*  w w w  .  j  a  v  a 2s  . co m*/

    window.setLayout(getWidth(), getHeight());
    window.setGravity(getGravity());

    // Transparent background; see http://stackoverflow.com/q/15007272/56285
    // (Needed to make dialog's alpha shadow look good)
    window.setBackgroundDrawableResource(android.R.color.transparent);

    final Resources res = getResources();
    final int titleDividerId = res.getIdentifier("titleDivider", "id", "android");
    if (titleDividerId > 0) {
        final View titleDivider = getDialog().findViewById(titleDividerId);
        if (titleDivider != null) {
            titleDivider.setBackgroundColor(res.getColor(android.R.color.transparent));
        }
    }
}

From source file:com.github.piasy.bootstrap.base.android.BaseDialogFragment.java

@Override
public void onStart() {
    super.onStart();
    // Less dimmed background; see http://stackoverflow.com/q/13822842/56285
    final Window window = getDialog().getWindow();
    if (window != null) {
        final WindowManager.LayoutParams params = window.getAttributes();
        params.dimAmount = getDimAmount(); // dim only a little bit
        window.setAttributes(params);/*w w w .j  a v  a  2 s. com*/

        window.setLayout(getWidth(), getHeight());
        window.setGravity(getGravity());

        // Transparent background; see http://stackoverflow.com/q/15007272/56285
        // (Needed to make dialog's alpha shadow look good)
        window.setBackgroundDrawableResource(android.R.color.transparent);
    }

    final Resources res = getResources();
    final int titleDividerId = res.getIdentifier("titleDivider", "id", "android");
    if (titleDividerId > 0) {
        final View titleDivider = getDialog().findViewById(titleDividerId);
        if (titleDivider != null) {
            titleDivider.setBackgroundColor(ContextCompat.getColor(getContext(), android.R.color.transparent));
        }
    }
}

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 ww .  j a  v a 2 s.  com*/
    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//  ww  w  .j a  v  a2  s  . c om
        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:net.momodalo.app.vimtouch.VimTouch.java

public void showCmdHistory() {

    final Dialog dialog = new Dialog(this, R.style.DialogSlideAnim);

    // Setting dialogview
    Window window = dialog.getWindow();
    window.setGravity(Gravity.BOTTOM);

    window.setLayout(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
    dialog.setTitle(null);/*from  w  ww .ja  va 2 s  .c o  m*/
    dialog.setContentView(R.layout.hist_list);
    dialog.setCancelable(true);

    LinearLayout layout = (LinearLayout) dialog.findViewById(R.id.hist_layout);
    if (AndroidCompat.SDK >= 11) {
        layout.setShowDividers(LinearLayout.SHOW_DIVIDER_BEGINNING | LinearLayout.SHOW_DIVIDER_MIDDLE
                | LinearLayout.SHOW_DIVIDER_END);
    }
    LayoutParams params = layout.getLayoutParams();
    params.width = mScreenWidth;
    layout.setLayoutParams(params);

    LayoutInflater inflater = LayoutInflater.from(this);
    boolean exists = false;

    for (int i = 1; i <= 10; i++) {
        TextView button = (TextView) inflater.inflate(R.layout.histbutton, layout, false);
        String cmd = Exec.getCmdHistory(i);
        if (cmd.length() == 0)
            break;
        exists = true;
        button.setText(":" + cmd);
        button.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                TextView text = (TextView) v;
                CharSequence cmd = text.getText();
                Exec.doCommand(cmd.subSequence(1, cmd.length()).toString());
                dialog.dismiss();
            }
        });
        layout.addView((View) button);
    }

    if (exists)
        dialog.show();
}

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

/**
 * Builds the UI for PaymentRequest.//from   w  w  w. j a v a2  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
 *                        &lt;title&gt; 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));
}