[fenix] No issue: Missing clear button in edit bookmarks UI
parent
45e634591a
commit
10a928c08f
@ -0,0 +1,50 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.utils
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.graphics.PorterDuff
|
||||
import android.graphics.PorterDuffColorFilter
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.util.AttributeSet
|
||||
import android.view.MotionEvent
|
||||
import androidx.appcompat.widget.AppCompatEditText
|
||||
import androidx.core.content.ContextCompat.getColor
|
||||
import org.mozilla.fenix.DefaultThemeManager
|
||||
import org.mozilla.fenix.R
|
||||
|
||||
class ClearableEditText @JvmOverloads
|
||||
constructor(
|
||||
context: Context,
|
||||
attrs: AttributeSet? = null,
|
||||
defStyleAttr: Int = R.attr.editTextStyle
|
||||
) :
|
||||
AppCompatEditText(context, attrs, defStyleAttr) {
|
||||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun onTouchEvent(event: MotionEvent?): Boolean {
|
||||
if (length() != 0 && event?.action == MotionEvent.ACTION_UP &&
|
||||
event.rawX >= (this@ClearableEditText.right - this@ClearableEditText.compoundPaddingRight)
|
||||
) {
|
||||
this@ClearableEditText.setText("")
|
||||
return true
|
||||
}
|
||||
return super.onTouchEvent(event)
|
||||
}
|
||||
|
||||
override fun onTextChanged(text: CharSequence?, start: Int, lengthBefore: Int, lengthAfter: Int) {
|
||||
super.onTextChanged(text, start, lengthBefore, lengthAfter)
|
||||
if (lengthAfter != 0 && error == null) {
|
||||
setCompoundDrawablesWithIntrinsicBounds(0, 0, R.drawable.ic_clear, 0)
|
||||
for (drawable: Drawable in compoundDrawables.filterNotNull()) {
|
||||
val color = DefaultThemeManager.resolveAttribute(R.attr.primaryText, context!!)
|
||||
drawable.colorFilter = PorterDuffColorFilter(getColor(context, color), PorterDuff.Mode.SRC_IN)
|
||||
}
|
||||
} else {
|
||||
setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="16dp"
|
||||
android:height="16dp"
|
||||
android:viewportWidth="16"
|
||||
android:viewportHeight="16">
|
||||
<path
|
||||
android:fillColor="?primaryText"
|
||||
android:pathData="M8,0a8,8 0,1 0,8 8,8 8,0 0,0 -8,-8zM12.243,10.828a1,1 0,0 1,-1.415 1.415L8,9.414l-2.828,2.829a1,1 0,0 1,-1.415 -1.415L6.586,8 3.757,5.172a1,1 0,0 1,1.415 -1.415L8,6.586l2.828,-2.829a1,1 0,0 1,1.415 1.415L9.414,8z"/>
|
||||
</vector>
|
Loading…
Reference in New Issue