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

The following examples show how to use org.chromium.base.ApiCompatibilityUtils#setTextAlignment() . 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: UrlBar.java    From delion with Apache License 2.0 6 votes vote down vote up
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
    mFocused = focused;
    if (!focused) mAutocompleteSpan.clearSpan();
    super.onFocusChanged(focused, direction, previouslyFocusedRect);

    if (focused && mFirstFocusTimeMs == 0) {
        mFirstFocusTimeMs = SystemClock.elapsedRealtime();
        if (mOmniboxLivenessListener != null) mOmniboxLivenessListener.onOmniboxFocused();
    }

    if (focused) StartupMetrics.getInstance().recordFocusedOmnibox();

    // When unfocused, force left-to-right rendering at the paragraph level (which is desired
    // for URLs). Right-to-left runs are still rendered RTL, but will not flip the whole URL
    // around. This is consistent with OmniboxViewViews on desktop. When focused, render text
    // normally (to allow users to make non-URL searches and to avoid showing Android's split
    // insertion point when an RTL user enters RTL text).
    if (focused) {
        ApiCompatibilityUtils.setTextDirection(this, TEXT_DIRECTION_INHERIT);
    } else {
        ApiCompatibilityUtils.setTextDirection(this, TEXT_DIRECTION_LTR);
    }
    // Always align to the same as the paragraph direction (LTR = left, RTL = right).
    ApiCompatibilityUtils.setTextAlignment(this, TEXT_ALIGNMENT_TEXT_START);
}
 
Example 2
Source File: UrlBar.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
    mFocused = focused;
    if (!focused) mAutocompleteSpan.clearSpan();
    super.onFocusChanged(focused, direction, previouslyFocusedRect);

    if (focused && mFirstFocusTimeMs == 0) {
        mFirstFocusTimeMs = SystemClock.elapsedRealtime();
        if (mOmniboxLivenessListener != null) mOmniboxLivenessListener.onOmniboxFocused();
    }

    if (focused) StartupMetrics.getInstance().recordFocusedOmnibox();

    fixupTextDirection();
    // Always align to the same as the paragraph direction (LTR = left, RTL = right).
    ApiCompatibilityUtils.setTextAlignment(this, TEXT_ALIGNMENT_TEXT_START);
}
 
Example 3
Source File: UrlBar.java    From 365browser with Apache License 2.0 6 votes vote down vote up
/**
 * Sets the {@link UrlBar}'s text direction based on focus and contents.
 *
 * Should be called whenever focus or text contents change.
 */
private void fixupTextDirection() {
    // When unfocused, force left-to-right rendering at the paragraph level (which is desired
    // for URLs). Right-to-left runs are still rendered RTL, but will not flip the whole URL
    // around. This is consistent with OmniboxViewViews on desktop. When focused, render text
    // normally (to allow users to make non-URL searches and to avoid showing Android's split
    // insertion point when an RTL user enters RTL text). Also render text normally when the
    // text field is empty (because then it displays an instruction that is not a URL).
    if (mFocused || length() == 0) {
        ApiCompatibilityUtils.setTextDirection(this, TEXT_DIRECTION_INHERIT);
    } else {
        ApiCompatibilityUtils.setTextDirection(this, TEXT_DIRECTION_LTR);
    }
    // Always align to the same as the paragraph direction (LTR = left, RTL = right).
    ApiCompatibilityUtils.setTextAlignment(this, TEXT_ALIGNMENT_TEXT_START);
}
 
Example 4
Source File: CertificateViewer.java    From delion with Apache License 2.0 5 votes vote down vote up
private TextView addLabel(LinearLayout certificateView, String label) {
    TextView t = new TextView(mContext);
    ApiCompatibilityUtils.setTextAlignment(t, View.TEXT_ALIGNMENT_VIEW_START);
    t.setPadding(mPadding, mPadding / 2, mPadding, 0);
    t.setText(label);
    t.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
    t.setTextColor(ApiCompatibilityUtils.getColor(mContext.getResources(),
            R.color.connection_info_popup_text));
    certificateView.addView(t);
    return t;
}
 
Example 5
Source File: CertificateViewer.java    From delion with Apache License 2.0 5 votes vote down vote up
private void addValue(LinearLayout certificateView, String value) {
    TextView t = new TextView(mContext);
    ApiCompatibilityUtils.setTextAlignment(t, View.TEXT_ALIGNMENT_VIEW_START);
    t.setText(value);
    t.setPadding(mPadding, 0, mPadding, mPadding / 2);
    t.setTextColor(ApiCompatibilityUtils.getColor(mContext.getResources(),
            R.color.connection_info_popup_text));
    certificateView.addView(t);
}
 
Example 6
Source File: CertificateViewer.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private TextView addLabel(LinearLayout certificateView, String label) {
    TextView t = new TextView(mContext);
    ApiCompatibilityUtils.setTextAlignment(t, View.TEXT_ALIGNMENT_VIEW_START);
    t.setPadding(mPadding, mPadding / 2, mPadding, 0);
    t.setText(label);
    t.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
    t.setTextColor(ApiCompatibilityUtils.getColor(mContext.getResources(),
            R.color.connection_info_popup_text));
    certificateView.addView(t);
    return t;
}
 
Example 7
Source File: CertificateViewer.java    From AndroidChromium with Apache License 2.0 5 votes vote down vote up
private void addValue(LinearLayout certificateView, String value) {
    TextView t = new TextView(mContext);
    ApiCompatibilityUtils.setTextAlignment(t, View.TEXT_ALIGNMENT_VIEW_START);
    t.setText(value);
    t.setPadding(mPadding, 0, mPadding, mPadding / 2);
    t.setTextColor(ApiCompatibilityUtils.getColor(mContext.getResources(),
            R.color.connection_info_popup_text));
    certificateView.addView(t);
}
 
Example 8
Source File: CertificateViewer.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private TextView addLabel(LinearLayout certificateView, String label) {
    TextView t = new TextView(mContext);
    ApiCompatibilityUtils.setTextAlignment(t, View.TEXT_ALIGNMENT_VIEW_START);
    t.setPadding(mPadding, mPadding / 2, mPadding, 0);
    t.setText(label);
    t.setTypeface(Typeface.defaultFromStyle(Typeface.BOLD));
    t.setTextColor(ApiCompatibilityUtils.getColor(mContext.getResources(),
            R.color.connection_info_popup_text));
    certificateView.addView(t);
    return t;
}
 
Example 9
Source File: CertificateViewer.java    From 365browser with Apache License 2.0 5 votes vote down vote up
private void addValue(LinearLayout certificateView, String value) {
    TextView t = new TextView(mContext);
    ApiCompatibilityUtils.setTextAlignment(t, View.TEXT_ALIGNMENT_VIEW_START);
    t.setText(value);
    t.setPadding(mPadding, 0, mPadding, mPadding / 2);
    t.setTextColor(ApiCompatibilityUtils.getColor(mContext.getResources(),
            R.color.connection_info_popup_text));
    certificateView.addView(t);
}
 
Example 10
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 11
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 12
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 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: 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 15
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);
}