Add preference controller for app header view.

- move code related to initializing/refreshing the app header from
AppInfoDashboardFragment into a new controller.
- this is the last preference logic in AppInfoDashboardFragment. With
this change, the conversion into dashboad fragment will be considered
as complete.
- remaining work for the bug will be enable the feature flag and remove
the obsolete InstalledAppDetails.

Bug: 69384089
Test: make RunSettingsRoboTests
Change-Id: I14056bf291278b2b36f9502177c84edd6a899d0f
This commit is contained in:
Doris Ling
2017-12-14 14:23:41 -08:00
parent 91ffc73152
commit e712aed3d7
3 changed files with 193 additions and 41 deletions

View File

@@ -0,0 +1,92 @@
/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.android.settings.applications.appinfo;
import android.app.Activity;
import android.content.Context;
import android.content.pm.PackageInfo;
import android.support.v7.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.core.BasePreferenceController;
import com.android.settings.widget.EntityHeaderController;
import com.android.settingslib.applications.AppUtils;
import com.android.settingslib.applications.ApplicationsState.AppEntry;
import com.android.settingslib.core.lifecycle.Lifecycle;
public class AppHeaderViewPreferenceController extends BasePreferenceController
implements AppInfoDashboardFragment.Callback {
private static final String KEY_HEADER = "header_view";
private LayoutPreference mHeader;
private final AppInfoDashboardFragment mParent;
private final String mPackageName;
private final Lifecycle mLifecycle;
public AppHeaderViewPreferenceController(Context context, AppInfoDashboardFragment parent,
String packageName, Lifecycle lifecycle) {
super(context, KEY_HEADER);
mParent = parent;
mPackageName = packageName;
mLifecycle = lifecycle;
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mHeader = (LayoutPreference) screen.findPreference(KEY_HEADER);
final Activity activity = mParent.getActivity();
EntityHeaderController
.newInstance(activity, mParent, mHeader.findViewById(R.id.entity_header))
.setRecyclerView(mParent.getListView(), mLifecycle)
.setPackageName(mPackageName)
.setHasAppInfoLink(false)
.setButtonActions(EntityHeaderController.ActionType.ACTION_APP_PREFERENCE,
EntityHeaderController.ActionType.ACTION_NONE)
.styleActionBar(activity)
.bindHeaderButtons();
}
@Override
public void refreshUi() {
setAppLabelAndIcon(mParent.getPackageInfo(), mParent.getAppEntry());
}
// Utility method to set application label and icon.
private void setAppLabelAndIcon(PackageInfo pkgInfo, AppEntry appEntry) {
final Activity activity = mParent.getActivity();
final boolean isInstantApp = AppUtils.isInstant(pkgInfo.applicationInfo);
final CharSequence summary = isInstantApp
? null : mContext.getString(Utils.getInstallationStatus(appEntry.info));
EntityHeaderController
.newInstance(activity, mParent, mHeader.findViewById(R.id.entity_header))
.setLabel(appEntry)
.setIcon(appEntry)
.setSummary(summary)
.setIsInstantApp(isInstantApp)
.done(activity, false /* rebindActions */);
}
}