mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
android tv search focus
This commit is contained in:
parent
3734871608
commit
40fd2fd49c
3 changed files with 18 additions and 30 deletions
|
@ -9,10 +9,8 @@ import android.content.pm.PackageManager
|
|||
import android.content.res.ColorStateList
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
import android.graphics.Rect
|
||||
import android.os.Build
|
||||
import android.os.Bundle
|
||||
import android.util.TypedValue
|
||||
import android.view.*
|
||||
import android.widget.TextView
|
||||
import android.widget.Toast
|
||||
|
@ -52,7 +50,6 @@ import kotlinx.android.synthetic.main.activity_main.*
|
|||
import kotlinx.android.synthetic.main.fragment_result.*
|
||||
import java.util.*
|
||||
import kotlin.concurrent.thread
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
|
||||
const val VLC_PACKAGE = "org.videolan.vlc"
|
||||
|
@ -140,28 +137,8 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
|||
}
|
||||
}
|
||||
|
||||
private fun Activity.getRootView(): View {
|
||||
return findViewById(android.R.id.content)
|
||||
}
|
||||
|
||||
private fun Context.convertDpToPx(dp: Float): Float {
|
||||
return TypedValue.applyDimension(
|
||||
TypedValue.COMPLEX_UNIT_DIP,
|
||||
dp,
|
||||
this.resources.displayMetrics
|
||||
)
|
||||
}
|
||||
|
||||
private fun Activity.isKeyboardOpen(): Boolean {
|
||||
val visibleBounds = Rect()
|
||||
this.getRootView().getWindowVisibleDisplayFrame(visibleBounds)
|
||||
val heightDiff = getRootView().height - visibleBounds.height()
|
||||
val marginOfError = this.convertDpToPx(50F).roundToInt()
|
||||
return heightDiff > marginOfError
|
||||
}
|
||||
|
||||
override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
|
||||
println("Keycode: $keyCode")
|
||||
//println("Keycode: $keyCode")
|
||||
//showToast(
|
||||
// this,
|
||||
// "Got Keycode $keyCode | ${KeyEvent.keyCodeToString(keyCode)} \n ${event?.action}",
|
||||
|
@ -222,11 +199,11 @@ class MainActivity : AppCompatActivity(), ColorPickerDialogListener {
|
|||
playerEventListener?.invoke(playerEvent)
|
||||
}
|
||||
|
||||
when (keyCode) {
|
||||
KeyEvent.KEYCODE_DPAD_CENTER -> {
|
||||
println("DPAD PRESSED ${this.isKeyboardOpen()}")
|
||||
}
|
||||
}
|
||||
//when (keyCode) {
|
||||
// KeyEvent.KEYCODE_DPAD_CENTER -> {
|
||||
// println("DPAD PRESSED ${this.isKeyboardOpen()}")
|
||||
// }
|
||||
//}
|
||||
|
||||
return super.onKeyDown(keyCode, event)
|
||||
}
|
||||
|
|
|
@ -300,6 +300,8 @@ class SearchFragment : Fragment() {
|
|||
main_search.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
|
||||
override fun onQueryTextSubmit(query: String): Boolean {
|
||||
searchViewModel.searchAndCancel(query)
|
||||
main_search?.clearFocus()
|
||||
search_filter?.requestFocus()
|
||||
return true
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,9 @@
|
|||
<com.google.android.material.switchmaterial.SwitchMaterial
|
||||
android:id="@+id/toggle1"
|
||||
|
||||
android:nextFocusLeft="@id/apply_btt"
|
||||
android:nextFocusRight="@id/cancel_btt"
|
||||
|
||||
android:layout_marginTop="10dp"
|
||||
android:paddingStart="20dp"
|
||||
android:paddingEnd="20dp"
|
||||
|
@ -24,12 +27,15 @@
|
|||
tools:text="Search"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<requestFocus/>
|
||||
</com.google.android.material.switchmaterial.SwitchMaterial>
|
||||
<ListView
|
||||
android:nextFocusRight="@id/cancel_btt"
|
||||
android:nextFocusLeft="@id/apply_btt"
|
||||
|
||||
android:nextFocusUp="@id/toggle1"
|
||||
android:nextFocusDown="@id/apply_btt"
|
||||
|
||||
android:id="@+id/listview1"
|
||||
android:layout_marginTop="-10dp"
|
||||
android:layout_marginBottom="60dp"
|
||||
|
@ -43,6 +49,9 @@
|
|||
android:nextFocusRight="@id/cancel_btt"
|
||||
android:nextFocusLeft="@id/apply_btt"
|
||||
|
||||
android:nextFocusUp="@id/toggle1"
|
||||
android:nextFocusDown="@id/apply_btt"
|
||||
|
||||
android:id="@+id/listview2"
|
||||
android:layout_marginTop="-10dp"
|
||||
android:layout_marginBottom="60dp"
|
||||
|
|
Loading…
Reference in a new issue