1 /*
2  * Copyright (C) 2022 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.privacy;
18 
19 import android.content.Context;
20 import android.graphics.drawable.Animatable;
21 import android.graphics.drawable.Drawable;
22 import android.os.Bundle;
23 import android.util.Log;
24 import android.view.LayoutInflater;
25 import android.view.View;
26 import android.view.ViewGroup;
27 import android.widget.ImageView;
28 import android.widget.TextView;
29 
30 import androidx.annotation.Keep;
31 import androidx.annotation.NonNull;
32 
33 import com.android.tv.settings.R;
34 import com.android.tv.twopanelsettings.slices.InfoFragment;
35 
36 
37 /**
38  * A {@link InfoFragment} that hosts the preview pane of the physical privacy enabled info box when
39  * it is focused.
40  */
41 @Keep
42 public class PhysicalPrivacyUnblockInfoFragment extends InfoFragment {
43 
44     private static final String TAG = "PhysicalPrivacyUnblockInfoFragment";
45     public static final String TOGGLE_EXTRA = "toggle";
46 
47     private PrivacyToggle mToggle;
48 
49     @Override
onAttach(@onNull Context context)50     public void onAttach(@NonNull Context context) {
51         super.onAttach(context);
52         mToggle = (PrivacyToggle) getArguments().get(TOGGLE_EXTRA);
53         if (mToggle == null) {
54             Log.e(TAG, "toggle not set as an extra");
55         }
56     }
57 
58     @Override
onCreate(Bundle savedInstanceState)59     public void onCreate(Bundle savedInstanceState) {
60         super.onCreate(savedInstanceState);
61     }
62 
63     @Override
onCreateView( LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)64     public View onCreateView(
65             LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
66 
67         View view = super.onCreateView(inflater, container, savedInstanceState);
68 
69         ImageView infoImage = view.findViewById(R.id.info_image);
70         infoImage.setImageResource(mToggle.physicalPrivacyEnabledInfoPanelImage);
71 
72         ImageView icon = view.findViewById(R.id.info_title_icon);
73         icon.setImageResource(R.drawable.ic_info_outline_base);
74         icon.setVisibility(View.VISIBLE);
75 
76         TextView titleView = view.findViewById(R.id.info_title);
77         titleView.setVisibility(View.VISIBLE);
78         titleView.setText(mToggle.physicalPrivacyEnabledInfoTitle);
79 
80         TextView infoSummary = view.findViewById(R.id.info_summary);
81         infoSummary.setText(mToggle.physicalPrivacyEnabledInfoPanelText);
82 
83         return view;
84     }
85 
86     @Override
onStart()87     public void onStart() {
88         super.onStart();
89 
90         ImageView infoImage = getView().findViewById(R.id.info_image);
91         if (infoImage != null) {
92             Drawable image = infoImage.getDrawable();
93             if (image instanceof Animatable) {
94                 ((Animatable) image).start();
95             }
96         }
97     }
98 }
99