mirror of
https://github.com/yggdrasil-network/crispa-android.git
synced 2024-11-12 21:41:05 +00:00
2. completed schema dropdown
This commit is contained in:
parent
f00d8b8af9
commit
aa00e9aeb4
@ -1,15 +1,15 @@
|
|||||||
package io.github.chronosx88.yggdrasil
|
package io.github.chronosx88.yggdrasil
|
||||||
|
|
||||||
import android.app.Activity
|
import android.app.Activity
|
||||||
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.*
|
||||||
import android.view.Menu
|
|
||||||
import android.view.MenuItem
|
|
||||||
import android.view.View
|
|
||||||
import android.widget.Button
|
import android.widget.Button
|
||||||
import android.widget.ListView
|
import android.widget.ListView
|
||||||
|
import android.widget.PopupWindow
|
||||||
|
import android.widget.TextView
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
import com.google.android.material.floatingactionbutton.FloatingActionButton
|
||||||
@ -18,6 +18,7 @@ import com.google.gson.reflect.TypeToken
|
|||||||
import com.hbb20.CCPCountry
|
import com.hbb20.CCPCountry
|
||||||
import io.github.chronosx88.yggdrasil.models.PeerInfo
|
import io.github.chronosx88.yggdrasil.models.PeerInfo
|
||||||
import io.github.chronosx88.yggdrasil.models.Status
|
import io.github.chronosx88.yggdrasil.models.Status
|
||||||
|
import io.github.chronosx88.yggdrasil.models.config.DropDownAdapter
|
||||||
import io.github.chronosx88.yggdrasil.models.config.SelectPeerInfoListAdapter
|
import io.github.chronosx88.yggdrasil.models.config.SelectPeerInfoListAdapter
|
||||||
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializeStringList2PeerInfoSet
|
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.deserializeStringList2PeerInfoSet
|
||||||
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.ping
|
import io.github.chronosx88.yggdrasil.models.config.Utils.Companion.ping
|
||||||
@ -52,6 +53,9 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
var isLoading = true;
|
var isLoading = true;
|
||||||
|
|
||||||
|
var popupAddress: PopupWindow? = null
|
||||||
|
var adapter: DropDownAdapter? = null
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.activity_peer_list)
|
setContentView(R.layout.activity_peer_list)
|
||||||
@ -128,12 +132,58 @@ class PeerListActivity : AppCompatActivity() {
|
|||||||
} else {
|
} else {
|
||||||
this.resources.configuration.locale.country
|
this.resources.configuration.locale.country
|
||||||
}
|
}
|
||||||
|
var schemaInput = view.findViewById<TextView>(R.id.schemaInput)
|
||||||
|
schemaInput.setOnFocusChangeListener { v, b ->
|
||||||
|
if(schemaInput.isFocused) {
|
||||||
|
val height = -1 * v.height +30
|
||||||
|
getAddressListPopup()?.showAsDropDown(v, -10, height)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
getPopupWindow(R.layout.spinner_item, resources.getStringArray(R.array.schemas), schemaInput, getString(R.string.schema));
|
||||||
view.findViewById<com.hbb20.CountryCodePicker>(R.id.ccp).setCountryForNameCode(countryCode)
|
view.findViewById<com.hbb20.CountryCodePicker>(R.id.ccp).setCountryForNameCode(countryCode)
|
||||||
val ab: AlertDialog.Builder = AlertDialog.Builder(this)
|
val ab: AlertDialog.Builder = AlertDialog.Builder(this)
|
||||||
ab.setCancelable(true).setView(view)
|
ab.setCancelable(true).setView(view)
|
||||||
ab.show()
|
ab.show()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun onClickSchemaList(v: View) {
|
||||||
|
val height = -1 * v.height +30
|
||||||
|
getAddressListPopup()?.showAsDropDown(v, -10, height)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getAddressListPopup(): PopupWindow? {
|
||||||
|
return popupAddress
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun getPopupWindow(
|
||||||
|
textViewResourceId: Int,
|
||||||
|
objects: Array<String>,
|
||||||
|
editText: TextView,
|
||||||
|
hint: String?
|
||||||
|
): PopupWindow? {
|
||||||
|
// initialize a pop up window type
|
||||||
|
val popupWindow = PopupWindow(this)
|
||||||
|
// the drop down list is a list view
|
||||||
|
val listView = ListView(this)
|
||||||
|
listView.dividerHeight = 0
|
||||||
|
// set our adapter and pass our pop up window contents
|
||||||
|
adapter = DropDownAdapter(this, textViewResourceId, objects, popupWindow, editText)
|
||||||
|
listView.adapter = adapter
|
||||||
|
// set the item click listener
|
||||||
|
listView.onItemClickListener = adapter
|
||||||
|
// some other visual settings
|
||||||
|
popupWindow.isFocusable = true
|
||||||
|
//popupWindow.setWidth(400);
|
||||||
|
val display: Display =
|
||||||
|
(this.getSystemService(Context.WINDOW_SERVICE) as WindowManager).getDefaultDisplay()
|
||||||
|
popupWindow.width = display.getWidth() - 230
|
||||||
|
popupWindow.height = WindowManager.LayoutParams.WRAP_CONTENT
|
||||||
|
// set the list view as pop up window content
|
||||||
|
popupWindow.contentView = listView
|
||||||
|
popupAddress = popupWindow
|
||||||
|
return popupWindow
|
||||||
|
}
|
||||||
|
|
||||||
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
override fun onCreateOptionsMenu(menu: Menu): Boolean {
|
||||||
// Inflate the menu; this adds items to the action bar if it is present.
|
// Inflate the menu; this adds items to the action bar if it is present.
|
||||||
menuInflater.inflate(R.menu.save, menu)
|
menuInflater.inflate(R.menu.save, menu)
|
||||||
|
@ -0,0 +1,69 @@
|
|||||||
|
package io.github.chronosx88.yggdrasil.models.config
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.view.LayoutInflater
|
||||||
|
import android.view.View
|
||||||
|
import android.view.ViewGroup
|
||||||
|
import android.view.animation.Animation
|
||||||
|
import android.view.animation.AnimationUtils
|
||||||
|
import android.widget.AdapterView
|
||||||
|
import android.widget.AdapterView.OnItemClickListener
|
||||||
|
import android.widget.ArrayAdapter
|
||||||
|
import android.widget.PopupWindow
|
||||||
|
import android.widget.TextView
|
||||||
|
import io.github.chronosx88.yggdrasil.R
|
||||||
|
|
||||||
|
|
||||||
|
class DropDownAdapter(
|
||||||
|
context: Context,
|
||||||
|
textViewResourceId: Int,
|
||||||
|
objects: Array<String>,
|
||||||
|
popup: PopupWindow,
|
||||||
|
editText: TextView
|
||||||
|
) :
|
||||||
|
ArrayAdapter<String?>(context, textViewResourceId, objects), OnItemClickListener {
|
||||||
|
|
||||||
|
private val objects: Array<String>
|
||||||
|
private val popup: PopupWindow
|
||||||
|
private val editText: TextView
|
||||||
|
override fun getDropDownView(position: Int, convertView: View?, parent: ViewGroup?): View? {
|
||||||
|
return getCustomView(position, convertView, parent)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||||
|
return getCustomView(position, convertView, parent)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getCustomView(position: Int, convertView: View?, parent: ViewGroup?): View {
|
||||||
|
var convertView: View? = convertView
|
||||||
|
if (convertView == null) {
|
||||||
|
convertView =
|
||||||
|
LayoutInflater.from(context).inflate(R.layout.dropdown_item, parent, false)
|
||||||
|
}
|
||||||
|
val sub = convertView?.findViewById(R.id.sub) as TextView
|
||||||
|
val address = objects[position]
|
||||||
|
sub.text = address
|
||||||
|
return convertView!!
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onItemClick(arg0: AdapterView<*>?, v: View, arg2: Int, arg3: Long) {
|
||||||
|
|
||||||
|
// get the context and main activity to access variables
|
||||||
|
// add some animation when a list item was clicked
|
||||||
|
val fadeInAnimation: Animation =
|
||||||
|
AnimationUtils.loadAnimation(context, android.R.anim.fade_in)
|
||||||
|
fadeInAnimation.duration = 10
|
||||||
|
v.startAnimation(fadeInAnimation)
|
||||||
|
val text: View = v.findViewById(R.id.sub) ?: return
|
||||||
|
val address = (text as TextView).text.toString()
|
||||||
|
// dismiss the pop up
|
||||||
|
popup.dismiss()
|
||||||
|
editText.text = address
|
||||||
|
}
|
||||||
|
|
||||||
|
init {
|
||||||
|
this.objects = objects
|
||||||
|
this.popup = popup
|
||||||
|
this.editText = editText
|
||||||
|
}
|
||||||
|
}
|
29
app/src/main/res/layout/dropdown_item.xml
Normal file
29
app/src/main/res/layout/dropdown_item.xml
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingLeft="15dp"
|
||||||
|
android:paddingRight="15dp"
|
||||||
|
android:paddingTop="12dp"
|
||||||
|
android:paddingBottom="12dp"
|
||||||
|
android:background="@drawable/info_panel_rounded_corner">
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:gravity="center_vertical">
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/icon"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/sub"
|
||||||
|
android:padding="10dp"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="14dp"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:hint="Schema"
|
||||||
|
android:ellipsize="middle"
|
||||||
|
android:singleLine="true"/>
|
||||||
|
</LinearLayout>
|
||||||
|
</RelativeLayout>
|
@ -2,7 +2,6 @@
|
|||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
xmlns:mask="http://schemas.android.com/tools"
|
|
||||||
android:padding="10dp"
|
android:padding="10dp"
|
||||||
android:background="@color/grey">
|
android:background="@color/grey">
|
||||||
|
|
||||||
@ -18,12 +17,14 @@
|
|||||||
android:textColorHint="@color/white"
|
android:textColorHint="@color/white"
|
||||||
style="@style/EditText.OutlinedBox">
|
style="@style/EditText.OutlinedBox">
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/schemaInput"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:hint="Schema"
|
android:hint="Schema"
|
||||||
android:textColor="@color/white"
|
android:textColor="@color/white"
|
||||||
android:inputType="text"
|
android:inputType="text"
|
||||||
android:textCursorDrawable="@null"/>
|
android:textCursorDrawable="@null"
|
||||||
|
android:onClick="onClickSchemaList"/>
|
||||||
</com.google.android.material.textfield.TextInputLayout>
|
</com.google.android.material.textfield.TextInputLayout>
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputLayout
|
<com.google.android.material.textfield.TextInputLayout
|
||||||
@ -39,6 +40,7 @@
|
|||||||
style="@style/EditText.OutlinedBox">
|
style="@style/EditText.OutlinedBox">
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/ipInput"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:digits="0123456789."
|
android:digits="0123456789."
|
||||||
@ -61,6 +63,7 @@
|
|||||||
style="@style/EditText.OutlinedBox">
|
style="@style/EditText.OutlinedBox">
|
||||||
|
|
||||||
<com.google.android.material.textfield.TextInputEditText
|
<com.google.android.material.textfield.TextInputEditText
|
||||||
|
android:id="@+id/portInput"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:digits="0123456789"
|
android:digits="0123456789"
|
||||||
|
14
app/src/main/res/layout/spinner_item.xml
Normal file
14
app/src/main/res/layout/spinner_item.xml
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:paddingLeft="20dp"
|
||||||
|
android:paddingRight="20dp"
|
||||||
|
android:paddingTop="15dp"
|
||||||
|
android:paddingBottom="15dp"
|
||||||
|
android:textSize="20dp"
|
||||||
|
android:gravity="left"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
/>
|
7
app/src/main/res/values/arrays.xml
Normal file
7
app/src/main/res/values/arrays.xml
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<string-array name="schemas">
|
||||||
|
<item>TCP</item>
|
||||||
|
<item>TLS</item>
|
||||||
|
</string-array>
|
||||||
|
</resources>
|
@ -6,4 +6,5 @@
|
|||||||
<string name="title_activity_peer_list">Edit peers</string>
|
<string name="title_activity_peer_list">Edit peers</string>
|
||||||
<string name="title_activity_dns_list">Edit DNS</string>
|
<string name="title_activity_dns_list">Edit DNS</string>
|
||||||
<string name="address_copied">Address copied</string>
|
<string name="address_copied">Address copied</string>
|
||||||
|
<string name="schema">Schema</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
Loading…
Reference in New Issue
Block a user