mColorChangeListeners;
// Class which defines a listener to be called when a new color is selected.
public interface ColorChangeListener {
void onColorSelected(@ColorInt int color);
}
// Registers a new listener
public final void addColorChangeListener(@NonNull ColorChangeListener colorChangeListener) {
mColorChangeListeners.add(colorChangeListener);
}
```
---
# Example in ColorPicker
You implemented this
.left-column-half[
`// TODO: Register callback to update {color,label} View when color changed.`
- What method do we call to register the callback?
- `addColorChangeListener()`
- What do we usually do in a callback?
- update application (`MainActivity`) model
]
.right-column-half[
![:img listener relationship diagram in color picker, 100%](img/listener.png)
]
---
# Custom Listener in Menus
You need to do this yourself in Menus
```java
// TODO: register a new listener with the menu so that the application knows when a selection is made
// TODO: implement the listener. When the user completes a trial, the menu listener should store
// the results of the trial, and setup for the next trial
```
---
# Android Studio Tips
- [Keyboard shortcuts](https://developer.android.com/studio/intro/keyboard-shortcuts)
- Structure tab
![:img android structure tab, 50%](img/tips.png)
---
# Work time on Menus
classDiagram
class MenuExperimentView {
onTouchEvent()
startSelection()
endSelection()
updateModel()
onDraw()
}
AbstractMenuExperimentView <|-- MenuExperimentView
AbstractMainActivity <|-- MainActivity
AbstractMainActivity <|-- TestActivity
MenuExperimentView <|-- PieMenuView
MenuExperimentView <|-- NormalMenuView
MenuExperimentView <|-- CustomMenuView