Merged PR 252409: PeoplePicker: Create proxy api for TokenClickStyle
Because we exposed `TokenClickStyle` in `PeoplePickerView`, we had to use `api 'com.splitwise:tokenautocomplete:2.0.8@aar'` instead of the desired `implementation 'com.splitwise:tokenautocomplete:2.0.8@aar'` in gradle. To get around this, I created a "proxy" enum, `PersonaChipClickStyle` to port our click style to `TokenCompleteTextView`. All functionality should remain the same. Related work items: #706980
This commit is contained in:
Родитель
6164493020
Коммит
475e3f07af
|
@ -9,8 +9,8 @@ import android.os.Bundle
|
|||
import android.view.ViewGroup
|
||||
import android.widget.LinearLayout
|
||||
import com.microsoft.officeuifabric.peoplepicker.PeoplePickerAccessibilityTextProvider
|
||||
import com.microsoft.officeuifabric.peoplepicker.PeoplePickerPersonaChipClickStyle
|
||||
import com.microsoft.officeuifabric.peoplepicker.PeoplePickerView
|
||||
import com.microsoft.officeuifabric.peoplepicker.PeoplePickerPersonaChipClickStyle
|
||||
import com.microsoft.officeuifabric.persona.IPersona
|
||||
import com.microsoft.officeuifabric.snackbar.Snackbar
|
||||
import com.microsoft.officeuifabricdemo.DemoActivity
|
||||
|
@ -74,12 +74,12 @@ class PeoplePickerViewActivity : DemoActivity() {
|
|||
setupPeoplePickerView(
|
||||
getString(R.string.people_picker_none_example),
|
||||
samplePersonas,
|
||||
PeoplePickerPersonaChipClickStyle.None
|
||||
PeoplePickerPersonaChipClickStyle.NONE
|
||||
)
|
||||
setupPeoplePickerView(
|
||||
getString(R.string.people_picker_delete_example),
|
||||
samplePersonas,
|
||||
PeoplePickerPersonaChipClickStyle.Delete
|
||||
PeoplePickerPersonaChipClickStyle.DELETE
|
||||
)
|
||||
setupPeoplePickerView(
|
||||
getString(R.string.people_picker_picked_personas_listener),
|
||||
|
@ -105,7 +105,7 @@ class PeoplePickerViewActivity : DemoActivity() {
|
|||
private fun setupPeoplePickerView(
|
||||
labelText: String,
|
||||
availablePersonas: ArrayList<IPersona> = ArrayList(),
|
||||
personaChipClickStyle: PeoplePickerPersonaChipClickStyle = PeoplePickerPersonaChipClickStyle.Select,
|
||||
personaChipClickStyle: PeoplePickerPersonaChipClickStyle = PeoplePickerPersonaChipClickStyle.SELECT,
|
||||
personaSuggestionsListener: PeoplePickerView.PersonaSuggestionsListener? = null,
|
||||
pickedPersonasChangeListener: PeoplePickerView.PickedPersonasChangeListener? = null
|
||||
) {
|
||||
|
|
|
@ -56,7 +56,7 @@ dependencies {
|
|||
implementation 'com.android.support:design:28.0.0'
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
implementation 'com.jakewharton.threetenabp:threetenabp:1.1.0'
|
||||
api 'com.splitwise:tokenautocomplete:2.0.8@aar'
|
||||
implementation 'com.splitwise:tokenautocomplete:2.0.8'
|
||||
androidTestImplementation 'com.android.support.test:runner:1.0.2'
|
||||
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.2'
|
||||
testImplementation 'junit:junit:4.12'
|
||||
|
|
|
@ -41,12 +41,23 @@ import com.microsoft.officeuifabric.util.getTextSize
|
|||
import com.tokenautocomplete.CountSpan
|
||||
import com.tokenautocomplete.TokenCompleteTextView
|
||||
|
||||
enum class PeoplePickerPersonaChipClickStyle(internal val tokenClickStyle: TokenCompleteTextView.TokenClickStyle) {
|
||||
// Do nothing, but make sure the cursor is not in the persona chip.
|
||||
NONE(TokenCompleteTextView.TokenClickStyle.None),
|
||||
// Delete the persona chip.
|
||||
DELETE(TokenCompleteTextView.TokenClickStyle.Delete),
|
||||
// Select the persona chip. A second click will delete it.
|
||||
SELECT(TokenCompleteTextView.TokenClickStyle.Select),
|
||||
// Select the persona chip. A second click will deselect it.
|
||||
SELECT_DESELECT(TokenCompleteTextView.TokenClickStyle.SelectDeselect)
|
||||
}
|
||||
|
||||
/**
|
||||
* [PeoplePickerTextView] provides all of the functionality needed to add [PersonaChipView]s as [tokens]
|
||||
* into an [EditText] view.
|
||||
*
|
||||
* Functionality we add in addition to [TokenCompleteTextView]'s functionality includes:
|
||||
* - Click api for SelectDeselect persona chips
|
||||
* - Click api for SELECT_DESELECT persona chips
|
||||
* - Drag and drop option
|
||||
* - Accessibility
|
||||
* - Hiding the cursor when a persona chip is selected
|
||||
|
@ -70,10 +81,10 @@ internal class PeoplePickerTextView : TokenCompleteTextView<IPersona> {
|
|||
/**
|
||||
* Defines what happens when a user clicks on a persona chip.
|
||||
*/
|
||||
var personaChipClickStyle: PeoplePickerPersonaChipClickStyle = PeoplePickerPersonaChipClickStyle.Select
|
||||
var personaChipClickStyle: PeoplePickerPersonaChipClickStyle = PeoplePickerPersonaChipClickStyle.SELECT
|
||||
set(value) {
|
||||
field = value
|
||||
setTokenClickStyle(value)
|
||||
setTokenClickStyle(value.tokenClickStyle)
|
||||
}
|
||||
/**
|
||||
* Flag for enabling Drag and Drop persona chips.
|
||||
|
@ -106,7 +117,7 @@ internal class PeoplePickerTextView : TokenCompleteTextView<IPersona> {
|
|||
}
|
||||
|
||||
/**
|
||||
* When a persona chip with a [PeoplePickerPersonaChipClickStyle] of SelectDeselect is selected,
|
||||
* When a persona chip with a [PeoplePickerPersonaChipClickStyle] of SELECT_DESELECT is selected,
|
||||
* the next touch will fire [PersonaChipClickListener.onClick].
|
||||
*/
|
||||
var personaChipClickListener: PeoplePickerView.PersonaChipClickListener? = null
|
||||
|
@ -160,7 +171,7 @@ internal class PeoplePickerTextView : TokenCompleteTextView<IPersona> {
|
|||
|
||||
override fun getViewForObject(`object`: IPersona): View {
|
||||
val view = PersonaChipView(context)
|
||||
view.showCloseIconWhenSelected = personaChipClickStyle == PeoplePickerPersonaChipClickStyle.Select
|
||||
view.showCloseIconWhenSelected = personaChipClickStyle == PeoplePickerPersonaChipClickStyle.SELECT
|
||||
view.listener = object : PersonaChipView.Listener {
|
||||
override fun onClicked() {
|
||||
// no op
|
||||
|
@ -547,7 +558,7 @@ internal class PeoplePickerTextView : TokenCompleteTextView<IPersona> {
|
|||
// This declares whether personaChipClickListener could be called
|
||||
private fun isPersonaChipClickable(persona: IPersona): Boolean =
|
||||
selectedPersona != null &&
|
||||
personaChipClickStyle == PeoplePickerPersonaChipClickStyle.SelectDeselect &&
|
||||
personaChipClickStyle == PeoplePickerPersonaChipClickStyle.SELECT_DESELECT &&
|
||||
persona == selectedPersona
|
||||
|
||||
private fun getClipDataForPersona(persona: IPersona): ClipData? {
|
||||
|
@ -917,13 +928,13 @@ internal class PeoplePickerTextView : TokenCompleteTextView<IPersona> {
|
|||
val persona = personaSpan.token
|
||||
val personaSpanIndex = getPersonaSpans<TokenCompleteTextView<IPersona>.TokenImageSpan>().indexOf(personaSpan)
|
||||
when (personaChipClickStyle) {
|
||||
PeoplePickerPersonaChipClickStyle.Select, PeoplePickerPersonaChipClickStyle.SelectDeselect -> {
|
||||
PeoplePickerPersonaChipClickStyle.SELECT, PeoplePickerPersonaChipClickStyle.SELECT_DESELECT -> {
|
||||
if (selectedPersona != null && selectedPersona == persona) {
|
||||
invalidateVirtualView(personaSpanIndex)
|
||||
sendEventForVirtualView(personaSpanIndex, AccessibilityEvent.TYPE_VIEW_CLICKED)
|
||||
sendEventForVirtualView(personaSpanIndex, AccessibilityEvent.TYPE_VIEW_SELECTED)
|
||||
} else {
|
||||
if (personaChipClickStyle == PeoplePickerPersonaChipClickStyle.SelectDeselect) {
|
||||
if (personaChipClickStyle == PeoplePickerPersonaChipClickStyle.SELECT_DESELECT) {
|
||||
if (personaChipClickListener != null) {
|
||||
personaChipClickListener?.onClick(persona)
|
||||
announceForAccessibility(resources.getString(
|
||||
|
@ -938,11 +949,11 @@ internal class PeoplePickerTextView : TokenCompleteTextView<IPersona> {
|
|||
}
|
||||
}
|
||||
sendEventForVirtualView(personaSpanIndex, AccessibilityEvent.TYPE_VIEW_CLICKED)
|
||||
if (personaChipClickStyle == PeoplePickerPersonaChipClickStyle.Select && personaSpanIndex == -1)
|
||||
if (personaChipClickStyle == PeoplePickerPersonaChipClickStyle.SELECT && personaSpanIndex == -1)
|
||||
invalidateRoot()
|
||||
}
|
||||
}
|
||||
PeoplePickerPersonaChipClickStyle.Delete -> {
|
||||
PeoplePickerPersonaChipClickStyle.DELETE -> {
|
||||
sendEventForVirtualView(personaSpanIndex, AccessibilityEvent.TYPE_VIEW_CLICKED)
|
||||
sendEventForVirtualView(personaSpanIndex, AccessibilityEvent.TYPE_VIEW_ACCESSIBILITY_FOCUS_CLEARED)
|
||||
}
|
||||
|
@ -950,7 +961,7 @@ internal class PeoplePickerTextView : TokenCompleteTextView<IPersona> {
|
|||
}
|
||||
|
||||
private fun setPersonaSpanClickAction(personaSpan: TokenImageSpan, node: AccessibilityNodeInfoCompat) {
|
||||
if (personaChipClickStyle == PeoplePickerPersonaChipClickStyle.None)
|
||||
if (personaChipClickStyle == PeoplePickerPersonaChipClickStyle.NONE)
|
||||
return
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||
|
@ -970,9 +981,9 @@ internal class PeoplePickerTextView : TokenCompleteTextView<IPersona> {
|
|||
private fun getActionText(personaSpan: TokenImageSpan): String {
|
||||
return if (personaSpan.token == selectedPersona) {
|
||||
when (personaChipClickStyle) {
|
||||
PeoplePickerPersonaChipClickStyle.Select ->
|
||||
PeoplePickerPersonaChipClickStyle.SELECT ->
|
||||
resources.getString(R.string.people_picker_accessibility_delete_persona)
|
||||
PeoplePickerPersonaChipClickStyle.SelectDeselect ->
|
||||
PeoplePickerPersonaChipClickStyle.SELECT_DESELECT ->
|
||||
if (personaChipClickListener != null)
|
||||
resources.getString(R.string.people_picker_accessibility_click_persona)
|
||||
else
|
||||
|
@ -981,9 +992,9 @@ internal class PeoplePickerTextView : TokenCompleteTextView<IPersona> {
|
|||
}
|
||||
} else {
|
||||
when (personaChipClickStyle) {
|
||||
PeoplePickerPersonaChipClickStyle.Select, PeoplePickerPersonaChipClickStyle.SelectDeselect ->
|
||||
PeoplePickerPersonaChipClickStyle.SELECT, PeoplePickerPersonaChipClickStyle.SELECT_DESELECT ->
|
||||
resources.getString(R.string.people_picker_accessibility_select_persona)
|
||||
PeoplePickerPersonaChipClickStyle.Delete ->
|
||||
PeoplePickerPersonaChipClickStyle.DELETE ->
|
||||
resources.getString(R.string.people_picker_accessibility_delete_persona)
|
||||
else -> ""
|
||||
}
|
||||
|
@ -999,9 +1010,9 @@ internal class PeoplePickerTextView : TokenCompleteTextView<IPersona> {
|
|||
return ""
|
||||
|
||||
return when (personaChipClickStyle) {
|
||||
PeoplePickerPersonaChipClickStyle.Select ->
|
||||
PeoplePickerPersonaChipClickStyle.SELECT ->
|
||||
resources.getString(R.string.people_picker_accessibility_delete_selected_persona)
|
||||
PeoplePickerPersonaChipClickStyle.SelectDeselect ->
|
||||
PeoplePickerPersonaChipClickStyle.SELECT_DESELECT ->
|
||||
if (personaChipClickListener != null)
|
||||
resources.getString(R.string.people_picker_accessibility_click_selected_persona)
|
||||
else
|
||||
|
|
|
@ -20,8 +20,6 @@ import com.microsoft.officeuifabric.view.TemplateView
|
|||
import com.tokenautocomplete.TokenCompleteTextView
|
||||
import kotlinx.android.synthetic.main.view_people_picker.view.*
|
||||
|
||||
typealias PeoplePickerPersonaChipClickStyle = TokenCompleteTextView.TokenClickStyle
|
||||
|
||||
/**
|
||||
* [PeoplePickerView] is a customizable view comprised of a label and [PeoplePickerTextView].
|
||||
*
|
||||
|
@ -102,10 +100,10 @@ class PeoplePickerView : TemplateView {
|
|||
}
|
||||
/**
|
||||
* Defines what happens when a user clicks on a persona chip.
|
||||
* To use your own onClick callback, set this property to [PeoplePickerPersonaChipClickStyle.SelectDeselect]
|
||||
* To use your own onClick callback, set this property to [PeoplePickerPersonaChipClickStyle.SELECT_DESELECT]
|
||||
* and set the [personaChipClickListener]'s onClick callback.
|
||||
*/
|
||||
var personaChipClickStyle: PeoplePickerPersonaChipClickStyle = PeoplePickerPersonaChipClickStyle.Select
|
||||
var personaChipClickStyle: PeoplePickerPersonaChipClickStyle = PeoplePickerPersonaChipClickStyle.SELECT
|
||||
set(value) {
|
||||
if (field == value)
|
||||
return
|
||||
|
@ -178,7 +176,7 @@ class PeoplePickerView : TemplateView {
|
|||
*/
|
||||
var searchDirectorySuggestionsListener: PersonaSuggestionsListener? = null
|
||||
/**
|
||||
* When a persona chip with a [PeoplePickerPersonaChipClickStyle] of SelectDeselect is selected,
|
||||
* When a persona chip with a [PeoplePickerPersonaChipClickStyle] of SELECT_DESELECT is selected,
|
||||
* the next touch will fire [PersonaChipClickListener.onClick].
|
||||
*/
|
||||
var personaChipClickListener: PersonaChipClickListener? = null
|
||||
|
@ -215,7 +213,7 @@ class PeoplePickerView : TemplateView {
|
|||
val styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.PeoplePickerView)
|
||||
label = styledAttrs.getString(R.styleable.PeoplePickerView_label) ?: ""
|
||||
valueHint = styledAttrs.getString(R.styleable.PeoplePickerView_valueHint) ?: context.getString(R.string.people_picker_accessibility_default_hint)
|
||||
val personaChipClickStyleOrdinal = styledAttrs.getInt(R.styleable.PeoplePickerView_personaChipClickStyle, PeoplePickerPersonaChipClickStyle.Select.ordinal)
|
||||
val personaChipClickStyleOrdinal = styledAttrs.getInt(R.styleable.PeoplePickerView_personaChipClickStyle, PeoplePickerPersonaChipClickStyle.SELECT.ordinal)
|
||||
personaChipClickStyle = PeoplePickerPersonaChipClickStyle.values()[personaChipClickStyleOrdinal]
|
||||
|
||||
styledAttrs.recycle()
|
||||
|
|
Загрузка…
Ссылка в новой задаче