Example usage for android.view MotionEvent getDownTime

List of usage examples for android.view MotionEvent getDownTime

Introduction

In this page you can find the example usage for android.view MotionEvent getDownTime.

Prototype

public final long getDownTime() 

Source Link

Document

Returns the time (in ms) when the user originally pressed down to start a stream of position events.

Usage

From source file:com.github.pedrovgs.DraggableView.java

/**
 * Clone given motion event and set specified action. This method is useful, when we want to
 * cancel event propagation in child views by sending event with {@link MotionEvent#ACTION_CANCEL} action.
 * @param event event to clone/*from  w  w w  .  ja  v a 2  s  .  c om*/
 * @param action new action
 * @return cloned motion event
 */
private MotionEvent cloneMotionEventWithAction(MotionEvent event, int action) {
    return MotionEvent.obtain(event.getDownTime(), event.getEventTime(), action, event.getX(), event.getY(),
            event.getMetaState());
}

From source file:com.smsc.usuario.ui.MapaActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mapa);/*from  w w  w .j ava2  s .c  om*/

    Button btnIncendio = (Button) findViewById(R.id.btnIncendio);
    OnTouchListener btnIncendioListener = new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP
                    && event.getEventTime() - event.getDownTime() >= 1000) {
                Toast.makeText(MapaActivity.this, "Incendio", Toast.LENGTH_SHORT).show();
                Intent i = new Intent(MapaActivity.this, RegistrarIncidenteActivity.class);
                i.putExtra("ID", "" + 2);
                i.putExtra("latitude", "" + latitude);
                i.putExtra("longitude", "" + longitude);
                startActivity(i);
            }
            return false;
        }
    };
    btnIncendio.setOnTouchListener(btnIncendioListener);

    Button btnSecuestro = (Button) findViewById(R.id.btnSecuestro);
    OnTouchListener btnSecuestroListener = new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP
                    && event.getEventTime() - event.getDownTime() >= 1000) {
                Toast.makeText(MapaActivity.this, "Secuestro", Toast.LENGTH_SHORT).show();
                Intent i = new Intent(MapaActivity.this, RegistrarIncidenteActivity.class);
                i.putExtra("ID", "" + 3);
                i.putExtra("latitude", "" + latitude);
                i.putExtra("longitude", "" + longitude);
                startActivity(i);
            }
            return false;
        }
    };
    btnSecuestro.setOnTouchListener(btnSecuestroListener);

    Button btnHomicidio = (Button) findViewById(R.id.btnHomicidio);
    OnTouchListener btnHomicidioListener = new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP
                    && event.getEventTime() - event.getDownTime() >= 1000) {
                Toast.makeText(MapaActivity.this, "Homicidio", Toast.LENGTH_SHORT).show();
                Intent i = new Intent(MapaActivity.this, RegistrarIncidenteActivity.class);
                i.putExtra("ID", "" + 4);
                i.putExtra("latitude", "" + latitude);
                i.putExtra("longitude", "" + longitude);
                startActivity(i);
            }
            return false;
        }
    };
    btnHomicidio.setOnTouchListener(btnHomicidioListener);

    Button btnAccidente = (Button) findViewById(R.id.btnAccidente);
    OnTouchListener btnAccidenteListener = new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP
                    && event.getEventTime() - event.getDownTime() >= 1000) {
                Toast.makeText(MapaActivity.this, "Accidente", Toast.LENGTH_SHORT).show();
                Intent i = new Intent(MapaActivity.this, RegistrarIncidenteActivity.class);
                i.putExtra("ID", "" + 5);
                i.putExtra("latitude", "" + latitude);
                i.putExtra("longitude", "" + longitude);
                startActivity(i);
            }
            return false;
        }
    };
    btnAccidente.setOnTouchListener(btnAccidenteListener);

    Button btnViolacion = (Button) findViewById(R.id.btnViolacion);
    OnTouchListener btnViolacionListener = new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP
                    && event.getEventTime() - event.getDownTime() >= 1000) {
                Toast.makeText(MapaActivity.this, "Violacion", Toast.LENGTH_SHORT).show();
                Intent i = new Intent(MapaActivity.this, RegistrarIncidenteActivity.class);
                i.putExtra("ID", "" + 6);
                i.putExtra("latitude", "" + latitude);
                i.putExtra("longitude", "" + longitude);
                startActivity(i);
            }
            return false;
        }
    };
    btnViolacion.setOnTouchListener(btnViolacionListener);

    Button btnOtros = (Button) findViewById(R.id.btnOtros);
    OnTouchListener btnOtrosListener = new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP
                    && event.getEventTime() - event.getDownTime() >= 1000) {
                Toast.makeText(MapaActivity.this, "Otros", Toast.LENGTH_SHORT).show();
                Intent i = new Intent(MapaActivity.this, RegistrarIncidenteActivity.class);
                i.putExtra("ID", "" + 7);
                i.putExtra("latitude", "" + latitude);
                i.putExtra("longitude", "" + longitude);
                startActivity(i);
            }
            return false;
        }
    };
    btnOtros.setOnTouchListener(btnOtrosListener);

    Button btnRobo = (Button) findViewById(R.id.btnRobo);
    OnTouchListener btnRoboListener = new OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP
                    && event.getEventTime() - event.getDownTime() >= 1000) {
                Toast.makeText(MapaActivity.this, "Robo", Toast.LENGTH_SHORT).show();
                Intent i = new Intent(MapaActivity.this, RegistrarIncidenteActivity.class);
                i.putExtra("ID", "" + 1);
                i.putExtra("latitude", "" + latitude);
                i.putExtra("longitude", "" + longitude);
                startActivity(i);
            }
            return false;
        }
    };
    btnRobo.setOnTouchListener(btnRoboListener);

    // Getting Google Play availability status
    int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getBaseContext());

    // Showing status
    if (status != ConnectionResult.SUCCESS) { // Google Play Services are not available

        int requestCode = 10;
        Dialog dialog = GooglePlayServicesUtil.getErrorDialog(status, this, requestCode);
        dialog.show();

    } else { // Google Play Services are available

        // Getting reference to the SupportMapFragment of activity_main.xml
        SupportMapFragment fm = (SupportMapFragment) getSupportFragmentManager().findFragmentById(R.id.map);

        // Getting GoogleMap object from the fragment
        googleMap = fm.getMap();

        // Enabling MyLocation Layer of Google Map
        googleMap.setMyLocationEnabled(true);

        googleMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
            @Override
            public void onInfoWindowClick(Marker marker) {

                getDetalle(Integer.parseInt(marker.getSnippet()));
            }
        });

        getLocation();
    }

}

From source file:org.deviceconnect.android.deviceplugin.theta.fragment.ThetaVRModeFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    mStorage = new ThetaObjectStorage(getContext());
    setRetainInstance(true);/*from   w ww. j  av a 2  s .c  o  m*/
    ThetaDeviceApplication app = (ThetaDeviceApplication) getActivity().getApplication();
    mDataCache = app.getCache();
    View rootView = inflater.inflate(R.layout.theta_vr_mode, null);
    mRightLayout = (RelativeLayout) rootView.findViewById(R.id.right_ui);
    mSphereView = (SphericalImageView) rootView.findViewById(R.id.vr_view);

    SphericalViewApi api = app.getSphericalViewApi();
    mSphereView.setViewApi(api);

    mSphereView.setOnTouchListener(new View.OnTouchListener() {

        private boolean mIsEnabledLongTouch = true;

        @Override
        public boolean onTouch(final View view, final MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                mIsEnabledLongTouch = true;
                return true;
            }
            if (motionEvent.getPointerCount() == 1) {
                if (mIsEnabledLongTouch && motionEvent.getEventTime() - motionEvent.getDownTime() >= 300) {
                    mSphereView.resetCameraDirection();
                }
            } else {
                mIsEnabledLongTouch = false;
                mScaleDetector.onTouchEvent(motionEvent);
            }
            return true;
        }
    });
    init3DButtons(rootView);
    enableView();
    mScaleDetector = new ScaleGestureDetector(getActivity(),
            new ScaleGestureDetector.SimpleOnScaleGestureListener() {
                @Override
                public boolean onScale(final ScaleGestureDetector detector) {
                    mScaleFactor /= detector.getScaleFactor();
                    double scale = mScaleFactor;
                    if (scale > MAX_FOV) {
                        scale = MAX_FOV;
                        mScaleFactor = MAX_FOV;
                    }
                    if (scale < MIN_FOV) {
                        scale = MIN_FOV;
                        mScaleFactor = MIN_FOV;
                    }
                    mSphereView.setFOV(scale);

                    return true;
                }
            });
    return rootView;
}

From source file:org.deviceconnect.android.deviceplugin.theta.fragment.ThetaShootingFragment.java

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
        final Bundle savedInstanceState) {
    View rootView = inflater.inflate(R.layout.theta_shooting_mode, null);
    ThetaDeviceApplication app = (ThetaDeviceApplication) getActivity().getApplication();
    ThetaDeviceManager deviceMgr = app.getDeviceManager();
    deviceMgr.registerDeviceEventListener(this);
    mDevice = deviceMgr.getConnectedDevice();
    if (mDevice == null) {
        ThetaDialogFragment.showAlert(getActivity(), getString(R.string.theta_ssid_prefix),
                getString(R.string.theta_error_disconnect_dialog_message),
                new DialogInterface.OnClickListener() {
                    @Override//from   w ww  .j a  v  a 2s.c o m
                    public void onClick(DialogInterface dialogInterface, int i) {
                        getActivity().finish();
                    }
                });

        return rootView;
    }
    mShootingTime = (TextView) rootView.findViewById(R.id.shooting_time);
    mLiveView = (SphericalImageLiveView) rootView.findViewById(R.id.shooting_preview);
    mApi = app.getSphericalViewApi();
    mLiveView.setViewApi(mApi);
    mLiveView.setDeviceManager(deviceMgr);
    initShootingLayouts(rootView);
    mShootingMode = (Spinner) rootView.findViewById(R.id.theta_shooting_mode);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity(), R.layout.theta_shooting_mode_adapter,
            getResources().getStringArray(R.array.theta_shooting_mode));

    mShootingMode.setAdapter(adapter);
    setRetainInstance(true);
    if (mShootingTasker == null) {
        mShootingTasker = new DownloadThetaDataTask();
        ShootingModeGetTask shootingGetTask = new ShootingModeGetTask();
        mShootingTasker.execute(shootingGetTask);
    }
    mLiveView.setOnTouchListener(new View.OnTouchListener() {

        private boolean mIsEnabledLongTouch = true;

        @Override
        public boolean onTouch(final View view, final MotionEvent motionEvent) {
            if (motionEvent.getAction() == MotionEvent.ACTION_UP) {
                mIsEnabledLongTouch = true;
                return true;
            }
            if (motionEvent.getPointerCount() == 1) {
                if (mIsEnabledLongTouch && motionEvent.getEventTime() - motionEvent.getDownTime() >= 300) {
                    mLiveView.resetCameraDirection();
                }
            } else {
                mIsEnabledLongTouch = false;
                mScaleDetector.onTouchEvent(motionEvent);
            }
            return true;
        }
    });
    mScaleDetector = new ScaleGestureDetector(getActivity(),
            new ScaleGestureDetector.SimpleOnScaleGestureListener() {
                @Override
                public boolean onScale(final ScaleGestureDetector detector) {
                    mScaleFactor /= detector.getScaleFactor();
                    double scale = mScaleFactor;
                    if (scale > MAX_FOV) {
                        scale = MAX_FOV;
                        mScaleFactor = MAX_FOV;
                    }
                    if (scale < MIN_FOV) {
                        scale = MIN_FOV;
                        mScaleFactor = MIN_FOV;
                    }
                    mLiveView.setFOV(scale);

                    return true;
                }
            });
    rotateShootingButton(getActivity().getResources().getConfiguration());
    return rootView;
}

From source file:de.dmxcontrol.activity.ControlActivity.java

@Override
public boolean dispatchTouchEvent(MotionEvent event) {
    if (!isPointInsideView(event.getX(), event.getY(),
            fManager.findFragmentById(R.id.action_fragment).getView())) {
        if (event.getPointerCount() == 2 && oldState == ActionSelectorFragment.STATE_OPTIC_PANEL) {
            return super.dispatchTouchEvent(event);
        } else {//from www .j  a va  2 s .  c  om

            gestureDetector.onTouchEvent(event);
        }
        switch (oldState) {
        case ActionSelectorFragment.STATE_INTENSITY_PANEL:
        case ActionSelectorFragment.STATE_COLOR_PANEL:
        case ActionSelectorFragment.STATE_PANTILT_PANEL:
            if (!(event.getAction() == MotionEvent.ACTION_MOVE) || event.getEventTime()
                    - event.getDownTime() > this.getResources().getInteger(R.integer.touch_gesture_delay)) {
                return super.dispatchTouchEvent(event);
            }
            return false;
        default:
            return super.dispatchTouchEvent(event);
        }
    }
    return super.dispatchTouchEvent(event);
}

From source file:com.timemachine.controller.ControllerActivity.java

private void setupUI() {
    // Set layout listener
    View controllerView = findViewById(R.id.controllerView);
    ViewTreeObserver vto = controllerView.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
        @Override// ww  w  . j  a  v  a2 s .  co  m
        public void onGlobalLayout() {
            runOnUiThread(new Runnable() {
                public void run() {
                    locationSliderHeight = locationSlider.getHeight();
                    originLocationSliderContainerY = locationSliderContainer.getY();
                    originPlayPauseButtonY = playPause.getY();
                    minLocationSliderContainerY = originLocationSliderContainerY;
                    maxLocationSliderContainerY = originLocationSliderContainerY + locationSliderHeight;
                    midLocationSliderContainerY = (minLocationSliderContainerY + maxLocationSliderContainerY)
                            / 2;
                }
            });
            System.out.println("locationSliderHeight: " + locationSliderHeight);
            System.out.println("locationSliderContainerY: " + originLocationSliderContainerY);
            locationSlider.getViewTreeObserver().removeOnGlobalLayoutListener(this);
        }
    });

    // Connect to controller.html
    controllerURL = "http://" + ipText + ":8080/controller.html";
    locationSlider = (WebView) findViewById(R.id.webview);
    locationSliderContainer = (FrameLayout) findViewById(R.id.sliderContainer);
    locationSlider.setBackgroundColor(Color.TRANSPARENT);
    locationSlider.setLayerType(WebView.LAYER_TYPE_SOFTWARE, null);
    locationSlider.setWebViewClient(new WebViewClient() {
        public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
            System.out.println("onReceivedError");
            showConnectDialog("Error while connecting to controller. Connect again.");
        }

        @Override
        public void onLoadResource(WebView view, String url) {
            if (url.contains("thumbnail"))
                isMasterConnected = true;
        }

        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            isMasterConnectedTimerTask = null;
            isMasterConnectedTimerTask = new TimerTask() {
                @Override
                public void run() {
                    if (isMasterConnected == false)
                        showConnectDialog("Master is not loaded in the browser. Connect again.");
                }
            };
            isMasterConnectedTimer.schedule(isMasterConnectedTimerTask, 6000);
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            if (url.contains(controllerURL)) {
                drag.setVisibility(View.VISIBLE);
                playPause.setVisibility(View.VISIBLE);
                loadPreferences();
            }
            super.onPageFinished(view, url);
        }
    });
    try {
        locationSlider.loadUrl(controllerURL);
    } catch (Exception e) {
        e.printStackTrace();
    }

    // Set JavaScript Interface
    locationSlider.addJavascriptInterface(this, "androidObject");
    WebSettings webSettings = locationSlider.getSettings();
    webSettings.setJavaScriptEnabled(true);

    // Set the play-pause button
    playPause = (ImageButton) findViewById(R.id.playPauseButton);
    playPause.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            socket.emit("handlePlayPauseServer");
        }
    });
    socket.emit("setControllerPlayButton");

    // Set the drag button
    drag = (ImageButton) findViewById(R.id.drag);
    drag.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                dragYDiffBetweenFingerAndSliderTop = locationSliderContainer.getY() - event.getRawY();
                dragYDiffBetweenFingerAndPlayPauseTop = playPause.getY() - event.getRawY();
            }
            if (event.getAction() == MotionEvent.ACTION_MOVE) {
                // Move the slider based on current finger location
                float newSliderY = event.getRawY() + dragYDiffBetweenFingerAndSliderTop;
                float newPlayPauseY = event.getRawY() + dragYDiffBetweenFingerAndPlayPauseTop;
                if (newSliderY > minLocationSliderContainerY && newSliderY < maxLocationSliderContainerY) {
                    locationSliderContainer.setY(newSliderY);
                    playPause.setY(newPlayPauseY);
                }
            }
            if (event.getAction() == MotionEvent.ACTION_UP) {
                if (event.getEventTime() - event.getDownTime() <= tapTimeout) {
                    // Tap is detected, toggle the slider
                    System.out.println("onTap");
                    runOnUiThread(new Runnable() {
                        public void run() {
                            toggleSlider();
                        }
                    });
                } else {
                    // Not a tap gesture, slide up or down based on the slider's current position
                    if (locationSliderContainer.getY() > midLocationSliderContainerY)
                        slideDown();
                    else
                        slideUp();
                }
            }
            return true;
        }
    });

    // Set the Google map
    setUpMapIfNeeded();
}

From source file:am.widget.tabstrip.TabStripHelper.java

boolean onTouchEvent(MotionEvent event) {
    if (mClickable) {
        final float x = event.getX();
        final float y = event.getY();
        final int action = event.getAction();
        switch (action) {
        case MotionEvent.ACTION_DOWN:
            mClickPosition = PagerAdapter.POSITION_NONE;
            mDownX = x;/*  w  w w. jav a  2s.c  om*/
            mDownY = y;
            break;
        case MotionEvent.ACTION_UP:
            mClickPosition = PagerAdapter.POSITION_NONE;
            if (mPager != null && getPageCount() > 0) {
                if (mView instanceof TabStripView)
                    mClickPosition = ((TabStripView) mView).getClickedPosition(mDownX, mDownY, x, y);
                else if (mView instanceof TabStripViewGroup)
                    mClickPosition = ((TabStripViewGroup) mView).getClickedPosition(mDownX, mDownY, x, y);
            }
            break;
        case MotionEvent.ACTION_CANCEL:
            mClickPosition = PagerAdapter.POSITION_NONE;
            break;
        }
    }
    if (mDoubleClickable) {
        final float x = event.getX();
        final float y = event.getY();
        final int action = event.getAction();
        switch (action) {
        case MotionEvent.ACTION_DOWN:
            mFirstDownX = mSecondDownX;
            mFirstDownY = mSecondDownY;
            mSecondDownX = x;
            mSecondDownY = y;
            break;
        case MotionEvent.ACTION_UP:
            final long downTime = event.getDownTime();
            if (mLastUpTime != 0 && downTime - mLastUpTime < DOUBLE_TAP_TIMEOUT) {
                mDoubleClicked = true;
                if (mView instanceof TabStripView)
                    mFirstPosition = ((TabStripView) mView).getClickedPosition(mFirstDownX, mFirstDownY,
                            mFirstUpX, mFirstUpY);
                else if (mView instanceof TabStripViewGroup)
                    mFirstPosition = ((TabStripViewGroup) mView).getClickedPosition(mFirstDownX, mFirstDownY,
                            mFirstUpX, mFirstUpY);
                if (mView instanceof TabStripView)
                    mSecondPosition = ((TabStripView) mView).getClickedPosition(mSecondDownX, mSecondDownY, x,
                            y);
                else if (mView instanceof TabStripViewGroup)
                    mSecondPosition = ((TabStripViewGroup) mView).getClickedPosition(mSecondDownX, mSecondDownY,
                            x, y);
                mLastUpTime = 0;
            } else {
                mDoubleClicked = false;
                mFirstPosition = PagerAdapter.POSITION_NONE;
                mSecondPosition = PagerAdapter.POSITION_NONE;
                mFirstUpX = x;
                mFirstUpY = y;
                mLastUpTime = event.getEventTime();
            }
            break;
        case MotionEvent.ACTION_CANCEL:

            break;
        }
    }

    return false;
}

From source file:refresh.renyi.io.supperrefreshview.customview.VerticalViewPager.java

private void sendCancelEvent() {
    System.out.println("sendCancelEvent");
    MotionEvent last = mLastMoveEvent;
    MotionEvent e = MotionEvent.obtain(last.getDownTime(), last.getEventTime(), MotionEvent.ACTION_CANCEL,
            last.getX(), last.getY(), last.getMetaState());
    dispatchTouchEventSupper(e);/*from   www .j  ava 2 s  .c o m*/
}

From source file:refresh.renyi.io.supperrefreshview.customview.VerticalViewPager.java

private void sendDownEvent() {
    System.out.println("sendDownEvent");
    final MotionEvent last = mLastMoveEvent;
    if (last == null)
        return;//w  w w  .j  av  a 2  s .  c o m
    MotionEvent e = MotionEvent.obtain(last.getDownTime(), last.getEventTime(), MotionEvent.ACTION_DOWN,
            last.getX(), last.getY(), last.getMetaState());
    dispatchTouchEventSupper(e);
}

From source file:com.yek.keyboard.keyboards.views.AnyKeyboardView.java

@Override
public boolean onTouchEvent(@NonNull MotionEvent me) {
    if (getKeyboard() == null)//I mean, if there isn't any keyboard I'm handling, what's the point?
        return false;

    if (areTouchesDisabled(me)) {
        return super.onTouchEvent(me);
    }//  w  w w.j a  va 2 s  . co m

    final int action = MotionEventCompat.getActionMasked(me);

    // Gesture detector must be enabled only when mini-keyboard is not
    // on the screen.
    if (!mMiniKeyboardPopup.isShowing() && mGestureDetector != null && mGestureDetector.onTouchEvent(me)) {
        Logger.d(TAG, "Gesture detected!");
        mKeyPressTimingHandler.cancelAllMessages();
        dismissAllKeyPreviews();
        return true;
    }

    if (action == MotionEvent.ACTION_DOWN) {
        mFirstTouchPoint.x = (int) me.getX();
        mFirstTouchPoint.y = (int) me.getY();
        mIsFirstDownEventInsideSpaceBar = mSpaceBarKey != null
                && mSpaceBarKey.isInside(mFirstTouchPoint.x, mFirstTouchPoint.y);
    }
    // If the motion event is above the keyboard and it's a MOVE event
    // coming even before the first MOVE event into the extension area
    if (!mIsFirstDownEventInsideSpaceBar && me.getY() < mExtensionKeyboardYActivationPoint
            && !mMiniKeyboardPopup.isShowing() && !mExtensionVisible && action == MotionEvent.ACTION_MOVE) {
        if (mExtensionKeyboardAreaEntranceTime <= 0)
            mExtensionKeyboardAreaEntranceTime = SystemClock.uptimeMillis();

        if (SystemClock.uptimeMillis()
                - mExtensionKeyboardAreaEntranceTime > DELAY_BEFORE_POPPING_UP_EXTENSION_KBD) {
            KeyboardExtension extKbd = ((ExternalAnyKeyboard) getKeyboard()).getExtensionLayout();
            if (extKbd == null || extKbd.getKeyboardResId() == AddOn.INVALID_RES_ID) {
                Logger.i(TAG, "No extension keyboard");
                return super.onTouchEvent(me);
            } else {
                // telling the main keyboard that the last touch was
                // canceled
                MotionEvent cancel = MotionEvent.obtain(me.getDownTime(), me.getEventTime(),
                        MotionEvent.ACTION_CANCEL, me.getX(), me.getY(), 0);
                super.onTouchEvent(cancel);
                cancel.recycle();

                mExtensionVisible = true;
                dismissAllKeyPreviews();
                if (mExtensionKey == null) {
                    mExtensionKey = new AnyKey(new Keyboard.Row(getKeyboard()), getThemedKeyboardDimens());
                    mExtensionKey.edgeFlags = 0;
                    mExtensionKey.height = 1;
                    mExtensionKey.width = 1;
                    mExtensionKey.popupResId = extKbd.getKeyboardResId();
                    mExtensionKey.externalResourcePopupLayout = mExtensionKey.popupResId != 0;
                    mExtensionKey.x = getWidth() / 2;
                    mExtensionKey.y = mExtensionKeyboardPopupOffset;
                }
                // so the popup will be right above your finger.
                mExtensionKey.x = (int) me.getX();

                onLongPress(extKbd, mExtensionKey, AnyApplication.getConfig().isStickyExtensionKeyboard(),
                        getPointerTracker(me));
                // it is an extension..
                getMiniKeyboard().setPreviewEnabled(true);
                return true;
            }
        } else {
            return super.onTouchEvent(me);
        }
    } else if (mExtensionVisible && me.getY() > mExtensionKeyboardYDismissPoint) {
        // closing the popup
        dismissPopupKeyboard();
        return true;
    } else {
        return super.onTouchEvent(me);
    }
}