diff --git a/CHANGELOG.md b/CHANGELOG.md index 2996e9a..27773c6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,13 @@ Changelog ========== +Version 5.1.1 *(2020-05-25)* +---------------------------- + + * Updated the app icon on lower Android versions + * Added a Bright Display shortcut + * Removed the Camera permission on Android 7+ + Version 5.1.0 *(2020-03-23)* ---------------------------- diff --git a/app/build.gradle b/app/build.gradle index fc880a5..373c188 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,8 +16,8 @@ android { applicationId "com.simplemobiletools.flashlight" minSdkVersion 21 targetSdkVersion 29 - versionCode 39 - versionName "5.1.0" + versionCode 41 + versionName "5.1.1" setProperty("archivesBaseName", "flashlight") } @@ -56,7 +56,7 @@ android { } dependencies { - implementation 'com.simplemobiletools:commons:5.23.8' - implementation 'com.squareup:otto:1.3.8' + implementation 'com.simplemobiletools:commons:5.28.23' + implementation 'org.greenrobot:eventbus:3.2.0' implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta4' } diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro index 027d1b4..e6c5986 100644 --- a/app/proguard-rules.pro +++ b/app/proguard-rules.pro @@ -1,6 +1,6 @@ -# Otto +# EventBus -keepattributes *Annotation* -keepclassmembers class ** { - @com.squareup.otto.Subscribe public *; - @com.squareup.otto.Produce public *; + @org.greenrobot.eventbus.Subscribe ; } +-keep enum org.greenrobot.eventbus.ThreadMode { *; } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e82bee8..9b88821 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -1,20 +1,22 @@ - - - + + + + tools:node="remove" /> + android:required="true" /> - + + android:theme="@style/AppTheme" /> - + + android:label="@string/bright_display" + android:theme="@style/FullScreenTheme" /> + android:parentActivityName=".activities.MainActivity" /> + android:parentActivityName=".activities.MainActivity" /> + android:parentActivityName="com.simplemobiletools.commons.activities.AboutActivity" /> + android:parentActivityName=".activities.SettingsActivity" /> + android:parentActivityName="com.simplemobiletools.commons.activities.AboutActivity" /> - + + android:resource="@xml/widget_info" /> - + @@ -105,8 +108,8 @@ android:targetActivity=".activities.SplashActivity"> - - + + @@ -118,8 +121,8 @@ android:targetActivity=".activities.SplashActivity"> - - + + @@ -131,8 +134,8 @@ android:targetActivity=".activities.SplashActivity"> - - + + @@ -144,8 +147,8 @@ android:targetActivity=".activities.SplashActivity"> - - + + @@ -157,8 +160,8 @@ android:targetActivity=".activities.SplashActivity"> - - + + @@ -170,8 +173,8 @@ android:targetActivity=".activities.SplashActivity"> - - + + @@ -183,8 +186,8 @@ android:targetActivity=".activities.SplashActivity"> - - + + @@ -196,8 +199,8 @@ android:targetActivity=".activities.SplashActivity"> - - + + @@ -209,8 +212,8 @@ android:targetActivity=".activities.SplashActivity"> - - + + @@ -222,8 +225,8 @@ android:targetActivity=".activities.SplashActivity"> - - + + @@ -235,8 +238,8 @@ android:targetActivity=".activities.SplashActivity"> - - + + @@ -248,8 +251,8 @@ android:targetActivity=".activities.SplashActivity"> - - + + @@ -261,8 +264,8 @@ android:targetActivity=".activities.SplashActivity"> - - + + @@ -274,8 +277,8 @@ android:targetActivity=".activities.SplashActivity"> - - + + @@ -286,8 +289,8 @@ android:roundIcon="@mipmap/ic_launcher" android:targetActivity=".activities.SplashActivity"> - - + + @@ -299,8 +302,8 @@ android:targetActivity=".activities.SplashActivity"> - - + + @@ -312,8 +315,8 @@ android:targetActivity=".activities.SplashActivity"> - - + + @@ -325,8 +328,8 @@ android:targetActivity=".activities.SplashActivity"> - - + + @@ -338,8 +341,8 @@ android:targetActivity=".activities.SplashActivity"> - - + + diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/MainActivity.kt index b23de99..39b902d 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/activities/MainActivity.kt @@ -1,27 +1,31 @@ package com.simplemobiletools.flashlight.activities +import android.annotation.SuppressLint import android.content.Intent import android.content.pm.ActivityInfo +import android.content.pm.ShortcutInfo +import android.graphics.drawable.Icon +import android.graphics.drawable.LayerDrawable import android.os.Bundle import android.view.Menu import android.view.MenuItem import android.view.WindowManager import android.widget.ImageView -import android.widget.SeekBar import com.simplemobiletools.commons.extensions.* -import com.simplemobiletools.commons.helpers.LICENSE_OTTO +import com.simplemobiletools.commons.helpers.LICENSE_EVENT_BUS import com.simplemobiletools.commons.helpers.PERMISSION_CAMERA +import com.simplemobiletools.commons.helpers.isNougatMR1Plus import com.simplemobiletools.commons.helpers.isNougatPlus import com.simplemobiletools.commons.models.FAQItem import com.simplemobiletools.flashlight.BuildConfig import com.simplemobiletools.flashlight.R import com.simplemobiletools.flashlight.extensions.config -import com.simplemobiletools.flashlight.helpers.BusProvider import com.simplemobiletools.flashlight.helpers.MyCameraImpl import com.simplemobiletools.flashlight.models.Events -import com.squareup.otto.Bus -import com.squareup.otto.Subscribe import kotlinx.android.synthetic.main.activity_main.* +import org.greenrobot.eventbus.EventBus +import org.greenrobot.eventbus.Subscribe +import java.util.* class MainActivity : SimpleActivity() { private val MAX_STROBO_DELAY = 2000L @@ -29,7 +33,7 @@ class MainActivity : SimpleActivity() { private val FLASHLIGHT_STATE = "flashlight_state" private val STROBOSCOPE_STATE = "stroboscope_state" - private var mBus: Bus? = null + private var mBus: EventBus? = null private var mCameraImpl: MyCameraImpl? = null private var mIsFlashlightOn = false private var reTurnFlashlightOn = true @@ -39,7 +43,7 @@ class MainActivity : SimpleActivity() { setContentView(R.layout.activity_main) appLaunched(BuildConfig.APPLICATION_ID) - mBus = BusProvider.instance + mBus = EventBus.getDefault() changeIconColor(getContrastColor(), stroboscope_btn) bright_display_btn.setOnClickListener { @@ -87,11 +91,14 @@ class MainActivity : SimpleActivity() { requestedOrientation = if (config.forcePortraitMode) ActivityInfo.SCREEN_ORIENTATION_PORTRAIT else ActivityInfo.SCREEN_ORIENTATION_SENSOR invalidateOptionsMenu() - - if(config.turnFlashlightOn && reTurnFlashlightOn){ + + if(config.turnFlashlightOn && reTurnFlashlightOn) { mCameraImpl!!.enableFlashlight() } + reTurnFlashlightOn = true + + checkShortcuts() } override fun onStart() { @@ -157,10 +164,10 @@ class MainActivity : SimpleActivity() { val licenses = LICENSE_OTTO val faqItems = arrayListOf( - FAQItem(R.string.faq_1_title_commons, R.string.faq_1_text_commons), - FAQItem(R.string.faq_4_title_commons, R.string.faq_4_text_commons), - FAQItem(R.string.faq_2_title_commons, R.string.faq_2_text_commons), - FAQItem(R.string.faq_6_title_commons, R.string.faq_6_text_commons) + FAQItem(R.string.faq_1_title_commons, R.string.faq_1_text_commons), + FAQItem(R.string.faq_4_title_commons, R.string.faq_4_text_commons), + FAQItem(R.string.faq_2_title_commons, R.string.faq_2_text_commons), + FAQItem(R.string.faq_6_title_commons, R.string.faq_6_text_commons) ) startAboutActivity(R.string.app_name, licenses, BuildConfig.VERSION_NAME, faqItems, true) @@ -176,22 +183,12 @@ class MainActivity : SimpleActivity() { private fun setupStroboscope() { stroboscope_bar.max = (MAX_STROBO_DELAY - MIN_STROBO_DELAY).toInt() stroboscope_bar.progress = config.stroboscopeProgress - stroboscope_bar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener { - override fun onProgressChanged(seekBar: SeekBar, progress: Int, b: Boolean) { - val frequency = stroboscope_bar.max - progress + MIN_STROBO_DELAY - mCameraImpl?.stroboFrequency = frequency - config.stroboscopeFrequency = frequency - config.stroboscopeProgress = progress - } - - override fun onStartTrackingTouch(seekBar: SeekBar) { - - } - - override fun onStopTrackingTouch(seekBar: SeekBar) { - - } - }) + stroboscope_bar.onSeekBarChangeListener { progress -> + val frequency = stroboscope_bar.max - progress + MIN_STROBO_DELAY + mCameraImpl?.stroboFrequency = frequency + config.stroboscopeFrequency = frequency + config.stroboscopeProgress = progress + } } private fun toggleStroboscope(isSOS: Boolean) { @@ -273,6 +270,37 @@ class MainActivity : SimpleActivity() { imageView!!.background.mutate().applyColorFilter(color) } + @SuppressLint("NewApi") + private fun checkShortcuts() { + val appIconColor = config.appIconColor + if (isNougatMR1Plus() && config.lastHandledShortcutColor != appIconColor) { + val createNewContact = getBrightDisplayShortcut(appIconColor) + + try { + shortcutManager.dynamicShortcuts = Arrays.asList(createNewContact) + config.lastHandledShortcutColor = appIconColor + } catch (ignored: Exception) { + } + } + } + + @SuppressLint("NewApi") + private fun getBrightDisplayShortcut(appIconColor: Int): ShortcutInfo { + val brightDisplay = getString(R.string.bright_display) + val drawable = resources.getDrawable(R.drawable.shortcut_bright_display) + (drawable as LayerDrawable).findDrawableByLayerId(R.id.shortcut_bright_display_background).applyColorFilter(appIconColor) + val bmp = drawable.convertToBitmap() + + val intent = Intent(this, BrightDisplayActivity::class.java) + intent.action = Intent.ACTION_VIEW + return ShortcutInfo.Builder(this, "bright_display") + .setShortLabel(brightDisplay) + .setLongLabel(brightDisplay) + .setIcon(Icon.createWithBitmap(bmp)) + .setIntent(intent) + .build() + } + @Subscribe fun cameraUnavailable(event: Events.CameraUnavailable) { toast(R.string.camera_error) diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/BusProvider.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/BusProvider.kt deleted file mode 100644 index c348c91..0000000 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/BusProvider.kt +++ /dev/null @@ -1,7 +0,0 @@ -package com.simplemobiletools.flashlight.helpers - -import com.squareup.otto.Bus - -object BusProvider { - val instance = Bus() -} diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MarshmallowCamera.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MarshmallowCamera.kt index da6de8d..12d6057 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MarshmallowCamera.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MarshmallowCamera.kt @@ -6,7 +6,7 @@ import android.hardware.camera2.CameraManager import android.os.Build import android.os.Handler import com.simplemobiletools.flashlight.models.Events -import com.squareup.otto.Bus +import org.greenrobot.eventbus.EventBus internal class MarshmallowCamera constructor(val context: Context) { @@ -21,12 +21,12 @@ internal class MarshmallowCamera constructor(val context: Context) { } @TargetApi(Build.VERSION_CODES.M) - fun toggleMarshmallowFlashlight(bus: Bus, enable: Boolean) { + fun toggleMarshmallowFlashlight(enable: Boolean) { try { manager.setTorchMode(cameraId!!, enable) } catch (e: Exception) { val mainRunnable = Runnable { - bus.post(Events.CameraUnavailable()) + EventBus.getDefault().post(Events.CameraUnavailable()) } Handler(context.mainLooper).post(mainRunnable) } diff --git a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyCameraImpl.kt b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyCameraImpl.kt index 124e2e4..655cc04 100644 --- a/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyCameraImpl.kt +++ b/app/src/main/kotlin/com/simplemobiletools/flashlight/helpers/MyCameraImpl.kt @@ -11,7 +11,7 @@ import com.simplemobiletools.flashlight.R import com.simplemobiletools.flashlight.extensions.config import com.simplemobiletools.flashlight.extensions.updateWidgets import com.simplemobiletools.flashlight.models.Events -import com.squareup.otto.Bus +import org.greenrobot.eventbus.EventBus import java.io.IOException class MyCameraImpl(val context: Context) { @@ -23,16 +23,18 @@ class MyCameraImpl(val context: Context) { private var camera: Camera? = null private var params: Camera.Parameters? = null - private var bus: Bus? = null private var isMarshmallow = false private var shouldEnableFlashlight = false private var isStroboSOS = false // are we sending SOS, or casual stroboscope? private var marshmallowCamera: MarshmallowCamera? = null + @Volatile private var shouldStroboscopeStop = false + @Volatile private var isStroboscopeRunning = false + @Volatile private var isSOSRunning = false @@ -41,12 +43,6 @@ class MyCameraImpl(val context: Context) { init { isMarshmallow = isMarshmallowPlus() - - if (bus == null) { - bus = BusProvider.instance - bus!!.register(this) - } - handleCameraSetup() stroboFrequency = context.config.stroboscopeFrequency } @@ -82,7 +78,7 @@ class MyCameraImpl(val context: Context) { fun stopStroboscope() { shouldStroboscopeStop = true - bus!!.post(Events.StopStroboscope()) + EventBus.getDefault().post(Events.StopStroboscope()) } fun toggleSOS(): Boolean { @@ -115,7 +111,7 @@ class MyCameraImpl(val context: Context) { fun stopSOS() { shouldStroboscopeStop = true - bus!!.post(Events.StopSOS()) + EventBus.getDefault().post(Events.StopSOS()) } private fun tryInitCamera(): Boolean { @@ -163,7 +159,7 @@ class MyCameraImpl(val context: Context) { params!!.flashMode = Camera.Parameters.FLASH_MODE_OFF camera!!.parameters = params } catch (e: Exception) { - bus!!.post(Events.CameraUnavailable()) + EventBus.getDefault().post(Events.CameraUnavailable()) } } @@ -223,12 +219,12 @@ class MyCameraImpl(val context: Context) { private fun stateChanged(isEnabled: Boolean) { isFlashlightOn = isEnabled - bus!!.post(Events.StateChanged(isEnabled)) + EventBus.getDefault().post(Events.StateChanged(isEnabled)) context.updateWidgets(isEnabled) } private fun toggleMarshmallowFlashlight(enable: Boolean) { - marshmallowCamera!!.toggleMarshmallowFlashlight(bus!!, enable) + marshmallowCamera!!.toggleMarshmallowFlashlight(enable) } fun releaseCamera() { @@ -239,7 +235,6 @@ class MyCameraImpl(val context: Context) { camera?.release() camera = null - bus?.unregister(this) isFlashlightOn = false shouldStroboscopeStop = true } @@ -260,10 +255,10 @@ class MyCameraImpl(val context: Context) { if (isNougatPlus()) { while (!shouldStroboscopeStop) { try { - marshmallowCamera!!.toggleMarshmallowFlashlight(bus!!, true) + marshmallowCamera!!.toggleMarshmallowFlashlight(true) val onDuration = if (isStroboSOS) SOS[sosIndex++ % SOS.size] else stroboFrequency Thread.sleep(onDuration) - marshmallowCamera!!.toggleMarshmallowFlashlight(bus!!, false) + marshmallowCamera!!.toggleMarshmallowFlashlight(false) val offDuration = if (isStroboSOS) SOS[sosIndex++ % SOS.size] else stroboFrequency Thread.sleep(offDuration) } catch (e: Exception) { diff --git a/app/src/main/res/drawable/shortcut_bright_display.xml b/app/src/main/res/drawable/shortcut_bright_display.xml new file mode 100644 index 0000000..cb7f759 --- /dev/null +++ b/app/src/main/res/drawable/shortcut_bright_display.xml @@ -0,0 +1,16 @@ + + + + + + + + + + + diff --git a/app/src/main/res/layout/activity_bright_display.xml b/app/src/main/res/layout/activity_bright_display.xml index b81a52d..0552071 100644 --- a/app/src/main/res/layout/activity_bright_display.xml +++ b/app/src/main/res/layout/activity_bright_display.xml @@ -1,6 +1,5 @@ - @@ -9,7 +8,7 @@ android:id="@+id/bright_display" android:layout_width="match_parent" android:layout_height="match_parent" - android:background="@android:color/white"/> + android:background="@android:color/white" /> + android:textSize="@dimen/big_text_size" /> diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 55daaf6..f08f84d 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -1,6 +1,5 @@ - + app:layout_constraintTop_toTopOf="parent" /> + app:layout_constraintTop_toBottomOf="@+id/flashlight_btn" /> + app:layout_constraintTop_toBottomOf="@+id/bright_display_btn" /> + app:layout_constraintTop_toBottomOf="@+id/sos_btn" /> + app:layout_constraintTop_toBottomOf="@+id/stroboscope_btn" /> diff --git a/app/src/main/res/layout/activity_settings.xml b/app/src/main/res/layout/activity_settings.xml index 557c2cc..04d64c6 100644 --- a/app/src/main/res/layout/activity_settings.xml +++ b/app/src/main/res/layout/activity_settings.xml @@ -1,6 +1,5 @@ - + android:text="@string/purchase_simple_thank_you" /> @@ -50,7 +49,7 @@ android:layout_height="wrap_content" android:layout_centerVertical="true" android:paddingStart="@dimen/medium_margin" - android:text="@string/customize_colors"/> + android:text="@string/customize_colors" /> @@ -71,7 +70,7 @@ android:layout_height="wrap_content" android:layout_centerVertical="true" android:paddingStart="@dimen/medium_margin" - android:text="@string/customize_widget_colors"/> + android:text="@string/customize_widget_colors" /> @@ -94,7 +93,7 @@ android:clickable="false" android:paddingStart="@dimen/medium_margin" android:text="@string/use_english_language" - app:switchPadding="@dimen/medium_margin"/> + app:switchPadding="@dimen/medium_margin" /> @@ -117,7 +116,7 @@ android:clickable="false" android:paddingStart="@dimen/medium_margin" android:text="@string/turn_flashlight_on" - app:switchPadding="@dimen/medium_margin"/> + app:switchPadding="@dimen/medium_margin" /> @@ -139,8 +138,8 @@ android:background="@null" android:clickable="false" android:paddingStart="@dimen/medium_margin" - android:text="@string/bright_display" - app:switchPadding="@dimen/medium_margin"/> + android:text="@string/show_bright_display" + app:switchPadding="@dimen/medium_margin" /> @@ -163,7 +162,7 @@ android:clickable="false" android:paddingStart="@dimen/medium_margin" android:text="@string/show_sos" - app:switchPadding="@dimen/medium_margin"/> + app:switchPadding="@dimen/medium_margin" /> @@ -186,7 +185,7 @@ android:clickable="false" android:paddingStart="@dimen/medium_margin" android:text="@string/show_stroboscope" - app:switchPadding="@dimen/medium_margin"/> + app:switchPadding="@dimen/medium_margin" /> @@ -209,7 +208,7 @@ android:clickable="false" android:paddingStart="@dimen/medium_margin" android:text="@string/force_portrait_mode" - app:switchPadding="@dimen/medium_margin"/> + app:switchPadding="@dimen/medium_margin" /> diff --git a/app/src/main/res/layout/widget.xml b/app/src/main/res/layout/widget.xml index d61288e..17b746c 100644 --- a/app/src/main/res/layout/widget.xml +++ b/app/src/main/res/layout/widget.xml @@ -1,7 +1,6 @@ - + android:layout_margin="5dp" /> diff --git a/app/src/main/res/layout/widget_config.xml b/app/src/main/res/layout/widget_config.xml index b5cf44b..17bb81a 100644 --- a/app/src/main/res/layout/widget_config.xml +++ b/app/src/main/res/layout/widget_config.xml @@ -1,6 +1,5 @@ - + android:background="@drawable/ic_flashlight" /> + android:layout_above="@+id/config_save" /> @@ -42,21 +41,21 @@ android:layout_height="wrap_content" android:layout_centerVertical="true" android:paddingLeft="@dimen/activity_margin" - android:paddingRight="@dimen/activity_margin"/> + android:paddingRight="@dimen/activity_margin" />