Support VPN over any native tethering
First big refactoring of this app.
This commit is contained in:
@@ -1,25 +0,0 @@
|
||||
package be.mygod.vpnhotspot.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.graphics.Rect
|
||||
import android.support.v7.widget.AppCompatAutoCompleteTextView
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import be.mygod.vpnhotspot.R
|
||||
|
||||
/**
|
||||
* Based on: https://gist.github.com/furycomptuers/4961368
|
||||
*/
|
||||
class AlwaysAutoCompleteEditText @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = R.attr.autoCompleteTextViewStyle) :
|
||||
AppCompatAutoCompleteTextView(context, attrs, defStyleAttr) {
|
||||
override fun enoughToFilter() = true
|
||||
|
||||
override fun onFocusChanged(focused: Boolean, direction: Int, previouslyFocusedRect: Rect?) {
|
||||
super.onFocusChanged(focused, direction, previouslyFocusedRect)
|
||||
if (focused && windowVisibility != View.GONE) {
|
||||
performFiltering(text, 0)
|
||||
showDropDown()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package be.mygod.vpnhotspot.preference
|
||||
|
||||
import android.content.Context
|
||||
import android.text.TextUtils
|
||||
import android.util.AttributeSet
|
||||
import be.mygod.vpnhotspot.R
|
||||
import com.takisoft.fix.support.v7.preference.AutoSummaryEditTextPreference
|
||||
|
||||
open class AlwaysAutoCompleteEditTextPreference @JvmOverloads constructor(
|
||||
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = R.attr.editTextPreferenceStyle,
|
||||
defStyleRes: Int = 0) : AutoSummaryEditTextPreference(context, attrs, defStyleAttr, defStyleRes) {
|
||||
val editText = AlwaysAutoCompleteEditText(context, attrs)
|
||||
|
||||
init {
|
||||
editText.id = android.R.id.edit
|
||||
}
|
||||
|
||||
override fun setText(text: String) {
|
||||
val oldText = getText()
|
||||
super.setText(text)
|
||||
if (!TextUtils.equals(text, oldText)) notifyChanged()
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package be.mygod.vpnhotspot.preference
|
||||
|
||||
import android.support.v7.preference.PreferenceDialogFragmentCompat
|
||||
import android.support.v7.widget.AppCompatAutoCompleteTextView
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.EditText
|
||||
|
||||
open class AlwaysAutoCompleteEditTextPreferenceDialogFragmentCompat : PreferenceDialogFragmentCompat() {
|
||||
companion object {
|
||||
const val KEY_SUGGESTIONS = "suggestions"
|
||||
}
|
||||
|
||||
private lateinit var editText: AppCompatAutoCompleteTextView
|
||||
private val editTextPreference get() = this.preference as AlwaysAutoCompleteEditTextPreference
|
||||
|
||||
override fun onBindDialogView(view: View) {
|
||||
super.onBindDialogView(view)
|
||||
|
||||
editText = editTextPreference.editText
|
||||
editText.setText(this.editTextPreference.text)
|
||||
|
||||
val text = editText.text
|
||||
if (text != null) editText.setSelection(text.length, text.length)
|
||||
|
||||
val suggestions = arguments?.getStringArray(KEY_SUGGESTIONS)
|
||||
if (suggestions != null)
|
||||
editText.setAdapter(ArrayAdapter(view.context, android.R.layout.select_dialog_item, suggestions))
|
||||
|
||||
val oldParent = editText.parent as? ViewGroup?
|
||||
if (oldParent !== view) {
|
||||
oldParent?.removeView(editText)
|
||||
onAddEditTextToDialogView(view, editText)
|
||||
}
|
||||
}
|
||||
|
||||
override fun needInputMethod(): Boolean = true
|
||||
|
||||
protected fun onAddEditTextToDialogView(dialogView: View, editText: EditText) {
|
||||
val oldEditText = dialogView.findViewById<View>(android.R.id.edit)
|
||||
if (oldEditText != null) {
|
||||
val container = oldEditText.parent as? ViewGroup?
|
||||
if (container != null) {
|
||||
container.removeView(oldEditText)
|
||||
container.addView(editText, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDialogClosed(positiveResult: Boolean) {
|
||||
if (positiveResult) {
|
||||
val value = this.editText.text.toString()
|
||||
if (this.editTextPreference.callChangeListener(value)) {
|
||||
this.editTextPreference.text = value
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user