• 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.tvleanback.ui;
15 
16 import android.app.Activity;
17 import android.app.Fragment;
18 import android.content.Intent;
19 import android.os.Bundle;
20 import android.os.Handler;
21 import android.view.Gravity;
22 import android.view.LayoutInflater;
23 import android.view.View;
24 import android.view.ViewGroup;
25 import android.widget.FrameLayout;
26 import android.widget.ProgressBar;
27 
28 import com.example.android.tvleanback.R;
29 
30 /*
31  * BrowseErrorActivity shows how to use ErrorFragment
32  */
33 public class BrowseErrorActivity extends Activity {
34     private static int TIMER_DELAY = 3000;
35     private static int SPINNER_WIDTH = 100;
36     private static int SPINNER_HEIGHT = 100;
37 
38     private ErrorFragment mErrorFragment;
39     private SpinnerFragment mSpinnerFragment;
40 
41     /**
42      * Called when the activity is first created.
43      */
44     @Override
onCreate(Bundle savedInstanceState)45     public void onCreate(Bundle savedInstanceState) {
46         super.onCreate(savedInstanceState);
47         setContentView(R.layout.main);
48 
49         testError();
50     }
51 
testError()52     private void testError() {
53         mErrorFragment = new ErrorFragment();
54         getFragmentManager().beginTransaction().add(R.id.main_frame, mErrorFragment).commit();
55 
56         mSpinnerFragment = new SpinnerFragment();
57         getFragmentManager().beginTransaction().add(R.id.main_frame, mSpinnerFragment).commit();
58 
59         final Handler handler = new Handler();
60         handler.postDelayed(new Runnable() {
61             @Override
62             public void run() {
63                 getFragmentManager().beginTransaction().remove(mSpinnerFragment).commit();
64                 mErrorFragment.setErrorContent();
65             }
66         }, TIMER_DELAY);
67     }
68 
69     @Override
onSearchRequested()70     public boolean onSearchRequested() {
71         startActivity(new Intent(this, SearchActivity.class));
72         return true;
73     }
74 
75     static public class SpinnerFragment extends Fragment {
76         @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)77         public View onCreateView(LayoutInflater inflater, ViewGroup container,
78                                  Bundle savedInstanceState) {
79             ProgressBar progressBar = new ProgressBar(container.getContext());
80             if (container instanceof FrameLayout) {
81                 FrameLayout.LayoutParams layoutParams =
82                         new FrameLayout.LayoutParams(SPINNER_WIDTH, SPINNER_HEIGHT, Gravity.CENTER);
83                 progressBar.setLayoutParams(layoutParams);
84             }
85             return progressBar;
86         }
87     }
88 }
89