Skip to content

Commit

Permalink
Merge branch 'release/0.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
unknownmoon committed Jun 8, 2016
2 parents 09fb478 + 8681c57 commit 51dd955
Show file tree
Hide file tree
Showing 13 changed files with 87 additions and 25 deletions.
36 changes: 31 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Cry for Light

> Note that this project is still in planning stage
> Note that this project is still in pre-stable stage, but it fits my personal demand now, and the main purpose of this little project is to try Android project.
[![GitHub version](https://badge.fury.io/gh/unknownmoon%2Fandroid-cry-for-light.svg)](https://badge.fury.io/gh/unknownmoon%2Fandroid-cry-for-light)

Expand All @@ -9,7 +9,9 @@ A humanitarian APP against sound activated light switches in some scenes.
<!-- MarkdownTOC -->

- [Intention](#intention)
- [Features \(Planing\)](#features-planing)
- [Highlights](#highlights)
- [Downloads](#downloads)
- [Features \(Paused..\)](#features-paused)
- [Feature Level - Core](#feature-level---core)
- [Feature Level - Basic](#feature-level---basic)
- [Feature Level - Enhancement](#feature-level---enhancement)
Expand All @@ -24,13 +26,37 @@ In some scenarios, one may find that the sound activated lights are very annoyin

This app is then used to keep the lights on, by taking advantage of the sensors (mostly the light sensor) of one's Android phone. Once the app detects the luminance is lower than the configured threshold, it will scream, literally, with the configured sound.

<a name="features-planing"></a>
## Features (Planing)
<a name="highlights"></a>
## Highlights

__Warning:__ Only tested against Nexus 5X under Android 6.0.1 (API version 23), in __portrait__ mode.

___ALERT:___ The `settings` screen, namely the home screen, is not happy with the __landscape__ mode for the moment.

- Use notification to `pause`/`resume`/`exit` the service, even the screen is locked. once it's started.
- Functional after screen lock and clean the main screen from the recent task stack (the [Overview Screen](https://developer.android.com/images/components/recents.png)).
- In the main screen, other than `start`/`exit` the service.
+ Display the current brightness in Luminance.
+ Set a brightness threshold to trigger the sound.
+ Set the maximum value of the brightness threshold to change the scale of the brightness threshold slider.
+ Set a sound level.
+ Choose a sound file.

<a name="downloads"></a>
## Downloads

> Too lazy to publish to Android market
Download APK file from [here](https://github.com/unknownmoon/android-cry-for-light/releases/download/v0.3.3/app-debug.apk) and install it.

<a name="features-paused"></a>
## Features (Paused..)

<a name="feature-level---core"></a>
### Feature Level - Core

- [x] When the environment luminance is lower than a configurable threshold, a _trigger sound_ will be played continuously till the environment luminance is back above the threshold.
- [x] When the environment luminance is lower than a configurable threshold, a _trigger sound_ will be played till the environment luminance is back above the threshold.
- [ ] When the environment luminance is lower than a configurable threshold, a _trigger sound_ will be played __continuously__ till the environment luminance is back above the threshold.

<a name="feature-level---basic"></a>
### Feature Level - Basic
Expand Down
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
applicationId "unknownmoon.cryforlight"
minSdkVersion 23
targetSdkVersion 23
versionCode 6
versionName "0.2.4"
versionCode 7
versionName "0.3.0"
}
buildTypes {
release {
Expand Down
72 changes: 54 additions & 18 deletions app/src/main/java/unknownmoon/cryforlight/LightService.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package unknownmoon.cryforlight;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.BroadcastReceiver;
Expand Down Expand Up @@ -31,6 +32,7 @@ public class LightService extends Service {
private final int NOTIFICATION_ID = 1;
protected BroadcastReceiver mMessageReceiver;
protected BroadcastReceiver mActionMessageReceiver;
Notification.Builder mBuilder;
private SensorHandler mSensorHandler;
private Toast mToast = null;
private int mPrefSoundLevel;
Expand Down Expand Up @@ -106,22 +108,6 @@ public int onStartCommand(Intent intent, int flags, int startId) {

mOriginalVol = audioManager.getStreamVolume(AudioManager.STREAM_RING);

Notification.Builder mBuilder = new Notification.Builder(getApplicationContext());

Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

mBuilder.setSmallIcon(R.mipmap.ic_launcher)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setStyle(new Notification.BigTextStyle().bigText("Change service status?"))
.setContentTitle("Cry for Light is on!")
.setContentText("Let's keep the light on!")
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.addAction(new Notification.Action.Builder(loadIcon(R.drawable.ic_service_off), "Pause", getActionIntent(LightActionService.ACTION_PAUSE)).build())
.addAction(new Notification.Action.Builder(loadIcon(R.drawable.ic_service_on), "Resume", getActionIntent(LightActionService.ACTION_RESUME)).build())
.addAction(new Notification.Action.Builder(loadIcon(R.drawable.ic_close), "Exit", getActionIntent(LightActionService.ACTION_EXIT)).build());

SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
Sensor lightSensor = sensorManager.getDefaultSensor(Sensor.TYPE_LIGHT);

Expand All @@ -138,13 +124,57 @@ public int onStartCommand(Intent intent, int flags, int startId) {

syncPrefs();

startForeground(NOTIFICATION_ID, mBuilder.build());
startForeground(NOTIFICATION_ID, updateNotification());

broadcastStarted();

return START_STICKY;
}

private Notification updateNotification() {
if (mBuilder == null) {
mBuilder = new Notification.Builder(getApplicationContext());
}

Intent notificationIntent = new Intent(this, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);

mBuilder.setSmallIcon(loadIcon(R.drawable.ic_logo_white))
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setContentTitle("Cry for Light is on!")
.setContentText("Let's keep the light on!")
.setAutoCancel(true)
.setContentIntent(pendingIntent)
.addAction(new Notification.Action.Builder(loadIcon(R.drawable.ic_service_off), "Pause", getActionIntent(LightActionService.ACTION_PAUSE)).build())
.addAction(new Notification.Action.Builder(loadIcon(R.drawable.ic_service_on), "Resume", getActionIntent(LightActionService.ACTION_RESUME)).build())
.addAction(new Notification.Action.Builder(loadIcon(R.drawable.ic_close), "Exit", getActionIntent(LightActionService.ACTION_EXIT)).build())
.setStyle(constructNotificationStyle());

return mBuilder.build();
}

private void updateNotificationAndNotify() {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, updateNotification());
}

private Notification.BigTextStyle constructNotificationStyle() {

String status = "";
Notification.BigTextStyle style = new Notification.BigTextStyle();

if (mIsPaused) {
status = "paused.";
} else {
status = "watching..";
}

style.bigText("Change service status?")
.setBigContentTitle("Cry for Light is " + status);

return style;
}

private Icon loadIcon(int resId) {
Icon ico = Icon.createWithResource(getPackageName(), resId);
return ico;
Expand Down Expand Up @@ -301,7 +331,7 @@ private void shouldWeCry() {
return;
}

if (mLastBrightness <= mPrefLightThreshold && !mIsCrying) {
if (mLastBrightness <= mPrefLightThreshold && (!mIsCrying || (mRingtone != null && !mRingtone.isPlaying() && mIsCrying))) {

mIsCrying = true;
Log.d(TAG, "I'm crying!!!");
Expand Down Expand Up @@ -336,15 +366,21 @@ private void releaseWakeLock() {

private void pauseService() {
Log.d(TAG, "pause service.");

mIsPaused = true;
releaseWakeLock();

updateNotificationAndNotify();
shouldWeCry();
}

private void resumeService() {
Log.d(TAG, "resume service.");

mIsPaused = false;
acquireWakeLock();

updateNotificationAndNotify();
shouldWeCry();
}

Expand Down
Binary file added app/src/main/res/drawable-hdpi/ic_logo_black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-hdpi/ic_logo_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_logo_black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-mdpi/ic_logo_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_logo_black.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/res/drawable-xhdpi/ic_logo_white.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 51dd955

Please sign in to comment.