Home | History | Annotate | Download | only in name
      1 /*
      2  * Copyright (C) 2015 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.name;
     18 
     19 import android.app.Activity;
     20 import android.content.Context;
     21 import android.os.Build;
     22 import android.os.Bundle;
     23 import android.support.annotation.NonNull;
     24 import android.support.v17.leanback.app.GuidedStepFragment;
     25 import android.support.v17.leanback.widget.GuidanceStylist;
     26 import android.support.v17.leanback.widget.GuidedAction;
     27 
     28 import com.android.tv.settings.R;
     29 
     30 import java.util.List;
     31 
     32 public class DeviceNameSummaryFragment extends GuidedStepFragment {
     33 
     34     public static DeviceNameSummaryFragment newInstance() {
     35         return new DeviceNameSummaryFragment();
     36     }
     37 
     38     @NonNull
     39     @Override
     40     public GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) {
     41         return new GuidanceStylist.Guidance(
     42                 getString(R.string.device_rename_title, Build.MODEL),
     43                 getString(R.string.device_rename_description, Build.MODEL,
     44                         DeviceManager.getDeviceName(getActivity())),
     45                 null,
     46                 null);
     47     }
     48 
     49     @Override
     50     public void onCreateActions(@NonNull List<GuidedAction> actions, Bundle savedInstanceState) {
     51         final Context context = getActivity();
     52         actions.add(new GuidedAction.Builder(context)
     53                 .id(GuidedAction.ACTION_ID_CONTINUE)
     54                 .title(R.string.change_setting)
     55                 .build());
     56         actions.add(new GuidedAction.Builder(context)
     57                 .id(GuidedAction.ACTION_ID_CANCEL)
     58                 .title(R.string.keep_settings)
     59                 .build());
     60     }
     61 
     62     @Override
     63     public void onGuidedActionClicked(GuidedAction action) {
     64         final long actionId = action.getId();
     65         if (actionId == GuidedAction.ACTION_ID_CONTINUE) {
     66             GuidedStepFragment.add(getFragmentManager(), DeviceNameSetFragment.newInstance());
     67         } else if (actionId == GuidedAction.ACTION_ID_CANCEL) {
     68             getActivity().finish();
     69         } else {
     70             throw new IllegalStateException("Unknown action");
     71         }
     72     }
     73 }
     74