summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2013-10-17 10:37:32 +0400
committerAndrew Dolgov <[email protected]>2013-10-17 10:37:32 +0400
commit45116bd86bed97ec87055e6454891c7db6dad21d (patch)
tree23dfaaeeff5add34730da4b5c0672d643235a634 /src
parentd975ea568dff63948fc2bf1541e256bb2d1bc87c (diff)
experimental support for making launcher shortcuts (to headlinesactivity
only atm)
Diffstat (limited to 'src')
-rw-r--r--src/org/fox/ttrss/FeedCategoriesFragment.java9
-rw-r--r--src/org/fox/ttrss/FeedsActivity.java26
-rw-r--r--src/org/fox/ttrss/FeedsFragment.java8
-rw-r--r--src/org/fox/ttrss/HeadlinesActivity.java20
4 files changed, 62 insertions, 1 deletions
diff --git a/src/org/fox/ttrss/FeedCategoriesFragment.java b/src/org/fox/ttrss/FeedCategoriesFragment.java
index 3c03952b..df4e6dff 100644
--- a/src/org/fox/ttrss/FeedCategoriesFragment.java
+++ b/src/org/fox/ttrss/FeedCategoriesFragment.java
@@ -128,6 +128,15 @@ public class FeedCategoriesFragment extends Fragment implements OnItemClickListe
}
}
return true;
+ case R.id.create_shortcut:
+ if (true) {
+ FeedCategory cat = getCategoryAtPosition(info.position);
+ if (cat != null) {
+ m_activity.createCategoryShortcut(cat);
+ //cf.setSelectedCategory(cat);
+ }
+ }
+ return true;
case R.id.catchup_category:
if (true) {
final FeedCategory cat = getCategoryAtPosition(info.position);
diff --git a/src/org/fox/ttrss/FeedsActivity.java b/src/org/fox/ttrss/FeedsActivity.java
index f7f0c989..4cd6148c 100644
--- a/src/org/fox/ttrss/FeedsActivity.java
+++ b/src/org/fox/ttrss/FeedsActivity.java
@@ -11,10 +11,13 @@ import org.fox.ttrss.util.AppRater;
import android.animation.ObjectAnimator;
import android.annotation.SuppressLint;
+import android.content.ComponentName;
import android.content.Intent;
+import android.content.Intent.ShortcutIconResource;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
+import android.os.Parcelable;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentTransaction;
@@ -389,4 +392,27 @@ public class FeedsActivity extends OnlineActivity implements HeadlinesEventListe
GlobalState.getInstance().m_activeArticle = null;
}
}
+
+ public void createFeedShortcut(Feed feed) {
+ final Intent shortcutIntent = new Intent(this, HeadlinesActivity.class);
+ shortcutIntent.putExtra("feed_id", feed.id);
+ shortcutIntent.putExtra("feed_is_cat", feed.is_cat);
+ shortcutIntent.putExtra("feed_title", feed.title);
+ shortcutIntent.putExtra("shortcut_mode", true);
+
+ Intent intent = new Intent("com.android.launcher.action.INSTALL_SHORTCUT");
+
+ intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, feed.title);
+ intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
+ intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(this, R.drawable.icon));
+ intent.putExtra("duplicate", false);
+
+ sendBroadcast(intent);
+
+ toast(R.string.shortcut_has_been_placed_on_the_home_screen);
+ }
+
+ public void createCategoryShortcut(FeedCategory cat) {
+ createFeedShortcut(new Feed(cat.id, cat.title, true));
+ }
}
diff --git a/src/org/fox/ttrss/FeedsFragment.java b/src/org/fox/ttrss/FeedsFragment.java
index f6692ca7..fe6ba048 100644
--- a/src/org/fox/ttrss/FeedsFragment.java
+++ b/src/org/fox/ttrss/FeedsFragment.java
@@ -159,6 +159,14 @@ public class FeedsFragment extends Fragment implements OnItemClickListener, OnSh
}
}
return true;
+ case R.id.create_shortcut:
+ if (true) {
+ Feed feed = getFeedAtPosition(info.position);
+ if (feed != null) {
+ m_activity.createFeedShortcut(feed);
+ }
+ }
+ return true;
case R.id.catchup_feed:
if (true) {
final Feed feed = getFeedAtPosition(info.position);
diff --git a/src/org/fox/ttrss/HeadlinesActivity.java b/src/org/fox/ttrss/HeadlinesActivity.java
index c25c755e..ed86867e 100644
--- a/src/org/fox/ttrss/HeadlinesActivity.java
+++ b/src/org/fox/ttrss/HeadlinesActivity.java
@@ -47,7 +47,25 @@ public class HeadlinesActivity extends OnlineActivity implements HeadlinesEventL
Intent i = getIntent();
if (i.getExtras() != null) {
- final Feed feed = i.getParcelableExtra("feed");
+ boolean shortcutMode = i.getBooleanExtra("shortcut_mode", false);
+
+ Log.d(TAG, "is_shortcut_mode: " + shortcutMode);
+
+ Feed tmpFeed;
+
+ if (shortcutMode) {
+ int feedId = i.getIntExtra("feed_id", 0);
+ boolean isCat = i.getBooleanExtra("feed_is_cat", false);
+ String feedTitle = i.getStringExtra("feed_title");
+
+ tmpFeed = new Feed(feedId, feedTitle, isCat);
+
+ } else {
+ tmpFeed = i.getParcelableExtra("feed");
+ }
+
+ final Feed feed = tmpFeed;
+
final Article article = i.getParcelableExtra("article");
final String searchQuery = i.getStringExtra("searchQuery");