List of usage examples for android.view GestureDetector GestureDetector
public GestureDetector(Context context, OnGestureListener listener)
From source file:com.momock.binder.container.ViewPagerBinder.java
public void onBind(final ViewPager view, final IDataList<?> dataSource) { if (view != null) { if (refIndicator != null && refIndicator.get() != null) { refIndicator.get().setCount(dataSource.getItemCount()); }//from w w w .j a v a 2 s . c om view.setOnPageChangeListener(new ViewPager.OnPageChangeListener() { @Override public void onPageSelected(int position) { position = adapter instanceof IRoundAdapter ? ((IRoundAdapter) adapter).getRealPosition(position) : position; Object item = dataSource.getItem(position); ItemEventArgs args = new ItemEventArgs(view, position, item); itemSelectedEvent.fireEvent(view, args); if (refIndicator != null && refIndicator.get() != null) { refIndicator.get().setCurrentIndex(position); } } @Override public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } @Override public void onPageScrollStateChanged(int state) { viewPagerState = state; } }); view.setOnTouchListener(new View.OnTouchListener() { GestureDetector detector = null; @Override public boolean onTouch(View v, MotionEvent event) { view.getParent().requestDisallowInterceptTouchEvent(true); if (detector == null) { detector = new GestureDetector(v.getContext(), new GestureDetector.SimpleOnGestureListener() { @Override public boolean onSingleTapConfirmed(MotionEvent e) { Object item = dataSource.getItem(adapter instanceof IRoundAdapter ? ((IRoundAdapter) adapter).getRealPosition(view.getCurrentItem()) : view.getCurrentItem()); ItemEventArgs args = new ItemEventArgs(view, view.getCurrentItem(), item); itemClickedEvent.fireEvent(view, args); return true; } }); } return detector.onTouchEvent(event); } }); adapter = new PagerAdapter() { BlockingQueue<View> savedViews = new LinkedBlockingQueue<View>(); @Override public int getCount() { return dataSource.getItemCount(); } @Override public boolean isViewFromObject(View view, Object object) { return view == ((View) object); } @Override public Object instantiateItem(ViewGroup container, int position) { View convertView = null; if (savedViews.size() > 0) { convertView = savedViews.poll(); } Object item = dataSource.getItem(position); if (convertView != null) convertView.setTag(null); convertView = itemBinder.onCreateItemView(convertView, item, ViewPagerBinder.this); convertView.setTag(item); container.addView(convertView, 0); return convertView; } @Override public void destroyItem(ViewGroup container, int position, Object object) { savedViews.add((View) object); container.removeView((View) object); } long lastDataSetChangedTick = 0; @Override public void notifyDataSetChanged() { lastDataSetChangedTick = System.nanoTime(); getDataChangedEvent().fireEvent(this, new EventArgs()); if (refIndicator != null && refIndicator.get() != null) { refIndicator.get().setCount(dataSource.getItemCount()); } super.notifyDataSetChanged(); Logger.debug("ViewPagerBinder.PagerAdapter.notifyDataSetChanged"); } long updateTick = 0; @Override public void startUpdate(ViewGroup container) { updateTick = System.nanoTime(); super.startUpdate(container); } @Override public void setPrimaryItem(ViewGroup container, int position, Object object) { super.setPrimaryItem(container, position, object); } @Override public void finishUpdate(ViewGroup container) { super.finishUpdate(container); if (lastDataSetChangedTick < updateTick) lastDataSetChangedTick = 0; } @Override public int getItemPosition(Object object) { return lastDataSetChangedTick == 0 ? PagerAdapter.POSITION_UNCHANGED : PagerAdapter.POSITION_NONE; } }; if (round) adapter = new RoundPagerAdapter(adapter); view.setAdapter(adapter); dataSource.addDataChangedHandler(new IEventHandler<DataChangedEventArgs>() { @Override public void process(Object sender, DataChangedEventArgs args) { adapter.notifyDataSetChanged(); } }); if (round) view.setCurrentItem(Math.max(100, dataSource.getItemCount() * 100), false); } }
From source file:it.jaschke.alexandria.activities.BarcodeCaptureActivity.java
@Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.barcode_capture); mPreview = (CameraSourcePreview) findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay<BarcodeGraphic>) findViewById(R.id.graphicOverlay); boolean autoFocus = getIntent().getBooleanExtra(AutoFocus, false); boolean useFlash = getIntent().getBooleanExtra(UseFlash, false); int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA); if (rc == PackageManager.PERMISSION_GRANTED) { createCameraSource(autoFocus, useFlash); } else {//from w w w . ja v a 2 s. c o m requestCameraPermission(); } gestureDetector = new GestureDetector(this, new CaptureGestureListener()); scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener()); Snackbar.make(mGraphicOverlay, "Tap to capture. Pinch/Stretch to zoom", Snackbar.LENGTH_LONG).show(); }
From source file:com.drmidnight.materialtest.MainActivity.java
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); toolbar = (Toolbar) findViewById(R.id.tool_bar); setSupportActionBar(toolbar);/* w w w . j a va 2s .co m*/ mRecyclerView = (RecyclerView) findViewById(R.id.RecyclerView); // Assigning the RecyclerView Object to the xml View mRecyclerView.setHasFixedSize(true); // Letting the system know that the list objects are of fixed size mAdapter = new MyAdapter(TITLES, ICONS, TITLES2, ICONS2, TITLES3, ICONS3, SUBTITLES, NAME, EMAIL, PROFILE, this); // Creating the Adapter of MyAdapter class(which we are going to see in a bit) // And passing the titles,icons,header view name, header view email, // and header view profile picture mRecyclerView.setAdapter(mAdapter); // Setting the adapter to RecyclerView final GestureDetector mGestureDetector = new GestureDetector(MainActivity.this, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onSingleTapUp(MotionEvent e) { return true; } }); mRecyclerView.addOnItemTouchListener(new RecyclerView.OnItemTouchListener() { @Override public boolean onInterceptTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) { View child = recyclerView.findChildViewUnder(motionEvent.getX(), motionEvent.getY()); if (child != null && mGestureDetector.onTouchEvent(motionEvent)) { //Drawer.closeDrawers(); Toast.makeText(MainActivity.this, "The Item Clicked is: " + recyclerView.getChildPosition(child), Toast.LENGTH_SHORT) .show(); switch (recyclerView.getChildPosition(child)) { case 0: //This is the header break; case 1: Drawer.closeDrawers(); break; case 2: Drawer.closeDrawers(); Intent diningintent = new Intent(MainActivity.this, DiningActivity.class); startActivity(diningintent); break; case 3: Drawer.closeDrawers(); break; case 4: Drawer.closeDrawers(); break; case 5: Drawer.closeDrawers(); break; case 6: //This is a line break; case 7: //This is a subtitle break; case 8: Drawer.closeDrawers(); Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("https://my.ucsc.edu/psp/ep9prd/?cmd=login&languageCd=ENG")); if (browserIntent.resolveActivity(getPackageManager()) != null) { startActivity(browserIntent); } break; case 9: Drawer.closeDrawers(); Intent browserIntent2 = new Intent(Intent.ACTION_VIEW, Uri.parse("https://ecommons.ucsc.edu/portal/login")); if (browserIntent2.resolveActivity(getPackageManager()) != null) { startActivity(browserIntent2); } break; case 10: Drawer.closeDrawers(); Intent browserIntent3 = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("https://piazza.com/class")); if (browserIntent3.resolveActivity(getPackageManager()) != null) { startActivity(browserIntent3); } break; case 12: Drawer.closeDrawers(); break; case 13: Drawer.closeDrawers(); break; case 14: Drawer.closeDrawers(); break; default: break; } return true; } return false; } @Override public void onTouchEvent(RecyclerView recyclerView, MotionEvent motionEvent) { } }); mLayoutManager = new LinearLayoutManager(this); // Creating a layout Manager mRecyclerView.setLayoutManager(mLayoutManager); // Setting the layout Manager Drawer = (DrawerLayout) findViewById(R.id.DrawerLayout); // Drawer object Assigned to the view mDrawerToggle = new ActionBarDrawerToggle(this, Drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close) { @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); // code here will execute once the drawer is opened( As I dont want anything happened whe drawer is // open I am not going to put anything here) } @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); // Code here will execute once drawer is closed } }; // Drawer Toggle Object Made Drawer.setDrawerListener(mDrawerToggle); // Drawer Listener set to the Drawer toggle mDrawerToggle.syncState(); // Finally we set the drawer toggle sync State }
From source file:io.github.azuldigital.OcrCaptureActivity.java
/** * Initializes the UI and creates the detector pipeline. *//*from w w w.j ava 2s .co m*/ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.activity_ocrreader); mPreview = (CameraSourcePreview) findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay<OcrGraphic>) findViewById(R.id.graphicOverlay); // Check for the camera permission before accessing the camera. If the // permission is not granted yet, request permission. int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA); if (rc == PackageManager.PERMISSION_GRANTED) { createCameraSource(true, false); } else { requestCameraPermission(); } gestureDetector = new GestureDetector(this, new CaptureGestureListener()); scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener()); Snackbar.make(mGraphicOverlay, "Toque para capturar a placa", Snackbar.LENGTH_LONG).show(); }
From source file:org.kei.android.phone.mangastore.AppFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { final ViewGroup rootView = (ViewGroup) inflater.inflate(layout_id, container, false); swipeRefreshLayout = (SwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh_layout); listMangas = (ListView) rootView.findViewById(R.id.list); listMangas.setAdapter(adapter);// www.j a v a2s . c o m indexer.initialize(rootView); multiChoice = new ListMultiChoice(((MangaStorePagerActivity) getActivity()), listMangas); gestureDetector = new GestureDetector(rootView.getContext(), indexer); listMangas.setOnItemClickListener(this); listMangas.setChoiceMode(AbsListView.CHOICE_MODE_MULTIPLE_MODAL); listMangas.setMultiChoiceModeListener(multiChoice); rootView.setOnTouchListener(new OnTouchListener() { @Override public boolean onTouch(final View v, final MotionEvent event) { if (gestureDetector.onTouchEvent(event)) return true; else return false; } }); swipeRefreshLayout.setOnRefreshListener(this); /** * Showing Swipe Refresh animation on activity create * As animation won't start on onCreate, post runnable is used */ swipeRefreshLayout.post(new Runnable() { @Override public void run() { swipeRefreshLayout.setRefreshing(true); fetch(); } }); return rootView; }
From source file:events.equaliser.android.barcode.BarcodeCaptureActivity.java
/** * Initializes the UI and creates the detector pipeline. *//*ww w . j av a 2 s. c o m*/ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.activity_barcode_capture); mPreview = (CameraSourcePreview) findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay<BarcodeGraphic>) findViewById(R.id.graphicOverlay); // Check for the camera permission before accessing the camera. If the // permission is not granted yet, request permission. int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA); if (rc == PackageManager.PERMISSION_GRANTED) { createCameraSource(true, false); } else { requestCameraPermission(); } gestureDetector = new GestureDetector(this, new CaptureGestureListener()); scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener()); Snackbar.make(mGraphicOverlay, "Tap to capture. Pinch/Stretch to zoom", Snackbar.LENGTH_LONG).show(); }
From source file:spinc.spmmvp.google_vision.ocrReader_start.OcrCaptureActivity.java
/** * Initializes the UI and creates the detector pipeline. *///www . j a v a 2s . c om @Override public void onCreate(Bundle bundle) { super.onCreate(bundle); setContentView(R.layout.ocr_capture_start); mPreview = (CameraSourcePreview) findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay<OcrGraphic>) findViewById(R.id.graphicOverlay); // Set good defaults for capturing text. boolean autoFocus = true; boolean useFlash = false; // Check for the camera permission before accessing the camera. If the // permission is not granted yet, request permission. int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA); if (rc == PackageManager.PERMISSION_GRANTED) { createCameraSource(autoFocus, useFlash); } else { requestCameraPermission(); } gestureDetector = new GestureDetector(this, new CaptureGestureListener()); scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener()); Snackbar.make(mGraphicOverlay, "Tap to Speak. Pinch/Stretch to zoom", Snackbar.LENGTH_LONG).show(); // TODO: Set up the Text To Speech engine. }
From source file:com.billooms.harppedals.HarpPedalsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { // Log.d(TAG, "HarpPedalsActivity.onCreate"); super.onCreate(savedInstanceState); setVolumeControlStream(AudioManager.STREAM_MUSIC); dialogBuilder = new AlertDialog.Builder(this); dialogBuilder.setPositiveButton("OK", new DialogInterface.OnClickListener() { @Override/*from w w w.j a va 2 s . co m*/ public void onClick(DialogInterface dialog, int which) { // don't do anything except close the dialog } }); // This will be either the standard (small) layout or the large layout setContentView(R.layout.activity_main); // Check that the activity is using the standard (small) layout version with the 'fragment_container' FrameLayout if (findViewById(R.id.fragment_container) != null) { // Gesture Detector to detect horizontal swipes if (gDetector == null) { gDetector = new GestureDetector(this, new GestureDetector.SimpleOnGestureListener() { @Override public boolean onFling(MotionEvent start, MotionEvent finish, float xVelocity, float yVelocity) { if ((finish == null) || (start == null)) { // not sure why, but the float dx = gives null pointer error sometimes return false; } Fragment swipeFragment = getSupportFragmentManager().findFragmentByTag(NO_SWIPE); if (swipeFragment == null) { // only process swipes in one-pane PedalFragments float dx = finish.getRawX() - start.getRawX(); float dy = finish.getRawY() - start.getRawY(); if (Math.abs(dy) < Math.abs(dx)) { // horizontal if (dx < 0) { // swipe toward the left for KeySignature launchKeyFragment(); } else { // swipe toward the right for Chord launchChordFragment(); } } return true; // gesture has been consumed } return false; // don't process swipes if we're not in a one-pane PedalFragment } }); } // If we're being restored from a previous state, // then we don't need to do anything and should return or else // we could end up with overlapping fragments. if (savedInstanceState != null) { return; } // Create a new PedalFragment to be placed in the activity layout PedalFragment pedalFragment = new PedalFragment(); // Add the fragment to the 'fragment_container' FrameLayout getSupportFragmentManager().beginTransaction() .add(R.id.fragment_container, pedalFragment, TAG_PEDAL_FRAG).commit(); } }
From source file:sdi.com.currencywizard.autocapture.OcrCaptureActivity.java
/** * Initializes the UI and creates the detector pipeline. *//*from www . j a v a 2 s .c o m*/ @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.ocr_capture); mPreview = (CameraSourcePreview) findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay<OcrGraphic>) findViewById(R.id.graphicOverlay); // read parameters from the intent used to launch the activity. boolean autoFocus = getIntent().getBooleanExtra(AutoFocus, false); boolean useFlash = getIntent().getBooleanExtra(UseFlash, false); // Check for the camera permission before accessing the camera. If the // permission is not granted yet, request permission. int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA); if (rc == PackageManager.PERMISSION_GRANTED) { createCameraSource(autoFocus, useFlash); } else { requestCameraPermission(); } gestureDetector = new GestureDetector(this, new CaptureGestureListener()); scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener()); }
From source file:com.arunsoorya.onthisday.ocrlib.OcrCaptureActivity.java
/** * Initializes the UI and creates the detector pipeline. */// w w w .j av a2 s . c om @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.ocr_capture); mPreview = (CameraSourcePreview) findViewById(R.id.preview); mGraphicOverlay = (GraphicOverlay<OcrGraphic>) findViewById(R.id.graphicOverlay); // read parameters from the intent used to launch the activity. boolean autoFocus = getIntent().getBooleanExtra(AutoFocus, true); boolean useFlash = getIntent().getBooleanExtra(UseFlash, false); // Check for the camera permission before accessing the camera. If the // permission is not granted yet, request permission. int rc = ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA); if (rc == PackageManager.PERMISSION_GRANTED) { createCameraSource(autoFocus, useFlash); } else { requestCameraPermission(); } gestureDetector = new GestureDetector(this, new CaptureGestureListener()); scaleGestureDetector = new ScaleGestureDetector(this, new ScaleListener()); Snackbar.make(mGraphicOverlay, "Tap to capture. Pinch/Stretch to zoom", Snackbar.LENGTH_LONG).show(); }