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:cn.bingoogolapple.refreshlayout.BGAStickyNavLayout.java
@Override public boolean onTouchEvent(MotionEvent event) { initVelocityTrackerIfNotExists();/*from w ww . ja v a 2 s .c o m*/ mVelocityTracker.addMovement(event); float currentTouchY = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: if (!mOverScroller.isFinished()) { mOverScroller.abortAnimation(); } mLastTouchY = currentTouchY; break; case MotionEvent.ACTION_MOVE: float differentY = currentTouchY - mLastTouchY; mLastTouchY = currentTouchY; if (Math.abs(differentY) > 0) { scrollBy(0, (int) -differentY); } break; case MotionEvent.ACTION_CANCEL: recycleVelocityTracker(); if (!mOverScroller.isFinished()) { mOverScroller.abortAnimation(); } break; case MotionEvent.ACTION_UP: mVelocityTracker.computeCurrentVelocity(1000, mMaximumVelocity); int initialVelocity = (int) mVelocityTracker.getYVelocity(); if ((Math.abs(initialVelocity) > mMinimumVelocity)) { fling(-initialVelocity); } recycleVelocityTracker(); break; } return true; }
From source file:com.danielme.android.webviewdemo.WebViewDemoActivity.java
@SuppressLint({ "SetJavaScriptEnabled", "NewApi" }) @Override/*from ww w.jav 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:com.ibuildapp.romanblack.WebPlugin.WebPlugin.java
@Override public void create() { try {/* w w w . j a va 2s . c om*/ 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:cl.monsoon.s1next.widget.PhotoView.java
@Override public boolean onTouchEvent(@NonNull MotionEvent event) { if (scaleGestureDetector == null || mGestureDetector == null) { // We're being destroyed; ignore any touch events return true; }// w w w .j a va 2 s. c o m scaleGestureDetector.onTouchEvent(event); mGestureDetector.onTouchEvent(event); final int action = event.getAction(); switch (action) { case MotionEvent.ACTION_UP: case MotionEvent.ACTION_CANCEL: if (!mTranslateRunnable.mRunning) { snap(); } break; } return true; }
From source file:com.anjuke.library.uicomponent.photo.EndlessCircleIndicator.java
public boolean onTouchEvent(android.view.MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }//from w ww .j av a 2 s . c o m if ((mViewPager == null) || (mCount == 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 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 < mCount - 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.appeaser.sublimepickerlibrary.datepicker.DayPickerViewPager.java
@Override public boolean onTouchEvent(MotionEvent ev) { if (!mCanPickRange) { return super.onTouchEvent(ev); }//w ww.j av a2s. com // looks like the ViewPager wants to step in if (mCheckForLongPress != null) { removeCallbacks(mCheckForLongPress); } if (mIsLongPressed && ev.getAction() == MotionEvent.ACTION_UP || ev.getAction() == MotionEvent.ACTION_CANCEL) { if (Config.DEBUG) { Log.i(TAG, "OTE: LONGPRESS && (UP || CANCEL)"); } if (ev.getAction() == MotionEvent.ACTION_UP) { if (mDayPickerPagerAdapter != null) { mTempSelectedDate = mDayPickerPagerAdapter.resolveEndDateForRange((int) ev.getX(), (int) ev.getY(), getCurrentItem(), false); mDayPickerPagerAdapter.onDateRangeSelectionEnded(mTempSelectedDate); } } mIsLongPressed = false; mInitialDownX = -1; mInitialDownY = -1; mScrollingDirection = NOT_SCROLLING; if (mScrollerRunnable != null) { removeCallbacks(mScrollerRunnable); } //return true; } else if (mIsLongPressed && ev.getAction() == MotionEvent.ACTION_DOWN) { if (Config.DEBUG) { Log.i(TAG, "OTE: LONGPRESS && DOWN"); } mScrollingDirection = NOT_SCROLLING; } else if (mIsLongPressed && ev.getAction() == MotionEvent.ACTION_MOVE) { if (Config.DEBUG) { Log.i(TAG, "OTE: LONGPRESS && MOVE"); } int direction = resolveDirectionForScroll(ev.getX()); boolean directionChanged = mScrollingDirection != direction; if (directionChanged) { if (mScrollerRunnable != null) { removeCallbacks(mScrollerRunnable); } } if (mScrollerRunnable == null) { mScrollerRunnable = new ScrollerRunnable(); } mScrollingDirection = direction; if (mScrollingDirection == NOT_SCROLLING) { if (mDayPickerPagerAdapter != null) { mTempSelectedDate = mDayPickerPagerAdapter.resolveEndDateForRange((int) ev.getX(), (int) ev.getY(), getCurrentItem(), true); if (mTempSelectedDate != null) { mDayPickerPagerAdapter.onDateRangeSelectionUpdated(mTempSelectedDate); } } } else if (directionChanged) { // SCROLLING_LEFT || SCROLLING_RIGHT post(mScrollerRunnable); } } return mIsLongPressed || super.onTouchEvent(ev); }
From source file:app.clirnet.com.clirnetapp.activity.LoginActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); Fabric.with(this, new Crashlytics()); setContentView(R.layout.activity_login); ButterKnife.inject(this); try {//ww w .j av a 2 s . c o m /*message from fcm service*/ msg = getIntent().getStringExtra("MSG"); type = getIntent().getStringExtra("TYPE"); actionPath = getIntent().getStringExtra("ACTION_PATH"); headerMsg = getIntent().getStringExtra("HEADER"); clubbingFlag = getIntent().getStringExtra("CLUBBINGFLAG"); notificationTreySize = getIntent().getIntExtra("NOTIFITREYSIZE", 0); // Log.e("Loginmsg", " " + msg + " header " + headerMsg + " " +type + " "+actionPath); /*Clearing notifications ArrayList from MyFirebaseMessagingService after clicking on it*/ MyFirebaseMessagingService.notifications.clear(); // FirebaseCrash.setCrashCollectionEnabled(false); } catch (Exception e) { appController.appendLog(appController.getDateTime() + "" + "/" + "Navigation Activity" + e + " Line Number: " + Thread.currentThread().getStackTrace()[2].getLineNumber()); } TextView btnLinkToForgetScreen = (TextView) findViewById(R.id.btnLinkToForgetScreen); DatabaseClass databaseClass = new DatabaseClass(getApplicationContext()); bannerClass = new BannerClass(getApplicationContext()); LastnameDatabaseClass lastnameDatabaseClass = new LastnameDatabaseClass(getApplicationContext()); dbController = SQLiteHandler.getInstance(getApplicationContext()); appController = new AppController(); if (md5 == null) { md5 = new MD5(); } //getCurrentDob(21); //getCurrentDob(10); //this will set value to run asynctask only once per login session new CallAsynOnce().setValue("1");//this set value which helps to call asyntask only once while app is running. // Progress dialog connectionDetector = new ConnectionDetector(getApplicationContext()); try { sInstance = SQLiteHandler.getInstance(getApplicationContext()); if (sqlController == null) { sqlController = new SQLController(getApplicationContext()); sqlController.open(); } // sInstance = SQLiteHandler.getInstance(getApplicationContext()); Boolean value = getFirstTimeLoginStatus(); if (value) { phoneNumber = sqlController.getPhoneNumber(); doctor_membership_number = sqlController.getDoctorMembershipIdNew(); docId = sqlController.getDoctorId(); } } catch (Exception e) { e.printStackTrace(); appController.appendLog(appController.getDateTimenew() + " " + "/ " + "Login Page" + e + " Line Number: " + Thread.currentThread().getStackTrace()[2].getLineNumber()); } try { databaseClass.createDataBase(); bannerClass.createDataBase(); } catch (Exception ioe) { appController.appendLog(appController.getDateTimenew() + "" + "/" + "Login Page" + ioe + " Line Number: " + Thread.currentThread().getStackTrace()[2].getLineNumber()); throw new Error("Unable to create database"); } try { databaseClass.openDataBase(); bannerClass.openDataBase(); /*This AsyncTask will Insert data from Asset folder file to data 23-03-2016*/ new InsertDataLocally().execute(); } catch (Exception e) { e.printStackTrace(); appController.appendLog(appController.getDateTimenew() + "" + "/" + "Login Page" + e + " Line Number: " + Thread.currentThread().getStackTrace()[2].getLineNumber()); } finally { databaseClass.close(); } try { lastnameDatabaseClass.createDataBase(); } catch (IOException e) { appController.appendLog(appController.getDateTimenew() + "" + "/" + "Login Page" + e + " Line Number: " + Thread.currentThread().getStackTrace()[2].getLineNumber()); throw new Error("Unable to create database"); } try { lastnameDatabaseClass.openDataBase(); getUsernamePasswordFromDatabase(); } catch (Exception e) { e.printStackTrace(); appController.appendLog(appController.getDateTimenew() + "" + "/" + "Login Page" + e + " Line Number: " + Thread.currentThread().getStackTrace()[2].getLineNumber()); } finally { lastnameDatabaseClass.close(); } btnLogin.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View view, MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { hideKeyBoard(); btnLogin.setBackground(getResources().getDrawable(R.drawable.rounded_corner_withbackground)); name = inputEmail.getText().toString().trim(); strPassword = inputPassword.getText().toString().trim(); String time = appController.getDateTimenew(); AppController.getInstance().trackEvent("Login", "Login Pressed"); //This code used for Remember Me(ie. save login id and password for future ref.) rememberMe(name, strPassword, time); //save username only //rememberMeCheckbox();//Removed remeber me check box for safety concern 04-11-16 //to authenticate user credentials //Log.e("name",""+name +" savedUserName "+savedUserName+ " phoneNumber "+phoneNumber); //if(name.equals(savedUserName) || name.equals(phoneNumber)) LoginAuthentication(); // else appController.showToastMsg(getApplicationContext(),"This username is not licensed to log into this device. Please check username"); } else if (event.getAction() == MotionEvent.ACTION_DOWN) { btnLogin.setBackground( getResources().getDrawable(R.drawable.rounded_corner_withbackground_blue)); } return false; } }); /*We are updating visit date format*/ // updateVisitDateFormat(); //Commented on 10-05-2017 addVitalsIntoInvstigation(); //Commented on 10-05-2017 /* Updateing banner stats flag to 0 build no 1.3+ */ /*Updating associate master flag from 1 to 0*/ String bannerUpdateFlag = getupdateBannerClickVisitFlag0(); if (bannerUpdateFlag == null || bannerUpdateFlag.equals("true")) { updateBannerTableDataFlag(); } // Link to Register Screen btnLinkToForgetScreen.setOnClickListener(new View.OnClickListener() { public void onClick(View view) { boolean isInternetPresent = connectionDetector.isConnectingToInternet(); if (isInternetPresent) { showChangePassDialog(); } else { appController.showToastMsg(getApplicationContext(), "Please Connect To Internet And Try Again!"); } } }); if (checkAndRequestPermissions()) { // carry on the normal flow, as the case of permissions granted. } }
From source file:com.android.nobug.view.viewpager.indicator.CirclePageIndicator.java
public boolean onTouchEvent(MotionEvent ev) { if (super.onTouchEvent(ev)) { return true; }//from www . j a v a 2s . c om 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.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 ww .j a va 2s .com 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; }
From source file:com.thousandthoughts.tutorials.SensorFusionActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main);/*from w w w .ja v a 2 s. co 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; } }); }