From cdae908f0a3c3754c592996df092722e1a96bde3 Mon Sep 17 00:00:00 2001 From: wangqi Date: Thu, 22 Mar 2018 14:08:28 -0700 Subject: Allow user to delete previous bubbles. After this change, user will be able to delete text in previous finished bubble. It will also correctly handle deletion from remote. Bug: 67596257 Test: RttChatMessageTest PiperOrigin-RevId: 190122728 Change-Id: Ifebcbe874e5f03857d109b58e758e53f408e7e44 --- .../android/incallui/rtt/impl/RttChatAdapter.java | 58 ++++------- .../android/incallui/rtt/impl/RttChatFragment.java | 24 ++++- .../android/incallui/rtt/impl/RttChatMessage.java | 116 +++++++++++++++------ 3 files changed, 131 insertions(+), 67 deletions(-) diff --git a/java/com/android/incallui/rtt/impl/RttChatAdapter.java b/java/com/android/incallui/rtt/impl/RttChatAdapter.java index 7e2b571c1..8d924c9f8 100644 --- a/java/com/android/incallui/rtt/impl/RttChatAdapter.java +++ b/java/com/android/incallui/rtt/impl/RttChatAdapter.java @@ -37,13 +37,11 @@ public class RttChatAdapter extends RecyclerView.Adapter rttMessages; private int lastIndexOfLocalMessage = -1; - private int lastIndexOfRemoteMessage = -1; private final MessageListener messageListener; RttChatAdapter(Context context, MessageListener listener, @Nullable Bundle savedInstanceState) { @@ -53,7 +51,6 @@ public class RttChatAdapter extends RecyclerView.Adapter(); } else { rttMessages = savedInstanceState.getParcelableArrayList(KEY_MESSAGE_DATA); - lastIndexOfRemoteMessage = savedInstanceState.getInt(KEY_LAST_REMOTE_MESSAGE); lastIndexOfLocalMessage = savedInstanceState.getInt(KEY_LAST_LOCAL_MESSAGE); } } @@ -84,33 +81,6 @@ public class RttChatAdapter extends RecyclerView.Adapter= 0) { - rttChatMessage = rttMessages.get(lastIndexOfRemoteMessage); - } - List newMessages = - RttChatMessage.getRemoteRttChatMessage(rttChatMessage, newText); - - if (rttChatMessage == null) { - lastIndexOfRemoteMessage = rttMessages.size(); - rttMessages.add(lastIndexOfRemoteMessage, newMessages.get(0)); - rttMessages.addAll(newMessages.subList(1, newMessages.size())); - notifyItemRangeInserted(lastIndexOfRemoteMessage, newMessages.size()); - lastIndexOfRemoteMessage = rttMessages.size() - 1; - } else { - rttMessages.set(lastIndexOfRemoteMessage, newMessages.get(0)); - int lastIndex = rttMessages.size(); - rttMessages.addAll(newMessages.subList(1, newMessages.size())); - - notifyItemChanged(lastIndexOfRemoteMessage); - notifyItemRangeInserted(lastIndex, newMessages.size()); - } - if (rttMessages.get(lastIndexOfRemoteMessage).isFinished()) { - lastIndexOfRemoteMessage = -1; - } - } - private void updateCurrentLocalMessage(String newMessage) { RttChatMessage rttChatMessage = null; if (lastIndexOfLocalMessage >= 0) { @@ -128,9 +98,6 @@ public class RttChatAdapter extends RecyclerView.Adapter lastIndexOfLocalMessage) { - lastIndexOfRemoteMessage -= 1; - } lastIndexOfLocalMessage = -1; } else { notifyItemChanged(lastIndexOfLocalMessage); @@ -138,8 +105,13 @@ public class RttChatAdapter extends RecyclerView.Adapter= 0) { + RttChatMessage rttChatMessage = rttMessages.get(lastIndexOfLocalMessage); + rttChatMessage.unfinish(); + return rttChatMessage.getContent(); + } else { + return null; + } + } + void onSaveInstanceState(@NonNull Bundle bundle) { bundle.putParcelableArrayList(KEY_MESSAGE_DATA, (ArrayList) rttMessages); - bundle.putInt(KEY_LAST_REMOTE_MESSAGE, lastIndexOfRemoteMessage); bundle.putInt(KEY_LAST_LOCAL_MESSAGE, lastIndexOfLocalMessage); } } diff --git a/java/com/android/incallui/rtt/impl/RttChatFragment.java b/java/com/android/incallui/rtt/impl/RttChatFragment.java index 90bf199b2..e14ee9b06 100644 --- a/java/com/android/incallui/rtt/impl/RttChatFragment.java +++ b/java/com/android/incallui/rtt/impl/RttChatFragment.java @@ -164,6 +164,26 @@ public class RttChatFragment extends Fragment editText = view.findViewById(R.id.rtt_chat_input); editText.setOnEditorActionListener(this); editText.addTextChangedListener(this); + + editText.setOnKeyListener( + (v, keyCode, event) -> { + // This is only triggered when input method doesn't handle delete key, which means the + // current + // input box is empty. + if (keyCode == KeyEvent.KEYCODE_DEL && event.getAction() == KeyEvent.ACTION_DOWN) { + String lastMessage = adapter.retrieveLastLocalMessage(); + if (lastMessage != null) { + isClearingInput = true; + editText.setText(lastMessage); + editText.setSelection(lastMessage.length()); + isClearingInput = false; + rttCallScreenDelegate.onLocalMessage("\b"); + return true; + } + return false; + } + return false; + }); recyclerView = view.findViewById(R.id.rtt_recycler_view); LinearLayoutManager layoutManager = new LinearLayoutManager(getContext()); layoutManager.setStackFromEnd(true); @@ -207,7 +227,9 @@ public class RttChatFragment extends Fragment @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { if (actionId == EditorInfo.IME_ACTION_SEND) { - submitButton.performClick(); + if (!TextUtils.isEmpty(editText.getText())) { + submitButton.performClick(); + } return true; } return false; diff --git a/java/com/android/incallui/rtt/impl/RttChatMessage.java b/java/com/android/incallui/rtt/impl/RttChatMessage.java index fd83fb82f..cbc53ef15 100644 --- a/java/com/android/incallui/rtt/impl/RttChatMessage.java +++ b/java/com/android/incallui/rtt/impl/RttChatMessage.java @@ -19,10 +19,9 @@ package com.android.incallui.rtt.impl; import android.os.Parcel; import android.os.Parcelable; import android.support.annotation.NonNull; -import android.support.annotation.Nullable; +import com.android.dialer.common.Assert; import com.android.incallui.rtt.protocol.Constants; import com.google.common.base.Splitter; -import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -44,13 +43,17 @@ final class RttChatMessage implements Parcelable { isFinished = true; } + void unfinish() { + isFinished = false; + } + public void append(String text) { for (int i = 0; i < text.length(); i++) { char c = text.charAt(i); - if (c != '\b') { - content.append(c); - } else if (content.length() > 0) { + if (c == '\b' && content.length() > 0 && content.charAt(content.length() - 1) != '\b') { content.deleteCharAt(content.length() - 1); + } else { + content.append(c); } } } @@ -87,39 +90,92 @@ final class RttChatMessage implements Parcelable { return modify.toString(); } - /** Convert remote input text into an array of {@code RttChatMessage}. */ - static List getRemoteRttChatMessage( - @Nullable RttChatMessage currentMessage, @NonNull String text) { + /** Update list of {@code RttChatMessage} based on given remote text. */ + static void updateRemoteRttChatMessage(List messageList, @NonNull String text) { + Assert.isNotNull(messageList); Iterator splitText = SPLITTER.split(text).iterator(); - List messageList = new ArrayList<>(); - - String firstMessageContent = splitText.next(); - RttChatMessage firstMessage = currentMessage; - if (firstMessage == null) { - firstMessage = new RttChatMessage(); - firstMessage.isRemote = true; - } - firstMessage.append(firstMessageContent); - if (splitText.hasNext() || text.endsWith(Constants.BUBBLE_BREAKER)) { - firstMessage.finish(); - } - messageList.add(firstMessage); while (splitText.hasNext()) { String singleMessageContent = splitText.next(); - if (singleMessageContent.isEmpty()) { - continue; + RttChatMessage message; + int index = getLastIndexUnfinishedRemoteMessage(messageList); + if (index < 0) { + message = new RttChatMessage(); + message.append(singleMessageContent); + message.isRemote = true; + if (splitText.hasNext()) { + message.finish(); + } + if (message.content.length() != 0) { + messageList.add(message); + } + } else { + message = messageList.get(index); + message.append(singleMessageContent); + if (splitText.hasNext()) { + message.finish(); + } + if (message.content.length() == 0) { + messageList.remove(index); + } } - RttChatMessage message = new RttChatMessage(); - message.append(singleMessageContent); - message.isRemote = true; - if (splitText.hasNext()) { - message.finish(); + StringBuilder content = message.content; + // Delete previous messages. + while (content.length() > 0 && content.charAt(0) == '\b') { + messageList.remove(message); + content.delete(0, 1); + int previous = getLastIndexRemoteMessage(messageList); + // There are more backspaces than existing characters. + if (previous < 0) { + while (content.length() > 0 && content.charAt(0) == '\b') { + content.deleteCharAt(0); + } + // Add message if there are still characters after backspaces. + if (content.length() > 0) { + message = new RttChatMessage(); + message.append(content.toString()); + message.isRemote = true; + if (splitText.hasNext()) { + message.finish(); + } + messageList.add(message); + } + break; + } + message = messageList.get(previous); + message.unfinish(); + message.append(content.toString()); + content = message.content; } - messageList.add(message); } + if (text.endsWith(Constants.BUBBLE_BREAKER)) { + int lastIndexRemoteMessage = getLastIndexRemoteMessage(messageList); + messageList.get(lastIndexRemoteMessage).finish(); + } + } + + private static int getLastIndexUnfinishedRemoteMessage(List messageList) { + int i = messageList.size() - 1; + while (i >= 0 && (!messageList.get(i).isRemote || messageList.get(i).isFinished)) { + i--; + } + return i; + } - return messageList; + private static int getLastIndexRemoteMessage(List messageList) { + int i = messageList.size() - 1; + while (i >= 0 && !messageList.get(i).isRemote) { + i--; + } + return i; + } + + static int getLastIndexLocalMessage(List messageList) { + int i = messageList.size() - 1; + while (i >= 0 && messageList.get(i).isRemote) { + i--; + } + return i; } @Override -- cgit v1.2.3 From 009695e477f02b13d563f17a8de0e179d7715bf9 Mon Sep 17 00:00:00 2001 From: wangqi Date: Thu, 22 Mar 2018 14:32:23 -0700 Subject: Add waiting for join banner to RTT outgoing call. Bug: 67596257 Test: manual PiperOrigin-RevId: 190126654 Change-Id: I412f8fbf5b345005f9fb3651c345303d965e4e02 --- .../com/android/incallui/rtt/impl/RttChatFragment.java | 18 ++++++++++++++++++ .../incallui/rtt/impl/res/layout/rtt_banner.xml | 10 ++++++++++ .../android/incallui/rtt/impl/res/values/strings.xml | 5 ++++- 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/java/com/android/incallui/rtt/impl/RttChatFragment.java b/java/com/android/incallui/rtt/impl/RttChatFragment.java index e14ee9b06..56ac2429c 100644 --- a/java/com/android/incallui/rtt/impl/RttChatFragment.java +++ b/java/com/android/incallui/rtt/impl/RttChatFragment.java @@ -103,6 +103,8 @@ public class RttChatFragment extends Fragment private boolean isTimerStarted; private RttOverflowMenu overflowMenu; private SecondaryInfo savedSecondaryInfo; + private TextView statusBanner; + private PrimaryInfo primaryInfo; /** * Create a new instance of RttChatFragment. @@ -221,6 +223,7 @@ public class RttChatFragment extends Fragment nameTextView = view.findViewById(R.id.rtt_name_or_number); chronometer = view.findViewById(R.id.rtt_timer); + statusBanner = view.findViewById(R.id.rtt_status_banner); return view; } @@ -334,6 +337,7 @@ public class RttChatFragment extends Fragment public void setPrimary(@NonNull PrimaryInfo primaryInfo) { LogUtil.i("RttChatFragment.setPrimary", primaryInfo.toString()); nameTextView.setText(primaryInfo.name()); + this.primaryInfo = primaryInfo; } @Override @@ -381,6 +385,20 @@ public class RttChatFragment extends Fragment chronometer.start(); isTimerStarted = true; } + if (primaryCallState.state() == State.DIALING) { + showWaitingForJoinBanner(); + } else { + hideWaitingForJoinBanner(); + } + } + + private void showWaitingForJoinBanner() { + statusBanner.setText(getString(R.string.rtt_status_banner_text, primaryInfo.name())); + statusBanner.setVisibility(View.VISIBLE); + } + + private void hideWaitingForJoinBanner() { + statusBanner.setVisibility(View.GONE); } @Override diff --git a/java/com/android/incallui/rtt/impl/res/layout/rtt_banner.xml b/java/com/android/incallui/rtt/impl/res/layout/rtt_banner.xml index c4d3a4290..d62cf1849 100644 --- a/java/com/android/incallui/rtt/impl/res/layout/rtt_banner.xml +++ b/java/com/android/incallui/rtt/impl/res/layout/rtt_banner.xml @@ -83,5 +83,15 @@ android:id="@id/rtt_on_hold_banner" android:layout_width="match_parent" android:layout_height="wrap_content"/> + \ No newline at end of file diff --git a/java/com/android/incallui/rtt/impl/res/values/strings.xml b/java/com/android/incallui/rtt/impl/res/values/strings.xml index dce16fdda..b0ac2057e 100644 --- a/java/com/android/incallui/rtt/impl/res/values/strings.xml +++ b/java/com/android/incallui/rtt/impl/res/values/strings.xml @@ -14,7 +14,7 @@ ~ See the License for the specific language governing permissions and ~ limitations under the License --> - + Go ahead @@ -27,4 +27,7 @@ Back + + Waiting for %s to join RTT call… + \ No newline at end of file -- cgit v1.2.3 From f4b484485a4519a99d797bd9c0c1cc902cfc7414 Mon Sep 17 00:00:00 2001 From: linyuh Date: Thu, 22 Mar 2018 17:39:29 -0700 Subject: Correctly display phone numbers containing whitespaces in RTL context. Bug: 74421656 Test: DialerBidiFormatterTest PiperOrigin-RevId: 190154072 Change-Id: Ic7cb3be702dd28b07b6e5e1e6d89f75f0bb12655 --- .../contacts/common/list/ContactTileView.java | 6 +- .../dialer/app/calllog/PhoneCallDetailsViews.java | 9 +- .../app/list/PhoneFavoriteSquareTileView.java | 10 +- .../dialer/app/res/layout/call_log_list_item.xml | 2 +- .../app/res/layout/phone_favorite_tile_view.xml | 2 +- .../calldetails/CallDetailsHeaderViewHolder.java | 3 +- .../calldetails/res/layout/contact_container.xml | 2 +- .../dialer/contactsfragment/ContactViewHolder.java | 3 +- .../contactsfragment/res/layout/contact_row.xml | 2 +- .../android/dialer/i18n/DialerBidiFormatter.java | 123 +++++++++++++++++++++ .../common/res/layout/search_contact_row.xml | 4 +- .../cp2/SearchContactViewHolder.java | 6 +- java/com/android/dialer/widget/BidiTextView.java | 40 +++++++ 13 files changed, 189 insertions(+), 23 deletions(-) create mode 100644 java/com/android/dialer/i18n/DialerBidiFormatter.java create mode 100644 java/com/android/dialer/widget/BidiTextView.java diff --git a/java/com/android/contacts/common/list/ContactTileView.java b/java/com/android/contacts/common/list/ContactTileView.java index cfd52f385..072e07dd2 100644 --- a/java/com/android/contacts/common/list/ContactTileView.java +++ b/java/com/android/contacts/common/list/ContactTileView.java @@ -22,7 +22,6 @@ import android.util.AttributeSet; import android.view.View; import android.widget.FrameLayout; import android.widget.ImageView; -import android.widget.TextView; import com.android.contacts.common.MoreContactUtils; import com.android.contacts.common.R; import com.android.dialer.callintent.CallInitiationType; @@ -30,6 +29,7 @@ import com.android.dialer.callintent.CallSpecificAppData; import com.android.dialer.common.LogUtil; import com.android.dialer.contactphoto.ContactPhotoManager; import com.android.dialer.contactphoto.ContactPhotoManager.DefaultImageRequest; +import com.android.dialer.widget.BidiTextView; /** A ContactTile displays a contact's picture and name */ public abstract class ContactTileView extends FrameLayout { @@ -38,7 +38,7 @@ public abstract class ContactTileView extends FrameLayout { protected Listener mListener; private Uri mLookupUri; private ImageView mPhoto; - private TextView mName; + private BidiTextView mName; private ContactPhotoManager mPhotoManager = null; public ContactTileView(Context context, AttributeSet attrs) { @@ -48,7 +48,7 @@ public abstract class ContactTileView extends FrameLayout { @Override protected void onFinishInflate() { super.onFinishInflate(); - mName = (TextView) findViewById(R.id.contact_tile_name); + mName = (BidiTextView) findViewById(R.id.contact_tile_name); mPhoto = (ImageView) findViewById(R.id.contact_tile_image); OnClickListener listener = createClickListener(); diff --git a/java/com/android/dialer/app/calllog/PhoneCallDetailsViews.java b/java/com/android/dialer/app/calllog/PhoneCallDetailsViews.java index 8b7a92bd4..71cbc8c12 100644 --- a/java/com/android/dialer/app/calllog/PhoneCallDetailsViews.java +++ b/java/com/android/dialer/app/calllog/PhoneCallDetailsViews.java @@ -21,11 +21,12 @@ import android.view.View; import android.widget.TextView; import com.android.dialer.app.R; import com.android.dialer.calllogutils.CallTypeIconsView; +import com.android.dialer.widget.BidiTextView; /** Encapsulates the views that are used to display the details of a phone call in the call log. */ public final class PhoneCallDetailsViews { - public final TextView nameView; + public final BidiTextView nameView; public final View callTypeView; public final CallTypeIconsView callTypeIcons; public final TextView callLocationAndDate; @@ -36,7 +37,7 @@ public final class PhoneCallDetailsViews { public final TextView callAccountLabel; private PhoneCallDetailsViews( - TextView nameView, + BidiTextView nameView, View callTypeView, CallTypeIconsView callTypeIcons, TextView callLocationAndDate, @@ -65,7 +66,7 @@ public final class PhoneCallDetailsViews { */ public static PhoneCallDetailsViews fromView(View view) { return new PhoneCallDetailsViews( - (TextView) view.findViewById(R.id.name), + (BidiTextView) view.findViewById(R.id.name), view.findViewById(R.id.call_type), (CallTypeIconsView) view.findViewById(R.id.call_type_icons), (TextView) view.findViewById(R.id.call_location_and_date), @@ -78,7 +79,7 @@ public final class PhoneCallDetailsViews { public static PhoneCallDetailsViews createForTest(Context context) { return new PhoneCallDetailsViews( - new TextView(context), + new BidiTextView(context), new View(context), new CallTypeIconsView(context), new TextView(context), diff --git a/java/com/android/dialer/app/list/PhoneFavoriteSquareTileView.java b/java/com/android/dialer/app/list/PhoneFavoriteSquareTileView.java index 330a3614c..6096ca872 100644 --- a/java/com/android/dialer/app/list/PhoneFavoriteSquareTileView.java +++ b/java/com/android/dialer/app/list/PhoneFavoriteSquareTileView.java @@ -28,12 +28,11 @@ import com.android.dialer.app.R; import com.android.dialer.compat.CompatUtils; import com.android.dialer.logging.InteractionEvent; import com.android.dialer.logging.Logger; +import com.android.dialer.widget.BidiTextView; /** Displays the contact's picture overlaid with their name and number type in a tile. */ public class PhoneFavoriteSquareTileView extends PhoneFavoriteTileView { - private static final String TAG = PhoneFavoriteSquareTileView.class.getSimpleName(); - private final float heightToWidthRatio; private ImageButton secondaryButton; @@ -50,11 +49,12 @@ public class PhoneFavoriteSquareTileView extends PhoneFavoriteTileView { @Override protected void onFinishInflate() { super.onFinishInflate(); - final TextView nameView = (TextView) findViewById(R.id.contact_tile_name); + BidiTextView nameView = findViewById(R.id.contact_tile_name); nameView.setElegantTextHeight(false); - final TextView phoneTypeView = (TextView) findViewById(R.id.contact_tile_phone_type); + + TextView phoneTypeView = findViewById(R.id.contact_tile_phone_type); phoneTypeView.setElegantTextHeight(false); - secondaryButton = (ImageButton) findViewById(R.id.contact_tile_secondary_button); + secondaryButton = findViewById(R.id.contact_tile_secondary_button); } @Override diff --git a/java/com/android/dialer/app/res/layout/call_log_list_item.xml b/java/com/android/dialer/app/res/layout/call_log_list_item.xml index acaa82085..d1111103e 100644 --- a/java/com/android/dialer/app/res/layout/call_log_list_item.xml +++ b/java/com/android/dialer/app/res/layout/call_log_list_item.xml @@ -93,7 +93,7 @@ android:gravity="center_vertical" android:layout_marginStart="@dimen/call_log_list_item_info_margin_start"> - - - - Formatted phone numbers usually contain one or more whitespaces (e.g., "+1 650-253-0000", + * "(650) 253-0000", etc). {@link BidiFormatter} mistakes such a number for tokens separated by + * whitespaces. Therefore, these numbers can't be correctly shown in a RTL context (e.g., "+1 + * 650-253-0000" would be shown as "650-253-0000 1+".) + */ +public final class DialerBidiFormatter { + + private DialerBidiFormatter() {} + + /** + * Divides the given text into segments, applies {@link BidiFormatter#unicodeWrap(CharSequence)} + * to each segment, and then reassembles the text. + * + *

A segment of the text is either a substring matching {@link Patterns#PHONE} or one that does + * not. + * + * @see BidiFormatter#unicodeWrap(CharSequence) + */ + public static CharSequence unicodeWrap(@Nullable CharSequence text) { + if (TextUtils.isEmpty(text)) { + return text; + } + + List segments = segmentText(text); + + StringBuilder formattedText = new StringBuilder(); + for (CharSequence segment : segments) { + formattedText.append(BidiFormatter.getInstance().unicodeWrap(segment)); + } + + return formattedText.toString(); + } + + /** + * Segments the given text using {@link Patterns#PHONE}. + * + *

For example, "Mobile, +1 650-253-0000, 20 seconds" will be segmented into {"Mobile, ", "+1 + * 650-253-0000", ", 20 seconds"}. + */ + @VisibleForTesting + static List segmentText(CharSequence text) { + Assert.checkArgument(!TextUtils.isEmpty(text)); + + List segments = new ArrayList<>(); + + // Find the start index and the end index of each segment matching the phone number pattern. + Matcher matcher = Patterns.PHONE.matcher(text.toString()); + List segmentRanges = new ArrayList<>(); + while (matcher.find()) { + segmentRanges.add(Range.newBuilder().setStart(matcher.start()).setEnd(matcher.end()).build()); + } + + // Segment the text. + int currIndex = 0; + for (Range segmentRange : segmentRanges) { + if (currIndex < segmentRange.getStart()) { + segments.add(text.subSequence(currIndex, segmentRange.getStart())); + } + + segments.add(text.subSequence(segmentRange.getStart(), segmentRange.getEnd())); + currIndex = segmentRange.getEnd(); + } + if (currIndex < text.length()) { + segments.add(text.subSequence(currIndex, text.length())); + } + + return segments; + } + + /** Represents the start index (inclusive) and the end index (exclusive) of a text segment. */ + @AutoValue + abstract static class Range { + static Builder newBuilder() { + return new AutoValue_DialerBidiFormatter_Range.Builder(); + } + + abstract int getStart(); + + abstract int getEnd(); + + @AutoValue.Builder + abstract static class Builder { + abstract Builder setStart(int start); + + abstract Builder setEnd(int end); + + abstract Range build(); + } + } +} diff --git a/java/com/android/dialer/searchfragment/common/res/layout/search_contact_row.xml b/java/com/android/dialer/searchfragment/common/res/layout/search_contact_row.xml index 9be7fa046..a0d9dd274 100644 --- a/java/com/android/dialer/searchfragment/common/res/layout/search_contact_row.xml +++ b/java/com/android/dialer/searchfragment/common/res/layout/search_contact_row.xml @@ -39,7 +39,7 @@ android:layout_centerVertical="true" android:layout_marginStart="8dp"> - -