Example usage for android.view MotionEvent ACTION_DOWN

List of usage examples for android.view MotionEvent ACTION_DOWN

Introduction

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

Prototype

int ACTION_DOWN

To view the source code for android.view MotionEvent ACTION_DOWN.

Click Source Link

Document

Constant for #getActionMasked : A pressed gesture has started, the motion contains the initial starting location.

Usage

From source file:com.thousandthoughts.tutorials.SensorFusionActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);/*w  w  w .ja va2  s . c o  m*/
    layout = (RelativeLayout) findViewById(R.id.mainlayout);
    IP1 = "";
    IP2 = "";
    angle1 = 0.0f;
    angle2 = 0.0f;
    gyroOrientation[0] = 0.0f;
    gyroOrientation[1] = 0.0f;
    gyroOrientation[2] = 0.0f;

    // initialise gyroMatrix with identity matrix
    gyroMatrix[0] = 1.0f;
    gyroMatrix[1] = 0.0f;
    gyroMatrix[2] = 0.0f;
    gyroMatrix[3] = 0.0f;
    gyroMatrix[4] = 1.0f;
    gyroMatrix[5] = 0.0f;
    gyroMatrix[6] = 0.0f;
    gyroMatrix[7] = 0.0f;
    gyroMatrix[8] = 1.0f;

    // get sensorManager and initialise sensor listeners
    mSensorManager = (SensorManager) this.getSystemService(SENSOR_SERVICE);
    initListeners();

    // wait for one second until gyroscope and magnetometer/accelerometer
    // data is initialised then scedule the complementary filter task
    fuseTimer.scheduleAtFixedRate(new calculateFusedOrientationTask(), 1000, TIME_CONSTANT);

    // GUI stuff
    try {
        client1 = new MyCoapClient(this.IP1);
        client2 = new MyCoapClient(this.IP2);
    } catch (UnknownHostException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    json = new JSONObject();
    mHandler = new Handler();
    radioSelection = 0;
    d.setRoundingMode(RoundingMode.HALF_UP);
    d.setMaximumFractionDigits(3);
    d.setMinimumFractionDigits(3);

    /// Application layout here only

    RelativeLayout.LayoutParams left = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams right = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams up = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams down = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams button1 = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams button2 = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams text1 = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    RelativeLayout.LayoutParams text2 = new RelativeLayout.LayoutParams(
            android.view.ViewGroup.LayoutParams.WRAP_CONTENT, android.view.ViewGroup.LayoutParams.WRAP_CONTENT);
    ImageView img_left = new ImageView(this);
    ImageView img_right = new ImageView(this);
    ImageView img_up = new ImageView(this);
    ImageView img_down = new ImageView(this);
    ImageView img_button1 = new ImageView(this);
    ImageView img_button2 = new ImageView(this);
    final EditText edittext1 = new EditText(this);
    final EditText edittext2 = new EditText(this);
    img_left.setImageResource(R.drawable.left_button);
    img_right.setImageResource(R.drawable.right_button);
    img_up.setImageResource(R.drawable.up);
    img_down.setImageResource(R.drawable.down);
    img_button1.setImageResource(R.drawable.button);
    img_button2.setImageResource(R.drawable.button);

    left.setMargins(0, 66, 0, 0);
    right.setMargins(360, 66, 0, 0);
    up.setMargins(240, 90, 0, 0);
    down.setMargins(240, 240, 0, 0);
    button1.setMargins(440, 800, 0, 0);
    button2.setMargins(440, 900, 0, 0);
    text1.setMargins(5, 800, 0, 0);
    text2.setMargins(5, 900, 0, 0);

    layout.addView(img_left, left);
    layout.addView(img_right, right);
    layout.addView(img_up, up);
    layout.addView(img_down, down);
    layout.addView(img_button1, button1);
    layout.addView(edittext1, text1);
    layout.addView(img_button2, button2);
    layout.addView(edittext2, text2);

    img_left.getLayoutParams().height = 560;
    img_left.getLayoutParams().width = 280;
    img_right.getLayoutParams().height = 560;
    img_right.getLayoutParams().width = 280;
    img_up.getLayoutParams().height = 150;
    img_up.getLayoutParams().width = 150;
    img_down.getLayoutParams().height = 150;
    img_down.getLayoutParams().width = 150;
    img_button1.getLayoutParams().height = 100;
    img_button1.getLayoutParams().width = 200;
    edittext1.getLayoutParams().width = 400;
    edittext1.setText("84.248.76.84");
    edittext2.setText("84.248.76.84");
    img_button2.getLayoutParams().height = 100;
    img_button2.getLayoutParams().width = 200;
    edittext2.getLayoutParams().width = 400;

    /////////// Define and Remember Position for EACH PHYSICAL OBJECTS (LAPTOPS) /////////////////////
    img_button1.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            // TODO Auto-generated method stub
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // POSITION OF LAPTOP 1 IS REMEMBERED
                angle1 = fusedOrientation[0];
                IP1 = edittext1.getText().toString();
                try {
                    // CREATE CLIENT CONNECT TO FIRST LAPTOP
                    client1 = new MyCoapClient(IP1);
                } catch (UnknownHostException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                //view.setImageResource(R.drawable.left_button);
                break;
            }
            return true;
        }

    });

    img_button2.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View view, MotionEvent event) {
            // TODO Auto-generated method stub
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                // POSITION OF LAPTOP 2 IS REMEMBERED
                angle2 = fusedOrientation[0];
                IP2 = edittext2.getText().toString();
                try {
                    // CREATE CLIENT CONNECT TO SECOND LAPTOP
                    client2 = new MyCoapClient(IP2);
                } catch (UnknownHostException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                break;
            }
            return true;
        }

    });

    img_left.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            ImageView view = (ImageView) v;
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                view.setImageResource(R.drawable.left_button_press);

                ///////////////////// PERFORM CLICK ACTION BASED ON POSITION OF 2 PHYSICAL OBJECTS (LAPTOPs) HERE/////////////////////////

                // PHONE's ANGLE WITHIN FIRST LAPTOP//
                if (angle1 != 0.0f) {
                    if (angle1 * 180 / Math.PI - 40.0 < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0) {
                        client1.runClient("left pressed");
                    }
                }
                //PHONE's ANGLE WITHIN SECOND LAPTOP//
                if (angle2 != 0.0f) {
                    if (angle2 * 180 / Math.PI - 40.0 < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0) {
                        client2.runClient("left pressed");
                    }
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                view.setImageResource(R.drawable.left_button);
                // PHONE's ANGLE WITHIN FIRST LAPTOP//
                if (angle1 != 0.0f) {
                    if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) {
                        client1.runClient("left released");
                    }
                }
                //PHONE's ANGLE WITHIN SECOND LAPTOP//
                if (angle2 != 0.0f) {
                    if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) {
                        client2.runClient("left released");
                    }
                }
                break;
            }
            return true;
        }
    });

    img_right.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            ImageView view = (ImageView) v;
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                view.setImageResource(R.drawable.right_button_press);
                // PHONE's ANGLE WITHIN FIRST LAPTOP//
                if (angle1 != 0.0f) {
                    if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) {
                        client1.runClient("right pressed");
                    }
                }
                //PHONE's ANGLE WITHIN SECOND LAPTOP//
                if (angle2 != 0.0f) {
                    if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) {
                        client2.runClient("right pressed");
                    }
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                view.setImageResource(R.drawable.right_button);
                break;
            }
            return true;
        }
    });

    img_up.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            ImageView view = (ImageView) v;
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                view.setImageResource(R.drawable.up_press);
                // PHONE's ANGLE WITHIN FIRST LAPTOP//
                if (angle1 != 0.0f) {
                    if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) {
                        client1.runClient("up pressed");
                    }
                }
                //PHONE's ANGLE WITHIN SECOND LAPTOP//
                if (angle2 != 0.0f) {
                    if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) {
                        client2.runClient("up pressed");
                    }
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                view.setImageResource(R.drawable.up);
                break;
            }
            return true;
        }
    });

    img_down.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            ImageView view = (ImageView) v;
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
                view.setImageResource(R.drawable.down_press);
                // PHONE's ANGLE WITHIN FIRST LAPTOP//
                if (angle1 != 0.0f) {
                    if (angle1 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle1 * 180 / Math.PI + 40.0f) {
                        client1.runClient("down pressed");
                    }
                }
                //PHONE's ANGLE WITHIN SECOND LAPTOP//
                if (angle2 != 0.0f) {
                    if (angle2 * 180 / Math.PI - 40.0f < fusedOrientation[0] * 180 / Math.PI
                            && fusedOrientation[0] * 180 / Math.PI < angle2 * 180 / Math.PI + 40.0f) {
                        client2.runClient("down pressed");
                    }
                }
                break;
            case MotionEvent.ACTION_MOVE:
                break;
            case MotionEvent.ACTION_UP:
                view.setImageResource(R.drawable.down);
                break;
            }
            return true;
        }
    });
}

From source file:cn.chuangblog.simplebanner1.indicator.CirclePageIndicator.java

public boolean onTouchEvent(MotionEvent ev) {
    if (super.onTouchEvent(ev)) {
        return true;
    }/*from   www .  ja v  a2 s  .c o m*/
    if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
        return false;
    }

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mLastMotionX = ev.getX();
        break;

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, activePointerIndex);
        final float deltaX = x - mLastMotionX;

        if (!mIsDragging) {
            if (Math.abs(deltaX) > mTouchSlop) {
                mIsDragging = true;
            }
        }

        if (mIsDragging) {
            mLastMotionX = x;
            if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) {
                mViewPager.fakeDragBy(deltaX);
            }
        }

        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (!mIsDragging) {
            final int count = InfiniteViewPager.FakePositionHelper.getAdapterSize(mViewPager);
            final int width = getWidth();
            final float halfWidth = width / 2f;
            final float sixthWidth = width / 6f;

            if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) {
                if (action != MotionEvent.ACTION_CANCEL) {
                    mViewPager.setCurrentItem(mCurrentPage - 1);
                }
                return true;
            } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) {
                if (action != MotionEvent.ACTION_CANCEL) {
                    mViewPager.setCurrentItem(mCurrentPage + 1);
                }
                return true;
            }
        }

        mIsDragging = false;
        mActivePointerId = INVALID_POINTER;
        if (mViewPager.isFakeDragging())
            mViewPager.endFakeDrag();
        break;

    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastMotionX = MotionEventCompat.getX(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }

    case MotionEventCompat.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }

    return true;
}

From source file:com.adwhirl.AdWhirlLayout.java

@Override
public boolean onInterceptTouchEvent(MotionEvent event) {
    switch (event.getAction()) {
    // Sending on an ACTION_DOWN isn't 100% correct... user could have touched
    // down and dragged out. Unlikely though.
    case MotionEvent.ACTION_DOWN:
        Log.d(AdWhirlUtil.ADWHIRL, "Intercepted ACTION_DOWN event");
        if (activeRation != null) {
            countClick();// ww  w.  j av  a 2  s  . co m

            if (activeRation.type == 9) {
                if (custom != null && custom.link != null) {
                    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(custom.link));
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    try {
                        if (activityReference == null) {
                            return false;
                        }
                        Activity activity = activityReference.get();
                        if (activity == null) {
                            return false;
                        }
                        activity.startActivity(intent);
                    } catch (Exception e) {
                        Log.w(AdWhirlUtil.ADWHIRL, "Could not handle click to " + custom.link, e);
                    }
                } else {
                    Log.w(AdWhirlUtil.ADWHIRL, "In onInterceptTouchEvent(), but custom or custom.link is null");
                }
            }
            break;
        }
    }

    // Return false so subViews can process event normally.
    return false;
}

From source file:com.andlu6.teacup.viewpagerindicator.CirclePageIndicator.java

@SuppressLint("ClickableViewAccessibility")
public boolean onTouchEvent(android.view.MotionEvent ev) {
    if (super.onTouchEvent(ev)) {
        return true;
    }/*from   w  w  w.  jav a2 s. com*/
    if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
        return false;
    }

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mLastMotionX = ev.getX();
        break;

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, activePointerIndex);
        final float deltaX = x - mLastMotionX;

        if (!mIsDragging) {
            if (Math.abs(deltaX) > mTouchSlop) {
                mIsDragging = true;
            }
        }

        if (mIsDragging) {
            mLastMotionX = x;
            if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) {
                mViewPager.fakeDragBy(deltaX);
            }
        }

        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (!mIsDragging) {
            final int count = mViewPager.getAdapter().getCount();
            final int width = getWidth();
            final float halfWidth = width / 2f;
            final float sixthWidth = width / 6f;

            if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) {
                if (action != MotionEvent.ACTION_CANCEL) {
                    mViewPager.setCurrentItem(mCurrentPage - 1);
                }
                return true;
            } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) {
                if (action != MotionEvent.ACTION_CANCEL) {
                    mViewPager.setCurrentItem(mCurrentPage + 1);
                }
                return true;
            }
        }

        mIsDragging = false;
        mActivePointerId = INVALID_POINTER;
        if (mViewPager.isFakeDragging())
            mViewPager.endFakeDrag();
        break;

    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastMotionX = MotionEventCompat.getX(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }

    case MotionEventCompat.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }

    return true;
}

From source file:com.ibuildapp.romanblack.WebPlugin.WebPlugin.java

@Override
public void create() {
    try {/*w ww . j a v a  2  s .co  m*/

        setContentView(R.layout.romanblack_html_main);
        root = (FrameLayout) findViewById(R.id.romanblack_root_layout);
        webView = new ObservableWebView(this);
        webView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT,
                RelativeLayout.LayoutParams.MATCH_PARENT));
        root.addView(webView);

        webView.setHorizontalScrollBarEnabled(false);
        setTitle("HTML");

        Intent currentIntent = getIntent();
        Bundle store = currentIntent.getExtras();
        widget = (Widget) store.getSerializable("Widget");
        if (widget == null) {
            handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 100);
            return;
        }
        appName = widget.getAppName();

        if (widget.getPluginXmlData().length() == 0) {
            if (currentIntent.getStringExtra("WidgetFile").length() == 0) {
                handler.sendEmptyMessageDelayed(INITIALIZATION_FAILED, 100);
                return;
            }
        }

        if (widget.getTitle() != null && widget.getTitle().length() > 0) {
            setTopBarTitle(widget.getTitle());
        } else {
            setTopBarTitle(getResources().getString(R.string.romanblack_html_web));
        }

        currentUrl = (String) getSession();
        if (currentUrl == null) {
            currentUrl = "";
        }

        ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo ni = cm.getActiveNetworkInfo();
        if (ni != null && ni.isConnectedOrConnecting()) {
            isOnline = true;
        }

        // topbar initialization
        setTopBarLeftButtonText(getString(R.string.common_home_upper), true, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onBackPressed();
            }
        });

        if (isOnline) {
            webView.getSettings().setJavaScriptEnabled(true);
        }

        webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
        webView.getSettings().setGeolocationEnabled(true);
        webView.getSettings().setAllowFileAccess(true);
        webView.getSettings().setAppCacheEnabled(true);
        webView.getSettings().setCacheMode(WebSettings.LOAD_DEFAULT);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.getSettings().setDomStorageEnabled(true);
        webView.getSettings().setUseWideViewPort(false);
        webView.getSettings().setSavePassword(false);
        webView.clearHistory();
        webView.invalidate();

        if (Build.VERSION.SDK_INT >= 19) {
        }
        webView.getSettings().setUserAgentString(
                "Mozilla/5.0 (Linux; U; Android 2.2.1; en-us; Nexus One Build/FRG83) AppleWebKit/533.1 (KHTML, like Gecko) Version/4.0 Mobile Safari/533.1");

        webView.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                v.invalidate();

                switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN: {
                }
                    break;
                case MotionEvent.ACTION_UP: {
                    if (!v.hasFocus()) {
                        v.requestFocus();
                    }
                }
                    break;

                case MotionEvent.ACTION_MOVE: {
                }
                    break;

                }
                return false;
            }
        });

        webView.setBackgroundColor(Color.WHITE);
        try {
            if (widget.getBackgroundColor() != Color.TRANSPARENT) {
                webView.setBackgroundColor(widget.getBackgroundColor());
            }
        } catch (IllegalArgumentException e) {
        }

        webView.setDownloadListener(new DownloadListener() {
            @Override
            public void onDownloadStart(String url, String userAgent, String contentDisposition,
                    String mimetype, long contentLength) {
                Intent intent = new Intent(Intent.ACTION_VIEW);
                intent.setData(Uri.parse(url));
                startActivity(intent);
            }
        });

        webView.setWebChromeClient(new WebChromeClient() {

            FrameLayout.LayoutParams LayoutParameters = new FrameLayout.LayoutParams(
                    FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT);

            @Override
            public void onGeolocationPermissionsShowPrompt(final String origin,
                    final GeolocationPermissions.Callback callback) {
                AlertDialog.Builder builder = new AlertDialog.Builder(WebPlugin.this);
                builder.setTitle(R.string.location_dialog_title);
                builder.setMessage(R.string.location_dialog_description);
                builder.setCancelable(true);

                builder.setPositiveButton(R.string.location_dialog_allow,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                callback.invoke(origin, true, false);
                            }
                        });

                builder.setNegativeButton(R.string.location_dialog_not_allow,
                        new DialogInterface.OnClickListener() {
                            public void onClick(DialogInterface dialog, int id) {
                                callback.invoke(origin, false, false);
                            }
                        });

                AlertDialog alert = builder.create();
                alert.show();
            }

            @Override
            public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback) {
                if (customView != null) {
                    customViewCallback.onCustomViewHidden();
                    return;
                }

                view.setBackgroundColor(Color.BLACK);
                view.setLayoutParams(LayoutParameters);
                root.addView(view);
                customView = view;
                customViewCallback = callback;
                webView.setVisibility(View.GONE);
            }

            @Override
            public void onHideCustomView() {
                if (customView == null) {
                    return;
                } else {
                    closeFullScreenVideo();
                }
            }

            public void openFileChooser(ValueCallback<Uri> uploadMsg) {

                mUploadMessage = uploadMsg;
                Intent i = new Intent(Intent.ACTION_GET_CONTENT);//Intent.ACTION_GET_CONTENT);
                i.addCategory(Intent.CATEGORY_OPENABLE);
                i.setType("image/*");
                isMedia = true;
                startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);

            }

            // For Android 3.0+
            public void openFileChooser(ValueCallback uploadMsg, String acceptType) {
                mUploadMessage = uploadMsg;
                Intent i = new Intent(Intent.ACTION_GET_CONTENT);
                i.addCategory(Intent.CATEGORY_OPENABLE);
                i.setType("*/*");
                startActivityForResult(Intent.createChooser(i, "File Browser"), FILECHOOSER_RESULTCODE);
            }

            //For Android 4.1
            public void openFileChooser(ValueCallback<Uri> uploadMsg, String acceptType, String capture) {
                mUploadMessage = uploadMsg;
                Intent i = new Intent(Intent.ACTION_GET_CONTENT);
                i.addCategory(Intent.CATEGORY_OPENABLE);
                isMedia = true;
                i.setType("image/*");
                startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);

            }

            @Override
            public boolean onShowFileChooser(WebView webView, ValueCallback<Uri[]> filePathCallback,
                    FileChooserParams fileChooserParams) {
                isV21 = true;
                mUploadMessageV21 = filePathCallback;
                Intent i = new Intent(Intent.ACTION_GET_CONTENT);
                i.addCategory(Intent.CATEGORY_OPENABLE);
                i.setType("image/*");
                startActivityForResult(Intent.createChooser(i, "File Chooser"), FILECHOOSER_RESULTCODE);
                return true;
            }

            @Override
            public void onReceivedTouchIconUrl(WebView view, String url, boolean precomposed) {
                super.onReceivedTouchIconUrl(view, url, precomposed);
            }
        });

        webView.setWebViewClient(new WebViewClient() {
            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                super.onPageStarted(view, url, favicon);

                if (state == states.EMPTY) {
                    currentUrl = url;
                    setSession(currentUrl);
                    state = states.LOAD_START;
                    handler.sendEmptyMessage(SHOW_PROGRESS);
                }
            }

            @Override
            public void onLoadResource(WebView view, String url) {

                if (!alreadyLoaded
                        && (url.startsWith("http://www.youtube.com/get_video_info?")
                                || url.startsWith("https://www.youtube.com/get_video_info?"))
                        && Build.VERSION.SDK_INT < 11) {
                    try {
                        String path = url.contains("https://www.youtube.com/get_video_info?")
                                ? url.replace("https://www.youtube.com/get_video_info?", "")
                                : url.replace("http://www.youtube.com/get_video_info?", "");

                        String[] parqamValuePairs = path.split("&");

                        String videoId = null;

                        for (String pair : parqamValuePairs) {
                            if (pair.startsWith("video_id")) {
                                videoId = pair.split("=")[1];
                                break;
                            }
                        }

                        if (videoId != null) {
                            startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com"))
                                    .setData(Uri.parse("http://www.youtube.com/watch?v=" + videoId)));
                            needRefresh = true;
                            alreadyLoaded = !alreadyLoaded;

                            return;
                        }
                    } catch (Exception ex) {
                    }
                } else {
                    super.onLoadResource(view, url);
                }
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                if (hideProgress) {
                    if (TextUtils.isEmpty(WebPlugin.this.url)) {
                        state = states.LOAD_COMPLETE;
                        handler.sendEmptyMessage(HIDE_PROGRESS);
                        super.onPageFinished(view, url);
                    } else {
                        view.loadUrl("javascript:(function(){" + "l=document.getElementById('link');"
                                + "e=document.createEvent('HTMLEvents');" + "e.initEvent('click',true,true);"
                                + "l.dispatchEvent(e);" + "})()");
                        hideProgress = false;
                    }
                } else {
                    state = states.LOAD_COMPLETE;
                    handler.sendEmptyMessage(HIDE_PROGRESS);
                    super.onPageFinished(view, url);
                }
            }

            @Override
            public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) {
                if (errorCode == WebViewClient.ERROR_BAD_URL) {
                    startActivityForResult(new Intent(Intent.ACTION_VIEW, Uri.parse(url)),
                            DOWNLOAD_REQUEST_CODE);
                }
            }

            @Override
            public void onReceivedSslError(WebView view, final SslErrorHandler handler, SslError error) {
                final AlertDialog.Builder builder = new AlertDialog.Builder(WebPlugin.this);
                builder.setMessage(R.string.notification_error_ssl_cert_invalid);
                builder.setPositiveButton(WebPlugin.this.getResources().getString(R.string.wp_continue),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                handler.proceed();
                            }
                        });
                builder.setNegativeButton(WebPlugin.this.getResources().getString(R.string.wp_cancel),
                        new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {
                                handler.cancel();
                            }
                        });
                final AlertDialog dialog = builder.create();
                dialog.show();
            }

            @Override
            public void onFormResubmission(WebView view, Message dontResend, Message resend) {
                super.onFormResubmission(view, dontResend, resend);
            }

            @Override
            public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
                return super.shouldInterceptRequest(view, request);
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                try {

                    if (url.contains("youtube.com/watch")) {
                        if (Build.VERSION.SDK_INT < 11) {
                            try {
                                startActivity(
                                        new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com"))
                                                .setData(Uri.parse(url)));
                                return true;
                            } catch (Exception ex) {
                                return false;
                            }
                        } else {
                            return false;
                        }
                    } else if (url.contains("paypal.com")) {
                        if (url.contains("&bn=ibuildapp_SP")) {
                            return false;
                        } else {
                            url = url + "&bn=ibuildapp_SP";

                            webView.loadUrl(url);

                            return true;
                        }
                    } else if (url.contains("sms:")) {
                        try {
                            Intent smsIntent = new Intent(Intent.ACTION_VIEW);
                            smsIntent.setData(Uri.parse(url));
                            startActivity(smsIntent);
                            return true;
                        } catch (Exception ex) {
                            Log.e("", ex.getMessage());
                            return false;
                        }
                    } else if (url.contains("tel:")) {
                        Intent callIntent = new Intent(Intent.ACTION_CALL);
                        callIntent.setData(Uri.parse(url));
                        startActivity(callIntent);
                        return true;
                    } else if (url.contains("mailto:")) {
                        MailTo mailTo = MailTo.parse(url);

                        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
                        emailIntent.setType("plain/text");
                        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
                                new String[] { mailTo.getTo() });

                        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, mailTo.getSubject());
                        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, mailTo.getBody());
                        WebPlugin.this.startActivity(Intent.createChooser(emailIntent,
                                getString(R.string.romanblack_html_send_email)));
                        return true;
                    } else if (url.contains("rtsp:")) {
                        Uri address = Uri.parse(url);
                        Intent intent = new Intent(Intent.ACTION_VIEW, address);

                        final PackageManager pm = getPackageManager();
                        final List<ResolveInfo> matches = pm.queryIntentActivities(intent, 0);
                        if (matches.size() > 0) {
                            startActivity(intent);
                        } else {
                            Toast.makeText(WebPlugin.this, getString(R.string.romanblack_html_no_video_player),
                                    Toast.LENGTH_SHORT).show();
                        }

                        return true;
                    } else if (url.startsWith("intent:") || url.startsWith("market:")
                            || url.startsWith("col-g2m-2:")) {
                        Intent it = new Intent();
                        it.setData(Uri.parse(url));
                        startActivity(it);

                        return true;
                    } else if (url.contains("//play.google.com/")) {
                        startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(url)));
                        return true;
                    } else {
                        if (url.contains("ibuildapp.com-1915109")) {
                            String param = Uri.parse(url).getQueryParameter("widget");
                            finish();
                            if (param != null && param.equals("1001"))
                                com.appbuilder.sdk.android.Statics.launchMain();
                            else if (param != null && !"".equals(param)) {
                                View.OnClickListener widget = Statics.linkWidgets.get(Integer.valueOf(param));
                                if (widget != null)
                                    widget.onClick(view);
                            }
                            return false;
                        }

                        currentUrl = url;
                        setSession(currentUrl);
                        if (!isOnline) {
                            handler.sendEmptyMessage(HIDE_PROGRESS);
                            handler.sendEmptyMessage(STOP_LOADING);
                        } else {
                            String pageType = "application/html";
                            if (!url.contains("vk.com")) {
                                getPageType(url);
                            }
                            if (pageType.contains("application") && !pageType.contains("html")
                                    && !pageType.contains("xml")) {
                                startActivityForResult(new Intent(Intent.ACTION_VIEW, Uri.parse(url)),
                                        DOWNLOAD_REQUEST_CODE);
                                return super.shouldOverrideUrlLoading(view, url);
                            } else {
                                view.getSettings().setLoadWithOverviewMode(true);
                                view.getSettings().setUseWideViewPort(true);
                                view.setBackgroundColor(Color.WHITE);
                            }
                        }
                        return false;
                    }

                } catch (Exception ex) { // Error Logging
                    return false;
                }
            }
        });

        handler.sendEmptyMessage(SHOW_PROGRESS);

        new Thread() {
            @Override
            public void run() {

                EntityParser parser;
                if (widget.getPluginXmlData() != null) {
                    if (widget.getPluginXmlData().length() > 0) {
                        parser = new EntityParser(widget.getPluginXmlData());
                    } else {
                        String xmlData = readXmlFromFile(getIntent().getStringExtra("WidgetFile"));
                        parser = new EntityParser(xmlData);
                    }
                } else {
                    String xmlData = readXmlFromFile(getIntent().getStringExtra("WidgetFile"));
                    parser = new EntityParser(xmlData);
                }

                parser.parse();

                url = parser.getUrl();
                html = parser.getHtml();

                if (url.length() > 0 && !isOnline) {
                    handler.sendEmptyMessage(NEED_INTERNET_CONNECTION);
                } else {
                    if (isOnline) {
                    } else {
                        if (html.length() == 0) {
                        }
                    }
                    if (html.length() > 0 || url.length() > 0) {
                        handler.sendEmptyMessageDelayed(SHOW_HTML, 700);
                    } else {
                        handler.sendEmptyMessage(HIDE_PROGRESS);
                        handler.sendEmptyMessage(INITIALIZATION_FAILED);
                    }
                }
            }
        }.start();

    } catch (Exception ex) {
    }
}

From source file:com.aibinong.tantan.ui.widget.CircleNoPageIndicator.java

public boolean onTouchEvent(android.view.MotionEvent ev) {
    if (super.onTouchEvent(ev)) {
        return true;
    }//from   w w  w.  j a v  a  2 s .c  o m
    //        if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
    //            return false;
    //        }

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mLastMotionX = ev.getX();
        break;

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, activePointerIndex);
        final float deltaX = x - mLastMotionX;

        if (!mIsDragging) {
            if (Math.abs(deltaX) > mTouchSlop) {
                mIsDragging = true;
            }
        }

        if (mIsDragging) {
            mLastMotionX = x;
            //                    if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) {
            //                        mViewPager.fakeDragBy(deltaX);
            //                    }
        }

        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (!mIsDragging) {
            final int count = mRealCountGetter.getRealCount();
            final int width = getWidth();
            final float halfWidth = width / 2f;
            final float sixthWidth = width / 6f;

            if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) {
                if (action != MotionEvent.ACTION_CANCEL) {
                    //                            mViewPager.setCurrentItem(mCurrentPage - 1);
                }
                return true;
            } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) {
                if (action != MotionEvent.ACTION_CANCEL) {
                    //                            mViewPager.setCurrentItem(mCurrentPage + 1);
                }
                return true;
            }
        }

        mIsDragging = false;
        mActivePointerId = INVALID_POINTER;
        //                if (mViewPager.isFakeDragging()) mViewPager.endFakeDrag();
        break;

    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastMotionX = MotionEventCompat.getX(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }

    case MotionEventCompat.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }

    return true;
}

From source file:com.danielme.android.webviewdemo.WebViewDemoActivity.java

@SuppressLint({ "SetJavaScriptEnabled", "NewApi" })
@Override//w  w w  . j  av a 2s. c  o  m
public void onCreate(Bundle savedInstanceState) {
    setTitle("?");
    AndroidUtil.removeStrict();
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    historyStack = new LinkedList<Link>();
    webview = (WebView) findViewById(R.id.webkit);
    faviconImageView = (ImageView) findViewById(R.id.favicon);

    urlEditText = (EditText) findViewById(R.id.url);
    progressBar = (ProgressBar) findViewById(R.id.progressbar);
    stopButton = ((Button) findViewById(R.id.stopButton));
    //favicon, deprecated since Android 4.3 but it's still necesary O_O ?
    WebIconDatabase.getInstance().open(getDir("icons", MODE_PRIVATE).getPath());

    freeQuotaSwitch = (Switch) findViewById(R.id.freeQuotaSwitch);

    leftQuotaText = (TextView) findViewById(R.id.leftQuota);

    SharedPreferences settings = getSharedPreferences("setting", 0);

    userid = settings.getString("userid", "123");
    tenantid = Integer.parseInt(settings.getString("tenantid", "3"));

    // check balance
    long balance = updateLeftQuota();

    freeQuotaSwitch.setChecked(balance > 0);
    tmMgr = new TMManager();

    // javascript and zoom
    webview.getSettings().setJavaScriptEnabled(true);
    webview.getSettings().setBuiltInZoomControls(true);

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.FROYO) {
        webview.getSettings().setPluginState(PluginState.ON);
    } else {
        //IMPORTANT!! this method is no longer available since Android 4.3
        //so the code doesn't compile anymore
        //webview.getSettings().setPluginsEnabled(true);
    }

    // downloads
    // webview.setDownloadListener(new CustomDownloadListener());

    webview.setWebViewClient(new CustomWebViewClient());

    webview.setWebChromeClient(new WebChromeClient() {
        @Override
        public void onProgressChanged(WebView view, int progress) {
            progressBar.setProgress(0);
            FrameLayout progressBarLayout = (FrameLayout) findViewById(R.id.progressBarLayout);
            progressBarLayout.setVisibility(View.VISIBLE);
            WebViewDemoActivity.this.setProgress(progress * 1000);

            TextView progressStatus = (TextView) findViewById(R.id.progressStatus);
            progressStatus.setText(progress + " %");
            progressBar.incrementProgressBy(progress);

            if (progress == 100) {
                progressBarLayout.setVisibility(View.GONE);
            }
        }

        @Override
        public void onReceivedTitle(WebView view, String title) {
            WebViewDemoActivity.this.setTitle(
                    getString(R.string.app_name) + " - " + WebViewDemoActivity.this.webview.getTitle());
            for (Link link : historyStack) {
                if (link.getUrl().equals(WebViewDemoActivity.this.webview.getUrl())) {
                    link.setTitle(title);
                }
            }
        }

        @Override
        public void onReceivedIcon(WebView view, Bitmap icon) {
            faviconImageView.setImageBitmap(icon);
            view.getUrl();
            boolean b = false;
            ListIterator<Link> listIterator = historyStack.listIterator();
            while (!b && listIterator.hasNext()) {
                Link link = listIterator.next();
                if (link.getUrl().equals(view.getUrl())) {
                    link.setFavicon(icon);
                    b = true;
                }
            }
        }

    });

    //http://stackoverflow.com/questions/2083909/android-webview-refusing-user-input
    webview.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_UP:
                if (!v.hasFocus()) {
                    v.requestFocus();
                }
                break;
            }
            return false;
        }

    });

}

From source file:android.hqs.view.pager.indicator.CirclePageIndicator.java

public boolean onTouchEvent(android.view.MotionEvent ev) {
    if (super.onTouchEvent(ev)) {
        return true;
    }// w  w w. j a  va  2s. c  o  m
    if ((mViewPager == null) || (mViewPager.getAdapter().getCount() == 0)) {
        return false;
    }

    final int action = ev.getAction() & MotionEventCompat.ACTION_MASK;
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        mActivePointerId = MotionEventCompat.getPointerId(ev, 0);
        mLastMotionX = ev.getX();
        break;

    case MotionEvent.ACTION_MOVE: {
        final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId);
        final float x = MotionEventCompat.getX(ev, activePointerIndex);
        final float deltaX = x - mLastMotionX;

        if (!mIsDragging) {
            if (Math.abs(deltaX) > mTouchSlop) {
                mIsDragging = true;
            }
        }

        if (mIsDragging) {
            mLastMotionX = x;
            if (mViewPager.isFakeDragging() || mViewPager.beginFakeDrag()) {
                mViewPager.fakeDragBy(deltaX);
            }
        }

        break;
    }

    case MotionEvent.ACTION_CANCEL:
    case MotionEvent.ACTION_UP:
        if (!mIsDragging) {
            final int count = mViewPager.getAdapter().getCount();
            final int width = getWidth();
            final float halfWidth = width / 2f;
            final float sixthWidth = width / 6f;

            if ((mCurrentPage > 0) && (ev.getX() < halfWidth - sixthWidth)) {
                if (action != MotionEvent.ACTION_CANCEL) {
                    mViewPager.setCurrentItem(mCurrentPage - 1);
                }
                return true;
            } else if ((mCurrentPage < count - 1) && (ev.getX() > halfWidth + sixthWidth)) {
                if (action != MotionEvent.ACTION_CANCEL) {
                    mViewPager.setCurrentItem(mCurrentPage + 1);
                }
                return true;
            }
        }

        mIsDragging = false;
        mActivePointerId = INVALID_POINTER;
        if (mViewPager.isFakeDragging())
            mViewPager.endFakeDrag();
        break;

    case MotionEventCompat.ACTION_POINTER_DOWN: {
        final int index = MotionEventCompat.getActionIndex(ev);
        mLastMotionX = MotionEventCompat.getX(ev, index);
        mActivePointerId = MotionEventCompat.getPointerId(ev, index);
        break;
    }

    case MotionEventCompat.ACTION_POINTER_UP:
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);
        final int pointerId = MotionEventCompat.getPointerId(ev, pointerIndex);
        if (pointerId == mActivePointerId) {
            final int newPointerIndex = pointerIndex == 0 ? 1 : 0;
            mActivePointerId = MotionEventCompat.getPointerId(ev, newPointerIndex);
        }
        mLastMotionX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId));
        break;
    }

    return true;
}

From source file:com.example.aaron.test.MyGLSurfaceView.java

@Override
public boolean onTouchEvent(MotionEvent e) {

    float x = e.getX();
    float y = e.getY();

    int cc = 0;//from   w w  w  .j a  v a 2 s.co m

    /*
            float xGL=(width1/2-x)/(float)(height1/1.85);
            float yGL=( height1/2+30-y)/(float)(height1/1.85);
    */

    float xGL = (width1 / 2 - x) / (float) (height1 / 2);
    float yGL = (height1 / 2 - y) / (float) (height1 / 2);

    workspace = -(width1 - 115) / (height1 * 2) + .15f - mRenderer.slider;

    mRenderer.tempFun(xGL, yGL);

    switch (e.getActionMasked()) {
    case MotionEvent.ACTION_DOWN:
        mRenderer.tToggle = 1;

        for (int i = 0; i < maxBots; i++) {
            if (tList[i].getOn() == 1) {
                cc = cc + 1;
                if (Math.abs(tList[i].getX() * getScale() + mRenderer.dragX * mRenderer.scale - xGL) < .1f
                        && Math.abs(
                                tList[i].getY() * getScale() + mRenderer.dragY * mRenderer.scale - yGL) < .1f) {
                    if (state[i] == 0) {
                        state[i] = 1;
                    } else {
                        state[i] = 0;
                    }
                    v.vibrate(50);
                }
            }
        }

        if (antispam > 1) {

            if (xGL < .85 && xGL > .65 && yGL > -.95 && yGL < -.75) {
                mRenderer.scale = mRenderer.scale + .5f;
                mRenderer.textList.get(1).setText("Scale: " + truncateDecimal(mRenderer.scale, 1) + "x");
                mRenderer.textList.get(2).setText(truncateDecimal(2 / mRenderer.scale, 2) + " ft");
                v.vibrate(75);
                break;
            }
            if (xGL < 1.2f && xGL > .95f && yGL > -.85f && yGL < -.75 && mRenderer.scale > .5f) {
                mRenderer.scale = mRenderer.scale - .5f;
                mRenderer.textList.get(1).setText("Scale: " + truncateDecimal(mRenderer.scale, 1) + "x");
                mRenderer.textList.get(2).setText(truncateDecimal(2 / mRenderer.scale, 2) + " ft");
                v.vibrate(75);
                break;
            }

            if (mRenderer.commit.blocked == false && xGL < mRenderer.commit.left - mRenderer.slider
                    && xGL > mRenderer.commit.right - mRenderer.slider && yGL > mRenderer.commit.down
                    && yGL < mRenderer.commit.up)
                if (mRenderer.commit.active == true) {
                    mRenderer.commit.active = false;
                    newAction = true;
                    v.vibrate(50);
                } else {
                    mRenderer.commit.active = true;
                    if (mRenderer.customFormation.active) {
                        mRenderer.justifyRelativePositions();
                        mRenderer.resetScaleAndRotation();
                        mRenderer.formation.send = true;
                    }
                    newAction = true;
                    v.vibrate(50);
                }

            //Turn on voronoi toggle
            if (buttonPush(xGL, yGL, mRenderer.vorToggle))
                if (mRenderer.getvToggle() == 1) {
                    mRenderer.setvToggle(0);
                    v.vibrate(500);
                } else {
                    mRenderer.setvToggle(1);
                    v.vibrate(500);
                }
            vFlag = mRenderer.getvToggle();

            //Turn on Free Draw Toggle
            if (buttonPush(xGL, yGL, mRenderer.freeDrawToggle))
                if (mRenderer.getfToggle() == 1) {
                    mRenderer.setfToggle(0);
                    fFlag = mRenderer.getfToggle();
                } else {
                    mRenderer.setfToggle(1);
                    mRenderer.eraseFreeLine();
                    freeDrawCount = 0;
                    previousy = 0;
                    previousx = 0;
                    connectable = 0;
                    firstPointFreeDraw[0] = -1000;
                    firstPointFreeDraw[1] = -1000;
                    fFlag = mRenderer.getfToggle();
                }

            //Toggable swarm for Path Follower
            /*if (mRenderer.getfToggle()==1 && xGL<mRenderer.swarmToggle.left- mRenderer.slider&& xGL>mRenderer.swarmToggle.right-mRenderer.slider&& yGL > mRenderer.swarmToggle.down && yGL < mRenderer.swarmToggle.up)
                if (mRenderer.swarmToggle.active == true) {
                    mRenderer.swarmToggle.active =  false;
                    v.vibrate(50);
                } else {
                    mRenderer.swarmToggle.active =  true;
                    v.vibrate(50);
                }
            */ //THIS FEATURE CAN BE ADDED LATER IF WE WANT

            //Turn on Way Point Toggle
            if (buttonPush(xGL, yGL, mRenderer.wayPointToggle))
                if (mRenderer.getpToggle() == 1) {
                    mRenderer.setpToggle(0);
                    pFlag2 = 0;
                    mRenderer.setpToggle2(pFlag2);
                    mRenderer.tToggle = 1;
                    pX = 0;
                    pY = 0;
                } else {
                    mRenderer.tToggle = 0;
                    mRenderer.setpToggle(1);
                    mRenderer.voronoiDeploymentToggle.active = false;
                    pX = 0;
                    pY = 0;
                }
            pFlag = mRenderer.getpToggle();

            //Turn on AndroneToggle
            if (buttonPush(xGL, yGL, mRenderer.ardronePrefToggle))
                if (mRenderer.getAPToggle() == 1) {
                    mRenderer.setAPToggle(0);
                    mRenderer.SINFO_FLAG = true;
                } else {
                    mRenderer.setAPToggle(1);
                    mRenderer.SINFO_FLAG = false;
                }

            if (buttonPush(xGL, yGL, mRenderer.gaussianTrackToggle)) {
                if (mRenderer.gaussianTrackToggle.active == true) {
                    mRenderer.gaussianTrackToggle.active = false;

                } else {
                    mRenderer.gaussianTrackToggle.active = true;

                }
                v.vibrate(50);
            }

            if (buttonPush(xGL, yGL, mRenderer.formation)) {
                if (mRenderer.formation.active == true) {
                    mRenderer.formation.active = false;
                    mRenderer.formation.send = false;
                } else {
                    mRenderer.formation.active = true;
                    mRenderer.formation.send = true;
                    mRenderer.refreshFormationtext();
                }
            }

            if (buttonPush(xGL, yGL, mRenderer.formationToggleTransform)) {
                if (mRenderer.formationToggleTransform.active == true) {
                    mRenderer.formationToggleTransform.active = false;
                } else {
                    mRenderer.formationToggleTransform.active = true;
                    mRenderer.customFormation.active = false;
                    mRenderer.commit.blocked = true;
                    mRenderer.refreshFormationtext();
                }
            }

            if (buttonPush(xGL, yGL, mRenderer.customFormation)) {
                if (mRenderer.customFormation.active == true) {
                    mRenderer.customFormation.active = false;
                    mRenderer.commit.blocked = true;
                } else {
                    mRenderer.customFormation.active = true;
                    mRenderer.resetFormation();
                    mRenderer.refreshCenter();
                    mRenderer.formationToggleTransform.active = false;
                    mRenderer.commit.blocked = false;
                    mRenderer.commit.active = false;
                    mRenderer.refreshFormationtext();
                }
            }

            if (buttonPush(xGL, yGL, mRenderer.ardroneAddToggle)) {
                dummyFlag = 1;
            }

            if (buttonPush(xGL, yGL, mRenderer.addToggle)) {
                mRenderer.formation.val1 = mRenderer.formation.val1 + 1;
                mRenderer.refreshFormationtext();
                mRenderer.formation.send = true;
            }

            if (buttonPush(xGL, yGL, mRenderer.subtractToggle)) {
                mRenderer.formation.val1 = mRenderer.formation.val1 - 1;
                mRenderer.refreshFormationtext();
                mRenderer.formation.send = true;
            }

            if (buttonPush(xGL, yGL, mRenderer.freeBoundarytoggle)) {
                if (mRenderer.freeBoundarytoggle.active == true) {
                    mRenderer.freeBoundarytoggle.active = false;
                    freeBoundaryFlag = true;
                    closedBoundaryFlag = false;
                } else {
                    mRenderer.freeBoundarytoggle.active = true;
                    closedBoundaryFlag = true;
                    freeBoundaryFlag = false;
                }
            }

            if (buttonPush(xGL, yGL, mRenderer.obstacleLineToggle)) {
                System.out.println("obstacle Line Pushed");

                addObstacleFlag = true;
                mRenderer.makeObstacle();
                mRenderer.fToggle = 0;
                fFlag = mRenderer.fToggle;
            }

            //IF GAUSS TOGGLE SELECTED
            if (buttonPush(xGL, yGL, mRenderer.gaussToggle))
                if (mRenderer.getgToggle() == 1) {
                    mRenderer.setgToggle(0);
                    gFlag2 = 0;
                    mRenderer.setgToggle2(gFlag2);
                } else {
                    mRenderer.setgToggle(1);
                }
            gFlag = mRenderer.getgToggle();

            //IF GAUSSPATH TOGGLE SELECTED
            /*if (xGL<mRenderer.temptoggle.left- mRenderer.slider&& xGL>mRenderer.temptoggle.right-mRenderer.slider&& yGL > mRenderer.temptoggle.down && yGL < mRenderer.temptoggle.up)
                if (mRenderer.getgpToggle() == 1) {
                    mRenderer.setgpToggle(0);
                    mRenderer.eraseGaussLine();
                    v.vibrate(50);
                } else {
                    mRenderer.setgpToggle(1);
                    mRenderer.makeGaussPoints();
                    v.vibrate(50);
                }*/
            gpFlag = mRenderer.getgpToggle();

            //Toggle for voronoi deployment
            if (buttonPush(xGL, yGL, mRenderer.voronoiDeploymentToggle))
                if (mRenderer.voronoiDeploymentToggle.active == true) {
                    mRenderer.voronoiDeploymentToggle.active = false;
                    newAction = true;
                } else {
                    newAction = true;
                    mRenderer.voronoiDeploymentToggle.active = true;
                    mRenderer.setpToggle(0);
                    mRenderer.setpToggle2(0);
                }

            if (buttonPush(xGL, yGL, mRenderer.dragToggle)) {
                addedTurtleNumber = 0;
                addedTurtleX = .1f;
                addedTurtleY = .1f;
                for (int j = 41; j < 44; j++) {
                    if (tList[j].getOn() != 1) {
                        addedTurtleNumber = j;
                    }
                }
                if (addedTurtleNumber == 0) {
                    addTurtleFlag = false;
                } else {
                    addTurtleFlag = true;

                }
            }

            if (buttonPush(xGL, yGL, mRenderer.addTurtle)) {
                addedTurtleNumber = 0;
                addedTurtleX = .1f;
                addedTurtleY = .1f;
                for (int j = 1; j < 11; j++) {
                    if (tList[j].getOn() != 1) {
                        addedTurtleNumber = j;
                    }
                }
                if (addedTurtleNumber == 0) {
                    addTurtleFlag = false;
                } else {
                    addTurtleFlag = true;

                }
            }

            if (buttonPush(xGL, yGL, mRenderer.dragRobotToggle)) {
                if (mRenderer.dragRobotToggle.active == false) {
                    mRenderer.dragRobotToggle.active = true;
                } else {
                    mRenderer.dragRobotToggle.active = false;
                }
            }

            if (buttonPush(xGL, yGL, mRenderer.gaussianPathToggle)) {
                if (mRenderer.gaussianPathToggle.active == true) {
                    mRenderer.gaussianPathToggle.active = false;
                    mRenderer.gaussPathPlay.active = false;
                } else {
                    mRenderer.gaussianPathToggle.active = true;
                    if (mRenderer.getfToggle() == 1) {//
                        mRenderer.gaussPathPlay.active = true;
                        mRenderer.updateGauss(
                                mRenderer.pathArray.pose[0].x * mRenderer.scale
                                        + mRenderer.dragX * mRenderer.scale,
                                mRenderer.pathArray.pose[0].y * mRenderer.scale
                                        + mRenderer.dragY * mRenderer.scale,
                                0);
                        gaussianPathArrayIteration = 1;
                        deltaX = (mRenderer.pathArray.pose[gaussianPathArrayIteration].x
                                - mRenderer.pathArray.pose[gaussianPathArrayIteration - 1].x)
                                / (float) Math.sqrt(Math
                                        .pow(mRenderer.pathArray.pose[gaussianPathArrayIteration].x
                                                - mRenderer.pathArray.pose[gaussianPathArrayIteration - 1].x, 2)
                                        + Math.pow(mRenderer.pathArray.pose[gaussianPathArrayIteration].y
                                                - mRenderer.pathArray.pose[gaussianPathArrayIteration - 1].y,
                                                2));
                        deltaY = (mRenderer.pathArray.pose[gaussianPathArrayIteration].y
                                - mRenderer.pathArray.pose[gaussianPathArrayIteration - 1].y)
                                / (float) Math.sqrt(Math
                                        .pow(mRenderer.pathArray.pose[gaussianPathArrayIteration].x
                                                - mRenderer.pathArray.pose[gaussianPathArrayIteration - 1].x, 2)
                                        + Math.pow(mRenderer.pathArray.pose[gaussianPathArrayIteration].y
                                                - mRenderer.pathArray.pose[gaussianPathArrayIteration - 1].y,
                                                2));

                    }
                }
            }

            if (xGL < mRenderer.clearAll.left - mRenderer.slider
                    && xGL > mRenderer.clearAll.right - mRenderer.slider && yGL > mRenderer.clearAll.down
                    && yGL < mRenderer.clearAll.up) {
                if (mRenderer.clearAll.active == true) {
                    mRenderer.clearAll.active = false;
                    v.vibrate(50);
                } else {
                    mRenderer.clearAll.active = true;
                    v.vibrate(50);
                }
            }

            if (xGL < mRenderer.resetToggle.left - mRenderer.slider
                    && xGL > mRenderer.resetToggle.right - mRenderer.slider && yGL > mRenderer.resetToggle.down
                    && yGL < mRenderer.resetToggle.up) {
                if (mRenderer.resetToggle.active == true) {
                    mRenderer.resetToggle.active = false;
                    v.vibrate(50);
                } else {
                    mRenderer.resetToggle.active = true;
                    v.vibrate(50);
                }
            }

            /*                    if (xGL<-(width1-90)/height1+.05f && xGL>-(width1-90)/height1 && yGL >-(height1-10)/(height1)-mRenderer.slider  && yGL < -(height1-10)/(height1)+05f-mRenderer.slider ){
                    
            }*/

            //Clear button
            if (xGL < mRenderer.clear.left - mRenderer.slider && xGL > mRenderer.clear.right - mRenderer.slider
                    && yGL > mRenderer.clear.down && yGL < mRenderer.clear.up) {
                if (mRenderer.getgToggle() == 1) {
                    gInd = 0;
                    mRenderer.clearGauss();

                }
                if (mRenderer.dragToggle.active == true) {
                    obsticle.on = 0;
                }

                deleteTurtleNumber = -1;
                for (int i = 0; i < maxBots; i++) {
                    if (tList[i].getState() == 1) {
                        deleteTurtleNumber = i;
                    }
                }
                if (deleteTurtleNumber != -1) {
                    deleteTurtleFlag = true;
                } else {
                    deleteTurtleFlag = false;
                }

                v.vibrate(75);
                mRenderer.clear.active = true;

            }

        }

        if (pFlag == 1 && xGL > workspace && xGL < mapLeft && yGL < mapTop && yGL > mapBottom) {
            pX = xGL - mRenderer.dragX * mRenderer.scale;
            pY = yGL - mRenderer.dragY * mRenderer.scale;
            pFlag2 = 1;
            mRenderer.setpToggle2(pFlag2);
            mRenderer.setWayPointValues(pX, pY);
        }

        if (gFlag == 1 && xGL > workspace && xGL < mapLeft && yGL < mapTop && yGL > mapBottom) {
            //pX=xGL;
            //pY=yGL;
            gFlag2 = 1;
            mRenderer.setgToggle2(gFlag2);

            //System.out.println("GAUSSIAN INDEX: " +gInd);
            //mRenderer.setWayPointValues(xGL, yGL);
            //mRenderer.setGaussValues(xGL, yGL, gInd);
            //mRenderer.setGaussScale(1f);
            if (gInd < 99) {
                //mRenderer.addGaussStuff(xGL, yGL, 1f,gInd);
                //TEMP FIX
                mRenderer.addGaussStuff(xGL, yGL, 1f, 0);
            }
            gInd++;
        }

        if (mRenderer.gToggle == 0 && mRenderer.fToggle == 0 && mRenderer.directionalDrag.active == true
                && (mRenderer.directionalDrag.active == true
                        && xGL < mRenderer.directionalDrag.left - mRenderer.slider
                        && xGL > mRenderer.directionalDrag.right - mRenderer.slider
                        && yGL > mRenderer.directionalDrag.down && yGL < mRenderer.directionalDrag.up)) {
            v.vibrate(50);
            if (xGL > mRenderer.directionalDrag.left
                    + (mRenderer.directionalDrag.right - mRenderer.directionalDrag.left) / 3
                    - mRenderer.slider) {
                mRenderer.dragX = mRenderer.dragX - .01f;
            }
            if (xGL < mRenderer.directionalDrag.left
                    + 2 * (mRenderer.directionalDrag.right - mRenderer.directionalDrag.left) / 3
                    - mRenderer.slider) {
                mRenderer.dragX = mRenderer.dragX + .01f;
            }

            if (yGL > mRenderer.directionalDrag.up
                    + (mRenderer.directionalDrag.down - mRenderer.directionalDrag.up) / 3) {
                mRenderer.dragY = mRenderer.dragY - .01f;
            }
            if (yGL < mRenderer.directionalDrag.up
                    + 2 * (mRenderer.directionalDrag.down - mRenderer.directionalDrag.up) / 3) {
                mRenderer.dragY = mRenderer.dragY + .01f;
            }
        }

    case MotionEvent.ACTION_POINTER_DOWN:
        //System.out.println("GAUSS 0");
        if (e.getActionIndex() == 1) {

            if (gFlag == 1) {
                float gaussX = e.getX(1);

                float gaussY = e.getY(1);

                float gauss_xGL = (width1 / 2 - gaussX) / (float) (height1 / 1.85);
                float gauss_yGL = (height1 / 2 + 30 - gaussY) / (float) (height1 / 1.85);

                float gauss_dx = gauss_xGL - xGL;
                float gauss_dy = gauss_yGL - yGL;

                float dgauss = (float) Math.sqrt(Math.pow(gauss_dx, 2) + Math.pow(gauss_dy, 2));

                gaussScale = dgauss / .2f;
                //System.out.println("SCALE");
                //mRenderer.addGaussStuff(xGL, yGL, gaussScale,gInd-1);
                //mRenderer.setGaussScale(gInd-1, gaussScale);
                //TEMP FIX
                mRenderer.setGaussScale(0, gaussScale);
            }
        }

    case MotionEvent.ACTION_MOVE:

        mRenderer.tToggle = 1;
        float dx = x - mPreviousX;
        float dy = y - mPreviousY;

        if (mRenderer.dragRobotToggle.active) {
            for (int i = 0; i < maxBots; i++) {
                if (tList[i].getOn() == 1) {
                    if (Math.abs(tList[i].getX() * getScale() + mRenderer.dragX * mRenderer.scale - xGL) < .1f
                            && Math.abs(tList[i].getY() * getScale() + mRenderer.dragY * mRenderer.scale
                                    - yGL) < .1f) {
                        addedTurtleNumber = i;
                        addedTurtleX = xGL / getScale() - mRenderer.dragX;
                        addedTurtleY = yGL / getScale() - mRenderer.dragY;
                        addTurtleFlag = true;
                        v.vibrate(50);
                    }
                }
            }

        }
        //pX+(float)Math.cos(formation.val4)*.3f+dragX*scale, pY+(float)Math.sin(formation.val4)*.3f+dragY*scale, 0);
        if (mRenderer.formation.active && mRenderer.formationToggleTransform.active) {

            if (Math.abs(mRenderer.formation.x * mRenderer.scale
                    + (float) Math.cos(mRenderer.formation.val4) * .3f * mRenderer.scale
                    + mRenderer.dragX * mRenderer.scale - xGL) < .15f
                    && Math.abs(mRenderer.formation.y * mRenderer.scale
                            + (float) Math.sin(mRenderer.formation.val4) * .3f * mRenderer.scale
                            + mRenderer.dragY * mRenderer.scale - yGL) < .15f) {
                mRenderer.formation.val4 = (float) Math.atan2(
                        yGL - (mRenderer.formation.y * mRenderer.scale + mRenderer.dragY * mRenderer.scale),
                        xGL - (mRenderer.formation.x * mRenderer.scale + mRenderer.dragX * mRenderer.scale));
                mRenderer.refreshFormationtext();
                mRenderer.justifyFormationLocations();
                mRenderer.rotation_block.active = true;
                mRenderer.formation.send = true;
            } else {
                mRenderer.rotation_block.active = false;
            }
        }

        if (mRenderer.formation.active && mRenderer.formationToggleTransform.active) {

            if (Math.abs(
                    mRenderer.formation.x * mRenderer.scale + mRenderer.dragX * mRenderer.scale - xGL) < .15f
                    && Math.abs(mRenderer.formation.y * mRenderer.scale + mRenderer.dragY * mRenderer.scale
                            - yGL) < .15f) {
                pX = xGL - mRenderer.scale * mRenderer.dragX;
                pY = yGL - mRenderer.scale * mRenderer.dragY;
                mRenderer.setWayPointValues(pX, pY);
                mRenderer.refreshFormationtext();
                mRenderer.justifyFormationLocations();
                mRenderer.center_block.active = true;
                mRenderer.formation.send = true;
            } else {
                mRenderer.center_block.active = false;
            }
        }

        if (mRenderer.formation.active && mRenderer.formationToggleTransform.active) {

            if (Math.abs(mRenderer.formation.x * mRenderer.scale + mRenderer.dragX * mRenderer.scale
                    + mRenderer.formation.val3 * .2f * mRenderer.scale - xGL) < .15f
                    && Math.abs(mRenderer.formation.y * mRenderer.scale + mRenderer.dragY * mRenderer.scale
                            - yGL) < .15f) {
                mRenderer.formation.val3 = (xGL
                        - (mRenderer.formation.x * mRenderer.scale + mRenderer.dragX * mRenderer.scale)) / .2f
                        / mRenderer.scale;
                mRenderer.refreshFormationtext();
                mRenderer.justifyFormationLocations();
                mRenderer.scale_block.active = true;
                mRenderer.formation.send = true;
            } else {
                mRenderer.scale_block.active = false;
            }
        }

        if (mRenderer.formation.active && mRenderer.customFormation.active) {
            for (int i = 0; i < mRenderer.formation.val1; i++) {
                if (target(convertToScreenPosition(mRenderer.formation_locations.x[i], true), xGL,
                        convertToScreenPosition(mRenderer.formation_locations.y[i], false), yGL, .15f)) {
                    //mRenderer.formation.x=mRenderer.formation.x*mRenderer.formation.val1-mRenderer.formation_locations.x[i];
                    //mRenderer.formation.y=mRenderer.formation.y*mRenderer.formation.val1-mRenderer.formation_locations.y[i];

                    mRenderer.formation_locations.x[i] = convertToGlobalPosition(xGL, true);
                    mRenderer.formation_locations.y[i] = convertToGlobalPosition(yGL, false);

                    //mRenderer.formation.x=mRenderer.formation.x+mRenderer.formation_locations.x[i];
                    //mRenderer.formation.x=mRenderer.formation.x/mRenderer.formation.val1;

                    //mRenderer.formation.y=mRenderer.formation.y+mRenderer.formation_locations.y[i];
                    //mRenderer.formation.y=mRenderer.formation.y/mRenderer.formation.val1;
                    mRenderer.refreshCenter();
                    break;
                }
            }
        }

        if (mRenderer.dragToggle.active == true && xGL > workspace && xGL < mapLeft && yGL < mapTop
                && yGL > mapBottom) {
            obsticle.x = xGL / getScale() - mRenderer.dragX;
            obsticle.y = yGL / getScale() - mRenderer.dragY;
            obsticle.Aw = 1;
            obsticle.on = 1;
            newObstacle = true;
        }

        if (mRenderer.gToggle == 0 && mRenderer.fToggle == 0 && mRenderer.directionalDrag.active == true
                && (mRenderer.directionalDrag.active == true
                        && xGL < mRenderer.directionalDrag.left - mRenderer.slider
                        && xGL > mRenderer.directionalDrag.right - mRenderer.slider
                        && yGL > mRenderer.directionalDrag.down && yGL < mRenderer.directionalDrag.up)) {
            v.vibrate(50);
            if (xGL > mRenderer.directionalDrag.left
                    + (mRenderer.directionalDrag.right - mRenderer.directionalDrag.left) / 3
                    - mRenderer.slider) {
                mRenderer.dragX = mRenderer.dragX - .01f;
                System.out.println("LEFT");

            }
            if (xGL < mRenderer.directionalDrag.left
                    + 2 * (mRenderer.directionalDrag.right - mRenderer.directionalDrag.left) / 3
                    - mRenderer.slider) {
                mRenderer.dragX = mRenderer.dragX + .01f;
                System.out.println("RIGHT");
            }

            if (yGL > mRenderer.directionalDrag.up
                    + (mRenderer.directionalDrag.down - mRenderer.directionalDrag.up) / 3) {
                mRenderer.dragY = mRenderer.dragY - .01f;
                System.out.println("UP");
            }
            if (yGL < mRenderer.directionalDrag.up
                    + 2 * (mRenderer.directionalDrag.down - mRenderer.directionalDrag.up) / 3) {
                mRenderer.dragY = mRenderer.dragY + .01f;
                System.out.println("DOWN");
            }
        }

        if (fFlag == 1 && (Math.abs(xGL - previousx) > .03f || Math.abs(yGL - previousy) > .03f)
                && xGL > workspace && xGL < mapLeft && yGL < mapTop && yGL > mapBottom) {
            if (previousx != 0 && previousy != 0) {
                if (firstPointFreeDraw[0] == -1000) {
                    firstPointFreeDraw[0] = previousx;
                    firstPointFreeDraw[1] = previousy;
                } else if (xGL > firstPointFreeDraw[0] + .1f || xGL < firstPointFreeDraw[0] - .1f
                        || yGL > firstPointFreeDraw[1] + .1f || yGL < firstPointFreeDraw[1] - .1f) {
                    connectable = 1;
                } else if (connectable == 1) {
                    fFlag = 0;
                    setFreeDrawCoordinates(firstPointFreeDraw[0], firstPointFreeDraw[1], previousx, previousy,
                            true);
                    v.vibrate(50);
                }

                if (fFlag == 1) {
                    setFreeDrawCoordinates(xGL - mRenderer.dragX * mRenderer.scale,
                            yGL - mRenderer.dragY * mRenderer.scale,
                            previousx - mRenderer.dragX * mRenderer.scale,
                            previousy - mRenderer.dragY * mRenderer.scale, false);
                }

            }

            previousx = xGL;
            previousy = yGL;
        }

        // reverse direction of rotation above the mid-line
        if (y > getHeight() / 2) {
            dx = dx * -1;
        }

        // reverse direction of rotation to left of the mid-line
        if (x < getWidth() / 2) {
            dy = dy * -1;
        }

        if (yGL > -.15f && yGL < .15f && xGL > -(width1 - 115) / (height1 * 2) - mRenderer.slider
                && xGL < -(width1 - 115) / (height1 * 2) - mRenderer.slider + .15f) {
            mRenderer.slider = -(width1 - 115) / (height1 * 2) - xGL;
            if (mRenderer.slider < .1f) {
                mRenderer.slider = 0;
            } else if (mRenderer.slider > -.1f + (width1 - 115) / (height1 * 2)) {
                mRenderer.slider = (width1 - 115) / (height1 * 2);
            }
        }

        mRenderer.setAngle(mRenderer.getAngle() + ((dx + dy) * TOUCH_SCALE_FACTOR)); // = 180.0f / 320
        requestRender();

        if (pFlag == 1 && xGL > workspace && xGL < mapLeft && yGL < mapTop && yGL > mapBottom) {
            pX = xGL - mRenderer.scale * mRenderer.dragX;
            pY = yGL - mRenderer.scale * mRenderer.dragY;
            pFlag2 = 1;
            mRenderer.setpToggle2(pFlag2);
            mRenderer.setWayPointValues(pX, pY);
        }

        //moving gauss
        if (gFlag == 1 && xGL > workspace && xGL < mapLeft && yGL < mapTop && yGL > mapBottom) {
            pX = xGL;
            pY = yGL;
            gFlag2 = 1;
            mRenderer.setpToggle2(gFlag2);
            //TEMP FIX
            mRenderer.updateGauss(xGL, yGL, 0);
            //mRenderer.updateGauss(xGL, yGL, gInd-1);
        }

        if (mRenderer.gToggle == 1 && xGL < mRenderer.bar.left + .04f - mRenderer.slider
                && xGL > mRenderer.bar.right - .04f - mRenderer.slider && yGL > mRenderer.dial.down
                && yGL < mRenderer.dial.up) {
            mRenderer.dial1 = -(xGL - mRenderer.bar.left - mRenderer.slider) / .6f;
            if (mRenderer.dial1 < 0.05) {
                mRenderer.dial1 = 0;
            } else if (mRenderer.dial1 > 1) {
                mRenderer.dial1 = 1;
            } else if (mRenderer.dial1 < .15) {
                mRenderer.dial1 = .1f;
            } else if (mRenderer.dial1 < .25) {
                mRenderer.dial1 = .2f;
            } else if (mRenderer.dial1 < .35) {
                mRenderer.dial1 = .3f;
            } else if (mRenderer.dial1 < .45) {
                mRenderer.dial1 = .4f;
            } else if (mRenderer.dial1 < .55) {
                mRenderer.dial1 = .5f;
            } else if (mRenderer.dial1 < .65) {
                mRenderer.dial1 = .6f;
            } else if (mRenderer.dial1 < .75) {
                mRenderer.dial1 = .7f;
            } else if (mRenderer.dial1 < .85) {
                mRenderer.dial1 = .8f;
            } else if (mRenderer.dial1 < .95) {
                mRenderer.dial1 = .9f;
            } else {
                mRenderer.dial1 = 1;
            }
            mRenderer.textListGaussian.get(1).setText(" " + truncateDecimal(mRenderer.dial1, 1));
            mRenderer.dial.active = true;
            v.vibrate(50);
        }

        if (mRenderer.gToggle == 1 && xGL < mRenderer.bar_2.left + .04f - mRenderer.slider
                && xGL > mRenderer.bar_2.right - .04f - mRenderer.slider && yGL > mRenderer.dial_2.down
                && yGL < mRenderer.dial_2.up) {
            mRenderer.dial2 = -(xGL - mRenderer.bar_2.left - mRenderer.slider) / .6f;
            if (mRenderer.dial2 < 0.05) {
                mRenderer.dial2 = 0;
            } else if (mRenderer.dial2 > 1) {
                mRenderer.dial2 = 1;
            } else if (mRenderer.dial2 < .15) {
                mRenderer.dial2 = .1f;
            } else if (mRenderer.dial2 < .25) {
                mRenderer.dial2 = .2f;
            } else if (mRenderer.dial2 < .35) {
                mRenderer.dial2 = .3f;
            } else if (mRenderer.dial2 < .45) {
                mRenderer.dial2 = .4f;
            } else if (mRenderer.dial2 < .55) {
                mRenderer.dial2 = .5f;
            } else if (mRenderer.dial2 < .65) {
                mRenderer.dial2 = .6f;
            } else if (mRenderer.dial2 < .75) {
                mRenderer.dial2 = .7f;
            } else if (mRenderer.dial2 < .85) {
                mRenderer.dial2 = .8f;
            } else if (mRenderer.dial2 < .95) {
                mRenderer.dial2 = .9f;
            } else {
                mRenderer.dial2 = 1;
            }
            mRenderer.textListGaussian.get(3).setText(" " + truncateDecimal(mRenderer.dial2, 1));
            mRenderer.dial_2.active = true;
            v.vibrate(50);
        }

        if (mRenderer.gToggle == 1 && xGL < mRenderer.bar_3.left + .04f - mRenderer.slider
                && xGL > mRenderer.bar_3.right - .04f - mRenderer.slider && yGL > mRenderer.dial_3.down
                && yGL < mRenderer.dial_3.up) {
            mRenderer.dial3 = -(xGL - mRenderer.bar_3.left - mRenderer.slider) / .6f;
            if (mRenderer.dial3 < 0.05) {
                mRenderer.dial3 = 0;
            } else if (mRenderer.dial3 > 1) {
                mRenderer.dial3 = 1;
            } else if (mRenderer.dial3 < .15) {
                mRenderer.dial3 = .1f;
            } else if (mRenderer.dial3 < .25) {
                mRenderer.dial3 = .2f;
            } else if (mRenderer.dial3 < .35) {
                mRenderer.dial3 = .3f;
            } else if (mRenderer.dial3 < .45) {
                mRenderer.dial3 = .4f;
            } else if (mRenderer.dial3 < .55) {
                mRenderer.dial3 = .5f;
            } else if (mRenderer.dial3 < .65) {
                mRenderer.dial3 = .6f;
            } else if (mRenderer.dial3 < .75) {
                mRenderer.dial3 = .7f;
            } else if (mRenderer.dial3 < .85) {
                mRenderer.dial3 = .8f;
            } else if (mRenderer.dial3 < .95) {
                mRenderer.dial3 = .9f;
            } else {
                mRenderer.dial3 = 1;
            }
            mRenderer.textListGaussian.get(5).setText(" " + truncateDecimal(mRenderer.dial3, 1));
            mRenderer.dial_3.active = true;
            v.vibrate(50);
        }

    case MotionEvent.ACTION_UP:

        mRenderer.tToggle = 1;
        //mRenderer.clear.active = false;

    }

    mPreviousX = x;
    mPreviousY = y;

    antispam = 0;
    return true;
}

From source file:com.am.pagergradienttab.view.PagerGradientTabStrip.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    final int action = ev.getAction();
    final float x = ev.getX();
    switch (action) {
    case MotionEvent.ACTION_DOWN:
        break;//from  w w  w.  ja v a  2  s . c  o  m

    case MotionEvent.ACTION_MOVE:
        break;

    case MotionEvent.ACTION_UP:
        for (int i = 0; i < tabs.size(); i++) {
            float l = getPaddingLeft() + intervalWidth * i + itemWidth * i;
            float r = l + itemWidth;
            if (x >= l && x <= r) {
                clickPosition = i;
                break;
            }
        }
        performClick();
        break;
    }

    return true;
}