BrowseErrorSupportActivity.java revision 71e7e67f320b23feac784b629db17b3bcce08722
1/* This file is auto-generated from BrowseErrorActivity.java.  DO NOT MODIFY. */
2
3/*
4 * Copyright (C) 2014 The Android Open Source Project
5 *
6 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
7 * in compliance with the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software distributed under the License
12 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
13 * or implied. See the License for the specific language governing permissions and limitations under
14 * the License.
15 */
16package com.example.android.leanback;
17
18import android.support.v4.app.FragmentActivity;
19import android.support.v4.app.Fragment;
20import android.os.Bundle;
21import android.os.Handler;
22import android.view.Gravity;
23import android.view.LayoutInflater;
24import android.view.View;
25import android.view.ViewGroup;
26import android.widget.FrameLayout;
27import android.widget.ProgressBar;
28
29public class BrowseErrorSupportActivity extends FragmentActivity
30{
31    private ErrorSupportFragment mErrorSupportFragment;
32    private SpinnerSupportFragment mSpinnerSupportFragment;
33
34    /** Called when the activity is first created. */
35    @Override
36    public void onCreate(Bundle savedInstanceState)
37    {
38        super.onCreate(savedInstanceState);
39        setContentView(R.layout.browse_support);
40
41        testError();
42    }
43
44    @Override
45    public void onAttachedToWindow() {
46        super.onAttachedToWindow();
47        BackgroundHelper.attach(this);
48    }
49
50    @Override
51    public void onStop() {
52        BackgroundHelper.release(this);
53        super.onStop();
54    }
55
56    private void testError() {
57        mErrorSupportFragment = new ErrorSupportFragment();
58        getSupportFragmentManager().beginTransaction().add(R.id.main_frame, mErrorSupportFragment).commit();
59
60        mSpinnerSupportFragment = new SpinnerSupportFragment();
61        getSupportFragmentManager().beginTransaction().add(R.id.main_frame, mSpinnerSupportFragment).commit();
62
63        Handler handler = new Handler();
64        handler.postDelayed(new Runnable() {
65            @Override
66            public void run() {
67                if (getSupportFragmentManager().isDestroyed()) {
68                    return;
69                }
70                getSupportFragmentManager().beginTransaction().remove(mSpinnerSupportFragment).commit();
71                mErrorSupportFragment.setErrorContent(getResources());
72            }
73        }, 3000);
74    }
75
76    static public class SpinnerSupportFragment extends Fragment {
77        @Override
78        public View onCreateView(LayoutInflater inflater, ViewGroup container,
79                    Bundle savedInstanceState) {
80            ProgressBar progressBar = new ProgressBar(container.getContext());
81            if (container instanceof FrameLayout) {
82                FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(100, 100, Gravity.CENTER);
83                progressBar.setLayoutParams(layoutParams);
84            }
85            return progressBar;
86        }
87    }
88}
89