Update summary for Recent Apps.
Change the formatting of the time since last used to match the formatting in battery info. Change-Id: Ibd59493719d9f90391713713b75afd11790deaa0 Fix: 62273254 Test: make RunSettingsRoboTests
This commit is contained in:
@@ -36,6 +36,7 @@ import android.util.IconDrawableFactory;
|
||||
import android.util.Log;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Utils;
|
||||
import com.android.settings.core.PreferenceController;
|
||||
import com.android.settingslib.applications.ApplicationsState;
|
||||
|
||||
@@ -227,10 +228,10 @@ public class RecentAppsPreferenceController extends PreferenceController
|
||||
pref.setKey(pkgName);
|
||||
pref.setTitle(appEntry.label);
|
||||
pref.setIcon(mIconDrawableFactory.getBadgedIcon(appEntry.info));
|
||||
pref.setSummary(DateUtils.getRelativeTimeSpanString(stat.getLastTimeUsed(),
|
||||
System.currentTimeMillis(),
|
||||
DateUtils.MINUTE_IN_MILLIS,
|
||||
DateUtils.FORMAT_ABBREV_RELATIVE));
|
||||
pref.setSummary(TextUtils.expandTemplate(
|
||||
mContext.getResources().getText(R.string.recent_app_summary),
|
||||
Utils.formatElapsedTime(mContext,
|
||||
System.currentTimeMillis() - stat.getLastTimeUsed(), false)));
|
||||
pref.setOrder(i);
|
||||
pref.setOnPreferenceClickListener(preference -> {
|
||||
AppInfoBase.startAppInfoFragment(InstalledAppDetails.class,
|
||||
|
@@ -27,6 +27,7 @@ import android.os.UserManager;
|
||||
import android.support.v7.preference.Preference;
|
||||
import android.support.v7.preference.PreferenceCategory;
|
||||
import android.support.v7.preference.PreferenceScreen;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
@@ -37,6 +38,7 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.ArgumentMatcher;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
@@ -50,6 +52,8 @@ import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Matchers.anyInt;
|
||||
import static org.mockito.Matchers.anyLong;
|
||||
import static org.mockito.Matchers.anyString;
|
||||
import static org.mockito.Matchers.argThat;
|
||||
import static org.mockito.Matchers.eq;
|
||||
import static org.mockito.Mockito.doNothing;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
@@ -169,6 +173,8 @@ public class RecentAppsPreferenceControllerTest {
|
||||
.thenReturn(new ResolveInfo());
|
||||
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
|
||||
.thenReturn(stats);
|
||||
when(mMockContext.getString(eq(R.string.battery_history_minutes_no_seconds), anyInt()))
|
||||
.thenReturn(mContext.getString(R.string.battery_history_minutes_no_seconds, 45));
|
||||
|
||||
mController = new RecentAppsPreferenceController(mMockContext, mAppState, null);
|
||||
mController.displayPreference(mScreen);
|
||||
@@ -215,4 +221,36 @@ public class RecentAppsPreferenceControllerTest {
|
||||
verify(mSeeAllPref).setTitle(R.string.applications_settings);
|
||||
verify(mSeeAllPref).setIcon(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void display_showRecents_formatSummary() {
|
||||
when(mMockContext.getResources().getBoolean(R.bool.config_display_recent_apps))
|
||||
.thenReturn(true);
|
||||
final List<UsageStats> stats = new ArrayList<>();
|
||||
final UsageStats stat1 = new UsageStats();
|
||||
stat1.mLastTimeUsed = System.currentTimeMillis();
|
||||
stat1.mPackageName = "pkg.class";
|
||||
stats.add(stat1);
|
||||
|
||||
when(mAppState.getEntry(stat1.mPackageName, UserHandle.myUserId()))
|
||||
.thenReturn(mock(ApplicationsState.AppEntry.class));
|
||||
when(mMockContext.getPackageManager().resolveActivity(any(Intent.class), anyInt()))
|
||||
.thenReturn(new ResolveInfo());
|
||||
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
|
||||
.thenReturn(stats);
|
||||
when(mMockContext.getString(eq(R.string.battery_history_minutes_no_seconds), anyInt()))
|
||||
.thenReturn(mContext.getString(R.string.battery_history_minutes_no_seconds, 35));
|
||||
when(mMockContext.getResources().getText(eq(R.string.recent_app_summary)))
|
||||
.thenReturn(mContext.getResources().getText(R.string.recent_app_summary));
|
||||
|
||||
mController = new RecentAppsPreferenceController(mMockContext, mAppState, null);
|
||||
mController.displayPreference(mScreen);
|
||||
|
||||
verify(mCategory).addPreference(argThat(summaryMatches("35m ago")));
|
||||
}
|
||||
|
||||
private static ArgumentMatcher<Preference> summaryMatches(String expected) {
|
||||
return preference -> TextUtils.equals(expected, preference.getSummary());
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user