• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.os.Build;
20 import android.os.Bundle;
21 import android.support.annotation.NonNull;
22 import android.support.v17.leanback.app.GuidedStepFragment;
23 import android.support.v17.leanback.widget.GuidanceStylist;
24 import android.support.v17.leanback.widget.GuidedAction;
25 import android.text.TextUtils;
26 
27 import com.android.tv.settings.R;
28 
29 import java.util.List;
30 
31 public class DeviceNameSetCustomFragment extends GuidedStepFragment {
32 
newInstance()33     public static DeviceNameSetCustomFragment newInstance() {
34         return new DeviceNameSetCustomFragment();
35     }
36 
37     @NonNull
38     @Override
onCreateGuidance(Bundle savedInstanceState)39     public GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) {
40         return new GuidanceStylist.Guidance(
41                 getString(R.string.select_device_name_title, Build.MODEL),
42                 getString(R.string.select_device_name_description, Build.MODEL),
43                 null,
44                 null);
45     }
46 
47     @Override
onCreateActions(@onNull List<GuidedAction> actions, Bundle savedInstanceState)48     public void onCreateActions(@NonNull List<GuidedAction> actions, Bundle savedInstanceState) {
49         actions.add(new GuidedAction.Builder()
50                 .title(DeviceManager.getDeviceName(getActivity()))
51                 .editable(true)
52                 .build());
53     }
54 
55     @Override
onGuidedActionEditedAndProceed(GuidedAction action)56     public long onGuidedActionEditedAndProceed(GuidedAction action) {
57         final CharSequence name = action.getTitle();
58         if (TextUtils.isGraphic(name)) {
59             DeviceManager.setDeviceName(getActivity(), name.toString());
60             getActivity().finish();
61             return super.onGuidedActionEditedAndProceed(action);
62         } else {
63             return GuidedAction.ACTION_ID_CURRENT;
64         }
65     }
66 }
67