inputdevice add some sensor detection

This commit is contained in:
侯歌 2024-04-10 16:13:12 +08:00
parent b69db27cbc
commit 33c4ae0998
5 changed files with 37 additions and 5 deletions

View File

@ -483,17 +483,22 @@ ColorStateList* Assets::getColorStateList(const std::string&fullresid) {
}
typedef struct {
XML_Parser parser;
cdroid::Context*context;
std::vector<std::string> tags;
std::vector<AttributeSet> attrs;
std::string content;
std::string resourceId;
std::string package;
std::function<void(const std::vector<std::string>&,const std::vector<AttributeSet>&attrs,const std::string&)>func;
} KVPARSER;
static void startElement(void *userData, const XML_Char *name, const XML_Char **satts) {
KVPARSER* kvp = (KVPARSER*)userData;
if(strcmp(name,"resources")) { //root node is not in KVPARSER::attrs
AttributeSet atts;
AttributeSet atts(kvp->context,kvp->package);
atts.set(satts);
atts.add("resourceId",kvp->resourceId);
kvp->tags.push_back(name);
kvp->attrs.push_back(atts);
kvp->content = std::string();
@ -529,7 +534,12 @@ int Assets::loadKeyValues(const std::string&fullresid,std::function<void(const s
std::string curKey;
std::string curValue;
KVPARSER kvp;
auto pos = fullresid.find(".xml");
kvp.context = this;
kvp.parser = parser;
kvp.resourceId = fullresid.substr(0,pos);
kvp.func = func;
parseResource(fullresid,nullptr,&kvp.package);
XML_SetUserData(parser,&kvp);
XML_SetElementHandler(parser, startElement, endElement);
XML_SetCharacterDataHandler(parser,CharacterHandler);

View File

@ -74,6 +74,19 @@ InputDevice::InputDevice(int fdev){
if(TEST_BIT(BTN_MOUSE,devInfos.keyBitMask) &&TEST_BIT(REL_X,devInfos.relBitMask) &&TEST_BIT(REL_Y,devInfos.relBitMask))
mDeviceClasses = INPUT_DEVICE_CLASS_CURSOR;
if(TEST_BIT(ABS_DISTANCE, devInfos.absBitMask)){
//Proximity sensor
}
if(TEST_BIT(ABS_X, devInfos.absBitMask) && TEST_BIT(ABS_Y, devInfos.absBitMask) && TEST_BIT(ABS_Z, devInfos.absBitMask)){
//Accelerometer sensor
}
if(TEST_BIT(ABS_RX, devInfos.absBitMask) && TEST_BIT(ABS_RY, devInfos.absBitMask) && TEST_BIT(ABS_RZ, devInfos.absBitMask)){
//Gyroscope sensor
}
if(TEST_BIT(ABS_HAT0X, devInfos.absBitMask) && TEST_BIT(ABS_HAT0Y, devInfos.absBitMask)
&& TEST_BIT(ABS_HAT1X, devInfos.absBitMask) && TEST_BIT(ABS_HAT1Y, devInfos.absBitMask)){
//Magnetometer sensor
}
if(TEST_BIT(ABS_MT_POSITION_X, devInfos.absBitMask) && TEST_BIT(ABS_MT_POSITION_Y, devInfos.absBitMask)) {
// Some joysticks such as the PS3 controller report axes that conflict
// with the ABS_MT range. Try to confirm that the device really is a touch screen.
@ -81,9 +94,10 @@ InputDevice::InputDevice(int fdev){
mDeviceClasses |= INPUT_DEVICE_CLASS_TOUCH | INPUT_DEVICE_CLASS_TOUCH_MT;
}
// Is this an old style single-touch driver?
} else if (TEST_BIT(BTN_TOUCH, devInfos.keyBitMask)
&& TEST_BIT(ABS_X, devInfos.absBitMask) && TEST_BIT(ABS_Y, devInfos.absBitMask)) {
mDeviceClasses |= INPUT_DEVICE_CLASS_TOUCH;
} else if ( TEST_BIT(ABS_X, devInfos.absBitMask) && TEST_BIT(ABS_Y, devInfos.absBitMask) ) {
if(TEST_BIT(BTN_TOUCH, devInfos.keyBitMask)) mDeviceClasses |= INPUT_DEVICE_CLASS_TOUCH;
else mDeviceClasses |= INPUT_DEVICE_CLASS_ROTARY_ENCODER;
LOGD("%s",TEST_BIT(BTN_TOUCH, devInfos.keyBitMask)?"Touch Device":"Rotaty Encoder");
// Is this a BT stylus?
} else if ((TEST_BIT(ABS_PRESSURE, devInfos.absBitMask) || TEST_BIT(BTN_TOUCH, devInfos.keyBitMask))
&& !TEST_BIT(ABS_X, devInfos.absBitMask) && !TEST_BIT(ABS_Y, devInfos.absBitMask)) {

View File

@ -11,7 +11,7 @@ private:
public:
bool mAutoMirrored;
int mFrameCount;
int mAlpha;
int mAlpha;
FrameSequence*mFrameSequence;
AnimatedImageState();
AnimatedImageState(const AnimatedImageState& state);

View File

@ -22,6 +22,13 @@ ColorStateList::ColorStateList(int color)
:ColorStateList(EMPTY,{color}){
}
int ColorStateList::addStateColor(cdroid::Context*ctx,const AttributeSet&atts){
std::vector<int>states;
const int color = ctx->getColor(atts.getString("color"));
StateSet::parseState(states,atts);
return addStateColor(states,color);
}
ColorStateList::ColorStateList(const ColorStateList&other)
:ColorStateList(other.mStateSpecs,other.mColors){
mIsOpaque = other.mIsOpaque;

View File

@ -29,6 +29,7 @@ public:
ColorStateList(const std::vector<std::vector<int>>&states,const std::vector<int>&colors);
~ColorStateList();
int addStateColor(const std::vector<int>&stateSet,int color);
int addStateColor(cdroid::Context*,const AttributeSet&);
int getDefaultColor()const override;
bool isOpaque()const;
bool isStateful()const override;