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.handheld; 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 29 import com.android.packageinstaller.DeviceUtils; 30 import com.android.packageinstaller.R; 31 32 public abstract class SettingsWithHeader extends PermissionsFrameFragment 33 implements OnClickListener { 34 35 private View mHeader; 36 protected Intent mInfoIntent; 37 protected Drawable mIcon; 38 protected CharSequence mLabel; 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 if (!DeviceUtils.isTelevision(getContext())) { 46 mHeader = inflater.inflate(R.layout.header, root, false); 47 getPreferencesContainer().addView(mHeader, 0); 48 updateHeader(); 49 } 50 51 return root; 52 } 53 setHeader(Drawable icon, CharSequence label, Intent infoIntent)54 public void setHeader(Drawable icon, CharSequence label, Intent infoIntent) { 55 mIcon = icon; 56 mLabel = label; 57 mInfoIntent = infoIntent; 58 updateHeader(); 59 } 60 updateHeader()61 private void updateHeader() { 62 if (mHeader != null) { 63 final ImageView appIcon = (ImageView) mHeader.findViewById(R.id.icon); 64 appIcon.setImageDrawable(mIcon); 65 66 final TextView appName = (TextView) mHeader.findViewById(R.id.name); 67 appName.setText(mLabel); 68 69 final View info = mHeader.findViewById(R.id.info); 70 if (mInfoIntent == null) { 71 info.setVisibility(View.GONE); 72 } else { 73 info.setVisibility(View.VISIBLE); 74 info.setClickable(true); 75 info.setOnClickListener(this); 76 } 77 } 78 } 79 80 @Override onClick(View v)81 public void onClick(View v) { 82 getActivity().startActivity(mInfoIntent); 83 } 84 } 85