• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  */
14 package com.example.android.leanback;
15 
16 import android.app.Activity;
17 import android.app.Fragment;
18 import android.os.Bundle;
19 import android.os.Handler;
20 import android.view.Gravity;
21 import android.view.LayoutInflater;
22 import android.view.View;
23 import android.view.ViewGroup;
24 import android.widget.FrameLayout;
25 import android.widget.ProgressBar;
26 
27 public class BrowseErrorActivity extends Activity
28 {
29     private ErrorFragment mErrorFragment;
30     private SpinnerFragment mSpinnerFragment;
31 
32     /** Called when the activity is first created. */
33     @Override
onCreate(Bundle savedInstanceState)34     public void onCreate(Bundle savedInstanceState)
35     {
36         super.onCreate(savedInstanceState);
37         setContentView(R.layout.main);
38 
39         testError();
40     }
41 
testError()42     private void testError() {
43         mErrorFragment = new ErrorFragment();
44         getFragmentManager().beginTransaction().add(R.id.main_frame, mErrorFragment).commit();
45 
46         mSpinnerFragment = new SpinnerFragment();
47         getFragmentManager().beginTransaction().add(R.id.main_frame, mSpinnerFragment).commit();
48 
49         Handler handler = new Handler();
50         handler.postDelayed(new Runnable() {
51             @Override
52             public void run() {
53                 if (getFragmentManager().isDestroyed()) {
54                     return;
55                 }
56                 getFragmentManager().beginTransaction().remove(mSpinnerFragment).commit();
57                 mErrorFragment.setErrorContent(getResources());
58             }
59         }, 3000);
60     }
61 
62     static public class SpinnerFragment extends Fragment {
63         @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)64         public View onCreateView(LayoutInflater inflater, ViewGroup container,
65                     Bundle savedInstanceState) {
66             ProgressBar progressBar = new ProgressBar(container.getContext());
67             if (container instanceof FrameLayout) {
68                 FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(100, 100, Gravity.CENTER);
69                 progressBar.setLayoutParams(layoutParams);
70             }
71             return progressBar;
72         }
73     }
74 }
75