Home | History | Annotate | Download | only in connectivity
      1 /*
      2  * Copyright (C) 2018 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;
     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.setup.WifiConnectivityGuidedStepFragment;
     29 import com.android.tv.settings.connectivity.util.State;
     30 import com.android.tv.settings.connectivity.util.StateMachine;
     31 
     32 import java.util.List;
     33 
     34 /**
     35  * State responsible for showing the save failure page.
     36  */
     37 public class SaveFailedState implements State {
     38     private final FragmentActivity mActivity;
     39     private Fragment mFragment;
     40 
     41     public SaveFailedState(FragmentActivity activity) {
     42         mActivity = activity;
     43     }
     44 
     45     @Override
     46     public void processForward() {
     47         mFragment = new SaveFailedFragment();
     48         FragmentChangeListener listener = (FragmentChangeListener) mActivity;
     49         if (listener != null) {
     50             listener.onFragmentChange(mFragment, true);
     51         }
     52     }
     53 
     54     @Override
     55     public void processBackward() {
     56         StateMachine sm = ViewModelProviders.of(mActivity).get(StateMachine.class);
     57         sm.back();
     58     }
     59 
     60     @Override
     61     public Fragment getFragment() {
     62         return mFragment;
     63     }
     64 
     65     /**
     66      * Fragment that needs user to enter dns1.
     67      */
     68     public static class SaveFailedFragment extends WifiConnectivityGuidedStepFragment {
     69         private StateMachine mStateMachine;
     70 
     71         @Override
     72         public GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) {
     73             return new GuidanceStylist.Guidance(
     74                     getString(R.string.title_wifi_could_not_save),
     75                     null,
     76                     null,
     77                     null);
     78         }
     79 
     80         @Override
     81         public void onCreate(Bundle savedInstanceState) {
     82             mStateMachine = ViewModelProviders
     83                     .of(getActivity())
     84                     .get(StateMachine.class);
     85             super.onCreate(savedInstanceState);
     86         }
     87 
     88         @Override
     89         public void onCreateActions(List<GuidedAction> actions, Bundle savedInstanceState) {
     90             Context context = getActivity();
     91             actions.add(new GuidedAction.Builder(context)
     92                     .title(getString(R.string.wifi_action_ok))
     93                     .id(GuidedAction.ACTION_ID_CONTINUE)
     94                     .build());
     95         }
     96 
     97         @Override
     98         public void onGuidedActionClicked(GuidedAction action) {
     99             if (action.getId() == GuidedAction.ACTION_ID_CONTINUE) {
    100                 mStateMachine.getListener().onComplete(StateMachine.FAIL);
    101             }
    102         }
    103     }
    104 }
    105