Skip to content

Commit

Permalink
[droid] break input into classes
Browse files Browse the repository at this point in the history
I couldn't come up with any way to do this in smaller chunks, so instead we get
one big lump of a change. Yikes. No functionality was changed, this is a
reshuffle only.
  • Loading branch information
Cory Fields committed Jul 17, 2012
1 parent c77f197 commit 620eb23
Show file tree
Hide file tree
Showing 9 changed files with 634 additions and 523 deletions.
138 changes: 138 additions & 0 deletions xbmc/android/activity/AndroidKey.cpp
@@ -0,0 +1,138 @@
/*
* Copyright (C) 2012 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/

#include "AndroidKey.h"
#include "XBMCApp.h"
#include "guilib/Key.h"
#include "windowing/WinEvents.h"

static KeyMap keyMap[] = {
// first list all keys that we don't handle
{ AKEYCODE_HOME , XBMCK_LAST },
{ AKEYCODE_POWER , XBMCK_LAST },

// now list all the keys with special functionality
{ AKEYCODE_BACK , XBMCK_BACKSPACE },
{ AKEYCODE_DPAD_UP , XBMCK_UP },
{ AKEYCODE_DPAD_DOWN , XBMCK_DOWN },
{ AKEYCODE_DPAD_LEFT , XBMCK_LEFT },
{ AKEYCODE_DPAD_RIGHT , XBMCK_RIGHT },
{ AKEYCODE_DPAD_CENTER , XBMCK_RETURN },
{ AKEYCODE_VOLUME_UP , XBMCK_VOLUME_UP },
{ AKEYCODE_VOLUME_DOWN , XBMCK_VOLUME_DOWN },
{ AKEYCODE_MUTE , XBMCK_VOLUME_MUTE },
{ AKEYCODE_MENU , XBMCK_MENU }
};

bool CAndroidKey::onKeyboardEvent(AInputEvent* event)
{
CXBMCApp::android_printf("%s", __PRETTY_FUNCTION__);
if (event == NULL)
return false;

int32_t keycode = AKeyEvent_getKeyCode(event);
int32_t flags = AKeyEvent_getFlags(event);
int32_t state = AKeyEvent_getMetaState(event);
int32_t repeatCount = AKeyEvent_getRepeatCount(event);

// Check if we got some special key
uint16_t sym = XBMCK_UNKNOWN;
for (unsigned int index = 0; index < sizeof(keyMap) / sizeof(KeyMap); index++)
{
if (keycode == keyMap[index].nativeKey)
{
sym = keyMap[index].xbmcKey;
break;
}
}

// check if this is a key we don't want to handle
if (sym == XBMCK_LAST)
return false;

uint16_t modifiers = 0;
if (state & AMETA_ALT_LEFT_ON)
modifiers |= XBMCKMOD_LALT;
if (state & AMETA_ALT_RIGHT_ON)
modifiers |= XBMCKMOD_RALT;
if (state & AMETA_SHIFT_LEFT_ON)
modifiers |= XBMCKMOD_LSHIFT;
if (state & AMETA_SHIFT_RIGHT_ON)
modifiers |= XBMCKMOD_RSHIFT;
/* TODO:
if (state & AMETA_SYM_ON)
modifiers |= 0x000?;*/

switch (AKeyEvent_getAction(event))
{
case AKEY_EVENT_ACTION_DOWN:
CXBMCApp::android_printf("CXBMCApp: key down (code: %d; repeat: %d; flags: 0x%0X; alt: %s; shift: %s; sym: %s)",
keycode, repeatCount, flags,
(state & AMETA_ALT_ON) ? "yes" : "no",
(state & AMETA_SHIFT_ON) ? "yes" : "no",
(state & AMETA_SYM_ON) ? "yes" : "no");
XBMC_Key((uint8_t)keycode, sym, modifiers, false);
return true;

case AKEY_EVENT_ACTION_UP:
CXBMCApp::android_printf("CXBMCApp: key up (code: %d; repeat: %d; flags: 0x%0X; alt: %s; shift: %s; sym: %s)",
keycode, repeatCount, flags,
(state & AMETA_ALT_ON) ? "yes" : "no",
(state & AMETA_SHIFT_ON) ? "yes" : "no",
(state & AMETA_SYM_ON) ? "yes" : "no");
XBMC_Key((uint8_t)keycode, sym, modifiers, true);
return true;

case AKEY_EVENT_ACTION_MULTIPLE:
CXBMCApp::android_printf("CXBMCApp: key multiple (code: %d; repeat: %d; flags: 0x%0X; alt: %s; shift: %s; sym: %s)",
keycode, repeatCount, flags,
(state & AMETA_ALT_ON) ? "yes" : "no",
(state & AMETA_SHIFT_ON) ? "yes" : "no",
(state & AMETA_SYM_ON) ? "yes" : "no");
break;

default:
CXBMCApp::android_printf("CXBMCApp: unknown key (code: %d; repeat: %d; flags: 0x%0X; alt: %s; shift: %s; sym: %s)",
keycode, repeatCount, flags,
(state & AMETA_ALT_ON) ? "yes" : "no",
(state & AMETA_SHIFT_ON) ? "yes" : "no",
(state & AMETA_SYM_ON) ? "yes" : "no");
break;
}

return false;
}

void CAndroidKey::XBMC_Key(uint8_t code, uint16_t key, uint16_t modifiers, bool up)
{
XBMC_Event newEvent;
memset(&newEvent, 0, sizeof(newEvent));

unsigned char type = up ? XBMC_KEYUP : XBMC_KEYDOWN;
newEvent.type = type;
newEvent.key.type = type;
newEvent.key.keysym.scancode = code;
newEvent.key.keysym.sym = (XBMCKey)key;
newEvent.key.keysym.unicode = key;
newEvent.key.keysym.mod = (XBMCMod)modifiers;

CXBMCApp::android_printf("XBMC_Key(%u, %u, 0x%04X, %d)", code, key, modifiers, up);
CWinEvents::MessagePush(&newEvent);
}
37 changes: 37 additions & 0 deletions xbmc/android/activity/AndroidKey.h
@@ -0,0 +1,37 @@
#pragma once
/*
* Copyright (C) 2012 Team XBMC
* http://www.xbmc.org
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/

#include <stdint.h>
#include <android/input.h>

typedef struct {
int32_t nativeKey;
int16_t xbmcKey;
} KeyMap;

class CAndroidKey
{
public:
CAndroidKey(){};
~CAndroidKey(){};
void XBMC_Key(uint8_t code, uint16_t key, uint16_t modifiers, bool up);
bool onKeyboardEvent(AInputEvent* event);
};

0 comments on commit 620eb23

Please sign in to comment.