-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merging settings persistence with main branch
- Loading branch information
Showing
11 changed files
with
135 additions
and
17 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
@@ -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(); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters