Java Code Examples for android.widget.TextView#addOnLayoutChangeListener()

The following examples show how to use android.widget.TextView#addOnLayoutChangeListener() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: delion   File: WebappUrlBar.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a WebappUrlBar.
 * @param context Context to grab resources from.
 */
public WebappUrlBar(Context context, AttributeSet attrSet) {
    super(context, attrSet);
    mIconResourceWidths = new SparseIntArray();

    mUrlBar = new TextView(context);
    mUrlBar.setSingleLine(true);
    mUrlBar.setGravity(Gravity.CENTER_VERTICAL);
    mUrlBar.setMovementMethod(ScrollingMovementMethod.getInstance());
    mUrlBar.setHorizontalFadingEdgeEnabled(true);
    mSeparator = new View(context);

    addView(mUrlBar,
            new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,
                    Gravity.CENTER));
    addView(mSeparator,
            new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, 1, Gravity.BOTTOM));

    // Set the colors.
    mSeparator.setBackgroundColor(ApiCompatibilityUtils.getColor(context.getResources(),
            R.color.webapp_url_bar_separator));
    setBackgroundColor(ApiCompatibilityUtils.getColor(context.getResources(),
            R.color.webapp_url_bar_bg));

    // Listen for changes in the URL bar's size.
    mUrlBar.addOnLayoutChangeListener(this);
}
 
Example 2
Source Project: AndroidChromium   File: WebappUrlBar.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a WebappUrlBar.
 * @param context Context to grab resources from.
 */
public WebappUrlBar(Context context, AttributeSet attrSet) {
    super(context, attrSet);
    mIconResourceWidths = new SparseIntArray();

    mUrlBar = new TextView(context);
    mUrlBar.setSingleLine(true);
    mUrlBar.setGravity(Gravity.CENTER_VERTICAL);
    mUrlBar.setMovementMethod(ScrollingMovementMethod.getInstance());
    mUrlBar.setHorizontalFadingEdgeEnabled(true);
    mSeparator = new View(context);

    addView(mUrlBar,
            new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,
                    Gravity.CENTER));
    addView(mSeparator,
            new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, 1, Gravity.BOTTOM));

    // Set the colors.
    mSeparator.setBackgroundColor(ApiCompatibilityUtils.getColor(context.getResources(),
            R.color.webapp_url_bar_separator));
    setBackgroundColor(ApiCompatibilityUtils.getColor(context.getResources(),
            R.color.webapp_url_bar_bg));

    // Listen for changes in the URL bar's size.
    mUrlBar.addOnLayoutChangeListener(this);
}
 
Example 3
Source Project: auid2   File: CaptionedImageView.java    License: Apache License 2.0 5 votes vote down vote up
private void init(Context context) {
    inflate(context, R.layout.captioned_image_view, this);
    mTextView = (TextView) findViewById(R.id.text);
    mImageView = (SquareImageView) findViewById(R.id.image);
    mScrimColor = getResources().getColor(R.color.grid_item_scrim);
    mTextView.addOnLayoutChangeListener(this);
}
 
Example 4
Source Project: auid2   File: CaptionedImageView.java    License: Apache License 2.0 5 votes vote down vote up
private void init(Context context) {
    inflate(context, R.layout.captioned_image_view, this);
    mTextView = (TextView) findViewById(R.id.text);
    mImageView = (SquareImageView) findViewById(R.id.image);
    mScrimColor = getResources().getColor(R.color.grid_item_scrim);
    mTextView.addOnLayoutChangeListener(this);
}
 
Example 5
Source Project: auid2   File: CaptionedImageView.java    License: Apache License 2.0 5 votes vote down vote up
private void init(Context context) {
    inflate(context, R.layout.captioned_image_view, this);
    mTextView = (TextView) findViewById(R.id.text);
    mImageView = (SquareImageView) findViewById(R.id.image);
    mScrimColor = getResources().getColor(R.color.grid_item_scrim);
    mTextView.addOnLayoutChangeListener(this);
}
 
Example 6
Source Project: 365browser   File: WebappUrlBar.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Creates a WebappUrlBar.
 * @param context Context to grab resources from.
 */
public WebappUrlBar(Context context, AttributeSet attrSet) {
    super(context, attrSet);
    mIconResourceWidths = new SparseIntArray();

    mUrlBar = new TextView(context);
    mUrlBar.setSingleLine(true);
    mUrlBar.setGravity(Gravity.CENTER_VERTICAL);
    mUrlBar.setMovementMethod(ScrollingMovementMethod.getInstance());
    mUrlBar.setHorizontalFadingEdgeEnabled(true);
    mSeparator = new View(context);

    addView(mUrlBar,
            new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT,
                    Gravity.CENTER));
    addView(mSeparator,
            new FrameLayout.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, 1, Gravity.BOTTOM));

    // Set the colors.
    mSeparator.setBackgroundColor(ApiCompatibilityUtils.getColor(context.getResources(),
            R.color.webapp_url_bar_separator));
    setBackgroundColor(ApiCompatibilityUtils.getColor(context.getResources(),
            R.color.webapp_url_bar_bg));

    // Listen for changes in the URL bar's size.
    mUrlBar.addOnLayoutChangeListener(this);
}
 
Example 7
public ViewHolder(View view) {
    super(view);
    mTitle = (TextView) view.findViewById(R.id.lb_details_description_title);
    mSubtitle = (TextView) view.findViewById(R.id.lb_details_description_subtitle);
    mBody = (TextView) view.findViewById(R.id.lb_details_description_body);

    FontMetricsInt titleFontMetricsInt = getFontMetricsInt(mTitle);
    final int titleAscent = view.getResources().getDimensionPixelSize(
            R.dimen.lb_details_description_title_baseline);
    // Ascent is negative
    mTitleMargin = titleAscent + titleFontMetricsInt.ascent;

    mUnderTitleBaselineMargin = view.getResources().getDimensionPixelSize(
            R.dimen.lb_details_description_under_title_baseline_margin);
    mUnderSubtitleBaselineMargin = view.getResources().getDimensionPixelSize(
            R.dimen.lb_details_description_under_subtitle_baseline_margin);

    mTitleLineSpacing = view.getResources().getDimensionPixelSize(
            R.dimen.lb_details_description_title_line_spacing);
    mBodyLineSpacing = view.getResources().getDimensionPixelSize(
            R.dimen.lb_details_description_body_line_spacing);

    mBodyMaxLines = view.getResources().getInteger(
            R.integer.lb_details_description_body_max_lines);
    mBodyMinLines = view.getResources().getInteger(
            R.integer.lb_details_description_body_min_lines);

    mTitleFontMetricsInt = getFontMetricsInt(mTitle);
    mSubtitleFontMetricsInt = getFontMetricsInt(mSubtitle);
    mBodyFontMetricsInt = getFontMetricsInt(mBody);

    mTitle.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right,
                int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
            mBody.setMaxLines(mTitle.getLineCount() > 1 ? mBodyMinLines : mBodyMaxLines);
        }
    });
}
 
Example 8
public ViewHolder(View view) {
    super(view);
    mTitle = (TextView) view.findViewById(androidx.leanback.R.id.lb_details_description_title);
    mSubtitle = (TextView) view.findViewById(androidx.leanback.R.id.lb_details_description_subtitle);
    mActivity = (Activity) view.getContext();
    mInfoRow = new LinearLayout(mActivity);
    LinearLayout.LayoutParams layout = new LinearLayout.LayoutParams(Utils.convertDpToPixel(mActivity, 500), Utils.convertDpToPixel(mActivity,20));
    layout.setMargins(0,15,0,0);
    mInfoRow.setLayoutParams(layout);
    //Replace subtitle with our info row
    ViewGroup parent = (ViewGroup) view;
    int index = parent.indexOfChild(mSubtitle);
    parent.removeView(mSubtitle);
    parent.addView(mInfoRow, index);
    mBody = (TextView) view.findViewById(androidx.leanback.R.id.lb_details_description_body);

    Paint.FontMetricsInt titleFontMetricsInt = getFontMetricsInt(mTitle);
    final int titleAscent = view.getResources().getDimensionPixelSize(
            androidx.leanback.R.dimen.lb_details_description_title_baseline);
    // Ascent is negative
    mTitleMargin = titleAscent + titleFontMetricsInt.ascent;

    mUnderTitleBaselineMargin = view.getResources().getDimensionPixelSize(
            androidx.leanback.R.dimen.lb_details_description_under_title_baseline_margin);
    mUnderSubtitleBaselineMargin = view.getResources().getDimensionPixelSize(
            androidx.leanback.R.dimen.lb_details_description_under_subtitle_baseline_margin);

    mTitleLineSpacing = view.getResources().getDimensionPixelSize(
            androidx.leanback.R.dimen.lb_details_description_title_line_spacing);
    mBodyLineSpacing = view.getResources().getDimensionPixelSize(
            androidx.leanback.R.dimen.lb_details_description_body_line_spacing);

    mBodyMaxLines = 6;
    mBodyMinLines = 4;

    mTitleFontMetricsInt = getFontMetricsInt(mTitle);
    mSubtitleFontMetricsInt = getFontMetricsInt(mSubtitle);
    mBodyFontMetricsInt = getFontMetricsInt(mBody);

    mTitle.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
        @Override
        public void onLayoutChange(View v, int left, int top, int right,
                                   int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom) {
            mBody.setMaxLines(mTitle.getLineCount() > 1 ? mBodyMinLines : mBodyMaxLines);
        }
    });
}
 
Example 9
public ChartHeaderView(Context context) {
    super(context);
    TextPaint textPaint = new TextPaint();
    textPaint.setTextSize(14);
    textPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    textMargin = (int) textPaint.measureText("00 MMM 0000 - 00 MMM 000");

    title = new TextView(context);
    title.setTextSize(15);
    title.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    addView(title, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.START | Gravity.CENTER_VERTICAL, 16, 0, textMargin, 0));

    back = new TextView(context);
    back.setTextSize(15);
    back.setTypeface(Typeface.DEFAULT_BOLD);
    back.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
    addView(back, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.START | Gravity.CENTER_VERTICAL, 8, 0, 8, 0));

    dates = new TextView(context);
    dates.setTextSize(13);
    dates.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    dates.setGravity(Gravity.END | Gravity.CENTER_VERTICAL);
    addView(dates, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.END | Gravity.CENTER_VERTICAL, 16, 0, 16, 0));

    datesTmp = new TextView(context);
    datesTmp.setTextSize(13);
    datesTmp.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    datesTmp.setGravity(Gravity.END | Gravity.CENTER_VERTICAL);
    addView(datesTmp, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.END | Gravity.CENTER_VERTICAL, 16, 0, 16, 0));
    datesTmp.setVisibility(View.GONE);


    back.setVisibility(View.GONE);
    back.setText(LocaleController.getString("ZoomOut", R.string.ZoomOut));
    zoomIcon = ContextCompat.getDrawable(getContext(), R.drawable.stats_zoom);
    back.setCompoundDrawablesWithIntrinsicBounds(zoomIcon, null, null, null);
    back.setCompoundDrawablePadding(AndroidUtilities.dp(4));
    back.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(4), AndroidUtilities.dp(8), AndroidUtilities.dp(4));
    back.setBackground(Theme.getRoundRectSelectorDrawable(Theme.getColor(Theme.key_featuredStickers_removeButtonText)));

    datesTmp.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
        datesTmp.setPivotX(datesTmp.getMeasuredWidth() * 0.7f);
        dates.setPivotX(dates.getMeasuredWidth() * 0.7f);
    });
    recolor();
}
 
Example 10
public ChartHeaderView(Context context) {
    super(context);
    TextPaint textPaint = new TextPaint();
    textPaint.setTextSize(14);
    textPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    textMargin = (int) textPaint.measureText("00 MMM 0000 - 00 MMM 000");

    title = new TextView(context);
    title.setTextSize(15);
    title.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    addView(title, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.START | Gravity.CENTER_VERTICAL, 16, 0, textMargin, 0));

    back = new TextView(context);
    back.setTextSize(15);
    back.setTypeface(Typeface.DEFAULT_BOLD);
    back.setGravity(Gravity.START | Gravity.CENTER_VERTICAL);
    addView(back, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.START | Gravity.CENTER_VERTICAL, 8, 0, 8, 0));

    dates = new TextView(context);
    dates.setTextSize(13);
    dates.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    dates.setGravity(Gravity.END | Gravity.CENTER_VERTICAL);
    addView(dates, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.END | Gravity.CENTER_VERTICAL, 16, 0, 16, 0));

    datesTmp = new TextView(context);
    datesTmp.setTextSize(13);
    datesTmp.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    datesTmp.setGravity(Gravity.END | Gravity.CENTER_VERTICAL);
    addView(datesTmp, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.END | Gravity.CENTER_VERTICAL, 16, 0, 16, 0));
    datesTmp.setVisibility(View.GONE);


    back.setVisibility(View.GONE);
    back.setText(LocaleController.getString("ZoomOut", R.string.ZoomOut));
    zoomIcon = ContextCompat.getDrawable(getContext(), R.drawable.stats_zoom);
    back.setCompoundDrawablesWithIntrinsicBounds(zoomIcon, null, null, null);
    back.setCompoundDrawablePadding(AndroidUtilities.dp(4));
    back.setPadding(AndroidUtilities.dp(8), AndroidUtilities.dp(4), AndroidUtilities.dp(8), AndroidUtilities.dp(4));
    back.setBackground(Theme.getRoundRectSelectorDrawable(Theme.getColor(Theme.key_featuredStickers_removeButtonText)));

    datesTmp.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
        datesTmp.setPivotX(datesTmp.getMeasuredWidth() * 0.7f);
        dates.setPivotX(dates.getMeasuredWidth() * 0.7f);
    });
    recolor();
}