List of usage examples for android.view MotionEvent ACTION_UP
int ACTION_UP
To view the source code for android.view MotionEvent ACTION_UP.
Click Source Link
From source file:com.example.SmartBoard.DrawingView.java
@Override public boolean onTouchEvent(MotionEvent event) { //detect user touch float touchX = event.getX(); float touchY = event.getY(); //System.out.println("X"+touchX); // System.out.println("Y"+touchY); if (rectMode) { onTouchRectangleMode(event);//ww w . j av a2s . c o m return true; } else if (circleMode) { onTouchCircleMode(event); return true; } else if (lineMode) { onTouchLineMode(event); return true; } else if (textMode) { onTouchTextMode(event); return true; } else if (dragMode) { onTouchDragEvent(event); return true; } else if (removeObjectMode) { onRemoveObjectEvent(event); return true; } else if (colorDropperMode) { onTouchColorDropperMode(event); return true; } else if (textSizeMode) { onTouchTextResizeEvent(event); return true; } switch (event.getAction()) { case MotionEvent.ACTION_DOWN: drawPath.moveTo(touchX, touchY); break; case MotionEvent.ACTION_MOVE: drawPath.lineTo(touchX, touchY); break; case MotionEvent.ACTION_UP: drawCanvas.drawPath(drawPath, drawPaint); drawPath.reset(); break; default: return false; } //System.out.println(mqtt); invalidate(); mqtt.publish(touchX, touchY, event.getAction(), paintColor, mode, strokeWidth); return true; }
From source file:com.ssn.currency.convertor.WheelView.java
@Override public boolean onTouchEvent(MotionEvent event) { if (!isEnabled() || getViewAdapter() == null) { return true; }//from ww w . j a v a 2s . c om switch (event.getAction()) { case MotionEvent.ACTION_MOVE: if (getParent() != null) { getParent().requestDisallowInterceptTouchEvent(true); } break; case MotionEvent.ACTION_UP: if (!isScrollingPerformed) { int distance = (int) event.getY() - getHeight() / 2; if (distance > 0) { distance += getItemHeight() / 2; } else { distance -= getItemHeight() / 2; } int items = distance / getItemHeight(); if (items != 0 && isValidItemIndex(currentItem + items)) { notifyClickListenersAboutClick(currentItem + items); } } break; } return scroller.onTouchEvent(event); }
From source file:com.ayuget.redface.ui.activity.ReplyActivity.java
/** * Initializes both the smiley selector// w w w .j a v a 2 s . c o m */ protected void setupSmileySelector() { smileyList.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { final int action = MotionEventCompat.getActionMasked(event); switch (action) { case MotionEvent.ACTION_DOWN: { final int pointerIndex = MotionEventCompat.getActionIndex(event); lastTouchY = MotionEventCompat.getY(event, pointerIndex); activePointerId = MotionEventCompat.getPointerId(event, 0); break; } case MotionEvent.ACTION_MOVE: { if (smileyList.getScrollY() == 0) { final int pointerIndex = MotionEventCompat.findPointerIndex(event, activePointerId); if (pointerIndex != -1) { final float y = MotionEventCompat.getY(event, pointerIndex); // Distance float dy = y - lastTouchY; isUpwardMovement = dy < 0; float targetY = smileysSelector.getY() + dy; if (targetY < toolbarHeight) { float difference = toolbarHeight - targetY; dy += difference; } else if (targetY > smileySelectorTopOffset) { float difference = targetY - smileySelectorTopOffset; dy -= difference; } smileysSelector.setY(smileysSelector.getY() + dy); // Show or hide the smileys toolbar based on current position if (isUpwardMovement && smileysSelector.getY() < replyWindowMaxHeight) { showSmileysToolbar(); } else { hideSmileysToolbar(); } } break; } } case MotionEvent.ACTION_UP: { int upAnimationThreshold = replyWindowMaxHeight - toolbarHeight; float yTranslation; ViewPropertyAnimator viewPropertyAnimator = smileysSelector.animate(); if (isUpwardMovement && smileysSelector.getY() == upAnimationThreshold) { // Do not move in that case yTranslation = 0; } else if (isUpwardMovement && smileysSelector.getY() < upAnimationThreshold) { // Moving too far, let's avoid this yTranslation = -(smileysSelector.getY() - toolbarHeight); } else { // Replace the smiley selector at its original position yTranslation = smileySelectorTopOffset - smileysSelector.getY(); } if (yTranslation != 0) { viewPropertyAnimator.translationYBy(yTranslation).setDuration(150).start(); } break; } } boolean touchConsumed; if (smileysSelector.getY() != smileySelectorTopOffset) { touchConsumed = (smileysSelector.getY() != toolbarHeight); } else { touchConsumed = false; } return touchConsumed; } }); }
From source file:com.z.stproperty.PropertyDetailFragment.java
/** * PHOTOS//w w w .j a va2 s . c o m * * photos are shown in pager and when the user touches the pager * then scroll stops to scroll vertically * * DETAILS * * Will show all the details related to the property or directory * like type, * title, * subtype, * district etc.. * * FACILITIES * * This method will add the facility details by calling both * loadLandDisplay() and loadPortraitDisplay(). It will check weather there * is any facility or not and if there is no facility, then noFacilites * TextView is made visible. Else, the TextView is made gone and * directory_facilities_row layout is inflated and is added to * facilityParent. * */ private View addProjectDetail() { View view = inflater.inflate(R.layout.property_details, null); try { projectDetailScrollView = (ScrollView) view.findViewById(R.id.DetailsScroll); if (detailsJson == null) { SharedPreferences mPrefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); detailsJson = new JSONObject(mPrefs.getString("PropertyDetailJson", null)); } else { SharedPreferences mPrefs = PreferenceManager .getDefaultSharedPreferences(getActivity().getApplicationContext()); mPrefs.edit().putString("PropertyDetailJson", detailsJson.toString()).commit(); } try { ((HelveticaBold) view.findViewById(R.id.propertyTitle)) .setText(detailsJson.getString("property_title")); ((HelveticaBold) view.findViewById(R.id.projectName)) .setText(detailsJson.getString("project_name")); ((HelveticaBold) view.findViewById(R.id.Classification)) .setText(detailsJson.getString("property_classification")); ((HelveticaBold) view.findViewById(R.id.Tenure)) .setText(detailsJson.getString("tenure").replace("null", "-")); ((HelveticaBold) view.findViewById(R.id.propertyType)) .setText(detailsJson.getString("property_type")); } catch (Exception e) { Toast.makeText(getActivity(), e.getLocalizedMessage(), Toast.LENGTH_LONG).show(); } String floorArea = "-"; if (!detailsJson.getString("builtin_area").equals("null")) { floorArea = detailsJson.getString("builtin_area") + " sqft"; } ((HelveticaBold) view.findViewById(R.id.FloorArea)).setText(floorArea); ((HelveticaBold) view.findViewById(R.id.Address)).setText(detailsJson.getString("address")); ((HelveticaBold) view.findViewById(R.id.PostalCode)) .setText(detailsJson.getString("postal_code").replace("null", "-")); String bedRoom = detailsJson.getString("bedrooms"); String bathRoom = detailsJson.getString("bathroom"); ((HelveticaBold) view.findViewById(R.id.Bedrooms)) .setText(bedRoom.equals("null") || bedRoom.equals("0") ? "-" : bedRoom); ((HelveticaBold) view.findViewById(R.id.Bathrooms)) .setText(bathRoom.equals("null") || bathRoom.equals("0") ? "-" : bathRoom); String psf = detailsJson.getString("psf"); psf = psf.equals("null") || psf.equals("0") ? "-" : "SGD " + psf; ((HelveticaBold) view.findViewById(R.id.Psf)).setText(psf); String district = detailsJson.get("property_district").toString(); String estate = detailsJson.get("property_estate").toString(); if (!estate.equals("")) { district = estate; } ((HelveticaBold) view.findViewById(R.id.district)).setText(district); price = detailsJson.getString("price").replace("null", ""); price = price.equals("") || price.equalsIgnoreCase("price on ask") ? price : "SGD " + SharedFunction.getPriceWithComma(detailsJson.getString("price")); view.findViewById(R.id.PSFDetailLayout).setVisibility(psf.equals("-") ? View.GONE : View.VISIBLE); if (price.equals("")) { ((LinearLayout) view.findViewById(R.id.PriceLayout)).setVisibility(View.GONE); ((LinearLayout) view.findViewById(R.id.PSFDetailLayout)).setVisibility(View.GONE); } else { ((HelveticaBold) view.findViewById(R.id.Price)).setText(price); } ((HelveticaBold) view.findViewById(R.id.Psf)).setText(psf); title = detailsJson.getString("property_title"); prurl = detailsJson.getString("url"); JSONObject sellerJson = detailsJson.getJSONObject("seller_info"); String registerNoStr = sellerJson.getString("agent_cea_reg_no").replace("null", "-"); String licenceNoStr = sellerJson.getString("agent_cea_license_no").replace("null", "-"); String agentImageUrl = sellerJson.getString("agent_image"); agentEmail = sellerJson.getString("agent_email"); mobileNoStr = sellerJson.getString("agent_mobile"); ((HelveticaBold) view.findViewById(R.id.AgentName)) .setText("Agent Name : " + sellerJson.getString("agent_name")); ((HelveticaBold) view.findViewById(R.id.AgentMobile)).setText(sellerJson.getString("agent_mobile")); ((HelveticaBold) view.findViewById(R.id.RegisterNo)).setText(registerNoStr); ((HelveticaBold) view.findViewById(R.id.LicenceNo)).setText(licenceNoStr); ((HelveticaBold) view.findViewById(R.id.agentEmail)).setText(sellerJson.getString("agent_email")); ((HelveticaBold) view.findViewById(R.id.Agency)).setText(sellerJson.getString("agency_name")); imageLoader.displayImage(agentImageUrl, (ImageView) view.findViewById(R.id.AgentImage)); if (detailsJson.getString("property_for").equalsIgnoreCase("for sale") && !price.equalsIgnoreCase("price on ask") && !price.equalsIgnoreCase("")) { ((Button) view.findViewById(R.id.LoanCalculator)).setOnClickListener(onClick); } else { ((Button) view.findViewById(R.id.LoanCalculator)) .setBackgroundResource(R.drawable.green_btn_disables); ((Button) view.findViewById(R.id.LoanCalculator)).getBackground().setAlpha(128); } final TextView imageCount = (TextView) view.findViewById(R.id.imageCount); view.findViewById(R.id.AgentMobile).setOnClickListener(onClick); view.findViewById(R.id.SendEmailBtn).setOnClickListener(onClick); view.findViewById(R.id.SendEnquiryBtn).setOnClickListener(onClick); ViewPager pager = (ViewPager) view.findViewById(R.id.pager); PhotoGallery gallery = new PhotoGallery(); pager.setAdapter(gallery); JSONArray galery = detailsJson.getJSONArray("photos"); final String[] photosArray = new String[galery.length()]; imageCount.setText("1/" + photosArray.length); for (int index = 0; index < galery.length(); index++) { View imageLoading = inflater.inflate(R.layout.image_with_loading, null); ImageView image = (ImageView) imageLoading.findViewById(R.id.galleryPhoto); photosArray[index] = galery.getString(index).replace("_S.", "_L."); imageLoader.displayImage(galery.getString(index).replace("_S.", "_L."), image); final int curIndex = index; imageLoading.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_DOWN) { projectDetailScrollView.requestDisallowInterceptTouchEvent(true); } else if (event.getAction() == MotionEvent.ACTION_UP) { projectDetailScrollView.requestDisallowInterceptTouchEvent(false); } return false; } }); imageLoading.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent galleryIntent = new Intent(getActivity(), Photos.class); galleryIntent.putExtra("photos1", photosArray); galleryIntent.putExtra("selected", curIndex); startActivity(galleryIntent); } }); gallery.addView(imageLoading); } pager.setOnPageChangeListener(new OnPageChangeListener() { @Override public void onPageSelected(int arg0) { imageCount.setText((arg0 + 1) + "/" + photosArray.length); } @Override public void onPageScrolled(int arg0, float arg1, int arg2) { // Auto-generated method stub } @Override public void onPageScrollStateChanged(int arg0) { // Auto-generated method stub } }); gallery.notifyDataSetChanged(); view.findViewById(R.id.BedBathLayout).setVisibility( Arrays.asList(Constants.RESIDENTIAL_TYPE).contains(detailsJson.getString("property_type")) ? View.VISIBLE : View.GONE); } catch (Exception e) { Log.e(this.getClass().getSimpleName(), e.getLocalizedMessage(), e); } return view; }
From source file:cn.bvin.app.swiperefresh.OldSwipeRefreshLayout.java
@Override public boolean onTouchEvent(MotionEvent event) { final int action = event.getAction(); boolean handled = false; switch (action) { case MotionEvent.ACTION_DOWN: mCurrPercentage = 0;//from ww w . j av a 2 s . c o m mDownEvent = MotionEvent.obtain(event); mPrevY = mDownEvent.getY(); break; case MotionEvent.ACTION_MOVE: if (mDownEvent != null && !mReturningToStart) { final float eventY = event.getY(); float yDiff = eventY - mDownEvent.getY(); if (yDiff > mTouchSlop) {//? // User velocity passed min velocity; trigger a refresh if (yDiff > mDistanceToTriggerSync) {//?? // User movement passed distance; trigger a refresh startRefresh(); handled = true; break; } else { // Just track the user's movement setTriggerPercentage( mAccelerateInterpolator.getInterpolation(yDiff / mDistanceToTriggerSync)); float offsetTop = yDiff; if (mPrevY > eventY) { offsetTop = yDiff - mTouchSlop; } //content???? updateContentOffsetTop((int) (offsetTop * mResistance)); if (mPrevY > eventY && (mTarget.getTop() < mTouchSlop)) { // If the user puts the view back at the top, we // don't need to. This shouldn't be considered // cancelling the gesture as the user can restart from the top. removeCallbacks(mCancel); } else { updatePositionTimeout(); } mPrevY = event.getY(); handled = true; } } } break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (mDownEvent != null) { mDownEvent.recycle(); mDownEvent = null; } break; } return handled; }
From source file:com.aretha.slidemenu.SlideMenu.java
@Override public boolean onTouchEvent(MotionEvent event) { super.onTouchEvent(event); final float x = event.getX(); final float y = event.getY(); final int currentState = mCurrentState; final boolean isTapContent = mIsTapContent; mVelocityTracker.addMovement(event); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mPressedX = mLastMotionX = x;/*w w w . j a va 2 s . c om*/ mIsTapContent = isTapContent(x, y); if (mIsTapContent) { mScroller.abortAnimation(); } mVelocityTracker = VelocityTracker.obtain(); break; case MotionEvent.ACTION_MOVE: if (Math.abs(x - mPressedX) >= mTouchSlop && isTapContent && currentState != STATE_DRAG) { setCurrentState(STATE_DRAG); } if (STATE_DRAG != currentState) { mLastMotionX = x; return false; } drag(mLastMotionX, x); mLastMotionX = x; break; case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: case MotionEvent.ACTION_OUTSIDE: if (STATE_DRAG == currentState) { mVelocityTracker.computeCurrentVelocity(1000); endDrag(x, mVelocityTracker.getXVelocity()); } else if (isTapContent) { performContentClick(); } mVelocityTracker.recycle(); mIsTapContent = false; break; } return true; }
From source file:com.pursuer.reader.easyrss.VerticalSingleItemView.java
@Override public boolean onTouch(final View view, final MotionEvent event) { final int action = event.getAction(); if (action == MotionEvent.ACTION_CANCEL) { showTop = false;// w ww . j a v a 2 s . co m showBottom = false; } else if (action == MotionEvent.ACTION_UP) { if (showTop) { if (listener != null && lastUid != null) { listener.showLastItem(); } } else if (showBottom) { if (listener != null && nextUid != null) { listener.showNextItem(); } } showTop = false; showBottom = false; } return false; }
From source file:com.VVTeam.ManHood.Fragment.HistogramFragment.java
private void initViews(View view) { parentLayout = (RelativeLayout) view.findViewById(R.id.fragment_histogram_parent_relative_layout); /*BitmapFactory.Options options = new BitmapFactory.Options(); options.inSampleSize = 2;/*from ww w . j a v a2 s . co m*/ parentLayout.setBackgroundDrawable(new BitmapDrawable(BitmapFactory.decodeResource(getResources(), R.drawable.histogram_bg, options)));*/ settingsRelative = (RelativeLayout) view.findViewById(R.id.fragment_histogram_settings_relative_layout); markRelative = (RelativeLayout) view.findViewById(R.id.fragment_histogram_mark_relative_layout); worldRelative = (RelativeLayout) view.findViewById(R.id.fragment_histogram_world_relative); // worldRelative.setSelected(true); worldRelative.setBackgroundResource(R.drawable.cell_p); areaRelative = (RelativeLayout) view.findViewById(R.id.fragment_histogram_area_relative); hoodRelative = (RelativeLayout) view.findViewById(R.id.fragment_histogram_hood_relative); yourResultButton = (Button) view.findViewById(R.id.fragment_histogram_your_result_button); contentRelative = (RelativeLayout) view.findViewById(R.id.fragment_histogram_content_relative); RelativeLayout shareRelative = (RelativeLayout) view .findViewById(R.id.fragment_histogram_share_button_relative); shareRelative.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub GoogleTracker.StarSendEvent(getActivity(), "ui_action", "user_action", "histogram_share"); Bitmap image = makeSnapshot(); File pictureFile = getOutputMediaFile(); try { FileOutputStream fos = new FileOutputStream(pictureFile); image.compress(Bitmap.CompressFormat.PNG, 90, fos); fos.close(); } catch (Exception e) { } // String pathofBmp = Images.Media.insertImage(getActivity().getContentResolver(), makeSnapshot(), "Man Hood App", null); // Uri bmpUri = Uri.parse(pathofBmp); Uri bmpUri = Uri.fromFile(pictureFile); final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); emailIntent.putExtra(Intent.EXTRA_STREAM, bmpUri); emailIntent.setType("image/png"); emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Man Hood App"); getActivity().startActivity(emailIntent); } }); polarPlot = (PolarPlot) view.findViewById(R.id.polarPlot); thicknessHisto = (Histogram) view.findViewById(R.id.thicknessHisto); thicknessHisto.setOrientation(ORIENT.LEFT); thicknessHisto.setBackgroundColor(Color.TRANSPARENT); lengthHisto = (Histogram) view.findViewById(R.id.lengthHistogram); lengthHisto.setOrientation(ORIENT.RIGHT); lengthHisto.setBackgroundColor(Color.TRANSPARENT); girthHisto = (Histogram) view.findViewById(R.id.girthHistogram); girthHisto.setOrientation(ORIENT.BOTTOM); girthHisto.setBackgroundColor(Color.TRANSPARENT); lengthHisto.setCallBackListener(new HistogramCallBack() { @Override public void setValueSelectionChangedBlock(Histogram histo, HistogramSelectionState selectionState, float value, HistogramBin bin) { // TODO Auto-generated method stub if (selectionState == HistogramSelectionState.HistogramSelectionStateSelected) { histogramSelected = true; setNearestUserID(usersData.userIDWithNearestLength(value)); setSelection(true, girthHisto, usersData.girthOfUserWithID(nearestUserID)); setSelection(true, thicknessHisto, usersData.thicknessOfUserWithID(nearestUserID)); // setSelection(false, lengthHisto, 0.0f); setSelection(true, lengthHisto, value); setupPolarPlotWithCurrentUserID(nearestUserID, usersData, selfUserData); } else if (selectionState == HistogramSelectionState.HistogramSelectionStateNotSelected) { histogramSelected = false; setNearestUserID(null); setSelectionForAverage(); setupPolarPlotWithCurrentUserID(nearestUserID, usersData, selfUserData); } else if (selectionState == HistogramSelectionState.HistogramSelectionStateDelayedFinish) { } } }); girthHisto.setCallBackListener(new HistogramCallBack() { @Override public void setValueSelectionChangedBlock(Histogram histo, HistogramSelectionState selectionState, float value, HistogramBin bin) { // TODO Auto-generated method stub if (selectionState == HistogramSelectionState.HistogramSelectionStateSelected) { histogramSelected = true; setNearestUserID(usersData.userIDWithNearestGirth(value)); setSelection(true, lengthHisto, usersData.lengthOfUserWithID(nearestUserID)); setSelection(true, thicknessHisto, usersData.thicknessOfUserWithID(nearestUserID)); // setSelection(false, girthHisto, 0.0f); setSelection(true, girthHisto, value); setupPolarPlotWithCurrentUserID(nearestUserID, usersData, selfUserData); } else if (selectionState == HistogramSelectionState.HistogramSelectionStateNotSelected) { histogramSelected = false; setNearestUserID(null); setSelectionForAverage(); setupPolarPlotWithCurrentUserID(nearestUserID, usersData, selfUserData); } else if (selectionState == HistogramSelectionState.HistogramSelectionStateDelayedFinish) { } } }); thicknessHisto.setCallBackListener(new HistogramCallBack() { @Override public void setValueSelectionChangedBlock(Histogram histo, HistogramSelectionState selectionState, float value, HistogramBin bin) { // TODO Auto-generated method stub if (selectionState == HistogramSelectionState.HistogramSelectionStateSelected) { histogramSelected = true; setNearestUserID(usersData.userIDWithNearestThickness(value)); setSelection(true, girthHisto, usersData.girthOfUserWithID(nearestUserID)); setSelection(true, lengthHisto, usersData.lengthOfUserWithID(nearestUserID)); // setSelection(false, thicknessHisto, 0.0f); setSelection(true, thicknessHisto, value); setupPolarPlotWithCurrentUserID(nearestUserID, usersData, selfUserData); } else if (selectionState == HistogramSelectionState.HistogramSelectionStateNotSelected) { histogramSelected = false; setNearestUserID(null); setSelectionForAverage(); setupPolarPlotWithCurrentUserID(nearestUserID, usersData, selfUserData); } else if (selectionState == HistogramSelectionState.HistogramSelectionStateDelayedFinish) { } } }); textBoxTitleLabel = (TextView) view.findViewById(R.id.txtBoxTitle); textBoxTitleLabel.setText("AVERAGE"); layoutSubTitle = (LinearLayout) view.findViewById(R.id.layoutSubTitle); layoutSubTitle.setVisibility(View.INVISIBLE); textBoxSubtitleLabel = (TextView) view.findViewById(R.id.txtBoxSubTitleLabel); textBoxSubtitleValueLabel = (TextView) view.findViewById(R.id.txtBoxSubTitleValue); lengthSelectedLabel = (TextView) view.findViewById(R.id.txtlengthselected); lengthSelectedLabel.setText("50%"); lengthTOPLabel = (TextView) view.findViewById(R.id.lengthTOPLabel); girthSelectedLabel = (TextView) view.findViewById(R.id.txtgirthselected); girthSelectedLabel.setText("50%"); girthTOPLabel = (TextView) view.findViewById(R.id.girthTOPLabel); thicknessSelectedLabel = (TextView) view.findViewById(R.id.txtthicknessselected); thicknessSelectedLabel.setText("50%"); thinkestAtTOPLabel = (TextView) view.findViewById(R.id.thinkestAtTOPLabel); curvedSelectedLabel = (TextView) view.findViewById(R.id.txtcurvedselected); curvedSelectedLabel.setText("0"); girthTopLB = (TextView) view.findViewById(R.id.girthTop); girthMiddleLB = (TextView) view.findViewById(R.id.girthMiddle); girthBottomLB = (TextView) view.findViewById(R.id.girthBottom); thicknessTopLB = (TextView) view.findViewById(R.id.thicknessTop); thicknessMiddleLB = (TextView) view.findViewById(R.id.thicknessMiddle); thicknessBottomLB = (TextView) view.findViewById(R.id.thicknessBottom); lengthTopLB = (TextView) view.findViewById(R.id.lengthTop); lengthMiddleLB = (TextView) view.findViewById(R.id.lengthMiddle); lengthBottomLB = (TextView) view.findViewById(R.id.lengthBottom); settingsRelative.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((MainActivity) getActivity()).openSettingsActivity(); } }); markRelative.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { ((MainActivity) getActivity()).openCertificateActivity(); } }); worldRelative.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setSelectedRange(SliceRange.SliceRangeAll); updateRangeSwitch(); } }); areaRelative.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setSelectedRange(SliceRange.SliceRange200); updateRangeSwitch(); } }); hoodRelative.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { setSelectedRange(SliceRange.SliceRange20); updateRangeSwitch(); } }); yourResultButton.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { // TODO Auto-generated method stub if (event.getAction() == MotionEvent.ACTION_DOWN) { youTouchDown(); } else if (event.getAction() == MotionEvent.ACTION_UP) { youTouchUp(); // final Handler handler = new Handler(); // handler.postDelayed(new Runnable() { // @Override // public void run() { // youTouchUp(); // } // }, 2000); } return true; } }); RequestManager.getInstance().checkUser(); /* in-app billing */ String base64EncodedPublicKey = LICENSE_KEY; // Create the helper, passing it our context and the public key to verify signatures with Log.d(TAG, "Creating IAB helper."); mHelper = new IabHelper(getActivity(), base64EncodedPublicKey); // enable debug logging (for a production application, you should set this to false). mHelper.enableDebugLogging(true); // Start setup. This is asynchronous and the specified listener // will be called once setup completes. Log.d(TAG, "Starting setup."); mHelper.startSetup(new IabHelper.OnIabSetupFinishedListener() { public void onIabSetupFinished(IabResult result) { Log.d(TAG, "Setup finished."); if (!result.isSuccess()) { // Oh noes, there was a problem. Log.d(TAG, "Problem setting up in-app billing: " + result); return; } // Have we been disposed of in the meantime? If so, quit. if (mHelper == null) return; // IAB is fully set up. Now, let's get an inventory of stuff we own. Log.d(TAG, "Setup successful. Querying inventory."); mHelper.queryInventoryAsync(mGotInventoryListener); } }); }
From source file:bk.vinhdo.taxiads.utils.view.SlidingLayer.java
@Override public boolean onTouchEvent(MotionEvent ev) { final int action = ev.getAction(); if (!mEnabled || !mIsDragging && !mLastTouchAllowed && !allowSlidingFromHereX(ev, mInitialX) && !allowSlidingFromHereY(ev, mInitialY)) { return false; }/*w w w. ja v a 2 s .c o m*/ if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_OUTSIDE) { mLastTouchAllowed = false; } else { mLastTouchAllowed = true; } if (mVelocityTracker == null) { mVelocityTracker = VelocityTracker.obtain(); } mVelocityTracker.addMovement(ev); switch (action & MotionEventCompat.ACTION_MASK) { case MotionEvent.ACTION_DOWN: completeScroll(); // Remember where the motion event started mLastX = mInitialX = ev.getX(); mLastY = mInitialY = ev.getY(); mActivePointerId = MotionEventCompat.getPointerId(ev, 0); break; case MotionEvent.ACTION_MOVE: if (!mIsDragging) { final int pointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (pointerIndex == -1) { mActivePointerId = INVALID_POINTER; break; } final float x = MotionEventCompat.getX(ev, pointerIndex); final float xDiff = Math.abs(x - mLastX); final float y = MotionEventCompat.getY(ev, pointerIndex); final float yDiff = Math.abs(y - mLastY); if (xDiff > mTouchSlop && xDiff > yDiff) { mIsDragging = true; mLastX = x; setDrawingCacheEnabled(true); } else if (yDiff > mTouchSlop && yDiff > xDiff) { mIsDragging = true; mLastY = y; setDrawingCacheEnabled(true); } } if (mIsDragging) { // Scroll to follow the motion event final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); if (activePointerIndex == -1) { mActivePointerId = INVALID_POINTER; break; } final float x = MotionEventCompat.getX(ev, activePointerIndex); final float y = MotionEventCompat.getY(ev, activePointerIndex); if (mOnInteractListener != null) { mOnInteractListener.onActionMove(x, y); } final float deltaX = mLastX - x; final float deltaY = mLastY - y; mLastX = x; mLastY = y; final float oldScrollX = getScrollX(); final float oldScrollY = getScrollY(); float scrollX = oldScrollX + deltaX; float scrollY = oldScrollY + deltaY; // Log.d("Layer", String.format("Layer scrollX[%f],scrollY[%f]", // scrollX, scrollY)); final float leftBound, rightBound; final float bottomBound, topBound; switch (mScreenSide) { case STICK_TO_LEFT: topBound = bottomBound = rightBound = 0; leftBound = getWidth(); // How far left we can scroll break; case STICK_TO_MIDDLE: topBound = getHeight(); bottomBound = -getHeight(); leftBound = getWidth(); rightBound = -getWidth(); break; case STICK_TO_RIGHT: rightBound = -getWidth(); topBound = bottomBound = leftBound = 0; break; case STICK_TO_TOP: topBound = getHeight(); bottomBound = rightBound = leftBound = 0; break; case STICK_TO_BOTTOM: topBound = rightBound = leftBound = 0; bottomBound = -getHeight(); break; default: topBound = bottomBound = rightBound = leftBound = 0; break; } if (scrollX > leftBound) { scrollX = leftBound; } else if (scrollX < rightBound) { scrollX = rightBound; } if (scrollY > topBound) { scrollY = topBound; } else if (scrollY < bottomBound) { scrollY = bottomBound; } // TODO top/bottom bounds // Keep the precision mLastX += scrollX - (int) scrollX; mLastY += scrollY - (int) scrollY; scrollTo((int) scrollX, (int) scrollY); } break; case MotionEvent.ACTION_UP: if (mIsDragging) { final VelocityTracker velocityTracker = mVelocityTracker; velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); final int initialVelocityX = (int) VelocityTrackerCompat.getXVelocity(velocityTracker, mActivePointerId); final int initialVelocityY = (int) VelocityTrackerCompat.getYVelocity(velocityTracker, mActivePointerId); final int scrollX = getScrollX(); final int scrollY = getScrollY(); final int activePointerIndex = MotionEventCompat.findPointerIndex(ev, mActivePointerId); final float x = MotionEventCompat.getX(ev, activePointerIndex); final float y = MotionEventCompat.getY(ev, activePointerIndex); final int totalDeltaX = (int) (x - mInitialX); final int totalDeltaY = (int) (y - mInitialY); boolean nextStateOpened = determineNextStateOpened(mIsOpen, scrollX, scrollY, initialVelocityX, initialVelocityY, totalDeltaX, totalDeltaY); boolean isControlled = false; if (isControlled) { break; } switchLayer(nextStateOpened, true, true, initialVelocityX, initialVelocityY); mActivePointerId = INVALID_POINTER; Log.d("", "end drag from action up"); endDrag(); } else if (mIsOpen && closeOnTapEnabled) { closeLayer(true); } else if (!mIsOpen && openOnTapEnabled) { openLayer(true); } break; case MotionEvent.ACTION_CANCEL: if (mIsDragging) { switchLayer(mIsOpen, true, true); mActivePointerId = INVALID_POINTER; Log.d(TAG, "end drag from action cancel"); endDrag(); } break; case MotionEventCompat.ACTION_POINTER_DOWN: { final int index = MotionEventCompat.getActionIndex(ev); mLastX = MotionEventCompat.getX(ev, index); mLastY = MotionEventCompat.getY(ev, index); mActivePointerId = MotionEventCompat.getPointerId(ev, index); break; } case MotionEventCompat.ACTION_POINTER_UP: onSecondaryPointerUp(ev); mLastX = MotionEventCompat.getX(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); mLastY = MotionEventCompat.getY(ev, MotionEventCompat.findPointerIndex(ev, mActivePointerId)); break; } if (mActivePointerId == INVALID_POINTER) { mLastTouchAllowed = false; } return true; }
From source file:com.android.widget.SlidingPaneLayout.java
@Override public boolean onInterceptTouchEvent(MotionEvent ev) { final int action = MotionEventCompat.getActionMasked(ev); if (!mCanSlide || (mIsUnableToDrag && action != MotionEvent.ACTION_DOWN)) { mDragHelper.cancel();/*from w ww.ja v a 2 s .co m*/ return super.onInterceptTouchEvent(ev); } if (action == MotionEvent.ACTION_CANCEL || action == MotionEvent.ACTION_UP) { mDragHelper.cancel(); return false; } float x, y; switch (action) { case MotionEvent.ACTION_DOWN: mIsUnableToDrag = false; x = ev.getX(); y = ev.getY(); mInitialMotionX = x; mInitialMotionY = y; break; case MotionEvent.ACTION_MOVE: x = ev.getX(); y = ev.getY(); final float adx = Math.abs(x - mInitialMotionX); final float ady = Math.abs(y - mInitialMotionY); final int slop = mDragHelper.getTouchSlop(); if (ady > slop && adx > ady) { mDragHelper.cancel(); mIsUnableToDrag = true; return false; } } final boolean interceptForDrag = mDragHelper.shouldInterceptTouchEvent(ev) // Intercept touch events only in the overhang area. && (ev.getY() <= mSlideOffset * mSlideRange + mOverhangSize && mState != STATE_OPENED_ENTIRELY); return interceptForDrag; }