Skip to content

Commit

Permalink
* Black screensaver added
Browse files Browse the repository at this point in the history
* Rotate camera feature
  • Loading branch information
thanksmister committed Oct 29, 2018
1 parent 294123e commit 4459dd3
Show file tree
Hide file tree
Showing 11 changed files with 77 additions and 18 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Expand Up @@ -113,7 +113,7 @@ def IMGUR_TAG() {

android {
compileSdkVersion 27
buildToolsVersion '27.0.3'
buildToolsVersion '28.0.2'
defaultConfig {
applicationId "com.thanksmister.iot.mqtt.alarmpanel"
minSdkVersion 26
Expand Down
Expand Up @@ -64,7 +64,7 @@ abstract class BaseActivity : DaggerAppCompatActivity() {
abstract fun getLayoutId(): Int

private val inactivityCallback = Runnable {
showScreenSaver()
showScreenSaver(false)
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down Expand Up @@ -233,19 +233,27 @@ abstract class BaseActivity : DaggerAppCompatActivity() {
* Show the screen saver only if the alarm isn't triggered. This shouldn't be an issue
* with the alarm disabled because the disable time will be longer than this.
*/
open fun showScreenSaver() {
Timber.d("showScreenSaver")
open fun showScreenSaver(manuallySet: Boolean) {
if (!configuration.isAlarmTriggeredMode() && configuration.hasScreenSaver()) {
Timber.d("showScreenSaver")
inactivityHandler.removeCallbacks(inactivityCallback)
val hasWeather = (configuration.showWeatherModule() && readWeatherOptions().isValid)
dialogUtils.showScreenSaver(this@BaseActivity,
configuration.showPhotoScreenSaver(),
readImageOptions(),
getScreenBrightness(),
View.OnClickListener {
dialogUtils.hideScreenSaverDialog()
resetInactivityTimer()
setScreenBrightness()
}, darkSkyDataSource, hasWeather)
} else if (manuallySet) {
Timber.d("showBlackScreenSaver")
dialogUtils.showBlackScreenSaver(this@BaseActivity,
View.OnClickListener {
Timber.d("Black Screen Clicked")
resetInactivityTimer()
setScreenBrightness()
})
}
}

Expand Down
Expand Up @@ -63,8 +63,8 @@ class LogActivity : BaseActivity() {
/**
* We should close this view if we have no more user activity.
*/
override fun showScreenSaver() {
super.showScreenSaver()
override fun showScreenSaver(manuallySet: Boolean) {
super.showScreenSaver(manuallySet)
this.finish()
}

Expand Down
Expand Up @@ -106,7 +106,7 @@ class MainActivity : BaseActivity(), ViewPager.OnPageChangeListener, ControlsFra
readWeatherOptions().setIsCelsius(true)
configuration.isFirstTime = false
configuration.setHasNotifications(true)
configuration.setClockScreenSaverModule(true)
configuration.setClockScreenSaverModule(false)
configuration.setHasCamera(true)
configuration.setWebModule(true)
configuration.setShowWeatherModule(true)
Expand Down Expand Up @@ -356,7 +356,7 @@ class MainActivity : BaseActivity(), ViewPager.OnPageChangeListener, ControlsFra
}

override fun manuallyLaunchScreenSaver() {
showScreenSaver()
showScreenSaver(true)
}

override fun onMotionDetected() {
Expand Down
Expand Up @@ -140,7 +140,7 @@ class SettingsActivity : BaseActivity(), ViewPager.OnPageChangeListener, Setting
/**
* We don't show screen saver on this screen
*/
override fun showScreenSaver() {
override fun showScreenSaver(manuallySet: Boolean) {
//na-da
}

Expand Down
Expand Up @@ -95,7 +95,7 @@ class SupportActivity : BaseActivity() {
/**
* We should close this view if we have no more user activity.
*/
override fun showScreenSaver() {
override fun showScreenSaver(manuallySet: Boolean) {
//na-da
}
companion object {
Expand Down
Expand Up @@ -130,14 +130,23 @@ class CameraSettingsFragment : PreferenceFragmentCompat(), SharedPreferences.OnS
telegramTokenPreference!!.summary = configuration.telegramToken
}

if (!TextUtils.isEmpty(mqttOptions!!.getCameraTopic())) {
mqttImageTopicPreference!!.text = mqttOptions!!.getCameraTopic()
mqttImageTopicPreference!!.summary = mqttOptions!!.getCameraTopic()
if (!TextUtils.isEmpty(mqttOptions.getCameraTopic())) {
mqttImageTopicPreference!!.text = mqttOptions.getCameraTopic()
mqttImageTopicPreference!!.summary = mqttOptions.getCameraTopic()
}

mqttImagePreference!!.isChecked = configuration.mqttImage
rotatePreference!!.setDefaultValue(configuration.getCameraRotate())
rotatePreference!!.value = configuration.getCameraRotate().toString()
if(configuration.getCameraRotate() == 0f) {
rotatePreference!!.setValueIndex(0)
} else if (configuration.getCameraRotate() == -90f) {
rotatePreference!!.setValueIndex(1)
} else if (configuration.getCameraRotate() == 90f) {
rotatePreference!!.setValueIndex(2)
} else if (configuration.getCameraRotate() == 180f) {
rotatePreference!!.setValueIndex(3)
}
}

override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) {
Expand Down
Expand Up @@ -156,7 +156,7 @@ class ScreenSaverView : RelativeLayout {
}
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ item ->
.subscribe { item ->
if (item != null) {
val displayUnits = if (item.units == DarkSkyRequest.UNITS_US) saverContext!!.getString(R.string.text_f) else saverContext!!.getString(R.string.text_c)
try {
Expand Down Expand Up @@ -189,7 +189,7 @@ class ScreenSaverView : RelativeLayout {
Timber.e(e.message)
}
}
})
}
}
}

Expand Down
Expand Up @@ -295,6 +295,21 @@ class DialogUtils(base: Context?) : ContextWrapper(base), LifecycleObserver {
}
}

fun showBlackScreenSaver(activity: AppCompatActivity, onClickListener: View.OnClickListener) {
if (screenSaverDialog != null && screenSaverDialog!!.isShowing) {
return
}
clearDialogs() // clear any alert dialogs
val inflater = activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE) as LayoutInflater
val view = inflater.inflate(R.layout.dialog_screen_saver_black, null, false)
view.setOnClickListener(onClickListener)
screenSaverDialog = buildImmersiveDialog(activity, true, view, true)
if (screenSaverDialog != null){
val lp: WindowManager.LayoutParams = screenSaverDialog!!.window.attributes;
lp.screenBrightness = 0F
screenSaverDialog!!.window.attributes = lp
}
}

// immersive dialogs without navigation
// https://stackoverflow.com/questions/22794049/how-do-i-maintain-the-immersive-mode-in-dialogs
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/res/layout/dialog_screen_saver_black.xml
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="utf-8"?><!--
~ Copyright (c) 2018 ThanksMister LLC
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software distributed
~ under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/screenSaverBlackView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="@color/screen_saver_black">


</FrameLayout>
4 changes: 2 additions & 2 deletions build.gradle
@@ -1,7 +1,7 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.2.41'
ext.kotlin_version = '1.2.60'
repositories {
google()
jcenter()
Expand All @@ -10,7 +10,7 @@ buildscript {
}
}
dependencies {
classpath 'com.android.tools.build:gradle:3.2.0-beta02'
classpath 'com.android.tools.build:gradle:3.2.0-rc02'
classpath 'com.neenbedankt.gradle.plugins:android-apt:1.4'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath 'io.fabric.tools:gradle:1.+'
Expand Down

0 comments on commit 4459dd3

Please sign in to comment.