diff --git a/README.md b/README.md index da64309..ee81397 100644 --- a/README.md +++ b/README.md @@ -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) @@ -9,7 +9,9 @@ A humanitarian APP against sound activated light switches in some scenes. - [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) @@ -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. - -## Features (Planing) + +## 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. + + +## 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. + + +## Features (Paused..) ### 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. ### Feature Level - Basic diff --git a/app/build.gradle b/app/build.gradle index 44a7797..d36d112 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -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 { diff --git a/app/src/main/java/unknownmoon/cryforlight/LightService.java b/app/src/main/java/unknownmoon/cryforlight/LightService.java index 73aaa50..0bf79a7 100644 --- a/app/src/main/java/unknownmoon/cryforlight/LightService.java +++ b/app/src/main/java/unknownmoon/cryforlight/LightService.java @@ -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; @@ -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; @@ -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); @@ -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; @@ -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!!!"); @@ -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(); } diff --git a/app/src/main/res/drawable-hdpi/ic_logo_black.png b/app/src/main/res/drawable-hdpi/ic_logo_black.png new file mode 100644 index 0000000..7ef4369 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_logo_black.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_logo_white.png b/app/src/main/res/drawable-hdpi/ic_logo_white.png new file mode 100644 index 0000000..89351cb Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_logo_white.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_logo_black.png b/app/src/main/res/drawable-mdpi/ic_logo_black.png new file mode 100644 index 0000000..ea83b62 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_logo_black.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_logo_white.png b/app/src/main/res/drawable-mdpi/ic_logo_white.png new file mode 100644 index 0000000..90a804f Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_logo_white.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_logo_black.png b/app/src/main/res/drawable-xhdpi/ic_logo_black.png new file mode 100644 index 0000000..4ed7be2 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_logo_black.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_logo_white.png b/app/src/main/res/drawable-xhdpi/ic_logo_white.png new file mode 100644 index 0000000..b365f03 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_logo_white.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_logo_black.png b/app/src/main/res/drawable-xxhdpi/ic_logo_black.png new file mode 100644 index 0000000..3f5c0da Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_logo_black.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_logo_white.png b/app/src/main/res/drawable-xxhdpi/ic_logo_white.png new file mode 100644 index 0000000..2d9a5b1 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_logo_white.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_logo_black.png b/app/src/main/res/drawable-xxxhdpi/ic_logo_black.png new file mode 100644 index 0000000..82d29b6 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_logo_black.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_logo_white.png b/app/src/main/res/drawable-xxxhdpi/ic_logo_white.png new file mode 100644 index 0000000..c6d269c Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_logo_white.png differ