Make system tethering entry always available

This commit is contained in:
Mygod
2018-01-15 13:40:32 -08:00
parent 3a3e6b8689
commit 67aa86f0f7
7 changed files with 30 additions and 46 deletions

View File

@@ -13,16 +13,16 @@ import android.support.v7.util.SortedList
import android.support.v7.widget.DefaultItemAnimator import android.support.v7.widget.DefaultItemAnimator
import android.support.v7.widget.LinearLayoutManager import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView import android.support.v7.widget.RecyclerView
import android.text.Html import android.support.v7.widget.Toolbar
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.MenuItem
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import be.mygod.vpnhotspot.App.Companion.app import be.mygod.vpnhotspot.App.Companion.app
import be.mygod.vpnhotspot.databinding.FragmentTetheringBinding import be.mygod.vpnhotspot.databinding.FragmentTetheringBinding
import be.mygod.vpnhotspot.databinding.ListitemInterfaceBinding import be.mygod.vpnhotspot.databinding.ListitemInterfaceBinding
import be.mygod.vpnhotspot.widget.TextViewLinkHandler
class TetheringFragment : Fragment() { class TetheringFragment : Fragment(), Toolbar.OnMenuItemClickListener {
companion object { companion object {
/** /**
* Source: https://android.googlesource.com/platform/frameworks/base/+/61fa313/core/res/res/values/config.xml#328 * Source: https://android.googlesource.com/platform/frameworks/base/+/61fa313/core/res/res/values/config.xml#328
@@ -115,11 +115,8 @@ class TetheringFragment : Fragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_tethering, container, false) binding = DataBindingUtil.inflate(inflater, R.layout.fragment_tethering, container, false)
binding.empty.text = Html.fromHtml(getString(R.string.tethering_no_interfaces)) binding.toolbar.inflateMenu(R.menu.tethering)
binding.empty.movementMethod = TextViewLinkHandler.create { binding.toolbar.setOnMenuItemClickListener(this)
startActivity(Intent().setClassName("com.android.settings",
"com.android.settings.Settings\$TetherSettingsActivity"))
}
binding.interfaces.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false) binding.interfaces.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
val animator = DefaultItemAnimator() val animator = DefaultItemAnimator()
animator.supportsChangeAnimations = false // prevent fading-in/out when rebinding animator.supportsChangeAnimations = false // prevent fading-in/out when rebinding
@@ -149,6 +146,15 @@ class TetheringFragment : Fragment() {
super.onStop() super.onStop()
} }
override fun onMenuItemClick(item: MenuItem) = when (item.itemId) {
R.id.systemTethering -> {
startActivity(Intent().setClassName("com.android.settings",
"com.android.settings.Settings\$TetherSettingsActivity"))
true
}
else -> false
}
private fun crossFade(old: View, new: View) { private fun crossFade(old: View, new: View) {
val shortAnimTime = resources.getInteger(android.R.integer.config_shortAnimTime).toLong() val shortAnimTime = resources.getInteger(android.R.integer.config_shortAnimTime).toLong()
old.animate().alpha(0F).setListener(object : AnimatorListenerAdapter() { old.animate().alpha(0F).setListener(object : AnimatorListenerAdapter() {

View File

@@ -1,32 +0,0 @@
package be.mygod.vpnhotspot.widget
import android.text.Spannable
import android.text.method.LinkMovementMethod
import android.text.style.URLSpan
import android.view.MotionEvent
import android.widget.TextView
/**
* Based on: https://stackoverflow.com/a/32443884/2245107
*/
abstract class TextViewLinkHandler : LinkMovementMethod() {
companion object {
fun create(handler: (String) -> Unit) = object : TextViewLinkHandler() {
override fun onLinkClick(url: String) = handler(url)
}
}
override fun onTouchEvent(widget: TextView, buffer: Spannable, event: MotionEvent): Boolean {
if (event.action != MotionEvent.ACTION_UP) return super.onTouchEvent(widget, buffer, event)
val x = event.x - widget.totalPaddingLeft + widget.scrollX
val y = event.y.toInt() - widget.totalPaddingTop + widget.scrollY
val layout = widget.layout
val line = layout.getLineForVertical(y)
val off = layout.getOffsetForHorizontal(line, x)
val link = buffer.getSpans(off, off, URLSpan::class.java)
if (link.isNotEmpty()) onLinkClick(link[0].url)
return true
}
abstract fun onLinkClick(url: String)
}

View File

@@ -4,6 +4,6 @@
android:viewportWidth="24.0" android:viewportWidth="24.0"
android:viewportHeight="24.0"> android:viewportHeight="24.0">
<path <path
android:fillColor="#fff" android:fillColor="#000"
android:pathData="M19.43,12.98c0.04,-0.32 0.07,-0.64 0.07,-0.98s-0.03,-0.66 -0.07,-0.98l2.11,-1.65c0.19,-0.15 0.24,-0.42 0.12,-0.64l-2,-3.46c-0.12,-0.22 -0.39,-0.3 -0.61,-0.22l-2.49,1c-0.52,-0.4 -1.08,-0.73 -1.69,-0.98l-0.38,-2.65C14.46,2.18 14.25,2 14,2h-4c-0.25,0 -0.46,0.18 -0.49,0.42l-0.38,2.65c-0.61,0.25 -1.17,0.59 -1.69,0.98l-2.49,-1c-0.23,-0.09 -0.49,0 -0.61,0.22l-2,3.46c-0.13,0.22 -0.07,0.49 0.12,0.64l2.11,1.65c-0.04,0.32 -0.07,0.65 -0.07,0.98s0.03,0.66 0.07,0.98l-2.11,1.65c-0.19,0.15 -0.24,0.42 -0.12,0.64l2,3.46c0.12,0.22 0.39,0.3 0.61,0.22l2.49,-1c0.52,0.4 1.08,0.73 1.69,0.98l0.38,2.65c0.03,0.24 0.24,0.42 0.49,0.42h4c0.25,0 0.46,-0.18 0.49,-0.42l0.38,-2.65c0.61,-0.25 1.17,-0.59 1.69,-0.98l2.49,1c0.23,0.09 0.49,0 0.61,-0.22l2,-3.46c0.12,-0.22 0.07,-0.49 -0.12,-0.64l-2.11,-1.65zM12,15.5c-1.93,0 -3.5,-1.57 -3.5,-3.5s1.57,-3.5 3.5,-3.5 3.5,1.57 3.5,3.5 -1.57,3.5 -3.5,3.5z"/> android:pathData="M19.43,12.98c0.04,-0.32 0.07,-0.64 0.07,-0.98s-0.03,-0.66 -0.07,-0.98l2.11,-1.65c0.19,-0.15 0.24,-0.42 0.12,-0.64l-2,-3.46c-0.12,-0.22 -0.39,-0.3 -0.61,-0.22l-2.49,1c-0.52,-0.4 -1.08,-0.73 -1.69,-0.98l-0.38,-2.65C14.46,2.18 14.25,2 14,2h-4c-0.25,0 -0.46,0.18 -0.49,0.42l-0.38,2.65c-0.61,0.25 -1.17,0.59 -1.69,0.98l-2.49,-1c-0.23,-0.09 -0.49,0 -0.61,0.22l-2,3.46c-0.13,0.22 -0.07,0.49 0.12,0.64l2.11,1.65c-0.04,0.32 -0.07,0.65 -0.07,0.98s0.03,0.66 0.07,0.98l-2.11,1.65c-0.19,0.15 -0.24,0.42 -0.12,0.64l2,3.46c0.12,0.22 0.39,0.3 0.61,0.22l2.49,-1c0.52,0.4 1.08,0.73 1.69,0.98l0.38,2.65c0.03,0.24 0.24,0.42 0.49,0.42h4c0.25,0 0.46,-0.18 0.49,-0.42l0.38,-2.65c0.61,-0.25 1.17,-0.59 1.69,-0.98l2.49,1c0.23,0.09 0.49,0 0.61,-0.22l2,-3.46c0.12,-0.22 0.07,-0.49 -0.12,-0.64l-2.11,-1.65zM12,15.5c-1.93,0 -3.5,-1.57 -3.5,-3.5s1.57,-3.5 3.5,-3.5 3.5,1.57 3.5,3.5 -1.57,3.5 -3.5,3.5z"/>
</vector> </vector>

View File

@@ -22,9 +22,8 @@
android:id="@+id/empty" android:id="@+id/empty"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:linksClickable="true"
android:padding="16dp" android:padding="16dp"
tools:text="@string/tethering_no_interfaces"/> android:text="@string/tethering_no_interfaces"/>
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/interfaces" android:id="@+id/interfaces"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<item
android:id="@+id/systemTethering"
android:icon="@drawable/ic_action_settings"
android:title="@string/tethering_system_tethering"
app:showAsAction="ifRoom"/>
</menu>

View File

@@ -35,7 +35,8 @@
<string name="repeater_failure_reason_no_service_requests">未添加服务请求</string> <string name="repeater_failure_reason_no_service_requests">未添加服务请求</string>
<string name="repeater_failure_reason_unknown">未知 #%d</string> <string name="repeater_failure_reason_unknown">未知 #%d</string>
<string name="tethering_no_interfaces"><![CDATA[请先打开<a href=&quot;#&quot;>系统共享</a>后使用此功能。]]></string> <string name="tethering_system_tethering">系统共享</string>
<string name="tethering_no_interfaces">请先打开系统共享后使用此功能。</string>
<string name="settings_service">服务</string> <string name="settings_service">服务</string>
<string name="settings_service_dns">下游 DNS 服务器:端口</string> <string name="settings_service_dns">下游 DNS 服务器:端口</string>

View File

@@ -37,8 +37,8 @@
<string name="repeater_failure_reason_no_service_requests">no service requests added</string> <string name="repeater_failure_reason_no_service_requests">no service requests added</string>
<string name="repeater_failure_reason_unknown">unknown #%d</string> <string name="repeater_failure_reason_unknown">unknown #%d</string>
<string name="tethering_no_interfaces"><![CDATA[To use this feature, turn on any <a href=&quot;#&quot;>system <string name="tethering_system_tethering">System tethering</string>
tethering</a> first.]]></string> <string name="tethering_no_interfaces">To use this feature, turn on any system tethering first.</string>
<string name="settings_service">Service</string> <string name="settings_service">Service</string>
<string name="settings_service_dns">Downstream DNS server:port</string> <string name="settings_service_dns">Downstream DNS server:port</string>