Redesign WifiP2pDialog using design lib
This commit is contained in:
@@ -5,6 +5,7 @@ import android.content.DialogInterface
|
||||
import android.net.wifi.WifiConfiguration
|
||||
import android.net.wifi.WifiConfiguration.AuthAlgorithm
|
||||
import android.os.Bundle
|
||||
import android.support.design.widget.TextInputLayout
|
||||
import android.support.v7.app.AlertDialog
|
||||
import android.text.Editable
|
||||
import android.text.InputType
|
||||
@@ -20,8 +21,7 @@ import java.nio.charset.Charset
|
||||
* https://android.googlesource.com/platform/packages/apps/Settings/+/39b4674/src/com/android/settings/wifi/WifiApDialog.java
|
||||
*/
|
||||
class WifiP2pDialog(mContext: Context, private val mListener: DialogInterface.OnClickListener,
|
||||
private val mWifiConfig: WifiConfiguration?) :
|
||||
AlertDialog(mContext), View.OnClickListener, TextWatcher {
|
||||
private val mWifiConfig: WifiConfiguration?) : AlertDialog(mContext), TextWatcher {
|
||||
companion object {
|
||||
private const val BUTTON_SUBMIT = DialogInterface.BUTTON_POSITIVE
|
||||
}
|
||||
@@ -29,12 +29,6 @@ class WifiP2pDialog(mContext: Context, private val mListener: DialogInterface.On
|
||||
private lateinit var mView: View
|
||||
private lateinit var mSsid: TextView
|
||||
private lateinit var mPassword: EditText
|
||||
/**
|
||||
* TODO: SSID in WifiConfiguration for soft ap
|
||||
* is being stored as a raw string without quotes.
|
||||
* This is not the case on the client side. We need to
|
||||
* make things consistent and clean it up
|
||||
*/
|
||||
val config: WifiConfiguration?
|
||||
get() {
|
||||
val config = WifiConfiguration()
|
||||
@@ -64,30 +58,17 @@ class WifiP2pDialog(mContext: Context, private val mListener: DialogInterface.On
|
||||
}
|
||||
mSsid.addTextChangedListener(this)
|
||||
mPassword.addTextChangedListener(this)
|
||||
(mView.findViewById(R.id.show_password) as CheckBox).setOnClickListener(this)
|
||||
super.onCreate(savedInstanceState)
|
||||
validate()
|
||||
}
|
||||
|
||||
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
||||
super.onRestoreInstanceState(savedInstanceState)
|
||||
mPassword.inputType = InputType.TYPE_CLASS_TEXT or
|
||||
if ((mView.findViewById(R.id.show_password) as CheckBox).isChecked)
|
||||
InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
|
||||
else InputType.TYPE_TEXT_VARIATION_PASSWORD
|
||||
}
|
||||
|
||||
private fun validate() {
|
||||
val mSsidString = mSsid.text.toString()
|
||||
getButton(BUTTON_SUBMIT).isEnabled = mSsid.length() != 0 &&
|
||||
mPassword.length() >= 8 && Charset.forName("UTF-8").encode(mSsidString).limit() <= 32
|
||||
}
|
||||
|
||||
override fun onClick(view: View) {
|
||||
mPassword.inputType = InputType.TYPE_CLASS_TEXT or if ((view as CheckBox).isChecked)
|
||||
InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
|
||||
else
|
||||
InputType.TYPE_TEXT_VARIATION_PASSWORD
|
||||
val ssidValid = mSsid.length() != 0 && Charset.forName("UTF-8").encode(mSsidString).limit() <= 32
|
||||
val passwordValid = mPassword.length() >= 8
|
||||
mView.findViewById<TextInputLayout>(R.id.password_wrapper).error =
|
||||
if (passwordValid) null else context.getString(R.string.credentials_password_too_short)
|
||||
getButton(BUTTON_SUBMIT).isEnabled = ssidValid && passwordValid
|
||||
}
|
||||
|
||||
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { }
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
limitations under the License.
|
||||
-->
|
||||
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="300sp"
|
||||
android:layout_height="wrap_content"
|
||||
android:fadeScrollbars="false">
|
||||
@@ -20,74 +21,38 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:descendantFocusability="beforeDescendants"
|
||||
android:focusableInTouchMode="true"
|
||||
android:orientation="vertical">
|
||||
<LinearLayout android:id="@+id/info"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_section" />
|
||||
<LinearLayout android:id="@+id/type"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_section">
|
||||
<LinearLayout
|
||||
style="@style/wifi_item">
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/ssid_wrapper"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dip"
|
||||
android:layout_marginBottom="8dip">
|
||||
<android.support.design.widget.TextInputEditText
|
||||
android:id="@+id/ssid"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item">
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item_label"
|
||||
android:layout_marginTop="8dip"
|
||||
android:text="@string/wifi_ssid" />
|
||||
<EditText android:id="@+id/ssid"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item_edit_content"
|
||||
android:hint="@string/wifi_ssid_hint"
|
||||
android:inputType="textMultiLine|textNoSuggestions"
|
||||
android:maxLength="32" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
<LinearLayout android:id="@+id/fields"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_section">
|
||||
<LinearLayout
|
||||
style="@style/wifi_item_edit_content"
|
||||
android:hint="@string/wifi_ssid"
|
||||
android:inputType="textMultiLine|textNoSuggestions"
|
||||
android:maxLength="32" />
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
<android.support.design.widget.TextInputLayout
|
||||
android:id="@+id/password_wrapper"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:passwordToggleEnabled="true"
|
||||
app:errorEnabled="true">
|
||||
<android.support.design.widget.TextInputEditText
|
||||
android:id="@+id/password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item">
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item_label"
|
||||
android:layout_marginTop="8dip"
|
||||
android:text="@string/wifi_password" />
|
||||
<EditText android:id="@+id/password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item_edit_content"
|
||||
android:singleLine="true"
|
||||
android:inputType="textPassword"
|
||||
android:maxLength="63"
|
||||
android:imeOptions="flagForceAscii" />
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item">
|
||||
<TextView android:id="@+id/hint"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item_label"
|
||||
android:text="@string/credentials_password_too_short"
|
||||
android:layout_marginTop="8dip"
|
||||
android:layout_marginBottom="10sp"/>
|
||||
<CheckBox android:id="@+id/show_password"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
style="@style/wifi_item_content"
|
||||
android:text="@string/wifi_show_password" />
|
||||
</LinearLayout>
|
||||
</LinearLayout>
|
||||
style="@style/wifi_item_edit_content"
|
||||
android:singleLine="true"
|
||||
android:hint="@string/wifi_password"
|
||||
android:inputType="textPassword"
|
||||
android:maxLength="63"
|
||||
android:imeOptions="flagForceAscii" />
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
</LinearLayout>
|
||||
</ScrollView>
|
||||
|
||||
@@ -77,9 +77,7 @@
|
||||
<string name="noisy_su_failure">发生异常,详情请查看调试信息。</string>
|
||||
|
||||
<string name="wifi_ssid" msgid="5519636102673067319">"网络名称"</string>
|
||||
<string name="wifi_ssid_hint" msgid="897593601067321355">"输入 SSID"</string>
|
||||
<string name="wifi_password" msgid="5948219759936151048">"密码"</string>
|
||||
<string name="wifi_show_password" msgid="6461249871236968884">"显示密码"</string>
|
||||
<string name="credentials_password_too_short" msgid="7502749986405522663">"密码至少应包含 8 个字符。"</string>
|
||||
<string name="wifi_save" msgid="3331121567988522826">"保存"</string>
|
||||
<string name="wifi_cancel" msgid="6763568902542968964">"取消"</string>
|
||||
|
||||
@@ -82,9 +82,7 @@
|
||||
<string name="noisy_su_failure">Something went wrong, please check the debug information.</string>
|
||||
|
||||
<string name="wifi_ssid">Network name</string>
|
||||
<string name="wifi_ssid_hint">Enter the SSID</string>
|
||||
<string name="wifi_password">Password</string>
|
||||
<string name="wifi_show_password">Show password</string>
|
||||
<string name="credentials_password_too_short">The password must have at least 8 characters.</string>
|
||||
<string name="wifi_save">Save</string>
|
||||
<string name="wifi_cancel">Cancel</string>
|
||||
|
||||
@@ -23,25 +23,10 @@
|
||||
<item name="android:orientation">vertical</item>
|
||||
<item name="android:gravity">start</item>
|
||||
</style>
|
||||
<style name="wifi_item_label">
|
||||
<item name="android:paddingStart">8dip</item>
|
||||
<item name="android:textSize">14sp</item>
|
||||
<item name="android:textAlignment">viewStart</item>
|
||||
<item name="android:textAppearance">@android:style/TextAppearance.Material.Body1</item>
|
||||
<item name="android:textColor">?android:attr/textColorSecondary</item>
|
||||
</style>
|
||||
<style name="wifi_item_edit_content">
|
||||
<item name="android:paddingStart">4dip</item>
|
||||
<item name="android:layout_marginStart">4dip</item>
|
||||
<item name="android:textSize">18sp</item>
|
||||
</style>
|
||||
<style name="wifi_section">
|
||||
<item name="android:orientation">vertical</item>
|
||||
</style>
|
||||
<style name="wifi_item_content">
|
||||
<item name="android:textAlignment">viewStart</item>
|
||||
<item name="android:textAppearance">@android:style/TextAppearance.Material.Subhead</item>
|
||||
<item name="android:textColor">?android:attr/textColorPrimary</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user