Call answer button listens to accessibility changes.
This commit is contained in:
parent
a58f564d1e
commit
900371bb30
1 changed files with 33 additions and 5 deletions
|
@ -26,7 +26,7 @@ import org.thoughtcrime.securesms.logging.Log;
|
|||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
import org.thoughtcrime.securesms.util.ViewUtil;
|
||||
|
||||
public final class WebRtcAnswerDeclineButton extends LinearLayout {
|
||||
public final class WebRtcAnswerDeclineButton extends LinearLayout implements AccessibilityManager.TouchExplorationStateChangeListener {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = Log.tag(WebRtcAnswerDeclineButton.class);
|
||||
|
@ -45,6 +45,8 @@ public final class WebRtcAnswerDeclineButton extends LinearLayout {
|
|||
|
||||
private AnswerDeclineListener listener;
|
||||
@Nullable private DragToAnswer dragToAnswerListener;
|
||||
private AccessibilityManager accessibilityManager;
|
||||
private boolean ringAnimation;
|
||||
|
||||
public WebRtcAnswerDeclineButton(Context context) {
|
||||
super(context);
|
||||
|
@ -65,15 +67,29 @@ public final class WebRtcAnswerDeclineButton extends LinearLayout {
|
|||
setOrientation(LinearLayout.VERTICAL);
|
||||
setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
|
||||
|
||||
AccessibilityManager accessibilityManager = ServiceUtil.getAccessibilityManager(getContext());
|
||||
boolean isExploreByTouchEnabled = accessibilityManager.isTouchExplorationEnabled();
|
||||
accessibilityManager = ServiceUtil.getAccessibilityManager(getContext());
|
||||
|
||||
if (isExploreByTouchEnabled) {
|
||||
createView(accessibilityManager.isTouchExplorationEnabled());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
accessibilityManager.addTouchExplorationStateChangeListener(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDetachedFromWindow() {
|
||||
accessibilityManager.removeTouchExplorationStateChangeListener(this);
|
||||
super.onDetachedFromWindow();
|
||||
}
|
||||
|
||||
private void createView(boolean isTouchExplorationEnabled) {
|
||||
if (isTouchExplorationEnabled) {
|
||||
inflate(getContext(), R.layout.webrtc_answer_decline_button_accessible, this);
|
||||
|
||||
findViewById(R.id.answer).setOnClickListener((view) -> listener.onAnswered());
|
||||
findViewById(R.id.reject).setOnClickListener((view) -> listener.onDeclined());
|
||||
|
||||
} else {
|
||||
inflate(getContext(), R.layout.webrtc_answer_decline_button, this);
|
||||
|
||||
|
@ -82,6 +98,10 @@ public final class WebRtcAnswerDeclineButton extends LinearLayout {
|
|||
dragToAnswerListener = new DragToAnswer(answer, this);
|
||||
|
||||
answer.setOnTouchListener(dragToAnswerListener);
|
||||
|
||||
if (ringAnimation) {
|
||||
startRingingAnimation();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,17 +110,25 @@ public final class WebRtcAnswerDeclineButton extends LinearLayout {
|
|||
}
|
||||
|
||||
public void startRingingAnimation() {
|
||||
ringAnimation = true;
|
||||
if (dragToAnswerListener != null) {
|
||||
dragToAnswerListener.startRingingAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
public void stopRingingAnimation() {
|
||||
ringAnimation = false;
|
||||
if (dragToAnswerListener != null) {
|
||||
dragToAnswerListener.stopRingingAnimation();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTouchExplorationStateChanged(boolean enabled) {
|
||||
removeAllViews();
|
||||
createView(enabled);
|
||||
}
|
||||
|
||||
private class DragToAnswer implements View.OnTouchListener {
|
||||
|
||||
private final TextView swipeUpText;
|
||||
|
|
Loading…
Add table
Reference in a new issue