Android Open Source - eyebrows-sync Notification Supervisor






From Project

Back to project page eyebrows-sync.

License

The source code is released under:

Copyright (c) 2014 Jon Petraglia of Qweex All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "...

If you think the Android project eyebrows-sync listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.qweex.eyebrowssync;
/*  w w w  . j a  v  a 2 s .  c o m*/
import android.app.Activity;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.support.v4.app.NotificationCompat;
import com.qweex.eyebrowssync.JobList.Base;

import java.util.Set;

public class NotificationSupervisor {
    NotificationManager manager;
    Activity activity;
    NotificationCompat.Builder mBuilder;
    final int NOTIFICATION_ID = 1337;

    public NotificationSupervisor(Activity activity) {
        manager = (NotificationManager) activity.getSystemService(android.content.Context.NOTIFICATION_SERVICE);
        this.activity = activity;
        Intent intent = activity.getIntent();
        PendingIntent pIntent = PendingIntent.getActivity(activity, 0, intent, 0);
        mBuilder = new NotificationCompat.Builder(activity)
                .setSmallIcon(android.R.drawable.stat_sys_download)
                .setContentIntent(pIntent)
                .setOngoing(true);
    }

    public void update() {
        int activeSyncers = 0, filesTotal = 0, filesDone = 0;
        Syncer.PHASE targetPhase = Syncer.PHASE.CANCELED; //DOWNLOADING, PREPARING/COUNTING, DELETING/ERROR/FINISHED
        Set<String> keys = Base.syncers.keySet();
        for(String key : keys) {
            Syncer syncer = Base.syncers.get(key);
            if(syncer == null)
                continue;
            activeSyncers++;
            filesTotal += syncer.totalDownloadCount();
            filesDone += syncer.finishedDownloadCount();
            if(targetPhase== Syncer.PHASE.DOWNLOADING)
                continue;
            if(syncer.getPhase() == Syncer.PHASE.DOWNLOADING)
                targetPhase = syncer.getPhase();
            else if((targetPhase==Syncer.PHASE.DELETING || targetPhase==Syncer.PHASE.ERROR || targetPhase==Syncer.PHASE.FINISHED || targetPhase==Syncer.PHASE.CANCELED) &&
                    (syncer.getPhase()==Syncer.PHASE.PREPARING || syncer.getPhase()==Syncer.PHASE.COUNTING))
                targetPhase = syncer.getPhase();
            else if((targetPhase==Syncer.PHASE.DELETING || targetPhase==Syncer.PHASE.ERROR || targetPhase==Syncer.PHASE.FINISHED) &&
                    (syncer.getPhase()==Syncer.PHASE.DELETING || syncer.getPhase()==Syncer.PHASE.ERROR || syncer.getPhase()==Syncer.PHASE.FINISHED))
                targetPhase = syncer.getPhase();
        }

        if(targetPhase==Syncer.PHASE.FINISHED || targetPhase==Syncer.PHASE.ERROR || targetPhase==Syncer.PHASE.CANCELED)
        {
            PendingIntent pIntent = PendingIntent.getActivity(activity, 0, activity.getIntent(), 0);
            mBuilder = new NotificationCompat.Builder(activity)
                    .setContentTitle("Finished Syncing")
                    .setProgress(0, 0, false)
                    .setSmallIcon(android.R.drawable.stat_sys_download_done)
                    .setOngoing(false)
                    .setContentIntent(pIntent);
            if(targetPhase==Syncer.PHASE.ERROR)
                mBuilder.setContentInfo("Some jobs had errors");
            else
                mBuilder.setContentInfo(null);
            manager.notify(NOTIFICATION_ID, mBuilder.build());
            return;
        }

        mBuilder.setContentTitle("Syncing " + activeSyncers + " job" + (activeSyncers>1 ? "s" : ""));

        switch(targetPhase) {
            case DOWNLOADING:
                mBuilder.setContentInfo("Downloading " + (filesTotal-filesDone) + " files")
                        .setProgress(filesDone, filesTotal, false);
                break;
            case PREPARING:
            case COUNTING:
                mBuilder.setContentInfo("Preparing...")
                        .setProgress(0, 1, true);
                break;
            case DELETING:
                mBuilder.setContentInfo("Finishing...")
                        .setProgress(0, 1, true);
            case CANCELED:
                mBuilder.setContentInfo("Canceling...")
                        .setProgress(0, 1, true);
        }

        manager.notify(NOTIFICATION_ID, mBuilder.build());
    }

}




Java Source Code List

com.qweex.NumberPickerDialogPreference.java
com.qweex.eyebrows.EyebrowsError.java
com.qweex.eyebrows.did_not_write.JSONDownloader.java
com.qweex.eyebrowssync.AboutActivity.java
com.qweex.eyebrowssync.AsyncCrypt.java
com.qweex.eyebrowssync.AttachedRelativeLayout.java
com.qweex.eyebrowssync.EditJob.java
com.qweex.eyebrowssync.FileModifiedHelper.java
com.qweex.eyebrowssync.NotificationSupervisor.java
com.qweex.eyebrowssync.SavedJobs.java
com.qweex.eyebrowssync.StartActivity.java
com.qweex.eyebrowssync.StatusWindow.java
com.qweex.eyebrowssync.Syncer.java
com.qweex.eyebrowssync.UserConfig.java
com.qweex.eyebrowssync.JobList.Base.java
com.qweex.eyebrowssync.JobList.v11.java
com.qweex.eyebrowssync.JobList.v3.java
com.qweex.utils.Crypt.java
com.qweex.utils.DirectoryChooserDialog.java