diff --git a/samples/ShortcutDemo/publisher/Android.mk b/samples/ShortcutDemo/publisher/Android.mk index 75f3bb6a2..c83baaf57 100644 --- a/samples/ShortcutDemo/publisher/Android.mk +++ b/samples/ShortcutDemo/publisher/Android.mk @@ -23,6 +23,8 @@ include $(CLEAR_VARS) LOCAL_PACKAGE_NAME := ShortcutDemo +LOCAL_STATIC_JAVA_LIBRARIES = android-support-v4 + LOCAL_MODULE_TAGS := samples tests LOCAL_AAPT_FLAGS += --rename-manifest-package com.example.android.pm.shortcutdemo @@ -43,6 +45,8 @@ include $(CLEAR_VARS) LOCAL_PACKAGE_NAME := ShortcutDemo2 +LOCAL_STATIC_JAVA_LIBRARIES = android-support-v4 + LOCAL_MODULE_TAGS := samples tests LOCAL_AAPT_FLAGS += --rename-manifest-package com.example.android.pm.shortcutdemo2 diff --git a/samples/ShortcutDemo/publisher/AndroidManifest.xml b/samples/ShortcutDemo/publisher/AndroidManifest.xml index a039764dd..69ccdcf88 100644 --- a/samples/ShortcutDemo/publisher/AndroidManifest.xml +++ b/samples/ShortcutDemo/publisher/AndroidManifest.xml @@ -17,7 +17,7 @@ - + diff --git a/samples/ShortcutDemo/publisher/src/com/example/android/pm/shortcutdemo/ShortcutPublisher.java b/samples/ShortcutDemo/publisher/src/com/example/android/pm/shortcutdemo/ShortcutPublisher.java index 6c68552f0..f86ef5fec 100644 --- a/samples/ShortcutDemo/publisher/src/com/example/android/pm/shortcutdemo/ShortcutPublisher.java +++ b/samples/ShortcutDemo/publisher/src/com/example/android/pm/shortcutdemo/ShortcutPublisher.java @@ -31,6 +31,9 @@ import android.graphics.BitmapFactory; import android.graphics.drawable.Icon; import android.net.Uri; import android.os.Bundle; +import android.support.v4.content.pm.ShortcutInfoCompat; +import android.support.v4.content.pm.ShortcutManagerCompat; +import android.support.v4.graphics.drawable.IconCompat; import android.text.format.Time; import android.util.ArrayMap; import android.util.Log; @@ -198,6 +201,21 @@ public class ShortcutPublisher extends Activity { return b; } + public static ShortcutInfoCompat.Builder addRandomIntents(Context context, + ShortcutInfoCompat.Builder b) { + final int i = sRandom.nextInt(sIntentList.size()); + b.setShortLabel(sIntentList.get(i).first); + b.setIntent(new Intent(Intent.ACTION_VIEW, Uri.parse(sIntentList.get(i).second))); + + if (sRandom.nextBoolean()) { + b.setIcon(IconCompat.createWithResource(context, R.drawable.icon2)); + } else { + b.setIcon(IconCompat.createWithBitmap( + BitmapFactory.decodeResource(context.getResources(), R.drawable.icon_large_2))); + } + return b; + } + public void onPublishPressed(View view) { dumpCurrentShortcuts(); final Icon icon2 = Icon.createWithBitmap(BitmapFactory.decodeResource(getResources(), @@ -305,12 +323,12 @@ public class ShortcutPublisher extends Activity { } public static void requestPinShortcut(Context context) { - if (!context.getSystemService(ShortcutManager.class).isRequestPinShortcutSupported()) { + if (!ShortcutManagerCompat.isRequestPinShortcutSupported(context)) { showToast(context, "requestPinShortcut() is not supported by launcher"); return; } - final ShortcutInfo si = addRandomIntents( - context, new ShortcutInfo.Builder(context, + final ShortcutInfoCompat si = addRandomIntents( + context, new ShortcutInfoCompat.Builder(context, "shortcut-" + System.currentTimeMillis())) .build(); final PendingIntent resultIntent = PendingIntent.getBroadcast(context, 0, @@ -318,7 +336,7 @@ public class ShortcutPublisher extends Activity { PendingIntent.FLAG_UPDATE_CURRENT); ShortcutPublisher.callApi(context, () -> { - context.getSystemService(ShortcutManager.class).requestPinShortcut( + ShortcutManagerCompat.requestPinShortcut(context, si, resultIntent.getIntentSender()); return true; }); diff --git a/samples/ShortcutSample/Android.mk b/samples/ShortcutSample/Android.mk index f1b9acca7..96d7f99bf 100644 --- a/samples/ShortcutSample/Android.mk +++ b/samples/ShortcutSample/Android.mk @@ -28,6 +28,8 @@ LOCAL_SRC_FILES := $(call all-java-files-under, src) LOCAL_RESOURCE_DIR := $(LOCAL_PATH)/res +LOCAL_STATIC_JAVA_LIBRARIES = android-support-v4 + LOCAL_SDK_VERSION := current include $(BUILD_PACKAGE) diff --git a/samples/ShortcutSample/AndroidManifest.xml b/samples/ShortcutSample/AndroidManifest.xml index b19992b4b..ebf4b3479 100644 --- a/samples/ShortcutSample/AndroidManifest.xml +++ b/samples/ShortcutSample/AndroidManifest.xml @@ -17,7 +17,7 @@ - + @@ -42,6 +42,12 @@ + + + + + + diff --git a/samples/ShortcutSample/src/com/example/android/shortcutsample/Main.java b/samples/ShortcutSample/src/com/example/android/shortcutsample/Main.java index 0ae623f2f..679994fc5 100644 --- a/samples/ShortcutSample/src/com/example/android/shortcutsample/Main.java +++ b/samples/ShortcutSample/src/com/example/android/shortcutsample/Main.java @@ -24,6 +24,7 @@ import android.content.pm.ShortcutInfo; import android.content.pm.ShortcutManager; import android.os.AsyncTask; import android.os.Bundle; +import android.support.v4.content.pm.ShortcutManagerCompat; import android.util.ArraySet; import android.util.Log; import android.view.LayoutInflater; @@ -88,7 +89,8 @@ public class Main extends ListActivity implements OnClickListener { sVisibleInstances.add(this); } findViewById(R.id.request_new_pin_shortcut).setVisibility( - mShortcutManager.isRequestPinShortcutSupported() ? View.VISIBLE : View.GONE); + ShortcutManagerCompat.isRequestPinShortcutSupported(this) + ? View.VISIBLE : View.GONE); } @Override @@ -309,7 +311,8 @@ public class Main extends ListActivity implements OnClickListener { remove.setVisibility(shortcut.isImmutable() ? View.GONE : View.VISIBLE); disable.setVisibility(shortcut.isImmutable() ? View.GONE : View.VISIBLE); requestPin.setVisibility( - mShortcutManager.isRequestPinShortcutSupported() ? View.VISIBLE : View.GONE); + ShortcutManagerCompat.isRequestPinShortcutSupported(mContext) + ? View.VISIBLE : View.GONE); remove.setOnClickListener(Main.this); disable.setOnClickListener(Main.this); diff --git a/samples/ShortcutSample/src/com/example/android/shortcutsample/ShortcutHelper.java b/samples/ShortcutSample/src/com/example/android/shortcutsample/ShortcutHelper.java index bd049b357..a708e6976 100644 --- a/samples/ShortcutSample/src/com/example/android/shortcutsample/ShortcutHelper.java +++ b/samples/ShortcutSample/src/com/example/android/shortcutsample/ShortcutHelper.java @@ -25,6 +25,8 @@ import android.graphics.drawable.Icon; import android.net.Uri; import android.os.AsyncTask; import android.os.PersistableBundle; +import android.support.v4.content.pm.ShortcutInfoCompat; +import android.support.v4.content.pm.ShortcutManagerCompat; import android.util.Log; import java.io.BufferedInputStream; @@ -227,8 +229,8 @@ public class ShortcutHelper { } public void requestPinShortcut(String id) { - mShortcutManager.requestPinShortcut( - new ShortcutInfo.Builder(mContext, id).build(), + ShortcutManagerCompat.requestPinShortcut(mContext, + new ShortcutInfoCompat.Builder(mContext, id).build(), MyReceiver.getPinRequestAcceptedIntent(mContext).getIntentSender()); }