Commit 7e6cc4e8 authored by Mygod's avatar Mygod

Refine EditTextPreference layout

parent 4f3c7dd8
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright (C) 2015 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License
-->
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="48dp"
android:layout_marginBottom="48dp"
android:overScrollMode="ifContentScrolls">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="?attr/dialogPreferredPadding"
android:paddingEnd="?attr/dialogPreferredPadding"
android:orientation="vertical">
<TextView android:id="@android:id/message"
style="@style/TextAppearance.AppCompat.Subhead"
android:layout_marginBottom="48dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="?android:attr/textColorSecondary" />
<EditText
android:id="@android:id/edit"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
...@@ -25,6 +25,9 @@ import android.support.v7.preference.{EditTextPreference => Parent} ...@@ -25,6 +25,9 @@ import android.support.v7.preference.{EditTextPreference => Parent}
import android.support.v7.widget.AppCompatEditText import android.support.v7.widget.AppCompatEditText
import android.text.InputType import android.text.InputType
import android.util.AttributeSet import android.util.AttributeSet
import android.view.ViewGroup
import android.widget.FrameLayout
import com.github.shadowsocks.plugin.R
/** /**
* Fixed EditTextPreference + SummaryPreference with password support! * Fixed EditTextPreference + SummaryPreference with password support!
...@@ -35,6 +38,15 @@ class EditTextPreference(context: Context, attrs: AttributeSet = null) extends P ...@@ -35,6 +38,15 @@ class EditTextPreference(context: Context, attrs: AttributeSet = null) extends P
val editText = new AppCompatEditText(context, attrs) val editText = new AppCompatEditText(context, attrs)
editText.setId(android.R.id.edit) editText.setId(android.R.id.edit)
{
val arr = context.obtainStyledAttributes(Array(R.attr.dialogPreferredPadding))
val margin = arr.getDimensionPixelOffset(0, 0)
arr.recycle()
val params = new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
params.setMargins(margin, 0, margin, 0)
editText.setLayoutParams(params)
}
override def createDialog() = new EditTextPreferenceDialogFragment() override def createDialog() = new EditTextPreferenceDialogFragment()
override protected def getSummaryValue: String = { override protected def getSummaryValue: String = {
......
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
package be.mygod.preference package be.mygod.preference
import android.content.Context
import android.support.v14.preference.PreferenceDialogFragment import android.support.v14.preference.PreferenceDialogFragment
import android.support.v7.widget.AppCompatEditText import android.support.v7.widget.AppCompatEditText
import android.view.{View, ViewGroup} import android.view.{View, ViewGroup}
...@@ -29,17 +28,20 @@ class EditTextPreferenceDialogFragment extends PreferenceDialogFragment { ...@@ -29,17 +28,20 @@ class EditTextPreferenceDialogFragment extends PreferenceDialogFragment {
private lazy val preference = getPreference.asInstanceOf[EditTextPreference] private lazy val preference = getPreference.asInstanceOf[EditTextPreference]
protected lazy val editText: AppCompatEditText = preference.editText protected lazy val editText: AppCompatEditText = preference.editText
override protected def onCreateDialogView(context: Context): AppCompatEditText = {
val parent = editText.getParent.asInstanceOf[ViewGroup]
if (parent != null) parent.removeView(editText)
editText
}
override protected def onBindDialogView(view: View) { override protected def onBindDialogView(view: View) {
super.onBindDialogView(view) super.onBindDialogView(view)
editText.setText(preference.getText) editText.setText(preference.getText)
val text = editText.getText val text = editText.getText
if (text != null) editText.setSelection(0, text.length) if (text != null) editText.setSelection(0, text.length)
val oldParent = editText.getParent.asInstanceOf[ViewGroup]
if (oldParent eq view) return
if (oldParent != null) oldParent.removeView(editText)
val oldEdit = view.findViewById(android.R.id.edit)
if (oldEdit == null) return
val container = oldEdit.getParent.asInstanceOf[ViewGroup]
if (container == null) return
container.removeView(oldEdit)
container.addView(editText, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
} }
override protected def needInputMethod = true override protected def needInputMethod = true
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment