InputMethod中的AirView无法正常工作

我正在尝试使用三星Galaxy S4的新AirView功能,特别是onHover事件。我已经通过...来正常工作


定位API级别17
提供一个onHover事件监听器
设置com.sec.android.airview.HOVER的意图过滤器


现在,我想将其用于输入法。我的问题是,即使我也设置了airview意图过滤器,输入方法的视图也没有任何onHover事件:

AndroidManifest.xml的摘录:

<application android:label="@string/ime_name"
    <service android:name="com.example.keyboard"
        android:permission="android.permission.BIND_INPUT_METHOD">
        <intent-filter>
            <action android:name="android.view.InputMethod" />
        </intent-filter>
        <intent-filter>
            <action android:name="com.sec.android.airview.HOVER" />
        </intent-filter>
        <meta-data android:name="android.view.im" android:resource="@xml/method" />
    </service>
</application>


目前,我在输入法布局中有一个带有单个按钮的简单LinearLayout:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hover Button"
        android:id="@+id/hoverbutton2"/>

</LinearLayout>


事件侦听器的设置如下:

Button hoverButton = (Button) mInputView.findViewById(R.id.hoverbutton2);
hoverButton.setOnHoverListener(new View.OnHoverListener() {
    @Override
    public boolean onHover(View v, MotionEvent event) {
        Log.d(TAG, "hoverButton2: onHover");
        return false;
    }
});


以相同方式设置的onClick侦听器可以按预期工作。

有指针吗?

最佳答案

我有同样的问题。我找到了Furbyx92在xda dev上发布的解决方案:


首先要确保在“设备”的“设置”中,将AirView的所有子设置都设置为“开”。
接下来的Android清单:

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <meta-data
        android:name="com.sec.android.airview.enable"
        android:value="true" />
    <intent-filter>
        <action android:name="com.sec.android.airview.HOVER" />
    </intent-filter>
    <activity
        android:name="edu.uanl.secondapp.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="com.sec.android.airview.HOVER" />
        </intent-filter>
    </activity>
</application>

在您的代码中:

textView.setOnHoverListener(new View.OnHoverListener() {
    @override
    public boolean onHover(View view, MotionEvent motionEvent) {
        switch(motionEvent.getAction()){
            case MotionEvent.ACTION_HOVER_ENTER : // Enter Hovered
            case MotionEvent.ACTION_HOVER_EXIT:   // Leave Hovered
                view.setBackgroundColor(Color.TRANSPARENT);
                view.setScaleX((float)1.0);
                view.setScaleY((float)1.0);
                break;
            case MotionEvent.ACTION_HOVER_MOVE:   // On Hover
                view.setBackgroundColor(Color.RED);
                view.setScaleX((float)2.0);
                view.setScaleY((float)2.0);
                break;
        }
        Log.wtf("Something", "I'm Being Hovered" + motionEvent.getAction());
        return false;
    }
});
textView.setHovered(true);

10-08 07:12