// Path: NotificationAnalyser/app/src/main/java/com/tierep/notificationanalyser/NotificationListener.java
// public class NotificationListener extends NotificationListenerService {
//     public static boolean isNotificationAccessEnabled = false;
// 
//     private DatabaseHelper databaseHelper = null;
// 
//     public NotificationListener() {
//     }
// 
//     public DatabaseHelper getDatabaseHelper() {
//         if (databaseHelper == null) {
//             databaseHelper = OpenHelperManager.getHelper(this, DatabaseHelper.class);
//         }
//         return databaseHelper;
//     }
// 
//     @Override
//     public void onDestroy() {
//         super.onDestroy();
//         if (databaseHelper != null) {
//             OpenHelperManager.releaseHelper();
//             databaseHelper = null;
//         }
//     }
// 
//     @Override
//     public void onNotificationPosted(StatusBarNotification sbn) {
//         if (!sbn.isOngoing()) {
//             storeNotification(sbn);
//         }
//     }
// 
//     @Override
//     public void onNotificationRemoved(StatusBarNotification sbn) {
//         if (sbn.isOngoing()) {
//             storeNotification(sbn);
//         }
//     }
// 
//     private void storeNotification(StatusBarNotification sbn) {
//         try {
//             String packageName = sbn.getPackageName();
//             ApplicationDao applicationDao = getDatabaseHelper().getApplicationDao();
//             if (!applicationDao.idExists(packageName)) {
//                 Application application = new Application(packageName, false);
//                 applicationDao.create(application);
//             }
// 
//             String appName = packageName;
//             try {
//                 ApplicationInfo info = getPackageManager().getApplicationInfo(packageName, 0);
//                 appName = getPackageManager().getApplicationLabel(info).toString();
//             } catch (PackageManager.NameNotFoundException e) {
//                 e.printStackTrace();
//             }
//             String message = null;
//             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//                 if (sbn.getNotification().extras != null) {
//                     message = sbn.getNotification().extras.getString(
//                             Notification.EXTRA_TITLE);
//                     if (message == null || "".equals(message)) {
//                         message = sbn.getNotification().extras.getString(
//                                 Notification.EXTRA_TEXT);
//                     } else if (message.equals(appName)) {
//                         String otherMsg = sbn.getNotification().extras.getString(
//                                 Notification.EXTRA_TEXT);
//                         if (otherMsg != null && !"".equals(otherMsg)) {
//                             message = otherMsg;
//                         }
//                     }
//                 }
//             }
// 
//             if (message == null || "".equals(message)) {
//                 message = sbn.getNotification().tickerText.toString();
//             } else if (message.equals(appName)) {
//                 String otherMsg = sbn.getNotification().tickerText.toString();
//                 if (otherMsg != null && !"".equals(otherMsg)) {
//                     message = otherMsg;
//                 }
//             }
// 
//             Dao<NotificationItem, Integer> dao = getDatabaseHelper().getNotificationDao();
//             NotificationItem newItem = new NotificationItem(packageName, new Date(sbn.getPostTime()), message);
//             dao.create(newItem);
//         } catch (SQLException e) {
//             e.printStackTrace();
//         }
//     }
// 
//     @Override
//     public IBinder onBind(Intent intent) {
//         IBinder binder = super.onBind(intent);
//         isNotificationAccessEnabled = true;
//         return binder;
//     }
// 
//     @Override
//     public boolean onUnbind(Intent intent) {
//         boolean onUnbind = super.onUnbind(intent);
//         isNotificationAccessEnabled = false;
//         return onUnbind;
//     }
// }


import android.app.Activity;
import android.app.DialogFragment;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import com.tierep.notificationanalyser.NotificationListener;
import com.tierep.notificationanalyser.R;
        drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawerList = (ListView) findViewById(R.id.drawer_list);
        drawerItems = getResources().getStringArray(R.array.navigation_drawer_list);
        drawerList.setAdapter(new ArrayAdapter<String>(this,
                R.layout.navigation_drawer_list_item, drawerItems));
        drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                selectItem(i);
            }
        });
        drawerToggle = new ActionBarDrawerToggle(
                this,
                drawerLayout,
                R.string.drawer_open,
                R.string.drawer_close) {
            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                getActionBar().setTitle(R.string.app_name);
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);
                getActionBar().setTitle(currentTitle);
            }
        };
        drawerLayout.setDrawerListener(drawerToggle);

// Path: NotificationAnalyser/app/src/main/java/com/tierep/notificationanalyser/NotificationListener.java
// public class NotificationListener extends NotificationListenerService {
//     public static boolean isNotificationAccessEnabled = false;
// 
//     private DatabaseHelper databaseHelper = null;
// 
//     public NotificationListener() {
//     }
// 
//     public DatabaseHelper getDatabaseHelper() {
//         if (databaseHelper == null) {
//             databaseHelper = OpenHelperManager.getHelper(this, DatabaseHelper.class);
//         }
//         return databaseHelper;
//     }
// 
//     @Override
//     public void onDestroy() {
//         super.onDestroy();
//         if (databaseHelper != null) {
//             OpenHelperManager.releaseHelper();
//             databaseHelper = null;
//         }
//     }
// 
//     @Override
//     public void onNotificationPosted(StatusBarNotification sbn) {
//         if (!sbn.isOngoing()) {
//             storeNotification(sbn);
//         }
//     }
// 
//     @Override
//     public void onNotificationRemoved(StatusBarNotification sbn) {
//         if (sbn.isOngoing()) {
//             storeNotification(sbn);
//         }
//     }
// 
//     private void storeNotification(StatusBarNotification sbn) {
//         try {
//             String packageName = sbn.getPackageName();
//             ApplicationDao applicationDao = getDatabaseHelper().getApplicationDao();
//             if (!applicationDao.idExists(packageName)) {
//                 Application application = new Application(packageName, false);
//                 applicationDao.create(application);
//             }
// 
//             String appName = packageName;
//             try {
//                 ApplicationInfo info = getPackageManager().getApplicationInfo(packageName, 0);
//                 appName = getPackageManager().getApplicationLabel(info).toString();
//             } catch (PackageManager.NameNotFoundException e) {
//                 e.printStackTrace();
//             }
//             String message = null;
//             if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//                 if (sbn.getNotification().extras != null) {
//                     message = sbn.getNotification().extras.getString(
//                             Notification.EXTRA_TITLE);
//                     if (message == null || "".equals(message)) {
//                         message = sbn.getNotification().extras.getString(
//                                 Notification.EXTRA_TEXT);
//                     } else if (message.equals(appName)) {
//                         String otherMsg = sbn.getNotification().extras.getString(
//                                 Notification.EXTRA_TEXT);
//                         if (otherMsg != null && !"".equals(otherMsg)) {
//                             message = otherMsg;
//                         }
//                     }
//                 }
//             }
// 
//             if (message == null || "".equals(message)) {
//                 message = sbn.getNotification().tickerText.toString();
//             } else if (message.equals(appName)) {
//                 String otherMsg = sbn.getNotification().tickerText.toString();
//                 if (otherMsg != null && !"".equals(otherMsg)) {
//                     message = otherMsg;
//                 }
//             }
// 
//             Dao<NotificationItem, Integer> dao = getDatabaseHelper().getNotificationDao();
//             NotificationItem newItem = new NotificationItem(packageName, new Date(sbn.getPostTime()), message);
//             dao.create(newItem);
//         } catch (SQLException e) {
//             e.printStackTrace();
//         }
//     }
// 
//     @Override
//     public IBinder onBind(Intent intent) {
//         IBinder binder = super.onBind(intent);
//         isNotificationAccessEnabled = true;
//         return binder;
//     }
// 
//     @Override
//     public boolean onUnbind(Intent intent) {
//         boolean onUnbind = super.onUnbind(intent);
//         isNotificationAccessEnabled = false;
//         return onUnbind;
//     }
// }


// Path: NotificationAnalyser/app/src/main/java/com/tierep/notificationanalyser/ui/DrawerActivity.java
import android.app.Activity;
import android.app.DialogFragment;
import android.app.FragmentTransaction;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import com.tierep.notificationanalyser.NotificationListener;
import com.tierep.notificationanalyser.R;

        drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawerList = (ListView) findViewById(R.id.drawer_list);
        drawerItems = getResources().getStringArray(R.array.navigation_drawer_list);
        drawerList.setAdapter(new ArrayAdapter<String>(this,
                R.layout.navigation_drawer_list_item, drawerItems));
        drawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                selectItem(i);
            }
        });
        drawerToggle = new ActionBarDrawerToggle(
                this,
                drawerLayout,
                R.string.drawer_open,
                R.string.drawer_close) {
            @Override
            public void onDrawerOpened(View drawerView) {
                super.onDrawerOpened(drawerView);
                getActionBar().setTitle(R.string.app_name);
            }

            @Override
            public void onDrawerClosed(View drawerView) {
                super.onDrawerClosed(drawerView);
                getActionBar().setTitle(currentTitle);
            }
        };
        drawerLayout.setDrawerListener(drawerToggle);

        if (!NotificationListener.isNotificationAccessEnabled) {