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