Add summary text for more top level setting tiles

- Connected devices
- App & notifs
- Battery

Bug: 110405144
Test: robotests
Change-Id: Ife44f7c5165483a1bad903ce90a241108ab5da25
This commit is contained in:
Fan Zhang
2018-08-09 09:51:35 -07:00
parent 25d9f3812b
commit f6747a2f44
17 changed files with 700 additions and 237 deletions

View File

@@ -121,7 +121,6 @@ public class Settings extends SettingsActivity {
}
public static class DirectoryAccessSettingsActivity extends SettingsActivity { /* empty */ }
public static class TopLevelSettings extends SettingsActivity { /* empty */ }
public static class ApnSettingsActivity extends SettingsActivity { /* empty */ }
public static class WifiCallingSettingsActivity extends SettingsActivity { /* empty */ }
public static class MemorySettingsActivity extends SettingsActivity { /* empty */ }

View File

@@ -0,0 +1,68 @@
/*
* 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.accounts;
import android.content.Context;
import android.icu.text.ListFormatter;
import android.os.UserHandle;
import android.text.BidiFormatter;
import android.text.TextUtils;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.accounts.AuthenticatorHelper;
import java.util.ArrayList;
import java.util.List;
public class TopLevelAccountEntryPreferenceController extends BasePreferenceController {
public TopLevelAccountEntryPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE_UNSEARCHABLE;
}
@Override
public CharSequence getSummary() {
final AuthenticatorHelper authHelper = new AuthenticatorHelper(mContext,
UserHandle.of(UserHandle.myUserId()), null /* OnAccountsUpdateListener */);
final String[] types = authHelper.getEnabledAccountTypes();
final BidiFormatter bidiFormatter = BidiFormatter.getInstance();
final List<CharSequence> summaries = new ArrayList<>();
if (types == null || types.length == 0) {
summaries.add(mContext.getString(R.string.account_dashboard_default_summary));
} else {
// Show up to 3 account types, ignore any null value
int accountToAdd = Math.min(3, types.length);
for (int i = 0; i < types.length && accountToAdd > 0; i++) {
final CharSequence label = authHelper.getLabelForType(mContext, types[i]);
if (TextUtils.isEmpty(label)) {
continue;
}
summaries.add(bidiFormatter.unicodeWrap(label));
accountToAdd--;
}
}
return ListFormatter.getInstance().format(summaries);
}
}

View File

@@ -0,0 +1,40 @@
/*
* 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.connecteddevice;
import android.content.Context;
import com.android.settings.core.BasePreferenceController;
public class TopLevelConnectedDevicesPreferenceController extends BasePreferenceController {
public TopLevelConnectedDevicesPreferenceController(Context context,
String preferenceKey) {
super(context, preferenceKey);
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE_UNSEARCHABLE;
}
@Override
public CharSequence getSummary() {
return mContext.getText(
AdvancedConnectedDeviceController.getConnectedDevicesSummaryResourceId(mContext));
}
}

View File

@@ -26,6 +26,11 @@ import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.VisibleForTesting;
import androidx.annotation.WorkerThread;
import androidx.loader.app.LoaderManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.core.InstrumentedFragment;
@@ -46,11 +51,12 @@ import com.android.settingslib.utils.ThreadUtils;
import java.util.List;
import androidx.annotation.VisibleForTesting;
import androidx.annotation.WorkerThread;
import androidx.loader.app.LoaderManager;
import androidx.recyclerview.widget.LinearLayoutManager;
/**
* Deprecated in favor of {@link com.android.settings.homepage.TopLevelSettings}
*
* @deprecated
*/
@Deprecated
public class DashboardSummary extends InstrumentedFragment
implements CategoryListener, ConditionListener,
FocusListener, SuggestionControllerMixinCompat.SuggestionControllerHost {

View File

@@ -0,0 +1,57 @@
/*
* 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.deviceinfo;
import android.content.Context;
import android.os.storage.StorageManager;
import android.text.format.Formatter;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.deviceinfo.PrivateStorageInfo;
import com.android.settingslib.deviceinfo.StorageManagerVolumeProvider;
import java.text.NumberFormat;
public class TopLevelStoragePreferenceController extends BasePreferenceController {
private final StorageManager mStorageManager;
private final StorageManagerVolumeProvider mStorageManagerVolumeProvider;
public TopLevelStoragePreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
mStorageManager = mContext.getSystemService(StorageManager.class);
mStorageManagerVolumeProvider = new StorageManagerVolumeProvider(mStorageManager);
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE_UNSEARCHABLE;
}
@Override
public CharSequence getSummary() {
// TODO: Register listener.
final NumberFormat percentageFormat = NumberFormat.getPercentInstance();
final PrivateStorageInfo info = PrivateStorageInfo.getPrivateStorageInfo(
mStorageManagerVolumeProvider);
double privateUsedBytes = info.totalBytes - info.freeBytes;
return mContext.getString(R.string.storage_summary,
percentageFormat.format(privateUsedBytes / info.totalBytes),
Formatter.formatFileSize(mContext, info.freeBytes));
}
}

View File

@@ -17,13 +17,13 @@
package com.android.settings.fuelgauge;
import static com.android.settings.fuelgauge.BatteryBroadcastReceiver.BatteryUpdateType;
import static com.android.settings.fuelgauge.TopLevelBatteryPreferenceController.getDashboardLabel;
import android.app.Activity;
import android.content.Context;
import android.os.BatteryStats;
import android.os.Bundle;
import android.provider.SearchIndexableResource;
import android.text.BidiFormatter;
import android.text.format.Formatter;
import android.view.Menu;
import android.view.MenuInflater;
@@ -32,6 +32,11 @@ import android.view.View;
import android.view.View.OnLongClickListener;
import android.widget.TextView;
import androidx.annotation.VisibleForTesting;
import androidx.loader.app.LoaderManager;
import androidx.loader.app.LoaderManager.LoaderCallbacks;
import androidx.loader.content.Loader;
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
import com.android.settings.R;
import com.android.settings.SettingsActivity;
@@ -51,11 +56,6 @@ import com.android.settingslib.utils.StringUtil;
import java.util.Collections;
import java.util.List;
import androidx.annotation.VisibleForTesting;
import androidx.loader.app.LoaderManager;
import androidx.loader.app.LoaderManager.LoaderCallbacks;
import androidx.loader.content.Loader;
/**
* Displays a list of apps and subsystems that consume power, ordered by how much power was
* consumed since the last time it was unplugged.
@@ -147,9 +147,9 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
protected void updateViews(List<BatteryInfo> batteryInfos) {
final BatteryMeterView batteryView = mBatteryLayoutPref
.findViewById(R.id.battery_header_icon);
.findViewById(R.id.battery_header_icon);
final TextView percentRemaining =
mBatteryLayoutPref.findViewById(R.id.battery_percent);
mBatteryLayoutPref.findViewById(R.id.battery_percent);
final TextView summary1 = mBatteryLayoutPref.findViewById(R.id.summary1);
final TextView summary2 = mBatteryLayoutPref.findViewById(R.id.summary2);
BatteryInfo oldInfo = batteryInfos.get(0);
@@ -160,13 +160,13 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
// can sometimes say 0 time remaining because battery stats requires the phone
// be unplugged for a period of time before being willing ot make an estimate.
summary1.setText(mPowerFeatureProvider.getOldEstimateDebugString(
Formatter.formatShortElapsedTime(getContext(),
PowerUtil.convertUsToMs(oldInfo.remainingTimeUs))));
Formatter.formatShortElapsedTime(getContext(),
PowerUtil.convertUsToMs(oldInfo.remainingTimeUs))));
// for this one we can just set the string directly
summary2.setText(mPowerFeatureProvider.getEnhancedEstimateDebugString(
Formatter.formatShortElapsedTime(getContext(),
PowerUtil.convertUsToMs(newInfo.remainingTimeUs))));
Formatter.formatShortElapsedTime(getContext(),
PowerUtil.convertUsToMs(newInfo.remainingTimeUs))));
batteryView.setBatteryLevel(oldInfo.batteryLevel);
batteryView.setCharging(!oldInfo.discharging);
@@ -419,19 +419,6 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
}
}
@VisibleForTesting
static CharSequence getDashboardLabel(Context context, BatteryInfo info) {
CharSequence label;
final BidiFormatter formatter = BidiFormatter.getInstance();
if (info.remainingLabel == null) {
label = info.batteryPercentString;
} else {
label = context.getString(R.string.power_remaining_settings_home_page,
formatter.unicodeWrap(info.batteryPercentString),
formatter.unicodeWrap(info.remainingLabel));
}
return label;
}
public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =
new BaseSearchIndexProvider() {

View File

@@ -0,0 +1,90 @@
/*
* 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.fuelgauge;
import android.content.Context;
import android.text.BidiFormatter;
import androidx.preference.Preference;
import androidx.preference.PreferenceScreen;
import com.android.settings.R;
import com.android.settings.core.BasePreferenceController;
import com.android.settingslib.core.lifecycle.LifecycleObserver;
import com.android.settingslib.core.lifecycle.events.OnStart;
import com.android.settingslib.core.lifecycle.events.OnStop;
public class TopLevelBatteryPreferenceController extends BasePreferenceController implements
LifecycleObserver, OnStart, OnStop {
private final BatteryBroadcastReceiver mBatteryBroadcastReceiver;
private Preference mPreference;
private BatteryInfo mBatteryInfo;
public TopLevelBatteryPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
mBatteryBroadcastReceiver = new BatteryBroadcastReceiver(mContext);
mBatteryBroadcastReceiver.setBatteryChangedListener(type -> {
BatteryInfo.getBatteryInfo(mContext, info -> {
mBatteryInfo = info;
updateState(mPreference);
}, true /* shortString */);
});
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE_UNSEARCHABLE;
}
@Override
public void displayPreference(PreferenceScreen screen) {
super.displayPreference(screen);
mPreference = screen.findPreference(getPreferenceKey());
}
@Override
public void onStart() {
mBatteryBroadcastReceiver.register();
}
@Override
public void onStop() {
mBatteryBroadcastReceiver.unRegister();
}
@Override
public CharSequence getSummary() {
return getDashboardLabel(mContext, mBatteryInfo);
}
static CharSequence getDashboardLabel(Context context, BatteryInfo info) {
if (info == null || context == null) {
return null;
}
CharSequence label;
final BidiFormatter formatter = BidiFormatter.getInstance();
if (info.remainingLabel == null) {
label = info.batteryPercentString;
} else {
label = context.getString(R.string.power_remaining_settings_home_page,
formatter.unicodeWrap(info.batteryPercentString),
formatter.unicodeWrap(info.remainingLabel));
}
return label;
}
}

View File

@@ -0,0 +1,52 @@
/*
* 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.security;
import android.content.Context;
import android.hardware.face.FaceManager;
import android.hardware.fingerprint.FingerprintManager;
import com.android.settings.R;
import com.android.settings.Utils;
import com.android.settings.core.BasePreferenceController;
public class TopLevelSecurityEntryPreferenceController extends BasePreferenceController {
public TopLevelSecurityEntryPreferenceController(Context context, String preferenceKey) {
super(context, preferenceKey);
}
@Override
public int getAvailabilityStatus() {
return AVAILABLE_UNSEARCHABLE;
}
@Override
public CharSequence getSummary() {
final FingerprintManager fpm =
Utils.getFingerprintManagerOrNull(mContext);
final FaceManager faceManager =
Utils.getFaceManagerOrNull(mContext);
if (faceManager != null && faceManager.isHardwareDetected()) {
return mContext.getText(R.string.security_dashboard_summary_face);
} else if (fpm != null && fpm.isHardwareDetected()) {
return mContext.getText(R.string.security_dashboard_summary);
} else {
return mContext.getText(R.string.security_dashboard_summary_no_fingerprint);
}
}
}