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.arch.lifecycle.ViewModelProviders; 20 import android.content.Context; 21 import android.os.Bundle; 22 import android.support.v17.leanback.widget.GuidanceStylist; 23 import android.support.v17.leanback.widget.GuidedAction; 24 import android.support.v4.app.Fragment; 25 import android.support.v4.app.FragmentActivity; 26 27 import com.android.tv.settings.R; 28 import com.android.tv.settings.connectivity.util.State; 29 import com.android.tv.settings.connectivity.util.StateMachine; 30 31 import java.util.List; 32 33 /** 34 * State responsible for displaying the summary of not connected network. 35 */ 36 public class SummaryNotConnectedState implements State { 37 private Fragment mFragment; 38 private FragmentActivity mActivity; 39 40 public SummaryNotConnectedState(FragmentActivity activity) { 41 mActivity = activity; 42 } 43 44 @Override 45 public void processForward() { 46 mFragment = new SummaryNotConnectedWifiFragment(); 47 FragmentChangeListener listener = (FragmentChangeListener) mActivity; 48 if (listener != null) { 49 listener.onFragmentChange(mFragment, true); 50 } 51 } 52 53 @Override 54 public void processBackward() { 55 mFragment = new SummaryNotConnectedWifiFragment(); 56 FragmentChangeListener listener = (FragmentChangeListener) mActivity; 57 if (listener != null) { 58 listener.onFragmentChange(mFragment, false); 59 } 60 } 61 62 @Override 63 public Fragment getFragment() { 64 return mFragment; 65 } 66 67 /** 68 * Fragment that shows the Wi-Fi is not connected. 69 */ 70 public static class SummaryNotConnectedWifiFragment extends WifiConnectivityGuidedStepFragment { 71 private static final int ACTION_OK = 100001; 72 private StateMachine mStateMachine; 73 private UserChoiceInfo mUserChoiceInfo; 74 75 @Override 76 public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) { 77 Context context = getActivity(); 78 actions.add(new GuidedAction.Builder(context) 79 .title(R.string.wifi_action_ok) 80 .build()); 81 } 82 83 @Override 84 public GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) { 85 return new GuidanceStylist.Guidance( 86 getString(R.string.wifi_summary_title_not_connected), 87 null, 88 null, 89 null); 90 } 91 92 @Override 93 public void onCreate(Bundle savedInstanceState) { 94 mUserChoiceInfo = ViewModelProviders 95 .of(getActivity()) 96 .get(UserChoiceInfo.class); 97 mStateMachine = ViewModelProviders 98 .of(getActivity()) 99 .get(StateMachine.class); 100 super.onCreate(savedInstanceState); 101 } 102 103 @Override 104 public void onGuidedActionClicked(GuidedAction action) { 105 if (action.getId() == ACTION_OK) { 106 mUserChoiceInfo.removePageSummary(UserChoiceInfo.SELECT_WIFI); 107 mStateMachine.getListener() 108 .onComplete(StateMachine.SELECT_WIFI); 109 } 110 } 111 } 112 } 113