• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2017 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.os.Bundle;
20 import android.view.LayoutInflater;
21 import android.view.View;
22 import android.view.ViewGroup;
23 import android.widget.TextView;
24 
25 import androidx.fragment.app.Fragment;
26 
27 import com.android.tv.settings.R;
28 import com.android.tv.settings.util.AccessibilityHelper;
29 
30 /**
31  * Displays a UI for showing a message with an optional progress indicator.
32  */
33 public class MessageFragment extends Fragment {
34 
35     private static final String EXTRA_TITLE = "title";
36     private static final String EXTRA_SHOW_PROGRESS_INDICATOR = "show_progress_indicator";
37 
38     /**
39      * Create a MessageFragment.
40      *
41      * @param title                 title of the fragment
42      * @param showProgressIndicator set true if need to show progress indicator
43      * @return The fragment.
44      */
newInstance(String title, boolean showProgressIndicator)45     public static MessageFragment newInstance(String title, boolean showProgressIndicator) {
46         MessageFragment
47                 fragment = new MessageFragment();
48         Bundle args = new Bundle();
49         addArguments(args, title, showProgressIndicator);
50         fragment.setArguments(args);
51         return fragment;
52     }
53 
54     /**
55      * Set arguments value for the bundle.
56      *
57      * @param args                  where the values are put in
58      * @param title                 the title string
59      * @param showProgressIndicator true if show progress indicator
60      */
addArguments(Bundle args, String title, boolean showProgressIndicator)61     public static void addArguments(Bundle args, String title, boolean showProgressIndicator) {
62         args.putString(EXTRA_TITLE, title);
63         args.putBoolean(EXTRA_SHOW_PROGRESS_INDICATOR, showProgressIndicator);
64     }
65 
66     @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle icicle)67     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle icicle) {
68         final View view = inflater.inflate(R.layout.setup_message, container, false);
69 
70         final View progressView = view.findViewById(R.id.progress);
71         final TextView titleView = view.findViewById(R.id.status_text);
72 
73         Bundle args = getArguments();
74         String title = args.getString(EXTRA_TITLE);
75         boolean showProgressIndicator = args.getBoolean(EXTRA_SHOW_PROGRESS_INDICATOR);
76 
77         if (title != null) {
78             titleView.setText(title);
79             titleView.setVisibility(View.VISIBLE);
80             if (AccessibilityHelper.forceFocusableViews(getActivity())) {
81                 titleView.setFocusable(true);
82                 titleView.setFocusableInTouchMode(true);
83             }
84         } else {
85             titleView.setVisibility(View.GONE);
86         }
87 
88         if (showProgressIndicator) {
89             progressView.setVisibility(View.VISIBLE);
90         } else {
91             progressView.setVisibility(View.GONE);
92         }
93 
94         return view;
95     }
96 
97     @Override
onResume()98     public void onResume() {
99         super.onResume();
100         if (AccessibilityHelper.forceFocusableViews(getActivity())) {
101             TextView titleView = getView().findViewById(R.id.status_text);
102             titleView.requestFocus();
103         }
104     }
105 }
106