165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane/*
265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Copyright (C) 2014 The Android Open Source Project
365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane *
465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Licensed under the Apache License, Version 2.0 (the "License");
565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * you may not use this file except in compliance with the License.
665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * You may obtain a copy of the License at
765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane *
865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane *      http://www.apache.org/licenses/LICENSE-2.0
965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane *
1065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Unless required by applicable law or agreed to in writing, software
1165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * distributed under the License is distributed on an "AS IS" BASIS,
1265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * See the License for the specific language governing permissions and
1465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * limitations under the License.
1565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */
1665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
1765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lanepackage com.android.tv.settings.connectivity.setup;
1865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
1965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.app.Fragment;
2065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.graphics.drawable.AnimationDrawable;
2165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.os.Bundle;
2265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.view.LayoutInflater;
2365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.view.View;
2465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.view.ViewGroup;
2565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.widget.ImageView;
2665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.widget.TextView;
2765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
2865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport com.android.tv.settings.R;
2965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport com.android.tv.settings.util.AccessibilityHelper;
3065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
3165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane/**
3265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Displays a UI for showing a message with an optional progress indicator in
3365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * the "wizard" style.
3465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */
3565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lanepublic class MessageWizardFragment extends Fragment {
3665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
3765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    private static final String EXTRA_TITLE = "title";
3865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    private static final String EXTRA_SHOW_PROGRESS_INDICATOR = "show_progress_indicator";
3965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
4065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    public static MessageWizardFragment newInstance(String title, boolean showProgressIndicator) {
4165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        MessageWizardFragment fragment = new MessageWizardFragment();
4265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        Bundle args = new Bundle();
4365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        addArguments(args, title, showProgressIndicator);
4465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        fragment.setArguments(args);
4565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        return fragment;
4665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    }
4765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
4865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    public static void addArguments(Bundle args, String title, boolean showProgressIndicator) {
4965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        args.putString(EXTRA_TITLE, title);
5065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        args.putBoolean(EXTRA_SHOW_PROGRESS_INDICATOR, showProgressIndicator);
5165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    }
5265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
5365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    @Override
5465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle icicle) {
556316b89e65828d537da309851529d1295efd5730Tony Mantler        final View view = inflater.inflate(R.layout.setup_activity_progress, container, false);
5665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
576316b89e65828d537da309851529d1295efd5730Tony Mantler        final ImageView progressView = (ImageView) view.findViewById(R.id.progress);
586316b89e65828d537da309851529d1295efd5730Tony Mantler        final TextView titleView = (TextView) view.findViewById(R.id.status_text);
5965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
6065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        Bundle args = getArguments();
6165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        String title = args.getString(EXTRA_TITLE);
6265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        boolean showProgressIndicator = args.getBoolean(EXTRA_SHOW_PROGRESS_INDICATOR);
6365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
6465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        if (title != null) {
656316b89e65828d537da309851529d1295efd5730Tony Mantler            titleView.setText(title);
666316b89e65828d537da309851529d1295efd5730Tony Mantler            titleView.setVisibility(View.VISIBLE);
6765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane            if (AccessibilityHelper.forceFocusableViews(getActivity())) {
686316b89e65828d537da309851529d1295efd5730Tony Mantler                titleView.setFocusable(true);
696316b89e65828d537da309851529d1295efd5730Tony Mantler                titleView.setFocusableInTouchMode(true);
7065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane            }
7165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        } else {
726316b89e65828d537da309851529d1295efd5730Tony Mantler            titleView.setVisibility(View.GONE);
7365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        }
7465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
7565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        if (showProgressIndicator) {
7665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane            progressView.setVisibility(View.VISIBLE);
7765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane            ((AnimationDrawable) progressView.getDrawable()).start();
7865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        } else {
7965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane            progressView.setVisibility(View.GONE);
8065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        }
8165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
8265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        return view;
8365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    }
841b2e7b8797755a5d152282f65937dfca578f53dfChristopher Lane
851b2e7b8797755a5d152282f65937dfca578f53dfChristopher Lane    @Override
861b2e7b8797755a5d152282f65937dfca578f53dfChristopher Lane    public void onResume() {
871b2e7b8797755a5d152282f65937dfca578f53dfChristopher Lane        super.onResume();
881b2e7b8797755a5d152282f65937dfca578f53dfChristopher Lane        if (AccessibilityHelper.forceFocusableViews(getActivity())) {
891b2e7b8797755a5d152282f65937dfca578f53dfChristopher Lane            TextView titleView = (TextView) getView().findViewById(R.id.status_text);
901b2e7b8797755a5d152282f65937dfca578f53dfChristopher Lane            titleView.requestFocus();
911b2e7b8797755a5d152282f65937dfca578f53dfChristopher Lane        }
921b2e7b8797755a5d152282f65937dfca578f53dfChristopher Lane    }
9365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane}
94