Example usage for android.view Gravity CENTER_HORIZONTAL

List of usage examples for android.view Gravity CENTER_HORIZONTAL

Introduction

In this page you can find the example usage for android.view Gravity CENTER_HORIZONTAL.

Prototype

int CENTER_HORIZONTAL

To view the source code for android.view Gravity CENTER_HORIZONTAL.

Click Source Link

Document

Place object in the horizontal center of its container, not changing its size.

Usage

From source file:com.mk4droid.IMC_Activities.FActivity_TabHost.java

private LinearLayout InActivateColorize(LinearLayout ll, String text, Drawable dr) {

    // text//from  www . j a va2s  .c  o  m
    TextView v = (TextView) ll.findViewWithTag("tv");

    v.setText(text);
    v.setTextSize(10);
    v.setTextColor(Color.GRAY);
    v.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);

    dr.setColorFilter(0xFF888888, android.graphics.PorterDuff.Mode.SRC_ATOP);
    v.setCompoundDrawablesWithIntrinsicBounds(null, dr, null, null);
    v.setPadding(0, 5, 0, 2);

    v.setBackgroundDrawable(resources.getDrawable(R.drawable.gradient_tabs));

    // hbar
    View hbar = ll.findViewWithTag("hbar");
    hbar.setBackgroundDrawable(null);
    hbar.setBackgroundColor(resources.getColor(R.color.graylight));
    return ll;
}

From source file:com.adarshahd.indianrailinfo.donate.PNRStat.java

private void createTableLayoutPsnDtls() {
    if (mPageResult.contains("FLUSHED PNR / ") || mPageResult.contains("Invalid PNR")) {
        mTextViewPNRSts.setText("The PNR entered is either invalid or expired! Please check.");
        mFrameLayout.removeAllViews();//from www  .  j  ava2s . com
        mFrameLayout.addView(mTextViewPNRSts);
        mStrPassengerDetails = null;
        return;
    }
    if (mPageResult.contains("Connectivity Failure") || mPageResult.contains("try again")) {
        mTextViewPNRSts.setText("Looks like server is busy or currently unavailable. Please try again later!");
        mFrameLayout.removeAllViews();
        mFrameLayout.addView(mTextViewPNRSts);
        mStrPassengerDetails = null;
        return;
    }
    List<List<String>> passengersList;
    if (mPassengerDetails == null || mPassengerDetails.getPNR() != mPNRNumber) {
        Elements elements = Jsoup.parse(mPageResult).select("table tr td:containsOwn(S. No.)");
        Iterator iterator = null;
        try {
            iterator = elements.first().parent().parent().getElementsByTag("tr").iterator();
        } catch (Exception e) {
            Log.i("PNRStat", mPageResult);
            return;
        }
        passengersList = new ArrayList<List<String>>();
        List<String> list;
        Element tmp;
        while (iterator.hasNext()) {
            tmp = (Element) iterator.next();
            if (tmp.toString().contains("Passenger")) {
                list = new ArrayList<String>();
                list.add(tmp.select("td").get(0).text());
                list.add(tmp.select("td").get(1).text());
                list.add(tmp.select("td").get(2).text());
                if (!tmp.select("td").get(2).text().toUpperCase().contains("CNF")
                        && !tmp.select("td").get(2).text().toUpperCase().contains("CAN")) {
                    isWaitingList = true;
                }
                passengersList.add(list);
            }
        }
        mPassengerDetails = new PassengerDetails(passengersList, mPNRNumber);
    } else {
        passengersList = mPassengerDetails.getPassengerList();
    }

    mTableLayoutPsn = new TableLayout(mActivity);
    TableRow row;
    TextView tv1, tv2, tv3, tv4;
    mStrPassengerDetails = new ArrayList<String>();
    int current;
    mTableLayoutPsn.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.WRAP_CONTENT));
    for (int i = 0; i < passengersList.size(); ++i) {
        current = i + 1;
        row = new TableRow(mActivity);
        row.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.WRAP_CONTENT));
        tv1 = new TextView(mActivity);
        tv2 = new TextView(mActivity);
        tv3 = new TextView(mActivity);
        tv4 = new TextView(mActivity);

        tv1.setText("" + (i + 1) + ".");
        tv2.setText("   " + passengersList.get(i).get(0));
        tv3.setText("   " + passengersList.get(i).get(1));
        tv4.setText("   " + passengersList.get(i).get(2));

        tv1.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium);
        tv2.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium);
        tv3.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium);
        tv4.setTextAppearance(mActivity, android.R.style.TextAppearance_DeviceDefault_Medium);

        tv1.setPadding(10, 10, 10, 10);
        tv2.setPadding(10, 10, 10, 10);
        tv3.setPadding(10, 10, 10, 10);
        tv4.setPadding(10, 10, 10, 10);

        row.addView(tv1);
        row.addView(tv2);
        row.addView(tv3);
        row.addView(tv4);

        row.setBackgroundResource(R.drawable.card_background);
        row.setGravity(Gravity.CENTER_HORIZONTAL | Gravity.CENTER_VERTICAL);
        mTableLayoutPsn.addView(row);
        String strPsn = "" + current + ". " + passengersList.get(i).get(0) + "   "
                + passengersList.get(i).get(1) + "   " + passengersList.get(i).get(2);
        mStrPassengerDetails.add(strPsn);
    }
}

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

/**
 * Builds the UI for PaymentRequest./* w ww.j a  v  a2  s  . c  o  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));
}

From source file:com.near.chimerarevo.fragments.PostFragment.java

private void parseTables(Elements tbls) {
    TableLayout tl = new TableLayout(getActivity());
    LayoutParams tl_prms = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    tl_prms.gravity = Gravity.CENTER_HORIZONTAL;
    tl_prms.setMargins(10, 10, 10, 0);/* ww w  . jav  a  2 s.  co  m*/
    tl.setLayoutParams(tl_prms);

    for (Element tbl : tbls) {
        Elements rws = tbl.getElementsByTag("td");
        TableRow row = new TableRow(getActivity());
        for (Element rw : rws) {
            TextView txt = new TextView(getActivity());
            txt.setLayoutParams(new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
                    TableRow.LayoutParams.WRAP_CONTENT));
            txt.setText(rw.text());
            row.addView(txt);
        }
        tl.addView(row);
    }
    lay.addView(tl);
}

From source file:com.github.antoniodisanto92.swipeselector.SwipeAdapter.java

private int getGravity(int gravity) {
    if (gravity == -1)
        return -1;

    int realGravityValue;

    switch (gravity) {
    case 0:/* w  w  w. j  a v  a 2 s .c o m*/
        realGravityValue = Gravity.START;
        break;
    case 1:
        realGravityValue = Gravity.CENTER_HORIZONTAL;
        break;
    case 2:
        realGravityValue = Gravity.END;
        break;
    default:
        throw new IllegalArgumentException("Invalid value " + "specified for swipe_descriptionGravity. "
                + "Use \"left\", \"center\", \"right\" or leave " + "blank for default.");
    }

    return realGravityValue;
}

From source file:com.sean.takeastand.ui.MainImageButtonFragment.java

private void setTextSwitchers() {
    txtTap.setFactory(new ViewSwitcher.ViewFactory() {
        @Override/*  w w w  . ja va 2s  .co  m*/
        public View makeView() {
            tapTextView = new TextView(getActivity());
            tapTextView.setTextSize(24);
            tapTextView.setGravity(Gravity.CENTER_HORIZONTAL);
            tapTextView.setTextColor(getResources().getColor(android.R.color.secondary_text_light));
            tapTextView.setText(getResources().getString(R.string.tap_to_start));
            mCurrentText = getResources().getString(R.string.tap_to_start);
            return tapTextView;
        }
    });
    Animation in = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_in_left);
    Animation out = AnimationUtils.loadAnimation(getActivity(), R.anim.slide_out_left);

    txtTap.setInAnimation(in);
    txtTap.setOutAnimation(out);
}

From source file:br.com.carlosrafaelgn.fplay.ActivityBrowserRadio.java

@Override
public void onClick(View view) {
    if (view == btnGoBack) {
        if (isAtFavorites) {
            isAtFavorites = false;/*w  w w  .ja v  a 2 s.c  om*/
            doSearch();
        } else {
            finish(0, view, true);
        }
    } else if (view == btnFavorite) {
        isAtFavorites = true;
        radioStationList.cancel();
        radioStationList.fetchFavorites(getApplication());
        updateButtons();
    } else if (view == btnSearch) {
        final Context ctx = getHostActivity();
        final LinearLayout l = (LinearLayout) UI.createDialogView(ctx, null);

        LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        chkGenre = new RadioButton(ctx);
        chkGenre.setText(R.string.genre);
        chkGenre.setChecked(Player.lastRadioSearchWasByGenre);
        chkGenre.setOnClickListener(this);
        chkGenre.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp);
        chkGenre.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad;
        btnGenre = new Spinner(ctx);
        btnGenre.setContentDescription(ctx.getText(R.string.genre));
        btnGenre.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad << 1;
        chkTerm = new RadioButton(ctx);
        chkTerm.setText(R.string.search_term);
        chkTerm.setChecked(!Player.lastRadioSearchWasByGenre);
        chkTerm.setOnClickListener(this);
        chkTerm.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp);
        chkTerm.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad;
        txtTerm = new EditText(ctx);
        txtTerm.setContentDescription(ctx.getText(R.string.search_term));
        txtTerm.setText(Player.radioSearchTerm == null ? "" : Player.radioSearchTerm);
        txtTerm.setOnClickListener(this);
        txtTerm.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._DLGsp);
        txtTerm.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
        txtTerm.setSingleLine();
        txtTerm.setLayoutParams(p);

        p = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        p.topMargin = UI._DLGsppad;
        p.bottomMargin = UI._DLGsppad;
        final TextView lbl = new TextView(ctx);
        lbl.setAutoLinkMask(0);
        lbl.setLinksClickable(true);
        //http://developer.android.com/design/style/color.html
        lbl.setLinkTextColor(new BgColorStateList(UI.isAndroidThemeLight() ? 0xff0099cc : 0xff33b5e5));
        lbl.setTextSize(TypedValue.COMPLEX_UNIT_PX, UI._14sp);
        lbl.setGravity(Gravity.CENTER_HORIZONTAL);
        lbl.setText(SafeURLSpan.parseSafeHtml(getText(R.string.by_dir_xiph_org)));
        lbl.setMovementMethod(LinkMovementMethod.getInstance());
        lbl.setLayoutParams(p);

        l.addView(chkGenre);
        l.addView(btnGenre);
        l.addView(chkTerm);
        l.addView(txtTerm);
        l.addView(lbl);

        btnGenre.setAdapter(this);
        btnGenre.setSelection(getValidGenre(Player.radioLastGenre));
        defaultTextColors = txtTerm.getTextColors();

        UI.prepareDialogAndShow((new AlertDialog.Builder(ctx)).setTitle(getText(R.string.search)).setView(l)
                .setPositiveButton(R.string.search, this).setNegativeButton(R.string.cancel, this)
                .setOnCancelListener(this).create());
    } else if (view == btnGoBackToPlayer) {
        finish(-1, view, false);
    } else if (view == btnAdd) {
        addPlaySelectedItem(false);
    } else if (view == btnPlay) {
        addPlaySelectedItem(true);
    } else if (view == chkGenre || view == btnGenre) {
        chkGenre.setChecked(true);
        chkTerm.setChecked(false);
    } else if (view == chkTerm || view == txtTerm) {
        chkGenre.setChecked(false);
        chkTerm.setChecked(true);
    } else if (view == list) {
        if (!isAtFavorites && !loading && (radioStationList == null || radioStationList.getCount() == 0))
            onClick(btnFavorite);
    }
}

From source file:com.quran.labs.androidquran.widgets.spinner.SpinnerCompat.java

/**
 * Creates and positions all views for this Spinner.
 *
 * @param delta Change in the selected position. +1 means selection is moving to the right, so
 *              views are scrolling to the left. -1 means selection is moving to the left.
 *///from w w w .jav a 2 s  .co  m
@SuppressLint("RtlHardcoded")
@Override
void layout(int delta, boolean animate) {
    int childrenLeft = mSpinnerPadding.left;
    int childrenWidth = getRight() - getLeft() - mSpinnerPadding.left - mSpinnerPadding.right;

    if (mDataChanged) {
        handleDataChanged();
    }

    // Handle the empty set by removing all views
    if (mItemCount == 0) {
        resetList();
        return;
    }

    if (mNextSelectedPosition >= 0) {
        setSelectedPositionInt(mNextSelectedPosition);
    }

    recycleAllViews();

    // Clear out old views
    removeAllViewsInLayout();

    // Make selected view and position it
    mFirstPosition = mSelectedPosition;
    if (mAdapter != null) {
        View sel = makeView(mSelectedPosition, true);
        int width = sel.getMeasuredWidth();
        int selectedOffset = childrenLeft;
        final int layoutDirection = ViewCompat.getLayoutDirection(this);
        final int absoluteGravity = GravityCompat.getAbsoluteGravity(mGravity, layoutDirection);
        switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.CENTER_HORIZONTAL:
            selectedOffset = childrenLeft + (childrenWidth / 2) - (width / 2);
            break;
        case Gravity.RIGHT:
            selectedOffset = childrenLeft + childrenWidth - width;
            break;
        }
        sel.offsetLeftAndRight(selectedOffset);
    }

    // Flush any cached views that did not get reused above
    mRecycler.clear();

    invalidate();

    checkSelectionChanged();

    mDataChanged = false;
    mNeedSync = false;
    setNextSelectedPositionInt(mSelectedPosition);
}

From source file:android.support.v7.internal.widget.SpinnerCompat.java

/**
 * Creates and positions all views for this Spinner.
 *
 * @param delta Change in the selected position. +1 means selection is moving to the right, so
 *              views are scrolling to the left. -1 means selection is moving to the left.
 *///www. j  ava2 s.  co m
@Override
void layout(int delta, boolean animate) {
    int childrenLeft = mSpinnerPadding.left;
    int childrenWidth = getRight() - getLeft() - mSpinnerPadding.left - mSpinnerPadding.right;

    if (mDataChanged) {
        handleDataChanged();
    }

    // Handle the empty set by removing all views
    if (mItemCount == 0) {
        resetList();
        return;
    }

    if (mNextSelectedPosition >= 0) {
        setSelectedPositionInt(mNextSelectedPosition);
    }

    recycleAllViews();

    // Clear out old views
    removeAllViewsInLayout();

    // Make selected view and position it
    mFirstPosition = mSelectedPosition;
    if (mAdapter != null) {
        View sel = makeView(mSelectedPosition, true);
        int width = sel.getMeasuredWidth();
        int selectedOffset = childrenLeft;
        final int layoutDirection = ViewCompat.getLayoutDirection(this);
        final int absoluteGravity = GravityCompat.getAbsoluteGravity(mGravity, layoutDirection);
        switch (absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
        case Gravity.CENTER_HORIZONTAL:
            selectedOffset = childrenLeft + (childrenWidth / 2) - (width / 2);
            break;
        case Gravity.RIGHT:
            selectedOffset = childrenLeft + childrenWidth - width;
            break;
        }
        sel.offsetLeftAndRight(selectedOffset);
    }

    // Flush any cached views that did not get reused above
    mRecycler.clear();

    invalidate();

    checkSelectionChanged();

    mDataChanged = false;
    mNeedSync = false;
    setNextSelectedPositionInt(mSelectedPosition);
}

From source file:com.android.contacts.list.DefaultContactBrowseListFragment.java

private View getEmptyHomeView(LayoutInflater inflater) {
    final View emptyHomeView = inflater.inflate(R.layout.empty_home_view, null);
    // Set image margins.
    final ImageView image = (ImageView) emptyHomeView.findViewById(R.id.empty_home_image);
    final LayoutParams params = (LayoutParams) image.getLayoutParams();
    final int screenHeight = getResources().getDisplayMetrics().heightPixels;
    final int marginTop = screenHeight / 2
            - getResources().getDimensionPixelSize(R.dimen.empty_home_view_image_offset);
    params.setMargins(0, marginTop, 0, 0);
    params.gravity = Gravity.CENTER_HORIZONTAL;
    image.setLayoutParams(params);//from  www.j av  a  2 s  .c om

    // Set up add contact button.
    final Button addContactButton = (Button) emptyHomeView.findViewById(R.id.add_contact_button);
    addContactButton.setOnClickListener(mAddContactListener);
    return emptyHomeView;
}