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 |
Methods Summary |
---|
public android.graphics.drawable.Drawable | getBackgroundDrawable()Returns the background drawable. May be null if a default is used.
return mBackgroundDrawable;
|
public android.graphics.drawable.Drawable | getBadgeDrawable()Returns the badge drawable used in the fragment title.
return mBadgeDrawable;
|
public android.view.View.OnClickListener | getButtonClickListener()Returns the button click listener.
return mButtonClickListener;
|
public java.lang.String | getButtonText()Returns the button text.
return mButtonText;
|
private static android.graphics.Paint.FontMetricsInt | getFontMetricsInt(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.Drawable | getImageDrawable()Returns the drawable used for the error image.
return mDrawable;
|
public java.lang.CharSequence | getMessage()Returns the error message.
return mMessage;
|
public java.lang.String | getTitle()Returns the title for the browse fragment.
return mTitle;
|
public boolean | isBackgroundTranslucent()Returns true if the background is translucent.
return mIsBackgroundTranslucent;
|
public android.view.View | onCreateView(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 void | onStart()
super.onStart();
mErrorFrame.requestFocus();
|
public void | setBackgroundDrawable(android.graphics.drawable.Drawable drawable)Sets a drawable for the fragment background.
mBackgroundDrawable = drawable;
if (drawable != null) {
final int opacity = drawable.getOpacity();
mIsBackgroundTranslucent = (opacity == PixelFormat.TRANSLUCENT ||
opacity == PixelFormat.TRANSPARENT);
}
updateBackground();
updateMessage();
|
public void | setBadgeDrawable(android.graphics.drawable.Drawable drawable)Sets the drawable displayed in the browse fragment title.
mBadgeDrawable = drawable;
updateTitle();
|
public void | setButtonClickListener(android.view.View.OnClickListener clickListener)Set the button click listener.
mButtonClickListener = clickListener;
updateButton();
|
public void | setButtonText(java.lang.String text)Sets the button text.
mButtonText = text;
updateButton();
|
public void | setDefaultBackground(boolean translucent)Sets the default background.
mBackgroundDrawable = null;
mIsBackgroundTranslucent = translucent;
updateBackground();
updateMessage();
|
public void | setImageDrawable(android.graphics.drawable.Drawable drawable)Sets the drawable to be used for the error image.
mDrawable = drawable;
updateImageDrawable();
|
public void | setMessage(java.lang.CharSequence message)Sets the error message.
mMessage = message;
updateMessage();
|
public void | setTitle(java.lang.String title)Sets a title for the browse fragment.
mTitle = title;
updateTitle();
|
private static void | setTopMargin(android.widget.TextView textView, int topMargin)
ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) textView.getLayoutParams();
lp.topMargin = topMargin;
textView.setLayoutParams(lp);
|
private void | updateBackground()
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 void | updateButton()
if (mButton != null) {
mButton.setText(mButtonText);
mButton.setOnClickListener(mButtonClickListener);
mButton.setVisibility(TextUtils.isEmpty(mButtonText) ? View.GONE : View.VISIBLE);
mButton.requestFocus();
}
|
private void | updateImageDrawable()
if (mImageView != null) {
mImageView.setImageDrawable(mDrawable);
mImageView.setVisibility(mDrawable == null ? View.GONE : View.VISIBLE);
}
|
private void | updateMessage()
if (mTextView != null) {
mTextView.setText(mMessage);
mTextView.setVisibility(TextUtils.isEmpty(mMessage) ? View.GONE : View.VISIBLE);
}
|
private void | updateTitle()
if (mTitleView != null) {
mTitleView.setTitle(mTitle);
mTitleView.setBadgeDrawable(mBadgeDrawable);
}
|