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
This commit is contained in:
@@ -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"/>
|
||||
|
@@ -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,
|
||||
|
@@ -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;
|
||||
|
@@ -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);
|
||||
@@ -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);
|
@@ -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));
|
||||
|
Reference in New Issue
Block a user