diff options
author | Fan Zhang <zhfan@google.com> | 2018-01-29 11:23:52 -0800 |
---|---|---|
committer | Fan Zhang <zhfan@google.com> | 2018-01-29 11:39:48 -0800 |
commit | 409eab14de3767aeb0d80885cadef32ef257f233 (patch) | |
tree | bd51267649da98496cdfef665f6ea7552fe95223 | |
parent | 499efd06ab8bcd6480d81e769e8f89c5d1e5cc10 (diff) | |
download | packages_apps_Settings-409eab14de3767aeb0d80885cadef32ef257f233.tar.gz packages_apps_Settings-409eab14de3767aeb0d80885cadef32ef257f233.tar.bz2 packages_apps_Settings-409eab14de3767aeb0d80885cadef32ef257f233.zip |
Fix shortcut icon in launcher
When building icon for shortcut, check if the icon is LayerDrawable.
- If yes, only take the second layer (foreground).
Also move the class to shortcut package
Change-Id: I3513dbeb6509f11aa70ab3230d441e268ca9356d
Fixes: 72553870
Test: atest
-rw-r--r-- | AndroidManifest.xml | 2 | ||||
-rw-r--r-- | src/com/android/settings/SettingsInitialize.java | 2 | ||||
-rw-r--r-- | src/com/android/settings/localepicker/LocaleDragAndDropAdapter.java | 2 | ||||
-rw-r--r-- | src/com/android/settings/shortcut/CreateShortcut.java (renamed from src/com/android/settings/CreateShortcut.java) | 18 | ||||
-rw-r--r-- | tests/unit/src/com/android/settings/shortcut/CreateShortcutTest.java (renamed from tests/unit/src/com/android/settings/CreateShortcutTest.java) | 28 |
5 files changed, 31 insertions, 21 deletions
diff --git a/AndroidManifest.xml b/AndroidManifest.xml index 2e511084b5..d637ac7da2 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -146,7 +146,7 @@ android:parentActivityName="Settings"> </activity> - <activity android:name="CreateShortcut" + <activity android:name=".shortcut.CreateShortcut" android:label="@string/settings_shortcut"> <intent-filter> <action android:name="android.intent.action.CREATE_SHORTCUT"/> diff --git a/src/com/android/settings/SettingsInitialize.java b/src/com/android/settings/SettingsInitialize.java index 6b15770a96..9f2bdcc6fc 100644 --- a/src/com/android/settings/SettingsInitialize.java +++ b/src/com/android/settings/SettingsInitialize.java @@ -34,6 +34,8 @@ import static android.content.pm.PackageManager.GET_META_DATA; import static android.content.pm.PackageManager.GET_RESOLVED_FILTER; import static android.content.pm.PackageManager.MATCH_DISABLED_COMPONENTS; +import com.android.settings.shortcut.CreateShortcut; + /** * Listens to {@link Intent.ACTION_PRE_BOOT_COMPLETED} and {@link Intent.ACTION_USER_INITIALIZED} * performs setup steps for a managed profile (disables the launcher icon of the Settings app, diff --git a/src/com/android/settings/localepicker/LocaleDragAndDropAdapter.java b/src/com/android/settings/localepicker/LocaleDragAndDropAdapter.java index 1d21c123c9..0d8cbaf116 100644 --- a/src/com/android/settings/localepicker/LocaleDragAndDropAdapter.java +++ b/src/com/android/settings/localepicker/LocaleDragAndDropAdapter.java @@ -34,7 +34,7 @@ import android.widget.CompoundButton; import com.android.internal.app.LocalePicker; import com.android.internal.app.LocaleStore; -import com.android.settings.CreateShortcut; +import com.android.settings.shortcut.CreateShortcut; import com.android.settings.R; import java.text.NumberFormat; diff --git a/src/com/android/settings/CreateShortcut.java b/src/com/android/settings/shortcut/CreateShortcut.java index 8bc801b99c..2bd9b76125 100644 --- a/src/com/android/settings/CreateShortcut.java +++ b/src/com/android/settings/shortcut/CreateShortcut.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.android.settings; +package com.android.settings.shortcut; import android.app.LauncherActivity; import android.content.ComponentName; @@ -28,7 +28,9 @@ import android.content.pm.ShortcutManager; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.graphics.Canvas; +import android.graphics.drawable.Drawable; import android.graphics.drawable.Icon; +import android.graphics.drawable.LayerDrawable; import android.net.ConnectivityManager; import android.os.AsyncTask; import android.support.annotation.VisibleForTesting; @@ -40,6 +42,7 @@ import android.widget.ImageView; import android.widget.ListView; import com.android.internal.logging.nano.MetricsProto; +import com.android.settings.R; import com.android.settings.Settings.TetherSettingsActivity; import com.android.settings.overlay.FeatureFactory; @@ -65,7 +68,8 @@ public class CreateShortcut extends LauncherActivity { finish(); } - protected Intent createResultIntent(Intent shortcutIntent, ResolveInfo resolveInfo, + @VisibleForTesting + Intent createResultIntent(Intent shortcutIntent, ResolveInfo resolveInfo, CharSequence label) { shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); ShortcutManager sm = getSystemService(ShortcutManager.class); @@ -94,8 +98,8 @@ public class CreateShortcut extends LauncherActivity { if (activityInfo.icon != 0) { intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, createIcon(activityInfo.icon, - R.layout.shortcut_badge, - getResources().getDimensionPixelSize(R.dimen.shortcut_size))); + R.layout.shortcut_badge, + getResources().getDimensionPixelSize(R.dimen.shortcut_size))); } return intent; } @@ -112,7 +116,11 @@ public class CreateShortcut extends LauncherActivity { private Bitmap createIcon(int resource, int layoutRes, int size) { Context context = new ContextThemeWrapper(this, android.R.style.Theme_Material); View view = LayoutInflater.from(context).inflate(layoutRes, null); - ((ImageView) view.findViewById(android.R.id.icon)).setImageResource(resource); + Drawable iconDrawable = getDrawable(resource); + if (iconDrawable instanceof LayerDrawable) { + iconDrawable = ((LayerDrawable) iconDrawable).getDrawable(1); + } + ((ImageView) view.findViewById(android.R.id.icon)).setImageDrawable(iconDrawable); int spec = MeasureSpec.makeMeasureSpec(size, MeasureSpec.EXACTLY); view.measure(spec, spec); diff --git a/tests/unit/src/com/android/settings/CreateShortcutTest.java b/tests/unit/src/com/android/settings/shortcut/CreateShortcutTest.java index 4ae9bd7997..5ec008b3d5 100644 --- a/tests/unit/src/com/android/settings/CreateShortcutTest.java +++ b/tests/unit/src/com/android/settings/shortcut/CreateShortcutTest.java @@ -14,12 +14,10 @@ * limitations under the License. */ -package com.android.settings; +package com.android.settings.shortcut; import static android.support.test.espresso.Espresso.onView; import static android.support.test.espresso.assertion.ViewAssertions.doesNotExist; -import static android.support.test.espresso.matcher.ViewMatchers.withText; - import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.mockito.Mockito.any; @@ -39,9 +37,13 @@ import android.content.pm.ResolveInfo; import android.content.pm.ShortcutInfo; import android.content.pm.ShortcutManager; import android.support.test.InstrumentationRegistry; +import android.support.test.espresso.matcher.ViewMatchers; import android.support.test.filters.SmallTest; import android.support.test.runner.AndroidJUnit4; +import com.android.settings.R; +import com.android.settings.Settings; + import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -55,12 +57,6 @@ import java.util.List; /** * Tests for {@link CreateShortcutTest} - * - m SettingsTests && - adb install \ - -r -g ${ANDROID_PRODUCT_OUT}/data/app/SettingsTests/SettingsTests.apk && - adb shell am instrument -e class com.android.settings.CreateShortcutTest \ - -w com.android.settings.tests/android.support.test.runner.AndroidJUnitRunner */ @RunWith(AndroidJUnit4.class) @SmallTest @@ -71,8 +67,10 @@ public class CreateShortcutTest { private Instrumentation mInstrumentation; private Context mContext; - @Mock ShortcutManager mShortcutManager; - @Captor ArgumentCaptor<List<ShortcutInfo>> mListCaptor; + @Mock + ShortcutManager mShortcutManager; + @Captor + ArgumentCaptor<List<ShortcutInfo>> mListCaptor; @Before public void setup() { @@ -84,15 +82,17 @@ public class CreateShortcutTest { @Test public void test_layoutDoesNotHaveCancelButton() { mInstrumentation.startActivitySync(new Intent(Intent.ACTION_CREATE_SHORTCUT) - .setClassName(mContext, CreateShortcut.class.getName())); - onView(withText(R.string.cancel)).check(doesNotExist()); + .setClassName(mContext, CreateShortcut.class.getName()) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); + onView(ViewMatchers.withText(R.string.cancel)).check(doesNotExist()); } @Test public void createResultIntent() { CreateShortcut orgActivity = (CreateShortcut) mInstrumentation.startActivitySync( new Intent(Intent.ACTION_CREATE_SHORTCUT) - .setClassName(mContext, CreateShortcut.class.getName())); + .setClassName(mContext, CreateShortcut.class.getName()) + .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)); CreateShortcut activity = spy(orgActivity); doReturn(mShortcutManager).when(activity).getSystemService(eq(Context.SHORTCUT_SERVICE)); |