Home | History | Annotate | Download | only in setup
      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.content.Context;
     21 import android.graphics.drawable.AnimationDrawable;
     22 import android.os.Bundle;
     23 import android.view.LayoutInflater;
     24 import android.view.View;
     25 import android.view.ViewGroup;
     26 import android.widget.ImageView;
     27 import android.widget.TextView;
     28 
     29 import com.android.tv.settings.R;
     30 import com.android.tv.settings.util.AccessibilityHelper;
     31 
     32 /**
     33  * Displays a UI for showing a message with an optional progress indicator in
     34  * the "wizard" style.
     35  */
     36 public class MessageWizardFragment extends Fragment {
     37 
     38     private static final String EXTRA_TITLE = "title";
     39     private static final String EXTRA_SHOW_PROGRESS_INDICATOR = "show_progress_indicator";
     40     private TextView mTitle;
     41 
     42     public static MessageWizardFragment newInstance(String title, boolean showProgressIndicator) {
     43         MessageWizardFragment fragment = new MessageWizardFragment();
     44         Bundle args = new Bundle();
     45         addArguments(args, title, showProgressIndicator);
     46         fragment.setArguments(args);
     47         return fragment;
     48     }
     49 
     50     public static void addArguments(Bundle args, String title, boolean showProgressIndicator) {
     51         args.putString(EXTRA_TITLE, title);
     52         args.putBoolean(EXTRA_SHOW_PROGRESS_INDICATOR, showProgressIndicator);
     53     }
     54 
     55     @Override
     56     public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle icicle) {
     57         View view = inflater.inflate(R.layout.setup_activity_progress, null);
     58 
     59         ImageView progressView = (ImageView) view.findViewById(R.id.progress);
     60         mTitle = (TextView) view.findViewById(R.id.status_text);
     61 
     62         Bundle args = getArguments();
     63         String title = args.getString(EXTRA_TITLE);
     64         boolean showProgressIndicator = args.getBoolean(EXTRA_SHOW_PROGRESS_INDICATOR);
     65 
     66         if (title != null) {
     67             mTitle.setText(title);
     68             mTitle.setVisibility(View.VISIBLE);
     69             if (AccessibilityHelper.forceFocusableViews(getActivity())) {
     70                 mTitle.setFocusable(true);
     71                 mTitle.setFocusableInTouchMode(true);
     72             }
     73         } else {
     74             mTitle.setVisibility(View.GONE);
     75         }
     76 
     77         if (showProgressIndicator) {
     78             progressView.setVisibility(View.VISIBLE);
     79             ((AnimationDrawable) progressView.getDrawable()).start();
     80         } else {
     81             progressView.setVisibility(View.GONE);
     82         }
     83 
     84         return view;
     85     }
     86 
     87     @Override
     88     public void onResume() {
     89         super.onResume();
     90         if (AccessibilityHelper.forceFocusableViews(getActivity())) {
     91             TextView titleView = (TextView) getView().findViewById(R.id.status_text);
     92             titleView.requestFocus();
     93         }
     94     }
     95 }
     96