Android Open Source - AlertDialogPro Dialog Title






From Project

Back to project page AlertDialogPro.

License

The source code is released under:

Apache License

If you think the Android project AlertDialogPro listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.alertdialogpro.internal;
// w w w  .j  a va  2 s . com
import android.content.Context;
import android.content.res.TypedArray;
import android.text.Layout;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.widget.TextView;

/**
 * Used by dialogs to change the font size and number of lines to try to fit
 * the text to the available space.
 */
public class DialogTitle extends TextView {

    private static final int[] TEXT_APPEARANCE_ATTRS = new int[]{android.R.attr.textSize};

    public DialogTitle(Context context,
                       AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    public DialogTitle(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public DialogTitle(Context context) {
        super(context);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);

        final Layout layout = getLayout();
        if (layout != null) {
            final int lineCount = layout.getLineCount();
            if (lineCount > 0) {
                final int ellipsisCount = layout.getEllipsisCount(lineCount - 1);
                if (ellipsisCount > 0) {
                    setSingleLine(false);
                    setMaxLines(2);

                    final TypedArray a = getContext().obtainStyledAttributes(null,
                            TEXT_APPEARANCE_ATTRS,
                            android.R.attr.textAppearanceMedium,
                            android.R.style.TextAppearance_Medium);
                    final int textSize = a.getDimensionPixelSize(0, 0);
                    if (textSize != 0) {
                        // textSize is already expressed in pixels
                        setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
                    }
                    a.recycle();

                    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
                }
            }
        }
    }
}




Java Source Code List

com.alertdialogpro.AlertDialogPro.java
com.alertdialogpro.ProgressDialogPro.java
com.alertdialogpro.demo.MainActivity.java
com.alertdialogpro.holo.internal.NoTintCheckedTextView.java
com.alertdialogpro.internal.AlertController.java
com.alertdialogpro.internal.DialogTitle.java
com.alertdialogpro.material.ButtonCompat.java
com.alertdialogpro.material.CheckedTextViewCompat.java
com.alertdialogpro.material.ProgressBarCompat.java
com.alertdialogpro.material.drawable.CircularAnimatedDrawable.java