Compare commits

...

10 Commits

Author SHA1 Message Date
warren powers
0a6dd1eea1 published today. refs #128 2011-03-05 20:01:30 +00:00
warren powers
e7a5885e97 published today. refs #128 2011-03-05 20:01:04 +00:00
warren powers
fca8c7f9c9 published today. refs #128 2011-03-05 20:00:51 +00:00
c499895095 refs #137
my initial commit of the new layouts for landscape. they need some tweaking
2011-02-17 19:16:38 +00:00
e9b549444a refs #128
updated manifest to lock the sweet dreams activity in portrait because the layout will not work in landscape
2011-02-17 15:38:59 +00:00
ff090f34ed refs #128
updated manifest to lock the sweet dreams activity in portrait because the layout will not work in landscape
2011-02-17 15:38:41 +00:00
0a6af33cf2 refs #128
updated manifest with proper version code, set save location to auto, and verified other information for release
2011-02-16 16:46:41 +00:00
60b337120b refs #128
updated manifest with proper version code, set save location to auto, and verified other information for release
2011-02-16 16:45:46 +00:00
f3e40559d4 updated to use the new exceptionhandler library 2011-02-13 23:09:57 +00:00
67e2bfce4c reduced redundant code 2011-02-12 20:22:03 +00:00
35 changed files with 810 additions and 388 deletions

View File

@@ -4,5 +4,6 @@
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="src" path="SweetDreamsLib_src"/>
<classpathentry kind="src" path="ExceptionHandlerLib_src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -31,6 +31,11 @@
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<linkedResources>
<link>
<name>ExceptionHandlerLib_src</name>
<type>2</type>
<locationURI>_android_ExceptionHandlerLib_7d68b46a/src</locationURI>
</link>
<link>
<name>SweetDreamsLib_src</name>
<type>2</type>

View File

@@ -1,11 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.TwentyCodes.android.SweetDreamsFull"
android:versionCode="1"
android:versionName="1.0">
android:versionCode="1" android:versionName="1.0.0" android:installLocation="auto">
<uses-sdk android:minSdkVersion="3" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<application android:label="@string/app_name" android:icon="@drawable/playdisabled">
<application android:label="@string/app_name" android:icon="@drawable/icon">
<activity android:name="SweetDreams">
<intent-filter>
<action android:name="android.intent.action.MAIN"></action>
@@ -13,6 +13,7 @@
</intent-filter>
</activity>
<activity android:name="com.TwentyCodes.android.SweetDreamsLib.Settings"></activity>
<service android:name="com.TwentyCodes.android.SweetDreamsLib.PlaybackService"></service>
</application>

View File

@@ -10,6 +10,7 @@ package com.TwentyCodes.android.SweetDreamsFull;
public final class R {
public static final class array {
public static final int sounds=0x7f060000;
public static final int sounds_lite=0x7f060001;
}
public static final class attr {
/** <p>Must be a color value, in the form of "<code>#<i>rgb</i></code>", "<code>#<i>argb</i></code>",
@@ -82,11 +83,11 @@ containing a value of this type.
public static final int main_lite=0x7f030001;
}
public static final class raw {
public static final int ac=0x7f050000;
public static final int beach=0x7f050001;
public static final int crickets=0x7f050002;
public static final int falls=0x7f050003;
public static final int river=0x7f050004;
public static final int beach=0x7f050000;
public static final int crickets=0x7f050001;
public static final int falls=0x7f050002;
public static final int river=0x7f050003;
public static final int wn=0x7f050004;
}
public static final class string {
public static final int app_name=0x7f070000;
@@ -94,6 +95,7 @@ containing a value of this type.
}
public static final class xml {
public static final int settings=0x7f040000;
public static final int settings_lite=0x7f040001;
}
public static final class styleable {
/** Attributes that can be used with a com_admob_android_ads_AdView.

View File

@@ -10,6 +10,7 @@ package com.TwentyCodes.android.SweetDreamsLib;
public final class R {
public static final class array {
public static final int sounds=0x7f060000;
public static final int sounds_lite=0x7f060001;
}
public static final class attr {
/** <p>Must be a color value, in the form of "<code>#<i>rgb</i></code>", "<code>#<i>argb</i></code>",
@@ -82,11 +83,11 @@ containing a value of this type.
public static final int main_lite=0x7f030001;
}
public static final class raw {
public static final int ac=0x7f050000;
public static final int beach=0x7f050001;
public static final int crickets=0x7f050002;
public static final int falls=0x7f050003;
public static final int river=0x7f050004;
public static final int beach=0x7f050000;
public static final int crickets=0x7f050001;
public static final int falls=0x7f050002;
public static final int river=0x7f050003;
public static final int wn=0x7f050004;
}
public static final class string {
public static final int app_name=0x7f070000;
@@ -94,6 +95,7 @@ containing a value of this type.
}
public static final class xml {
public static final int settings=0x7f040000;
public static final int settings_lite=0x7f040001;
}
public static final class styleable {
/** Attributes that can be used with a com_admob_android_ads_AdView.

View File

@@ -0,0 +1,197 @@
/* AUTO-GENERATED FILE. DO NOT MODIFY.
*
* This class was automatically generated by the
* aapt tool from the resource data it found. It
* should not be modified by hand.
*/
package com.TwentyCodes.android.exception;
public final class R {
public static final class array {
public static final int sounds=0x7f060000;
public static final int sounds_lite=0x7f060001;
}
public static final class attr {
/** <p>Must be a color value, in the form of "<code>#<i>rgb</i></code>", "<code>#<i>argb</i></code>",
"<code>#<i>rrggbb</i></code>", or "<code>#<i>aarrggbb</i></code>".
<p>This may also be a reference to a resource (in the form
"<code>@[<i>package</i>:]<i>type</i>:<i>name</i></code>") or
theme attribute (in the form
"<code>?[<i>package</i>:][<i>type</i>:]<i>name</i></code>")
containing a value of this type.
*/
public static final int backgroundColor=0x7f010000;
/** <p>Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.
<p>This may also be a reference to a resource (in the form
"<code>@[<i>package</i>:]<i>type</i>:<i>name</i></code>") or
theme attribute (in the form
"<code>?[<i>package</i>:][<i>type</i>:]<i>name</i></code>")
containing a value of this type.
*/
public static final int keywords=0x7f010003;
/** <p>Must be a color value, in the form of "<code>#<i>rgb</i></code>", "<code>#<i>argb</i></code>",
"<code>#<i>rrggbb</i></code>", or "<code>#<i>aarrggbb</i></code>".
<p>This may also be a reference to a resource (in the form
"<code>@[<i>package</i>:]<i>type</i>:<i>name</i></code>") or
theme attribute (in the form
"<code>?[<i>package</i>:][<i>type</i>:]<i>name</i></code>")
containing a value of this type.
*/
public static final int primaryTextColor=0x7f010001;
/** <p>Must be an integer value, such as "<code>100</code>".
<p>This may also be a reference to a resource (in the form
"<code>@[<i>package</i>:]<i>type</i>:<i>name</i></code>") or
theme attribute (in the form
"<code>?[<i>package</i>:][<i>type</i>:]<i>name</i></code>")
containing a value of this type.
*/
public static final int refreshInterval=0x7f010004;
/** <p>Must be a color value, in the form of "<code>#<i>rgb</i></code>", "<code>#<i>argb</i></code>",
"<code>#<i>rrggbb</i></code>", or "<code>#<i>aarrggbb</i></code>".
<p>This may also be a reference to a resource (in the form
"<code>@[<i>package</i>:]<i>type</i>:<i>name</i></code>") or
theme attribute (in the form
"<code>?[<i>package</i>:][<i>type</i>:]<i>name</i></code>")
containing a value of this type.
*/
public static final int secondaryTextColor=0x7f010002;
}
public static final class drawable {
public static final int icon=0x7f020000;
public static final int pasusenormal=0x7f020001;
public static final int pause_button=0x7f020002;
public static final int pausedisabled=0x7f020003;
public static final int pausehot=0x7f020004;
public static final int pausenormalred=0x7f020005;
public static final int pausepressed=0x7f020006;
public static final int play_button=0x7f020007;
public static final int playdisabled=0x7f020008;
public static final int playhot=0x7f020009;
public static final int playnormal=0x7f02000a;
public static final int playpressed=0x7f02000b;
}
public static final class id {
public static final int ad=0x7f080004;
public static final int play_pause_button=0x7f080001;
public static final int time_left=0x7f080002;
public static final int track_title=0x7f080000;
public static final int volume=0x7f080003;
}
public static final class layout {
public static final int main=0x7f030000;
public static final int main_lite=0x7f030001;
}
public static final class raw {
public static final int beach=0x7f050000;
public static final int crickets=0x7f050001;
public static final int falls=0x7f050002;
public static final int river=0x7f050003;
public static final int wn=0x7f050004;
}
public static final class string {
public static final int app_name=0x7f070000;
public static final int app_name_lite=0x7f070001;
}
public static final class xml {
public static final int settings=0x7f040000;
public static final int settings_lite=0x7f040001;
}
public static final class styleable {
/** Attributes that can be used with a com_admob_android_ads_AdView.
<p>Includes the following attributes:</p>
<table>
<colgroup align="left" />
<colgroup align="left" />
<tr><th>Attribute</th><th>Description</th></tr>
<tr><td><code>{@link #com_admob_android_ads_AdView_backgroundColor com.TwentyCodes.android.SweetDreamsFull:backgroundColor}</code></td><td></td></tr>
<tr><td><code>{@link #com_admob_android_ads_AdView_keywords com.TwentyCodes.android.SweetDreamsFull:keywords}</code></td><td></td></tr>
<tr><td><code>{@link #com_admob_android_ads_AdView_primaryTextColor com.TwentyCodes.android.SweetDreamsFull:primaryTextColor}</code></td><td></td></tr>
<tr><td><code>{@link #com_admob_android_ads_AdView_refreshInterval com.TwentyCodes.android.SweetDreamsFull:refreshInterval}</code></td><td></td></tr>
<tr><td><code>{@link #com_admob_android_ads_AdView_secondaryTextColor com.TwentyCodes.android.SweetDreamsFull:secondaryTextColor}</code></td><td></td></tr>
</table>
@see #com_admob_android_ads_AdView_backgroundColor
@see #com_admob_android_ads_AdView_keywords
@see #com_admob_android_ads_AdView_primaryTextColor
@see #com_admob_android_ads_AdView_refreshInterval
@see #com_admob_android_ads_AdView_secondaryTextColor
*/
public static final int[] com_admob_android_ads_AdView = {
0x7f010000, 0x7f010001, 0x7f010002, 0x7f010003,
0x7f010004
};
/**
<p>This symbol is the offset where the {@link com.TwentyCodes.android.SweetDreamsFull.R.attr#backgroundColor}
attribute's value can be found in the {@link #com_admob_android_ads_AdView} array.
<p>Must be a color value, in the form of "<code>#<i>rgb</i></code>", "<code>#<i>argb</i></code>",
"<code>#<i>rrggbb</i></code>", or "<code>#<i>aarrggbb</i></code>".
<p>This may also be a reference to a resource (in the form
"<code>@[<i>package</i>:]<i>type</i>:<i>name</i></code>") or
theme attribute (in the form
"<code>?[<i>package</i>:][<i>type</i>:]<i>name</i></code>")
containing a value of this type.
@attr name android:backgroundColor
*/
public static final int com_admob_android_ads_AdView_backgroundColor = 0;
/**
<p>This symbol is the offset where the {@link com.TwentyCodes.android.SweetDreamsFull.R.attr#keywords}
attribute's value can be found in the {@link #com_admob_android_ads_AdView} array.
<p>Must be a string value, using '\\;' to escape characters such as '\\n' or '\\uxxxx' for a unicode character.
<p>This may also be a reference to a resource (in the form
"<code>@[<i>package</i>:]<i>type</i>:<i>name</i></code>") or
theme attribute (in the form
"<code>?[<i>package</i>:][<i>type</i>:]<i>name</i></code>")
containing a value of this type.
@attr name android:keywords
*/
public static final int com_admob_android_ads_AdView_keywords = 3;
/**
<p>This symbol is the offset where the {@link com.TwentyCodes.android.SweetDreamsFull.R.attr#primaryTextColor}
attribute's value can be found in the {@link #com_admob_android_ads_AdView} array.
<p>Must be a color value, in the form of "<code>#<i>rgb</i></code>", "<code>#<i>argb</i></code>",
"<code>#<i>rrggbb</i></code>", or "<code>#<i>aarrggbb</i></code>".
<p>This may also be a reference to a resource (in the form
"<code>@[<i>package</i>:]<i>type</i>:<i>name</i></code>") or
theme attribute (in the form
"<code>?[<i>package</i>:][<i>type</i>:]<i>name</i></code>")
containing a value of this type.
@attr name android:primaryTextColor
*/
public static final int com_admob_android_ads_AdView_primaryTextColor = 1;
/**
<p>This symbol is the offset where the {@link com.TwentyCodes.android.SweetDreamsFull.R.attr#refreshInterval}
attribute's value can be found in the {@link #com_admob_android_ads_AdView} array.
<p>Must be an integer value, such as "<code>100</code>".
<p>This may also be a reference to a resource (in the form
"<code>@[<i>package</i>:]<i>type</i>:<i>name</i></code>") or
theme attribute (in the form
"<code>?[<i>package</i>:][<i>type</i>:]<i>name</i></code>")
containing a value of this type.
@attr name android:refreshInterval
*/
public static final int com_admob_android_ads_AdView_refreshInterval = 4;
/**
<p>This symbol is the offset where the {@link com.TwentyCodes.android.SweetDreamsFull.R.attr#secondaryTextColor}
attribute's value can be found in the {@link #com_admob_android_ads_AdView} array.
<p>Must be a color value, in the form of "<code>#<i>rgb</i></code>", "<code>#<i>argb</i></code>",
"<code>#<i>rrggbb</i></code>", or "<code>#<i>aarrggbb</i></code>".
<p>This may also be a reference to a resource (in the form
"<code>@[<i>package</i>:]<i>type</i>:<i>name</i></code>") or
theme attribute (in the form
"<code>?[<i>package</i>:][<i>type</i>:]<i>name</i></code>")
containing a value of this type.
@attr name android:secondaryTextColor
*/
public static final int com_admob_android_ads_AdView_secondaryTextColor = 2;
};
}

View File

@@ -8,13 +8,13 @@ package com.TwentyCodes.android.SweetDreamsFull;
import android.os.Bundle;
import com.TwentyCodes.android.SweetDreamsLib.SweetDreamsFull;
import com.TwentyCodes.android.SweetDreamsLib.SweetDreamsMain;
/**
* Main activity
* @author ricky barrette
*/
public class SweetDreams extends SweetDreamsFull {
public class SweetDreams extends SweetDreamsMain {
/**
* Called when the activity is first created.

View File

@@ -4,5 +4,6 @@
<classpathentry kind="src" path="gen"/>
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="lib" path="libs/admob-sdk-android.jar"/>
<classpathentry kind="src" path="ExceptionHandlerLib_src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -30,4 +30,11 @@
<nature>com.android.ide.eclipse.adt.AndroidNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<linkedResources>
<link>
<name>ExceptionHandlerLib_src</name>
<type>2</type>
<locationURI>_android_ExceptionHandlerLib_7d68b46a/src</locationURI>
</link>
</linkedResources>
</projectDescription>

View File

@@ -3,7 +3,7 @@
android:installLocation="auto" android:versionCode="5" android:versionName="0.0.5" package="com.TwentyCodes.android.SweetDreamsLib">
<application android:label="@string/app_name" android:icon="@drawable/playdisabled">
<activity android:name="SweetDreamsFull"
<activity android:name="SweetDreamsMain"
android:label="@string/app_name"
android:screenOrientation="portrait">
<intent-filter>

View File

@@ -0,0 +1,8 @@
fixes #172
added a check in SweetDreamsMain to see if the timer is <= to 0. if so close application. This resulted in the application
closing if the exit on finish was selected because the timer is always 0 or less than if it isn't running.
modified line in Service for when timer is decreased to stop at 0.
in short. the issue was being that the timer only had two states. it was either -1 or above zero. if the timer was -1 it represented both the timer was complete
and that a timer never existed. thus the application would not close. modified the timer to be at 0 if the timer never existed and -1 if finished. above zero
represents still in play

View File

@@ -10,3 +10,4 @@
# Project target.
target=android-9
android.library=true
android.library.reference.1=../ExceptionHandlerLib

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.7 KiB

After

Width:  |  Height:  |  Size: 3.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.5 KiB

After

Width:  |  Height:  |  Size: 4.7 KiB

View File

@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="com.TwentyCodes.android.SweetSoundsLite"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
>
<TextView
android:id="@+id/track_title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="20dip"
/>
<ImageButton
android:layout_marginTop="5dip"
android:layout_below="@id/track_title"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/play_pause_button"
android:background="@drawable/play_button"
/>
<TextView
android:id="@+id/time_left"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="@id/track_title"
android:layout_marginLeft="5dip"
android:layout_centerHorizontal="true"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="20dip"
/>
<SeekBar
android:max="100"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginRight="20dip"
android:layout_marginLeft="20dip"
android:id="@+id/volume"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/volume"
android:layout_centerHorizontal="true"
android:text="Volume"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="20dip"
/>
</RelativeLayout>

View File

@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:myapp="com.TwentyCodes.android.SweetSoundsLite"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
>
<TextView
android:id="@+id/track_title"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="20dip"
/>
<ImageButton
android:layout_marginTop="5dip"
android:layout_below="@id/track_title"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/play_pause_button"
android:background="@drawable/play_button"
/>
<TextView
android:id="@+id/time_left"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="@id/track_title"
android:layout_marginLeft="5dip"
android:layout_centerHorizontal="true"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="20dip"
/>
<com.admob.android.ads.AdView
android:id="@+id/ad"
android:layout_alignParentBottom="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
myapp:backgroundColor="#000000"
myapp:primaryTextColor="#FFFFFF"
myapp:secondaryTextColor="#CCCCCC"/>
<SeekBar
android:max="100"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="@id/ad"
android:layout_marginRight="20dip"
android:layout_marginLeft="20dip"
android:id="@+id/volume"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@id/volume"
android:layout_centerHorizontal="true"
android:text="Volume"
android:textColor="#000000"
android:textStyle="bold"
android:textSize="20dip"
/>
</RelativeLayout>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -5,6 +5,6 @@
<item>Beach</item>
<item>Crickets</item>
<item>Water Falls</item>
<item>Air Conditioner</item>
<item>White Noise</item>
</string-array>
</resources>

View File

@@ -0,0 +1,20 @@
/**
* Playback.aidl
* @date Feb 19, 2011
* @author ricky barrette
* @author Twenty Codes, LLC
*/
package com.TwentyCodes.android.SweetDreamsLib;
interface Playback {
void play(int resId);
void stop();
boolean isPlaying();
long getTimeRemaining();
}

View File

@@ -0,0 +1,176 @@
/**
* PlaybackService.java
* @date Feb 19, 2011
* @author ricky barrette
* @author Twenty Codes, LLC
*/
package com.TwentyCodes.android.SweetDreamsLib;
import android.app.Service;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.media.MediaPlayer;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
import android.util.Log;
import com.TwentyCodes.android.SweetDreamsLib.Playback.Stub;
/**
* This service will handle sound track play back to allow for seem-less play back while configuration changes happen
* @author ricky barrette
*/
public class PlaybackService extends Service implements Runnable{
private MediaPlayer mMediaPlayer;
private long mTimeRemaining = 0;
private Handler mHandler;
private final Stub mPlayback = new Playback.Stub(){
/**
* a convince method used to get the amount of time left
* (non-Javadoc)
* @see com.TwentyCodes.android.SweetDreamsLib.Playback#getTimeRemaining()
* @author ricky barrette
*/
@Override
public long getTimeRemaining() throws RemoteException {
return mTimeRemaining;
}
/**
* returns whether or not the media player is playing
* (non-Javadoc)
* @see com.TwentyCodes.android.SweetDreamsLib.Playback#isPlaying()
* @author ricky barrette
*/
@Override
public boolean isPlaying() throws RemoteException {
if(mMediaPlayer != null)
return mMediaPlayer.isPlaying();
else
return false;
}
/**
* plays the specified sound track, infinitely looping it
* (non-Javadoc)
* @see com.TwentyCodes.android.SweetDreamsLib.Playback#play(int)
* @author ricky barrette
*/
@Override
public void play(int resId) throws RemoteException {
stop();
mMediaPlayer = MediaPlayer.create(PlaybackService.this, resId);
mMediaPlayer.setLooping(true);
mMediaPlayer.start();
SharedPreferences settings = PlaybackService.this.getSharedPreferences(Settings.SETTINGS, Context.MODE_PRIVATE);
boolean timerEnabled = settings.getBoolean(Settings.TIMER_ENABLED, false);
if(SweetDreamsMain.isFUll == false)
timerEnabled = true;
if (timerEnabled){
mTimeRemaining = (settings.getInt("timer_length", 30) * 60000);
//start the timer
mHandler.postDelayed(PlaybackService.this, 1000l);
}
}
/**
* Stops the play back of the sound track
* (non-Javadoc)
* @see com.TwentyCodes.android.SweetDreamsLib.Playback#stop()
* @author ricky barrette
*/
@Override
public void stop() throws RemoteException {
try {
mMediaPlayer.stop();
} catch (Exception e) {
e.printStackTrace();
}
mHandler.removeCallbacks(PlaybackService.this);
}
};
/**
* (non-Javadoc)
* @see android.app.Service#onBind(android.content.Intent)
* @author ricky barrette
*/
@Override
public IBinder onBind(Intent intent) {
return mPlayback;
}
@Override
public void onCreate(){
Log.v(SweetDreamsMain.TAG, "PlaybackService.onCreate()");
super.onCreate();
mHandler = new Handler();
}
/**
* Called when the service is about to be destroyed.
* Here we release the media player
* (non-Javadoc)
* @see android.app.Service#onDestroy()
* @author ricky barrette
*/
@Override
public void onDestroy(){
Log.v(SweetDreamsMain.TAG, "PlaybackService.onDestroy()");
try {
mMediaPlayer.stop();
} catch (Exception e) {
e.printStackTrace();
}
try {
mMediaPlayer.release();
} catch (Exception e) {
e.printStackTrace();
}
mHandler.removeCallbacks(this);
mTimeRemaining = 0;
super.onDestroy();
}
@Override
public void run() {
Log.v(SweetDreamsMain.TAG, "Tick");
//stop the timer if there is nothing playing
if(mMediaPlayer != null) {
if(! mMediaPlayer.isPlaying())
mHandler.removeCallbacks(this);
}
else
mHandler.removeCallbacks(this);
mTimeRemaining = mTimeRemaining - 1000l;
if(mTimeRemaining <= 0) {
try {
mTimeRemaining = -1;
mPlayback.stop();
} catch (RemoteException e) {
e.printStackTrace();
}
this.stopSelf();
}
//que the next tick
mHandler.postDelayed(this, 1000l);
}
}

View File

@@ -1,215 +0,0 @@
/**
* @author Twenty Codes
* @author ricky barrette
*/
package com.TwentyCodes.android.SweetDreamsLib;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.Thread.UncaughtExceptionHandler;
import java.lang.reflect.Field;
import java.text.SimpleDateFormat;
import java.util.Date;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.os.Build;
/**
* dont forget the manifest tag
* <uses-permission android:name="android.permission.READ_LOGS" />
* @author ricky
*/
public class PostMortemReportExceptionHandler implements UncaughtExceptionHandler, Runnable {
public static final String ExceptionReportFilename = "postmortem.trace";
private static final String MSG_SUBJECT_TAG = "Exception Report"; //"app title + this tag" = email subject
private static final String MSG_SENDTO = "twentycodes@gmail.com"; //email will be sent to this account
//the following may be something you wish to consider localizing
private static final String MSG_BODY = "Just click send to help make this application better. "+
"No personal information is being sent (you can check by reading the rest of the email).";
private Thread.UncaughtExceptionHandler mDefaultUEH;
private Activity mApp = null;
public PostMortemReportExceptionHandler(Activity aApp) {
mDefaultUEH = Thread.getDefaultUncaughtExceptionHandler();
mApp = aApp;
}
public void uncaughtException(Thread t, Throwable e) {
submit(e);
//do not forget to pass this exception through up the chain
mDefaultUEH.uncaughtException(t,e);
}
public String getDebugReport(Throwable aException) {
// NumberFormat theFormatter = new DecimalFormat("#0.");
//stack trace
StackTraceElement[] theStackTrace = aException.getStackTrace();
StringBuffer report = new StringBuffer();
report.append("--------- Application ---------\n\n");
report.append(mApp.getPackageName()+" generated the following exception:\n\n");
report.append(aException.toString() + "\n\n");
report.append("-------------------------------\n\n");
report.append("--------- Stack trace ---------\n\n");
for (int i = 0; i < theStackTrace.length; i++) {
report.append(" " + theStackTrace[i].toString() + "\n");
}
report.append("-------------------------------\n\n");
//app environment
PackageManager pm = mApp.getPackageManager();
PackageInfo pi;
try {
pi = pm.getPackageInfo(mApp.getPackageName(), 0);
} catch (NameNotFoundException eNnf) {
//doubt this will ever run since we want info about our own package
pi = new PackageInfo();
pi.versionName = "unknown";
pi.versionCode = 69;
}
Date theDate = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy.MM.dd_HH.mm.ss_zzz");
report.append("-------- Environment --------\n");
report.append("Time\t="+sdf.format(theDate)+"\n");
report.append("Device\t="+Build.FINGERPRINT+"\n");
try {
Field theMfrField = Build.class.getField("MANUFACTURER");
report.append("Make\t="+theMfrField.get(null)+"\n");
} catch (SecurityException e) {
} catch (NoSuchFieldException e) {
} catch (IllegalArgumentException e) {
} catch (IllegalAccessException e) {
}
report.append("Device: " + Build.DEVICE + "\n");
report.append("Brand: " + Build.BRAND + "\n");
report.append("Model: "+Build.MODEL+"\n");
report.append("Product: "+Build.PRODUCT+"\n");
report.append("App:\t "+mApp.getPackageName()+", version "+pi.versionName+" (build "+pi.versionCode+")\n");
report.append("Locale: "+mApp.getResources().getConfiguration().locale.getDisplayName()+"\n");
report.append("-----------------------------\n\n");
report.append("--------- Firmware ---------\n\n");
report.append("SDK: " + Build.VERSION.SDK + "\n");
report.append("Release: " + Build.VERSION.RELEASE + "\n");
report.append("Incremental: " + Build.VERSION.INCREMENTAL + "\n");
report.append("Build Id: " + Build.ID + "\n");
report.append("-------------------------------\n\n");
// If the exception was thrown in a background thread inside
// AsyncTask, then the actual exception can be found with getCause
report.append("--------- Cause ---------\n\n");
Throwable cause = aException.getCause();
if (cause != null) {
report.append(cause.toString() + "\n\n");
theStackTrace = cause.getStackTrace();
for (int i = 0; i < theStackTrace.length; i++) {
report.append(" " + theStackTrace[i].toString() + "\n");
}
}
report.append("-------------------------------\n\n");
report.append("--------- Complete Logcat ---------\n\n");
report.append(getLog().toString());
report.append("-------------------------------\n\n");
report.append("END REPORT");
return report.toString();
}
protected void saveDebugReport(String aReport) {
//save report to file
try {
FileOutputStream theFile = mApp.openFileOutput(ExceptionReportFilename, Context.MODE_PRIVATE);
theFile.write(aReport.getBytes());
theFile.close();
} catch(IOException ioe) {
//error during error report needs to be ignored, do not wish to start infinite loop
}
}
public void sendDebugReportToAuthor() {
String theLine = "";
StringBuffer theTrace = new StringBuffer();
try {
BufferedReader theReader = new BufferedReader(
new InputStreamReader(mApp.openFileInput(ExceptionReportFilename)));
while ((theLine = theReader.readLine())!=null) {
theTrace.append(theLine+"\n");
}
if (sendDebugReportToAuthor(theTrace.toString())) {
mApp.deleteFile(ExceptionReportFilename);
}
} catch (FileNotFoundException eFnf) {
// nothing to do
} catch(IOException eIo) {
// not going to report
}
}
public Boolean sendDebugReportToAuthor(String aReport) {
if (aReport!=null) {
Intent theIntent = new Intent(Intent.ACTION_SEND);
String theSubject = mApp.getTitle()+" "+MSG_SUBJECT_TAG;
String theBody = "\n"+MSG_BODY+"\n\n"+aReport+"\n\n";
theIntent.putExtra(Intent.EXTRA_EMAIL,new String[] {MSG_SENDTO});
theIntent.putExtra(Intent.EXTRA_TEXT, theBody);
theIntent.putExtra(Intent.EXTRA_SUBJECT, theSubject);
theIntent.setType("message/rfc822");
Boolean hasSendRecipients = (mApp.getPackageManager().queryIntentActivities(theIntent,0).size()>0);
if (hasSendRecipients) {
mApp.startActivity(theIntent);
return true;
} else {
return false;
}
} else {
return true;
}
}
public void run() {
sendDebugReportToAuthor();
}
public void submit(Throwable e) {
String theErrReport = getDebugReport(e);
saveDebugReport(theErrReport);
//try to send file contents via email (need to do so via the UI thread)
mApp.runOnUiThread(this);
}
protected StringBuilder getLog(){
final StringBuilder log = new StringBuilder();
try{
Process process = Runtime.getRuntime().exec("logcat -d");
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
while ((line = bufferedReader.readLine()) != null){
log.append(line);
log.append("\n");
}
}
catch (IOException e){
}
return log;
}
}

View File

@@ -26,7 +26,7 @@ public class Settings extends PreferenceActivity implements OnPreferenceChangeLi
protected static final String SOUND_BEACH = "Beach";
protected static final String SOUND_CRICKETS = "Crickets";
protected static final String SOUND_FALLS = "Water Falls";
protected static final String SOUND_AC = "Air Conditioner";
protected static final String SOUND_WN = "White Noise";
//the following strings are for saving volume level from the audiomanager.STREAM_MUSIC so we can restore them back when the app quits
protected static final String MUSIC_VOLUME = "music_volume";
@@ -47,7 +47,7 @@ public class Settings extends PreferenceActivity implements OnPreferenceChangeLi
getPreferenceManager().setSharedPreferencesName(SETTINGS);
//load preferences xml
this.addPreferencesFromResource( SweetDreamsFull.isFUll ? R.xml.settings : R.xml.settings_lite);
this.addPreferencesFromResource( SweetDreamsMain.isFUll ? R.xml.settings : R.xml.settings_lite);
//get shared_prefs
SharedPreferences settings = getPreferenceManager().getSharedPreferences();
@@ -69,7 +69,7 @@ public class Settings extends PreferenceActivity implements OnPreferenceChangeLi
Preference timerLength = findPreference(TIMER_LENGTH);
timerLength.setOnPreferenceChangeListener(this);
try {
if(SweetDreamsFull.isFUll)
if(SweetDreamsMain.isFUll)
timerLength.setSummary(settings.getInt(TIMER_LENGTH, 5));
else
timerLength.setSummary(30);

View File

@@ -5,14 +5,19 @@
package com.TwentyCodes.android.SweetDreamsLib;
import android.app.Activity;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.os.Bundle;
import android.os.CountDownTimer;
import android.os.Handler;
import android.os.IBinder;
import android.os.RemoteException;
import android.telephony.PhoneStateListener;
import android.telephony.TelephonyManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
@@ -23,25 +28,65 @@ import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import com.TwentyCodes.android.exception.ExceptionHandler;
/**
* this class is responsible for setting up the ui and handling ui events
* @author ricky
*/
public class SweetDreamsFull extends Activity implements OnClickListener, OnSeekBarChangeListener{
public class SweetDreamsMain extends Activity implements OnClickListener, OnSeekBarChangeListener, ServiceConnection, Runnable {
private boolean isPlaying;
private ImageButton mPlayPauseButton;
private AudioManager mAudioManager;
private final int STREAM = AudioManager.STREAM_MUSIC;
protected static MediaPlayer mMediaPlayer;
private PostMortemReportExceptionHandler mDamageReport;
private ExceptionHandler mDamageReport;
private final int SETTINGS = Menu.FIRST;
private final int QUIT = Menu.FIRST +1;
private SharedPreferences mSettings;
protected static final String TAG = "WhiteNoise";
private Timer mTimer;
protected static final String TAG = "SweetDreams";
private Playback mService;
private Handler mHandler;
private SeekBar mVolume;
protected static TextView mTimeLeftTextView;
protected static boolean isFUll = true;
protected static final boolean DEBUG = true;
protected boolean inCall;
/**
* Call back class for PhoneStateListener to be used
* @author ricky barrette
*/
private class MyPhoneStateListener extends PhoneStateListener {
@Override
public void onCallStateChanged(int state,String incomingNumber){
Log.e(TAG, "PhoneCallStateNotified.Incoming");
switch(state){
case TelephonyManager.CALL_STATE_RINGING:
if(isPlaying){
inCall = true;
stopPlaying();
}
break;
case TelephonyManager.CALL_STATE_IDLE:
if(inCall){
inCall = false;
try {
loadSound();
} catch (RemoteException e) {
e.printStackTrace();
}
}
break;
case TelephonyManager.CALL_STATE_OFFHOOK:
if(isPlaying){
inCall = true;
stopPlaying();
}
break;
}
}
}
/**
* adjusts the provided Stream volume to the provided level
@@ -50,7 +95,6 @@ public class SweetDreamsFull extends Activity implements OnClickListener, OnSeek
* @author ricky barrette
*/
private void adjustVolume(int stream, int level) {
/*
* if the seek bar is set to a value that is higher than what the the stream value is set for
* then subtract the seek bar's value from the current volume of the stream, and then
@@ -77,42 +121,38 @@ public class SweetDreamsFull extends Activity implements OnClickListener, OnSeek
}
/**
* loads the sound from shared_prefs that the user wants, and set the mediaplayer to loop
* loads the sound from shared_prefs that the user wants, and starts the playback service
* loads river sound track by default.
*
* @author ricky barrette
* @throws RemoteException
*/
private void loadSound(){
private void loadSound() throws RemoteException{
if (DEBUG)
Log.i(TAG,"loadSound()");
try {
mMediaPlayer.reset();
} catch (Exception e) {
e.printStackTrace();
}
mPlayPauseButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.pause_button));
isPlaying = true;
String sound = mSettings.getString("sounds", Settings.SOUND_RIVER);
if (DEBUG)
Log.v(TAG,"sound = "+ sound);
if (sound != null){
if (sound.equals(Settings.SOUND_BEACH)){
mMediaPlayer = MediaPlayer.create(this, R.raw.beach);
mMediaPlayer.setLooping(true);
}
if (sound.equals(Settings.SOUND_AC)){
mMediaPlayer = MediaPlayer.create(this, R.raw.ac);
mMediaPlayer.setLooping(true);
}
if (sound.equals(Settings.SOUND_CRICKETS)){
mMediaPlayer = MediaPlayer.create(this, R.raw.crickets);
mMediaPlayer.setLooping(true);
}
if (sound.equals(Settings.SOUND_FALLS)){
mMediaPlayer = MediaPlayer.create(this, R.raw.falls);
mMediaPlayer.setLooping(true);
}
if (sound.equals(Settings.SOUND_RIVER)){
mMediaPlayer = MediaPlayer.create(this, R.raw.river);
mMediaPlayer.setLooping(true);
if (mService != null) {
if (sound.equals(Settings.SOUND_BEACH))
mService.play(R.raw.beach);
if (sound.equals(Settings.SOUND_WN))
mService.play(R.raw.wn);
if (sound.equals(Settings.SOUND_CRICKETS))
mService.play(R.raw.crickets);
if (sound.equals(Settings.SOUND_FALLS))
mService.play(R.raw.falls);
if (sound.equals(Settings.SOUND_RIVER))
mService.play(R.raw.river);
}
}
}
/**
@@ -121,6 +161,8 @@ public class SweetDreamsFull extends Activity implements OnClickListener, OnSeek
*/
@Override
public void onClick(View v) {
if (DEBUG)
Log.i(TAG, "onClick()");
/*
* if the sound track is no playing then
* change the button background from a play symbol to a pause symbol, set isPlaying to true, load the user preferred sound track, and play it
@@ -128,23 +170,15 @@ public class SweetDreamsFull extends Activity implements OnClickListener, OnSeek
* change the button background from a pause symbol to a play symbol, set isPlaying to false, and stop playing the sound track
*/
if (!isPlaying){
mPlayPauseButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.pause_button));
isPlaying = true;
try {
loadSound();
mMediaPlayer.start();
boolean timerEnabled = mSettings.getBoolean(Settings.TIMER_ENABLED, false);
if(isFUll == false)
timerEnabled = true;
if (timerEnabled){
Log.v(TAG,"Starting timer");
long time = + (mSettings.getInt("timer_length", 30) * 60000);
Log.v(TAG,"time = " + time);
mTimer = new Timer(time);
mTimer.start();
} catch (RemoteException e) {
e.printStackTrace();
}
//if the timer is enabled, then start the ui updating handler
if(mSettings.getBoolean(Settings.TIMER_ENABLED, false) || ! isFUll)
mHandler.post(this);
} else {
stopPlaying();
}
@@ -160,11 +194,11 @@ public class SweetDreamsFull extends Activity implements OnClickListener, OnSeek
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
if (DEBUG)
Log.i(TAG,"onCreate()");
// setup crash report handler
mDamageReport = new PostMortemReportExceptionHandler(this);
mDamageReport = new ExceptionHandler(this);
mDamageReport.run();
Thread.setDefaultUncaughtExceptionHandler(mDamageReport);
@@ -176,17 +210,24 @@ public class SweetDreamsFull extends Activity implements OnClickListener, OnSeek
mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
//initialize the volume seekbar and set
SeekBar sbVolume = (SeekBar) findViewById(R.id.volume);
sbVolume.setOnSeekBarChangeListener(this);
sbVolume.setMax(mAudioManager.getStreamMaxVolume(STREAM));
sbVolume.setProgress(mAudioManager.getStreamVolume(STREAM));
mVolume = (SeekBar) findViewById(R.id.volume);
mVolume.setOnSeekBarChangeListener(this);
mVolume.setMax(mAudioManager.getStreamMaxVolume(STREAM));
mVolume.setProgress(mAudioManager.getStreamVolume(STREAM));
mTimeLeftTextView = (TextView) findViewById(R.id.time_left);
//load shared_prefs
mSettings = getSharedPreferences(Settings.SETTINGS, 0);
loadSound();
startService(new Intent(this, PlaybackService.class));
mHandler = new Handler();
saveStreamVolume(STREAM);
TelephonyManager telephonyManager = (TelephonyManager)getSystemService(TELEPHONY_SERVICE);
telephonyManager.listen(new MyPhoneStateListener(), PhoneStateListener.LISTEN_CALL_STATE);
}
/**
@@ -201,14 +242,22 @@ public class SweetDreamsFull extends Activity implements OnClickListener, OnSeek
}
/**
* here we set the Stream volume back to what ever it was when the activity started
* (non-Javadoc)
* @see android.app.Activity#onDestroy()
* @author ricky barrette
*/
@Override
public void onDestroy(){
adjustVolume(STREAM,mSettings.getInt(Settings.MUSIC_VOLUME, 0));
mHandler.removeCallbacks(this);
if(this.isPlaying && this.isFinishing() && mService != null)
stopPlaying();
this.unbindService(this);
if(this.isFinishing())
this.stopService(new Intent(this, PlaybackService.class));
super.onDestroy();
}
@@ -233,8 +282,18 @@ public class SweetDreamsFull extends Activity implements OnClickListener, OnSeek
return false;
}
/**
* called when the activity is being paused.
* here we cancel the timer if it exists to prevent any funky stuff from happening
* (non-Javadoc)
* @see android.app.Activity#onPause()
* @author ricky barrette
*/
@Override
public void onPause(){
if (DEBUG)
Log.v(TAG, "onPause()");
mHandler.removeCallbacks(this);
super.onPause();
}
@@ -255,11 +314,6 @@ public class SweetDreamsFull extends Activity implements OnClickListener, OnSeek
}
}
@Override
public void onRestart(){
super.onRestart();
}
/**
* we load the track title textview in onResume so it will update every time the activity loads
* (non-Javadoc)
@@ -268,20 +322,19 @@ public class SweetDreamsFull extends Activity implements OnClickListener, OnSeek
*/
@Override
public void onResume(){
if (DEBUG)
Log.v(TAG,"onResume()");
super.onResume();
this.bindService(new Intent(this, PlaybackService.class), this, Context.BIND_AUTO_CREATE);
TextView trackTitle = (TextView) findViewById(R.id.track_title);
trackTitle.setText(mSettings.getString(Settings.SOUNDS,"Rainy River"));
}
@Override
public void onStart(){
super.onStart();
mHandler.post(this);
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
/*
* NOT YET IMPLEMENTED
* NOT IMPLEMENTED
* needed for OnSeekBarChangeListener
*/
}
@@ -294,19 +347,14 @@ public class SweetDreamsFull extends Activity implements OnClickListener, OnSeek
*/
@Override
public void onStop(){
stopPlaying();
try {
mMediaPlayer.release();
} catch (Exception e) {
e.printStackTrace();
}
mHandler.removeCallbacks(this);
super.onStop();
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
/*
* NOT YET IMPLEMENTED
* NOT IMPLEMENTED
* needed for OnSeekBarChangeListener
*/
}
@@ -327,80 +375,58 @@ public class SweetDreamsFull extends Activity implements OnClickListener, OnSeek
* stops music from playing, sets the pay_pause button background to a play symbol, and if the time is enabled, cancels the timer
*
* @author ricky barrette
* @throws RemoteException
*/
private void stopPlaying(){
if (DEBUG)
Log.i(TAG, "stopPlaying()");
mPlayPauseButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.play_button));
isPlaying = false;
try {
mMediaPlayer.stop();
} catch (IllegalStateException e) {
mService.stop();
} catch (RemoteException e) {
e.printStackTrace();
} catch (NullPointerException e){
e.printStackTrace();
Log.e(TAG,"failed to stop media player");
}
if (mTimer != null) {
mTimer.cancel();
mTimer = null;
mHandler.removeCallbacks(this);
mTimeLeftTextView.setText("");
}
}
/**
* this internal class will handle timing functions such as a timer that stops play back of a sound track & updates timeLeft textview every second
* @author ricky barrette
*/
class Timer extends CountDownTimer {
/**
* creates a new count down timer that stops play back of a sound track after specified time, and
* updates timeLeft textview every second
* @param millisInFuture
*/
public Timer(long millisInFuture) {
super(millisInFuture, 1000l);
Log.i(TAG,"Timer()");
Log.v(TAG,"millisInFuture = "+ millisInFuture);
mTimeLeftTextView = (TextView) findViewById(R.id.time_left);
int hours = (int) (millisInFuture / 3600000);
millisInFuture = millisInFuture - (hours * 3600000);
int minutes = (int) ( millisInFuture / 60000);
int seconds = (int) (millisInFuture % 60000);
seconds = seconds / 1000;
mTimeLeftTextView.setText(hours +" : "+ padTime(minutes) +" : "+ padTime(seconds));
}
/**
* stops the sound track being played by the media player
* called when we get our connection to the playback service
* (non-Javadoc)
* @see android.os.CountDownTimer#onFinish()
* @see android.content.ServiceConnection#onServiceConnected(android.content.ComponentName, android.os.IBinder)
* @author ricky barrette
*/
@Override
public void onFinish() {
Log.i(TAG,"onFinish()");
mTimeLeftTextView.setText("");
stopPlaying();
//if the user enables exit on finish, then kill the application
if(mSettings.getBoolean(Settings.TIMER_EXIT_ON_FINISH, false)){
Log.v(TAG,"exit on finish enabled, calling finish()");
finish();
public void onServiceConnected(ComponentName name, IBinder service) {
if (DEBUG)
Log.v(TAG,"onServiceConnected()");
mService = Playback.Stub.asInterface(service);
try {
isPlaying = mService.isPlaying();
} catch (RemoteException e) {
e.printStackTrace();
} catch (NullPointerException e){
e.printStackTrace();
}
if(isPlaying) {
mPlayPauseButton.setBackgroundDrawable(getResources().getDrawable(R.drawable.pause_button));
mHandler.post(this);
}
}
/**
* updates the timeLeft textView to display the current time left till sound stops
* @see android.os.CountDownTimer#onTick(long)
* @param millisUntilFinished
* called when we disconnect from our service
* (non-Javadoc)
* @see android.content.ServiceConnection#onServiceDisconnected(android.content.ComponentName)
* @author ricky barrette
*/
@Override
public void onTick(long millisUntilFinished) {
Log.i(TAG,"onTick()");
int hours = (int) (millisUntilFinished / 3600000);
millisUntilFinished = millisUntilFinished - (hours * 3600000);
int minutes = (int) ( millisUntilFinished / 60000);
int seconds = (int) (millisUntilFinished % 60000);
seconds = seconds / 1000;
mTimeLeftTextView.setText(hours +" : "+ padTime(minutes) +" : "+ padTime(seconds));
public void onServiceDisconnected(ComponentName name) {
mService = null;
}
/**
@@ -415,5 +441,49 @@ public class SweetDreamsFull extends Activity implements OnClickListener, OnSeek
return ""+ seconds;
}
/**
* the run method of this runnable activity that is used to update the ui with the amount of time left
* (non-Javadoc)
* @see java.lang.Runnable#run()
* @author ricky barrette
*/
@Override
public void run() {
boolean isTimerEnabled = mSettings.getBoolean("timer_enabled", false);
//if there is another instance in the que, remove it
mHandler.removeCallbacks(this);
//get the time remaining
long millisUntilFinished = 1;
try {
millisUntilFinished = mService.getTimeRemaining();
} catch (RemoteException e) {
e.printStackTrace();
} catch (NullPointerException e){
e.printStackTrace();
}
//update the UI
if(millisUntilFinished == -1 && isTimerEnabled){
if (DEBUG)
Log.i(TAG, "run().timer is up");
stopPlaying();
} else {
int hours = (int) (millisUntilFinished / 3600000);
millisUntilFinished = millisUntilFinished - (hours * 3600000);
int minutes = (int) ( millisUntilFinished / 60000);
int seconds = (int) (millisUntilFinished % 60000);
seconds = seconds / 1000;
mTimeLeftTextView.setText(hours +" : "+ padTime(minutes) +" : "+ padTime(seconds));
}
//if the time is 0 && if exit on finish is enabled, then exit else just stop playing then finish
if(millisUntilFinished == -1 && isTimerEnabled)
if(mSettings.getBoolean(Settings.TIMER_EXIT_ON_FINISH, false))
this.finish();
//que another ui update
mHandler.postDelayed(this, 1000l);
}
}

View File

@@ -5,5 +5,6 @@
<classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
<classpathentry kind="lib" path="/SweetDreamsLib/libs/admob-sdk-android.jar"/>
<classpathentry kind="src" path="SweetDreamsLib_src"/>
<classpathentry kind="src" path="ExceptionHandlerLib_src"/>
<classpathentry kind="output" path="bin"/>
</classpath>

View File

@@ -31,6 +31,11 @@
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
<linkedResources>
<link>
<name>ExceptionHandlerLib_src</name>
<type>2</type>
<locationURI>_android_ExceptionHandlerLib_7d68b46a/src</locationURI>
</link>
<link>
<name>SweetDreamsLib_src</name>
<type>2</type>

View File

@@ -2,10 +2,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.TwentyCodes.android.SweetDreamsLite"
android:versionCode="1"
android:versionName="1.0">
android:installLocation="auto" android:versionName="1.0.0">
<uses-sdk android:minSdkVersion="3" />
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
<application android:label="@string/app_name_lite" android:icon="@drawable/playdisabled">
<application android:label="@string/app_name_lite" android:icon="@drawable/icon">
<activity android:name=".SweetDreams" android:label="@string/app_name_lite">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
@@ -14,6 +15,7 @@
</activity>
<activity android:name="com.TwentyCodes.android.SweetDreamsLib.Settings"></activity>
<service android:name="com.TwentyCodes.android.SweetDreamsLib.PlaybackService"></service>
<activity android:name="com.admob.android.ads.AdMobActivity"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
@@ -21,6 +23,7 @@
<meta-data android:value="a14d552cbd272f2" android:name="ADMOB_PUBLISHER_ID" />
<service android:name="com.TwentyCodes.android.SweetDreamsLib.PlaybackService"></service>
</application>

Binary file not shown.

Binary file not shown.

View File

@@ -8,14 +8,14 @@ package com.TwentyCodes.android.SweetDreamsLite;
import android.os.Bundle;
import com.TwentyCodes.android.SweetDreamsLib.SweetDreamsFull;
import com.TwentyCodes.android.SweetDreamsLib.SweetDreamsMain;
import com.admob.android.ads.AdManager;
/**
* Main Activity
* @author ricky barrette
*/
public class SweetDreams extends SweetDreamsFull {
public class SweetDreams extends SweetDreamsMain {
/**
* Called when the activity is first created.