Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
notifications service in a separated process, min api 15
Browse files Browse the repository at this point in the history
indywidualny committed Jun 18, 2015
1 parent 1676ad8 commit 1a29731
Showing 7 changed files with 83 additions and 71 deletions.
Binary file modified app/app-release.apk
Binary file not shown.
4 changes: 3 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -6,7 +6,8 @@ android {

defaultConfig {
applicationId "org.indywidualni.fblite"
minSdkVersion 14
resValue "string", "tray__authority", "${applicationId}.tray"
minSdkVersion 15
targetSdkVersion 22
versionCode 14
versionName "1.7.4"
@@ -27,5 +28,6 @@ dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:support-v4:22.1.1'
compile 'com.android.support:appcompat-v7:22.1.1'
compile 'net.grandcentrix.tray:tray:0.9.2'
compile project(':saxrssreader')
}
96 changes: 55 additions & 41 deletions app/manifest-merger-release-report.txt
Original file line number Diff line number Diff line change
@@ -22,6 +22,7 @@ ADDED from AndroidManifest.xml:8:5
MERGED from com.android.support:support-v4:22.1.1:20:5
MERGED from com.android.support:appcompat-v7:22.1.1:20:5
MERGED from com.android.support:support-v4:22.1.1:20:5
MERGED from net.grandcentrix.tray:tray:0.9.2:7:5
MERGED from FacebookLite:saxrssreader:unspecified:7:5
android:targetSdkVersion
ADDED from AndroidManifest.xml:10:9
@@ -57,6 +58,7 @@ ADDED from AndroidManifest.xml:18:5
MERGED from com.android.support:support-v4:22.1.1:22:5
MERGED from com.android.support:appcompat-v7:22.1.1:22:5
MERGED from com.android.support:support-v4:22.1.1:22:5
MERGED from net.grandcentrix.tray:tray:0.9.2:11:5
MERGED from FacebookLite:saxrssreader:unspecified:11:5
android:label
ADDED from AndroidManifest.xml:23:9
@@ -92,93 +94,105 @@ service#org.indywidualni.fblite.NotificationsService
ADDED from AndroidManifest.xml:34:9
android:enabled
ADDED from AndroidManifest.xml:37:13
android:process
ADDED from AndroidManifest.xml:39:13
android:exported
ADDED from AndroidManifest.xml:38:13
android:icon
ADDED from AndroidManifest.xml:36:13
android:name
ADDED from AndroidManifest.xml:35:13
activity#org.indywidualni.fblite.MainActivity
ADDED from AndroidManifest.xml:40:9
ADDED from AndroidManifest.xml:41:9
android:label
ADDED from AndroidManifest.xml:42:13
ADDED from AndroidManifest.xml:43:13
android:launchMode
ADDED from AndroidManifest.xml:44:13
ADDED from AndroidManifest.xml:45:13
android:configChanges
ADDED from AndroidManifest.xml:43:13
ADDED from AndroidManifest.xml:44:13
android:name
ADDED from AndroidManifest.xml:41:13
ADDED from AndroidManifest.xml:42:13
intent-filter#android.intent.action.MAIN+android.intent.category.LAUNCHER
ADDED from AndroidManifest.xml:45:13
ADDED from AndroidManifest.xml:46:13
action#android.intent.action.MAIN
ADDED from AndroidManifest.xml:46:17
ADDED from AndroidManifest.xml:47:17
android:name
ADDED from AndroidManifest.xml:46:25
ADDED from AndroidManifest.xml:47:25
category#android.intent.category.LAUNCHER
ADDED from AndroidManifest.xml:47:17
ADDED from AndroidManifest.xml:48:17
android:name
ADDED from AndroidManifest.xml:47:27
ADDED from AndroidManifest.xml:48:27
intent-filter#android.intent.action.VIEW+android.intent.category.BROWSABLE+android.intent.category.DEFAULT
ADDED from AndroidManifest.xml:49:13
ADDED from AndroidManifest.xml:50:13
action#android.intent.action.VIEW
ADDED from AndroidManifest.xml:50:17
android:name
ADDED from AndroidManifest.xml:50:25
category#android.intent.category.DEFAULT
ADDED from AndroidManifest.xml:51:17
android:name
ADDED from AndroidManifest.xml:51:27
category#android.intent.category.BROWSABLE
ADDED from AndroidManifest.xml:51:25
category#android.intent.category.DEFAULT
ADDED from AndroidManifest.xml:52:17
android:name
ADDED from AndroidManifest.xml:52:27
data
category#android.intent.category.BROWSABLE
ADDED from AndroidManifest.xml:53:17
android:name
ADDED from AndroidManifest.xml:53:27
data
ADDED from AndroidManifest.xml:54:17
android:host
ADDED from AndroidManifest.xml:53:23
ADDED from AndroidManifest.xml:54:23
android:scheme
ADDED from AndroidManifest.xml:53:51
ADDED from AndroidManifest.xml:54:51
activity#org.indywidualni.fblite.SettingsActivity
ADDED from AndroidManifest.xml:61:9
ADDED from AndroidManifest.xml:62:9
android:label
ADDED from AndroidManifest.xml:63:13
android:parentActivityName
ADDED from AndroidManifest.xml:64:13
android:configChanges
android:parentActivityName
ADDED from AndroidManifest.xml:65:13
android:theme
android:configChanges
ADDED from AndroidManifest.xml:66:13
android:theme
ADDED from AndroidManifest.xml:67:13
android:name
ADDED from AndroidManifest.xml:62:13
ADDED from AndroidManifest.xml:63:13
meta-data#android.support.PARENT_ACTIVITY
ADDED from AndroidManifest.xml:67:13
ADDED from AndroidManifest.xml:68:13
android:value
ADDED from AndroidManifest.xml:69:17
ADDED from AndroidManifest.xml:70:17
android:name
ADDED from AndroidManifest.xml:68:17
ADDED from AndroidManifest.xml:69:17
activity#org.indywidualni.fblite.AboutActivity
ADDED from AndroidManifest.xml:71:9
ADDED from AndroidManifest.xml:72:9
android:label
ADDED from AndroidManifest.xml:73:13
android:parentActivityName
ADDED from AndroidManifest.xml:74:13
android:theme
android:parentActivityName
ADDED from AndroidManifest.xml:75:13
android:theme
ADDED from AndroidManifest.xml:76:13
android:name
ADDED from AndroidManifest.xml:72:13
ADDED from AndroidManifest.xml:73:13
activity#org.indywidualni.fblite.MessagesShortcutActivity
ADDED from AndroidManifest.xml:80:9
ADDED from AndroidManifest.xml:81:9
android:label
ADDED from AndroidManifest.xml:82:13
android:icon
ADDED from AndroidManifest.xml:83:13
android:icon
ADDED from AndroidManifest.xml:84:13
android:name
ADDED from AndroidManifest.xml:81:13
ADDED from AndroidManifest.xml:82:13
intent-filter#android.intent.action.CREATE_SHORTCUT+android.intent.category.DEFAULT
ADDED from AndroidManifest.xml:84:13
ADDED from AndroidManifest.xml:85:13
action#android.intent.action.CREATE_SHORTCUT
ADDED from AndroidManifest.xml:85:17
ADDED from AndroidManifest.xml:86:17
android:name
ADDED from AndroidManifest.xml:86:25
provider#net.grandcentrix.tray.provider.TrayProvider
ADDED from net.grandcentrix.tray:tray:0.9.2:12:9
android:authorities
ADDED from net.grandcentrix.tray:tray:0.9.2:14:13
android:multiprocess
ADDED from net.grandcentrix.tray:tray:0.9.2:16:13
android:exported
ADDED from net.grandcentrix.tray:tray:0.9.2:15:13
android:name
ADDED from AndroidManifest.xml:85:25
ADDED from net.grandcentrix.tray:tray:0.9.2:13:13
android:uses-permission#android.permission.READ_PHONE_STATE
IMPLIED from AndroidManifest.xml:2:1 reason: nl.matshofman.saxrssreader has a targetSdkVersion < 4
5 changes: 3 additions & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -6,7 +6,7 @@
android:installLocation="internalOnly" >

<uses-sdk
android:minSdkVersion="14"
android:minSdkVersion="15"
android:targetSdkVersion="22" />

<uses-permission android:name="android.permission.INTERNET" />
@@ -35,7 +35,8 @@
android:name=".NotificationsService"
android:icon="@drawable/ic_launcher"
android:enabled="true"
android:exported="false" >
android:exported="false"
android:process=":remote" >
</service>
<activity
android:name=".MainActivity"
15 changes: 11 additions & 4 deletions app/src/main/java/org/indywidualni/fblite/MainActivity.java
Original file line number Diff line number Diff line change
@@ -34,6 +34,9 @@
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.Toast;

import net.grandcentrix.tray.TrayAppPreferences;

import java.io.File;
import java.io.IOException;
import java.lang.ref.WeakReference;
@@ -58,17 +61,19 @@ public class MainActivity extends Activity {
private ValueCallback<Uri[]> mFilePathCallback;
private String mCameraPhotoPath;

// error handling
// error handling, shared prefs and TrayPreferences
private static final String TAG = MainActivity.class.getSimpleName();
private SharedPreferences preferences;
private TrayAppPreferences trayPreferences;

@Override
@SuppressLint("setJavaScriptEnabled")
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// get shared preferences
// get shared preferences and TrayPreferences
preferences = PreferenceManager.getDefaultSharedPreferences(this);
trayPreferences = new TrayAppPreferences(getApplicationContext());

// set the main content view (for drawer position)
if ("0".equals(preferences.getString("drawer_pos", "0")))
@@ -527,6 +532,7 @@ private void selectItem(int position) {
startActivity(about);
break;
case 8:
trayPreferences.put("activity_visible", false);
//finish();
System.exit(0); // ugly, ugly, ugly!
break;
@@ -564,6 +570,7 @@ private void selectItem(int position) {
startActivity(about);
break;
case 8:
trayPreferences.put("activity_visible", false);
//finish();
System.exit(0); // ugly, ugly, ugly!
break;
@@ -653,13 +660,13 @@ public void onBackPressed() {
@Override
protected void onResume() {
super.onResume();
MyApplication.activityResumed();
trayPreferences.put("activity_visible", true);
}

@Override
protected void onPause() {
super.onPause();
MyApplication.activityPaused();
trayPreferences.put("activity_visible", false);
}

@Override
15 changes: 0 additions & 15 deletions app/src/main/java/org/indywidualni/fblite/MyApplication.java
Original file line number Diff line number Diff line change
@@ -8,9 +8,6 @@ public class MyApplication extends Application {
// context of application for non context classes
private static Context mContext;

// is MainActivity active right now
private static boolean activityVisible;

@Override
public void onCreate() {
mContext = getApplicationContext();
@@ -21,16 +18,4 @@ public static Context getContextOfApplication() {
return mContext;
}

public static boolean isActivityVisible() {
return activityVisible;
}

public static void activityResumed() {
activityVisible = true;
}

public static void activityPaused() {
activityVisible = false;
}

}
Original file line number Diff line number Diff line change
@@ -17,6 +17,7 @@
import android.support.v4.app.TaskStackBuilder;
import android.util.Log;
import android.widget.Toast;
import net.grandcentrix.tray.TrayAppPreferences;
import java.net.URL;
import java.util.ArrayList;
import nl.matshofman.saxrssreader.RssFeed;
@@ -32,6 +33,7 @@ public class NotificationsService extends Service {
private String feedUrl;
private int timeInterval;
private SharedPreferences preferences;
private TrayAppPreferences trayPreferences;

@Override
public IBinder onBind(Intent intent) {
@@ -40,17 +42,18 @@ public IBinder onBind(Intent intent) {

@Override
public void onCreate() {
Toast.makeText(this, getString(R.string.facebook) + ": " + getString(R.string.notifications_service_created), Toast.LENGTH_LONG).show();
//Toast.makeText(this, getString(R.string.facebook) + ": " + getString(R.string.notifications_service_created), Toast.LENGTH_LONG).show();
Log.i("NotificationsService", "********** Service created! **********");

// get shared preferences (for a multi process app)
// get shared preferences (for a multi process app) and TrayPreferences
preferences = getSharedPreferences(getApplicationContext().getPackageName() + "_preferences", Context.MODE_MULTI_PROCESS);
trayPreferences = new TrayAppPreferences(getApplicationContext());

handler = new Handler();
runnable = new Runnable() {
public void run() {
//Log.i("NotificationsService", "********** Service is still running **********");
Log.i("NotificationsService", "isActivityVisible: " + Boolean.toString(MyApplication.isActivityVisible()));
Log.i("NotificationsService", "isActivityVisible: " + Boolean.toString(trayPreferences.getBoolean("activity_visible", false)));

// get the url and time interval from shared prefs
feedUrl = preferences.getString("feed_url", "");
@@ -118,18 +121,18 @@ protected void onPostExecute(ArrayList<RssItem> result) {
* of avoiding it, it's a nice example how it will work in the future.
*/

// get the last PubDate (String) from shared prefs
String savedDate = preferences.getString("saved_date", "nothing");
// get the last PubDate (String) from TrayPreferences
final String savedDate = trayPreferences.getString("saved_date", "nothing");

// if the saved PubDate is different than the new one it means there is new notification
// display it only when MainActivity is not active or 'Always notify' is checked
try {
if (!result.get(0).getPubDate().toString().equals(savedDate))
if (!MyApplication.isActivityVisible() || preferences.getBoolean("notifications_everywhere", true))
if (!trayPreferences.getBoolean("activity_visible", false) || preferences.getBoolean("notifications_everywhere", true))
notifier(result.get(0).getTitle(), result.get(0).getDescription(), result.get(0).getLink());

// save the latest PubDate (as a String) to shared prefs
preferences.edit().putString("saved_date", result.get(0).getPubDate().toString()).apply();
// save the latest PubDate (as a String) to TrayPreferences
trayPreferences.put("saved_date", result.get(0).getPubDate().toString());

// log success
Log.i("RssReaderTask", "********** onPostExecute: Aight biatch ;)");

0 comments on commit 1a29731

Please sign in to comment.