Improve notification slice string on home page

Add ContextualNotificationChannelSlice to show more clear sub title on
notification slice.

Fixes: 128641319
Test: visual, robotests
Change-Id: I650102f4cde7d8d397c7a501ba9ee76c401ba9db
This commit is contained in:
Yanting Yang
2019-03-19 18:17:50 +08:00
parent e4359a9eee
commit aed7ad5a43
6 changed files with 120 additions and 7 deletions

View File

@@ -17,8 +17,8 @@
package com.android.settings.homepage.contextualcards; package com.android.settings.homepage.contextualcards;
import static com.android.settings.slices.CustomSliceRegistry.BLUETOOTH_DEVICES_SLICE_URI; import static com.android.settings.slices.CustomSliceRegistry.BLUETOOTH_DEVICES_SLICE_URI;
import static com.android.settings.slices.CustomSliceRegistry.CONTEXTUAL_NOTIFICATION_CHANNEL_SLICE_URI;
import static com.android.settings.slices.CustomSliceRegistry.CONTEXTUAL_WIFI_SLICE_URI; import static com.android.settings.slices.CustomSliceRegistry.CONTEXTUAL_WIFI_SLICE_URI;
import static com.android.settings.slices.CustomSliceRegistry.NOTIFICATION_CHANNEL_SLICE_URI;
import android.content.Context; import android.content.Context;
import android.database.ContentObserver; import android.database.ContentObserver;
@@ -208,7 +208,7 @@ public class ContextualCardLoader extends AsyncLoaderCompat<List<ContextualCard>
private boolean isLargeCard(ContextualCard card) { private boolean isLargeCard(ContextualCard card) {
return card.getSliceUri().equals(CONTEXTUAL_WIFI_SLICE_URI) return card.getSliceUri().equals(CONTEXTUAL_WIFI_SLICE_URI)
|| card.getSliceUri().equals(BLUETOOTH_DEVICES_SLICE_URI) || card.getSliceUri().equals(BLUETOOTH_DEVICES_SLICE_URI)
|| card.getSliceUri().equals(NOTIFICATION_CHANNEL_SLICE_URI); || card.getSliceUri().equals(CONTEXTUAL_NOTIFICATION_CHANNEL_SLICE_URI);
} }
public interface CardContentLoaderListener { public interface CardContentLoaderListener {

View File

@@ -56,10 +56,12 @@ public class SettingsContextualCardProvider extends ContextualCardProvider {
.setCardName(CustomSliceRegistry.BATTERY_FIX_SLICE_URI.toString()) .setCardName(CustomSliceRegistry.BATTERY_FIX_SLICE_URI.toString())
.setCardCategory(ContextualCard.Category.IMPORTANT) .setCardCategory(ContextualCard.Category.IMPORTANT)
.build(); .build();
final String contextualNotificationChannelSliceUri =
CustomSliceRegistry.CONTEXTUAL_NOTIFICATION_CHANNEL_SLICE_URI.toString();
final ContextualCard notificationChannelCard = final ContextualCard notificationChannelCard =
ContextualCard.newBuilder() ContextualCard.newBuilder()
.setSliceUri(CustomSliceRegistry.NOTIFICATION_CHANNEL_SLICE_URI.toString()) .setSliceUri(contextualNotificationChannelSliceUri)
.setCardName(CustomSliceRegistry.NOTIFICATION_CHANNEL_SLICE_URI.toString()) .setCardName(contextualNotificationChannelSliceUri)
.setCardCategory(ContextualCard.Category.POSSIBLE) .setCardCategory(ContextualCard.Category.POSSIBLE)
.build(); .build();
final ContextualCardList cards = ContextualCardList.newBuilder() final ContextualCardList cards = ContextualCardList.newBuilder()
@@ -72,4 +74,4 @@ public class SettingsContextualCardProvider extends ContextualCardProvider {
return cards; return cards;
} }
} }

View File

@@ -0,0 +1,40 @@
/*
* Copyright (C) 2019 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.homepage.contextualcards.slices;
import android.content.Context;
import android.net.Uri;
import com.android.settings.R;
import com.android.settings.slices.CustomSliceRegistry;
public class ContextualNotificationChannelSlice extends NotificationChannelSlice {
public ContextualNotificationChannelSlice(Context context) {
super(context);
}
@Override
public Uri getUri() {
return CustomSliceRegistry.CONTEXTUAL_NOTIFICATION_CHANNEL_SLICE_URI;
}
@Override
protected CharSequence getSubTitle(String packageName, int uid) {
return mContext.getText(R.string.recently_installed_app);
}
}

View File

@@ -128,7 +128,7 @@ public class NotificationChannelSlice implements CustomSliceable {
return leftChannel.getId().compareTo(rightChannel.getId()); return leftChannel.getId().compareTo(rightChannel.getId());
}; };
private final Context mContext; protected final Context mContext;
@VisibleForTesting @VisibleForTesting
NotificationBackend mNotificationBackend; NotificationBackend mNotificationBackend;
private String mPackageName; private String mPackageName;
@@ -413,7 +413,7 @@ public class NotificationChannelSlice implements CustomSliceable {
return maxSentCountPackage; return maxSentCountPackage;
} }
private CharSequence getSubTitle(String packageName, int uid) { protected CharSequence getSubTitle(String packageName, int uid) {
final int channelCount = mNotificationBackend.getChannelCount(packageName, uid); final int channelCount = mNotificationBackend.getChannelCount(packageName, uid);
if (channelCount > DEFAULT_EXPANDED_ROW_COUNT) { if (channelCount > DEFAULT_EXPANDED_ROW_COUNT) {

View File

@@ -36,6 +36,7 @@ import com.android.settings.homepage.contextualcards.deviceinfo.EmergencyInfoSli
import com.android.settings.homepage.contextualcards.deviceinfo.StorageSlice; import com.android.settings.homepage.contextualcards.deviceinfo.StorageSlice;
import com.android.settings.homepage.contextualcards.slices.BatteryFixSlice; import com.android.settings.homepage.contextualcards.slices.BatteryFixSlice;
import com.android.settings.homepage.contextualcards.slices.BluetoothDevicesSlice; import com.android.settings.homepage.contextualcards.slices.BluetoothDevicesSlice;
import com.android.settings.homepage.contextualcards.slices.ContextualNotificationChannelSlice;
import com.android.settings.homepage.contextualcards.slices.LowStorageSlice; import com.android.settings.homepage.contextualcards.slices.LowStorageSlice;
import com.android.settings.homepage.contextualcards.slices.NotificationChannelSlice; import com.android.settings.homepage.contextualcards.slices.NotificationChannelSlice;
import com.android.settings.location.LocationSlice; import com.android.settings.location.LocationSlice;
@@ -94,6 +95,16 @@ public class CustomSliceRegistry {
.appendPath("bluetooth_devices") .appendPath("bluetooth_devices")
.build(); .build();
/**
* Backing Uri for Contextual Notification channel Slice.
*/
public static final Uri CONTEXTUAL_NOTIFICATION_CHANNEL_SLICE_URI = new Uri.Builder()
.scheme(ContentResolver.SCHEME_CONTENT)
.authority(SettingsSliceProvider.SLICE_AUTHORITY)
.appendPath(SettingsSlicesContract.PATH_SETTING_ACTION)
.appendPath("contextual_notification_channel")
.build();
/** /**
* Backing Uri for the Wifi Slice. * Backing Uri for the Wifi Slice.
*/ */
@@ -318,6 +329,8 @@ public class CustomSliceRegistry {
sUriToSlice.put(BATTERY_FIX_SLICE_URI, BatteryFixSlice.class); sUriToSlice.put(BATTERY_FIX_SLICE_URI, BatteryFixSlice.class);
sUriToSlice.put(BLUETOOTH_DEVICES_SLICE_URI, BluetoothDevicesSlice.class); sUriToSlice.put(BLUETOOTH_DEVICES_SLICE_URI, BluetoothDevicesSlice.class);
sUriToSlice.put(CONTEXTUAL_NOTIFICATION_CHANNEL_SLICE_URI,
ContextualNotificationChannelSlice.class);
sUriToSlice.put(CONTEXTUAL_WIFI_SLICE_URI, ContextualWifiSlice.class); sUriToSlice.put(CONTEXTUAL_WIFI_SLICE_URI, ContextualWifiSlice.class);
sUriToSlice.put(DATA_USAGE_SLICE_URI, DataUsageSlice.class); sUriToSlice.put(DATA_USAGE_SLICE_URI, DataUsageSlice.class);
sUriToSlice.put(DEVICE_INFO_SLICE_URI, DeviceInfoSlice.class); sUriToSlice.put(DEVICE_INFO_SLICE_URI, DeviceInfoSlice.class);

View File

@@ -0,0 +1,58 @@
/*
* Copyright (C) 2019 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.homepage.contextualcards.slices;
import static com.google.common.truth.Truth.assertThat;
import android.content.Context;
import android.net.Uri;
import com.android.settings.R;
import com.android.settings.slices.CustomSliceRegistry;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
@RunWith(RobolectricTestRunner.class)
public class ContextualNotificationChannelSliceTest {
private Context mContext;
private ContextualNotificationChannelSlice mNotificationChannelSlice;
@Before
public void setUp() {
mContext = RuntimeEnvironment.application;
mNotificationChannelSlice = new ContextualNotificationChannelSlice(mContext);
}
@Test
public void getUri_shouldBeContextualNotificationChannelSliceUri() {
final Uri uri = mNotificationChannelSlice.getUri();
assertThat(uri).isEqualTo(CustomSliceRegistry.CONTEXTUAL_NOTIFICATION_CHANNEL_SLICE_URI);
}
@Test
public void getSubTitle_shouldBeRecentlyInstalledApp() {
final CharSequence subTitle = mNotificationChannelSlice.getSubTitle("com.test.package", 0);
assertThat(subTitle).isEqualTo(mContext.getText(R.string.recently_installed_app));
}
}