Skip to content

Commit

Permalink
Android 12 compatibility (Part 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
dkrivoruchko committed Sep 10, 2021
1 parent 5e2efe8 commit b3a574f
Show file tree
Hide file tree
Showing 19 changed files with 81 additions and 59 deletions.
7 changes: 4 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,8 @@ dependencies {

implementation(project(":data"))

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-android:1.5.2")

implementation("androidx.core:core-ktx:1.6.0")
implementation("androidx.activity:activity-ktx:1.3.1")
Expand All @@ -97,6 +97,7 @@ dependencies {
implementation("androidx.constraintlayout:constraintlayout:2.1.0")
implementation("androidx.recyclerview:recyclerview:1.2.1")
implementation("com.google.android.material:material:1.4.0")
implementation("androidx.window:window:1.0.0-beta02")

implementation("androidx.navigation:navigation-fragment-ktx:2.4.0-alpha08")
implementation("androidx.navigation:navigation-ui-ktx:2.4.0-alpha08")
Expand All @@ -115,7 +116,7 @@ dependencies {
implementation("com.github.iamironz:binaryprefs:1.0.1")
implementation("com.elvishew:xlog:1.11.0")

firebaseImplementation("com.google.android.play:core:1.10.0")
firebaseImplementation("com.google.android.play:core:1.10.1")
firebaseImplementation("com.google.android.play:core-ktx:1.8.1") {
exclude group: "org.jetbrains.kotlin"
exclude group: "org.jetbrains.kotlinx"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package info.dvkr.screenstream.ui.fragment

import android.util.DisplayMetrics
import android.view.ViewTreeObserver
import android.widget.FrameLayout
import androidx.annotation.LayoutRes
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.window.layout.WindowMetricsCalculator
import com.google.android.gms.ads.AdRequest
import com.google.android.gms.ads.AdSize
import com.google.android.gms.ads.AdView
Expand All @@ -16,10 +16,6 @@ import kotlinx.coroutines.delay

abstract class AdFragment(@LayoutRes contentLayoutId: Int) : Fragment(contentLayoutId) {

private companion object {
private const val TEST_AD_UNIT_ID = "ca-app-pub-3940256099942544/6300978111"
}

private var adView: AdView? = null
private lateinit var adSize: AdSize

Expand All @@ -28,11 +24,10 @@ abstract class AdFragment(@LayoutRes contentLayoutId: Int) : Fragment(contentLay
else adViewContainer.viewTreeObserver.addOnGlobalLayoutListener(
object : ViewTreeObserver.OnGlobalLayoutListener {
override fun onGlobalLayout() {
val outMetrics =
DisplayMetrics().also { requireActivity().windowManager.defaultDisplay.getMetrics(it) }
var adWidthPixels = adViewContainer.width.toFloat()
if (adWidthPixels == 0f) adWidthPixels = outMetrics.widthPixels.toFloat()
val adWidth = (adWidthPixels / outMetrics.density).toInt()
if (adWidthPixels == 0f) adWidthPixels = WindowMetricsCalculator.getOrCreate()
.computeCurrentWindowMetrics(requireActivity()).bounds.width().toFloat()
val adWidth = (adWidthPixels / resources.displayMetrics.density).toInt()
adSize = AdSize.getCurrentOrientationAnchoredAdaptiveBannerAdSize(requireContext(), adWidth)

adViewContainer.viewTreeObserver.removeOnGlobalLayoutListener(this)
Expand All @@ -43,13 +38,13 @@ abstract class AdFragment(@LayoutRes contentLayoutId: Int) : Fragment(contentLay
}

private fun loadAd(adViewContainer: FrameLayout) {
adViewContainer.minimumHeight = adSize.getHeightInPixels(requireContext())
adViewContainer.minimumHeight = adSize.getHeightInPixels(requireActivity())
viewLifecycleOwner.lifecycleScope.launchWhenStarted {
delay((requireActivity().application as BaseApp).lastAdLoadTime + 61_000 - System.currentTimeMillis())
MobileAds.initialize(requireActivity()) {}
adView = AdView(requireActivity()).also { adView ->
adViewContainer.addView(adView)
adView.adUnitId = if (BuildConfig.DEBUG) TEST_AD_UNIT_ID else BuildConfig.AD_UNIT_ID;
adView.adUnitId = BuildConfig.AD_UNIT_ID
adView.adSize = adSize
adView.loadAd(AdRequest.Builder().build())
(requireActivity().application as BaseApp).lastAdLoadTime = System.currentTimeMillis()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ class AppService : Service() {
}

@SuppressLint("MissingPermission")
@Suppress("DEPRECATION")
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
val intentAction = IntentAction.fromIntent(intent)
intentAction != null || return START_NOT_STICKY
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ abstract class BaseActivity(@LayoutRes contentLayoutId: Int) : AppCompatActivity
XLog.d(getLog("onCreate", "Invoked"))
}

@Suppress("DEPRECATION")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
XLog.e(getLog("onActivityResult"), IllegalStateException("Unknown requestCode: $requestCode"))
super.onActivityResult(requestCode, resultCode, data)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ abstract class PermissionActivity(@LayoutRes contentLayoutId: Int) : ServiceActi
super.onSaveInstanceState(outState)
}

@Suppress("DEPRECATION")
override fun onServiceMessage(serviceMessage: ServiceMessage) {
super.onServiceMessage(serviceMessage)

Expand Down Expand Up @@ -70,7 +71,7 @@ abstract class PermissionActivity(@LayoutRes contentLayoutId: Int) : ServiceActi
}
}
}

@Suppress("DEPRECATION")
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (requestCode == SCREEN_CAPTURE_REQUEST_CODE) {
if (resultCode == Activity.RESULT_OK) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package info.dvkr.screenstream.ui.fragment

import android.graphics.Point
import android.graphics.Rect
import android.os.Bundle
import android.text.Editable
import android.text.InputFilter
import android.text.InputType
import android.text.TextWatcher
import android.view.View
import android.view.WindowManager
import android.view.inputmethod.EditorInfo
import android.widget.EditText
import android.widget.TextView
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.window.layout.WindowMetricsCalculator
import com.afollestad.materialdialogs.LayoutMode
import com.afollestad.materialdialogs.MaterialDialog
import com.afollestad.materialdialogs.WhichButton
Expand Down Expand Up @@ -57,11 +56,8 @@ class SettingsImageFragment : Fragment(R.layout.fragment_settings_image) {
}
}

private val screenSize: Point by lazy {
Point().apply {
ContextCompat.getSystemService(requireContext(), WindowManager::class.java)
?.defaultDisplay?.getRealSize(this)
}
private val screenBounds: Rect by lazy {
WindowMetricsCalculator.getOrCreate().computeMaximumWindowMetrics(requireActivity()).bounds
}

private val rotationList = listOf(
Expand Down Expand Up @@ -180,7 +176,7 @@ class SettingsImageFragment : Fragment(R.layout.fragment_settings_image) {
.apply Dialog@{
DialogSettingsResizeBinding.bind(getCustomView()).apply {
tvDialogSettingsResizeContent.text =
getString(R.string.pref_resize_dialog_text, screenSize.x, screenSize.y)
getString(R.string.pref_resize_dialog_text, screenBounds.width(), screenBounds.height())

tiDialogSettingsResize.isCounterEnabled = true
tiDialogSettingsResize.counterMaxLength = 3
Expand All @@ -193,8 +189,8 @@ class SettingsImageFragment : Fragment(R.layout.fragment_settings_image) {
(if (isValid) text.toString().toInt() else settings.resizeFactor) / 100f

tvDialogSettingsResizeResult.text = resizePictureSizeString.format(
(screenSize.x * newResizeFactor).toInt(),
(screenSize.y * newResizeFactor).toInt()
(screenBounds.width() * newResizeFactor).toInt(),
(screenBounds.height() * newResizeFactor).toInt()
)
})
setText(settings.resizeFactor.toString())
Expand All @@ -206,8 +202,8 @@ class SettingsImageFragment : Fragment(R.layout.fragment_settings_image) {
}

tvDialogSettingsResizeResult.text = resizePictureSizeString.format(
(screenSize.x * settings.resizeFactor / 100f).toInt(),
(screenSize.y * settings.resizeFactor / 100f).toInt()
(screenBounds.width() * settings.resizeFactor / 100f).toInt(),
(screenBounds.height() * settings.resizeFactor / 100f).toInt()
)

show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ class ExpansionHeader @JvmOverloads constructor(
expansionLayout?.removeListener(listener)
}

override fun onSaveInstanceState(): Parcelable? = Bundle().apply {
override fun onSaveInstanceState(): Parcelable = Bundle().apply {
putParcelable("super", super.onSaveInstanceState())

putInt("headerIndicatorId", headerIndicatorId)
Expand Down
10 changes: 5 additions & 5 deletions app/src/main/res/values-ar/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<string name="error_ip_address_not_found"> عنوان الانترنت غير موجود \n حاول تعطيل \"استخدام واي فاي فقط\" في الاعدادات </string>
<string name="error_wrong_image_format">يقوم النظام بإرجاع الصورة بتنسيق غير معروف .لا يوجد إصلاح المتاحة .آسف</string>
<string name="error_exit">خروج</string>
<string name="app_activity_collecting_logs">...جمع سجلات التطبيق</string>
<string name="app_activity_collecting_logs">جمع سجلات التطبيق</string>
<string name="app_activity_send_logs">إرسال السجلات إلى المطور</string>
<string name="app_activity_send_logs_dialog_title">إرسال سجلات في البريد الإلكتروني إلى مطور</string>
<string name="app_activity_send_logs_dialog_message"> : الرجاء إضافة وصف المشكلة</string>
Expand Down Expand Up @@ -44,7 +44,7 @@
<string name="notification_press_start">اضغط على بدء على الجهاز</string>
<string name="notification_start">ابدأ</string>
<string name="notification_exit">خروج</string>
<string name="notification_stream">...بث</string>
<string name="notification_stream">بث</string>
<string name="notification_press_stop">اضغط على وقف لإنهاء بث</string>
<string name="notification_stop">وقف</string>
<string name="toast_slow_client_connection">تم اكتشاف اتصال عميل بطيء</string>
Expand Down Expand Up @@ -93,13 +93,13 @@
<string name="pref_crop_dialog_error_message">أدخل قيم قص صالحة</string>
<string name="pref_resize">تغيير حجم الصورة</string>
<string name="pref_resize_summary">تغيير حجم الصورة قبل إرسالها إلى العميل</string>
<string name="pref_resize_dialog_text">تعيين عامل تغيير حجم الصورة في المئةالقيم: 10-150</string>
<string name="pref_resize_dialog_text">تعيين عامل تغيير حجم الصورة في المئةالقيم: 10150</string>
<string name="pref_resize_dialog_result">%1$dx%2$d حجم الصورة</string>
<string name="pref_rotate">تدوير الصورة في اتجاه عقارب الساعة</string>
<string name="pref_rotate_summary">تدوير الصورة قبل إرسالها إلى العميل</string>
<string name="pref_fps">الحد من صور في الثانية الواحدة</string>
<string name="pref_fps_summary">اضبط أقصى صور في الثانية</string>
<string name="pref_fps_dialog">عيّن الحد الأقصى للصور في الثانية. \ n القيم: 1-60 (افتراضيًا: 30)</string>
<string name="pref_fps_dialog">عيّن الحد الأقصى للصور في الثانية. \n القيم: 160 (افتراضيًا: 30)</string>
<string name="pref_jpeg_quality">جودة ضغط JPEG</string>
<string name="pref_jpeg_quality_summary">اضبط جودة ضغط JPEG</string>
<string name="pref_jpeg_quality_dialog">اضبط جودة ضغط JPEG. القيم: 10–100 (الافتراضي: 80)</string>
Expand Down Expand Up @@ -132,7 +132,7 @@
<string name="about_fragment_rate_app">قيم التطبيق</string>
<string name="about_fragment_write_email">إرسال بريد إلكتروني إلى المطور</string>
<string name="about_fragment_write_email_dialog">إرسال بريد إلكتروني إلى المطور؟</string>
<string name="about_fragment_email_chooser_header">...إرسال البريد الإلكتروني</string>
<string name="about_fragment_email_chooser_header">إرسال البريد الإلكتروني</string>
<string name="about_fragment_app_sources">مصادر التطبيق</string>
<string name="about_fragment_privacy_policy">سياسة الخصوصية</string>
</resources>
8 changes: 4 additions & 4 deletions app/src/main/res/values-ca/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<string name="error_ip_address_not_found">No s\'ha trobat l\'adreça IP. \nTproveu de desactivar \n"Utilitzeu només WiFi\n" a la configuració.</string>
<string name="error_wrong_image_format">El sistema retorna la imatge en un format desconegut. No hi ha cap correcció disponible. Excusa.</string>
<string name="error_exit">Encès</string>
<string name="app_activity_collecting_logs">S\'estan recopilant registres d\'aplicacions ...</string>
<string name="app_activity_collecting_logs">S\'estan recopilant registres d\'aplicacions </string>
<string name="app_activity_send_logs">Envieu registres al desenvolupador</string>

<string name="bottom_menu_stream">Stream</string>
Expand Down Expand Up @@ -71,7 +71,7 @@
<string name="pref_settings_image">Imatge</string>
<string name="pref_resize">Canviar la mida de la imatge</string>
<string name="pref_resize_summary">Canvieu la mida de la imatge abans d’enviar-la al client</string>
<string name="pref_resize_dialog_text">"Definiu el percentatge d’escala de la imatge. \nVvalors: 10-150 (valor per defecte: 50) \nMida de la pantalla: %1$dx%2$d"</string>
<string name="pref_resize_dialog_text">"Definiu el percentatge d’escala de la imatge. \nVvalors: 10150 (valor per defecte: 50) \nMida de la pantalla: %1$dx%2$d"</string>
<string name="pref_resize_dialog_result">Mida de la imatge: %1$dx%2$d</string>
<string name="pref_rotate">Gireu la imatge en sentit horari</string>
<string name="pref_rotate_summary">Gireu la imatge abans d\'enviar-la al client</string>
Expand All @@ -95,14 +95,14 @@
<string name="pref_wifi_only_summary">Executeu el servidor només a la interfície Wi-Fi</string>
<string name="pref_server_port">Port del servidor</string>
<string name="pref_server_port_summary">Estableix el port per a les connexions entrants</string>
<string name="pref_server_port_dialog">Definiu el port del servidor per a les connexions entrants. \nValors: 1025-65535 (valor per defecte: 8080)</string>
<string name="pref_server_port_dialog">Definiu el port del servidor per a les connexions entrants. \nValors: 102565535 (valor per defecte: 8080)</string>
<string name="pref_logging">Activa els registres d\'aplicacions</string>
<string name="pref_logging_summary">Recopileu registres d\'aplicacions</string>

<string name="about_fragment_app_version">Versió: %1$s</string>
<string name="about_fragment_developer_name">Desenvolupat per Dmitriy Krivoruchko</string>
<string name="about_fragment_rate_app">Valora l\'aplicació</string>
<string name="about_fragment_write_email">Envieu un correu electrònic al desenvolupador</string>
<string name="about_fragment_email_chooser_header">S\'està enviant el correu electrònic ...</string>
<string name="about_fragment_email_chooser_header">S\'està enviant el correu electrònic </string>
<string name="about_fragment_app_sources">Codis font de l\'aplicació</string>
</resources>
3 changes: 2 additions & 1 deletion data/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ android {
}

dependencies {
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.5.2")
implementation("org.jetbrains.kotlin:kotlin-reflect:1.5.30")

implementation("androidx.core:core:1.6.0")
implementation("androidx.window:window:1.0.0-beta02")

implementation("io.ktor:ktor-server-cio:1.6.3")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@

package com.android.grafika.gles;

import android.opengl.Matrix;

/**
* This class essentially represents a viewport-sized sprite that will be rendered with
* a texture, usually from an external source like the camera or video decoder.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import io.ktor.utils.io.*
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import java.io.ByteArrayOutputStream
import java.io.IOException
import java.net.BindException
import java.util.*
import java.util.concurrent.atomic.AtomicReference
Expand Down Expand Up @@ -110,7 +109,7 @@ internal class HttpServer(
}
serverAddresses.forEach { netInterface ->
connector {
host = netInterface.address.hostAddress
host = netInterface.address.hostAddress!!
port = settingsReadOnly.severPort
}
}
Expand Down
Loading

0 comments on commit b3a574f

Please sign in to comment.