Example usage for android.view MotionEvent ACTION_POINTER_DOWN

List of usage examples for android.view MotionEvent ACTION_POINTER_DOWN

Introduction

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

Prototype

int ACTION_POINTER_DOWN

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

Click Source Link

Document

Constant for #getActionMasked : A non-primary pointer has gone down.

Usage

From source file:ch.tutti.android.bottomsheet.ResolverDrawerLayout.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    final int action = ev.getActionMasked();

    if (canChildScrollUp()) {
        // Fail fast if we're not in a state where a swipe is possible
        return super.onTouchEvent(ev);
    }/*  w w w  .  j av a 2s  .c  om*/

    mVelocityTracker.addMovement(ev);

    boolean handled = false;
    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        final float x = ev.getX();
        final float y = ev.getY();
        mInitialTouchX = x;
        mInitialTouchY = mLastTouchY = y;
        mActivePointerId = ev.getPointerId(0);
        if (findChildUnder(mInitialTouchX, mInitialTouchY) == null && mClickOutsideListener != null) {
            mIsDragging = handled = true;
        }
        handled |= mCollapsibleHeight > 0;
        mScroller.abortAnimation();
    }
        break;

    case MotionEvent.ACTION_MOVE: {
        int index = ev.findPointerIndex(mActivePointerId);
        if (index < 0) {
            Log.e(TAG, "Bad pointer id " + mActivePointerId + ", resetting");
            index = 0;
            mActivePointerId = ev.getPointerId(0);
            mInitialTouchX = ev.getX();
            mInitialTouchY = mLastTouchY = ev.getY();
        }
        final float x = ev.getX(index);
        final float y = ev.getY(index);
        if (!mIsDragging) {
            final float dy = y - mInitialTouchY;
            if (Math.abs(dy) > mTouchSlop && findChildUnder(x, y) != null) {
                handled = mIsDragging = true;
                mLastTouchY = Math.max(mLastTouchY - mTouchSlop,
                        Math.min(mLastTouchY + dy, mLastTouchY + mTouchSlop));
            }
        }
        if (mIsDragging) {
            final float dy = y - mLastTouchY;
            performDrag(dy);
        }
        mLastTouchY = y;
    }
        break;

    case MotionEvent.ACTION_POINTER_DOWN: {
        final int pointerIndex = ev.getActionIndex();
        final int pointerId = ev.getPointerId(pointerIndex);
        mActivePointerId = pointerId;
        mInitialTouchX = ev.getX(pointerIndex);
        mInitialTouchY = mLastTouchY = ev.getY(pointerIndex);
    }
        break;

    case MotionEvent.ACTION_POINTER_UP: {
        onSecondaryPointerUp(ev);
    }
        break;

    case MotionEvent.ACTION_UP: {
        mIsDragging = false;
        if (!mIsDragging && findChildUnder(mInitialTouchX, mInitialTouchY) == null
                && findChildUnder(ev.getX(), ev.getY()) == null) {
            if (mClickOutsideListener != null) {
                mClickOutsideListener.onClick(this);
                resetTouch();
                return true;
            }
        }
        if (mOpenOnClick && Math.abs(ev.getX() - mInitialTouchX) < mTouchSlop
                && Math.abs(ev.getY() - mInitialTouchY) < mTouchSlop) {
            smoothScrollTo(0, 0);
            return true;
        }
        mVelocityTracker.computeCurrentVelocity(1000);
        final float yvel = mVelocityTracker.getYVelocity(mActivePointerId);
        if (Math.abs(yvel) > mMinFlingVelocity) {
            smoothScrollTo(yvel < 0 ? 0 : mCollapsibleHeight, yvel);
        } else {
            smoothScrollTo(mCollapseOffset < mCollapsibleHeight / 2 ? 0 : mCollapsibleHeight, 0);
        }
        resetTouch();
    }
        break;

    case MotionEvent.ACTION_CANCEL: {
        if (mIsDragging) {
            smoothScrollTo(mCollapseOffset < mCollapsibleHeight / 2 ? 0 : mCollapsibleHeight, 0);
        }
        resetTouch();
        return true;
    }
    }

    return handled || (action == MotionEvent.ACTION_MOVE && mCollapseOffset > 0);
}

From source file:cc.solart.turbo.TurboRecyclerView.java

@Override
public boolean onInterceptTouchEvent(MotionEvent e) {
    if (!mLoadEnabled || canScrollEnd() || mIsLoading || isEmpty()) {
        return super.onInterceptTouchEvent(e);
    }/*from ww  w  .  ja  v a2s. co m*/

    if (dispatchOnItemTouchIntercept(e)) {
        return true;
    }

    final int action = MotionEventCompat.getActionMasked(e);
    final int actionIndex = MotionEventCompat.getActionIndex(e);
    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        mActivePointerId = MotionEventCompat.getPointerId(e, 0);
        mInitialMotionX = getMotionEventX(e, actionIndex);
        mInitialMotionY = getMotionEventY(e, actionIndex);
    }
        break;

    case MotionEvent.ACTION_POINTER_DOWN: {
        mActivePointerId = MotionEventCompat.getPointerId(e, actionIndex);
        mInitialMotionX = getMotionEventX(e, actionIndex);
        mInitialMotionY = getMotionEventY(e, actionIndex);
    }
        break;

    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        mActivePointerId = INVALID_POINTER;
        break;
    case MotionEventCompat.ACTION_POINTER_UP: {
        onPointerUp(e);
    }
        break;
    }
    return super.onInterceptTouchEvent(e);
}

From source file:com.tasomaniac.openwith.resolver.ResolverDrawerLayout.java

@Override
public boolean onTouchEvent(MotionEvent ev) {
    final int action = MotionEventCompat.getActionMasked(ev);

    mVelocityTracker.addMovement(ev);/* w  w w.j  a  v  a2  s  .  c om*/

    boolean handled = false;
    switch (action) {
    case MotionEvent.ACTION_DOWN: {
        final float x = ev.getX(0);
        final float y = ev.getY(0);
        mInitialTouchX = x;
        mInitialTouchY = mLastTouchY = y;
        mActivePointerId = ev.getPointerId(0);
        final boolean hitView = findChildUnder(mInitialTouchX, mInitialTouchY) != null;
        handled = (!hitView && mOnDismissedListener != null) || mCollapsibleHeight > 0;
        mIsDragging = hitView && handled;
        abortAnimation();
    }
        break;

    case MotionEvent.ACTION_MOVE: {
        int index = ev.findPointerIndex(mActivePointerId);
        if (index < 0) {
            Timber.e("Bad pointer id %d, resetting", mActivePointerId);
            index = 0;
            mActivePointerId = ev.getPointerId(0);
            mInitialTouchX = ev.getX(0);
            mInitialTouchY = mLastTouchY = ev.getY(0);
        }
        final float x = ev.getX(index);
        final float y = ev.getY(index);
        if (!mIsDragging) {
            final float dy = y - mInitialTouchY;
            if (Math.abs(dy) > mTouchSlop && findChildUnder(x, y) != null) {
                handled = mIsDragging = true;
                mLastTouchY = Math.max(mLastTouchY - mTouchSlop,
                        Math.min(mLastTouchY + dy, mLastTouchY + mTouchSlop));
            }
        }
        if (mIsDragging) {
            final float dy = y - mLastTouchY;
            performDrag(dy);
        }
        mLastTouchY = y;
    }
        break;

    case MotionEvent.ACTION_POINTER_DOWN: {
        final int pointerIndex = MotionEventCompat.getActionIndex(ev);

        mActivePointerId = ev.getPointerId(pointerIndex);
        mInitialTouchX = ev.getX(pointerIndex);
        mInitialTouchY = mLastTouchY = ev.getY(pointerIndex);
    }
        break;

    case MotionEvent.ACTION_POINTER_UP: {
        onSecondaryPointerUp(ev);
    }
        break;

    case MotionEvent.ACTION_UP: {
        final boolean wasDragging = mIsDragging;
        mIsDragging = false;
        if (!wasDragging && findChildUnder(mInitialTouchX, mInitialTouchY) == null
                && findChildUnder(ev.getX(0), ev.getY(0)) == null) {
            if (mOnDismissedListener != null) {
                dispatchOnDismissed();
                resetTouch();
                return true;
            }
        }
        if (mOpenOnClick && Math.abs(ev.getX(0) - mInitialTouchX) < mTouchSlop
                && Math.abs(ev.getY(0) - mInitialTouchY) < mTouchSlop) {
            smoothScrollTo(0, 0);
            return true;
        }
        mVelocityTracker.computeCurrentVelocity(1000);
        final float yvel = VelocityTrackerCompat.getYVelocity(mVelocityTracker, mActivePointerId);
        if (Math.abs(yvel) > mMinFlingVelocity) {
            if (mOnDismissedListener != null && yvel > 0 && mCollapseOffset > mCollapsibleHeight) {
                smoothScrollTo(mCollapsibleHeight + mUncollapsibleHeight, yvel);
                mDismissOnScrollerFinished = true;
            } else {
                smoothScrollTo(yvel < 0 ? 0 : mCollapsibleHeight, yvel);
            }
        } else {
            smoothScrollTo(mCollapseOffset < mCollapsibleHeight / 2 ? 0 : mCollapsibleHeight, 0);
        }
        resetTouch();
    }
        break;

    case MotionEvent.ACTION_CANCEL: {
        if (mIsDragging) {
            smoothScrollTo(mCollapseOffset < mCollapsibleHeight / 2 ? 0 : mCollapsibleHeight, 0);
        }
        resetTouch();
        return true;
    }
    }

    return handled;
}

From source file:org.que.activities.fragments.MapImageFragment.java

/**
 * The onTouch method which will be called if an onTouch event appears.
 * /*from w  w w . ja  v  a 2 s .co m*/
 * @param view the view which was touched
 * @param event the touch event
 * @return true if the touch event was handled, false otherwise
 */
public boolean onTouch(View view, MotionEvent event) {
    Boolean consumed;
    ImageView image = (ImageView) view;
    switch (event.getAction() & MotionEvent.ACTION_MASK) //bitwise and with mask
    {
    case MotionEvent.ACTION_DOWN:
        saved.set(m);
        p.set(event.getX(), event.getY());
        mode = TOUCH_MODE.DRAG;
        consumed = true;
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
        mode = TOUCH_MODE.NONE;
        consumed = true;
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
        saved.set(m);
        mode = TOUCH_MODE.ZOOM;
        oldDis = euclideanDistance(event);
        p = calcMidPoint(p, event);
        consumed = true;
        break;
    case MotionEvent.ACTION_MOVE:
        if (mode == TOUCH_MODE.ZOOM) {
            m.set(saved);
            newDis = euclideanDistance(event);
            scale = newDis / oldDis;
            m.postScale(scale, scale, p.x, p.y);
            float[] values = new float[9];
            m.getValues(values);
            float mscale = values[Matrix.MSCALE_X];
            if (mscale < MIN_ZOOM) {
                m.setScale(MIN_ZOOM, MIN_ZOOM, p.x, p.y);
            } else if (mscale > MAX_ZOOM) {
                m.setScale(MAX_ZOOM, MAX_ZOOM, p.x, p.y);
            }
        } else if (mode == TOUCH_MODE.DRAG) {
            m.set(saved);
            m.postTranslate(event.getX() - p.x, event.getY() - p.y);
        }
        consumed = true;
        break;
    default:
        consumed = false;

    }
    image.setImageMatrix(m);
    return consumed;
}

From source file:sjizl.com.ChatFriendListFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    LayoutInflater factory = LayoutInflater.from(getActivity());
    View myView = factory.inflate(R.layout.activity_chatfriendlist_fragment, null);
    position222 = getArguments().getInt(ARG_POSITION);
    i22d = this.getId();
    AbsListViewBaseActivity.imageLoader/*from w w w .  j av  a 2 s.c  o  m*/
            .init(ImageLoaderConfiguration.createDefault(getActivity().getBaseContext()));

    if (userFunctions.isUserLoggedIn(getActivity().getApplicationContext())) {

        Image3 = (ImageView) getActivity().findViewById(R.id.imageView2_dashboard);
        imageView1_logo = (ImageView) getActivity().findViewById(R.id.imageView1_logo);
        imageView_bericht = (ImageView) getActivity().findViewById(R.id.imageView_bericht);

        right_lin = (LinearLayout) myView.findViewById(R.id.search_right_lin);
        left_lin1 = (LinearLayout) getActivity().findViewById(R.id.left_lin1);

        left_lin3 = (LinearLayout) getActivity().findViewById(R.id.left_lin3);
        left_lin4 = (LinearLayout) getActivity().findViewById(R.id.left_lin4);
        middle_lin = (LinearLayout) myView.findViewById(R.id.search_middle_lin);
        progressBar_hole = (ProgressBar) getActivity().findViewById(R.id.progressBar_hole);
        progressBar_hole.setVisibility(View.INVISIBLE);
        final ImageView left_button;

        left_button = (ImageView) getActivity().findViewById(R.id.imageView1_back);
        editText_search = new EditText(getActivity().getApplicationContext());

        SharedPreferences sp = getActivity().getApplicationContext().getSharedPreferences("loginSaved",
                Context.MODE_PRIVATE);
        naam = sp.getString("naam", null);
        username = sp.getString("username", null);
        password = sp.getString("password", null);
        foto = sp.getString("foto", null);
        foto_num = sp.getString("foto_num", null);

        getActivity().registerReceiver(mHandleMessageReceiver2, new IntentFilter(DISPLAY_MESSAGE_ACTION));

        imageLoader.displayImage("http://sjizl.com/fotos/" + foto_num + "/thumbs/" + foto, Image3, options);
        listView = (ListView) myView.findViewById(android.R.id.list);
        //imageLoader.displayImage("drawable://" + R.drawable.browse, imageView_bericht, options);

        listView.setLongClickable(true);

        registerForContextMenu(listView);

        listView.setOnItemClickListener(new OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                //startImagePagerActivity(position);

                String selectedValue0 = pids[position];
                String selectedValue = names[position];
                String selectedValue2 = laatste_bericht[position];
                String selectedValue3 = imageUrls2[position];
                String selectedValue4 = fotos[position];
                String selectedValue5 = fotos_nums[position];

                Intent dashboard = new Intent(getActivity().getApplicationContext(), ChatActivity.class);
                dashboard.putExtra("pid_user", selectedValue0);
                dashboard.putExtra("user", selectedValue);
                dashboard.putExtra("user_foto", selectedValue4);
                dashboard.putExtra("user_foto_num", selectedValue5);

                startActivity(dashboard);
            }
        });

        right_lin.setOnTouchListener(new OnTouchListener() {
            @SuppressLint("DefaultLocale")
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE
                        || event.getAction() == MotionEvent.ACTION_POINTER_DOWN) {

                    //textView1_bgtext.setVisibility(View.GONE);
                    //textView2_under_title.setVisibility(View.GONE);

                    //editText_search.setId(9000);
                    if (!clicked) {

                        middle_lin.addView(editText_search);
                        editText_search.requestFocus();
                        clicked = true;

                    } else {

                        //clicked=false;

                    }

                    editText_search.addTextChangedListener(new TextWatcher() {

                        @SuppressLint("DefaultLocale")
                        @Override
                        public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {

                            ArrayList<String> new_stock_list0 = new ArrayList<String>();
                            ArrayList<String> new_stock_list = new ArrayList<String>();
                            ArrayList<String> new_stock_list2 = new ArrayList<String>();
                            ArrayList<String> new_stock_list3 = new ArrayList<String>();
                            ArrayList<String> new_stock_list4 = new ArrayList<String>();
                            ArrayList<String> new_stock_list5 = new ArrayList<String>();
                            ArrayList<String> new_stock_list6 = new ArrayList<String>();
                            ArrayList<String> new_stock_list7 = new ArrayList<String>();
                            ArrayList<String> new_stock_list8 = new ArrayList<String>();

                            int p = stock_list2.size();
                            for (int i = 0; i < p; i++) { // **line 2**

                                Log.d("" + i, "" + stock_list2.get(i));
                                if (stock_list2.get(i).toString().trim().toLowerCase()
                                        .contains(cs.toString().toLowerCase())) {
                                    Log.d("" + i, "" + stock_list2.get(i));

                                    new_stock_list8.add(stock_list8.get(i));
                                    new_stock_list7.add(stock_list7.get(i));
                                    new_stock_list6.add(stock_list6.get(i));
                                    new_stock_list4.add(stock_list4.get(i));
                                    new_stock_list5.add(stock_list5.get(i));
                                    new_stock_list2.add(stock_list2.get(i));
                                    new_stock_list3.add(stock_list3.get(i));
                                    new_stock_list.add(stock_list.get(i));
                                    new_stock_list0.add(stock_list0.get(i));

                                }

                            }

                            stockArr0 = new String[new_stock_list0.size()];
                            stockArr = new String[new_stock_list.size()];
                            stockArr2 = new String[new_stock_list2.size()];
                            stockArr3 = new String[new_stock_list3.size()];
                            stockArr4 = new String[new_stock_list4.size()];
                            stockArr5 = new String[new_stock_list5.size()];
                            stockArr6 = new String[new_stock_list6.size()];
                            stockArr7 = new String[new_stock_list7.size()];
                            stockArr8 = new String[new_stock_list8.size()];

                            pids = new_stock_list0.toArray(stockArr0);
                            is_onlines = new_stock_list8.toArray(stockArr8);
                            laatste_tijd = new_stock_list7.toArray(stockArr7);
                            aantal_new_ber = new_stock_list6.toArray(stockArr6);
                            imageUrls2 = new_stock_list.toArray(stockArr);
                            names = new_stock_list2.toArray(stockArr2);
                            laatste_bericht = new_stock_list3.toArray(stockArr3);
                            fotos = new_stock_list4.toArray(stockArr4);
                            fotos_nums = new_stock_list5.toArray(stockArr5);

                            adapter.notifyDataSetChanged();

                        }

                        @Override
                        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
                            // TODO Auto-generated method stub

                        }

                        @Override
                        public void afterTextChanged(Editable arg0) {
                            // TODO Auto-generated method stub
                            //   Toast.makeText(getApplicationContext(), "search for"+arg0.toString(), Toast.LENGTH_SHORT).show();
                        }
                    });

                    //right_lin.setBackgroundColor(Color.DKGRAY);
                    //v.setBackgroundColor(Color.DKGRAY);
                    //Intent dash = new Intent(getApplicationContext(),ChatFriendList.class);
                    //dash.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                    //startActivity(dash);
                } else if (event.getAction() == MotionEvent.ACTION_UP
                        || event.getAction() == MotionEvent.ACTION_CANCEL) {
                    //right_lin.setBackgroundColor(Color.BLACK);
                    //v.setBackgroundColor(Color.BLACK);
                }
                return false;
            }
        });

        new UpdateList().execute();

    } else {
        // user is not logged in show login screen

        Intent login = new Intent(getActivity().getApplicationContext(), LoginActivity.class);
        login.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        startActivity(login);
        // Closing dashboard screen
        getActivity().finish();
    }
    return myView;

}

From source file:com.pseudosurface.levels.template.SimulatorActivity.java

@Override
public boolean onTouchEvent(MotionEvent event) {

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

    // Remember some things for zooming
    PointF start = new PointF();
    PointF mid = new PointF();
    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        start.set(event.getX(), event.getY());
        //          Log.d(TAG, "mode=DRAG");

        break;//from w w  w. j  a  va 2  s. co  m
    case MotionEvent.ACTION_POINTER_DOWN:
        oldDist = spacing(event);
        if (oldDist > 10f) {
            midPoint(mid, event);
            mode = ZOOM;
            //             Log.d(TAG, "mode=ZOOM");
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
        mode = NONE;
        oldDist = -1;
        //          Log.d(TAG, "mode=NONE");
        break;
    case MotionEvent.ACTION_MOVE:

        if (mode == ZOOM) {
            float newDist = spacing(event);
            if (newDist > simulation.minZoom && oldDist != -1) {
                simulation.zoom -= (newDist - oldDist) * .05;
            }
            oldDist = newDist;
        } else {
            float dz = x - mPreviousX;
            float dy = y - mPreviousY;

            float r = (float) Math.sqrt(dz * dz + dy * dy);

            double theta = Math.atan2(dy, dz) + Math.PI + SimulatorActivity.angleLR;

            try {
                simulation.world.objects[simulation.world.getPlayerIndex()].omega[0] += .05f * r
                        * Math.cos(theta);
                simulation.world.objects[simulation.world.getPlayerIndex()].omega[2] += .05f * r
                        * Math.sin(theta);
            } catch (Exception e) {
            }

            //MainActivity.angleLR += dx*.01;
            //simulation.zoom += dy*.01;
        }
        break;
    }

    mPreviousX = x;
    mPreviousY = y;

    gestureDetector.onTouchEvent(event);

    return true; // indicate event was handled
}

From source file:sjizl.com.FileUploadTest.java

@SuppressLint("NewApi")
@Override// www  .j  a  v  a2  s .c  om
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.fileuploadtest2);
    //ac_image_grid
    TextView textView2_under_title;
    final ImageLoader imageLoader = ImageLoader.getInstance();
    imageLoader.init(ImageLoaderConfiguration.createDefault(getApplicationContext()));
    progressBar_hole = (ProgressBar) findViewById(R.id.progressBar_hole);
    progressBar_hole.setVisibility(View.INVISIBLE);
    right_lin = (LinearLayout) findViewById(R.id.right_lin);
    rand = CommonUtilities.randInt(111, 999);
    middle_lin = (LinearLayout) findViewById(R.id.middle_lin);
    //right_lin.setBackgroundColor(Color.BLUE);
    right_lin = (LinearLayout) findViewById(R.id.right_lin);
    left_lin1 = (LinearLayout) findViewById(R.id.left_lin1);

    left_lin3 = (LinearLayout) findViewById(R.id.left_lin3);
    left_lin4 = (LinearLayout) findViewById(R.id.left_lin4);
    middle_lin = (LinearLayout) findViewById(R.id.middle_lin);

    upload_photo_text = (LinearLayout) findViewById(R.id.upload_photo_text);

    textView2_under_title = (TextView) findViewById(R.id.textView2_under_title);
    ((LinearLayout) textView2_under_title.getParent()).removeView(textView2_under_title);
    textView2_under_title.setVisibility(View.GONE);
    ImageView imageView2_dashboard = (ImageView) findViewById(R.id.imageView2_dashboard);
    if (android.os.Build.VERSION.SDK_INT > 9) {
        StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy);
    }

    Button upload_photo0 = (Button) findViewById(R.id.upload_photo0);
    Button upload_photo1 = (Button) findViewById(R.id.upload_photo1);
    Button upload_photo2 = (Button) findViewById(R.id.upload_photo2);

    upload_photo0.setVisibility(View.GONE);
    upload_photo1.setVisibility(View.GONE);
    upload_photo2.setVisibility(View.GONE);

    upload_photo0.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            CommonUtilities.custom_toast(getApplicationContext(), FileUploadTest.this, "UploadActivity! ", null,
                    R.drawable.iconbd);

            Intent dashboard = new Intent(getApplicationContext(), UploadActivity.class);

            startActivity(dashboard);
        }
    });
    upload_photo1.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {

            Toast.makeText(getApplicationContext(), "FileChooserExampleActivity!", Toast.LENGTH_LONG).show();
            Intent dashboard = new Intent(getApplicationContext(), FileChooserExampleActivity.class);

            startActivity(dashboard);
        }
    });

    upload_photo2.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Toast.makeText(getApplicationContext(), "FileChooserExampleActivity!", Toast.LENGTH_LONG).show();
            Intent dashboard = new Intent(getApplicationContext(), FileChooserExampleActivity.class);

            startActivity(dashboard);
        }
    });

    final ImageView left_button;

    left_button = (ImageView) findViewById(R.id.imageView1_back);
    Button button1 = (Button) findViewById(R.id.upload_photo1);

    SharedPreferences sp = getApplicationContext().getSharedPreferences("loginSaved", Context.MODE_PRIVATE);
    naam = sp.getString("naam", null);
    username = sp.getString("username", null);
    password = sp.getString("password", null);
    foto = sp.getString("foto", null);
    foto_num = sp.getString("foto_num", null);
    imageLoader.displayImage("http://sjizl.com/fotos/" + foto_num + "/thumbs/" + foto, imageView2_dashboard,
            options);

    Brows();

    listView.setLongClickable(true);
    registerForContextMenu(listView);

    listView.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            //startImagePagerActivity(position);

            if (position == 0) {
                openGallery(SELECT_FILE1);
            } else {

                listView.showContextMenuForChild(view);
                //  registerForContextMenu(view); 
                //  openContextMenu(view);
                //  unregisterForContextMenu(view);
            }

        }
    });

    left_lin1.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE
                    || event.getAction() == MotionEvent.ACTION_POINTER_DOWN) {
                left_lin1.setBackgroundColor(Color.DKGRAY);
                v.setBackgroundColor(Color.DKGRAY);
                onBackPressed();
            } else if (event.getAction() == MotionEvent.ACTION_UP
                    || event.getAction() == MotionEvent.ACTION_CANCEL) {
                left_lin1.setBackgroundColor(Color.BLACK);
                v.setBackgroundColor(Color.BLACK);
            }
            return false;
        }
    });
    CommonUtilities u = new CommonUtilities();
    u.setHeaderConrols(getApplicationContext(), this,

            right_lin,

            left_lin3, left_lin4, left_lin1, left_button);
    ;

    middle_lin.setOnTouchListener(new OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE
                    || event.getAction() == MotionEvent.ACTION_POINTER_DOWN) {
                middle_lin.setBackgroundColor(Color.DKGRAY);
                v.setBackgroundColor(Color.DKGRAY);
            } else if (event.getAction() == MotionEvent.ACTION_UP
                    || event.getAction() == MotionEvent.ACTION_CANCEL) {
                middle_lin.setBackgroundColor(Color.BLACK);
                v.setBackgroundColor(Color.BLACK);
            }
            return false;
        }
    });

}

From source file:com.lixplor.rocketpulltorefresh.RefreshLayout.java

/**
 * Evaluate if this should intercept touch event to enable pull actions
 * @param ev MotionEvent/*from   w w w.j  a v  a2  s  .  co m*/
 * @param contentView content view to help evaluate
 * @return true if intercepts; false otherwise
 */
private boolean shouldInterceptTouchEvent(MotionEvent ev, View contentView) {
    boolean shouldIntercept;
    switch (ev.getAction()) {
    case MotionEvent.ACTION_DOWN:
    case MotionEvent.ACTION_POINTER_DOWN:
        mInterceptDownY = ev.getRawY();
        break;
    case MotionEvent.ACTION_MOVE:
        mInterceptMoveY = ev.getRawY();
        mLastTouchRawY = mInterceptMoveY;
        if (Math.abs(mInterceptMoveY - mInterceptDownY) > mTouchSlop) {
            if (mEnableRefresh && mInterceptMoveY - mInterceptDownY > 0) {
                // pull down, evaluate if content view is at top
                shouldIntercept = !ViewCompat.canScrollVertically(contentView, -1);
                return shouldIntercept;
            } else if (mEnableLoadMore && mInterceptMoveY - mInterceptDownY < 0) {
                // pull up, evaluate if content view is at bottom
                shouldIntercept = !ViewCompat.canScrollVertically(contentView, 1);
                return shouldIntercept;
            }
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_CANCEL:
        break;
    }
    return super.onInterceptTouchEvent(ev);
}

From source file:org.cocos2dx.lib.TextInputWraper.java

public boolean onTouchEvent(final MotionEvent event) {
    // these data are used in ACTION_MOVE and ACTION_CANCEL
    final int pointerNumber = event.getPointerCount();
    final int[] ids = new int[pointerNumber];
    final float[] xs = new float[pointerNumber];
    final float[] ys = new float[pointerNumber];

    for (int i = 0; i < pointerNumber; i++) {
        ids[i] = event.getPointerId(i);//from  w w  w.  j  a v a2 s  .  c om
        xs[i] = event.getX(i);
        ys[i] = event.getY(i);
    }

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_POINTER_DOWN:
        final int indexPointerDown = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
        final int idPointerDown = event.getPointerId(indexPointerDown);
        final float xPointerDown = event.getX(indexPointerDown);
        final float yPointerDown = event.getY(indexPointerDown);

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionDown(idPointerDown, xPointerDown, yPointerDown);
            }
        });
        break;

    case MotionEvent.ACTION_DOWN:
        // there are only one finger on the screen
        final int idDown = event.getPointerId(0);
        final float xDown = xs[0];
        final float yDown = ys[0];

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionDown(idDown, xDown, yDown);
            }
        });
        break;

    case MotionEvent.ACTION_MOVE:
        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionMove(ids, xs, ys);
            }
        });
        break;

    case MotionEvent.ACTION_POINTER_UP:
        final int indexPointUp = event.getAction() >> MotionEvent.ACTION_POINTER_ID_SHIFT;
        final int idPointerUp = event.getPointerId(indexPointUp);
        final float xPointerUp = event.getX(indexPointUp);
        final float yPointerUp = event.getY(indexPointUp);

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionUp(idPointerUp, xPointerUp, yPointerUp);
            }
        });
        break;

    case MotionEvent.ACTION_UP:
        // there are only one finger on the screen
        final int idUp = event.getPointerId(0);
        final float xUp = xs[0];
        final float yUp = ys[0];

        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionUp(idUp, xUp, yUp);
            }
        });
        break;

    case MotionEvent.ACTION_CANCEL:
        queueEvent(new Runnable() {
            @Override
            public void run() {
                mRenderer.handleActionCancel(ids, xs, ys);
            }
        });
        break;
    }

    if (debug) {
        dumpEvent(event);
    }
    return true;
}

From source file:com.slushpupie.deskclock.DeskClock.java

@Override
public boolean onTouch(View v, MotionEvent event) {
    if (!supportMultiTouch)
        return false;

    switch (event.getAction() & MotionEvent.ACTION_MASK) {
    case MotionEvent.ACTION_DOWN:
        mode = DRAG;//www .  j  av a 2s  .co  m
        break;
    case MotionEvent.ACTION_POINTER_DOWN:
        oldDist = spacing(event);
        if (oldDist > 10f) {
            mode = ZOOM;
        }
        break;
    case MotionEvent.ACTION_UP:
    case MotionEvent.ACTION_POINTER_UP:
        mode = NONE;
        break;
    case MotionEvent.ACTION_MOVE:
        if (mode == DRAG) {
            // ..
        } else if (mode == ZOOM) {
            float newDist = spacing(event);
            if (newDist > 10f) {
                float scaleF = newDist / oldDist;
                int scale = (int) (scaleF * 100.0);
                if (scale < 0)
                    scale = scale * -1;
                if (scale > 100)
                    scale = 100;

                // change font size
                SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
                prefs.edit().putInt("pref_scale", scale).commit();
            }
        }
        break;
    }
    if (mode == ZOOM) {
        return true;
    } else {
        return false;
    }
}