List of usage examples for android.view GestureDetector GestureDetector
public GestureDetector(Context context, OnGestureListener listener)
From source file:com.caro.smartmodule.viewComponent.viewpagers.SmartViewPager.java
private void setup() { final GestureDetector tapGestureDetector = new GestureDetector(getContext(), new TapGestureListener()); setOnTouchListener(new OnTouchListener() { @Override/* w w w. ja va 2 s .c om*/ public boolean onTouch(View v, MotionEvent event) { tapGestureDetector.onTouchEvent(event); return false; } }); }
From source file:xiaofan.llongimageview.view.SubsamplingScaleImageView.java
private void setGestureDetector(final Context context) { this.detector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Override//from w w w . j a v a 2 s .c o m public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (panEnabled && readySent && vTranslate != null && e1 != null && e2 != null && (Math.abs(e1.getX() - e2.getX()) > 50 || Math.abs(e1.getY() - e2.getY()) > 50) && (Math.abs(velocityX) > 500 || Math.abs(velocityY) > 500) && !isZooming) { PointF vTranslateEnd = new PointF(vTranslate.x + (velocityX * 0.25f), vTranslate.y + (velocityY * 0.25f)); float sCenterXEnd = ((getWidth() / 2) - vTranslateEnd.x) / scale; float sCenterYEnd = ((getHeight() / 2) - vTranslateEnd.y) / scale; new AnimationBuilder(new PointF(sCenterXEnd, sCenterYEnd)).withEasing(EASE_OUT_QUAD) .withPanLimited(false).start(); return true; } return super.onFling(e1, e2, velocityX, velocityY); } @Override public boolean onSingleTapConfirmed(MotionEvent e) { performClick(); return true; } @Override public boolean onDoubleTap(MotionEvent e) { if (zoomEnabled && readySent && vTranslate != null) { float doubleTapZoomScale = Math.min(maxScale, SubsamplingScaleImageView.this.doubleTapZoomScale); boolean zoomIn = scale <= doubleTapZoomScale * 0.9; float targetScale = zoomIn ? doubleTapZoomScale : Math.min(getWidth() / (float) sWidth(), getHeight() / (float) sHeight()); PointF targetSCenter = viewToSourceCoord(new PointF(e.getX(), e.getY())); if (doubleTapZoomStyle == ZOOM_FOCUS_CENTER_IMMEDIATE) { setScaleAndCenter(targetScale, targetSCenter); } else if (doubleTapZoomStyle == ZOOM_FOCUS_CENTER || !zoomIn) { new AnimationBuilder(targetScale, targetSCenter).withInterruptible(false).start(); } else if (doubleTapZoomStyle == ZOOM_FOCUS_FIXED) { new AnimationBuilder(targetScale, targetSCenter, new PointF(e.getX(), e.getY())) .withInterruptible(false).start(); } // Hacky solution for #15 - after a double tap the GestureDetector gets in a state where the next // fling is ignored, so here we replace it with a new one. setGestureDetector(context); invalidate(); return true; } return super.onDoubleTapEvent(e); } }); }
From source file:org.botlibre.sdk.activity.ChatActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_chat); // Remove flag button if a single bot app. if (MainActivity.launchType == LaunchType.Bot) { //findViewById(R.id.flagButton).setVisibility(View.GONE); }//from w ww . j a v a2s.c o m //permission required. ActivityCompat.requestPermissions(ChatActivity.this, new String[] { Manifest.permission.RECORD_AUDIO }, 1); //set/Save the current volume from the device. setStreamVolume(); //Music Volume is Enabled. muteMicBeep(false); //For "scream" issue micLastStat = MainActivity.listenInBackground; getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); this.instance = (InstanceConfig) MainActivity.instance; if (this.instance == null) { return; } /*if (MainActivity.showAds) { AdView mAdView = (AdView) findViewById(R.id.adView); AdRequest adRequest = new AdRequest.Builder().build(); mAdView.loadAd(adRequest); } else { AdView mAdView = (AdView) findViewById(R.id.adView); mAdView.setVisibility(View.GONE); }*/ setTitle(this.instance.name); ((TextView) findViewById(R.id.title)).setText(this.instance.name); HttpGetImageAction.fetchImage(this, this.instance.avatar, findViewById(R.id.icon)); ttsInit = false; tts = new TextToSpeech(this, this); if (!MainActivity.handsFreeSpeech) { setMicIcon(false, false); } else if (!MainActivity.listenInBackground) { setMicIcon(false, false); } //Last time will be saved for the MIC. if (MainActivity.listenInBackground && MainActivity.handsFreeSpeech) { microphoneThread(thread); } speech = SpeechRecognizer.createSpeechRecognizer(this); speech.setRecognitionListener(this); //scrollVie added and stuff scrollView = findViewById(R.id.chatList); menuMLayout = (LinearLayout) findViewById(R.id.menuMLayout); chatCLayout = (LinearLayout) findViewById(R.id.chatCLayout); responseLayout = (LinearLayout) findViewById(R.id.responseLayout); chatToolBar = (LinearLayout) findViewById(R.id.chatToolBar); videoView = (VideoView) findViewById(R.id.videoView); resetVideoErrorListener(); videoError = false; imageView = (ImageView) findViewById(R.id.imageView); videoLayout = findViewById(R.id.videoLayout); textView = (EditText) findViewById(R.id.messageText); textView.setOnEditorActionListener(new OnEditorActionListener() { @Override public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { submitChat(); return false; } }); if (MainActivity.translate) { findViewById(R.id.yandex).setVisibility(View.VISIBLE); } else { findViewById(R.id.yandex).setVisibility(View.GONE); } Spinner emoteSpin = (Spinner) findViewById(R.id.emoteSpin); emoteSpin.setAdapter( new EmoteSpinAdapter(this, R.layout.emote_list, Arrays.asList(EmotionalState.values()))); ListView list = (ListView) findViewById(R.id.chatList); list.setAdapter(new ChatListAdapter(this, R.layout.chat_list, this.messages)); list.setTranscriptMode(ListView.TRANSCRIPT_MODE_ALWAYS_SCROLL); ImageButton button = (ImageButton) findViewById(R.id.speakButton); button.setOnClickListener(new View.OnClickListener() { @TargetApi(23) @Override public void onClick(View v) { if (MainActivity.handsFreeSpeech) { //set the current volume to the setting. setStreamVolume(); //if its ON Or OFF - Switching back and forth MainActivity.listenInBackground = !MainActivity.listenInBackground; //saving the boolean data of MainActivity.listeningInBackground SharedPreferences.Editor cookies = MainActivity.current.getPreferences(Context.MODE_PRIVATE) .edit(); cookies.putBoolean("listenInBackground", MainActivity.listenInBackground); cookies.commit(); if (MainActivity.listenInBackground) { micLastStat = true; try { microphoneThread(thread); } catch (Exception ignore) { } beginListening(); } else { micLastStat = false; microphoneThread(thread); stopListening(); } } else { Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH); intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, MainActivity.voice.language); try { startActivityForResult(intent, RESULT_SPEECH); textView.setText(""); } catch (ActivityNotFoundException a) { Toast t = Toast.makeText(getApplicationContext(), "Your device doesn't support Speech to Text", Toast.LENGTH_SHORT); t.show(); } } } }); //adding functionality on clicking the image imageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (stateLayouts == 4) { stateLayouts = 0; } switch (stateLayouts) { case 0: scrollView.setVisibility(View.VISIBLE); chatCLayout.setVisibility(View.VISIBLE); menuMLayout.setVisibility(View.VISIBLE); responseLayout.setVisibility(View.VISIBLE); chatToolBar.setVisibility(View.VISIBLE); break; case 1: scrollView.setVisibility(View.GONE); break; case 2: responseLayout.setVisibility(View.GONE); chatToolBar.setVisibility(View.GONE); break; case 3: menuMLayout.setVisibility(View.GONE); chatCLayout.setVisibility(View.GONE); break; } stateLayouts++; } }); //adding functionality on clicking the image videoLayout.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (stateLayouts == 4) { stateLayouts = 0; } switch (stateLayouts) { case 0: scrollView.setVisibility(View.VISIBLE); chatCLayout.setVisibility(View.VISIBLE); menuMLayout.setVisibility(View.VISIBLE); responseLayout.setVisibility(View.VISIBLE); chatToolBar.setVisibility(View.VISIBLE); break; case 1: scrollView.setVisibility(View.GONE); break; case 2: responseLayout.setVisibility(View.GONE); chatToolBar.setVisibility(View.GONE); break; case 3: menuMLayout.setVisibility(View.GONE); chatCLayout.setVisibility(View.GONE); break; } stateLayouts++; } }); GestureDetector.SimpleOnGestureListener listener = new GestureDetector.SimpleOnGestureListener() { @Override public boolean onDoubleTapEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { boolean isVideo = !MainActivity.disableVideo && !videoError && response != null && response.isVideo(); View imageView = findViewById(R.id.imageView); View videoLayout = findViewById(R.id.videoLayout); if (imageView.getVisibility() == View.VISIBLE) { imageView.setVisibility(View.GONE); } else if (!isVideo) { imageView.setVisibility(View.VISIBLE); } if (videoLayout.getVisibility() == View.VISIBLE) { videoLayout.setVisibility(View.GONE); } else if (isVideo) { videoLayout.setVisibility(View.VISIBLE); } return true; } return false; } }; final GestureDetector detector = new GestureDetector(this, listener); findViewById(R.id.chatList).setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return detector.onTouchEvent(event); } }); listener = new GestureDetector.SimpleOnGestureListener() { @Override public boolean onDoubleTapEvent(MotionEvent event) { if (event.getAction() == MotionEvent.ACTION_UP) { View avatarLayout = findViewById(R.id.avatarLayout); if (avatarLayout.getVisibility() == View.VISIBLE) { avatarLayout.setVisibility(View.GONE); } else { avatarLayout.setVisibility(View.VISIBLE); } return true; } return false; } }; final GestureDetector detector2 = new GestureDetector(this, listener); /*findViewById(R.id.responseText).setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { return detector2.onTouchEvent(event); } });*/ WebView responseView = (WebView) findViewById(R.id.responseText); responseView.getSettings().setJavaScriptEnabled(true); responseView.getSettings().setDomStorageEnabled(true); responseView.addJavascriptInterface(new WebAppInterface(this), "Android"); findViewById(R.id.responseImageView).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { View avatarLayout = findViewById(R.id.avatarLayout); if (avatarLayout.getVisibility() == View.VISIBLE) { avatarLayout.setVisibility(View.GONE); } else { avatarLayout.setVisibility(View.VISIBLE); } } }); HttpGetImageAction.fetchImage(this, instance.avatar, this.imageView); HttpGetImageAction.fetchImage(this, instance.avatar, (ImageView) findViewById(R.id.responseImageView)); final ChatConfig config = new ChatConfig(); config.instance = instance.id; config.avatar = this.avatarId; if (MainActivity.translate && MainActivity.voice != null) { config.language = MainActivity.voice.language; } if (MainActivity.disableVideo) { config.avatarFormat = "image"; } else { config.avatarFormat = MainActivity.webm ? "webm" : "mp4"; } config.avatarHD = MainActivity.hd; config.speak = !MainActivity.deviceVoice; // This is required because of a bug in TextToSpeech that prevents onInit being called if an AsynchTask is called... Thread thread1 = new Thread() { public void run() { for (int count = 0; count < 5; count++) { if (ttsInit) { break; } try { Thread.sleep(1000); } catch (Exception exception) { } } HttpAction action = new HttpChatAction(ChatActivity.this, config); action.execute(); } }; thread1.start(); }
From source file:com.bizcom.vc.widget.cus.SubsamplingScaleImageView.java
private void setGestureDetector(final Context context) { this.detector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Override/*from w ww . j a va 2s .co m*/ public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { if (panEnabled && readySent && vTranslate != null && e1 != null && e2 != null && (Math.abs(e1.getX() - e2.getX()) > 50 || Math.abs(e1.getY() - e2.getY()) > 50) && (Math.abs(velocityX) > 500 || Math.abs(velocityY) > 500) && !isZooming) { PointF vTranslateEnd = new PointF(vTranslate.x + (velocityX * 0.25f), vTranslate.y + (velocityY * 0.25f)); float sCenterXEnd = ((getWidth() / 2) - vTranslateEnd.x) / scale; float sCenterYEnd = ((getHeight() / 2) - vTranslateEnd.y) / scale; new AnimationBuilder(new PointF(sCenterXEnd, sCenterYEnd)).withEasing(EASE_OUT_QUAD) .withPanLimited(false).start(); return true; } return super.onFling(e1, e2, velocityX, velocityY); } @Override public boolean onSingleTapConfirmed(MotionEvent e) { if (doubleTapListener != null) { return doubleTapListener.onSingleTapConfirmed(e); } performClick(); return true; } @Override public boolean onDoubleTap(MotionEvent e) { if (zoomEnabled && readySent && vTranslate != null) { float doubleTapZoomScale = Math.min(maxScale, SubsamplingScaleImageView.this.doubleTapZoomScale); boolean zoomIn = scale <= doubleTapZoomScale * 0.9; float targetScale = zoomIn ? doubleTapZoomScale : Math.min(getWidth() / (float) sWidth(), getHeight() / (float) sHeight()); PointF targetSCenter = viewToSourceCoord(new PointF(e.getX(), e.getY())); if (doubleTapZoomStyle == ZOOM_FOCUS_CENTER_IMMEDIATE) { setScaleAndCenter(targetScale, targetSCenter); } else if (doubleTapZoomStyle == ZOOM_FOCUS_CENTER || !zoomIn) { new AnimationBuilder(targetScale, targetSCenter).withInterruptible(false).start(); } else if (doubleTapZoomStyle == ZOOM_FOCUS_FIXED) { new AnimationBuilder(targetScale, targetSCenter, new PointF(e.getX(), e.getY())) .withInterruptible(false).start(); } // Hacky solution for #15 - after a double tap the // GestureDetector gets in a state where the next // fling is ignored, so here we replace it with a // new one. setGestureDetector(context); invalidate(); return true; } return super.onDoubleTapEvent(e); } }); }
From source file:net.zorgblub.typhon.fragment.ReadingFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); DisplayMetrics metrics = new DisplayMetrics(); AppCompatActivity activity = (AppCompatActivity) getActivity(); this.context = activity; activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); displayPageNumber(-1); // Initializes the pagenumber view properly final GestureDetector gestureDetector = new GestureDetector(context, new NavGestureDetector(bookView, this, metrics)); View.OnTouchListener gestureListener = (View v, MotionEvent event) -> !ttsIsRunning() && gestureDetector.onTouchEvent(event); this.viewSwitcher.setOnTouchListener(gestureListener); this.bookView.setOnTouchListener(gestureListener); this.dummyView.setOnTouchListener(gestureListener); registerForContextMenu(bookView);/*from ww w. j a va 2 s. c o m*/ saveConfigState(); Intent intent = activity.getIntent(); String file = null; if (intent.getData() != null) { file = intent.getData().getPath(); } if (file == null) { file = config.getLastOpenedFile(); } updateFromPrefs(); updateFileName(savedInstanceState, file); if ("".equals(fileName) || !new File(fileName).exists()) { LOG.info("Requested to open file " + fileName + ", which doesn't seem to exist. " + "Switching back to the library."); Intent newIntent = new Intent(context, LibraryActivity.class); startActivity(newIntent); activity.finish(); return; } else { if (savedInstanceState == null && config.isSyncEnabled()) { new DownloadProgressTask().execute(); } else { bookView.restore(); } } if (ttsIsRunning()) { this.mediaLayout.setVisibility(View.VISIBLE); this.ttsPlaybackItemQueue.updateSpeechCompletedCallbacks(this::speechCompleted); uiHandler.post(progressBarUpdater); } activity.getSupportActionBar().addOnMenuVisibilityListener(isVisible -> { LOG.debug("Detected change of visibility in action-bar: visible=" + isVisible); int visibility = isVisible ? View.VISIBLE : View.GONE; titleBarLayout.setVisibility(visibility); }); }
From source file:com.aujur.ebookreader.activity.ReadingFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); DisplayMetrics metrics = new DisplayMetrics(); SherlockFragmentActivity activity = getSherlockActivity(); activity.getWindowManager().getDefaultDisplay().getMetrics(metrics); displayPageNumber(-1); // Initializes the pagenumber view properly final GestureDetector gestureDetector = new GestureDetector(context, new NavGestureDetector(bookView, this, metrics)); View.OnTouchListener gestureListener = new View.OnTouchListener() { public boolean onTouch(View v, MotionEvent event) { if (ttsIsRunning()) { return false; }//w w w .j av a2s. c o m return gestureDetector.onTouchEvent(event); } }; this.viewSwitcher.setOnTouchListener(gestureListener); this.bookView.setOnTouchListener(gestureListener); this.dummyView.setOnTouchListener(gestureListener); registerForContextMenu(bookView); saveConfigState(); Intent intent = activity.getIntent(); String file = null; if (intent.getData() != null) { file = intent.getData().getPath(); } if (file == null) { file = config.getLastOpenedFile(); } updateFromPrefs(); updateFileName(savedInstanceState, file); if ("".equals(fileName) || !new File(fileName).exists()) { LOG.info("Requested to open file " + fileName + ", which doesn't seem to exist. " + "Switching back to the library."); Intent newIntent = new Intent(context, LibraryActivity.class); startActivity(newIntent); activity.finish(); return; } else { if (savedInstanceState == null && config.isSyncEnabled()) { new DownloadProgressTask().execute(); } else { bookView.restore(); } } if (ttsIsRunning()) { this.mediaLayout.setVisibility(View.VISIBLE); this.ttsPlaybackItemQueue.updateSpeechCompletedCallbacks(this); uiHandler.post(progressBarUpdater); } activity.getSupportActionBar().addOnMenuVisibilityListener(new ActionBar.OnMenuVisibilityListener() { @Override public void onMenuVisibilityChanged(boolean isVisible) { LOG.debug("Detected change of visibility in action-bar: visible=" + isVisible); if (isVisible) { titleBarLayout.setVisibility(View.VISIBLE); } else { titleBarLayout.setVisibility(View.GONE); } } }); /* * new ShakeListener(getActivity()).setOnShakeListener(new * ShakeListener.OnShakeListener() { * * @Override public void onShake() { if ( ! ttsIsRunning() ) { * startTextToSpeech(); } } }); */ }
From source file:xyz.zpayh.hdimage.HDImageView.java
private void setLongPress(Context context) { mLongPressDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Override//from w ww .j a va2s .c om public void onLongPress(MotionEvent e) { if (isLongClickable() && mOnLongClickListener != null) { mOnLongClickListener.onLongClick(HDImageView.this); } super.onLongPress(e); } }); }
From source file:com.wanikani.androidnotifier.graph.TYPlot.java
/** * Constructor/*from www .j ava 2 s.c o m*/ * @param ctxt the context * @param attrs the attributes */ public TYPlot(Context ctxt, AttributeSet attrs) { super(ctxt, attrs); scroller = new Scroller(ctxt); glist = new GestureListener(); gdect = new GestureDetector(ctxt, glist); datef = new SimpleDateFormat("MMM", Locale.US); janf = new SimpleDateFormat("MMM yyyy", Locale.US); taxis = new TimeAxis(); dsink = new DataSink(); loadAttributes(ctxt, attrs); }
From source file:com.example.view.wheel.WheelView.java
/** * Initializes class data//from ww w. j a va 2 s . c o m * @param context the context */ private void initData(Context context) { gestureDetector = new GestureDetector(context, gestureListener); gestureDetector.setIsLongpressEnabled(false); scroller = new Scroller(context); this.context = context; }
From source file:xyz.zpayh.hdimage.HDImageView.java
private void setClickGesture(Context context) { mClickDetector = new GestureDetector(context, new GestureDetector.SimpleOnGestureListener() { @Override/*from w w w .j av a 2 s . c o m*/ public boolean onSingleTapConfirmed(MotionEvent e) { if (BuildConfig.DEBUG) Log.d(TAG, "?"); performClick(); return true; } @Override public boolean onDoubleTap(MotionEvent e) { if (BuildConfig.DEBUG) Log.d(TAG, "?"); if (mZoomEnabled && mQuickScaleEnabled && mReadySent && mViewTranslate != null) { //???? setFilingGesture(getContext()); PointF sourceCenter = viewToSourceCoordinate(new PointF(e.getX(), e.getY())); PointF viewFocus = new PointF(e.getX(), e.getY()); startDoubleTapAnimator(sourceCenter, viewFocus); return true; } return false; } }); }