1 /* 2 * Copyright (C) 2014 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.android.tv.settings.connectivity.setup; 18 19 import android.app.Fragment; 20 import android.graphics.drawable.AnimationDrawable; 21 import android.os.Bundle; 22 import android.view.LayoutInflater; 23 import android.view.View; 24 import android.view.ViewGroup; 25 import android.widget.ImageView; 26 import android.widget.TextView; 27 28 import com.android.tv.settings.R; 29 import com.android.tv.settings.util.AccessibilityHelper; 30 31 /** 32 * Displays a UI for showing a message with an optional progress indicator in 33 * the "wizard" style. 34 */ 35 public class MessageWizardFragment extends Fragment { 36 37 private static final String EXTRA_TITLE = "title"; 38 private static final String EXTRA_SHOW_PROGRESS_INDICATOR = "show_progress_indicator"; 39 newInstance(String title, boolean showProgressIndicator)40 public static MessageWizardFragment newInstance(String title, boolean showProgressIndicator) { 41 MessageWizardFragment fragment = new MessageWizardFragment(); 42 Bundle args = new Bundle(); 43 addArguments(args, title, showProgressIndicator); 44 fragment.setArguments(args); 45 return fragment; 46 } 47 addArguments(Bundle args, String title, boolean showProgressIndicator)48 public static void addArguments(Bundle args, String title, boolean showProgressIndicator) { 49 args.putString(EXTRA_TITLE, title); 50 args.putBoolean(EXTRA_SHOW_PROGRESS_INDICATOR, showProgressIndicator); 51 } 52 53 @Override onCreateView(LayoutInflater inflater, ViewGroup container, Bundle icicle)54 public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle icicle) { 55 final View view = inflater.inflate(R.layout.setup_activity_progress, container, false); 56 57 final ImageView progressView = (ImageView) view.findViewById(R.id.progress); 58 final TextView titleView = (TextView) view.findViewById(R.id.status_text); 59 60 Bundle args = getArguments(); 61 String title = args.getString(EXTRA_TITLE); 62 boolean showProgressIndicator = args.getBoolean(EXTRA_SHOW_PROGRESS_INDICATOR); 63 64 if (title != null) { 65 titleView.setText(title); 66 titleView.setVisibility(View.VISIBLE); 67 if (AccessibilityHelper.forceFocusableViews(getActivity())) { 68 titleView.setFocusable(true); 69 titleView.setFocusableInTouchMode(true); 70 } 71 } else { 72 titleView.setVisibility(View.GONE); 73 } 74 75 if (showProgressIndicator) { 76 progressView.setVisibility(View.VISIBLE); 77 ((AnimationDrawable) progressView.getDrawable()).start(); 78 } else { 79 progressView.setVisibility(View.GONE); 80 } 81 82 return view; 83 } 84 85 @Override onResume()86 public void onResume() { 87 super.onResume(); 88 if (AccessibilityHelper.forceFocusableViews(getActivity())) { 89 TextView titleView = (TextView) getView().findViewById(R.id.status_text); 90 titleView.requestFocus(); 91 } 92 } 93 } 94