ErrorFragment.java revision def582a5836579a3fadabfdbe4413cb1652bf098
1/* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except 5 * in compliance with the License. You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software distributed under the License 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express 11 * or implied. See the License for the specific language governing permissions and limitations under 12 * the License. 13 */ 14package com.example.android.leanback; 15 16import android.content.Context; 17import android.os.Bundle; 18import android.util.Log; 19import android.view.View; 20 21import androidx.core.content.res.ResourcesCompat; 22 23public class ErrorFragment extends androidx.leanback.app.ErrorFragment { 24 private static final String TAG = "leanback.ErrorFragment"; 25 private static final boolean TRANSLUCENT = true; 26 27 @Override 28 public void onCreate(Bundle savedInstanceState) { 29 Log.i(TAG, "onCreate"); 30 super.onCreate(savedInstanceState); 31 32 setTitle("Leanback Sample App"); 33 final Context context = getActivity(); 34 setImageDrawable(ResourcesCompat.getDrawable(context.getResources(), 35 R.drawable.lb_ic_sad_cloud, context.getTheme())); 36 setMessage("An error occurred."); 37 setDefaultBackground(TRANSLUCENT); 38 39 setButtonText("Dismiss"); 40 setButtonClickListener(new View.OnClickListener() { 41 @Override 42 public void onClick(View arg0) { 43 Log.i(TAG, "button clicked"); 44 getFragmentManager().beginTransaction().remove(ErrorFragment.this).commit(); 45 } 46 }); 47 } 48} 49