• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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.system;
18 
19 import android.os.Bundle;
20 import android.support.annotation.Keep;
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 
26 import com.android.tv.settings.R;
27 
28 import java.util.List;
29 
30 @Keep
31 public class UnknownSourcesConfirmationFragment extends GuidedStepFragment {
32     public interface Callback {
onConfirmUnknownSources(boolean success)33         void onConfirmUnknownSources(boolean success);
34     }
35 
36     @NonNull
37     @Override
onCreateGuidance(Bundle savedInstanceState)38     public GuidanceStylist.Guidance onCreateGuidance(Bundle savedInstanceState) {
39         return new GuidanceStylist.Guidance(
40                 getString(R.string.security_unknown_sources_confirm_title),
41                 getString(R.string.security_unknown_sources_confirm_desc),
42                 null,
43                 getActivity().getDrawable(R.drawable.ic_warning_132dp)
44         );
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(getContext())
50                 .clickAction(GuidedAction.ACTION_ID_OK)
51                 .build());
52         actions.add(new GuidedAction.Builder(getContext())
53                 .clickAction(GuidedAction.ACTION_ID_CANCEL)
54                 .build());
55     }
56 
57     @Override
onGuidedActionClicked(GuidedAction action)58     public void onGuidedActionClicked(GuidedAction action) {
59         final Callback callback = (Callback) getTargetFragment();
60         if (action.getId() == GuidedAction.ACTION_ID_OK) {
61             callback.onConfirmUnknownSources(true);
62             getFragmentManager().popBackStack();
63         } else if (action.getId() == GuidedAction.ACTION_ID_CANCEL) {
64             callback.onConfirmUnknownSources(false);
65             getFragmentManager().popBackStack();
66         } else {
67             throw new IllegalArgumentException("Unknown action");
68         }
69     }
70 }
71