Skip to content

Commit

Permalink
Add option to show/hide "Press START on device"
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrivoruchko committed Dec 9, 2021
1 parent 4237574 commit d350620
Show file tree
Hide file tree
Showing 12 changed files with 121 additions and 17 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ android {
applicationId = "info.dvkr.screenstream"
minSdkVersion(21)
targetSdkVersion(31)
versionCode = 30804
versionName = "3.8.4"
versionCode = 30805
versionName = "3.8.5"
resConfigs("en", "ru", "pt-rBR", "zh-rTW", "fr-rFR", "fa", "it", "pl", "hi", "de", "sk", "es", "ar", "ja", "gl", "ca", "uk", "nl")

vectorDrawables.useSupportLibrary = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@ class SettingsInterfaceFragment : Fragment(R.layout.fragment_settings_interface)
binding.clFragmentSettingsHtmlButtons.setOnClickListener { performClick() }
}

// Interface - Web page show "Press START on device"
with(binding.cbFragmentSettingsHtmlPressStart) {
isChecked = settings.htmlShowPressStart
setOnClickListener { settings.htmlShowPressStart = isChecked }
binding.clFragmentSettingsHtmlPressStart.setOnClickListener { performClick() }
}

// Interface - Web page HTML Back color
binding.vFragmentSettingsHtmlBackColor.color = settings.htmlBackColor
binding.vFragmentSettingsHtmlBackColor.border =
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:fillColor="@color/colorIcon"
android:pathData="M13 5C15.21 5 17 6.79 17 9C17 10.5 16.2 11.77 15 12.46V11.24C15.61 10.69 16 9.89 16 9C16 7.34 14.66 6 13 6S10 7.34 10 9C10 9.89 10.39 10.69 11 11.24V12.46C9.8 11.77 9 10.5 9 9C9 6.79 10.79 5 13 5M20 20.5C19.97 21.32 19.32 21.97 18.5 22H13C12.62 22 12.26 21.85 12 21.57L8 17.37L8.74 16.6C8.93 16.39 9.2 16.28 9.5 16.28H9.7L12 18V9C12 8.45 12.45 8 13 8S14 8.45 14 9V13.47L15.21 13.6L19.15 15.79C19.68 16.03 20 16.56 20 17.14V20.5M20 2H4C2.9 2 2 2.9 2 4V12C2 13.11 2.9 14 4 14H8V12L4 12L4 4H20L20 12H18V14H20V13.96L20.04 14C21.13 14 22 13.09 22 12V4C22 2.9 21.11 2 20 2Z" />
</vector>
67 changes: 67 additions & 0 deletions app/src/main/res/layout/fragment_settings_interface.xml
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,73 @@
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:background="@color/colorSettingsDivider" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/cl_fragment_settings_html_press_start"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:focusable="true"
android:minHeight="@dimen/fragment_settings_item_min_height"
android:paddingStart="@dimen/fragment_settings_item_start_end"
android:paddingTop="8dp"
android:paddingEnd="@dimen/fragment_settings_item_start_end"
android:paddingBottom="8dp">

<androidx.appcompat.widget.AppCompatImageView
android:id="@+id/iv_fragment_settings_html_press_start"
android:layout_width="24dp"
android:layout_height="24dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_settings_html_show_press_start_24dp" />

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_fragment_settings_html_press_start"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="@dimen/fragment_settings_item_margin_end"
android:text="@string/pref_html_show_press_start"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/colorSettingsHeader"
app:layout_constraintBottom_toTopOf="@id/tv_fragment_settings_html_press_start_summary"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/iv_fragment_settings_html_press_start"
app:layout_constraintTop_toTopOf="parent" />

<androidx.appcompat.widget.AppCompatTextView
android:id="@+id/tv_fragment_settings_html_press_start_summary"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="@dimen/fragment_settings_item_margin_end"
android:text="@string/pref_html_show_press_start_summary"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="@color/colorSettingsSummary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/iv_fragment_settings_html_press_start"
app:layout_constraintTop_toBottomOf="@id/tv_fragment_settings_html_press_start" />

<com.google.android.material.checkbox.MaterialCheckBox
android:id="@+id/cb_fragment_settings_html_press_start"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

<View
android:layout_width="match_parent"
android:layout_height="1dp"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-ru/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@
<string name="pref_detect_slow_connections_summary">Определять и уведомлять о медленных клиентах</string>
<string name="pref_html_buttons">Включить кнопки веб-страницы</string>
<string name="pref_html_buttons_summary">Показывать кнопки управления на веб-странице</string>
<string name="pref_html_show_press_start">Показывать \"Нажмите СТАРТ для старта трансляции\"</string>
<string name="pref_html_show_press_start_summary">Показывать \"Нажмите СТАРТ для старта трансляции\" на веб-странице</string>
<string name="pref_html_back_color">Цвет фона веб-страницы</string>
<string name="pref_html_back_color_summary">Выбрать цвет фона веб-странцы</string>
<string name="pref_html_back_color_title">Выберите цвет фона</string>
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/res/values-uk/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@
<string name="pref_detect_slow_connections">Повідомляти про повільне з\'єднання</string>
<string name="pref_detect_slow_connections_summary">Визначати та повідомляти про повільні підключення клієнтів</string>
<string name="pref_html_buttons">Увімкнути кнопки веб сторінки</string>
<string name="pref_html_buttons_summary">Показати кнопки веб сторінки</string>
<string name="pref_html_buttons_summary">Показувати кнопки веб сторінки</string>
<string name="pref_html_show_press_start">Показувати \"Натисніть ПОЧАТИ щоб почати передачу\"</string>
<string name="pref_html_show_press_start_summary">Показувати \"Натисніть ПОЧАТИ щоб почати передачу\" на веб сторінці</string>
<string name="pref_html_back_color">Задній фон веб сторінки</string>
<string name="pref_html_back_color_summary">Встановити задній фон веб сторінки</string>
<string name="pref_html_back_color_title">Вибрати задній фон</string>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
<string name="pref_detect_slow_connections_summary">Detect and notify for slow client connections</string>
<string name="pref_html_buttons">Enable web page buttons</string>
<string name="pref_html_buttons_summary">Show control buttons on web page</string>
<string name="pref_html_show_press_start">Show \"Press START on device\"</string>
<string name="pref_html_show_press_start_summary">Show \"Press START on device\" on web page</string>
<string name="pref_html_back_color">Web page background color</string>
<string name="pref_html_back_color_summary">Set web page background color</string>
<string name="pref_html_back_color_title">Select background color</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ import info.dvkr.screenstream.data.R
import info.dvkr.screenstream.data.httpserver.HttpServerFiles
import info.dvkr.screenstream.data.other.getFileFromAssets
import info.dvkr.screenstream.data.other.getLog
import info.dvkr.screenstream.data.settings.SettingsReadOnly


class NotificationBitmap(context: Context) {
class NotificationBitmap(context: Context, private val settingsReadOnly: SettingsReadOnly) {

enum class Type { START, RELOAD_PAGE, NEW_ADDRESS, ADDRESS_BLOCKED }

Expand Down Expand Up @@ -38,18 +39,25 @@ class NotificationBitmap(context: Context) {
}

private fun generateImage(message: String, logo: Bitmap): Bitmap {
val bitmap: Bitmap = Bitmap.createBitmap(640, 400, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
canvas.drawRGB(25, 118, 159)
val paint = Paint(Paint.ANTI_ALIAS_FLAG)
canvas.drawBitmap(logo, 192f, 16f, paint)

paint.textSize = 24f
paint.color = Color.WHITE
val bounds = Rect()
paint.getTextBounds(message, 0, message.length, bounds)
val x = (bitmap.width - bounds.width()) / 2f
canvas.drawText(message, x, 324f, paint)
val bitmap: Bitmap
if (settingsReadOnly.htmlShowPressStart) {
bitmap = Bitmap.createBitmap(640, 400, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
canvas.drawRGB(25, 118, 159)
val paint = Paint(Paint.ANTI_ALIAS_FLAG)
canvas.drawBitmap(logo, 192f, 16f, paint)

paint.textSize = 24f
paint.color = Color.WHITE
val bounds = Rect()
paint.getTextBounds(message, 0, message.length, bounds)
val x = (bitmap.width - bounds.width()) / 2f
canvas.drawText(message, x, 324f, paint)
} else {
bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888)
val canvas = Canvas(bitmap)
canvas.drawColor(settingsReadOnly.htmlBackColor)
}
return bitmap
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ interface Settings : SettingsReadOnly {
const val NOTIFY_SLOW_CONNECTIONS = "PREF_KEY_NOTIFY_SLOW_CONNECTIONS"

const val HTML_ENABLE_BUTTONS = "PREF_KEY_HTML_ENABLE_BUTTONS"
const val HTML_SHOW_PRESS_START = "PREF_KEY_HTML_SHOW_PRESS_START"
const val HTML_BACK_COLOR = "PREF_KEY_HTML_BACK_COLOR"

const val VR_MODE = "PREF_KEY_VR_MODE"
Expand Down Expand Up @@ -51,6 +52,7 @@ interface Settings : SettingsReadOnly {
const val NOTIFY_SLOW_CONNECTIONS = true

const val HTML_ENABLE_BUTTONS = false
const val HTML_SHOW_PRESS_START = true
const val HTML_BACK_COLOR = -16777216 // "ff000000".toLong(radix = 16).toInt()

const val VR_MODE_DISABLE = 0
Expand Down Expand Up @@ -100,6 +102,7 @@ interface Settings : SettingsReadOnly {
override var notifySlowConnections: Boolean

override var htmlEnableButtons: Boolean
override var htmlShowPressStart: Boolean
override var htmlBackColor: Int

override var vrMode: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class SettingsImpl(private val preferences: Preferences) : Settings {
override var htmlEnableButtons: Boolean
by bindPreference(preferences, Settings.Key.HTML_ENABLE_BUTTONS, Settings.Default.HTML_ENABLE_BUTTONS)

override var htmlShowPressStart: Boolean
by bindPreference(preferences, Settings.Key.HTML_SHOW_PRESS_START, Settings.Default.HTML_SHOW_PRESS_START)

override var htmlBackColor: Int
by bindPreference(preferences, Settings.Key.HTML_BACK_COLOR, Settings.Default.HTML_BACK_COLOR)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ interface SettingsReadOnly {
val notifySlowConnections: Boolean

val htmlEnableButtons: Boolean
val htmlShowPressStart: Boolean
val htmlBackColor: Int

val vrMode: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class AppStateMachineImpl(
private val broadcastHelper = BroadcastHelper.getInstance(context)
private val connectivityHelper: ConnectivityHelper = ConnectivityHelper.getInstance(context)
private val networkHelper = NetworkHelper(context)
private val notificationBitmap = NotificationBitmap(context)
private val notificationBitmap = NotificationBitmap(context, settingsReadOnly)
private val httpServer = HttpServer(
context, coroutineScope, settingsReadOnly, bitmapStateFlow.asStateFlow(),
notificationBitmap.getNotificationBitmap(NotificationBitmap.Type.ADDRESS_BLOCKED)
Expand Down

0 comments on commit d350620

Please sign in to comment.