content: package com.adjust.examples.keyboard;
  
  import android.inputmethodservice.InputMethodService;
  import android.inputmethodservice.Keyboard;
  import android.inputmethodservice.KeyboardView;
  import android.text.TextUtils;
  import android.view.KeyEvent;
  import android.view.View;
  import android.view.inputmethod.InputConnection;
  
  import com.adjust.sdk.Adjust;
  import com.adjust.sdk.AdjustEvent;
  
  public class KeyboardInputMethodService extends InputMethodService implements KeyboardView.OnKeyboardActionListener {
  
      private KeyboardView keyboardView;
      private Keyboard keyboard;
  
      private boolean caps = false;
  
      @Override
      public View onCreateInputView() {
          keyboardView = (KeyboardView) getLayoutInflater().inflate(R.layout.keyboard_view, null);
          keyboard = new Keyboard(this, R.xml.keyboard);
          keyboardView.setKeyboard(keyboard);
          keyboardView.setOnKeyboardActionListener(this);
          return keyboardView;
      }
  
      @Override
      public void onWindowShown() {
          super.onWindowShown();
  
          // notify Adjust sdk to resume on keyboard open
          Adjust.onResume();
      }
  
      @Override
      public void onWindowHidden() {
          super.onWindowHidden();
  
          // notify Adjust sdk to pause on keyboard close
          Adjust.onPause();
      }
  
      @Override
      public void onPress(int primaryCode) {
  
      }
  
      @Override
      public void onRelease(int primaryCode) {
  
      }
  
      @Override
      public void onKey(int primaryCode, int[] keyCodes) {
          InputConnection inputConnection = getCurrentInputConnection();
          if (inputConnection != null) {
              switch(primaryCode) {
                  case Keyboard.KEYCODE_DELETE :
                      CharSequence selectedText = inputConnection.getSelectedText(0);
  
                      if (TextUtils.isEmpty(selectedText)) {
                          inputConnection.deleteSurroundingText(1, 0);
                      } else {
                          inputConnection.commitText("", 1);
                      }
  
                      // track an event
                      onTrackSimpleEventClick();
  
                      break;
                  case Keyboard.KEYCODE_SHIFT:
                      caps = !caps;
                      keyboard.setShifted(caps);
                      keyboardView.invalidateAllKeys();
                      break;
                  case Keyboard.KEYCODE_DONE:
                      inputConnection.sendKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_ENTER));
  
                      break;
                  default :
                      char code = (char) primaryCode;
                      if(Character.isLetter(code) && caps){
                          code = Character.toUpperCase(code);
                      }
                      inputConnection.commitText(String.valueOf(code), 1);
  
              }
          }
      }
  
      @Override
      public void onText(CharSequence text) {
  
      }
  
      @Override
      public void swipeLeft() {
  
      }
  
      @Override
      public void swipeRight() {
  
      }
  
      @Override
      public void swipeDown() {
  
      }
  
      @Override
      public void swipeUp() {
  
      }
  
      public void onTrackSimpleEventClick() {
          AdjustEvent event = new AdjustEvent("g3mfiw");
  
          // Assign custom identifier to event which will be reported in success/failure callbacks.
          event.setCallbackId("PrettyRandomIdentifier");
  
          Adjust.trackEvent(event);
      }
  }
  