Skip to content

Commit

Permalink
Merging settings persistence with main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenfross94 committed Apr 8, 2017
2 parents 07cc085 + 1a1c069 commit f91b002
Show file tree
Hide file tree
Showing 11 changed files with 135 additions and 17 deletions.
2 changes: 1 addition & 1 deletion .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
</intent-filter>
</activity>
<activity android:name=".AlarmActivity" />
<activity android:name=".SettingsActivity" />
<activity android:name=".SettingsActivity"></activity>
<uses-feature android:name="android.hardware.sensor.accelerometer" android:required="true" />
</application>

</manifest>
57 changes: 48 additions & 9 deletions app/src/main/java/barkr/barkr/AlarmActivity.java
Original file line number Diff line number Diff line change
@@ -1,23 +1,68 @@
package barkr.barkr;

import android.content.Context;
import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Button;
import android.widget.Toast;

public class AlarmActivity extends AppCompatActivity {

private final String TAG = this.getClass().getSimpleName();
// The following are used for the shake detection
private SensorManager mSensorManager;
private Sensor mAccelerometer;
private MoveDetector mMoveDetector;

private Button mGiantRedButton;

public void emailNotify () {
Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL , new String[]{"[email protected]"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT , "body of email");
try {
startActivity(Intent.createChooser(i, "Send mail..."));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(AlarmActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
}
}

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

mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
mAccelerometer = mSensorManager
.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);
mMoveDetector = new MoveDetector();
mMoveDetector.setOnMoveListener(new MoveDetector.OnMoveListener() {
@Override
public void onMove(int count) {
Toast.makeText(AlarmActivity.this, "WOWWEE!", Toast.LENGTH_SHORT).show();
Log.d(TAG, "SHAKE SHAKE SHAKE: " + count);
//emailNotify();
}
});
}
@Override
protected void onResume(){
public void onResume() {
super.onResume();
Log.d(TAG, "ON RESUME");
// Add the following line to register the Session Manager Listener onResume
mSensorManager.registerListener(mMoveDetector, mAccelerometer, SensorManager.SENSOR_DELAY_UI);
}

@Override
public void onPause() {
// Add the following line to unregister the Sensor Manager onPause
mSensorManager.unregisterListener(mMoveDetector);
super.onPause();
}

@Override
Expand All @@ -32,12 +77,6 @@ protected void onDestroy(){
Log.d(TAG, "---ON DESTROY---");
}

@Override
protected void onPause(){
super.onPause();
Log.d(TAG, "ON PAUSE");
}

@Override
protected void onStart(){
super.onStart();
Expand Down
66 changes: 66 additions & 0 deletions app/src/main/java/barkr/barkr/MoveDetector.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package barkr.barkr;

import android.content.Intent;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.widget.Toast;

public class MoveDetector implements SensorEventListener {
private static final double MOVE_THRESHOLD_GRAVITY = 1.1;
private static final int MOVE_SLOP_TIME_MS = 500;
private static final int MOVE_COUNT_RESET_TIME_MS = 3000;

private OnMoveListener mListener;
private long mMoveTimestamp;
private int mMoveCount;

public void setOnMoveListener(OnMoveListener listener) {
this.mListener = listener;
}

public interface OnMoveListener {
public void onMove(int count);
}

@Override
public void onAccuracyChanged(Sensor sensor, int accuracy) {
// ignore
}

@Override
public void onSensorChanged(SensorEvent event) {

if (mListener != null) {
double x = event.values[0];
double y = event.values[1];
double z = event.values[2];

double gX = x / SensorManager.GRAVITY_EARTH;
double gY = y / SensorManager.GRAVITY_EARTH;
double gZ = z / SensorManager.GRAVITY_EARTH;

// gForce will be close to 1 when there is no movement.
double gForce = Math.sqrt(gX * gX + gY * gY + gZ * gZ);

if (gForce > MOVE_THRESHOLD_GRAVITY) {
final long now = System.currentTimeMillis();
// ignore movement events too close to each other (500ms)
if (mMoveTimestamp + MOVE_SLOP_TIME_MS > now) {
return;
}

// reset the movement count after 3 seconds of no movement
if (mMoveTimestamp + MOVE_COUNT_RESET_TIME_MS < now) {
mMoveCount = 0;
}

mMoveTimestamp = now;
mMoveCount++;

mListener.onMove(mMoveCount);
}
}
}
}
5 changes: 5 additions & 0 deletions app/src/main/res/drawable/roundbutton.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<solid android:color="#bb0000"/>
</shape>
6 changes: 6 additions & 0 deletions app/src/main/res/layout/activity_alarm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,13 @@
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:background="@color/colorAccent"
>

<Button
android:layout_width="250dp"
android:layout_height="250dp"
android:background="@drawable/roundbutton"/>

</android.support.v7.widget.LinearLayoutCompat>

1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center"
android:background="@color/colorAccent"
>

<ImageView
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>
<color name="colorPrimary">#bb0000</color>
<color name="colorPrimaryDark">#666666</color>
<color name="colorAccent">#ffffff</color>
</resources>
2 changes: 1 addition & 1 deletion app/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<resources>

<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ buildscript {
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.0'
classpath 'com.android.tools.build:gradle:2.3.1'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#Wed Mar 29 12:03:56 EDT 2017
#Sat Apr 08 13:27:04 EDT 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Expand Down

0 comments on commit f91b002

Please sign in to comment.