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.packageinstaller.permission.ui.television;
18 
19 import android.content.Intent;
20 import android.graphics.drawable.Drawable;
21 import android.os.Bundle;
22 import android.view.LayoutInflater;
23 import android.view.View;
24 import android.view.View.OnClickListener;
25 import android.view.ViewGroup;
26 import android.widget.ImageView;
27 import android.widget.TextView;
28 import com.android.packageinstaller.DeviceUtils;
29 import com.android.packageinstaller.R;
30 
31 public abstract class SettingsWithHeader extends PermissionsFrameFragment
32         implements OnClickListener {
33 
34     private View mHeader;
35     protected Intent mInfoIntent;
36     protected Drawable mIcon;
37     protected CharSequence mLabel;
38     protected CharSequence mDecorTitle;
39 
40     @Override
onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)41     public View onCreateView(LayoutInflater inflater, ViewGroup container,
42             Bundle savedInstanceState) {
43         ViewGroup root = (ViewGroup) super.onCreateView(inflater, container, savedInstanceState);
44 
45         mHeader = inflater.inflate(R.layout.header, root, false);
46         getPreferencesContainer().addView(mHeader, 0);
47         updateHeader();
48 
49         return root;
50     }
51 
setHeader(Drawable icon, CharSequence label, Intent infoIntent, CharSequence decorTitle)52     public void setHeader(Drawable icon, CharSequence label, Intent infoIntent,
53                           CharSequence decorTitle) {
54         mIcon = icon;
55         mLabel = label;
56         mInfoIntent = infoIntent;
57         mDecorTitle = decorTitle;
58         updateHeader();
59     }
60 
getHeader()61     public View getHeader() {
62         return mHeader;
63     }
64 
updateHeader()65     protected void updateHeader() {
66             final TextView decorTitle = (TextView) mHeader.findViewById(R.id.decor_title);
67             decorTitle.setText(mDecorTitle);
68     }
69 
70     @Override
onClick(View v)71     public void onClick(View v) {
72         getActivity().startActivity(mInfoIntent);
73     }
74 }
75