简体   繁体   中英

Touch Event Missed

Q. I am trying to capture touch events in code, they appear to work but do not catch the first touch of the screen?

Below is the log printout, it knows about the touch but its not allowing me to capture it? any help would be much appreciated.

I have included the code for the ontouch event, onCreate and the setViewFeatures:

At the top of the activity I have

    public class MediaActivity extends Activity implements OnCompletionListener, OnErrorListener,   OnInfoListener,
    OnPreparedListener, OnSeekCompleteListener, OnTouchListener, OnVideoSizeChangedListener,
    SurfaceHolder.Callback, MediaController.MediaPlayerControl

    @Override
    public void onCreate(Bundle savedInstanceState)
    {

    super.onCreate(savedInstanceState);

    setViewFeatures();

    setSessionData();

    setContentView(R.layout.activity_media);



    setProgressBar();

    createPADialog();

    setDRMListeners();

    setClientAndServer();

    setButtonListeners();

    // Might use this for getting ref. for grabbing view when its first
    // displayed...
    // View v =
    // getWindow().getDecorView().findViewById(android.R.id.content);

    try
    {

        setSurfaceView();

    }
    catch (Exception e)
    {
        errorLevel = ERRORS.CRITICAL;
        callError("UNABLE TO RUN MediaActivity", errorLevel);
    }

    }

    private void setViewFeatures()
    {


    requestWindowFeature(Window.FEATURE_NO_TITLE);

    int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION 
                  | View.SYSTEM_UI_FLAG_FULLSCREEN
                  | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION 
                  | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                  | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 
                  | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;

    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(uiOptions);

    int flags = WindowManager.LayoutParams.FLAG_FULLSCREEN 
              | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
              | WindowManager.LayoutParams.FLAG_TOUCHABLE_WHEN_WAKING
              | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED 
              | WindowManager.LayoutParams.FLAG_FULLSCREEN;

    getWindow().addFlags(flags);

    }

    @Override
    public boolean onTouch(View v, MotionEvent event)
    {

    Log.d("TAG", "In onTouch ");
    try
    {
        if (event.getAction() == MotionEvent.ACTION_DOWN)
        {
            if (topBar.isOpened())
            {
                callCloseBars();
            }
            else
            {
                callOpenBars();
            }
        }
    }
    catch (Exception e)
    {
        Log.d("TAG", e.getMessage());
    }

         return true;
    }


    10-14 07:33:09.900: I/InputReader(192): Touch event's action is 0x0 (deviceType=0) [pCnt=1, pending(waiting finished signal)=0, s=0.80 ]
    10-14 07:33:09.910: I/InputDispatcher(192): Delivering touch to current input target: action: 0x0
    10-14 07:33:09.910: I/InputDispatcher(192): Delivering touch to current input target: action: 0x0
    10-14 07:33:09.910: D/InputDispatcher(192): [drainOutboundQueueLocked] initialize cntPair(sender-receiver)
    10-14 07:33:09.910: I/InputQueue-JNI(192): Sending finished signal for input channel 'hidden nav  (client)' since it is being unregistered while an input message is still in progress.
    10-14 07:33:09.910: I/InputQueue-JNI(192): Ignoring finish signal on channel that is no longer registered.
    10-14 07:33:09.910: I/PowerManagerService(192): Ulight 3->7|0
    10-14 07:33:09.910: D/PowerManagerService(192): setLightBrightness : mButtonLight : 255
    10-14 07:33:10.060: D/Tethering(192): getTetheredIfacePairs
    10-14 07:33:10.080: I/InputReader(192): Touch event's action is 0x1 (deviceType=0) [pCnt=1,    pending(waiting finished signal)=0, s=]

This is the solution if the listener called from the beginning(OnCreate):

public class MainActivity extends ActionBarActivity implements OnTouchListener {
    View view;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        view = (View)findViewById(R.id.view1);
        view.setOnTouchListener(this);
    }

@Override
public boolean onTouch(View v, MotionEvent event) {
     Log.d("TAG", "In onTouch ");
        try
        {
            if (event.getAction() == MotionEvent.ACTION_DOWN)
            {
                i = 1;
            }
        }
        catch (Exception e)
        {
            Log.d("TAG", e.getMessage());
        }
    return true;
   }
}

In your code you can start the listening when the film start.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM