Shortcut Demo: Address API changes

Bug 29515722
Bug 29516909
Bug 29515090

Change-Id: I7214d1d75acb7550cb8181d076d0b7b938a04488
This commit is contained in:
Makoto Onuki
2016-06-20 17:52:11 -07:00
parent 7621142253
commit 1cf985bff6
6 changed files with 15 additions and 21 deletions

View File

@@ -165,7 +165,7 @@ public abstract class ShortcutAdapter extends BaseAdapter implements OnClickList
if (showLine2()) {
line2.setText(
si.getId() + (si.isDynamic() ? " [dynamic]" : "")
+ (si.isManifestShortcut() ? " [manifest]" : "")
+ (si.isDeclaredInManifest() ? " [manifest]" : "")
+ (si.isPinned() ? " [pinned]" : "") + "\n"
+ "Long label: " + si.getLongLabel() + "\n"
+ "App: " + mAppLabelCache.getAppLabel(si.getPackage()));

View File

@@ -161,9 +161,9 @@ public class AppListFragment extends MyBaseListFragment {
v.setVisibility(View.INVISIBLE);
if (mLauncherApps.hasShortcutHostPermission()) {
mQuery.setPackage(ai.getComponentName().getPackageName());
mQuery.setQueryFlags(ShortcutQuery.FLAG_GET_DYNAMIC
| ShortcutQuery.FLAG_GET_PINNED
| ShortcutQuery.FLAG_GET_MANIFEST
mQuery.setQueryFlags(ShortcutQuery.FLAG_MATCH_DYNAMIC
| ShortcutQuery.FLAG_MATCH_PINNED
| ShortcutQuery.FLAG_MATCH_MANIFEST
| ShortcutQuery.FLAG_GET_KEY_FIELDS_ONLY);
mQuery.setActivity(ai.getComponentName());

View File

@@ -24,7 +24,6 @@ import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.pm.LauncherApps;
import android.os.Bundle;
import android.os.UserHandle;
import android.support.v13.app.FragmentStatePagerAdapter;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;

View File

@@ -125,9 +125,9 @@ public class ShortcutListFragment extends MyBaseListFragment {
for (UserHandle user : getTargetUsers()) {
final Bundle b = getArguments();
mQuery.setQueryFlags(
(b.getBoolean(ARG_INCLUDE_DYNAMIC) ? ShortcutQuery.FLAG_GET_DYNAMIC : 0) |
(b.getBoolean(ARG_INCLUDE_MANIFEST) ? ShortcutQuery.FLAG_GET_MANIFEST : 0) |
(b.getBoolean(ARG_INCLUDE_PINNED) ? ShortcutQuery.FLAG_GET_PINNED : 0));
(b.getBoolean(ARG_INCLUDE_DYNAMIC) ? ShortcutQuery.FLAG_MATCH_DYNAMIC : 0) |
(b.getBoolean(ARG_INCLUDE_MANIFEST) ? ShortcutQuery.FLAG_MATCH_MANIFEST : 0) |
(b.getBoolean(ARG_INCLUDE_PINNED) ? ShortcutQuery.FLAG_MATCH_PINNED : 0));
mQuery.setPackage(b.getString(ARG_TARGET_PACKAGE));
mQuery.setActivity(b.getParcelable(ARG_TARGET_ACTIVITY));

View File

@@ -119,7 +119,7 @@ public class ShortcutPublisher extends Activity {
private final Comparator<ShortcutInfo> mShortcutComparator =
(ShortcutInfo s1, ShortcutInfo s2) -> {
int ret = 0;
ret = (s1.isManifestShortcut() ? 0 : 1) - (s2.isManifestShortcut() ? 0 : 1);
ret = (s1.isDeclaredInManifest() ? 0 : 1) - (s2.isDeclaredInManifest() ? 0 : 1);
if (ret != 0) return ret;
ret = (s1.isDynamic() ? 0 : 1) - (s2.isDynamic() ? 0 : 1);
@@ -197,21 +197,18 @@ public class ShortcutPublisher extends Activity {
final ComponentName activity = new ComponentName(this, ShortcutPublisher.class);
final ShortcutInfo si1 = addRandomIntents(this, new ShortcutInfo.Builder(this)
.setId("shortcut1"))
final ShortcutInfo si1 = addRandomIntents(this, new ShortcutInfo.Builder(this, "shortcut1"))
.setActivity(activity)
.build();
final ShortcutInfo si2 = new ShortcutInfo.Builder(this)
.setId(SETUP_SHORTCUT_ID)
final ShortcutInfo si2 = new ShortcutInfo.Builder(this, SETUP_SHORTCUT_ID)
.setActivity(activity)
.setShortLabel("Shortcut Demo Main")
.setIcon(icon2)
.setIntent(intent2)
.build();
final ShortcutInfo si3 = new ShortcutInfo.Builder(this)
.setId("shortcut3")
final ShortcutInfo si3 = new ShortcutInfo.Builder(this, "shortcut3")
.setActivity(activity)
.setShortLabel("Shortcut Demo Main with extras")
.setIcon(icon3)
@@ -237,8 +234,8 @@ public class ShortcutPublisher extends Activity {
}
public void onAddPressed(View view) {
final ShortcutInfo si = addRandomIntents(this, new ShortcutInfo.Builder(this)
.setId("shortcut-" + formatTime(System.currentTimeMillis()) + "-"
final ShortcutInfo si = addRandomIntents(this, new ShortcutInfo.Builder(this,
"shortcut-" + formatTime(System.currentTimeMillis()) + "-"
+ sSequenceNumber.getAndIncrement()))
.setActivity(new ComponentName(this, ShortcutPublisher.class))
.build();
@@ -251,8 +248,7 @@ public class ShortcutPublisher extends Activity {
for (ShortcutInfo si : getAllShortcuts()) {
if (SETUP_SHORTCUT_ID.equals(si.getId())) continue;
updateList.add(addRandomIntents(this, new ShortcutInfo.Builder(this)
.setId(si.getId()))
updateList.add(addRandomIntents(this, new ShortcutInfo.Builder(this, si.getId()))
.build());
}
callApi(this, () -> mShortcutManager.updateShortcuts(updateList));

View File

@@ -49,8 +49,7 @@ public class ShortcutPublishingService extends IntentService {
private void addShortcut() {
final ShortcutInfo si1 = ShortcutPublisher.addRandomIntents(
this, new ShortcutInfo.Builder(this)
.setId("shortcut-" + System.currentTimeMillis()))
this, new ShortcutInfo.Builder(this, ("shortcut-" + System.currentTimeMillis())))
.setActivity(new ComponentName(this, ShortcutPublisher.class))
.build();
ShortcutPublisher.callApi(this, () ->