experimental support for making launcher shortcuts (to headlinesactivity
only atm)
This commit is contained in:
parent
d975ea568d
commit
45116bd86b
@ -11,6 +11,7 @@
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
|
||||
|
||||
<application
|
||||
android:name=".GlobalState"
|
||||
@ -41,6 +42,9 @@
|
||||
android:name=".HeadlinesActivity"
|
||||
android:uiOptions="splitActionBarWhenNarrow"
|
||||
android:label="@string/app_name" >
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity
|
||||
android:name=".CommonActivity"
|
||||
|
@ -16,4 +16,7 @@
|
||||
android:id="@+id/catchup_category"
|
||||
android:title="@string/catchup"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/create_shortcut"
|
||||
android:title="@string/place_shortcut"/>
|
||||
</menu>
|
@ -15,5 +15,9 @@
|
||||
<item
|
||||
android:id="@+id/catchup_feed"
|
||||
android:title="@string/catchup"/>
|
||||
|
||||
<item
|
||||
android:id="@+id/create_shortcut"
|
||||
android:title="@string/place_shortcut"/>
|
||||
|
||||
</menu>
|
@ -204,4 +204,6 @@
|
||||
<string name="theme_system">Device Default</string>
|
||||
<string name="accel_webview_summary">Disable if you see flicker or visual glitches.</string>
|
||||
<string name="accel_webview_title">Accelerate web views</string>
|
||||
<string name="place_shortcut">Place shortcut</string>
|
||||
<string name="shortcut_has_been_placed_on_the_home_screen">Shortcut has been placed on the home screen</string>
|
||||
</resources>
|
||||
|
@ -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);
|
||||
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
@ -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);
|
||||
|
@ -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");
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user