That fuck shit the fascists are using
at master 94 lines 2.7 kB view raw
1package org.tm.archive.components; 2 3import android.content.Context; 4import android.util.AttributeSet; 5import android.widget.EditText; 6 7import androidx.annotation.NonNull; 8import androidx.annotation.Nullable; 9 10import org.tm.archive.components.KeyboardAwareLinearLayout.OnKeyboardShownListener; 11import org.tm.archive.util.ServiceUtil; 12 13public class InputAwareLayout extends KeyboardAwareLinearLayout implements OnKeyboardShownListener { 14 private InputView current; 15 16 public InputAwareLayout(Context context) { 17 this(context, null); 18 } 19 20 public InputAwareLayout(Context context, AttributeSet attrs) { 21 this(context, attrs, 0); 22 } 23 24 public InputAwareLayout(Context context, AttributeSet attrs, int defStyle) { 25 super(context, attrs, defStyle); 26 addOnKeyboardShownListener(this); 27 } 28 29 @Override 30 public void onKeyboardShown() { 31 } 32 33 public void show(@NonNull final EditText imeTarget, @NonNull final InputView input) { 34 if (isKeyboardOpen()) { 35 hideSoftkey(imeTarget, new Runnable() { 36 @Override public void run() { 37 hideAttachedInput(true); 38 input.show(getKeyboardHeight(), true); 39 current = input; 40 } 41 }); 42 } else { 43 if (current != null) current.hide(true); 44 input.show(getKeyboardHeight(), current != null); 45 current = input; 46 } 47 } 48 49 public InputView getCurrentInput() { 50 return current; 51 } 52 53 public void hideCurrentInput(EditText imeTarget) { 54 if (isKeyboardOpen()) hideSoftkey(imeTarget, null); 55 else hideAttachedInput(false); 56 } 57 58 public void hideAttachedInput(boolean instant) { 59 if (current != null) current.hide(instant); 60 current = null; 61 } 62 63 public boolean isInputOpen() { 64 return (isKeyboardOpen() || (current != null && current.isShowing())); 65 } 66 67 public void showSoftkey(final EditText inputTarget) { 68 postOnKeyboardOpen(new Runnable() { 69 @Override public void run() { 70 hideAttachedInput(true); 71 } 72 }); 73 inputTarget.post(new Runnable() { 74 @Override public void run() { 75 inputTarget.requestFocus(); 76 ServiceUtil.getInputMethodManager(inputTarget.getContext()).showSoftInput(inputTarget, 0); 77 } 78 }); 79 } 80 81 public void hideSoftkey(final EditText inputTarget, @Nullable Runnable runAfterClose) { 82 if (runAfterClose != null) postOnKeyboardClose(runAfterClose); 83 84 ServiceUtil.getInputMethodManager(inputTarget.getContext()) 85 .hideSoftInputFromWindow(inputTarget.getWindowToken(), 0); 86 } 87 88 public interface InputView { 89 void show(int height, boolean immediate); 90 void hide(boolean immediate); 91 boolean isShowing(); 92 } 93} 94