This adds the "Me Card" page. The current functionality is to show information based upon the first account added to the system. The page shows the user's avatar, name, primary account, and phone number. Bug: 63819909 Test: Robotest Change-Id: I64bfae922e828994b2b87009d0647e67dab0da42
138 lines
5.1 KiB
Java
138 lines
5.1 KiB
Java
/*
|
|
* Copyright (C) 2018 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;
|
|
|
|
import android.app.Activity;
|
|
import android.app.Fragment;
|
|
import android.content.Context;
|
|
import android.content.pm.UserInfo;
|
|
import android.os.Bundle;
|
|
import android.os.UserManager;
|
|
import android.provider.SearchIndexableResource;
|
|
import android.view.View;
|
|
|
|
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
|
import com.android.settings.applications.LayoutPreference;
|
|
import com.android.settings.dashboard.DashboardFragment;
|
|
import com.android.settings.deviceinfo.BrandedAccountPreferenceController;
|
|
import com.android.settings.deviceinfo.PhoneNumberPreferenceController;
|
|
import com.android.settings.search.BaseSearchIndexProvider;
|
|
import com.android.settings.search.Indexable;
|
|
import com.android.settings.widget.EntityHeaderController;
|
|
import com.android.settingslib.core.AbstractPreferenceController;
|
|
import com.android.settingslib.core.lifecycle.Lifecycle;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Arrays;
|
|
import java.util.List;
|
|
|
|
public class MeCardFragment extends DashboardFragment implements Indexable {
|
|
private static final String LOG_TAG = "MeCardFragment";
|
|
|
|
private static final String KEY_ME_CARD_HEADER = "me_card_header";
|
|
|
|
@Override
|
|
public int getMetricsCategory() {
|
|
return MetricsEvent.DEVICEINFO;
|
|
}
|
|
|
|
@Override
|
|
public int getHelpResource() {
|
|
return R.string.help_uri_about;
|
|
}
|
|
|
|
@Override
|
|
public void onResume() {
|
|
super.onResume();
|
|
initHeader();
|
|
}
|
|
|
|
@Override
|
|
protected String getLogTag() {
|
|
return LOG_TAG;
|
|
}
|
|
|
|
@Override
|
|
protected int getPreferenceScreenResId() {
|
|
return R.xml.me_card;
|
|
}
|
|
|
|
@Override
|
|
protected List<AbstractPreferenceController> getPreferenceControllers(Context context) {
|
|
return buildPreferenceControllers(context, getActivity(), this /* fragment */,
|
|
getLifecycle());
|
|
}
|
|
|
|
private static List<AbstractPreferenceController> buildPreferenceControllers(Context context,
|
|
Activity activity, Fragment fragment, Lifecycle lifecycle) {
|
|
final List<AbstractPreferenceController> controllers = new ArrayList<>();
|
|
controllers.add(new PhoneNumberPreferenceController(context));
|
|
controllers.add(new BrandedAccountPreferenceController(context));
|
|
// TODO: Add preference controller for getting the device name.
|
|
return controllers;
|
|
}
|
|
|
|
private void initHeader() {
|
|
// TODO: Migrate into its own controller.
|
|
final LayoutPreference headerPreference =
|
|
(LayoutPreference) getPreferenceScreen().findPreference(KEY_ME_CARD_HEADER);
|
|
final View appSnippet = headerPreference.findViewById(R.id.entity_header);
|
|
final Activity context = getActivity();
|
|
final Bundle bundle = getArguments();
|
|
EntityHeaderController controller = EntityHeaderController
|
|
.newInstance(context, this, appSnippet)
|
|
.setRecyclerView(getListView(), getLifecycle())
|
|
.setButtonActions(EntityHeaderController.ActionType.ACTION_NONE,
|
|
EntityHeaderController.ActionType.ACTION_NONE);
|
|
|
|
// TODO: There may be an avatar setting action we can use here.
|
|
final int iconId = bundle.getInt("icon_id", 0);
|
|
if (iconId == 0) {
|
|
UserManager userManager = (UserManager) getActivity().getSystemService(
|
|
Context.USER_SERVICE);
|
|
UserInfo info = Utils.getExistingUser(userManager, android.os.Process.myUserHandle());
|
|
controller.setLabel(info.name);
|
|
controller.setIcon(
|
|
com.android.settingslib.Utils.getUserIcon(getActivity(), userManager, info));
|
|
}
|
|
|
|
controller.done(context, true /* rebindActions */);
|
|
}
|
|
|
|
/**
|
|
* For Search.
|
|
*/
|
|
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
|
|
new BaseSearchIndexProvider() {
|
|
|
|
@Override
|
|
public List<SearchIndexableResource> getXmlResourcesToIndex(
|
|
Context context, boolean enabled) {
|
|
final SearchIndexableResource sir = new SearchIndexableResource(context);
|
|
sir.xmlResId = R.xml.me_card;
|
|
return Arrays.asList(sir);
|
|
}
|
|
|
|
@Override
|
|
public List<AbstractPreferenceController> getPreferenceControllers(
|
|
Context context) {
|
|
return buildPreferenceControllers(context, null /*activity */,
|
|
null /* fragment */, null /* lifecycle */);
|
|
}
|
|
};
|
|
}
|