summaryrefslogtreecommitdiff
path: root/java/com/android/incallui
diff options
context:
space:
mode:
authorwangqi <wangqi@google.com>2018-02-13 11:32:03 -0800
committerCopybara-Service <copybara-piper@google.com>2018-02-22 01:22:31 -0800
commite54764461b7833f5ebe34dafabdf8d9c3434ce37 (patch)
tree4527c93af1e8296a2337408dc53dc711289d9a9e /java/com/android/incallui
parentd844a34e6ca44c7c917b5f0cc70609ac450e438a (diff)
Move RttChatBot to simulator.
Bug: 67596257 Test: none PiperOrigin-RevId: 185561470 Change-Id: I96755cc76e2a1cba65cd496d74593cdd1dedddae
Diffstat (limited to 'java/com/android/incallui')
-rw-r--r--java/com/android/incallui/rtt/impl/RttChatAdapter.java76
-rw-r--r--java/com/android/incallui/rtt/impl/RttChatMessage.java6
-rw-r--r--java/com/android/incallui/rtt/protocol/Constants.java24
3 files changed, 27 insertions, 79 deletions
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<RttChatMessageViewHolder> {
@@ -42,13 +38,11 @@ public class RttChatAdapter extends RecyclerView.Adapter<RttChatMessageViewHolde
private final List<RttChatMessage> 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<RttChatMessageViewHolde
rttMessages.get(lastIndexOfLocalMessage).finish();
notifyItemChanged(lastIndexOfLocalMessage);
lastIndexOfLocalMessage = -1;
- startChatBot();
}
void addRemoteMessage(String message) {
@@ -146,73 +139,4 @@ public class RttChatAdapter extends RecyclerView.Adapter<RttChatMessageViewHolde
messageListener.newMessageAdded();
}
}
-
- private void startChatBot() {
- typeBot.scheduleMessage();
- }
-
- // TODO(wangqi): Move this out of this class once a bug is fixed.
- private static class TypeBot {
- interface Callback {
- void type(String text);
- }
-
- private static final String[] CANDIDATE_MESSAGES =
- new String[] {
- "To RTT or not to RTT, that is the question...",
- "Making TTY great again!",
- "I would be more comfortable with real \"Thyme\" chatting."
- + " I don't know how to end this pun",
- "お疲れ様でした",
- "The FCC has mandated that I respond... I will do so begrudgingly",
- "😂😂😂💯"
- };
- private final Random random = new Random();
- private final Callback callback;
- private final List<String> 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);
diff --git a/java/com/android/incallui/rtt/protocol/Constants.java b/java/com/android/incallui/rtt/protocol/Constants.java
new file mode 100644
index 000000000..5806bbada
--- /dev/null
+++ b/java/com/android/incallui/rtt/protocol/Constants.java
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2018 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License
+ */
+
+package com.android.incallui.rtt.protocol;
+
+/** Constants for RTT call. */
+public interface Constants {
+
+ /** String used to break bubble, which means one RTT message is complete. */
+ String BUBBLE_BREAKER = "\n\n";
+}