AppInfoWithHeader.java revision b83fd6c3d1b6d4d9321c6f8858a8ab996fd463e7
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
17package com.android.settings.applications;
18
19import static com.android.settings.widget.EntityHeaderController.ActionType;
20
21import android.app.Activity;
22import android.os.Bundle;
23import android.support.v7.preference.Preference;
24import android.util.IconDrawableFactory;
25import android.util.Log;
26
27import com.android.settings.widget.EntityHeaderController;
28import com.android.settingslib.applications.AppUtils;
29
30public abstract class AppInfoWithHeader extends AppInfoBase {
31
32    private boolean mCreated;
33
34    @Override
35    public void onActivityCreated(Bundle savedInstanceState) {
36        super.onActivityCreated(savedInstanceState);
37        if (mCreated) {
38            Log.w(TAG, "onActivityCreated: ignoring duplicate call");
39            return;
40        }
41        mCreated = true;
42        if (mPackageInfo == null) return;
43        final Activity activity = getActivity();
44        final Preference pref = EntityHeaderController
45                .newInstance(activity, this, null /* header */)
46                .setRecyclerView(getListView(), getLifecycle())
47                .setIcon(IconDrawableFactory.newInstance(getContext())
48                        .getBadgedIcon(mPackageInfo.applicationInfo))
49                .setLabel(mPackageInfo.applicationInfo.loadLabel(mPm))
50                .setSummary(mPackageInfo)
51                .setIsInstantApp(AppUtils.isInstant(mPackageInfo.applicationInfo))
52                .setPackageName(mPackageName)
53                .setUid(mPackageInfo.applicationInfo.uid)
54                .setHasAppInfoLink(true)
55                .setButtonActions(ActionType.ACTION_NONE, ActionType.ACTION_NONE)
56                .done(activity, getPrefContext());
57        getPreferenceScreen().addPreference(pref);
58    }
59}
60