FileDocCategorySizeDatePackage
ErrorFragment.javaAPI DocAndroid 5.1 API8614Thu Mar 12 22:22:56 GMT 2015android.support.v17.leanback.app

ErrorFragment

public class ErrorFragment extends android.app.Fragment
A fragment for displaying an error indication.

Fields Summary
private android.view.View
mErrorFrame
private String
mTitle
private android.graphics.drawable.Drawable
mBadgeDrawable
private android.support.v17.leanback.widget.TitleView
mTitleView
private android.widget.ImageView
mImageView
private android.widget.TextView
mTextView
private android.widget.Button
mButton
private android.graphics.drawable.Drawable
mDrawable
private CharSequence
mMessage
private String
mButtonText
private android.view.View.OnClickListener
mButtonClickListener
private android.graphics.drawable.Drawable
mBackgroundDrawable
private boolean
mIsBackgroundTranslucent
Constructors Summary
Methods Summary
public android.graphics.drawable.DrawablegetBackgroundDrawable()
Returns the background drawable. May be null if a default is used.

        return mBackgroundDrawable;
    
public android.graphics.drawable.DrawablegetBadgeDrawable()
Returns the badge drawable used in the fragment title.

        return mBadgeDrawable;
    
public android.view.View.OnClickListenergetButtonClickListener()
Returns the button click listener.

        return mButtonClickListener;
    
public java.lang.StringgetButtonText()
Returns the button text.

        return mButtonText;
    
private static android.graphics.Paint.FontMetricsIntgetFontMetricsInt(android.widget.TextView textView)

        Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
        paint.setTextSize(textView.getTextSize());
        paint.setTypeface(textView.getTypeface());
        return paint.getFontMetricsInt();
    
public android.graphics.drawable.DrawablegetImageDrawable()
Returns the drawable used for the error image.

        return mDrawable;
    
public java.lang.CharSequencegetMessage()
Returns the error message.

        return mMessage;
    
public java.lang.StringgetTitle()
Returns the title for the browse fragment.

        return mTitle;
    
public booleanisBackgroundTranslucent()
Returns true if the background is translucent.

        return mIsBackgroundTranslucent;
    
public android.view.ViewonCreateView(android.view.LayoutInflater inflater, android.view.ViewGroup container, android.os.Bundle savedInstanceState)

        View root = inflater.inflate(R.layout.lb_error_fragment, container, false);

        mErrorFrame = root.findViewById(R.id.error_frame);
        updateBackground();

        mImageView = (ImageView) root.findViewById(R.id.image);
        updateImageDrawable();

        mTextView = (TextView) root.findViewById(R.id.message);
        updateMessage();

        mButton = (Button) root.findViewById(R.id.button);
        updateButton();

        mTitleView = (TitleView) root.findViewById(R.id.browse_title_group);
        updateTitle();

        FontMetricsInt metrics = getFontMetricsInt(mTextView);
        int underImageBaselineMargin = container.getResources().getDimensionPixelSize(
                R.dimen.lb_error_under_image_baseline_margin);
        setTopMargin(mTextView, underImageBaselineMargin + metrics.ascent);

        int underMessageBaselineMargin = container.getResources().getDimensionPixelSize(
                R.dimen.lb_error_under_message_baseline_margin);
        setTopMargin(mButton, underMessageBaselineMargin - metrics.descent);

        return root;
    
public voidonStart()

        super.onStart();
        mErrorFrame.requestFocus();
    
public voidsetBackgroundDrawable(android.graphics.drawable.Drawable drawable)
Sets a drawable for the fragment background.

param
drawable The drawable used for the background.

        mBackgroundDrawable = drawable;
        if (drawable != null) {
            final int opacity = drawable.getOpacity();
            mIsBackgroundTranslucent = (opacity == PixelFormat.TRANSLUCENT ||
                    opacity == PixelFormat.TRANSPARENT);
        }
        updateBackground();
        updateMessage();
    
public voidsetBadgeDrawable(android.graphics.drawable.Drawable drawable)
Sets the drawable displayed in the browse fragment title.

param
drawable The drawable to display in the browse fragment title.


                             
        
        mBadgeDrawable = drawable;
        updateTitle();
    
public voidsetButtonClickListener(android.view.View.OnClickListener clickListener)
Set the button click listener.

param
clickListener The click listener for the button.

        mButtonClickListener = clickListener;
        updateButton();
    
public voidsetButtonText(java.lang.String text)
Sets the button text.

param
text The button text.

        mButtonText = text;
        updateButton();
    
public voidsetDefaultBackground(boolean translucent)
Sets the default background.

param
translucent True to set a translucent background.

        mBackgroundDrawable = null;
        mIsBackgroundTranslucent = translucent;
        updateBackground();
        updateMessage();
    
public voidsetImageDrawable(android.graphics.drawable.Drawable drawable)
Sets the drawable to be used for the error image.

param
drawable The drawable used for the error image.

        mDrawable = drawable;
        updateImageDrawable();
    
public voidsetMessage(java.lang.CharSequence message)
Sets the error message.

param
message The error message.

        mMessage = message;
        updateMessage();
    
public voidsetTitle(java.lang.String title)
Sets a title for the browse fragment.

param
title The title of the browse fragment.

        mTitle = title;
        updateTitle();
    
private static voidsetTopMargin(android.widget.TextView textView, int topMargin)

        ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) textView.getLayoutParams();
        lp.topMargin = topMargin;
        textView.setLayoutParams(lp);
    
private voidupdateBackground()

        if (mErrorFrame != null) {
            if (mBackgroundDrawable != null) {
                mErrorFrame.setBackground(mBackgroundDrawable);
            } else {
                mErrorFrame.setBackgroundColor(mErrorFrame.getResources().getColor(
                        mIsBackgroundTranslucent ?
                        R.color.lb_error_background_color_translucent :
                        R.color.lb_error_background_color_opaque));
            }
        }
    
private voidupdateButton()

        if (mButton != null) {
            mButton.setText(mButtonText);
            mButton.setOnClickListener(mButtonClickListener);
            mButton.setVisibility(TextUtils.isEmpty(mButtonText) ? View.GONE : View.VISIBLE);
            mButton.requestFocus();
        }
    
private voidupdateImageDrawable()

        if (mImageView != null) {
            mImageView.setImageDrawable(mDrawable);
            mImageView.setVisibility(mDrawable == null ? View.GONE : View.VISIBLE);
        }
    
private voidupdateMessage()

        if (mTextView != null) {
            mTextView.setText(mMessage);
            mTextView.setVisibility(TextUtils.isEmpty(mMessage) ? View.GONE : View.VISIBLE);
        }
    
private voidupdateTitle()

        if (mTitleView != null) {
            mTitleView.setTitle(mTitle);
            mTitleView.setBadgeDrawable(mBadgeDrawable);
        }