mirror of
https://github.com/oxen-io/session-android.git
synced 2025-10-24 18:19:38 +00:00
stop using PopupWindow for emoji. too many android bugs.
Closes #3655 // FREEBIE
This commit is contained in:
committed by
Moxie Marlinspike
parent
c7599094f5
commit
b519fd2533
@@ -97,14 +97,6 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
|
||||
oldRect.set(newRect);
|
||||
}
|
||||
|
||||
public void padForCustomKeyboard(final int height) {
|
||||
setPadding(0, 0, 0, height);
|
||||
}
|
||||
|
||||
public void unpadForCustomKeyboard() {
|
||||
setPadding(0, 0, 0, 0);
|
||||
}
|
||||
|
||||
private int getViewInset() {
|
||||
if (Build.VERSION.SDK_INT < VERSION_CODES.LOLLIPOP) {
|
||||
return 0;
|
||||
@@ -135,7 +127,6 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
|
||||
setKeyboardPortraitHeight(keyboardHeight);
|
||||
}
|
||||
notifyShownListeners();
|
||||
unpadForCustomKeyboard();
|
||||
}
|
||||
|
||||
protected void onKeyboardClose() {
|
||||
@@ -188,6 +179,19 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
|
||||
}
|
||||
}
|
||||
|
||||
public void postOnKeyboardOpen(final Runnable runnable) {
|
||||
if (!keyboardOpen) {
|
||||
addOnKeyboardShownListener(new OnKeyboardShownListener() {
|
||||
@Override public void onKeyboardShown() {
|
||||
removeOnKeyboardShownListener(this);
|
||||
runnable.run();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
|
||||
public void addOnKeyboardHiddenListener(OnKeyboardHiddenListener listener) {
|
||||
hiddenListeners.add(listener);
|
||||
}
|
||||
@@ -205,13 +209,15 @@ public class KeyboardAwareLinearLayout extends LinearLayoutCompat {
|
||||
}
|
||||
|
||||
private void notifyHiddenListeners() {
|
||||
for (OnKeyboardHiddenListener listener : hiddenListeners) {
|
||||
final Set<OnKeyboardHiddenListener> listeners = new HashSet<>(hiddenListeners);
|
||||
for (OnKeyboardHiddenListener listener : listeners) {
|
||||
listener.onKeyboardHidden();
|
||||
}
|
||||
}
|
||||
|
||||
private void notifyShownListeners() {
|
||||
for (OnKeyboardShownListener listener : shownListeners) {
|
||||
final Set<OnKeyboardShownListener> listeners = new HashSet<>(shownListeners);
|
||||
for (OnKeyboardShownListener listener : listeners) {
|
||||
listener.onKeyboardShown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,6 @@ import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.view.PagerAdapter;
|
||||
import android.support.v4.view.ViewPager;
|
||||
import android.support.v7.widget.LinearLayoutCompat;
|
||||
import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.KeyEvent;
|
||||
@@ -19,6 +18,7 @@ import android.widget.LinearLayout;
|
||||
import com.astuetz.PagerSlidingTabStrip;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.components.KeyboardAwareLinearLayout;
|
||||
import org.thoughtcrime.securesms.components.RepeatableImageKey;
|
||||
import org.thoughtcrime.securesms.components.RepeatableImageKey.KeyEventListener;
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiPageView.EmojiSelectionListener;
|
||||
@@ -27,10 +27,9 @@ import org.thoughtcrime.securesms.util.ResUtil;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class EmojiDrawer extends LinearLayoutCompat {
|
||||
public class EmojiDrawer extends LinearLayout {
|
||||
private static final KeyEvent DELETE_KEY_EVENT = new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL);
|
||||
|
||||
private LinearLayout container;
|
||||
private ViewPager pager;
|
||||
private List<EmojiPageModel> models;
|
||||
private PagerSlidingTabStrip strip;
|
||||
@@ -42,11 +41,8 @@ public class EmojiDrawer extends LinearLayoutCompat {
|
||||
}
|
||||
|
||||
public EmojiDrawer(Context context, AttributeSet attrs) {
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public EmojiDrawer(Context context, AttributeSet attrs, int defStyle) {
|
||||
super(context, attrs, defStyle);
|
||||
super(context, attrs);
|
||||
setOrientation(VERTICAL);
|
||||
final View v = LayoutInflater.from(getContext()).inflate(R.layout.emoji_drawer, this, true);
|
||||
initializeResources(v);
|
||||
initializePageModels();
|
||||
@@ -59,7 +55,6 @@ public class EmojiDrawer extends LinearLayoutCompat {
|
||||
|
||||
private void initializeResources(View v) {
|
||||
Log.w("EmojiDrawer", "initializeResources()");
|
||||
this.container = (LinearLayout) v.findViewById(R.id.container);
|
||||
this.pager = (ViewPager) v.findViewById(R.id.emoji_pager);
|
||||
this.strip = (PagerSlidingTabStrip) v.findViewById(R.id.tabs);
|
||||
|
||||
@@ -71,8 +66,19 @@ public class EmojiDrawer extends LinearLayoutCompat {
|
||||
});
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
return container.getVisibility() == View.VISIBLE;
|
||||
public boolean isShowing() {
|
||||
return getVisibility() == VISIBLE;
|
||||
}
|
||||
|
||||
public void show(KeyboardAwareLinearLayout container) {
|
||||
ViewGroup.LayoutParams params = getLayoutParams();
|
||||
params.height = container.getKeyboardHeight();
|
||||
setLayoutParams(params);
|
||||
setVisibility(VISIBLE);
|
||||
}
|
||||
|
||||
public void dismiss() {
|
||||
setVisibility(GONE);
|
||||
}
|
||||
|
||||
private void initializeEmojiGrid() {
|
||||
|
||||
@@ -1,49 +0,0 @@
|
||||
package org.thoughtcrime.securesms.components.emoji;
|
||||
|
||||
import android.util.Log;
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
import android.view.ViewTreeObserver.OnGlobalLayoutListener;
|
||||
import android.widget.PopupWindow;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.components.KeyboardAwareLinearLayout;
|
||||
import org.thoughtcrime.securesms.components.emoji.EmojiDrawer.EmojiEventListener;
|
||||
|
||||
public class EmojiPopup extends PopupWindow {
|
||||
private static final String TAG = EmojiPopup.class.getSimpleName();
|
||||
private KeyboardAwareLinearLayout parent;
|
||||
|
||||
public EmojiPopup(KeyboardAwareLinearLayout parent) {
|
||||
super(new EmojiDrawer(parent.getContext()),
|
||||
parent.getWidth(),
|
||||
parent.getResources().getDimensionPixelSize(R.dimen.min_emoji_drawer_height));
|
||||
this.parent = parent;
|
||||
getContentView().setClickable(true);
|
||||
getContentView().setFocusableInTouchMode(true);
|
||||
getContentView().setFocusable(true);
|
||||
setTouchable(true);
|
||||
setFocusable(true);
|
||||
}
|
||||
|
||||
public void setEmojiEventListener(EmojiEventListener listener) {
|
||||
((EmojiDrawer)getContentView()).setEmojiEventListener(listener);
|
||||
}
|
||||
|
||||
public void show() {
|
||||
setHeight(parent.getKeyboardHeight());
|
||||
setWidth(parent.getWidth());
|
||||
parent.padForCustomKeyboard(getHeight());
|
||||
Log.w(TAG, String.format("show(%d, %d)", getWidth(), getHeight()));
|
||||
showAtLocation(parent, Gravity.BOTTOM | Gravity.LEFT, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dismiss() {
|
||||
super.dismiss();
|
||||
}
|
||||
|
||||
public void update() {
|
||||
update(parent, 0, 0, parent.getWidth(), -1);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user