0
0
mirror of https://github.com/markusfisch/BinaryEye.git synced 2024-09-19 19:42:18 +02:00

Set maximum brightness when showing a barcode

To make scanning from screen easier.
This commit is contained in:
Markus Fisch 2024-07-09 19:11:35 +02:00
parent 876d8fc7b3
commit 54aa15e1be
30 changed files with 149 additions and 1 deletions

View File

@ -17,6 +17,7 @@ import android.widget.EditText
import de.markusfisch.android.binaryeye.R
import de.markusfisch.android.binaryeye.app.db
import de.markusfisch.android.binaryeye.app.hasWritePermission
import de.markusfisch.android.binaryeye.app.prefs
import de.markusfisch.android.binaryeye.content.copyToClipboard
import de.markusfisch.android.binaryeye.content.shareFile
import de.markusfisch.android.binaryeye.content.shareText
@ -26,6 +27,8 @@ import de.markusfisch.android.binaryeye.graphics.COLOR_WHITE
import de.markusfisch.android.binaryeye.io.addSuffixIfNotGiven
import de.markusfisch.android.binaryeye.io.toSaveResult
import de.markusfisch.android.binaryeye.io.writeExternalFile
import de.markusfisch.android.binaryeye.os.getScreenBrightness
import de.markusfisch.android.binaryeye.os.setScreenBrightness
import de.markusfisch.android.binaryeye.view.doOnApplyWindowInsets
import de.markusfisch.android.binaryeye.view.setPaddingFromWindowInsets
import de.markusfisch.android.binaryeye.widget.ConfinedScalingImageView
@ -55,6 +58,8 @@ class BarcodeFragment : Fragment() {
private lateinit var barcode: Barcode<*>
private lateinit var addToHistoryItem: MenuItem
private var currentBrightness = -1f;
override fun onCreate(state: Bundle?) {
super.onCreate(state)
setHasOptionsMenu(true)
@ -136,6 +141,24 @@ class BarcodeFragment : Fragment() {
Colors.entries[getInt(COLORS)]
)
override fun onResume() {
super.onResume()
if (prefs.brightenScreen) {
activity?.let {
currentBrightness = it.getScreenBrightness()
it.setScreenBrightness(1f);
}
}
}
override fun onPause() {
super.onPause()
if (currentBrightness > -1f) {
activity?.setScreenBrightness(currentBrightness);
currentBrightness = -1f
}
}
override fun onDestroyView() {
super.onDestroyView()
parentJob.cancel()

View File

@ -0,0 +1,22 @@
package de.markusfisch.android.binaryeye.os
import android.app.Activity
import android.view.WindowManager
fun Activity.getScreenBrightness(): Float {
val layoutParams = window.attributes
return if (layoutParams.screenBrightness == WindowManager.LayoutParams.BRIGHTNESS_OVERRIDE_NONE) {
android.provider.Settings.System.getInt(
contentResolver,
android.provider.Settings.System.SCREEN_BRIGHTNESS
) / 255.0f
} else {
layoutParams.screenBrightness
}
}
fun Activity.setScreenBrightness(brightness: Float) {
val layoutParams = window.attributes
layoutParams.screenBrightness = brightness
window.attributes = layoutParams
}

View File

@ -215,6 +215,11 @@ class Preferences {
apply(EXPAND_ESCAPE_SEQUENCES, value)
field = value
}
var brightenScreen = false
set(value) {
apply(BRIGHTEN_SCREEN, value)
field = value
}
fun init(context: Context) {
preferences = PreferenceManager.getDefaultSharedPreferences(context)
@ -335,6 +340,10 @@ class Preferences {
EXPAND_ESCAPE_SEQUENCES,
expandEscapeSequences
)
brightenScreen = preferences.getBoolean(
BRIGHTEN_SCREEN,
brightenScreen
)
}
private fun addFormatsOnUpdate(
@ -434,5 +443,6 @@ class Preferences {
private const val LAST_MARGIN = "last_margin"
private const val FREE_ROTATION = "free_rotation"
private const val EXPAND_ESCAPE_SEQUENCES = "expand_escape_sequences"
private const val BRIGHTEN_SCREEN = "brighten_screen"
}
}

View File

@ -138,6 +138,9 @@
<string name="bluetooth_connect_fail">Неуспешно свързване с Bluetooth устройство.</string>
<string name="bluetooth_send_fail">Неуспешно изпращане до Bluetooth устройство.</string>
<string name="bluetooth_send_success">Успешно Bluetooth изпращане.</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Brighten screen</string>
<string name="brighten_screen_summary">Set brightness to maximum to enhance scanning a barcode from the screen.</string>
<string name="really_remove_scan">Наистина ли искате да премахнете това сканиране?</string>
<string name="really_remove_all_scans">Наистина ли искате да премахнете всички сканирания?</string>
<string name="really_remove_selected_scans">Наистина ли искате да премахнете избраните сканирания?</string>

View File

@ -138,6 +138,9 @@
<string name="bluetooth_connect_fail">Could not connect to bluetooth device.</string>
<string name="bluetooth_send_fail">Could not send to bluetooth device.</string>
<string name="bluetooth_send_success">Successful bluetooth send.</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Brighten screen</string>
<string name="brighten_screen_summary">Set brightness to maximum to enhance scanning a barcode from the screen.</string>
<string name="really_remove_scan">আসলেই এটা মুছবে?</string>
<string name="really_remove_all_scans">আসলেই সব মুছবে?</string>
<string name="really_remove_selected_scans">আসলেই নির্বাচিত সব মুছবে?</string>

View File

@ -140,6 +140,9 @@
<string name="bluetooth_connect_fail">Nelze se připojit k zařízení Bluetooth.</string>
<string name="bluetooth_send_fail">Nelze odesílat na zařízení Bluetooth.</string>
<string name="bluetooth_send_success">Odesílání přes Bluetooth se zdařilo.</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Brighten screen</string>
<string name="brighten_screen_summary">Set brightness to maximum to enhance scanning a barcode from the screen.</string>
<string name="really_remove_scan">Opravdu odstranit sken?</string>
<string name="really_remove_all_scans">Opravdu odstranit všechny skeny?</string>
<string name="really_remove_selected_scans">Opravdu odstranit zvolené skeny?</string>

View File

@ -138,6 +138,9 @@
<string name="bluetooth_connect_fail">Could not connect to bluetooth device.</string>
<string name="bluetooth_send_fail">Could not send to bluetooth device.</string>
<string name="bluetooth_send_success">Successful bluetooth send.</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Brighten screen</string>
<string name="brighten_screen_summary">Set brightness to maximum to enhance scanning a barcode from the screen.</string>
<string name="really_remove_scan">Vil du virkelig fjerne scanningen?</string>
<string name="really_remove_all_scans">Vil du virkelig fjerne alle scanninger?</string>
<string name="really_remove_selected_scans">Vil du virkelig fjerne valgte scanninger?</string>

View File

@ -138,6 +138,9 @@
<string name="bluetooth_connect_fail">Es kann leider keine Verbindung zum Bluetooth-Gerät hergestellt werden</string>
<string name="bluetooth_send_fail">Senden zum Bluetooth-Gerät fehlgeschlagen</string>
<string name="bluetooth_send_success">Erfolgreich zum Bluetooth-Gerät gesendet</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Bildschrim aufhellen</string>
<string name="brighten_screen_summary">Helligkeit auf Maximum stellen um das Scannen eines Barcodes vom Bildschirm zu verbessern.</string>
<string name="really_remove_scan">Code wirklich entfernen?</string>
<string name="really_remove_all_scans">Alle Codes entfernen?</string>
<string name="really_remove_selected_scans">Alle ausgewählten Codes entfernen?</string>

View File

@ -138,6 +138,9 @@
<string name="bluetooth_connect_fail">No se pudo conectar a un dispositivo bluetooth.</string>
<string name="bluetooth_send_fail">No se pudo enviar a un dispositivo bluetooth.</string>
<string name="bluetooth_send_success">Envío bluetooth completado.</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Brighten screen</string>
<string name="brighten_screen_summary">Set brightness to maximum to enhance scanning a barcode from the screen.</string>
<string name="really_remove_scan">¿Eliminar el escaneo seleccionado?</string>
<string name="really_remove_all_scans">¿Eliminar todos los escaneos?</string>
<string name="really_remove_selected_scans">¿Eliminar los escaneos seleccionados?</string>

View File

@ -138,6 +138,9 @@
<string name="bluetooth_connect_fail">Could not connect to bluetooth device.</string>
<string name="bluetooth_send_fail">Could not send to bluetooth device.</string>
<string name="bluetooth_send_success">Successful bluetooth send.</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Brighten screen</string>
<string name="brighten_screen_summary">Set brightness to maximum to enhance scanning a barcode from the screen.</string>
<string name="really_remove_scan">برای برداشتن پویش مطمئنید؟</string>
<string name="really_remove_all_scans">برای برداشتن همهٔ پویش‌ها مطمئنید؟</string>
<string name="really_remove_selected_scans">برای برداشتن پویش‌های برگزیده شده مطمئنید؟</string>

View File

@ -138,6 +138,9 @@
<string name="bluetooth_connect_fail">Impossible de se connecter à l\'appareil Bluetooth.</string>
<string name="bluetooth_send_fail">Impossible d\'envoyer à l\'appareil Bluetooth.</string>
<string name="bluetooth_send_success">Envoi Bluetooth réussi.</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Brighten screen</string>
<string name="brighten_screen_summary">Set brightness to maximum to enhance scanning a barcode from the screen.</string>
<string name="really_remove_scan">Supprimer le scan ?</string>
<string name="really_remove_all_scans">Supprimer tous les scans ?</string>
<string name="really_remove_selected_scans">Supprimer les scans sélectionnés ?</string>

View File

@ -138,6 +138,9 @@
<string name="bluetooth_connect_fail">Could not connect to bluetooth device.</string>
<string name="bluetooth_send_fail">Could not send to bluetooth device.</string>
<string name="bluetooth_send_success">Successful bluetooth send.</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Brighten screen</string>
<string name="brighten_screen_summary">Set brightness to maximum to enhance scanning a barcode from the screen.</string>
<string name="really_remove_scan">Valóban eltávolítja a beolvasást?</string>
<string name="really_remove_all_scans">Valóban eltávolítja az összes beolvasását?</string>
<string name="really_remove_selected_scans">Valóban eltávolítja a kijelölt beolvasásokat?</string>

View File

@ -137,6 +137,9 @@
<string name="bluetooth_connect_fail">Could not connect to bluetooth device.</string>
<string name="bluetooth_send_fail">Could not send to bluetooth device.</string>
<string name="bluetooth_send_success">Successful bluetooth send.</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Brighten screen</string>
<string name="brighten_screen_summary">Set brightness to maximum to enhance scanning a barcode from the screen.</string>
<string name="really_remove_scan">Yakin menghapus pindaian?</string>
<string name="really_remove_all_scans">Yakin menghapus semua pindaian?</string>
<string name="really_remove_selected_scans">Yakin menghapus pindaian yang dipilih?</string>

View File

@ -138,6 +138,9 @@
<string name="bluetooth_connect_fail">Impossibile connettersi al dispositivo Bluetooth.</string>
<string name="bluetooth_send_fail">Impossibile inviare al dispositivo Bluetooth.</string>
<string name="bluetooth_send_success">Invio via Bluetooth riuscito.</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Brighten screen</string>
<string name="brighten_screen_summary">Set brightness to maximum to enhance scanning a barcode from the screen.</string>
<string name="really_remove_scan">Vuoi rimuovere la scansione?</string>
<string name="really_remove_all_scans">Vuoi rimuovere tutte le scansioni?</string>
<string name="really_remove_selected_scans">Vuoi rimuovere le scansioni selezionate?</string>

View File

@ -137,6 +137,9 @@
<string name="bluetooth_connect_fail">Could not connect to bluetooth device.</string>
<string name="bluetooth_send_fail">Could not send to bluetooth device.</string>
<string name="bluetooth_send_success">Successful bluetooth send.</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Brighten screen</string>
<string name="brighten_screen_summary">Set brightness to maximum to enhance scanning a barcode from the screen.</string>
<string name="really_remove_scan">このスキャン履歴を削除しても宜しいですか?</string>
<string name="really_remove_all_scans">全てのスキャン履歴を削除しても宜しいですか?</string>
<string name="really_remove_selected_scans">選択されたスキャン履歴を削除しても宜しいですか?</string>

View File

@ -138,6 +138,9 @@
<string name="bluetooth_connect_fail">Could not connect to bluetooth device.</string>
<string name="bluetooth_send_fail">Could not send to bluetooth device.</string>
<string name="bluetooth_send_success">Successful bluetooth send.</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Brighten screen</string>
<string name="brighten_screen_summary">Set brightness to maximum to enhance scanning a barcode from the screen.</string>
<string name="really_remove_scan">ნამდვილად გსურთ სკანირების წაშლა?</string>
<string name="really_remove_all_scans">ნამდვილად გსურთ ყველაფრის წაშლა?</string>
<string name="really_remove_selected_scans">ნამდვილად გსურთ შერჩეული შტრიხ-კოდების წაშლა?</string>

View File

@ -137,6 +137,9 @@
<string name="bluetooth_connect_fail">Could not connect to bluetooth device.</string>
<string name="bluetooth_send_fail">Could not send to bluetooth device.</string>
<string name="bluetooth_send_success">Successful bluetooth send.</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Brighten screen</string>
<string name="brighten_screen_summary">Set brightness to maximum to enhance scanning a barcode from the screen.</string>
<string name="really_remove_scan">Really remove scan?</string>
<string name="really_remove_all_scans">Really remove all scans?</string>
<string name="really_remove_selected_scans">Really remove selected scans?</string>

View File

@ -138,6 +138,9 @@
<string name="bluetooth_connect_fail">Could not connect to bluetooth device.</string>
<string name="bluetooth_send_fail">Could not send to bluetooth device.</string>
<string name="bluetooth_send_success">Successful bluetooth send.</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Brighten screen</string>
<string name="brighten_screen_summary">Set brightness to maximum to enhance scanning a barcode from the screen.</string>
<string name="really_remove_scan">Scan echt verwijderen?</string>
<string name="really_remove_all_scans">Alle scans echt verwijderen?</string>
<string name="really_remove_selected_scans">Geselecteerde scans verwijderen?</string>

View File

@ -161,6 +161,9 @@
<string name="bluetooth_connect_fail">Could not connect to bluetooth device.</string>
<string name="bluetooth_send_fail">Could not send to bluetooth device.</string>
<string name="bluetooth_send_success">Successful bluetooth send.</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Brighten screen</string>
<string name="brighten_screen_summary">Set brightness to maximum to enhance scanning a barcode from the screen.</string>
<string name="copy_password">Skopiuj hasło do schowka</string>
<string name="copied_password_to_clipboard">Hasło skopiowane do schowka</string>
<string name="gtin_price">Sugerowana cena</string>
@ -205,4 +208,4 @@
<string name="wifi_phase2">Metoda fazy 2</string>
<string name="network_suggestions">Network suggestions</string>
<string name="remove_suggestion">Usuń sugestię</string>
</resources>
</resources>

View File

@ -139,6 +139,9 @@
<string name="bluetooth_connect_fail">Não foi possível conectar com o dispositivo Bluetooth.</string>
<string name="bluetooth_send_fail">Não foi possível enviar para o dispositivo Bluetooth.</string>
<string name="bluetooth_send_success">Envio Bluetooth com sucesso.</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Brighten screen</string>
<string name="brighten_screen_summary">Set brightness to maximum to enhance scanning a barcode from the screen.</string>
<string name="really_remove_scan">Deseja excluir esta digitalização?</string>
<string name="really_remove_all_scans">Deseja excluir todas as digitalizações?</string>
<string name="really_remove_selected_scans">Deseja excluir as digitalizações selecionadas?</string>

View File

@ -140,6 +140,9 @@
<string name="bluetooth_connect_fail">Невозможно подключиться к bluetooth-устройству.</string>
<string name="bluetooth_send_fail">Невозможно отправить на bluetooth-устройство.</string>
<string name="bluetooth_send_success">Успешно отправлено по bluetooth.</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Brighten screen</string>
<string name="brighten_screen_summary">Set brightness to maximum to enhance scanning a barcode from the screen.</string>
<string name="really_remove_scan">Удалить сканирование?</string>
<string name="really_remove_all_scans">Удалить все сканирования?</string>
<string name="really_remove_selected_scans">Удалить выбранные штрих-коды?</string>

View File

@ -138,6 +138,9 @@
<string name="bluetooth_connect_fail">Bluetooth aygıtına bağlanılamadı.</string>
<string name="bluetooth_send_fail">Bluetooth aygıtına gönderilemedi.</string>
<string name="bluetooth_send_success">Bluetooth aygıtına gönderildi.</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Brighten screen</string>
<string name="brighten_screen_summary">Set brightness to maximum to enhance scanning a barcode from the screen.</string>
<string name="really_remove_scan">Tarama gerçekten silinsin mi?</string>
<string name="really_remove_all_scans">Tüm taramalar gerçekten silinsin mi?</string>
<string name="really_remove_selected_scans">Seçili taramalar gerçekten silinsin mi?</string>

View File

@ -139,6 +139,9 @@
<string name="bluetooth_connect_fail">Неможливо підключитися до пристрою Bluetooth.</string>
<string name="bluetooth_send_fail">Неможливо надіслати на пристрій Bluetooth.</string>
<string name="bluetooth_send_success">Успішно надіслано через Bluetooth.</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Brighten screen</string>
<string name="brighten_screen_summary">Set brightness to maximum to enhance scanning a barcode from the screen.</string>
<string name="really_remove_scan">Дійсно видалити сканування?</string>
<string name="really_remove_all_scans">Дійсно видалити всі сканування?</string>
<string name="really_remove_selected_scans">Дійсно видалити вибрані сканування?</string>

View File

@ -137,6 +137,9 @@
<string name="bluetooth_connect_fail">Could not connect to bluetooth device.</string>
<string name="bluetooth_send_fail">Could not send to bluetooth device.</string>
<string name="bluetooth_send_success">Successful bluetooth send.</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Brighten screen</string>
<string name="brighten_screen_summary">Set brightness to maximum to enhance scanning a barcode from the screen.</string>
<string name="really_remove_scan">Thật sự xoá lần quét này?</string>
<string name="really_remove_all_scans">Thật sự xoá tất cả các lần quét?</string>
<string name="really_remove_selected_scans">Thật sự xoá các lần quét được chọn?</string>

View File

@ -137,6 +137,9 @@
<string name="bluetooth_connect_fail">无法连接蓝牙设备。</string>
<string name="bluetooth_send_fail">无法将结果发送至蓝牙设备。</string>
<string name="bluetooth_send_success">已通过蓝牙发送。</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Brighten screen</string>
<string name="brighten_screen_summary">Set brightness to maximum to enhance scanning a barcode from the screen.</string>
<string name="really_remove_scan">确定删除记录?</string>
<string name="really_remove_all_scans">确定删除全部记录?</string>
<string name="really_remove_selected_scans">确定删除所选记录?</string>

View File

@ -137,6 +137,9 @@
<string name="bluetooth_connect_fail">無法連線到藍牙裝置</string>
<string name="bluetooth_send_fail">無法傳送到藍牙裝置</string>
<string name="bluetooth_send_success">藍牙傳送完成</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Brighten screen</string>
<string name="brighten_screen_summary">Set brightness to maximum to enhance scanning a barcode from the screen.</string>
<string name="really_remove_scan">確定刪除記錄?</string>
<string name="really_remove_all_scans">確定要刪除所有掃描記錄?</string>
<string name="really_remove_selected_scans">確定要刪除選擇的掃描記錄?</string>

View File

@ -138,6 +138,9 @@
<string name="bluetooth_connect_fail">Could not connect to Bluetooth device.</string>
<string name="bluetooth_send_fail">Could not send to Bluetooth device.</string>
<string name="bluetooth_send_success">Successful Bluetooth send.</string>
<string name="generation_category">Generation</string>
<string name="brighten_screen">Brighten screen</string>
<string name="brighten_screen_summary">Set brightness to maximum to enhance scanning a barcode from the screen.</string>
<string name="really_remove_scan">Really remove scan?</string>
<string name="really_remove_all_scans">Really remove all scans?</string>
<string name="really_remove_selected_scans">Really remove selected scans?</string>

View File

@ -150,6 +150,13 @@
android:title="@string/clear_network_suggestions"
android:summary="@string/clear_network_suggestions_summary"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/generation_category">
<android.support.v7.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:key="brighten_screen"
android:title="@string/brighten_screen"
android:summary="@string/brighten_screen_summary"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/locale_category">
<ListPreference
android:key="custom_locale"

View File

@ -150,4 +150,11 @@
android:title="@string/clear_network_suggestions"
android:summary="@string/clear_network_suggestions_summary"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/generation_category">
<android.support.v7.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:key="brighten_screen"
android:title="@string/brighten_screen"
android:summary="@string/brighten_screen_summary"/>
</PreferenceCategory>
</PreferenceScreen>

View File

@ -145,6 +145,13 @@
android:title="@string/clear_network_suggestions"
android:summary="@string/clear_network_suggestions_summary"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/generation_category">
<android.support.v7.preference.SwitchPreferenceCompat
android:defaultValue="false"
android:key="brighten_screen"
android:title="@string/brighten_screen"
android:summary="@string/brighten_screen_summary"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/locale_category">
<ListPreference
android:key="custom_locale"