1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
12 * the License.
13 */
14
15package android.support.v17.leanback.supportleanbackshowcase.app.dialog;
16
17import android.os.Bundle;
18import android.support.annotation.NonNull;
19import android.support.v17.leanback.app.GuidedStepFragment;
20import android.support.v17.leanback.supportleanbackshowcase.R;
21import android.support.v17.leanback.widget.GuidanceStylist.Guidance;
22import android.support.v17.leanback.widget.GuidedAction;
23import android.widget.Toast;
24
25import java.util.List;
26
27/**
28 * TODO: Javadoc
29 */
30public class DialogExampleFragment extends GuidedStepFragment {
31
32    private static final int ACTION_ID_POSITIVE = 1;
33    private static final int ACTION_ID_NEGATIVE = ACTION_ID_POSITIVE + 1;
34
35    @NonNull
36    @Override
37    public Guidance onCreateGuidance(Bundle savedInstanceState) {
38        Guidance guidance = new Guidance(getString(R.string.dialog_example_title),
39                getString(R.string.dialog_example_description),
40                "", null);
41        return guidance;
42    }
43
44    @Override
45    public void onCreateActions(@NonNull List<GuidedAction> actions, Bundle savedInstanceState) {
46        GuidedAction action = new GuidedAction.Builder()
47                .id(ACTION_ID_POSITIVE)
48                .title(getString(R.string.dialog_example_button_positive)).build();
49        actions.add(action);
50        action = new GuidedAction.Builder()
51                .id(ACTION_ID_NEGATIVE)
52                .title(getString(R.string.dialog_example_button_negative)).build();
53        actions.add(action);
54    }
55
56    @Override
57    public void onGuidedActionClicked(GuidedAction action) {
58        if (ACTION_ID_POSITIVE == action.getId()) {
59            Toast.makeText(getActivity(), R.string.dialog_example_button_toast_positive_clicked,
60                    Toast.LENGTH_SHORT).show();
61        } else {
62            Toast.makeText(getActivity(), R.string.dialog_example_button_toast_negative_clicked,
63                    Toast.LENGTH_SHORT).show();
64        }
65        getActivity().finish();
66    }
67}
68