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.content.Context; 20 import android.os.Build; 21 import android.os.Bundle; 22 import android.view.LayoutInflater; 23 import android.view.View; 24 import android.view.ViewGroup; 25 26 import androidx.annotation.NonNull; 27 import androidx.leanback.app.GuidedStepSupportFragment; 28 import androidx.leanback.widget.GuidanceStylist; 29 import androidx.leanback.widget.GuidedAction; 30 import androidx.leanback.widget.GuidedActionsStylist; 31 32 import com.android.tv.settings.R; 33 import com.android.tv.settings.util.GuidedActionsAlignUtil; 34 35 import java.util.List; 36 37 /** 38 * Fragment responsible for showing the device name summary. 39 */ 40 public class DeviceNameSummaryFragment extends GuidedStepSupportFragment { 41 newInstance()42 public static DeviceNameSummaryFragment newInstance() { 43 return new DeviceNameSummaryFragment(); 44 } 45 46 @Override onCreateGuidanceStylist()47 public GuidanceStylist onCreateGuidanceStylist() { 48 return GuidedActionsAlignUtil.createGuidanceStylist(); 49 } 50 51 @Override onCreateActionsStylist()52 public GuidedActionsStylist onCreateActionsStylist() { 53 return GuidedActionsAlignUtil.createGuidedActionsStylist(); 54 } 55 56 @Override onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)57 public View onCreateView(LayoutInflater inflater, ViewGroup container, 58 Bundle savedInstanceState) { 59 View view = super.onCreateView(inflater, container, savedInstanceState); 60 return GuidedActionsAlignUtil.createView(view, this); 61 } 62 63 @NonNull 64 @Override onCreateGuidance(Bundle savedInstanceState)65 public GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) { 66 return new GuidanceStylist.Guidance( 67 getString(R.string.device_rename_title, Build.MODEL), 68 getString(R.string.device_rename_description, Build.MODEL, 69 DeviceManager.getDeviceName(getActivity())), 70 null, 71 null); 72 } 73 74 @Override onCreateActions(@onNull List<GuidedAction> actions, Bundle savedInstanceState)75 public void onCreateActions(@NonNull List<GuidedAction> actions, Bundle savedInstanceState) { 76 final Context context = getActivity(); 77 actions.add(new GuidedAction.Builder(context) 78 .id(GuidedAction.ACTION_ID_CONTINUE) 79 .title(R.string.change_setting) 80 .build()); 81 actions.add(new GuidedAction.Builder(context) 82 .id(GuidedAction.ACTION_ID_CANCEL) 83 .title(R.string.keep_settings) 84 .build()); 85 } 86 87 @Override onGuidedActionClicked(GuidedAction action)88 public void onGuidedActionClicked(GuidedAction action) { 89 final long actionId = action.getId(); 90 if (actionId == GuidedAction.ACTION_ID_CONTINUE) { 91 GuidedStepSupportFragment.add( 92 getFragmentManager(), DeviceNameSetFragment.newInstance()); 93 } else if (actionId == GuidedAction.ACTION_ID_CANCEL) { 94 getActivity().finish(); 95 } else { 96 throw new IllegalStateException("Unknown action"); 97 } 98 } 99 } 100