首页 文章 精选 留言 我的

精选列表

搜索[应用与服务编排工作流],共10000篇文章
优秀的个人博客,低调大师

Android应用程序键盘(Keyboard)消息处理机制分析(7)

函数首先根据文件名来打开这个设备文件: fd=open(deviceName,O_RDWR); 系统中所有输入设备文件信息都保存在成员变量mDevicesById中,因此,先在mDevicesById找到一个空位置来保存当前打开的设备文件信息: mDevicesById[devid].seq=(mDevicesById[devid].seq+(1<<SEQ_SHIFT))&SEQ_MASK; if(mDevicesById[devid].seq==0){ mDevicesById[devid].seq=1<<SEQ_SHIFT; } 找到了空闲位置后,就为这个输入设备文件创建相应的device_t信息: mDevicesById[devid].seq=(mDevicesById[devid].seq+(1<<SEQ_SHIFT))&SEQ_MASK; if(mDevicesById[devid].seq==0){ mDevicesById[devid].seq=1<<SEQ_SHIFT; } new_mFDs=(pollfd*)realloc(mFDs,sizeof(mFDs[0])*(mFDCount+1)); new_devices=(device_t**)realloc(mDevices,sizeof(mDevices[0])*(mFDCount+1)); if(new_mFDs==NULL||new_devices==NULL){ LOGE("outofmemory"); return-1; } mFDs=new_mFDs; mDevices=new_devices; ...... device_t*device=newdevice_t(devid|mDevicesById[devid].seq,deviceName,name); if(device==NULL){ LOGE("outofmemory"); return-1; } device->fd=fd; 同时,这个设备文件还会保存在数组mFDs中: mFDs[mFDCount].fd=fd; mFDs[mFDCount].events=POLLIN; mFDs[mFDCount].revents=0; 接下来查看这个设备是不是键盘: //Figureoutthekindsofeventsthedevicereports. uint8_tkey_bitmask[sizeof_bit_array(KEY_MAX+1)]; memset(key_bitmask,0,sizeof(key_bitmask)); LOGV("Gettingkeys..."); if(ioctl(fd,EVIOCGBIT(EV_KEY,sizeof(key_bitmask)),key_bitmask)>=0){ //Seeifthisisakeyboard.Ignoreeverythinginthebuttonrangeexceptfor //gamepadswhicharealsoconsideredkeyboards. if(containsNonZeroByte(key_bitmask,0,sizeof_bit_array(BTN_MISC)) ||containsNonZeroByte(key_bitmask,sizeof_bit_array(BTN_GAMEPAD), sizeof_bit_array(BTN_DIGI)) ||containsNonZeroByte(key_bitmask,sizeof_bit_array(KEY_OK), sizeof_bit_array(KEY_MAX+1))){ device->classes|=INPUT_DEVICE_CLASS_KEYBOARD; device->keyBitmask=newuint8_t[sizeof(key_bitmask)]; if(device->keyBitmask!=NULL){ memcpy(device->keyBitmask,key_bitmask,sizeof(key_bitmask)); }else{ deletedevice; LOGE("outofmemoryallocatingkeybitmask"); return-1; } } } 如果是的话,还要继续进一步初始化前面为这个设备文件所创建的device_t结构体,主要就是把结构体device的classes成员变量的INPUT_DEVICE_CLASS_KEYBOARD位置为1了,以表明这是一个键盘。 如果是键盘设备,初始化工作还未完成,还要继续设置键盘的布局等信息: if((device->classes&INPUT_DEVICE_CLASS_KEYBOARD)!=0){ chartmpfn[sizeof(name)]; charkeylayoutFilename[300]; //amoredescriptivename device->name=name; //replaceallthespaceswithunderscores strcpy(tmpfn,name); for(char*p=strchr(tmpfn,'');p&&*p;p=strchr(tmpfn,'')) *p='_'; //findthe.klfileweneedforthisdevice constchar*root=getenv("ANDROID_ROOT"); snprintf(keylayoutFilename,sizeof(keylayoutFilename), "%s/usr/keylayout/%s.kl",root,tmpfn); booldefaultKeymap=false; if(access(keylayoutFilename,R_OK)){ snprintf(keylayoutFilename,sizeof(keylayoutFilename), "%s/usr/keylayout/%s",root,"qwerty.kl"); defaultKeymap=true; } status_tstatus=device->layoutMap->load(keylayoutFilename); if(status){ LOGE("Error%dloadingkeylayout.",status); } //telltheworldaboutthedevname(thedescriptivename) if(!mHaveFirstKeyboard&&!defaultKeymap&&strstr(name,"-keypad")){ //thebuilt-inkeyboardhasawell-knowndeviceIDof0, //thisdevicebetternotgoaway. mHaveFirstKeyboard=true; mFirstKeyboardId=device->id; property_set("hw.keyboards.0.devname",name); }else{ //ensuremFirstKeyboardIdissetto-something-. if(mFirstKeyboardId==0){ mFirstKeyboardId=device->id; } } charpropName[100]; sprintf(propName,"hw.keyboards.%u.devname",device->id); property_set(propName,name); //'Q'keysupport=cheaptestofwhetherthisisanalpha-capablekbd if(hasKeycodeLocked(device,AKEYCODE_Q)){ device->classes|=INPUT_DEVICE_CLASS_ALPHAKEY; } //SeeifthisdevicehasaDPAD. if(hasKeycodeLocked(device,AKEYCODE_DPAD_UP)&& hasKeycodeLocked(device,AKEYCODE_DPAD_DOWN)&& hasKeycodeLocked(device,AKEYCODE_DPAD_LEFT)&& hasKeycodeLocked(device,AKEYCODE_DPAD_RIGHT)&& hasKeycodeLocked(device,AKEYCODE_DPAD_CENTER)){ device->classes|=INPUT_DEVICE_CLASS_DPAD; } //Seeifthisdevicehasagamepad. for(size_ti=0;i<sizeof(GAMEPAD_KEYCODES)/sizeof(GAMEPAD_KEYCODES[0]);i++){ if(hasKeycodeLocked(device,GAMEPAD_KEYCODES[i])){ device->classes|=INPUT_DEVICE_CLASS_GAMEPAD; break; } } LOGI("Newkeyboard:device->id=0x%xdevname='%s'propName='%s'keylayout='%s'\n", device->id,name,propName,keylayoutFilename); } 到这里,系统中的输入设备文件就打开了。 本文转自 Luoshengyang 51CTO博客,原文链接:http://blog.51cto.com/shyluo/966619,如需转载请自行联系原作者

优秀的个人博客,低调大师

让android应用程序跳转到系统的各个设置页面

在android SDK文档中有这样一个类,android.provider.Settings类提供android系统各个页面的跳转常量: String ACTION_ACCESSIBILITY_SETTINGS Activity Action: Show settings for accessibility modules. String ACTION_ADD_ACCOUNT Activity Action: Show add account screen for creating a new account. String ACTION_AIRPLANE_MODE_SETTINGS Activity Action: Show settings to allow entering/exiting airplane mode. String ACTION_APN_SETTINGS Activity Action: Show settings to allow configuration of APNs. String ACTION_APPLICATION_DETAILS_SETTINGS Activity Action: Show screen of details about a particular application. String ACTION_APPLICATION_DEVELOPMENT_SETTINGS Activity Action: Show settings to allow configuration of application development-related settings. String ACTION_APPLICATION_SETTINGS Activity Action: Show settings to allow configuration of application-related settings. String ACTION_BLUETOOTH_SETTINGS Activity Action: Show settings to allow configuration of Bluetooth. String ACTION_DATA_ROAMING_SETTINGS Activity Action: Show settings for selection of2G/3G. String ACTION_DATE_SETTINGS Activity Action: Show settings to allow configuration of date and time. String ACTION_DEVICE_INFO_SETTINGS Activity Action: Show general device information settings (serial number, software version, phone number, etc.). String ACTION_DISPLAY_SETTINGS Activity Action: Show settings to allow configuration of display. String ACTION_INPUT_METHOD_SETTINGS Activity Action: Show settings to configure input methods, in particular allowing the user to enable input methods. String ACTION_INPUT_METHOD_SUBTYPE_SETTINGS Activity Action: Show settings to enable/disable input method subtypes. String ACTION_INTERNAL_STORAGE_SETTINGS Activity Action: Show settings for internal storage. String ACTION_LOCALE_SETTINGS Activity Action: Show settings to allow configuration of locale. String ACTION_LOCATION_SOURCE_SETTINGS Activity Action: Show settings to allow configuration of current location sources. String ACTION_MANAGE_ALL_APPLICATIONS_SETTINGS Activity Action: Show settings to manage all applications. String ACTION_MANAGE_APPLICATIONS_SETTINGS Activity Action: Show settings to manage installed applications. String ACTION_MEMORY_CARD_SETTINGS Activity Action: Show settings for memory card storage. String ACTION_NETWORK_OPERATOR_SETTINGS Activity Action: Show settings for selecting the network operator. String ACTION_PRIVACY_SETTINGS Activity Action: Show settings to allow configuration of privacy options. String ACTION_QUICK_LAUNCH_SETTINGS Activity Action: Show settings to allow configuration of quick launch shortcuts. String ACTION_SEARCH_SETTINGS Activity Action: Show settings for global search. String ACTION_SECURITY_SETTINGS Activity Action: Show settings to allow configuration of security and location privacy. String ACTION_SETTINGS Activity Action: Show system settings. String ACTION_SOUND_SETTINGS Activity Action: Show settings to allow configuration of sound and volume. String ACTION_SYNC_SETTINGS Activity Action: Show settings to allow configuration of sync settings. String ACTION_USER_DICTIONARY_SETTINGS Activity Action: Show settings to manage the user input dictionary. String ACTION_WIFI_IP_SETTINGS Activity Action: Show settings to allow configuration of a static IP address for Wi-Fi. String ACTION_WIFI_SETTINGS Activity Action: Show settings to allow configuration of Wi-Fi. String ACTION_WIRELESS_SETTINGS Activity Action: Show settings to allow configuration of wireless controls such as Wi-Fi, Bluetooth and Mobile networks. String AUTHORITY String EXTRA_AUTHORITIES Activity Extra: Limit available options in launched activity based on the given authority. String EXTRA_INPUT_METHOD_ID 如何使用呢? 例如:startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS)); 即可跳到android手机网络设置页面。 如果要launch Mobile NetworksSetting页面按如下方法: Intent intent=new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS); ComponentName cName = new ComponentName("com.android.phone","com.android.phone.Settings"); intent.setComponent(cName); startActivity(intent); 如果要进入Networks Operators页面按如下方法: Intent intent = new Intent(Intent.ACTION_MAIN); intent.setClassName("com.android.phone", "com.android.phone.NetworkSetting"); startActivity(intent); 本文转自java豆子博客园博客,原文链接:http://www.cnblogs.com/error404/archive/2011/11/10/2244761.html,如需转载请自行联系原作者

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

腾讯云软件源

腾讯云软件源

为解决软件依赖安装时官方源访问速度慢的问题,腾讯云为一些软件搭建了缓存服务。您可以通过使用腾讯云软件源站来提升依赖包的安装速度。为了方便用户自由搭建服务架构,目前腾讯云软件源站支持公网访问和内网访问。

Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

用户登录
用户注册