InvisibleInputView.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* This file is part of DarkFi (https://dark.fi)
  2. *
  3. * Copyright (C) 2020-2025 Dyne.org foundation
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as
  7. * published by the Free Software Foundation, either version 3 of the
  8. * License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. package autosuggest;
  19. import android.content.Context;
  20. import android.graphics.Canvas;
  21. import android.graphics.Rect;
  22. import android.util.Log;
  23. import android.view.View;
  24. import android.view.ViewGroup;
  25. import android.view.inputmethod.EditorInfo;
  26. import android.view.inputmethod.InputConnection;
  27. import autosuggest.CustomInputConnection;
  28. public class InvisibleInputView extends View {
  29. public CustomInputConnection inputConnection;
  30. public int id = -1;
  31. native static void onCreateInputConnect(int id);
  32. public InvisibleInputView(Context ctx, int id) {
  33. super(ctx);
  34. setFocusable(true);
  35. setFocusableInTouchMode(true);
  36. //setVisibility(INVISIBLE);
  37. setVisibility(VISIBLE);
  38. //setAlpha(0f);
  39. setLayoutParams(new ViewGroup.LayoutParams(400, 200));
  40. this.id = id;
  41. }
  42. /*
  43. @Override
  44. protected void onDraw(Canvas canvas) {
  45. Log.d("darkfi", "InvisibleInputView skipping onDraw()");
  46. }
  47. */
  48. @Override
  49. protected void onAttachedToWindow() {
  50. super.onAttachedToWindow();
  51. Log.d("darkfi", "InvisibleInputView " + id + " attached to window");
  52. }
  53. @Override
  54. public boolean onCheckIsTextEditor() {
  55. Log.d("darkfi", "onCheckIsTextEditor");
  56. return true;
  57. }
  58. @Override
  59. public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
  60. Log.d("darkfi", "Create InputConnection for view=" + this.toString());
  61. if (inputConnection != null) {
  62. Log.d("darkfi", " -> return existing InputConnection");
  63. return inputConnection;
  64. }
  65. outAttrs.inputType = EditorInfo.TYPE_CLASS_TEXT
  66. | EditorInfo.TYPE_TEXT_FLAG_AUTO_CORRECT;
  67. outAttrs.imeOptions = EditorInfo.IME_FLAG_NO_FULLSCREEN
  68. | EditorInfo.IME_ACTION_NONE;
  69. inputConnection = new CustomInputConnection(id, this, outAttrs);
  70. onCreateInputConnect(id);
  71. return inputConnection;
  72. }
  73. @Override
  74. protected void onFocusChanged(boolean gainFocus, int direction, Rect previouslyFocusedRect) {
  75. super.onFocusChanged(gainFocus, direction, previouslyFocusedRect);
  76. Log.d("darkfi", "onFocusChanged: " + gainFocus);
  77. }
  78. }