Show settings app icon and name in recents
If user opens a settings activity by intent, it will show icon and label get from activity. However, we should show settings app icon and name constantly. Bug: 34645742 Test: RunSettingsRoboTest Change-Id: Ic2f0fef32529ba3f425a0130d25ead47fa0bb97d
This commit is contained in:
@@ -31,6 +31,10 @@ import android.content.pm.ActivityInfo;
|
|||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.pm.PackageManager.NameNotFoundException;
|
import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.content.res.Configuration;
|
import android.content.res.Configuration;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.nfc.NfcAdapter;
|
import android.nfc.NfcAdapter;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
@@ -679,6 +683,13 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
mDevelopmentPreferencesListener = null;
|
mDevelopmentPreferencesListener = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTaskDescription(ActivityManager.TaskDescription taskDescription) {
|
||||||
|
final Bitmap icon = getBitmapFromXmlResource(R.drawable.ic_launcher_settings);
|
||||||
|
taskDescription.setIcon(icon);
|
||||||
|
super.setTaskDescription(taskDescription);
|
||||||
|
}
|
||||||
|
|
||||||
protected boolean isValidFragment(String fragmentName) {
|
protected boolean isValidFragment(String fragmentName) {
|
||||||
// Almost all fragments are wrapped in this,
|
// Almost all fragments are wrapped in this,
|
||||||
// except for a few that have their own activities.
|
// except for a few that have their own activities.
|
||||||
@@ -1114,4 +1125,17 @@ public class SettingsActivity extends SettingsDrawerActivity
|
|||||||
}
|
}
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@VisibleForTesting
|
||||||
|
Bitmap getBitmapFromXmlResource(int drawableRes) {
|
||||||
|
Drawable drawable = getResources().getDrawable(drawableRes, getTheme());
|
||||||
|
Canvas canvas = new Canvas();
|
||||||
|
Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(),
|
||||||
|
drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888);
|
||||||
|
canvas.setBitmap(bitmap);
|
||||||
|
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
||||||
|
drawable.draw(canvas);
|
||||||
|
|
||||||
|
return bitmap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -16,12 +16,13 @@
|
|||||||
|
|
||||||
package com.android.settings;
|
package com.android.settings;
|
||||||
|
|
||||||
|
import android.app.ActivityManager;
|
||||||
import android.app.FragmentManager;
|
import android.app.FragmentManager;
|
||||||
import android.app.FragmentTransaction;
|
import android.app.FragmentTransaction;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import com.android.settings.testutils.FakeFeatureFactory;
|
import com.android.settings.testutils.FakeFeatureFactory;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@@ -32,9 +33,12 @@ import org.robolectric.RuntimeEnvironment;
|
|||||||
import org.robolectric.annotation.Config;
|
import org.robolectric.annotation.Config;
|
||||||
|
|
||||||
import static com.google.common.truth.Truth.assertThat;
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Matchers.anyInt;
|
||||||
import static org.mockito.Mockito.doReturn;
|
import static org.mockito.Mockito.doReturn;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.spy;
|
import static org.mockito.Mockito.spy;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
@RunWith(SettingsRobolectricTestRunner.class)
|
@RunWith(SettingsRobolectricTestRunner.class)
|
||||||
@@ -45,7 +49,10 @@ public class SettingsActivityTest {
|
|||||||
private Context mContext;
|
private Context mContext;
|
||||||
@Mock
|
@Mock
|
||||||
private FragmentManager mFragmentManager;
|
private FragmentManager mFragmentManager;
|
||||||
|
@Mock
|
||||||
|
private ActivityManager.TaskDescription mTaskDescription;
|
||||||
|
@Mock
|
||||||
|
private Bitmap mBitmap;
|
||||||
private SettingsActivity mActivity;
|
private SettingsActivity mActivity;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
@@ -53,14 +60,16 @@ public class SettingsActivityTest {
|
|||||||
MockitoAnnotations.initMocks(this);
|
MockitoAnnotations.initMocks(this);
|
||||||
FakeFeatureFactory.setupForTest(mContext);
|
FakeFeatureFactory.setupForTest(mContext);
|
||||||
final FakeFeatureFactory factory =
|
final FakeFeatureFactory factory =
|
||||||
(FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
(FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||||
when(factory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
|
when(factory.dashboardFeatureProvider.isEnabled()).thenReturn(true);
|
||||||
|
|
||||||
|
mActivity = spy(new SettingsActivity());
|
||||||
|
doReturn(mBitmap).when(mActivity).getBitmapFromXmlResource(anyInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testQueryTextChange_shouldUpdate() {
|
public void testQueryTextChange_shouldUpdate() {
|
||||||
final String testQuery = "abc";
|
final String testQuery = "abc";
|
||||||
mActivity = new SettingsActivity();
|
|
||||||
|
|
||||||
assertThat(mActivity.mSearchQuery).isNull();
|
assertThat(mActivity.mSearchQuery).isNull();
|
||||||
try {
|
try {
|
||||||
@@ -83,4 +92,11 @@ public class SettingsActivityTest {
|
|||||||
|
|
||||||
mActivity.launchSettingFragment(null, true, mock(Intent.class));
|
mActivity.launchSettingFragment(null, true, mock(Intent.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetTaskDescription_IconChanged() {
|
||||||
|
mActivity.setTaskDescription(mTaskDescription);
|
||||||
|
|
||||||
|
verify(mTaskDescription).setIcon(any());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -56,6 +56,10 @@ public class SettingsShadowResources extends ShadowResources {
|
|||||||
// TODO: Remove this once Robolectric is updated.
|
// TODO: Remove this once Robolectric is updated.
|
||||||
if (id == com.android.settings.R.drawable.switchbar_background) {
|
if (id == com.android.settings.R.drawable.switchbar_background) {
|
||||||
return new ColorDrawable();
|
return new ColorDrawable();
|
||||||
|
} else if (id == com.android.settings.R.drawable.ic_launcher_settings) {
|
||||||
|
// ic_launcher_settings uses adaptive-icon, which is not supported by robolectric,
|
||||||
|
// change it to a normal drawable.
|
||||||
|
id = com.android.settings.R.drawable.ic_settings_wireless;
|
||||||
}
|
}
|
||||||
return super.loadDrawable(value, id, theme);
|
return super.loadDrawable(value, id, theme);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user