Android Open Source - AmbientAlarmClock Action Manager






From Project

Back to project page AmbientAlarmClock.

License

The source code is released under:

<p align="center"><a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/"> <img alt="Creative Commons License" style="border-width:0" src="http://i.creativecommons.org/l/by-nc-sa/4.0...

If you think the Android project AmbientAlarmClock 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 de.lukeslog.alarmclock.actions;
/*from  w  w  w . j  a  va2  s .c  o  m*/
import org.joda.time.DateTime;

import java.util.HashMap;
import java.util.ArrayList;

import de.lukeslog.alarmclock.datatabse.AmbientAlarmDatabase;
import de.lukeslog.alarmclock.support.AlarmClockConstants;
import de.lukeslog.alarmclock.support.Logger;

/**
 * Created by lukas on 15.04.14.
 */
public class ActionManager
{

    public static String TAG = ActionManager.class.getName();

    private static ArrayList<AmbientAction> actionList = new ArrayList<AmbientAction>();

    public static void updateActionList()
    {
        actionList = AmbientAlarmDatabase.getAllActionsFromDatabase();
    }

    public static AmbientAction createActionFromConfigBundle(ActionConfigBundle configBundle, String className)
    {
        //This method is lame but I don't want to do reflection and building a plugin infrastructre is
        // just a lot of work so the types are hardcoded... I'm sorry about that.
        if(className.equals(AmbientAction.COUNTDOWN_ACTION))
        {
            CountdownAction ca = new CountdownAction(configBundle);
            return ca;
        }
        if(className.equals(AmbientAction.SENDMAIL_ACTION))
        {
            SendMailAction sma = new SendMailAction(configBundle);
            return sma;
        }
        if(className.equals(AmbientAction.PHILIPSHUE_ACTION))
        {
            PhilipsHueAction pha = new PhilipsHueAction(configBundle);
            return pha;
        }
        if(className.equals(AmbientAction.MUSIC_ACTION))
        {
            Logger.d(TAG, "new music action from config bundle...");
            MusicAction ma = new MusicAction(configBundle);
            return ma;
        }
        if(className.equals(AmbientAction.EZCONTROLPLUG_ACTION))
        {
            EZControlPlugAction ezpa = new EZControlPlugAction(configBundle);
            return ezpa;
        }
        if(className.equals(AmbientAction.EZCONTROLHEAT_ACTION))
        {
            EZControlHeatAction ezha = new EZControlHeatAction(configBundle);
            return ezha;
        }
        if(className.equals(AmbientAction.WEBSITE_ACTION))
        {
            WebsiteAction wa = new WebsiteAction(configBundle);
            return wa;
        }
        //if(className.equals(AmbientAction.CHROMECAST_ACTION))
        //{
        //    ChromecastAction cca = new ChromecastAction(configBundle);
        //    return cca;
        //}
        return null;
    }

    public static void notifyOfCurrentTime(DateTime currentTime)
    {
        Logger.d(TAG, "notifyactionsoftime...");
        for(AmbientAction action: actionList)
        {
            Logger.d(TAG, action.actionName);
            action.tick(currentTime);
        }
    }

    public static void addNewAction(AmbientAction ambientAction)
    {
        Logger.d(TAG, "add new action in ActionManager");
        actionList.add(ambientAction);
    }

    /**
     *
     * @return
     */
    public static ArrayList<HashMap<String, String>> getActionTypes()
    {
        ArrayList<HashMap<String, String>> actionInformation = new ArrayList<HashMap<String, String>>();
       //CountDownAction
        HashMap<String, String> descriptionCountdownAction = new HashMap<String, String>();
        fillDescription(descriptionCountdownAction, AmbientAction.COUNTDOWN_ACTION, "Countdown Action", "countdown_action_icon", "Showing you a countdown when the alarm rings.");

        HashMap<String, String> descriptionSendMailAction = new HashMap<String, String>();
        fillDescription(descriptionSendMailAction, AmbientAction.SENDMAIL_ACTION, "Send Mail Action", "send_mail_action_icon", "Sending an email at a specified time");

        HashMap<String, String> descriptionPhilipsHueAction = new HashMap<String, String>();
        fillDescription(descriptionPhilipsHueAction, AmbientAction.PHILIPSHUE_ACTION, "Philips Hue Action", "light_action_icon", "Turning on the light when you wake up.");

        HashMap<String, String> descriptionMusicAction = new HashMap<String, String>();
        fillDescription(descriptionMusicAction, AmbientAction.MUSIC_ACTION, "Music Action", "music_action_icon", "Playing Music on Wakeup.");

        HashMap <String, String> descriptionEZControlPlugAction = new HashMap<String, String>();
        fillDescription(descriptionEZControlPlugAction, AmbientAction.EZCONTROLPLUG_ACTION, "ezControl Plug Action", "action_icon", "Switching a plug using the ezControl Home Automation System.");

        HashMap<String, String> descriptionEZControlHeatAction = new HashMap<String, String>();
        fillDescription(descriptionEZControlHeatAction, AmbientAction.EZCONTROLHEAT_ACTION, "ezControl Radiator Action", "action_icon", "Controlling The Radiator.");

        HashMap<String, String> descriptionWebsiteAction = new HashMap<String, String>();
        fillDescription(descriptionWebsiteAction, AmbientAction.WEBSITE_ACTION, "Website Action", "action_icon", "Show a website on the alarm-screen.");

       // HashMap<String, String> descriptionChromecastAction = new HashMap<String, String>();
        //fillDescription(descriptionChromecastAction, AmbientAction.CHROMECAST_ACTION, "Chromecast Action", "action_icon", "Display pictures or video on a chromecast receiver.");

        actionInformation.add(descriptionCountdownAction);
        actionInformation.add(descriptionSendMailAction);
        actionInformation.add(descriptionPhilipsHueAction);
        actionInformation.add(descriptionMusicAction);
        actionInformation.add(descriptionEZControlPlugAction);
        actionInformation.add(descriptionWebsiteAction);
        actionInformation.add(descriptionEZControlHeatAction);
      //  actionInformation.add(descriptionChromecastAction);

        return actionInformation;
    }

    private static void fillDescription(HashMap<String, String> map, String type, String name, String icon, String desc)
    {
        map.put("actionType", type);
        map.put("actionName", name);
        map.put("actionIcon", icon);
        map.put("description", desc);
    }

    public static AmbientAction getActionByID(String actionID)
    {
        for(AmbientAction action : actionList)
        {
            if(action.getActionID().equals(actionID))
            {
                return action;
            }
        }
        return null;
    }

    public static ArrayList<AmbientAction> getActionList()
    {
        return actionList;
    }

    public static AmbientAction createNewDefaultAction(String actionTypeName)
    {
        if(actionTypeName.equals(AmbientAction.COUNTDOWN_ACTION))
        {
            CountdownAction cda = new CountdownAction("New Countdown Action", 3600);
            return cda;
        }
        if(actionTypeName.equals(AmbientAction.SENDMAIL_ACTION))
        {
            SendMailAction sma = new SendMailAction("New Send Mail Action", "", "Subject", "Content");
            return sma;
        }
        if(actionTypeName.equals(AmbientAction.PHILIPSHUE_ACTION))
        {
            PhilipsHueAction pha = new PhilipsHueAction("New Philips Hue Action");
            return pha;
        }
        if(actionTypeName.equals(AmbientAction.MUSIC_ACTION))
        {
            MusicAction ma = new MusicAction("New Music Action");
            return ma;
        }
        if(actionTypeName.equals(AmbientAction.EZCONTROLPLUG_ACTION))
        {
            EZControlPlugAction ezpa = new EZControlPlugAction("New ezControl Plug Action");
            return ezpa;
        }
        if(actionTypeName.equals((AmbientAction.EZCONTROLHEAT_ACTION)))
        {
            EZControlHeatAction ezha = new EZControlHeatAction("New ezControl Radiator Action");
            return ezha;
        }
        if(actionTypeName.equals(AmbientAction.WEBSITE_ACTION))
        {
            WebsiteAction wa = new WebsiteAction("New Website Action", "http://www.tagesschau.de");
            return wa;
        }
        //if(actionTypeName.equals(AmbientAction.CHROMECAST_ACTION))
        //{
        //    ChromecastAction ccax = new ChromecastAction("New Chromecast Action");
        //    return ccax;
        //}
        return null;
    }
}




Java Source Code List

de.lukeslog.alarmclock.MediaPlayer.MediaPlayerService.java
de.lukeslog.alarmclock.actions.ActionActivity.java
de.lukeslog.alarmclock.actions.ActionConfigBundle.java
de.lukeslog.alarmclock.actions.ActionManager.java
de.lukeslog.alarmclock.actions.AmbientAction.java
de.lukeslog.alarmclock.actions.CountdownActionConfigurationFragment.java
de.lukeslog.alarmclock.actions.CountdownAction.java
de.lukeslog.alarmclock.actions.EZControlHeatActionConfigurationFragment.java
de.lukeslog.alarmclock.actions.EZControlHeatAction.java
de.lukeslog.alarmclock.actions.EZControlPlugActionConfigurationFragment.java
de.lukeslog.alarmclock.actions.EZControlPlugAction.java
de.lukeslog.alarmclock.actions.MusicActionConfigurationFragment.java
de.lukeslog.alarmclock.actions.MusicAction.java
de.lukeslog.alarmclock.actions.PhilipsHueActionConfigurationFragment.java
de.lukeslog.alarmclock.actions.PhilipsHueAction.java
de.lukeslog.alarmclock.actions.SendMailActionFragment.java
de.lukeslog.alarmclock.actions.SendMailAction.java
de.lukeslog.alarmclock.actions.WebsiteActionConfigurationFragment.java
de.lukeslog.alarmclock.actions.WebsiteAction.java
de.lukeslog.alarmclock.ambientService.dropbox.DropBox.java
de.lukeslog.alarmclock.ambientService.lastfm.Scrobbler.java
de.lukeslog.alarmclock.ambientService.mail.BackgroundMail.java
de.lukeslog.alarmclock.ambientService.mail.Mail.java
de.lukeslog.alarmclock.ambientalarm.AmbientAlarmManager.java
de.lukeslog.alarmclock.ambientalarm.AmbientAlarm.java
de.lukeslog.alarmclock.datatabse.AmbientAlarmDatabase.java
de.lukeslog.alarmclock.datatabse.DatabaseConstants.java
de.lukeslog.alarmclock.main.ClockWorkService.java
de.lukeslog.alarmclock.main.NotificationManagement.java
de.lukeslog.alarmclock.main.Timable.java
de.lukeslog.alarmclock.startup.NotificationService.java
de.lukeslog.alarmclock.startup.ServiceStarter.java
de.lukeslog.alarmclock.startup.StartUp.java
de.lukeslog.alarmclock.support.AlarmClockConstants.java
de.lukeslog.alarmclock.support.AlarmState.java
de.lukeslog.alarmclock.support.Day.java
de.lukeslog.alarmclock.support.Logger.java
de.lukeslog.alarmclock.support.Radiostations.java
de.lukeslog.alarmclock.support.Settings.java
de.lukeslog.alarmclock.support.UISupport.java
de.lukeslog.alarmclock.teardown.Teardown.java
de.lukeslog.alarmclock.ui.ActionListAdapter.java
de.lukeslog.alarmclock.ui.AlarmClockMainActivity.java
de.lukeslog.alarmclock.ui.AlarmListAdapter.java
de.lukeslog.alarmclock.ui.AmbientAlarmActivity.java
de.lukeslog.alarmclock.ui.AmbientAlarmConfigurationActivity.java
de.lukeslog.alarmclock.ui.NewAmbientAction.java
de.lukeslog.alarmclock.ui.NewSettingsFragment.java
de.lukeslog.alarmclock.ui.SettingsActivity.java
org.json2.JSONArray.java
org.json2.JSONException.java
org.json2.JSONObject.java
org.json2.JSONString.java
org.json2.JSONStringer.java
org.json2.JSONTokener.java
org.json2.JSONWriter.java