Java Code Examples for org.chromium.base.ApiCompatibilityUtils#setTextAppearance()

The following examples show how to use org.chromium.base.ApiCompatibilityUtils#setTextAppearance() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BillingAddressAdapter.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
public View getDropDownView(int position, View convertView, ViewGroup parent) {
    View view;

    // Add a "+" icon and a blue tint to the last element.
    if (position == getCount() - 1) {
        view = super.getDropDownView(position, convertView, parent);
        TextView tv = (TextView) view;
        Resources resources = getContext().getResources();

        // Create the "+" icon, put it left of the text and add appropriate padding.
        tv.setCompoundDrawablesWithIntrinsicBounds(
                TintedDrawable.constructTintedDrawable(
                    resources, R.drawable.plus, R.color.light_active_color),
                null, null, null);
        tv.setCompoundDrawablePadding(
                resources.getDimensionPixelSize(R.dimen.payments_section_large_spacing));

        // Set the correct appearance, face and style for the text.
        ApiCompatibilityUtils.setTextAppearance(tv, R.style.PaymentsUiSectionAddButtonLabel);
        tv.setTypeface(Typeface.create(
                resources.getString(R.string.roboto_medium_typeface),
                R.integer.roboto_medium_textstyle));
    } else {
        // Don't use the recycled convertView, as it may have the style of the last element.
        view = super.getDropDownView(position, null, parent);
    }

    return view;
}
 
Example 2
Source File: PaymentRequestUI.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void addCardAndAddressOptionsSettingsView(LinearLayout parent) {
    String message;
    if (!mShowDataSource) {
        message = mContext.getString(R.string.payments_card_and_address_settings);
    } else if (ChromeSigninController.get().isSignedIn()) {
        message = mContext.getString(R.string.payments_card_and_address_settings_signed_in,
                ChromeSigninController.get().getSignedInAccountName());
    } else {
        message = mContext.getString(R.string.payments_card_and_address_settings_signed_out);
    }

    NoUnderlineClickableSpan settingsSpan = new NoUnderlineClickableSpan() {
        @Override
        public void onClick(View widget) {
            mClient.onCardAndAddressSettingsClicked();
        }
    };
    SpannableString spannableMessage = SpanApplier.applySpans(
            message, new SpanInfo("BEGIN_LINK", "END_LINK", settingsSpan));

    TextView view = new TextViewWithClickableSpans(mContext);
    view.setText(spannableMessage);
    view.setMovementMethod(LinkMovementMethod.getInstance());
    ApiCompatibilityUtils.setTextAppearance(view, R.style.PaymentsUiSectionDescriptiveText);

    // Add paddings instead of margin to let getMeasuredHeight return correct value for section
    // resize animation.
    int paddingSize = mContext.getResources().getDimensionPixelSize(
            R.dimen.payments_section_large_spacing);
    ApiCompatibilityUtils.setPaddingRelative(
            view, paddingSize, paddingSize, paddingSize, paddingSize);
    parent.addView(view);
}
 
Example 3
Source File: PaymentRequestSection.java    From 365browser with Apache License 2.0 5 votes vote down vote up
@Override
protected void createMainSectionContent(LinearLayout mainSectionLayout) {
    Context context = mainSectionLayout.getContext();

    mExtraTextViews = new TextView[3];
    for (int i = 0; i < mExtraTextViews.length; i++) {
        mExtraTextViews[i] = new TextView(context);
        ApiCompatibilityUtils.setTextAppearance(
                mExtraTextViews[i], R.style.PaymentsUiSectionDefaultText);
        mainSectionLayout.addView(
                mExtraTextViews[i], new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                                            LayoutParams.WRAP_CONTENT));
    }
}
 
Example 4
Source File: PaymentRequestSection.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
@Override
protected void createMainSectionContent(LinearLayout mainSectionLayout) {
    Context context = mainSectionLayout.getContext();

    mExtraTextViews = new TextView[3];
    for (int i = 0; i < mExtraTextViews.length; i++) {
        mExtraTextViews[i] = new TextView(context);
        ApiCompatibilityUtils.setTextAppearance(
                mExtraTextViews[i], R.style.PaymentsUiSectionDefaultText);
        mainSectionLayout.addView(
                mExtraTextViews[i], new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,
                                            LayoutParams.WRAP_CONTENT));
    }
}
 
Example 5
Source File: PaymentRequestSection.java    From delion with Apache License 2.0 5 votes vote down vote up
@Override
protected void createMainSectionContent(LinearLayout mainSectionLayout) {
    Context context = mainSectionLayout.getContext();

    mExtraTextView = new TextView(context);
    ApiCompatibilityUtils.setTextAppearance(
            mExtraTextView, R.style.PaymentsUiSectionDescriptiveTextEndAligned);
    mainSectionLayout.addView(mExtraTextView, new LinearLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
}
 
Example 6
Source File: CertificateViewer.java    From delion with Apache License 2.0 4 votes vote down vote up
private void showCertificateChain(byte[][] derData) {
    for (int i = 0; i < derData.length; i++) {
        addCertificate(derData[i]);
    }
    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(mContext,
            android.R.layout.simple_spinner_item,
            mTitles) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            TextView view = (TextView) super.getView(position, convertView, parent);
            // Add extra padding on the end side to avoid overlapping the dropdown arrow.
            ApiCompatibilityUtils.setPaddingRelative(view, mPadding, mPadding, mPadding * 2,
                    mPadding);
            return view;
        }
    };
    arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    LinearLayout dialogContainer = new LinearLayout(mContext);
    dialogContainer.setOrientation(LinearLayout.VERTICAL);

    TextView title = new TextView(mContext);
    title.setText(R.string.certtitle);
    ApiCompatibilityUtils.setTextAlignment(title, View.TEXT_ALIGNMENT_VIEW_START);
    ApiCompatibilityUtils.setTextAppearance(title, android.R.style.TextAppearance_Large);
    title.setTypeface(title.getTypeface(), Typeface.BOLD);
    title.setPadding(mPadding, mPadding, mPadding, mPadding / 2);
    dialogContainer.addView(title);

    Spinner spinner = new Spinner(mContext);
    ApiCompatibilityUtils.setTextAlignment(spinner, View.TEXT_ALIGNMENT_VIEW_START);
    spinner.setAdapter(arrayAdapter);
    spinner.setOnItemSelectedListener(this);
    spinner.setDropDownWidth(ViewGroup.LayoutParams.MATCH_PARENT);
    // Remove padding so that dropdown has same width as the spinner.
    spinner.setPadding(0, 0, 0, 0);
    dialogContainer.addView(spinner);

    LinearLayout certContainer = new LinearLayout(mContext);
    certContainer.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < mViews.size(); ++i) {
        LinearLayout certificateView = mViews.get(i);
        if (i != 0) {
            certificateView.setVisibility(LinearLayout.GONE);
        }
        certContainer.addView(certificateView);
    }
    ScrollView scrollView = new ScrollView(mContext);
    scrollView.addView(certContainer);
    dialogContainer.addView(scrollView);

    showDialogForView(dialogContainer);
}
 
Example 7
Source File: FloatLabelLayout.java    From delion with Apache License 2.0 4 votes vote down vote up
public FloatLabelLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setOrientation(VERTICAL);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatLabelLayout);

    int leftPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingLeft,
            dipsToPix(DEFAULT_LABEL_PADDING_LEFT));
    int topPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingTop,
            dipsToPix(DEFAULT_LABEL_PADDING_TOP));
    int rightPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingRight,
            dipsToPix(DEFAULT_LABEL_PADDING_RIGHT));
    int bottomPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingBottom,
            dipsToPix(DEFAULT_LABEL_PADDING_BOTTOM));
    mHint = a.getText(R.styleable.FloatLabelLayout_floatLabelHint);

    mLabel = new TextView(context);
    mLabel.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
    mLabel.setVisibility(INVISIBLE);
    mLabel.setText(mHint);
    mLabel.setFocusable(true);
    ViewCompat.setPivotX(mLabel, 0f);
    ViewCompat.setPivotY(mLabel, 0f);

    ApiCompatibilityUtils.setTextAppearance(mLabel,
            a.getResourceId(R.styleable.FloatLabelLayout_floatLabelTextAppearance,
                    android.R.style.TextAppearance_Small));
    a.recycle();

    addView(mLabel, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    mInterpolator = AnimationUtils.loadInterpolator(context,
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
                ? android.R.interpolator.fast_out_slow_in
                : android.R.anim.decelerate_interpolator);
}
 
Example 8
Source File: PaymentRequestSection.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Creates the main section.  Subclasses must call super#createMainSection() immediately to
 * guarantee that Views are added in the correct order.
 *
 * @param sectionName Title to display for the section.
 */
private LinearLayout prepareMainSection(String sectionName) {
    // The main section is a vertical linear layout that subclasses can append to.
    LinearLayout mainSectionLayout = new LinearLayout(getContext());
    mainSectionLayout.setOrientation(VERTICAL);
    LinearLayout.LayoutParams mainParams = new LayoutParams(0, LayoutParams.WRAP_CONTENT);
    mainParams.weight = 1;
    addView(mainSectionLayout, mainParams);

    // The title is always displayed for the row at the top of the main section.
    mTitleView = new TextView(getContext());
    mTitleView.setText(sectionName);
    ApiCompatibilityUtils.setTextAppearance(
            mTitleView, R.style.PaymentsUiSectionHeader);
    mainSectionLayout.addView(
            mTitleView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

    // Create the two TextViews for showing the summary text.
    mSummaryLeftTextView = new TextView(getContext());
    mSummaryLeftTextView.setId(R.id.payments_left_summary_label);
    ApiCompatibilityUtils.setTextAppearance(
            mSummaryLeftTextView, R.style.PaymentsUiSectionDefaultText);

    mSummaryRightTextView = new TextView(getContext());
    ApiCompatibilityUtils.setTextAppearance(
            mSummaryRightTextView, R.style.PaymentsUiSectionDefaultText);
    ApiCompatibilityUtils.setTextAlignment(mSummaryRightTextView, TEXT_ALIGNMENT_TEXT_END);

    // The main TextView sucks up all the available space.
    LinearLayout.LayoutParams leftLayoutParams = new LinearLayout.LayoutParams(
            0, LayoutParams.WRAP_CONTENT);
    leftLayoutParams.weight = 1;

    LinearLayout.LayoutParams rightLayoutParams = new LinearLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    ApiCompatibilityUtils.setMarginStart(
            rightLayoutParams,
            getContext().getResources().getDimensionPixelSize(
                    R.dimen.payments_section_small_spacing));

    // The summary section displays up to two TextViews side by side.
    mSummaryLayout = new LinearLayout(getContext());
    mSummaryLayout.addView(mSummaryLeftTextView, leftLayoutParams);
    mSummaryLayout.addView(mSummaryRightTextView, rightLayoutParams);
    mainSectionLayout.addView(mSummaryLayout, new LinearLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    setSummaryText(null, null);

    createMainSectionContent(mainSectionLayout);
    return mainSectionLayout;
}
 
Example 9
Source File: PaymentRequestSection.java    From delion with Apache License 2.0 4 votes vote down vote up
private TextView createLabel(
        GridLayout parent, int rowIndex, boolean iconExists, boolean isEnabled) {
    Context context = parent.getContext();
    Resources resources = context.getResources();

    // By default, the label appears to the right of the "button" in the second column.
    // + If there is no button and no icon, the label spans the whole row.
    // + If there is no icon, the label spans two columns.
    // + Otherwise, the label occupies only its own column.
    int columnStart = 1;
    int columnSpan = iconExists ? 1 : 2;

    TextView labelView = new TextView(context);
    if (mRowType == OPTION_ROW_TYPE_OPTION) {
        // Show the string representing the PaymentOption.
        ApiCompatibilityUtils.setTextAppearance(labelView, isEnabled
                ? R.style.PaymentsUiSectionDefaultText
                : R.style.PaymentsUiSectionDisabledText);
        labelView.setText(convertOptionToString(mOption));
        labelView.setEnabled(isEnabled);
    } else if (mRowType == OPTION_ROW_TYPE_ADD) {
        // Shows string saying that the user can add a new option, e.g. credit card no.
        String typeface = resources.getString(R.string.roboto_medium_typeface);
        int textStyle = resources.getInteger(R.integer.roboto_medium_textstyle);
        int buttonHeight = resources.getDimensionPixelSize(
                R.dimen.payments_section_add_button_height);

        ApiCompatibilityUtils.setTextAppearance(
                labelView, R.style.PaymentsUiSectionAddButtonLabel);
        labelView.setMinimumHeight(buttonHeight);
        labelView.setGravity(Gravity.CENTER_VERTICAL);
        labelView.setTypeface(Typeface.create(typeface, textStyle));
    } else if (mRowType == OPTION_ROW_TYPE_DESCRIPTION) {
        // The description spans all the columns.
        columnStart = 0;
        columnSpan = 3;

        ApiCompatibilityUtils.setTextAppearance(
                labelView, R.style.PaymentsUiSectionDescriptiveText);
    } else if (mRowType == OPTION_ROW_TYPE_WARNING) {
        // Warnings use two columns.
        columnSpan = 2;
        ApiCompatibilityUtils.setTextAppearance(
                labelView, R.style.PaymentsUiSectionWarningText);
    }

    // The label spans two columns if no icon exists.  Setting the view width to 0
    // forces it to stretch.
    GridLayout.LayoutParams labelParams = new GridLayout.LayoutParams(
            GridLayout.spec(rowIndex, 1, GridLayout.CENTER),
            GridLayout.spec(columnStart, columnSpan, GridLayout.FILL));
    labelParams.topMargin = mVerticalMargin;
    labelParams.width = 0;
    parent.addView(labelView, labelParams);

    labelView.setOnClickListener(OptionSection.this);
    return labelView;
}
 
Example 10
Source File: PaymentRequestSection.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the total and how it's broken down.
 *
 * @param cart The shopping cart contents and the total.
 */
public void update(ShoppingCart cart) {
    Context context = mBreakdownLayout.getContext();

    CharSequence totalPrice = createValueString(
            cart.getTotal().getCurrency(), cart.getTotal().getPrice(), true);

    // Show the updated text view if the total changed.
    showUpdateIfTextChanged(totalPrice);

    // Update the summary to display information about the total.
    setSummaryText(cart.getTotal().getLabel(), totalPrice);

    mBreakdownLayout.removeAllViews();
    if (cart.getContents() == null) return;

    int maximumDescriptionWidthPx =
            ((View) mBreakdownLayout.getParent()).getWidth() * 2 / 3;

    // Update the breakdown, using one row per {@link LineItem}.
    int numItems = cart.getContents().size();
    mBreakdownLayout.setRowCount(numItems);
    for (int i = 0; i < numItems; i++) {
        LineItem item = cart.getContents().get(i);

        TextView description = new TextView(context);
        ApiCompatibilityUtils.setTextAppearance(description, item.getIsPending()
                        ? R.style.PaymentsUiSectionPendingTextEndAligned
                        : R.style.PaymentsUiSectionDescriptiveTextEndAligned);
        description.setText(item.getLabel());
        description.setEllipsize(TruncateAt.END);
        description.setMaxLines(2);
        if (maximumDescriptionWidthPx > 0) {
            description.setMaxWidth(maximumDescriptionWidthPx);
        }

        TextView amount = new TextView(context);
        ApiCompatibilityUtils.setTextAppearance(amount, item.getIsPending()
                        ? R.style.PaymentsUiSectionPendingTextEndAligned
                        : R.style.PaymentsUiSectionDescriptiveTextEndAligned);
        amount.setText(createValueString(item.getCurrency(), item.getPrice(), false));

        // Each item is represented by a row in the GridLayout.
        GridLayout.LayoutParams descriptionParams = new GridLayout.LayoutParams(
                GridLayout.spec(i, 1, GridLayout.END),
                GridLayout.spec(0, 1, GridLayout.END));
        GridLayout.LayoutParams amountParams = new GridLayout.LayoutParams(
                GridLayout.spec(i, 1, GridLayout.END),
                GridLayout.spec(1, 1, GridLayout.END));
        ApiCompatibilityUtils.setMarginStart(amountParams,
                context.getResources().getDimensionPixelSize(
                        R.dimen.payments_section_descriptive_item_spacing));

        mBreakdownLayout.addView(description, descriptionParams);
        mBreakdownLayout.addView(amount, amountParams);
    }
}
 
Example 11
Source File: PaymentRequestSection.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private TextView createLabel(GridLayout parent, int rowIndex, boolean optionIconExists,
        boolean editIconExists, boolean isEnabled) {
    Context context = parent.getContext();
    Resources resources = context.getResources();

    // By default, the label appears to the right of the "button" in the second column.
    // + If there is no button, no option and edit icon, the label spans the whole row.
    // + If there is no option and edit icon, the label spans three columns.
    // + If there is no edit icon or option icon, the label spans two columns.
    // + Otherwise, the label occupies only its own column.
    int columnStart = 1;
    int columnSpan = 1;
    if (!optionIconExists) columnSpan++;
    if (!editIconExists) columnSpan++;

    TextView labelView = new TextView(context);
    if (mRowType == OPTION_ROW_TYPE_OPTION) {
        // Show the string representing the PaymentOption.
        ApiCompatibilityUtils.setTextAppearance(labelView, isEnabled
                ? R.style.PaymentsUiSectionDefaultText
                : R.style.PaymentsUiSectionDisabledText);
        labelView.setText(convertOptionToString(
                mOption, mDelegate.isBoldLabelNeeded(OptionSection.this)));
        labelView.setEnabled(isEnabled);
    } else if (mRowType == OPTION_ROW_TYPE_ADD) {
        // Shows string saying that the user can add a new option, e.g. credit card no.
        String typeface = resources.getString(R.string.roboto_medium_typeface);
        int textStyle = resources.getInteger(R.integer.roboto_medium_textstyle);
        int buttonHeight = resources.getDimensionPixelSize(
                R.dimen.payments_section_add_button_height);

        ApiCompatibilityUtils.setTextAppearance(
                labelView, R.style.PaymentsUiSectionAddButtonLabel);
        labelView.setMinimumHeight(buttonHeight);
        labelView.setGravity(Gravity.CENTER_VERTICAL);
        labelView.setTypeface(Typeface.create(typeface, textStyle));
    } else if (mRowType == OPTION_ROW_TYPE_DESCRIPTION) {
        // The description spans all the columns.
        columnStart = 0;
        columnSpan = 4;

        ApiCompatibilityUtils.setTextAppearance(
                labelView, R.style.PaymentsUiSectionDescriptiveText);
    } else if (mRowType == OPTION_ROW_TYPE_WARNING) {
        // Warnings use three columns.
        columnSpan = 3;
        ApiCompatibilityUtils.setTextAppearance(
                labelView, R.style.PaymentsUiSectionWarningText);
    }

    // The label spans two columns if no option or edit icon, or spans three columns if
    // no option and edit icons. Setting the view width to 0 forces it to stretch.
    GridLayout.LayoutParams labelParams = new GridLayout.LayoutParams(
            GridLayout.spec(rowIndex, 1, GridLayout.CENTER),
            GridLayout.spec(columnStart, columnSpan, GridLayout.FILL));
    labelParams.topMargin = mVerticalMargin;
    labelParams.width = 0;
    if (optionIconExists) {
        // Margin at the end of the label instead of the start of the option icon to
        // allow option icon in the the next row align with the end of label (include
        // end margin) when edit icon exits in that row, like below:
        // ---Label---------------------[label margin]|---option icon---|
        // ---Label---[label margin]|---option icon---|----edit icon----|
        ApiCompatibilityUtils.setMarginEnd(labelParams, mLargeSpacing);
    }
    parent.addView(labelView, labelParams);

    labelView.setOnClickListener(OptionSection.this);
    return labelView;
}
 
Example 12
Source File: PaymentRequestSection.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Creates the main section.  Subclasses must call super#createMainSection() immediately to
 * guarantee that Views are added in the correct order.
 *
 * @param sectionName Title to display for the section.
 */
private final LinearLayout prepareMainSection(String sectionName) {
    // The main section is a vertical linear layout that subclasses can append to.
    LinearLayout mainSectionLayout = new LinearLayout(getContext());
    mainSectionLayout.setOrientation(VERTICAL);
    LinearLayout.LayoutParams mainParams = new LayoutParams(0, LayoutParams.WRAP_CONTENT);
    mainParams.weight = 1;
    addView(mainSectionLayout, mainParams);

    // The title is always displayed for the row at the top of the main section.
    mTitleView = new TextView(getContext());
    mTitleView.setText(sectionName);
    ApiCompatibilityUtils.setTextAppearance(
            mTitleView, R.style.PaymentsUiSectionHeader);
    mainSectionLayout.addView(
            mTitleView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

    // Create the two TextViews for showing the summary text.
    mSummaryLeftTextView = new TextView(getContext());
    mSummaryLeftTextView.setId(R.id.payments_left_summary_label);
    ApiCompatibilityUtils.setTextAppearance(
            mSummaryLeftTextView, R.style.PaymentsUiSectionDefaultText);

    mSummaryRightTextView = new TextView(getContext());
    ApiCompatibilityUtils.setTextAppearance(
            mSummaryRightTextView, R.style.PaymentsUiSectionDefaultText);
    ApiCompatibilityUtils.setTextAlignment(mSummaryRightTextView, TEXT_ALIGNMENT_TEXT_END);

    // The main TextView sucks up all the available space.
    LinearLayout.LayoutParams leftLayoutParams = new LinearLayout.LayoutParams(
            0, LayoutParams.WRAP_CONTENT);
    leftLayoutParams.weight = 1;

    LinearLayout.LayoutParams rightLayoutParams = new LinearLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    ApiCompatibilityUtils.setMarginStart(
            rightLayoutParams,
            getContext().getResources().getDimensionPixelSize(
                    R.dimen.payments_section_small_spacing));

    // The summary section displays up to two TextViews side by side.
    mSummaryLayout = new LinearLayout(getContext());
    mSummaryLayout.addView(mSummaryLeftTextView, leftLayoutParams);
    mSummaryLayout.addView(mSummaryRightTextView, rightLayoutParams);
    mainSectionLayout.addView(mSummaryLayout, new LinearLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    setSummaryText(null, null);

    createMainSectionContent(mainSectionLayout);
    return mainSectionLayout;
}
 
Example 13
Source File: CertificateViewer.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
private void showCertificateChain(byte[][] derData) {
    for (int i = 0; i < derData.length; i++) {
        addCertificate(derData[i]);
    }
    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(mContext,
            android.R.layout.simple_spinner_item,
            mTitles) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            TextView view = (TextView) super.getView(position, convertView, parent);
            // Add extra padding on the end side to avoid overlapping the dropdown arrow.
            ApiCompatibilityUtils.setPaddingRelative(view, mPadding, mPadding, mPadding * 2,
                    mPadding);
            return view;
        }
    };
    arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    LinearLayout dialogContainer = new LinearLayout(mContext);
    dialogContainer.setOrientation(LinearLayout.VERTICAL);

    TextView title = new TextView(mContext);
    title.setText(R.string.certtitle);
    ApiCompatibilityUtils.setTextAlignment(title, View.TEXT_ALIGNMENT_VIEW_START);
    ApiCompatibilityUtils.setTextAppearance(title, android.R.style.TextAppearance_Large);
    title.setTypeface(title.getTypeface(), Typeface.BOLD);
    title.setPadding(mPadding, mPadding, mPadding, mPadding / 2);
    dialogContainer.addView(title);

    Spinner spinner = new Spinner(mContext);
    ApiCompatibilityUtils.setTextAlignment(spinner, View.TEXT_ALIGNMENT_VIEW_START);
    spinner.setAdapter(arrayAdapter);
    spinner.setOnItemSelectedListener(this);
    spinner.setDropDownWidth(ViewGroup.LayoutParams.MATCH_PARENT);
    // Remove padding so that dropdown has same width as the spinner.
    spinner.setPadding(0, 0, 0, 0);
    dialogContainer.addView(spinner);

    LinearLayout certContainer = new LinearLayout(mContext);
    certContainer.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < mViews.size(); ++i) {
        LinearLayout certificateView = mViews.get(i);
        if (i != 0) {
            certificateView.setVisibility(LinearLayout.GONE);
        }
        certContainer.addView(certificateView);
    }
    ScrollView scrollView = new ScrollView(mContext);
    scrollView.addView(certContainer);
    dialogContainer.addView(scrollView);

    showDialogForView(dialogContainer);
}
 
Example 14
Source File: FloatLabelLayout.java    From AndroidChromium with Apache License 2.0 4 votes vote down vote up
public FloatLabelLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setOrientation(VERTICAL);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatLabelLayout);

    int leftPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingLeft,
            dipsToPix(DEFAULT_LABEL_PADDING_LEFT));
    int topPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingTop,
            dipsToPix(DEFAULT_LABEL_PADDING_TOP));
    int rightPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingRight,
            dipsToPix(DEFAULT_LABEL_PADDING_RIGHT));
    int bottomPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingBottom,
            dipsToPix(DEFAULT_LABEL_PADDING_BOTTOM));
    mHint = a.getText(R.styleable.FloatLabelLayout_floatLabelHint);

    mLabel = new TextView(context);
    mLabel.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
    mLabel.setVisibility(INVISIBLE);
    mLabel.setText(mHint);
    mLabel.setFocusable(true);
    ViewCompat.setPivotX(mLabel, 0f);
    ViewCompat.setPivotY(mLabel, 0f);

    ApiCompatibilityUtils.setTextAppearance(mLabel,
            a.getResourceId(R.styleable.FloatLabelLayout_floatLabelTextAppearance,
                    android.R.style.TextAppearance_Small));
    a.recycle();

    addView(mLabel, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    mInterpolator = AnimationUtils.loadInterpolator(context,
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
                ? android.R.interpolator.fast_out_slow_in
                : android.R.anim.decelerate_interpolator);
}
 
Example 15
Source File: PaymentRequestSection.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Creates the main section.  Subclasses must call super#createMainSection() immediately to
 * guarantee that Views are added in the correct order.
 *
 * @param sectionName Title to display for the section.
 */
private LinearLayout prepareMainSection(String sectionName) {
    // The main section is a vertical linear layout that subclasses can append to.
    LinearLayout mainSectionLayout = new LinearLayout(getContext());
    mainSectionLayout.setOrientation(VERTICAL);
    LinearLayout.LayoutParams mainParams = new LayoutParams(0, LayoutParams.WRAP_CONTENT);
    mainParams.weight = 1;
    addView(mainSectionLayout, mainParams);

    // The title is always displayed for the row at the top of the main section.
    mTitleView = new TextView(getContext());
    mTitleView.setText(sectionName);
    ApiCompatibilityUtils.setTextAppearance(
            mTitleView, R.style.PaymentsUiSectionHeader);
    mainSectionLayout.addView(
            mTitleView, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));

    // Create the two TextViews for showing the summary text.
    mSummaryLeftTextView = new TextView(getContext());
    mSummaryLeftTextView.setId(R.id.payments_left_summary_label);
    ApiCompatibilityUtils.setTextAppearance(
            mSummaryLeftTextView, R.style.PaymentsUiSectionDefaultText);

    mSummaryRightTextView = new TextView(getContext());
    ApiCompatibilityUtils.setTextAppearance(
            mSummaryRightTextView, R.style.PaymentsUiSectionDefaultText);
    ApiCompatibilityUtils.setTextAlignment(mSummaryRightTextView, TEXT_ALIGNMENT_TEXT_END);

    // The main TextView sucks up all the available space.
    LinearLayout.LayoutParams leftLayoutParams = new LinearLayout.LayoutParams(
            0, LayoutParams.WRAP_CONTENT);
    leftLayoutParams.weight = 1;

    LinearLayout.LayoutParams rightLayoutParams = new LinearLayout.LayoutParams(
            LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    ApiCompatibilityUtils.setMarginStart(
            rightLayoutParams,
            getContext().getResources().getDimensionPixelSize(
                    R.dimen.payments_section_small_spacing));

    // The summary section displays up to two TextViews side by side.
    mSummaryLayout = new LinearLayout(getContext());
    mSummaryLayout.addView(mSummaryLeftTextView, leftLayoutParams);
    mSummaryLayout.addView(mSummaryRightTextView, rightLayoutParams);
    mainSectionLayout.addView(mSummaryLayout, new LinearLayout.LayoutParams(
            LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
    setSummaryText(null, null);

    createMainSectionContent(mainSectionLayout);
    return mainSectionLayout;
}
 
Example 16
Source File: PaymentRequestSection.java    From delion with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the total and how it's broken down.
 *
 * @param cart The shopping cart contents and the total.
 */
public void update(ShoppingCart cart) {
    Context context = mBreakdownLayout.getContext();

    // Update the summary to display information about the total.
    setSummaryText(cart.getTotal().getLabel(), createValueString(
            cart.getTotal().getCurrency(), cart.getTotal().getPrice(), true));

    mBreakdownLayout.removeAllViews();
    if (cart.getContents() == null) return;

    // Update the breakdown, using one row per {@link LineItem}.
    int numItems = cart.getContents().size();
    mBreakdownLayout.setRowCount(numItems);
    for (int i = 0; i < numItems; i++) {
        LineItem item = cart.getContents().get(i);

        TextView description = new TextView(context);
        ApiCompatibilityUtils.setTextAppearance(
                description, R.style.PaymentsUiSectionDescriptiveTextEndAligned);
        description.setText(item.getLabel());

        TextView amount = new TextView(context);
        ApiCompatibilityUtils.setTextAppearance(
                amount, R.style.PaymentsUiSectionDescriptiveTextEndAligned);
        amount.setText(createValueString(item.getCurrency(), item.getPrice(), false));

        // Each item is represented by a row in the GridLayout.
        GridLayout.LayoutParams descriptionParams = new GridLayout.LayoutParams(
                GridLayout.spec(i, 1, GridLayout.END),
                GridLayout.spec(0, 1, GridLayout.END));
        GridLayout.LayoutParams amountParams = new GridLayout.LayoutParams(
                GridLayout.spec(i, 1, GridLayout.END),
                GridLayout.spec(1, 1, GridLayout.END));
        ApiCompatibilityUtils.setMarginStart(amountParams,
                context.getResources().getDimensionPixelSize(
                        R.dimen.payments_section_descriptive_item_spacing));

        mBreakdownLayout.addView(description, descriptionParams);
        mBreakdownLayout.addView(amount, amountParams);
    }
}
 
Example 17
Source File: FloatLabelLayout.java    From 365browser with Apache License 2.0 4 votes vote down vote up
public FloatLabelLayout(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

    setOrientation(VERTICAL);

    final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.FloatLabelLayout);

    int leftPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingLeft,
            dipsToPix(DEFAULT_LABEL_PADDING_LEFT));
    int topPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingTop,
            dipsToPix(DEFAULT_LABEL_PADDING_TOP));
    int rightPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingRight,
            dipsToPix(DEFAULT_LABEL_PADDING_RIGHT));
    int bottomPadding = a.getDimensionPixelSize(
            R.styleable.FloatLabelLayout_floatLabelPaddingBottom,
            dipsToPix(DEFAULT_LABEL_PADDING_BOTTOM));
    mHint = a.getText(R.styleable.FloatLabelLayout_floatLabelHint);

    mLabel = new TextView(context);
    mLabel.setPadding(leftPadding, topPadding, rightPadding, bottomPadding);
    mLabel.setVisibility(INVISIBLE);
    mLabel.setText(mHint);
    mLabel.setFocusable(true);
    ViewCompat.setPivotX(mLabel, 0f);
    ViewCompat.setPivotY(mLabel, 0f);

    ApiCompatibilityUtils.setTextAppearance(mLabel,
            a.getResourceId(R.styleable.FloatLabelLayout_floatLabelTextAppearance,
                    android.R.style.TextAppearance_Small));
    a.recycle();

    addView(mLabel, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);

    mInterpolator = AnimationUtils.loadInterpolator(context,
            Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP
                ? android.R.interpolator.fast_out_slow_in
                : android.R.anim.decelerate_interpolator);
}
 
Example 18
Source File: PaymentRequestSection.java    From 365browser with Apache License 2.0 4 votes vote down vote up
/**
 * Updates the total and how it's broken down.
 *
 * @param cart The shopping cart contents and the total.
 */
public void update(ShoppingCart cart) {
    Context context = mBreakdownLayout.getContext();

    CharSequence totalPrice = createValueString(
            cart.getTotal().getCurrency(), cart.getTotal().getPrice(), true);

    // Show the updated text view if the total changed.
    showUpdateIfTextChanged(totalPrice);

    // Update the summary to display information about the total.
    setSummaryText(cart.getTotal().getLabel(), totalPrice);

    mBreakdownLayout.removeAllViews();
    if (cart.getContents() == null) return;

    int maximumDescriptionWidthPx =
            ((View) mBreakdownLayout.getParent()).getWidth() * 2 / 3;

    // Update the breakdown, using one row per {@link LineItem}.
    int numItems = cart.getContents().size();
    mBreakdownLayout.setRowCount(numItems);
    for (int i = 0; i < numItems; i++) {
        LineItem item = cart.getContents().get(i);

        TextView description = new TextView(context);
        ApiCompatibilityUtils.setTextAppearance(description, item.getIsPending()
                        ? R.style.PaymentsUiSectionPendingTextEndAligned
                        : R.style.PaymentsUiSectionDescriptiveTextEndAligned);
        description.setText(item.getLabel());
        description.setEllipsize(TruncateAt.END);
        description.setMaxLines(2);
        if (maximumDescriptionWidthPx > 0) {
            description.setMaxWidth(maximumDescriptionWidthPx);
        }

        TextView amount = new TextView(context);
        ApiCompatibilityUtils.setTextAppearance(amount, item.getIsPending()
                        ? R.style.PaymentsUiSectionPendingTextEndAligned
                        : R.style.PaymentsUiSectionDescriptiveTextEndAligned);
        amount.setText(createValueString(item.getCurrency(), item.getPrice(), false));

        // Each item is represented by a row in the GridLayout.
        GridLayout.LayoutParams descriptionParams = new GridLayout.LayoutParams(
                GridLayout.spec(i, 1, GridLayout.END),
                GridLayout.spec(0, 1, GridLayout.END));
        GridLayout.LayoutParams amountParams = new GridLayout.LayoutParams(
                GridLayout.spec(i, 1, GridLayout.END),
                GridLayout.spec(1, 1, GridLayout.END));
        ApiCompatibilityUtils.setMarginStart(amountParams,
                context.getResources().getDimensionPixelSize(
                        R.dimen.payments_section_descriptive_item_spacing));

        mBreakdownLayout.addView(description, descriptionParams);
        mBreakdownLayout.addView(amount, amountParams);
    }
}
 
Example 19
Source File: CertificateViewer.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private void showCertificateChain(byte[][] derData) {
    for (int i = 0; i < derData.length; i++) {
        addCertificate(derData[i]);
    }
    ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(mContext,
            android.R.layout.simple_spinner_item,
            mTitles) {
        @Override
        public View getView(int position, View convertView, ViewGroup parent) {
            TextView view = (TextView) super.getView(position, convertView, parent);
            // Add extra padding on the end side to avoid overlapping the dropdown arrow.
            ApiCompatibilityUtils.setPaddingRelative(view, mPadding, mPadding, mPadding * 2,
                    mPadding);
            return view;
        }
    };
    arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    LinearLayout dialogContainer = new LinearLayout(mContext);
    dialogContainer.setOrientation(LinearLayout.VERTICAL);

    TextView title = new TextView(mContext);
    title.setText(R.string.certtitle);
    ApiCompatibilityUtils.setTextAlignment(title, View.TEXT_ALIGNMENT_VIEW_START);
    ApiCompatibilityUtils.setTextAppearance(title, android.R.style.TextAppearance_Large);
    title.setTypeface(title.getTypeface(), Typeface.BOLD);
    title.setPadding(mPadding, mPadding, mPadding, mPadding / 2);
    dialogContainer.addView(title);

    Spinner spinner = new Spinner(mContext);
    ApiCompatibilityUtils.setTextAlignment(spinner, View.TEXT_ALIGNMENT_VIEW_START);
    spinner.setAdapter(arrayAdapter);
    spinner.setOnItemSelectedListener(this);
    spinner.setDropDownWidth(ViewGroup.LayoutParams.MATCH_PARENT);
    // Remove padding so that dropdown has same width as the spinner.
    spinner.setPadding(0, 0, 0, 0);
    dialogContainer.addView(spinner);

    LinearLayout certContainer = new LinearLayout(mContext);
    certContainer.setOrientation(LinearLayout.VERTICAL);
    for (int i = 0; i < mViews.size(); ++i) {
        LinearLayout certificateView = mViews.get(i);
        if (i != 0) {
            certificateView.setVisibility(LinearLayout.GONE);
        }
        certContainer.addView(certificateView);
    }
    ScrollView scrollView = new ScrollView(mContext);
    scrollView.addView(certContainer);
    dialogContainer.addView(scrollView);

    showDialogForView(dialogContainer);
}
 
Example 20
Source File: PaymentRequestSection.java    From 365browser with Apache License 2.0 4 votes vote down vote up
private void updateSelectedItem(PaymentOption selectedItem) {
    // Only left TextView in the summary section is used in this section.
    // Set the summary to display in a single line when there is no selected item in this
    // section or the display mode is DISPLAY_MODE_NORMAL.
    if (selectedItem == null || mDisplayMode == DISPLAY_MODE_NORMAL) {
        if (!mSummaryInSingleLine) {
            setSummaryProperties(TruncateAt.END, true /* leftIsSingleLine */,
                    null /* rightTruncate */, false /* rightIsSingleLine */);
            mSummaryInSingleLine = true;
        }
    } else if (mSummaryInSingleLine) {
        setSummaryProperties(null /* leftTruncate */, false /* leftIsSingleLine */,
                null /* rightTruncate */, false /* rightIsSingleLine */);
        mSummaryInSingleLine = false;
    }

    if (selectedItem == null) {
        setLogoDrawable(null);
        // Section summary should be displayed as R.style.PaymentsUiSectionDescriptiveText.
        if (!mSummaryInDescriptiveText) {
            ApiCompatibilityUtils.setTextAppearance(
                    getSummaryLeftTextView(), R.style.PaymentsUiSectionDescriptiveText);
            mSummaryInDescriptiveText = true;
        }
        SectionUiUtils.showSectionSummaryInTextViewInSingeLine(
                getContext(), mSectionInformation, getSummaryLeftTextView());
    } else {
        setLogoDrawable(selectedItem.getDrawableIcon());
        // Selected item summary should be displayed as
        // R.style.PaymentsUiSectionDefaultText.
        if (mSummaryInDescriptiveText) {
            ApiCompatibilityUtils.setTextAppearance(
                    getSummaryLeftTextView(), R.style.PaymentsUiSectionDefaultText);
            mSummaryInDescriptiveText = false;
        }
        setSummaryText(
                convertOptionToString(selectedItem, false /* useBoldLabel */,
                        mSummaryInSingleLine),
                null);
    }

    updateControlLayout();
}