Skip to content

Commit

Permalink
Fixed UI for Android TV (for d-pad usage).
Browse files Browse the repository at this point in the history
  • Loading branch information
Revertron committed Aug 26, 2023
1 parent ce50b01 commit 0c6c378
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 42 deletions.
10 changes: 5 additions & 5 deletions app/src/main/java/eu/neilalexander/yggdrasil/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ import android.graphics.Color
import android.net.VpnService
import android.os.Bundle
import android.widget.Switch
import android.widget.TableRow
import android.widget.TextView
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.LinearLayoutCompat
import androidx.core.content.edit
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import androidx.preference.PreferenceManager
Expand All @@ -26,10 +26,10 @@ class MainActivity : AppCompatActivity() {
private lateinit var subnetLabel: TextView
private lateinit var coordinatesLabel: TextView
private lateinit var peersLabel: TextView
private lateinit var peersRow: TableRow
private lateinit var peersRow: LinearLayoutCompat
private lateinit var dnsLabel: TextView
private lateinit var dnsRow: TableRow
private lateinit var settingsRow: TableRow
private lateinit var dnsRow: LinearLayoutCompat
private lateinit var settingsRow: LinearLayoutCompat

private fun start() {
val intent = Intent(this, PacketTunnelProvider::class.java)
Expand Down Expand Up @@ -82,7 +82,7 @@ class MainActivity : AppCompatActivity() {
preferences.edit(commit = true) { putBoolean(PREF_KEY_ENABLED, isChecked) }
}

val enableYggdrasilPanel = findViewById<TableRow>(R.id.enableYggdrasilPanel)
val enableYggdrasilPanel = findViewById<LinearLayoutCompat>(R.id.enableYggdrasilPanel)
enableYggdrasilPanel.setOnClickListener {
enabledSwitch.toggle()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class PeersActivity : AppCompatActivity() {
view.findViewById<ImageButton>(R.id.deletePeerButton).tag = i

view.findViewById<ImageButton>(R.id.deletePeerButton).setOnClickListener { button ->
val builder: AlertDialog.Builder = AlertDialog.Builder(this)
val builder: AlertDialog.Builder = AlertDialog.Builder(ContextThemeWrapper(this, R.style.Theme_MaterialComponents_DayNight_Dialog))
builder.setTitle(getString(R.string.peers_remove_title, peer))
builder.setPositiveButton(getString(R.string.peers_remove)) { dialog, _ ->
config.updateJSON { json ->
Expand Down
23 changes: 22 additions & 1 deletion app/src/main/java/eu/neilalexander/yggdrasil/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ import android.content.ClipData
import android.content.ClipboardManager
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.util.Log
import android.view.ContextThemeWrapper
import android.view.KeyEvent
import android.view.LayoutInflater
import android.view.View
import android.widget.*
import androidx.appcompat.widget.LinearLayoutCompat
import androidx.core.widget.doOnTextChanged
import org.json.JSONObject

Expand All @@ -18,7 +21,7 @@ class SettingsActivity : AppCompatActivity() {

private lateinit var deviceNameEntry: EditText
private lateinit var publicKeyLabel: TextView
private lateinit var resetConfigurationRow: TableRow
private lateinit var resetConfigurationRow: LinearLayoutCompat

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -41,6 +44,24 @@ class SettingsActivity : AppCompatActivity() {
}
}

deviceNameEntry.setOnKeyListener { view, keyCode, event ->
(keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER)
}

findViewById<View>(R.id.deviceNameTableRow).setOnKeyListener { view, keyCode, event ->
Log.i("Key", keyCode.toString())
if (event.action == KeyEvent.ACTION_DOWN) {
if (keyCode == KeyEvent.KEYCODE_DPAD_CENTER || keyCode == KeyEvent.KEYCODE_ENTER) {
deviceNameEntry.requestFocus()
true
} else {
false
}
} else {
false
}
}

resetConfigurationRow.setOnClickListener {
val view = inflater.inflate(R.layout.dialog_resetconfig, null)
val builder: AlertDialog.Builder = AlertDialog.Builder(ContextThemeWrapper(this, R.style.Theme_MaterialComponents_DayNight_Dialog))
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_dns.xml
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@
android:layout_marginStart="16pt"
android:layout_marginLeft="16pt"
android:layout_marginTop="4pt"
android:layout_marginBottom="4pt"
android:layout_marginEnd="8pt"
android:layout_marginRight="8pt"
android:alpha="0.7"
Expand Down
53 changes: 28 additions & 25 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textSize="12sp" />

<TableLayout
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/connectedPeersTableLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8pt"
Expand All @@ -70,7 +71,7 @@
android:paddingBottom="2pt"
android:showDividers="middle">

<TableRow
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/enableYggdrasilPanel"
style="@style/SelectableSwitchItemStyle">

Expand All @@ -92,9 +93,9 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</TableRow>
</androidx.appcompat.widget.LinearLayoutCompat>

<TableRow style="@style/SelectableItemStyle">
<androidx.appcompat.widget.LinearLayoutCompat style="@style/SelectableItemStyle">

<TextView
android:id="@+id/yggdrasilStatusLabel"
Expand All @@ -106,9 +107,9 @@
android:textSize="14sp"
android:textStyle="bold" />

</TableRow>
</androidx.appcompat.widget.LinearLayoutCompat>

</TableLayout>
</androidx.appcompat.widget.LinearLayoutCompat>

<Space
android:layout_width="match_parent"
Expand All @@ -130,8 +131,9 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textSize="12sp" />

<TableLayout
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/configuredPeersTableLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8pt"
Expand All @@ -148,7 +150,7 @@
android:paddingBottom="2pt"
android:showDividers="middle">

<TableRow style="@style/SelectableItemStyle">
<androidx.appcompat.widget.LinearLayoutCompat style="@style/SelectableItemStyle">

<TextView
android:id="@+id/ipAddressLabel"
Expand All @@ -172,9 +174,9 @@
android:textAlignment="viewEnd"
android:textIsSelectable="true"
android:textSize="14sp" />
</TableRow>
</androidx.appcompat.widget.LinearLayoutCompat>

<TableRow style="@style/SelectableItemStyle">
<androidx.appcompat.widget.LinearLayoutCompat style="@style/SelectableItemStyle">

<TextView
android:id="@+id/subnetLabel"
Expand All @@ -199,9 +201,9 @@
android:textIsSelectable="true"
android:textSize="14sp" />

</TableRow>
</androidx.appcompat.widget.LinearLayoutCompat>

<TableRow style="@style/SelectableItemStyle">
<androidx.appcompat.widget.LinearLayoutCompat style="@style/SelectableItemStyle">

<TextView
android:id="@+id/coordinatesLabel"
Expand All @@ -225,9 +227,9 @@
android:text="[]"
android:textAlignment="viewEnd"
android:textIsSelectable="true" />
</TableRow>
</androidx.appcompat.widget.LinearLayoutCompat>

</TableLayout>
</androidx.appcompat.widget.LinearLayoutCompat>

<Space
android:layout_width="match_parent"
Expand All @@ -249,16 +251,16 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textSize="12sp" />

<TableLayout
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/configurationTableLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8pt"
android:layout_marginLeft="8pt"
android:layout_marginEnd="8pt"
android:layout_marginRight="8pt"
android:background="@drawable/rounded"
android:clickable="true"
android:divider="#46878787"
android:dividerPadding="4pt"
android:paddingLeft="4pt"
Expand All @@ -267,7 +269,7 @@
android:paddingBottom="2pt"
android:showDividers="middle">

<TableRow
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/peersTableRow"
style="@style/SelectableItemStyle">

Expand Down Expand Up @@ -302,9 +304,9 @@
android:scaleX="1.2"
android:scaleY="1.2"
app:srcCompat="@drawable/ic_baseline_chevron_right_24" />
</TableRow>
</androidx.appcompat.widget.LinearLayoutCompat>

<TableRow
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/dnsTableRow"
style="@style/SelectableItemStyle">

Expand Down Expand Up @@ -339,9 +341,9 @@
android:scaleX="1.2"
android:scaleY="1.2"
app:srcCompat="@drawable/ic_baseline_chevron_right_24" />
</TableRow>
</androidx.appcompat.widget.LinearLayoutCompat>

<TableRow
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/settingsTableRow"
style="@style/SelectableItemStyle">

Expand Down Expand Up @@ -373,9 +375,9 @@
android:scaleY="1.2"
app:srcCompat="@drawable/ic_baseline_chevron_right_24" />

</TableRow>
</androidx.appcompat.widget.LinearLayoutCompat>

<TableRow style="@style/SelectableItemStyle">
<androidx.appcompat.widget.LinearLayoutCompat style="@style/SelectableItemStyle">

<TextView
android:id="@+id/versionLabel"
Expand All @@ -397,16 +399,17 @@
android:text="@string/main_unknown"
android:textAlignment="textEnd" />

</TableRow>
</androidx.appcompat.widget.LinearLayoutCompat>

</TableLayout>
</androidx.appcompat.widget.LinearLayoutCompat>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16pt"
android:layout_marginLeft="16pt"
android:layout_marginTop="4pt"
android:layout_marginBottom="4pt"
android:layout_marginEnd="8pt"
android:layout_marginRight="8pt"
android:alpha="0.7"
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_peers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
android:layout_marginStart="16pt"
android:layout_marginLeft="16pt"
android:layout_marginTop="4pt"
android:layout_marginBottom="4pt"
android:layout_marginEnd="8pt"
android:layout_marginRight="8pt"
android:alpha="0.7"
Expand Down
22 changes: 12 additions & 10 deletions app/src/main/res/layout/activity_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@
android:id="@+id/publicKeyLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:focusable="true"
android:fontFamily="monospace"
android:text="@string/public_key"
android:textSize="14sp" />
Expand Down Expand Up @@ -216,16 +217,16 @@
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textSize="12sp" />

<TableLayout
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/backupTableLayout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8pt"
android:layout_marginLeft="8pt"
android:layout_marginEnd="8pt"
android:layout_marginRight="8pt"
android:background="@drawable/rounded"
android:clickable="true"
android:divider="#46878787"
android:dividerPadding="4pt"
android:paddingLeft="4pt"
Expand All @@ -234,27 +235,27 @@
android:paddingBottom="2pt"
android:showDividers="middle">

<TableRow
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/resetKeysRow"
style="@style/SelectableItemStyle">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/regenerate_keys" />
</TableRow>
</androidx.appcompat.widget.LinearLayoutCompat>

<TableRow
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/setKeysRow"
style="@style/SelectableItemStyle">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/set_keys" />
</TableRow>
</androidx.appcompat.widget.LinearLayoutCompat>

<TableRow
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/resetConfigurationRow"
style="@style/SelectableItemStyle">

Expand All @@ -263,15 +264,16 @@
android:layout_height="wrap_content"
android:text="@string/reset_configuration"
android:textColor="@android:color/holo_red_dark" />
</TableRow>
</TableLayout>
</androidx.appcompat.widget.LinearLayoutCompat>
</androidx.appcompat.widget.LinearLayoutCompat>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16pt"
android:layout_marginLeft="16pt"
android:layout_marginTop="2pt"
android:layout_marginTop="4pt"
android:layout_marginBottom="4pt"
android:layout_marginEnd="8pt"
android:layout_marginRight="8pt"
android:alpha="0.7"
Expand Down

0 comments on commit 0c6c378

Please sign in to comment.