aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorBananeweizen <Bananeweizen@gmx.de>2013-12-29 15:15:24 +0100
committerBananeweizen <Bananeweizen@gmx.de>2013-12-29 15:15:44 +0100
commit11bd776ee2bd1a1722692f9c4288b8f0a507e43b (patch)
treecb2aa50bce367a169c1b8e240b5c54839db4c06c /main
parent9da711d11a68d05e560e522d1478d67b3b611b48 (diff)
downloadcgeo-11bd776ee2bd1a1722692f9c4288b8f0a507e43b.zip
cgeo-11bd776ee2bd1a1722692f9c4288b8f0a507e43b.tar.gz
cgeo-11bd776ee2bd1a1722692f9c4288b8f0a507e43b.tar.bz2
new: create shortcut from Android launcher to cgeo lists
Diffstat (limited to 'main')
-rw-r--r--main/AndroidManifest.xml9
-rw-r--r--main/res/values/strings.xml3
-rw-r--r--main/src/cgeo/geocaching/CacheListActivity.java11
-rw-r--r--main/src/cgeo/geocaching/CreateShortcutActivity.java55
4 files changed, 76 insertions, 2 deletions
diff --git a/main/AndroidManifest.xml b/main/AndroidManifest.xml
index 5a204e9..1884a9b 100644
--- a/main/AndroidManifest.xml
+++ b/main/AndroidManifest.xml
@@ -419,5 +419,14 @@
android:scheme="callback" />
</intent-filter>
</activity>
+ <activity
+ android:name=".CreateShortcutActivity"
+ android:label="@string/create_shortcut" >
+ <intent-filter>
+ <action android:name="android.intent.action.CREATE_SHORTCUT"/>
+ <category android:name="android.intent.category.DEFAULT"/>
+ </intent-filter>
+ </activity>
+
</application>
</manifest>
diff --git a/main/res/values/strings.xml b/main/res/values/strings.xml
index 199b847..f72fa06 100644
--- a/main/res/values/strings.xml
+++ b/main/res/values/strings.xml
@@ -1257,4 +1257,7 @@
</plurals>
<string name="percent_favorite_points">%\ favorites</string>
+
+ <!-- shortcuts -->
+ <string name="create_shortcut">Create shortcut</string>
</resources>
diff --git a/main/src/cgeo/geocaching/CacheListActivity.java b/main/src/cgeo/geocaching/CacheListActivity.java
index 08d41d0..be9b59c 100644
--- a/main/src/cgeo/geocaching/CacheListActivity.java
+++ b/main/src/cgeo/geocaching/CacheListActivity.java
@@ -444,7 +444,8 @@ public class CacheListActivity extends AbstractListActivity implements FilteredA
}
private boolean isInvokedFromAttachment() {
- return Intent.ACTION_VIEW.equals(getIntent().getAction());
+ final Intent intent = getIntent();
+ return Intent.ACTION_VIEW.equals(intent.getAction()) && intent.getData() != null;
}
private void importGpxAttachement() {
@@ -1550,7 +1551,13 @@ public class CacheListActivity extends AbstractListActivity implements FilteredA
AbstractSearchLoader loader = null;
switch (enumType) {
case OFFLINE:
- listId = Settings.getLastList();
+ // open either the requested or the last list
+ if (extras.containsKey(Intents.EXTRA_LIST_ID)) {
+ listId = extras.getInt(Intents.EXTRA_LIST_ID);
+ }
+ else {
+ listId = Settings.getLastList();
+ }
if (listId <= StoredList.TEMPORARY_LIST_ID) {
listId = StoredList.STANDARD_LIST_ID;
title = res.getString(R.string.stored_caches_button);
diff --git a/main/src/cgeo/geocaching/CreateShortcutActivity.java b/main/src/cgeo/geocaching/CreateShortcutActivity.java
new file mode 100644
index 0000000..7b91ba1
--- /dev/null
+++ b/main/src/cgeo/geocaching/CreateShortcutActivity.java
@@ -0,0 +1,55 @@
+package cgeo.geocaching;
+
+import cgeo.geocaching.activity.AbstractActivity;
+import cgeo.geocaching.list.StoredList;
+import cgeo.geocaching.utils.RunnableWithArgument;
+
+import android.content.Intent;
+import android.content.Intent.ShortcutIconResource;
+import android.os.Bundle;
+
+public class CreateShortcutActivity extends AbstractActivity {
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ // init
+ setTheme();
+
+ promptForShortcut();
+ }
+
+ private void promptForShortcut() {
+ new StoredList.UserInterface(this).promptForListSelection(R.string.create_shortcut, new RunnableWithArgument<Integer>() {
+
+ @Override
+ public void run(final Integer listId) {
+ final Intent shortcut = createShortcut(listId.intValue());
+ setResult(RESULT_OK, shortcut);
+
+ // finish activity to return the shortcut
+ finish();
+ }
+ });
+ }
+
+ protected Intent createShortcut(int listId) {
+ final StoredList list = DataStore.getList(listId);
+ if (list == null) {
+ return null;
+ }
+ // target to be executed by the shortcut
+ final Intent targetIntent = new Intent(this, CacheListActivity.class);
+ targetIntent.putExtra(Intents.EXTRA_LIST_ID, list.id);
+ final ShortcutIconResource iconResource = Intent.ShortcutIconResource.fromContext(this, R.drawable.cgeo);
+
+ // shortcut to be returned
+ final Intent intent = new Intent();
+ intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, targetIntent);
+ intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, list.title);
+ intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, iconResource);
+ return intent;
+ }
+
+}