From e54764461b7833f5ebe34dafabdf8d9c3434ce37 Mon Sep 17 00:00:00 2001 From: wangqi Date: Tue, 13 Feb 2018 11:32:03 -0800 Subject: Move RttChatBot to simulator. Bug: 67596257 Test: none PiperOrigin-RevId: 185561470 Change-Id: I96755cc76e2a1cba65cd496d74593cdd1dedddae --- .../android/incallui/rtt/impl/RttChatAdapter.java | 76 ---------------------- .../android/incallui/rtt/impl/RttChatMessage.java | 6 +- 2 files changed, 3 insertions(+), 79 deletions(-) (limited to 'java/com/android/incallui/rtt/impl') diff --git a/java/com/android/incallui/rtt/impl/RttChatAdapter.java b/java/com/android/incallui/rtt/impl/RttChatAdapter.java index 1db4c6bad..1ea7f31b1 100644 --- a/java/com/android/incallui/rtt/impl/RttChatAdapter.java +++ b/java/com/android/incallui/rtt/impl/RttChatAdapter.java @@ -17,19 +17,15 @@ package com.android.incallui.rtt.impl; import android.content.Context; -import android.support.annotation.MainThread; import android.support.v7.widget.RecyclerView; import android.text.TextUtils; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; -import com.android.dialer.common.Assert; import com.android.dialer.common.LogUtil; -import com.android.dialer.common.concurrent.ThreadUtil; import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import java.util.Random; /** Adapter class for holding RTT chat data. */ public class RttChatAdapter extends RecyclerView.Adapter { @@ -42,13 +38,11 @@ public class RttChatAdapter extends RecyclerView.Adapter rttMessages = new ArrayList<>(); private int lastIndexOfLocalMessage = -1; private int lastIndexOfRemoteMessage = -1; - private final TypeBot typeBot; private final MessageListener messageListener; RttChatAdapter(Context context, MessageListener listener) { this.context = context; this.messageListener = listener; - typeBot = new TypeBot(text -> ThreadUtil.postOnUiThread(() -> addRemoteMessage(text))); } @Override @@ -133,7 +127,6 @@ public class RttChatAdapter extends RecyclerView.Adapter messageQueue = new ArrayList<>(); - private int currentTypingPosition = -1; - private String currentTypingMessage = null; - - TypeBot(Callback callback) { - this.callback = callback; - } - - @MainThread - public void scheduleMessage() { - Assert.isMainThread(); - if (random.nextDouble() < 0.5) { - return; - } - - String text = CANDIDATE_MESSAGES[random.nextInt(CANDIDATE_MESSAGES.length)]; - messageQueue.add(text); - typeMessage(); - } - - @MainThread - private void typeMessage() { - Assert.isMainThread(); - if (currentTypingPosition < 0 || currentTypingMessage == null) { - if (messageQueue.size() <= 0) { - return; - } - currentTypingMessage = messageQueue.remove(0); - currentTypingPosition = 0; - } - if (currentTypingPosition < currentTypingMessage.length()) { - int size = random.nextInt(currentTypingMessage.length() - currentTypingPosition + 1); - callback.type( - currentTypingMessage.substring(currentTypingPosition, currentTypingPosition + size)); - currentTypingPosition = currentTypingPosition + size; - // Wait up to 2s between typing. - ThreadUtil.postDelayedOnUiThread(this::typeMessage, 200 * random.nextInt(10)); - } else { - callback.type(RttChatMessage.BUBBLE_BREAKER); - currentTypingPosition = -1; - currentTypingMessage = null; - // Wait 1-11s between two messages. - ThreadUtil.postDelayedOnUiThread(this::typeMessage, 1000 * (1 + random.nextInt(10))); - } - } - } } diff --git a/java/com/android/incallui/rtt/impl/RttChatMessage.java b/java/com/android/incallui/rtt/impl/RttChatMessage.java index 85b045183..b36da77cc 100644 --- a/java/com/android/incallui/rtt/impl/RttChatMessage.java +++ b/java/com/android/incallui/rtt/impl/RttChatMessage.java @@ -19,6 +19,7 @@ package com.android.incallui.rtt.impl; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.text.TextWatcher; +import com.android.incallui.rtt.protocol.Constants; import com.google.common.base.Splitter; import java.util.ArrayList; import java.util.Iterator; @@ -27,8 +28,7 @@ import java.util.List; /** Message class that holds one RTT chat content. */ final class RttChatMessage { - static final String BUBBLE_BREAKER = "\n\n"; - private static final Splitter SPLITTER = Splitter.on(BUBBLE_BREAKER); + private static final Splitter SPLITTER = Splitter.on(Constants.BUBBLE_BREAKER); boolean isRemote; public boolean hasAvatar; @@ -108,7 +108,7 @@ final class RttChatMessage { firstMessage.isRemote = true; } firstMessage.append(firstMessageContent); - if (splitText.hasNext() || text.endsWith(BUBBLE_BREAKER)) { + if (splitText.hasNext() || text.endsWith(Constants.BUBBLE_BREAKER)) { firstMessage.finish(); } messageList.add(firstMessage); -- cgit v1.2.3