コード例 #1
0
    private void handleGoogTvKeyPress(KeyEvent event, int keyCode) {
      int hash;
      String charLabel = "";

      if (event.getKeyCode() == KeyEvent.KEYCODE_DPAD_DOWN
          || event.getKeyCode() == KeyEvent.KEYCODE_DPAD_UP
          || event.getKeyCode() == KeyEvent.KEYCODE_DPAD_LEFT
          || event.getKeyCode() == KeyEvent.KEYCODE_DPAD_RIGHT) {
        // ---Navigate with DPad---
        Log.i("KeyBindings", event.toString());
      } else {
        if (event.getKeyCode()
            == KeyEvent.KEYCODE_UNKNOWN) { // key was pressed on soft (on-screen) keyboard
          hash = BasicOnKeyboardActionListener.KEY_PRESSED;
          SearchFragmentTab.PHYSICAL_KEY = false;
        } else { // key was pressed on physical keyboard for Goog TV
          SearchFragmentTab.PHYSICAL_KEY = true;
          hash = event.getKeyCode();

          if (event.isLongPress() && event.getKeyCode() == KeyEvent.KEYCODE_DEL) {
            SearchFragmentTab.backSpaceLong();
          }
        }

        switch (hash) {
          case 0: // A letter was pressed on the English keyboard
            SearchFragmentTab.retainSearch();
            break;
        }

        ApplicationContext.getInstance().readyToSearch = true;

        // Russian Keyboard
        if (ApplicationContext.getInstance().keyboardType.equals("Russian")) {
          if (event.getKeyCode()
              == KeyEvent.KEYCODE_UNKNOWN) { // key was pressed on soft (on-screen) keyboard
            charLabel = sparseArrRussian.get(hash);
          } else { // key was pressed on the physical keyboard (for GoogTV)
            charLabel = sparseArrRussian_GoogTV.get(hash);
          }

          // Hybrid Keyboard
        } else if (ApplicationContext.getInstance()
            .keyboardType
            .equals("Hybrid")) { // Hybrid keyboard
          if (ApplicationContext.getInstance()
              .getHybridKeyboardMode()
              .equals("Hybrid_English_To_Russ")) {
            if (event.getKeyCode()
                != KeyEvent
                    .KEYCODE_UNKNOWN) { // key was pressed on the physical keyboard (for GoogTV)
              charLabel = sparseArrHybridEngToRuss_GoogTV.get(hash);
            } else { // key was pressed on the soft (on-screen) keyboard (for GoogTV)
              ApplicationContext.getInstance().readyToSearch = true;
              charLabel = sparseArrHybrid_EngToRuss.get(hash);
            }
          } else if (ApplicationContext.getInstance()
              .getHybridKeyboardMode()
              .equals("Hybrid_Russian_To_Eng")) {
            if (event.getKeyCode()
                != KeyEvent
                    .KEYCODE_UNKNOWN) { // key was pressed on the physical keyboard (for GoogTV)
              charLabel = sparseArrHybrid_RussToEng_GoogTV.get(hash);
            } else { // key was pressed on the soft (on-screen) keyboard (for GoogTV)
              ApplicationContext.getInstance().readyToSearch = true;
              charLabel = sparseArrHybrid_RussToEng.get(hash);
            }
          }
        }

        // English Keyboard
        else if (ApplicationContext.getInstance().keyboardType.equals("English")) {
          try {
            charLabel = sparseArrEnglish.get(hash);
          } catch (Exception e) {
            BugSenseHandler.addCrashExtraData(
                "KeyBindings", "Exception in dispatchKeyEvent: " + e.getMessage());
            BugSenseHandler.leaveBreadcrumb("KeyBindings.keyboardType.equals(\"English\")");
            BugSenseHandler.sendException(e);
            Crashlytics.setString("KeyBindings", "keyboardType.equals(\"English\")");
            Crashlytics.logException(e);
          }
        }

        if (event.getKeyCode()
            != KeyEvent.KEYCODE_UNKNOWN) { // physical key was pressed on physical GoogTV keyboard
          if (event.getAction() == KeyEvent.ACTION_UP) {
            if (keyCode == KeyEvent.KEYCODE_DEL) {
              SearchFragmentTab.backSpace(true);
            } else {
              if (event.getAction() == KeyEvent.ACTION_UP)
                if (event.getKeyCode() == KeyEvent.KEYCODE_BACK) {
                  Intent intent = new Intent("key_bindings_event");
                  intent.putExtra("message", "onBackPressed");
                  LocalBroadcastManager.getInstance(ApplicationContext.getInstance())
                      .sendBroadcast(intent);
                } else {
                  SearchFragmentTab.typeText(charLabel);
                  // ---keep track of key presses to avoid double-typing on Goog TV---
                  SearchFragmentTab.ENGLISH_KBD_BACKSPACE = false;
                }
            }
          }
        } else { // soft input key was pressed on IMM keyboard
          SearchFragmentTab.typeText(charLabel);
          SearchFragmentTab.ENGLISH_KBD_BACKSPACE = false;
        }
      }
    }
コード例 #2
0
    /** Keyboard event processing for non-Google TV devices */
    private void handleNonGoogTvKeyPress(KeyEvent event, int keyCode) {
      int hash;
      String charLabel = "";

      hash = BasicOnKeyboardActionListener.KEY_PRESSED;
      if (hash == 3) {
        // Space key
        try {
          SearchFragmentTab.typeText(" ");
          SearchFragmentTab.ENGLISH_KBD_BACKSPACE = false;
        } catch (Exception e) {
          BugSenseHandler.addCrashExtraData(
              "KeyBindings", "dispatchKeyEvent (not google tv)" + e.getMessage());
          BugSenseHandler.leaveBreadcrumb("KeyBindings.handleNonGoogTvKeyPress");
          BugSenseHandler.sendException(e);
          Crashlytics.setString("KeyBindings", "dispatchKeyEvent (not google tv)");
          Crashlytics.logException(e);
        }
      } else if (hash == 591) {
        // Shift button was pressed on the Russian keyboard
        // do what?
      } else if (hash == 0) {
        // ---A letter was pressed on the English keyboard---
        SearchFragmentTab.retainSearch();
      } else {
        // ---Regular key was pressed---
        ApplicationContext.getInstance().readyToSearch = true;

        if (ApplicationContext.getInstance().keyboardType.equals("Russian")) {
          charLabel = sparseArrRussian.get(hash);
        } else if (ApplicationContext.getInstance().keyboardType.equals("Hybrid")) {
          if (ApplicationContext.getInstance()
              .getHybridKeyboardMode()
              .equals("Hybrid_English_To_Russ")) {
            charLabel = sparseArrHybrid_EngToRuss.get(hash);
          } else if (ApplicationContext.getInstance()
              .getHybridKeyboardMode()
              .equals("Hybrid_Russian_To_Eng")) {
            charLabel = sparseArrHybrid_RussToEng.get(hash);
          }
        } else if (ApplicationContext.getInstance().keyboardType.equals("English")) {
          try {
            if (sparseArrEnglish != null) charLabel = sparseArrEnglish.get(hash);
          } catch (Exception e) {
            BugSenseHandler.addCrashExtraData(
                "KeyBindings", "regular key was pressed" + e.getMessage());
            BugSenseHandler.leaveBreadcrumb("KeyBindings.handleNonGoogTvKeyPress");
            BugSenseHandler.sendException(e);
            Crashlytics.setString("KeyBindings", "regular key was pressed");
            Crashlytics.logException(e);
          }
        }

        if (keyCode != KeyEvent.KEYCODE_BACK
            && keyCode != KeyEvent.KEYCODE_POWER
            && keyCode != KeyEvent.KEYCODE_VOLUME_UP
            && keyCode != KeyEvent.KEYCODE_VOLUME_DOWN) {
          if (keyCode == KeyEvent.KEYCODE_DEL) {
            SearchFragmentTab.backSpace(true);
          } else {
            SearchFragmentTab.typeText(charLabel);
          }
        }
        SearchFragmentTab.ENGLISH_KBD_BACKSPACE = false;
      }
    }