mirror of
https://github.com/SimpleMobileTools/Simple-Flashlight.git
synced 2025-04-21 13:47:21 +02:00
few more updates here and there
This commit is contained in:
parent
94fef5494c
commit
cb2ec43b24
@ -60,6 +60,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
mCameraImpl!!.stopStroboscope()
|
mCameraImpl!!.stopStroboscope()
|
||||||
stroboscope_bar.beInvisible()
|
stroboscope_bar.beInvisible()
|
||||||
}
|
}
|
||||||
|
updateTextColors(main_holder)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
@ -118,8 +119,7 @@ class MainActivity : SimpleActivity() {
|
|||||||
stroboscope_bar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
stroboscope_bar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
|
||||||
override fun onProgressChanged(seekBar: SeekBar, progress: Int, b: Boolean) {
|
override fun onProgressChanged(seekBar: SeekBar, progress: Int, b: Boolean) {
|
||||||
val frequency = stroboscope_bar.max - progress + MIN_STROBO_DELAY
|
val frequency = stroboscope_bar.max - progress + MIN_STROBO_DELAY
|
||||||
if (mCameraImpl != null)
|
mCameraImpl?.stroboFrequency = frequency
|
||||||
mCameraImpl!!.stroboFrequency = frequency
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStartTrackingTouch(seekBar: SeekBar) {
|
override fun onStartTrackingTouch(seekBar: SeekBar) {
|
||||||
|
@ -2,29 +2,24 @@ package com.simplemobiletools.flashlight.activities
|
|||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
import android.appwidget.AppWidgetManager
|
import android.appwidget.AppWidgetManager
|
||||||
import android.content.Context
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.PorterDuff
|
import android.graphics.PorterDuff
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.support.v7.app.AppCompatActivity
|
import android.support.v7.app.AppCompatActivity
|
||||||
import android.widget.RemoteViews
|
|
||||||
import android.widget.SeekBar
|
import android.widget.SeekBar
|
||||||
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
|
import com.simplemobiletools.commons.dialogs.ColorPickerDialog
|
||||||
import com.simplemobiletools.commons.extensions.adjustAlpha
|
import com.simplemobiletools.commons.extensions.adjustAlpha
|
||||||
import com.simplemobiletools.commons.helpers.PREFS_KEY
|
|
||||||
import com.simplemobiletools.flashlight.R
|
import com.simplemobiletools.flashlight.R
|
||||||
|
import com.simplemobiletools.flashlight.extensions.config
|
||||||
import com.simplemobiletools.flashlight.helpers.MyWidgetProvider
|
import com.simplemobiletools.flashlight.helpers.MyWidgetProvider
|
||||||
import com.simplemobiletools.flashlight.helpers.WIDGET_COLOR
|
|
||||||
import kotlinx.android.synthetic.main.widget_config.*
|
import kotlinx.android.synthetic.main.widget_config.*
|
||||||
|
|
||||||
class WidgetConfigureActivity : AppCompatActivity() {
|
class WidgetConfigureActivity : AppCompatActivity() {
|
||||||
companion object {
|
|
||||||
private var mWidgetAlpha = 0f
|
private var mWidgetAlpha = 0f
|
||||||
private var mWidgetId = 0
|
private var mWidgetId = 0
|
||||||
private var mWidgetColor = 0
|
private var mWidgetColor = 0
|
||||||
private var mWidgetColorWithoutTransparency = 0
|
private var mWidgetColorWithoutTransparency = 0
|
||||||
}
|
|
||||||
|
|
||||||
public override fun onCreate(savedInstanceState: Bundle?) {
|
public override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
@ -32,7 +27,6 @@ class WidgetConfigureActivity : AppCompatActivity() {
|
|||||||
setContentView(R.layout.widget_config)
|
setContentView(R.layout.widget_config)
|
||||||
initVariables()
|
initVariables()
|
||||||
|
|
||||||
val intent = intent
|
|
||||||
val extras = intent.extras
|
val extras = intent.extras
|
||||||
if (extras != null)
|
if (extras != null)
|
||||||
mWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID)
|
mWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID, AppWidgetManager.INVALID_APPWIDGET_ID)
|
||||||
@ -45,8 +39,7 @@ class WidgetConfigureActivity : AppCompatActivity() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun initVariables() {
|
private fun initVariables() {
|
||||||
val prefs = getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
|
mWidgetColor = config.widgetBgColor
|
||||||
mWidgetColor = prefs.getInt(WIDGET_COLOR, 1)
|
|
||||||
if (mWidgetColor == 1) {
|
if (mWidgetColor == 1) {
|
||||||
mWidgetColor = resources.getColor(R.color.color_primary)
|
mWidgetColor = resources.getColor(R.color.color_primary)
|
||||||
mWidgetAlpha = 1f
|
mWidgetAlpha = 1f
|
||||||
@ -60,36 +53,29 @@ class WidgetConfigureActivity : AppCompatActivity() {
|
|||||||
updateColors()
|
updateColors()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun saveConfig() {
|
private fun saveConfig() {
|
||||||
val appWidgetManager = AppWidgetManager.getInstance(this)
|
config.widgetBgColor = mWidgetColor
|
||||||
val views = RemoteViews(packageName, R.layout.widget)
|
|
||||||
appWidgetManager.updateAppWidget(mWidgetId, views)
|
|
||||||
|
|
||||||
storeWidgetColors()
|
|
||||||
requestWidgetUpdate()
|
requestWidgetUpdate()
|
||||||
|
|
||||||
val resultValue = Intent()
|
Intent().apply {
|
||||||
resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mWidgetId)
|
putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mWidgetId)
|
||||||
setResult(Activity.RESULT_OK, resultValue)
|
setResult(Activity.RESULT_OK, this)
|
||||||
|
}
|
||||||
finish()
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun pickBackgroundColor() {
|
private fun pickBackgroundColor() {
|
||||||
ColorPickerDialog(this, mWidgetColorWithoutTransparency) {
|
ColorPickerDialog(this, mWidgetColorWithoutTransparency) {
|
||||||
mWidgetColorWithoutTransparency = it
|
mWidgetColorWithoutTransparency = it
|
||||||
updateColors()
|
updateColors()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun storeWidgetColors() {
|
|
||||||
val prefs = getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
|
|
||||||
prefs.edit().putInt(WIDGET_COLOR, mWidgetColor).apply()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun requestWidgetUpdate() {
|
private fun requestWidgetUpdate() {
|
||||||
val intent = Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null, this, MyWidgetProvider::class.java)
|
Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE, null, this, MyWidgetProvider::class.java).apply {
|
||||||
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, intArrayOf(mWidgetId))
|
putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, intArrayOf(mWidgetId))
|
||||||
sendBroadcast(intent)
|
sendBroadcast(this)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun updateColors() {
|
private fun updateColors() {
|
||||||
@ -104,12 +90,8 @@ class WidgetConfigureActivity : AppCompatActivity() {
|
|||||||
updateColors()
|
updateColors()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStartTrackingTouch(seekBar: SeekBar) {
|
override fun onStartTrackingTouch(seekBar: SeekBar) {}
|
||||||
|
|
||||||
}
|
override fun onStopTrackingTouch(seekBar: SeekBar) {}
|
||||||
|
|
||||||
override fun onStopTrackingTouch(seekBar: SeekBar) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,31 +6,37 @@ import android.appwidget.AppWidgetProvider
|
|||||||
import android.content.ComponentName
|
import android.content.ComponentName
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
|
||||||
import android.graphics.Bitmap
|
import android.graphics.Bitmap
|
||||||
import android.graphics.Color
|
import android.graphics.Color
|
||||||
import android.graphics.PorterDuff
|
import android.graphics.PorterDuff
|
||||||
import android.widget.RemoteViews
|
import android.widget.RemoteViews
|
||||||
import com.simplemobiletools.commons.extensions.toast
|
import com.simplemobiletools.commons.extensions.toast
|
||||||
import com.simplemobiletools.commons.helpers.PREFS_KEY
|
|
||||||
import com.simplemobiletools.flashlight.R
|
import com.simplemobiletools.flashlight.R
|
||||||
|
import com.simplemobiletools.flashlight.extensions.config
|
||||||
import com.simplemobiletools.flashlight.models.Events
|
import com.simplemobiletools.flashlight.models.Events
|
||||||
import com.squareup.otto.Bus
|
import com.squareup.otto.Bus
|
||||||
import com.squareup.otto.Subscribe
|
import com.squareup.otto.Subscribe
|
||||||
|
|
||||||
class MyWidgetProvider : AppWidgetProvider() {
|
class MyWidgetProvider : AppWidgetProvider() {
|
||||||
|
private val TOGGLE = "toggle"
|
||||||
|
|
||||||
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
|
companion object {
|
||||||
initVariables(context)
|
private var mCameraImpl: MyCameraImpl? = null
|
||||||
appWidgetManager.updateAppWidget(appWidgetIds, mRemoteViews)
|
private var mRemoteViews: RemoteViews? = null
|
||||||
|
private var mColoredBmp: Bitmap? = null
|
||||||
|
private var mWhiteBmp: Bitmap? = null
|
||||||
|
private var mBus: Bus? = null
|
||||||
|
private var mContext: Context? = null
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initVariables(context: Context) {
|
override fun onUpdate(context: Context, appWidgetManager: AppWidgetManager, appWidgetIds: IntArray) {
|
||||||
mContext = context
|
performUpdate(context)
|
||||||
val component = ComponentName(context, MyWidgetProvider::class.java)
|
}
|
||||||
mWidgetManager = AppWidgetManager.getInstance(context)
|
|
||||||
mWidgetIds = mWidgetManager!!.getAppWidgetIds(component)
|
|
||||||
|
|
||||||
|
private fun performUpdate(context: Context) {
|
||||||
|
mContext = context
|
||||||
|
val appWidgetManager = AppWidgetManager.getInstance(context)
|
||||||
|
appWidgetManager.getAppWidgetIds(getComponentName(context)).forEach {
|
||||||
val intent = Intent(context, MyWidgetProvider::class.java)
|
val intent = Intent(context, MyWidgetProvider::class.java)
|
||||||
intent.action = TOGGLE
|
intent.action = TOGGLE
|
||||||
|
|
||||||
@ -39,10 +45,7 @@ class MyWidgetProvider : AppWidgetProvider() {
|
|||||||
mRemoteViews!!.setOnClickPendingIntent(R.id.toggle_btn, pendingIntent)
|
mRemoteViews!!.setOnClickPendingIntent(R.id.toggle_btn, pendingIntent)
|
||||||
mCameraImpl = MyCameraImpl(context)
|
mCameraImpl = MyCameraImpl(context)
|
||||||
|
|
||||||
val prefs = initPrefs(context)
|
val selectedColor = context.config.widgetBgColor
|
||||||
val res = context.resources
|
|
||||||
val defaultColor = res.getColor(R.color.color_primary)
|
|
||||||
val selectedColor = prefs.getInt(WIDGET_COLOR, defaultColor)
|
|
||||||
val alpha = Color.alpha(selectedColor)
|
val alpha = Color.alpha(selectedColor)
|
||||||
|
|
||||||
mColoredBmp = getColoredCircles(selectedColor, alpha)
|
mColoredBmp = getColoredCircles(selectedColor, alpha)
|
||||||
@ -54,17 +57,23 @@ class MyWidgetProvider : AppWidgetProvider() {
|
|||||||
}
|
}
|
||||||
registerBus()
|
registerBus()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getComponentName(context: Context) = ComponentName(context, MyWidgetProvider::class.java)
|
||||||
|
|
||||||
override fun onReceive(context: Context, intent: Intent) {
|
override fun onReceive(context: Context, intent: Intent) {
|
||||||
val action = intent.action
|
when (intent.action) {
|
||||||
if (action == TOGGLE) {
|
TOGGLE -> toggleFlashlight(context)
|
||||||
|
else -> super.onReceive(context, intent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun toggleFlashlight(context: Context) {
|
||||||
if (mCameraImpl == null || mBus == null) {
|
if (mCameraImpl == null || mBus == null) {
|
||||||
initVariables(context)
|
performUpdate(context)
|
||||||
}
|
}
|
||||||
|
|
||||||
mCameraImpl!!.toggleFlashlight()
|
mCameraImpl!!.toggleFlashlight()
|
||||||
} else
|
|
||||||
super.onReceive(context, intent)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getColoredCircles(color: Int, alpha: Int): Bitmap {
|
private fun getColoredCircles(color: Int, alpha: Int): Bitmap {
|
||||||
@ -74,22 +83,18 @@ class MyWidgetProvider : AppWidgetProvider() {
|
|||||||
return Utils.drawableToBitmap(drawable)
|
return Utils.drawableToBitmap(drawable)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun enableFlashlight() {
|
private fun enableFlashlight() {
|
||||||
mRemoteViews!!.setImageViewBitmap(R.id.toggle_btn, mColoredBmp)
|
mRemoteViews!!.setImageViewBitmap(R.id.toggle_btn, mColoredBmp)
|
||||||
for (widgetId in mWidgetIds!!) {
|
/*for (widgetId in mWidgetIds!!) {
|
||||||
mWidgetManager!!.updateAppWidget(widgetId, mRemoteViews)
|
mWidgetManager!!.updateAppWidget(widgetId, mRemoteViews)
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
|
|
||||||
fun disableFlashlight() {
|
private fun disableFlashlight() {
|
||||||
mRemoteViews!!.setImageViewBitmap(R.id.toggle_btn, mWhiteBmp)
|
mRemoteViews!!.setImageViewBitmap(R.id.toggle_btn, mWhiteBmp)
|
||||||
for (widgetId in mWidgetIds!!) {
|
/*for (widgetId in mWidgetIds!!) {
|
||||||
mWidgetManager!!.updateAppWidget(widgetId, mRemoteViews)
|
mWidgetManager!!.updateAppWidget(widgetId, mRemoteViews)
|
||||||
}
|
}*/
|
||||||
}
|
|
||||||
|
|
||||||
private fun initPrefs(context: Context): SharedPreferences {
|
|
||||||
return context.getSharedPreferences(PREFS_KEY, Context.MODE_PRIVATE)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@ -116,8 +121,9 @@ class MyWidgetProvider : AppWidgetProvider() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun releaseCamera(context: Context) {
|
private fun releaseCamera(context: Context) {
|
||||||
if (mCameraImpl == null)
|
if (mCameraImpl == null) {
|
||||||
initVariables(context)
|
performUpdate(context)
|
||||||
|
}
|
||||||
|
|
||||||
mCameraImpl!!.releaseCamera()
|
mCameraImpl!!.releaseCamera()
|
||||||
}
|
}
|
||||||
@ -137,17 +143,4 @@ class MyWidgetProvider : AppWidgetProvider() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
|
||||||
private val TOGGLE = "toggle"
|
|
||||||
private var mCameraImpl: MyCameraImpl? = null
|
|
||||||
private var mRemoteViews: RemoteViews? = null
|
|
||||||
private var mWidgetManager: AppWidgetManager? = null
|
|
||||||
private var mColoredBmp: Bitmap? = null
|
|
||||||
private var mWhiteBmp: Bitmap? = null
|
|
||||||
private var mBus: Bus? = null
|
|
||||||
private var mContext: Context? = null
|
|
||||||
|
|
||||||
private var mWidgetIds: IntArray? = null
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
android:background="@mipmap/stroboscope"
|
android:background="@mipmap/stroboscope"
|
||||||
android:padding="@dimen/activity_margin"/>
|
android:padding="@dimen/activity_margin"/>
|
||||||
|
|
||||||
<SeekBar
|
<com.simplemobiletools.commons.views.MySeekBar
|
||||||
android:id="@+id/stroboscope_bar"
|
android:id="@+id/stroboscope_bar"
|
||||||
android:layout_width="@dimen/seekbar_width"
|
android:layout_width="@dimen/seekbar_width"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user