BrowseErrorActivity.java revision b7087e036a48f5a3db28d02ff7f9b97fbbc46c4f
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 16def91eaec25417523827df321d2e3babbcd40a36Craig Stoutimport android.app.Activity; 17def91eaec25417523827df321d2e3babbcd40a36Craig Stoutimport android.app.Fragment; 18def91eaec25417523827df321d2e3babbcd40a36Craig Stoutimport android.os.Bundle; 19def91eaec25417523827df321d2e3babbcd40a36Craig Stoutimport android.os.Handler; 20def91eaec25417523827df321d2e3babbcd40a36Craig Stoutimport android.view.Gravity; 21def91eaec25417523827df321d2e3babbcd40a36Craig Stoutimport android.view.LayoutInflater; 22def91eaec25417523827df321d2e3babbcd40a36Craig Stoutimport android.view.View; 23def91eaec25417523827df321d2e3babbcd40a36Craig Stoutimport android.view.ViewGroup; 24def91eaec25417523827df321d2e3babbcd40a36Craig Stoutimport android.widget.FrameLayout; 25def91eaec25417523827df321d2e3babbcd40a36Craig Stoutimport android.widget.ProgressBar; 26def91eaec25417523827df321d2e3babbcd40a36Craig Stout 27def91eaec25417523827df321d2e3babbcd40a36Craig Stoutpublic class BrowseErrorActivity extends Activity 28def91eaec25417523827df321d2e3babbcd40a36Craig Stout{ 29def91eaec25417523827df321d2e3babbcd40a36Craig Stout /** Called when the activity is first created. */ 30def91eaec25417523827df321d2e3babbcd40a36Craig Stout @Override 31def91eaec25417523827df321d2e3babbcd40a36Craig Stout public void onCreate(Bundle savedInstanceState) 32def91eaec25417523827df321d2e3babbcd40a36Craig Stout { 33def91eaec25417523827df321d2e3babbcd40a36Craig Stout super.onCreate(savedInstanceState); 346f0d24aab5d9668c489097d26d4c3643f575b0c8Kris Giesing setContentView(R.layout.browse); 35def91eaec25417523827df321d2e3babbcd40a36Craig Stout 36def91eaec25417523827df321d2e3babbcd40a36Craig Stout testError(); 37def91eaec25417523827df321d2e3babbcd40a36Craig Stout } 38def91eaec25417523827df321d2e3babbcd40a36Craig Stout 3941b41b04d49910df4c1cf1299d6389d5b7c1d817Dake Gu @Override 4041b41b04d49910df4c1cf1299d6389d5b7c1d817Dake Gu public void onAttachedToWindow() { 4141b41b04d49910df4c1cf1299d6389d5b7c1d817Dake Gu super.onAttachedToWindow(); 4241b41b04d49910df4c1cf1299d6389d5b7c1d817Dake Gu BackgroundHelper.attach(this); 4341b41b04d49910df4c1cf1299d6389d5b7c1d817Dake Gu } 4441b41b04d49910df4c1cf1299d6389d5b7c1d817Dake Gu 4541b41b04d49910df4c1cf1299d6389d5b7c1d817Dake Gu @Override 4641b41b04d49910df4c1cf1299d6389d5b7c1d817Dake Gu public void onStop() { 4741b41b04d49910df4c1cf1299d6389d5b7c1d817Dake Gu BackgroundHelper.release(this); 4841b41b04d49910df4c1cf1299d6389d5b7c1d817Dake Gu super.onStop(); 4941b41b04d49910df4c1cf1299d6389d5b7c1d817Dake Gu } 5041b41b04d49910df4c1cf1299d6389d5b7c1d817Dake Gu 51def91eaec25417523827df321d2e3babbcd40a36Craig Stout private void testError() { 52def91eaec25417523827df321d2e3babbcd40a36Craig Stout Handler handler = new Handler(); 53def91eaec25417523827df321d2e3babbcd40a36Craig Stout handler.postDelayed(new Runnable() { 54def91eaec25417523827df321d2e3babbcd40a36Craig Stout @Override 55def91eaec25417523827df321d2e3babbcd40a36Craig Stout public void run() { 5653e230dfe568d0f713f797be09cdac4ab1a21d28Craig Stout if (getFragmentManager().isDestroyed()) { 5753e230dfe568d0f713f797be09cdac4ab1a21d28Craig Stout return; 5853e230dfe568d0f713f797be09cdac4ab1a21d28Craig Stout } 59b7087e036a48f5a3db28d02ff7f9b97fbbc46c4fDake Gu getFragmentManager().beginTransaction().add(R.id.main_frame, 60b7087e036a48f5a3db28d02ff7f9b97fbbc46c4fDake Gu new ErrorFragment()).commit(); 61def91eaec25417523827df321d2e3babbcd40a36Craig Stout } 62def91eaec25417523827df321d2e3babbcd40a36Craig Stout }, 3000); 63def91eaec25417523827df321d2e3babbcd40a36Craig Stout } 64def91eaec25417523827df321d2e3babbcd40a36Craig Stout 65def91eaec25417523827df321d2e3babbcd40a36Craig Stout static public class SpinnerFragment extends Fragment { 66def91eaec25417523827df321d2e3babbcd40a36Craig Stout @Override 67def91eaec25417523827df321d2e3babbcd40a36Craig Stout public View onCreateView(LayoutInflater inflater, ViewGroup container, 68def91eaec25417523827df321d2e3babbcd40a36Craig Stout Bundle savedInstanceState) { 69def91eaec25417523827df321d2e3babbcd40a36Craig Stout ProgressBar progressBar = new ProgressBar(container.getContext()); 70def91eaec25417523827df321d2e3babbcd40a36Craig Stout if (container instanceof FrameLayout) { 71b7087e036a48f5a3db28d02ff7f9b97fbbc46c4fDake Gu FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(100, 100, 72b7087e036a48f5a3db28d02ff7f9b97fbbc46c4fDake Gu Gravity.CENTER); 73def91eaec25417523827df321d2e3babbcd40a36Craig Stout progressBar.setLayoutParams(layoutParams); 74def91eaec25417523827df321d2e3babbcd40a36Craig Stout } 75def91eaec25417523827df321d2e3babbcd40a36Craig Stout return progressBar; 76def91eaec25417523827df321d2e3babbcd40a36Craig Stout } 77def91eaec25417523827df321d2e3babbcd40a36Craig Stout } 78def91eaec25417523827df321d2e3babbcd40a36Craig Stout} 79