Make InputPanel fully responsible for emoji toggle

Fixes #4638
// FREEBIE
This commit is contained in:
Moxie Marlinspike 2015-11-22 10:44:53 -08:00
parent fc5777e904
commit a4f7b78fd0
2 changed files with 59 additions and 41 deletions

View File

@ -59,7 +59,6 @@ import com.google.protobuf.ByteString;
import org.thoughtcrime.redphone.RedPhone; import org.thoughtcrime.redphone.RedPhone;
import org.thoughtcrime.redphone.RedPhoneService; import org.thoughtcrime.redphone.RedPhoneService;
import org.thoughtcrime.securesms.TransportOptions.OnTransportChangedListener; import org.thoughtcrime.securesms.TransportOptions.OnTransportChangedListener;
import org.thoughtcrime.securesms.audio.AudioCodec;
import org.thoughtcrime.securesms.audio.AudioRecorder; import org.thoughtcrime.securesms.audio.AudioRecorder;
import org.thoughtcrime.securesms.audio.AudioSlidePlayer; import org.thoughtcrime.securesms.audio.AudioSlidePlayer;
import org.thoughtcrime.securesms.color.MaterialColor; import org.thoughtcrime.securesms.color.MaterialColor;
@ -75,8 +74,6 @@ import org.thoughtcrime.securesms.components.camera.QuickAttachmentDrawer;
import org.thoughtcrime.securesms.components.camera.QuickAttachmentDrawer.AttachmentDrawerListener; import org.thoughtcrime.securesms.components.camera.QuickAttachmentDrawer.AttachmentDrawerListener;
import org.thoughtcrime.securesms.components.camera.QuickAttachmentDrawer.DrawerState; import org.thoughtcrime.securesms.components.camera.QuickAttachmentDrawer.DrawerState;
import org.thoughtcrime.securesms.components.emoji.EmojiDrawer; import org.thoughtcrime.securesms.components.emoji.EmojiDrawer;
import org.thoughtcrime.securesms.components.emoji.EmojiDrawer.EmojiEventListener;
import org.thoughtcrime.securesms.components.emoji.EmojiToggle;
import org.thoughtcrime.securesms.components.reminder.InviteReminder; import org.thoughtcrime.securesms.components.reminder.InviteReminder;
import org.thoughtcrime.securesms.components.reminder.ReminderView; import org.thoughtcrime.securesms.components.reminder.ReminderView;
import org.thoughtcrime.securesms.contacts.ContactAccessor; import org.thoughtcrime.securesms.contacts.ContactAccessor;
@ -193,7 +190,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
private BroadcastReceiver securityUpdateReceiver; private BroadcastReceiver securityUpdateReceiver;
private BroadcastReceiver groupUpdateReceiver; private BroadcastReceiver groupUpdateReceiver;
private EmojiDrawer emojiDrawer; private EmojiDrawer emojiDrawer;
private EmojiToggle emojiToggle;
protected HidingLinearLayout quickAttachmentToggle; protected HidingLinearLayout quickAttachmentToggle;
private QuickAttachmentDrawer quickAttachmentDrawer; private QuickAttachmentDrawer quickAttachmentDrawer;
private InputPanel inputPanel; private InputPanel inputPanel;
@ -423,7 +419,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
@Override @Override
public void onKeyboardShown() { public void onKeyboardShown() {
emojiToggle.setToEmoji(); inputPanel.onKeyboardShown();
} }
//////// Event Handlers //////// Event Handlers
@ -853,7 +849,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
attachButton = ViewUtil.findById(this, R.id.attach_button); attachButton = ViewUtil.findById(this, R.id.attach_button);
composeText = ViewUtil.findById(this, R.id.embedded_text_editor); composeText = ViewUtil.findById(this, R.id.embedded_text_editor);
charactersLeft = ViewUtil.findById(this, R.id.space_left); charactersLeft = ViewUtil.findById(this, R.id.space_left);
emojiToggle = ViewUtil.findById(this, R.id.emoji_toggle);
emojiDrawer = ViewUtil.findById(this, R.id.emoji_drawer); emojiDrawer = ViewUtil.findById(this, R.id.emoji_drawer);
unblockButton = ViewUtil.findById(this, R.id.unblock_button); unblockButton = ViewUtil.findById(this, R.id.unblock_button);
composePanel = ViewUtil.findById(this, R.id.bottom_panel); composePanel = ViewUtil.findById(this, R.id.bottom_panel);
@ -867,7 +862,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
View composeBubble = ViewUtil.findById(this, R.id.compose_bubble); View composeBubble = ViewUtil.findById(this, R.id.compose_bubble);
container.addOnKeyboardShownListener(this); container.addOnKeyboardShownListener(this);
inputPanel.setListener(this); inputPanel.setListener(this, emojiDrawer);
int[] attributes = new int[]{R.attr.conversation_item_bubble_background}; int[] attributes = new int[]{R.attr.conversation_item_bubble_background};
TypedArray colors = obtainStyledAttributes(attributes); TypedArray colors = obtainStyledAttributes(attributes);
@ -882,22 +877,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
SendButtonListener sendButtonListener = new SendButtonListener(); SendButtonListener sendButtonListener = new SendButtonListener();
ComposeKeyPressedListener composeKeyPressedListener = new ComposeKeyPressedListener(); ComposeKeyPressedListener composeKeyPressedListener = new ComposeKeyPressedListener();
if (TextSecurePreferences.isSystemEmojiPreferred(this)) { emojiDrawer.setEmojiEventListener(inputPanel);
emojiToggle.setVisibility(View.GONE);
} else {
emojiToggle.attach(emojiDrawer);
emojiToggle.setOnClickListener(new EmojiToggleListener());
emojiDrawer.setEmojiEventListener(new EmojiEventListener() {
@Override public void onKeyEvent(KeyEvent keyEvent) {
composeText.dispatchKeyEvent(keyEvent);
}
@Override public void onEmojiSelected(String emoji) {
composeText.insertEmoji(emoji);
}
});
}
composeText.setOnEditorActionListener(sendButtonListener); composeText.setOnEditorActionListener(sendButtonListener);
attachButton.setOnClickListener(new AttachButtonListener()); attachButton.setOnClickListener(new AttachButtonListener());
attachButton.setOnLongClickListener(new AttachButtonLongClickListener()); attachButton.setOnLongClickListener(new AttachButtonLongClickListener());
@ -1444,6 +1424,12 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
}); });
} }
@Override
public void onEmojiToggle() {
if (container.getCurrentInput() == emojiDrawer) container.showSoftkey(composeText);
else container.show(composeText, emojiDrawer);
}
// Listeners // Listeners
private class AttachmentTypeListener implements AttachmentTypeSelector.AttachmentClickedListener { private class AttachmentTypeListener implements AttachmentTypeSelector.AttachmentClickedListener {
@ -1453,14 +1439,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
} }
} }
private class EmojiToggleListener implements OnClickListener {
@Override public void onClick(View v) {
if (container.getCurrentInput() == emojiDrawer) container.showSoftkey(composeText);
else container.show(composeText, emojiDrawer);
}
}
private class QuickCameraToggleListener implements OnClickListener { private class QuickCameraToggleListener implements OnClickListener {
@Override @Override
public void onClick(View v) { public void onClick(View v) {

View File

@ -4,9 +4,11 @@ import android.annotation.TargetApi;
import android.content.Context; import android.content.Context;
import android.os.Build; import android.os.Build;
import android.os.Handler; import android.os.Handler;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.util.Log; import android.util.Log;
import android.view.KeyEvent;
import android.view.View; import android.view.View;
import android.view.animation.AlphaAnimation; import android.view.animation.AlphaAnimation;
import android.view.animation.Animation; import android.view.animation.Animation;
@ -17,6 +19,10 @@ import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import org.thoughtcrime.securesms.R; import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.components.emoji.EmojiDrawer;
import org.thoughtcrime.securesms.components.emoji.EmojiEditText;
import org.thoughtcrime.securesms.components.emoji.EmojiToggle;
import org.thoughtcrime.securesms.util.TextSecurePreferences;
import org.thoughtcrime.securesms.util.ViewUtil; import org.thoughtcrime.securesms.util.ViewUtil;
import org.thoughtcrime.securesms.util.concurrent.AssertedSuccessListener; import org.thoughtcrime.securesms.util.concurrent.AssertedSuccessListener;
import org.thoughtcrime.securesms.util.concurrent.ListenableFuture; import org.thoughtcrime.securesms.util.concurrent.ListenableFuture;
@ -25,14 +31,15 @@ import org.thoughtcrime.securesms.util.concurrent.SettableFuture;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
public class InputPanel extends LinearLayout implements MicrophoneRecorderView.Listener { public class InputPanel extends LinearLayout
implements MicrophoneRecorderView.Listener, KeyboardAwareLinearLayout.OnKeyboardShownListener, EmojiDrawer.EmojiEventListener {
private static final String TAG = InputPanel.class.getSimpleName(); private static final String TAG = InputPanel.class.getSimpleName();
private static final int FADE_TIME = 150; private static final int FADE_TIME = 150;
private View emojiToggle; private EmojiToggle emojiToggle;
private View composeText; private EmojiEditText composeText;
private View quickCameraToggle; private View quickCameraToggle;
private View quickAudioToggle; private View quickAudioToggle;
private View buttonToggle; private View buttonToggle;
@ -43,6 +50,7 @@ public class InputPanel extends LinearLayout implements MicrophoneRecorderView.L
private RecordTime recordTime; private RecordTime recordTime;
private @Nullable Listener listener; private @Nullable Listener listener;
private boolean emojiVisible;
public InputPanel(Context context) { public InputPanel(Context context) {
super(context); super(context);
@ -76,10 +84,26 @@ public class InputPanel extends LinearLayout implements MicrophoneRecorderView.L
this.microphoneRecorderView.setVisibility(View.GONE); this.microphoneRecorderView.setVisibility(View.GONE);
this.microphoneRecorderView.setClickable(false); this.microphoneRecorderView.setClickable(false);
} }
if (TextSecurePreferences.isSystemEmojiPreferred(getContext())) {
emojiToggle.setVisibility(View.GONE);
emojiVisible = false;
} else {
emojiToggle.setVisibility(View.VISIBLE);
emojiVisible = true;
}
} }
public void setListener(@Nullable Listener listener) { public void setListener(final @NonNull Listener listener, @NonNull EmojiDrawer emojiDrawer) {
this.listener = listener; this.listener = listener;
emojiToggle.attach(emojiDrawer);
emojiToggle.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
listener.onEmojiToggle();
}
});
} }
@Override @Override
@ -88,7 +112,7 @@ public class InputPanel extends LinearLayout implements MicrophoneRecorderView.L
recordTime.display(); recordTime.display();
slideToCancel.display(startPositionX); slideToCancel.display(startPositionX);
ViewUtil.fadeOut(emojiToggle, FADE_TIME, View.INVISIBLE); if (emojiVisible) ViewUtil.fadeOut(emojiToggle, FADE_TIME, View.INVISIBLE);
ViewUtil.fadeOut(composeText, FADE_TIME, View.INVISIBLE); ViewUtil.fadeOut(composeText, FADE_TIME, View.INVISIBLE);
ViewUtil.fadeOut(quickCameraToggle, FADE_TIME, View.INVISIBLE); ViewUtil.fadeOut(quickCameraToggle, FADE_TIME, View.INVISIBLE);
ViewUtil.fadeOut(quickAudioToggle, FADE_TIME, View.INVISIBLE); ViewUtil.fadeOut(quickAudioToggle, FADE_TIME, View.INVISIBLE);
@ -136,7 +160,7 @@ public class InputPanel extends LinearLayout implements MicrophoneRecorderView.L
future.addListener(new AssertedSuccessListener<Void>() { future.addListener(new AssertedSuccessListener<Void>() {
@Override @Override
public void onSuccess(Void result) { public void onSuccess(Void result) {
ViewUtil.fadeIn(emojiToggle, FADE_TIME); if (emojiVisible) ViewUtil.fadeIn(emojiToggle, FADE_TIME);
ViewUtil.fadeIn(composeText, FADE_TIME); ViewUtil.fadeIn(composeText, FADE_TIME);
ViewUtil.fadeIn(quickCameraToggle, FADE_TIME); ViewUtil.fadeIn(quickCameraToggle, FADE_TIME);
ViewUtil.fadeIn(quickAudioToggle, FADE_TIME); ViewUtil.fadeIn(quickAudioToggle, FADE_TIME);
@ -147,10 +171,26 @@ public class InputPanel extends LinearLayout implements MicrophoneRecorderView.L
return elapsedTime; return elapsedTime;
} }
@Override
public void onKeyboardShown() {
emojiToggle.setToEmoji();
}
@Override
public void onKeyEvent(KeyEvent keyEvent) {
composeText.dispatchKeyEvent(keyEvent);
}
@Override
public void onEmojiSelected(String emoji) {
composeText.insertEmoji(emoji);
}
public interface Listener { public interface Listener {
public void onRecorderStarted(); public void onRecorderStarted();
public void onRecorderFinished(); public void onRecorderFinished();
public void onRecorderCanceled(); public void onRecorderCanceled();
public void onEmojiToggle();
} }
private static class SlideToCancel { private static class SlideToCancel {