触摸错过的事件

时间:2014-10-14 07:38:35

标签: android

Q值。我试图在代码中捕获触摸事件,它们似乎工作但是没有抓住屏幕的第一次触摸?

下面是日志打印输出,它知道触摸但它不允许我捕获它?任何帮助将非常感激。

我已经包含了ontouch事件的代码,onCreate和setViewFeatures:

在活动的顶部我有

    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=]

1 个答案:

答案 0 :(得分:0)

如果侦听器从头开始调用(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;
   }
}

在你的代码中,你可以在电影开始时开始聆听。