/** Called when the activity is first created. */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION_2_4_3, this, mLoaderCallback); currentView = 0; mGestureSensor = new CameraGestureSensor(this); mGestureSensor.addGestureListener(this); mGestureSensor.enableClickByColor(true); mGestureSensor.addClickListener(this); mOpenCVInitiated = false; imageView = (ImageView) findViewById(R.id.ImageView01); imageView.setImageResource(pics[currentView]); ga = (Gallery) findViewById(R.id.Gallery01); ga.setAdapter(new ImageAdapter(this)); ga.setOnItemClickListener( new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapter, View givenView, int index, long arg3) { Toast.makeText(getBaseContext(), "A click was recieved!", Toast.LENGTH_SHORT).show(); imageView.setImageResource(pics[index]); currentView = index; } }); }
@Override public void onManagerConnected(int status) { switch (status) { case LoaderCallbackInterface.SUCCESS: { mOpenCVInitiated = true; CameraGestureSensor.loadLibrary(); mGestureSensor.start(); } break; default: { super.onManagerConnected(status); } break; } }
/** * Called when the activity is paused. The gesture detector is stopped so that the camera is no * longer working to recognize gestures. */ @Override public void onPause() { super.onPause(); if (!mOpenCVInitiated) return; mGestureSensor.stop(); }
/** Called when the activity is resumed. The gesture detector is initialized. */ @Override public void onResume() { super.onResume(); if (!mOpenCVInitiated) return; mGestureSensor.start(); }