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.device.storage;
18 
19 import android.os.Bundle;
20 import android.os.storage.DiskInfo;
21 
22 import androidx.annotation.NonNull;
23 import androidx.leanback.app.GuidedStepFragment;
24 import androidx.leanback.widget.GuidanceStylist;
25 import androidx.leanback.widget.GuidedAction;
26 
27 import com.android.tv.settings.R;
28 
29 import java.util.List;
30 
31 public class FormatAsPrivateStepFragment extends GuidedStepFragment {
32 
33     private static final int ACTION_ID_FORMAT = 1;
34 //    private static final int ACTION_ID_LEARN_MORE = 2;
35 
36     public interface Callback {
onRequestFormatAsPrivate(String diskId)37         void onRequestFormatAsPrivate(String diskId);
onCancelFormatDialog()38         void onCancelFormatDialog();
39     }
40 
newInstance(String diskId)41     public static FormatAsPrivateStepFragment newInstance(String diskId) {
42         final FormatAsPrivateStepFragment fragment = new FormatAsPrivateStepFragment();
43         final Bundle b = new Bundle(1);
44         b.putString(DiskInfo.EXTRA_DISK_ID, diskId);
45         fragment.setArguments(b);
46         return fragment;
47     }
48 
49     @Override
onCreateGuidance(Bundle savedInstanceState)50     public @NonNull GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) {
51         return new GuidanceStylist.Guidance(
52                 getString(R.string.storage_wizard_format_as_private_title),
53                 getString(R.string.storage_wizard_format_as_private_description), "",
54                 getActivity().getDrawable(R.drawable.ic_warning_132dp));
55     }
56 
57     @Override
onCreateActions(@onNull List<GuidedAction> actions, Bundle savedInstanceState)58     public void onCreateActions(@NonNull List<GuidedAction> actions, Bundle savedInstanceState) {
59         actions.add(new GuidedAction.Builder(getContext())
60                 .clickAction(GuidedAction.ACTION_ID_CANCEL)
61                 .build());
62         actions.add(new GuidedAction.Builder(getContext())
63                 .id(ACTION_ID_FORMAT)
64                 .title(getString(R.string.storage_wizard_format_action))
65                 .build());
66         // TODO: enable this when we have something useful to link to
67         /* actions.add(new GuidedAction.Builder()
68                 .id(ACTION_ID_LEARN_MORE)
69                 .title(getString(R.string.learn_more_action))
70                 .build()); */
71     }
72 
73     @Override
onGuidedActionClicked(GuidedAction action)74     public void onGuidedActionClicked(GuidedAction action) {
75         final long id = action.getId();
76 
77         if (id == GuidedAction.ACTION_ID_CANCEL) {
78             final Callback callback = (Callback) getActivity();
79             callback.onCancelFormatDialog();
80         } else if (id == ACTION_ID_FORMAT) {
81             final Callback callback = (Callback) getActivity();
82             callback.onRequestFormatAsPrivate(getArguments().getString(DiskInfo.EXTRA_DISK_ID));
83         } /* else if (id == ACTION_ID_LEARN_MORE) {
84             // todo
85         } */
86     }
87 }
88