Merge \"ShortcutDemo: Add 2nd main activity with manifest shortcuts\" into nyc-mr1-dev
am: 0f3323555c
Change-Id: I2814cdfd8afab448715edc1845ec536330dbad07
This commit is contained in:
@@ -34,6 +34,18 @@
|
|||||||
<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts"/>
|
<meta-data android:name="android.app.shortcuts" android:resource="@xml/shortcuts"/>
|
||||||
</activity>
|
</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">
|
<service android:name="ShortcutPublishingService">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="com.example.android.pm.shortcutdemo.ADD" />
|
<action android:name="com.example.android.pm.shortcutdemo.ADD" />
|
||||||
|
|||||||
@@ -47,4 +47,5 @@
|
|||||||
|
|
||||||
<add-resource type="string" name="show_notification"/>
|
<add-resource type="string" name="show_notification"/>
|
||||||
<string name="show_notification">Show notification</string>
|
<string name="show_notification">Show notification</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -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" >
|
<shortcuts xmlns:android="http://schemas.android.com/apk/res/android" >
|
||||||
<shortcut
|
<shortcut
|
||||||
android:shortcutId="manifest-shortcut-1"
|
android:shortcutId="manifest-shortcut-1"
|
||||||
|
|||||||
27
samples/ShortcutDemo/publisher/res/xml/shortcuts2.xml
Normal file
27
samples/ShortcutDemo/publisher/res/xml/shortcuts2.xml
Normal 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>
|
||||||
@@ -16,4 +16,5 @@
|
|||||||
|
|
||||||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
||||||
<string name="app_title">[P1] Shortcuts Demo</string>
|
<string name="app_title">[P1] Shortcuts Demo</string>
|
||||||
|
<string name="activity_alias_label">[P1] Shortcuts Demo Alias</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -16,4 +16,5 @@
|
|||||||
|
|
||||||
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
<resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2">
|
||||||
<string name="app_title">[P2] Shortcuts Demo</string>
|
<string name="app_title">[P2] Shortcuts Demo</string>
|
||||||
|
<string name="activity_alias_label">[P2] Shortcuts Demo Alias</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -63,6 +63,8 @@ public class ShortcutPublisher extends Activity {
|
|||||||
|
|
||||||
private static final AtomicInteger sSequenceNumber = new AtomicInteger();
|
private static final AtomicInteger sSequenceNumber = new AtomicInteger();
|
||||||
|
|
||||||
|
private ComponentName mMyActivity;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
@@ -71,10 +73,16 @@ public class ShortcutPublisher extends Activity {
|
|||||||
|
|
||||||
mShortcutManager = getSystemService(ShortcutManager.class);
|
mShortcutManager = getSystemService(ShortcutManager.class);
|
||||||
|
|
||||||
|
mMyActivity = getIntent().getComponent();
|
||||||
|
if (mMyActivity == null) {
|
||||||
|
mMyActivity = new ComponentName(this, ShortcutPublisher.class);
|
||||||
|
}
|
||||||
|
|
||||||
mList = (ListView) findViewById(android.R.id.list);
|
mList = (ListView) findViewById(android.R.id.list);
|
||||||
mAdapter = new MyAdapter(this);
|
mAdapter = new MyAdapter(this);
|
||||||
mList.setAdapter(mAdapter);
|
mList.setAdapter(mAdapter);
|
||||||
|
|
||||||
|
Log.d(TAG, "intent=" + getIntent());
|
||||||
Log.d(TAG, "extras=" + getIntent().getExtras());
|
Log.d(TAG, "extras=" + getIntent().getExtras());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,16 +101,19 @@ public class ShortcutPublisher extends Activity {
|
|||||||
private List<ShortcutInfo> getAllShortcuts() {
|
private List<ShortcutInfo> getAllShortcuts() {
|
||||||
final Map<String, ShortcutInfo> map = new ArrayMap<>();
|
final Map<String, ShortcutInfo> map = new ArrayMap<>();
|
||||||
for (ShortcutInfo si : mShortcutManager.getManifestShortcuts()) {
|
for (ShortcutInfo si : mShortcutManager.getManifestShortcuts()) {
|
||||||
|
if (!si.getActivity().equals(mMyActivity)) continue;
|
||||||
if (!map.containsKey(si.getId())) {
|
if (!map.containsKey(si.getId())) {
|
||||||
map.put(si.getId(), si);
|
map.put(si.getId(), si);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (ShortcutInfo si : mShortcutManager.getDynamicShortcuts()) {
|
for (ShortcutInfo si : mShortcutManager.getDynamicShortcuts()) {
|
||||||
|
if (!si.getActivity().equals(mMyActivity)) continue;
|
||||||
if (!map.containsKey(si.getId())) {
|
if (!map.containsKey(si.getId())) {
|
||||||
map.put(si.getId(), si);
|
map.put(si.getId(), si);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (ShortcutInfo si : mShortcutManager.getPinnedShortcuts()) {
|
for (ShortcutInfo si : mShortcutManager.getPinnedShortcuts()) {
|
||||||
|
if (!si.getActivity().equals(mMyActivity)) continue;
|
||||||
if (!map.containsKey(si.getId())) {
|
if (!map.containsKey(si.getId())) {
|
||||||
map.put(si.getId(), si);
|
map.put(si.getId(), si);
|
||||||
}
|
}
|
||||||
@@ -195,21 +206,19 @@ public class ShortcutPublisher extends Activity {
|
|||||||
intent3.putExtra("nest", new Bundle());
|
intent3.putExtra("nest", new Bundle());
|
||||||
intent3.getBundleExtra("nest").putInt("int", 123);
|
intent3.getBundleExtra("nest").putInt("int", 123);
|
||||||
|
|
||||||
final ComponentName activity = new ComponentName(this, ShortcutPublisher.class);
|
|
||||||
|
|
||||||
final ShortcutInfo si1 = addRandomIntents(this, new ShortcutInfo.Builder(this, "shortcut1"))
|
final ShortcutInfo si1 = addRandomIntents(this, new ShortcutInfo.Builder(this, "shortcut1"))
|
||||||
.setActivity(activity)
|
.setActivity(mMyActivity)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
final ShortcutInfo si2 = new ShortcutInfo.Builder(this, SETUP_SHORTCUT_ID)
|
final ShortcutInfo si2 = new ShortcutInfo.Builder(this, SETUP_SHORTCUT_ID)
|
||||||
.setActivity(activity)
|
.setActivity(mMyActivity)
|
||||||
.setShortLabel("Shortcut Demo Main")
|
.setShortLabel("Shortcut Demo Main")
|
||||||
.setIcon(icon2)
|
.setIcon(icon2)
|
||||||
.setIntent(intent2)
|
.setIntent(intent2)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
final ShortcutInfo si3 = new ShortcutInfo.Builder(this, "shortcut3")
|
final ShortcutInfo si3 = new ShortcutInfo.Builder(this, "shortcut3")
|
||||||
.setActivity(activity)
|
.setActivity(mMyActivity)
|
||||||
.setShortLabel("Shortcut Demo Main with extras")
|
.setShortLabel("Shortcut Demo Main with extras")
|
||||||
.setIcon(icon3)
|
.setIcon(icon3)
|
||||||
.setIntent(intent3)
|
.setIntent(intent3)
|
||||||
@@ -237,7 +246,7 @@ public class ShortcutPublisher extends Activity {
|
|||||||
final ShortcutInfo si = addRandomIntents(this, new ShortcutInfo.Builder(this,
|
final ShortcutInfo si = addRandomIntents(this, new ShortcutInfo.Builder(this,
|
||||||
"shortcut-" + formatTime(System.currentTimeMillis()) + "-"
|
"shortcut-" + formatTime(System.currentTimeMillis()) + "-"
|
||||||
+ sSequenceNumber.getAndIncrement()))
|
+ sSequenceNumber.getAndIncrement()))
|
||||||
.setActivity(new ComponentName(this, ShortcutPublisher.class))
|
.setActivity(mMyActivity)
|
||||||
.build();
|
.build();
|
||||||
callApi(this, () -> mShortcutManager.addDynamicShortcuts(Arrays.asList(si)));
|
callApi(this, () -> mShortcutManager.addDynamicShortcuts(Arrays.asList(si)));
|
||||||
refreshList();
|
refreshList();
|
||||||
@@ -248,6 +257,8 @@ public class ShortcutPublisher extends Activity {
|
|||||||
|
|
||||||
for (ShortcutInfo si : getAllShortcuts()) {
|
for (ShortcutInfo si : getAllShortcuts()) {
|
||||||
if (SETUP_SHORTCUT_ID.equals(si.getId())) continue;
|
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()))
|
updateList.add(addRandomIntents(this, new ShortcutInfo.Builder(this, si.getId()))
|
||||||
.build());
|
.build());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,6 @@ public class ShortcutPublishingService extends IntentService {
|
|||||||
private void addShortcut() {
|
private void addShortcut() {
|
||||||
final ShortcutInfo si1 = ShortcutPublisher.addRandomIntents(
|
final ShortcutInfo si1 = ShortcutPublisher.addRandomIntents(
|
||||||
this, new ShortcutInfo.Builder(this, ("shortcut-" + System.currentTimeMillis())))
|
this, new ShortcutInfo.Builder(this, ("shortcut-" + System.currentTimeMillis())))
|
||||||
.setActivity(new ComponentName(this, ShortcutPublisher.class))
|
|
||||||
.build();
|
.build();
|
||||||
ShortcutPublisher.callApi(this, () ->
|
ShortcutPublisher.callApi(this, () ->
|
||||||
getSystemService(ShortcutManager.class).addDynamicShortcuts(Arrays.asList(si1)));
|
getSystemService(ShortcutManager.class).addDynamicShortcuts(Arrays.asList(si1)));
|
||||||
|
|||||||
Reference in New Issue
Block a user