Obtaining Touch Data Generated on the Touch Engine Client
Application Scenario
Obtain the touch data generated on the client and send the touch data by calling the API provided by the touch engine client.
Prerequisites
The touch engine client depends on the Android View.
Development Process
- Register the hook function for sending touch data on the client.
- The touch engine client is inherited from View.OnTouchListener of Android. Call the setOnTouchListener interface function at the Android View layer.
- In the onTouch methods of the input parameter View.OnTouchListener() of the preceding interface function, call the onTouch method of the touch engine client.
Encoding Instance
Scenario
According to the development process, call the API of the touch engine client to obtain the touch data generated by View and send the data to the server.
Code Sample
import android.util.Log;
import android.view.View;
import com.huawei.cloudgame.touch.TOUCHSENDHOOK;
import com.huawei.cloudgame.touch.VmiTouch;
public class DataPipe implements TOUCHSENDHOOK{
private static DataPipe instance = new DataPipe();
private DataPipe() {
}
public static DataPipe getInstance() {
return instance;
}
public void touchSendData(byte[] data, int length) {
// The data sending interface function is implemented by you.
}
public static void registerHookToTouch() {
int ret = VmiTouch.getInstance().registerTouchSendHook(DataPipe.getInstance());
if (ret != VmiTouch.VMI_SUCCESS) {
Log.e("TouchClient", "register touch send hook fail");
}
}
}
public class Test {
public static void main(String[] args) {
DataPipe.registerHookToTouch();
View view = getDisplayView() // Example function for obtaining the client View.
view.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent event) {
return VmiTouch.getInstance().onTouch(view, event);
}
});
}
}
Parent topic: Touch Engine Client