Merge \\"ShortcutDemo: Add 2nd main activity with manifest shortcuts\\" into nyc-mr1-dev am: 0f3323555c

am: 1b342b02dd

Change-Id: I424a604818b2668645f11321f707a505d87fd445
This commit is contained in:
Makoto Onuki
2016-07-11 20:08:24 +00:00
committed by android-build-merger
8 changed files with 74 additions and 7 deletions

View File

@@ -34,6 +34,18 @@
<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts"/>
</activity>
<activity-alias android:name="ShortcutPublisherAlias"
android:targetActivity="ShortcutPublisher"
android:label="@string/activity_alias_label"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts2"/>
</activity-alias>
<service android:name="ShortcutPublishingService">
<intent-filter>
<action android:name="com.example.android.pm.shortcutdemo.ADD" />

View File

@@ -47,4 +47,5 @@
<add-resource type="string" name="show_notification"/>
<string name="show_notification">Show notification</string>
</resources>

View File

@@ -1,3 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android" >
<shortcut
android:shortcutId="manifest-shortcut-1"

View File

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (C) 2016 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android" >
<shortcut
android:shortcutId="manifest-shortcut-xyz"
android:icon="@drawable/icon_large_1"
android:shortcutShortLabel="@string/shortcut_short_text1"
>
<intent
android:action="android.intent.action.VIEW"
android:data="http://www.google.com/"
/>
</shortcut>
</shortcuts>

View File

@@ -16,4 +16,5 @@
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="app_title">[P1] Shortcuts Demo</string>
<string name="activity_alias_label">[P1] Shortcuts Demo Alias</string>
</resources>

View File

@@ -16,4 +16,5 @@
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
<string name="app_title">[P2] Shortcuts Demo</string>
<string name="activity_alias_label">[P2] Shortcuts Demo Alias</string>
</resources>

View File

@@ -63,6 +63,8 @@ public class ShortcutPublisher extends Activity {
private static final AtomicInteger sSequenceNumber = new AtomicInteger();
private ComponentName mMyActivity;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -71,10 +73,16 @@ public class ShortcutPublisher extends Activity {
mShortcutManager = getSystemService(ShortcutManager.class);
mMyActivity = getIntent().getComponent();
if (mMyActivity == null) {
mMyActivity = new ComponentName(this, ShortcutPublisher.class);
}
mList = (ListView) findViewById(android.R.id.list);
mAdapter = new MyAdapter(this);
mList.setAdapter(mAdapter);
Log.d(TAG, "intent=" + getIntent());
Log.d(TAG, "extras=" + getIntent().getExtras());
}
@@ -93,16 +101,19 @@ public class ShortcutPublisher extends Activity {
private List<ShortcutInfo> getAllShortcuts() {
final Map<String, ShortcutInfo> map = new ArrayMap<>();
for (ShortcutInfo si : mShortcutManager.getManifestShortcuts()) {
if (!si.getActivity().equals(mMyActivity)) continue;
if (!map.containsKey(si.getId())) {
map.put(si.getId(), si);
}
}
for (ShortcutInfo si : mShortcutManager.getDynamicShortcuts()) {
if (!si.getActivity().equals(mMyActivity)) continue;
if (!map.containsKey(si.getId())) {
map.put(si.getId(), si);
}
}
for (ShortcutInfo si : mShortcutManager.getPinnedShortcuts()) {
if (!si.getActivity().equals(mMyActivity)) continue;
if (!map.containsKey(si.getId())) {
map.put(si.getId(), si);
}
@@ -195,21 +206,19 @@ public class ShortcutPublisher extends Activity {
intent3.putExtra("nest", new Bundle());
intent3.getBundleExtra("nest").putInt("int", 123);
final ComponentName activity = new ComponentName(this, ShortcutPublisher.class);
final ShortcutInfo si1 = addRandomIntents(this, new ShortcutInfo.Builder(this, "shortcut1"))
.setActivity(activity)
.setActivity(mMyActivity)
.build();
final ShortcutInfo si2 = new ShortcutInfo.Builder(this, SETUP_SHORTCUT_ID)
.setActivity(activity)
.setActivity(mMyActivity)
.setShortLabel("Shortcut Demo Main")
.setIcon(icon2)
.setIntent(intent2)
.build();
final ShortcutInfo si3 = new ShortcutInfo.Builder(this, "shortcut3")
.setActivity(activity)
.setActivity(mMyActivity)
.setShortLabel("Shortcut Demo Main with extras")
.setIcon(icon3)
.setIntent(intent3)
@@ -237,7 +246,7 @@ public class ShortcutPublisher extends Activity {
final ShortcutInfo si = addRandomIntents(this, new ShortcutInfo.Builder(this,
"shortcut-" + formatTime(System.currentTimeMillis()) + "-"
+ sSequenceNumber.getAndIncrement()))
.setActivity(new ComponentName(this, ShortcutPublisher.class))
.setActivity(mMyActivity)
.build();
callApi(this, () -> mShortcutManager.addDynamicShortcuts(Arrays.asList(si)));
refreshList();
@@ -248,6 +257,8 @@ public class ShortcutPublisher extends Activity {
for (ShortcutInfo si : getAllShortcuts()) {
if (SETUP_SHORTCUT_ID.equals(si.getId())) continue;
if (si.isImmutable()) continue;
if (!si.getActivity().equals(mMyActivity)) continue;
updateList.add(addRandomIntents(this, new ShortcutInfo.Builder(this, si.getId()))
.build());
}

View File

@@ -50,7 +50,6 @@ public class ShortcutPublishingService extends IntentService {
private void addShortcut() {
final ShortcutInfo si1 = ShortcutPublisher.addRandomIntents(
this, new ShortcutInfo.Builder(this, ("shortcut-" + System.currentTimeMillis())))
.setActivity(new ComponentName(this, ShortcutPublisher.class))
.build();
ShortcutPublisher.callApi(this, () ->
getSystemService(ShortcutManager.class).addDynamicShortcuts(Arrays.asList(si1)));