Android Open Source - wakeup Receive Notification






From Project

Back to project page wakeup.

License

The source code is released under:

GNU General Public License

If you think the Android project wakeup 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

/*
Copyright (C) 2009 Gopalkrishna Sharma.//www  .j a  v a 2  s . co  m
Email: gopalkri@umich.edu / gopalkrishnaps@gmail.com

This file is part of WakeUp!.

Wake Up! is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

Wake Up! is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Wake Up!.  If not, see <http://www.gnu.org/licenses/>.
*/

package edu.umich.gopalkri.wakeup;

import java.io.FileNotFoundException;

import android.app.Activity;
import android.app.NotificationManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import edu.umich.gopalkri.wakeup.data.Alarm;

public class ReceiveNotification extends Activity
{
    public static final int NOTIFICATION_ID = 1;

    private static final int MENU_HOME = Menu.FIRST;

    /**
     * (non-Javadoc)
     *
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
    @Override
    protected void onCreate(Bundle savedInstanceState)
    {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        setContentView(R.layout.receive_notification);
        TextView text = (TextView) findViewById(R.id.receive_notification_text);

        NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.cancel(NOTIFICATION_ID);

        Alarm alarm = Utilities.getActiveAlarm(this);
        if (alarm == null)
        {
            // This should never happen.
            throw new RuntimeException("Notification was triggered but there was no alarm.");
        }

        String content = "You had set alarm: " + alarm.getName() + "\n\n" + "You are now within "
                + ((Double) alarm.getRadius()) + " " + Alarm.UnitsToString(alarm.getUnit())
                + " of your destination.\n\nThe alarm has now been deactiviated.";
        text.setText(content);

        try
        {
            Utilities.writeStringToFile("", openFileOutput(GPSService.ACTIVE_ALARM_FILE, Context.MODE_PRIVATE));
        }
        catch (FileNotFoundException e)
        {
            // Should never happen.
            throw new RuntimeException("Unexpected FileNotFoundException thrown in ReceiveNotification.onCreate.");
        }
    }

    /**
     * @see android.app.Activity#onCreateOptionsMenu(android.view.Menu)
     */
    @Override
    public boolean onCreateOptionsMenu(Menu menu)
    {
        boolean result = super.onCreateOptionsMenu(menu);
        menu.add(Menu.NONE, MENU_HOME, Menu.NONE, R.string.receive_notification_home);
        return result;
    }

    /**
     * @see android.app.Activity#onOptionsItemSelected(android.view.MenuItem)
     */
    @Override
    public boolean onOptionsItemSelected(MenuItem item)
    {
        switch (item.getItemId())
        {
        case MENU_HOME:
            Intent i = new Intent(this, Home.class);
            startActivity(i);
            setResult(RESULT_OK);
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}




Java Source Code List

edu.umich.gopalkri.wakeup.DestinationOverlay.java
edu.umich.gopalkri.wakeup.EditAlarm.java
edu.umich.gopalkri.wakeup.EditSettings.java
edu.umich.gopalkri.wakeup.GPSService.java
edu.umich.gopalkri.wakeup.Help.java
edu.umich.gopalkri.wakeup.Home.java
edu.umich.gopalkri.wakeup.ManageAlarms.java
edu.umich.gopalkri.wakeup.ReceiveNotification.java
edu.umich.gopalkri.wakeup.SelectDestination.java
edu.umich.gopalkri.wakeup.Utilities.java
edu.umich.gopalkri.wakeup.WakeUpException.java
edu.umich.gopalkri.wakeup.data.AlarmAlreadyExistsException.java
edu.umich.gopalkri.wakeup.data.Alarm.java
edu.umich.gopalkri.wakeup.data.Alarms.java
edu.umich.gopalkri.wakeup.data.InvalidAlarmNameException.java
edu.umich.gopalkri.wakeup.data.InvalidAlarmStringException.java
edu.umich.gopalkri.wakeup.data.Settings.java