fix: make Android TV setup usable on Android 9

Fixes #144
This commit is contained in:
kuekhaoyang
2026-04-07 22:23:15 +08:00
parent a380ed4133
commit e93c259e4a
3 changed files with 107 additions and 81 deletions
+3 -2
View File
@@ -6,7 +6,7 @@
<uses-feature
android:name="android.software.leanback"
android:required="true" />
android:required="false" />
<uses-feature
android:name="android.hardware.touchscreen"
@@ -28,7 +28,8 @@
android:name=".MainActivity"
android:configChanges="orientation|screenSize|keyboardHidden"
android:exported="true"
android:screenOrientation="landscape">
android:screenOrientation="landscape"
android:windowSoftInputMode="adjustResize">
<!-- Leanback launcher (Android TV home) -->
<intent-filter>
@@ -7,6 +7,7 @@ import android.os.Bundle
import android.view.KeyEvent
import android.view.View
import android.view.WindowManager
import android.view.inputmethod.EditorInfo
import android.webkit.WebChromeClient
import android.webkit.WebSettings
import android.webkit.WebView
@@ -59,6 +60,24 @@ class MainActivity : ComponentActivity() {
saveButton.setOnClickListener {
openConfiguredUrl()
}
urlInput.setOnEditorActionListener { _, actionId, event ->
val isKeyboardConfirmAction = actionId == EditorInfo.IME_NULL ||
actionId == EditorInfo.IME_ACTION_DONE ||
actionId == EditorInfo.IME_ACTION_GO ||
actionId == EditorInfo.IME_ACTION_SEND ||
actionId == EditorInfo.IME_ACTION_NEXT
val isEnterKey = event?.action == KeyEvent.ACTION_DOWN && (
event.keyCode == KeyEvent.KEYCODE_ENTER ||
event.keyCode == KeyEvent.KEYCODE_NUMPAD_ENTER
)
if (isKeyboardConfirmAction || isEnterKey) {
openConfiguredUrl()
true
} else {
false
}
}
webView.apply {
setLayerType(View.LAYER_TYPE_HARDWARE, null)
@@ -9,101 +9,107 @@
android:layout_width="match_parent"
android:layout_height="match_parent" />
<LinearLayout
<ScrollView
android:id="@+id/setup_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#E6101115"
android:gravity="center"
android:orientation="vertical"
android:padding="32dp">
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#F31A1C22"
android:elevation="12dp"
android:maxWidth="680dp"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
android:padding="32dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/setup_title"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/setup_description"
android:textColor="#D7DBE5"
android:textSize="18sp" />
<EditText
android:id="@+id/url_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:background="#FF0D0F14"
android:hint="@string/setup_hint"
android:importantForAutofill="no"
android:imeOptions="actionDone"
android:inputType="textUri"
android:minHeight="56dp"
android:paddingHorizontal="18dp"
android:paddingVertical="14dp"
android:singleLine="true"
android:textColor="#FFFFFF"
android:textColorHint="#7D8597"
android:textSize="20sp" />
<TextView
android:id="@+id/status_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:text="@string/status_ready"
android:textColor="#F5B942"
android:textSize="16sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:gravity="center_vertical"
android:orientation="horizontal">
android:background="#F31A1C22"
android:elevation="12dp"
android:maxWidth="680dp"
android:orientation="vertical"
android:padding="32dp">
<Button
android:id="@+id/open_button"
android:layout_width="0dp"
android:layout_height="56dp"
android:layout_weight="1"
android:text="@string/button_open_saved"
android:textAllCaps="false"
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/setup_title"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:textStyle="bold" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/setup_description"
android:textColor="#D7DBE5"
android:textSize="18sp" />
<Button
android:id="@+id/save_button"
android:layout_width="0dp"
android:layout_height="56dp"
android:layout_marginStart="16dp"
android:layout_weight="1"
android:text="@string/button_save"
android:textAllCaps="false"
android:textSize="18sp" />
<EditText
android:id="@+id/url_input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:background="#FF0D0F14"
android:hint="@string/setup_hint"
android:importantForAutofill="no"
android:imeOptions="actionDone"
android:inputType="textUri"
android:minHeight="56dp"
android:paddingHorizontal="18dp"
android:paddingVertical="14dp"
android:singleLine="true"
android:textColor="#FFFFFF"
android:textColorHint="#7D8597"
android:textSize="20sp" />
<TextView
android:id="@+id/status_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="14dp"
android:text="@string/status_ready"
android:textColor="#F5B942"
android:textSize="16sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
android:gravity="center_vertical"
android:orientation="horizontal">
<Button
android:id="@+id/open_button"
android:layout_width="0dp"
android:layout_height="56dp"
android:layout_weight="1"
android:text="@string/button_open_saved"
android:textAllCaps="false"
android:textSize="18sp" />
<Button
android:id="@+id/save_button"
android:layout_width="0dp"
android:layout_height="56dp"
android:layout_marginStart="16dp"
android:layout_weight="1"
android:text="@string/button_save"
android:textAllCaps="false"
android:textSize="18sp" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/setup_footer"
android:textColor="#9EA7BA"
android:textSize="15sp" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:text="@string/setup_footer"
android:textColor="#9EA7BA"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</FrameLayout>