Skip to content

Commit

Permalink
Add Alarm Activity
Browse files Browse the repository at this point in the history
zariye committed Aug 11, 2015
1 parent cc634c2 commit 4bc92b8
Showing 9 changed files with 106 additions and 7 deletions.
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@
-->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.android.alarm.permission.SET_ALARM"/>

<application
android:allowBackup="true"
@@ -45,6 +44,11 @@
android:enabled="true"
android:exported="false" >
</service>

<activity
android:name=".AlarmActivity"
android:label="@string/title_activity_alarm" >
</activity>
</application>

</manifest>
59 changes: 59 additions & 0 deletions app/src/main/java/zarag/locationbasedalarms/AlarmActivity.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package zarag.locationbasedalarms;

import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.Switch;
import android.widget.TextView;


/**
* Created by zara and javeed on 11.08.2015.
*
* The AlarmActivity is used for the alarm view, we will not use the AlarmClock class, because it is
* activating the alarm by a time instant of a specific event. In out case, the user is close enough
* to his/her destination.
* */
public class AlarmActivity extends Activity {

public static final String WAKE_UP_TEXT = "Wake up you are almost at your destination.";

private TextView wakeUpTxt;

private MediaPlayer mediaPlayer;

private Switch turnOffSwtch;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_alarm);

wakeUpTxt = (TextView)findViewById(R.id.wakeUpTxt);
// TODO maybe add the location-name later
wakeUpTxt.setText(WAKE_UP_TEXT);

mediaPlayer = MediaPlayer.create(getApplicationContext(), R.raw.wakemeup);
mediaPlayer.start();

turnOffSwtch = (Switch)findViewById(R.id.turnOffSwtch);
turnOffSwtch.setChecked(true);

turnOffSwtch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
if (!isChecked) {
mediaPlayer.stop();

startActivity(new Intent(Intent.ACTION_MAIN).
addCategory(Intent.CATEGORY_HOME).
setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
}
}
});
}
}
12 changes: 8 additions & 4 deletions app/src/main/java/zarag/locationbasedalarms/LocationService.java
Original file line number Diff line number Diff line change
@@ -10,7 +10,6 @@
import android.os.Bundle;
import android.os.IBinder;


/**
* Created by zara and javeed on 09.08.2015.
*
@@ -25,11 +24,11 @@ public class LocationService extends Service {
* Important for different travelling choices,
* e.g. by train/ car, bike or foot. */

// 0.5 meters
public static final int DEFAULT_DISTANCE = 500;
// 0.5 km
public static final int DEFAULT_DISTANCE = 10;

// 5 minutes
public static final int DEFAULT_TIME = 5000 * 60;
public static final int DEFAULT_TIME = 1000;//5000 * 60;

// the current location
private Location currentLocation, destination;
@@ -73,6 +72,11 @@ private void callLocationListener() {
@Override
public void onLocationChanged(Location location) {
currentLocation = location;

// if close by destination start the alarm
if(currentLocation.distanceTo(destination) <= 500) {
startActivity(new Intent(getApplicationContext(), AlarmActivity.class));
}
}

@Override
4 changes: 2 additions & 2 deletions app/src/main/java/zarag/locationbasedalarms/MainActivity.java
Original file line number Diff line number Diff line change
@@ -7,7 +7,6 @@
import android.content.ServiceConnection;
import android.os.Bundle;
import android.os.IBinder;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
@@ -50,7 +49,8 @@ public void onClick(View v) {
startApplicationBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO start the application
//startActivity(new Intent(getApplicationContext(), AlarmActivity.class));
// TODO start the application - some how start the alarm
}
});

Binary file added app/src/main/res/drawable/destinationalarm.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions app/src/main/res/layout/activity_alarm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="zarag.locationbasedalarms.AlarmActivity"
android:background="@drawable/destinationalarm">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/wakeUpTxt"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" />

<Switch
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/turnOffSwtch"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:checked="false" />
</RelativeLayout>
7 changes: 7 additions & 0 deletions app/src/main/res/menu/menu_alarm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="zarag.locationbasedalarms.AlarmActivity">
<item android:id="@+id/action_settings" android:title="@string/action_settings"
android:orderInCategory="100" app:showAsAction="never" />
</menu>
Binary file added app/src/main/res/raw/wakemeup.mp3
Binary file not shown.
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -8,4 +8,5 @@
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
<string name="title_activity_maps">Map</string>
<string name="title_activity_alarm">AlarmActivity</string>
</resources>

0 comments on commit 4bc92b8

Please sign in to comment.