Skip to content
Snippets Groups Projects
Commit 48ab596e authored by Nicolas Pomepuy's avatar Nicolas Pomepuy Committed by Duncan McNamara
Browse files

Use a virtual keyboard for the PIN code on TV

parent b12917ec
No related branches found
No related tags found
1 merge request!1753Parental control
<!--
~ *************************************************************************
~ ic_backspace.xml
~ **************************************************************************
~ Copyright © 2020 VLC authors and VideoLAN
~ Author: Nicolas POMEPUY
~ This program is free software; you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation; either version 2 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program; if not, write to the Free Software
~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
~ ***************************************************************************
~
~
-->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:viewportWidth="48"
android:viewportHeight="48">
<path
android:pathData="m37,36c1.662,0 3,-1.338 3,-3L40,15c0,-1.662 -1.338,-3 -3,-3L18,12 17.6035,12c-0.9988,0.0001 -1.931,0.4979 -2.4883,1.3262L8,24 15.1152,34.6738C15.6725,35.5021 16.6047,35.9999 17.6035,36L18,36ZM22,17 L27,22 32,17 34,19 29,24 34,29 32,31 27,26 22,31 20,29 25,24 20,19z"
android:strokeAlpha="1"
android:strokeLineJoin="miter"
android:strokeWidth="1"
android:fillColor="@color/white"
android:strokeColor="#00000000"
android:fillType="evenOdd"
android:fillAlpha="1"
android:strokeLineCap="butt" />
</vector>
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:drawable="@drawable/keyboard_button_background_focused"/>
<item android:state_selected="true" android:drawable="@drawable/keyboard_button_background_focused"/>
<item android:state_pressed="true" android:drawable="@drawable/keyboard_button_background_focused"/>
<item android:drawable="@drawable/keyboard_button_background_normal" />
</selector>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--
~ *************************************************************************
~ keyboard_button_background_focused.xml
~ **************************************************************************
~ Copyright © 2023 VLC authors and VideoLAN
~ Author: Nicolas POMEPUY
~ This program is free software; you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation; either version 2 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program; if not, write to the Free Software
~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
~ ***************************************************************************
~
~
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="8dp"/>
<solid android:color="@color/tv_card_content_dark" />
</shape>
\ No newline at end of file
<?xml version="1.0" encoding="utf-8"?>
<!--
~ *************************************************************************
~ keyboard_button_background_normal.xml
~ **************************************************************************
~ Copyright © 2023 VLC authors and VideoLAN
~ Author: Nicolas POMEPUY
~ This program is free software; you can redistribute it and/or modify
~ it under the terms of the GNU General Public License as published by
~ the Free Software Foundation; either version 2 of the License, or
~ (at your option) any later version.
~
~ This program is distributed in the hope that it will be useful,
~ but WITHOUT ANY WARRANTY; without even the implied warranty of
~ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
~ GNU General Public License for more details.
~
~ You should have received a copy of the GNU General Public License
~ along with this program; if not, write to the Free Software
~ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
~ ***************************************************************************
~
~
-->
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="8dp"/>
<solid android:color="@color/black_transparent_80" />
</shape>
\ No newline at end of file
......@@ -172,6 +172,7 @@ dependencies {
api "androidx.room:room-runtime:$rootProject.ext.roomVersion"
api "androidx.window:window:1.0.0"
api "androidx.media:media:1.6.0"
api 'androidx.gridlayout:gridlayout:1.0.0'
kapt ('org.xerial:sqlite-jdbc:3.36.0')
kapt("androidx.room:room-compiler:$rootProject.ext.roomVersion")
......
......@@ -44,6 +44,7 @@
android:layout_marginEnd="32dp"
android:textSize="16sp"
android:textColor="?attr/font_default"
android:gravity="center"
tools:text="@string/safe_mode_pin"
vlc:layout_constraintEnd_toEndOf="parent"
vlc:layout_constraintStart_toStartOf="parent"
......@@ -53,6 +54,7 @@
android:id="@+id/pin_code_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginStart="32dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="32dp"
......@@ -86,6 +88,115 @@
android:singleLine="true" />
</com.google.android.material.textfield.TextInputLayout>
<androidx.gridlayout.widget.GridLayout
android:id="@+id/keyboard_grid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:visibility="gone"
tools:visibility="visible"
vlc:columnCount="3"
vlc:rowCount="4"
vlc:useDefaultMargins="true"
vlc:layout_constraintEnd_toEndOf="parent"
vlc:layout_constraintStart_toStartOf="parent"
vlc:layout_constraintTop_toBottomOf="@+id/pin_code_parent">
<TextView
android:id="@+id/keyboard_button_1"
style="@style/KeyboardButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:tag="1"
android:text="1" />
<TextView
android:id="@+id/keyboard_button_2"
style="@style/KeyboardButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:tag="2"
android:text="2" />
<TextView
android:id="@+id/keyboard_button_3"
style="@style/KeyboardButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:tag="3"
android:text="3" />
<TextView
android:id="@+id/keyboard_button_4"
style="@style/KeyboardButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:tag="4"
android:text="4" />
<TextView
android:id="@+id/keyboard_button_5"
style="@style/KeyboardButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:tag="5"
android:text="5" />
<TextView
android:id="@+id/keyboard_button_6"
style="@style/KeyboardButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:tag="6"
android:text="6" />
<TextView
android:id="@+id/keyboard_button_7"
style="@style/KeyboardButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:tag="7"
android:text="7" />
<TextView
android:id="@+id/keyboard_button_8"
style="@style/KeyboardButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:tag="8"
android:text="8" />
<TextView
android:id="@+id/keyboard_button_9"
style="@style/KeyboardButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:tag="9"
android:text="9" />
<TextView
android:id="@+id/keyboard_button_0"
style="@style/KeyboardButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:tag="0"
android:text="0" />
<ImageView
android:id="@+id/keyboard_button_clear"
style="@style/KeyboardButton"
android:layout_width="48dp"
android:layout_height="48dp"
android:contentDescription="@string/delete"
android:scaleType="center"
android:padding="4dp"
vlc:layout_columnSpan="2"
vlc:layout_columnWeight="2"
android:tag="-1"
vlc:srcCompat="@drawable/ic_backspace_white" />
</androidx.gridlayout.widget.GridLayout>
<Button
android:id="@+id/cancel_button"
......
......@@ -544,6 +544,15 @@
<item name="android:textColor">@color/white</item>
</style>
<style name="KeyboardButton">
<item name="android:background">@drawable/keyboard_button_background</item>
<item name="android:focusable">true</item>
<item name="android:fontFamily">sans-serif-medium</item>
<item name="android:gravity">center</item>
<item name="android:textSize">16sp</item>
<item name="android:elevation">0dp</item>
</style>
<style name="VLC.Onboarding.Text" parent="TextAppearance.AppCompat.Headline">
<item name="android:textSize">16sp</item>
<item name="android:fontFamily">sans-serif</item>
......
......@@ -24,12 +24,17 @@
package org.videolan.vlc.gui
import android.annotation.SuppressLint
import android.app.Application
import android.content.Context
import android.content.Intent
import android.os.Build
import android.os.Bundle
import android.text.InputType
import android.view.KeyEvent
import android.view.MenuItem
import android.view.inputmethod.EditorInfo
import androidx.core.view.children
import androidx.core.widget.doOnTextChanged
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.AndroidViewModel
......@@ -40,6 +45,7 @@ import org.videolan.resources.util.applyOverscanMargin
import org.videolan.tools.KEY_SAFE_MODE_PIN
import org.videolan.tools.Settings
import org.videolan.tools.putSingle
import org.videolan.tools.setVisible
import org.videolan.vlc.R
import org.videolan.vlc.databinding.PinCodeActivityBinding
import org.videolan.vlc.gui.helpers.UiTools
......@@ -61,6 +67,7 @@ class PinCodeActivity : BaseActivity() {
override fun getSnackAnchorView(overAudioPlayer: Boolean) = binding.root
override val displayTitle = true
@SuppressLint("SetTextI18n")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
......@@ -68,7 +75,21 @@ class PinCodeActivity : BaseActivity() {
reason = PinCodeReason.values() [intent.getIntExtra(PIN_CODE_REASON, 0)]
binding = DataBindingUtil.setContentView(this, R.layout.pin_code_activity)
binding.pinCode.requestFocus()
if (!Settings.tvUI) {
binding.pinCode.requestFocus()
} else {
binding.keyboardButton1.requestFocus()
}
if (Settings.tvUI) {
binding.pinCode.setOnTouchListener { v, event -> true }
if (Build.VERSION.SDK_INT >= 21) {
binding.pinCode.showSoftInputOnFocus = false
} else {
binding.pinCode.setRawInputType(InputType.TYPE_CLASS_TEXT)
binding.pinCode.setTextIsSelectable(true)
}
}
if (Settings.tvUI) binding.keyboardGrid.setVisible()
UiTools.setKeyboardVisibility(binding.pinCode, true)
binding.pinCodeReason.text = getString(when (reason) {
PinCodeReason.FIRST_CREATION -> R.string.pin_code_reason_create
......@@ -106,7 +127,7 @@ class PinCodeActivity : BaseActivity() {
binding.pinCode.imeOptions = EditorInfo.IME_ACTION_DONE
binding.nextButton.text = getString(R.string.done)
}
binding.pinCode.requestFocus()
if (!Settings.tvUI) binding.pinCode.requestFocus()
}
binding.pinCode.setOnEditorActionListener { v, actionId, event ->
......@@ -124,6 +145,14 @@ class PinCodeActivity : BaseActivity() {
}
setResult(RESULT_CANCELED)
if (AndroidDevices.isTv) applyOverscanMargin(this)
binding.keyboardGrid.children.forEach {
it.setOnClickListener { keyboardButton ->
when (keyboardButton.tag) {
"-1" -> binding.pinCode.setText(binding.pinCode.text.toString().replaceFirst(".$".toRegex(), ""))
else -> binding.pinCode.setText(binding.pinCode.text.toString() + keyboardButton.tag)
}
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment