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
17package com.android.tv.settings.connectivity.setup;
18
19import android.app.Fragment;
20import android.graphics.drawable.AnimationDrawable;
21import android.os.Bundle;
22import android.view.LayoutInflater;
23import android.view.View;
24import android.view.ViewGroup;
25import android.widget.ImageView;
26import android.widget.TextView;
27
28import com.android.tv.settings.R;
29import 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 */
35public 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
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
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
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
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