165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane/*
2b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantler * Copyright (C) 2015 The Android Open Source Project
365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane *
465a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Licensed under the Apache License, Version 2.0 (the "License");
565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * you may not use this file except in compliance with the License.
665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * You may obtain a copy of the License at
765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane *
865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane *      http://www.apache.org/licenses/LICENSE-2.0
965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane *
1065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * Unless required by applicable law or agreed to in writing, software
1165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * distributed under the License is distributed on an "AS IS" BASIS,
1265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane * See the License for the specific language governing permissions and
14b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantler * limitations under the License
1565a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane */
1665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
1765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lanepackage com.android.tv.settings.name;
1865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
1965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.app.Activity;
20846b83807749cd73aa1b75749e8d072e8f58860dDake Guimport android.content.Context;
21b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantlerimport android.os.Build;
2265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Laneimport android.os.Bundle;
23b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantlerimport android.support.annotation.NonNull;
24b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantlerimport android.support.v17.leanback.app.GuidedStepFragment;
25b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantlerimport android.support.v17.leanback.widget.GuidanceStylist;
26b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantlerimport android.support.v17.leanback.widget.GuidedAction;
2765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
28b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantlerimport com.android.tv.settings.R;
2965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
30b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantlerimport java.util.List;
3165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
32b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantlerpublic class DeviceNameSummaryFragment extends GuidedStepFragment {
3365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
34b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantler    public static DeviceNameSummaryFragment newInstance() {
35b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantler        return new DeviceNameSummaryFragment();
3665a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    }
3765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
38b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantler    @NonNull
3965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    @Override
40b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantler    public GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) {
41b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantler        return new GuidanceStylist.Guidance(
42b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantler                getString(R.string.device_rename_title, Build.MODEL),
43b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantler                getString(R.string.device_rename_description, Build.MODEL,
44b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantler                        DeviceManager.getDeviceName(getActivity())),
45b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantler                null,
46b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantler                null);
4765a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    }
4865a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
4965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    @Override
50b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantler    public void onCreateActions(@NonNull List<GuidedAction> actions, Bundle savedInstanceState) {
51846b83807749cd73aa1b75749e8d072e8f58860dDake Gu        final Context context = getActivity();
52846b83807749cd73aa1b75749e8d072e8f58860dDake Gu        actions.add(new GuidedAction.Builder(context)
53846b83807749cd73aa1b75749e8d072e8f58860dDake Gu                .id(GuidedAction.ACTION_ID_CONTINUE)
54846b83807749cd73aa1b75749e8d072e8f58860dDake Gu                .title(R.string.change_setting)
55b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantler                .build());
56846b83807749cd73aa1b75749e8d072e8f58860dDake Gu        actions.add(new GuidedAction.Builder(context)
57846b83807749cd73aa1b75749e8d072e8f58860dDake Gu                .id(GuidedAction.ACTION_ID_CANCEL)
58846b83807749cd73aa1b75749e8d072e8f58860dDake Gu                .title(R.string.keep_settings)
59b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantler                .build());
6065a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    }
6165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane
6265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    @Override
63b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantler    public void onGuidedActionClicked(GuidedAction action) {
64b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantler        final long actionId = action.getId();
65b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantler        if (actionId == GuidedAction.ACTION_ID_CONTINUE) {
66b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantler            GuidedStepFragment.add(getFragmentManager(), DeviceNameSetFragment.newInstance());
67b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantler        } else if (actionId == GuidedAction.ACTION_ID_CANCEL) {
68b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantler            getActivity().finish();
6965a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        } else {
70b172e3b4a955f81a37249b376f946ef2eeac074dTony Mantler            throw new IllegalStateException("Unknown action");
7165a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane        }
7265a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane    }
7365a5a7d84ad9b5324ae53eda526e39e513473af7Christopher Lane}
74