List of usage examples for android.view SurfaceView setOnTouchListener
public void setOnTouchListener(OnTouchListener l)
From source file:org.skia.viewer.ViewerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surfaceView); surfaceView.getHolder().addCallback(this); surfaceView.setOnTouchListener(this); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout); if (mDrawerLayout != null) { // xlarge-land has no drawer layout (drawer is always open) mDrawerToggle = new ActionBarDrawerToggle(this, mDrawerLayout, R.string.drawer_open, R.string.drawer_close);// w w w. j ava 2 s. co m mDrawerLayout.addDrawerListener(mDrawerToggle); getActionBar().setDisplayHomeAsUpEnabled(true); getActionBar().setHomeButtonEnabled(true); } mDrawerList = (ListView) findViewById(R.id.leftDrawer); mStateAdapter = new StateAdapter(this); mDrawerList.setAdapter(mStateAdapter); mApplication = (ViewerApplication) getApplication(); mApplication.setViewerActivity(this); }
From source file:ch.jeda.platform.android.CanvasFragment.java
@Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { final SurfaceView result = new SurfaceView(this.getActivity()); result.setFocusable(true);/* ww w . j a v a2 s .c o m*/ result.setFocusableInTouchMode(true); result.setOnKeyListener(this); result.setOnTouchListener(this); this.surfaceHolder = result.getHolder(); this.surfaceHolder.addCallback(this); return result; }
From source file:eu.veldsoft.adsbobball.ActivityStateEnum.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.main);/* w w w . ja v a 2s. c om*/ SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surface_view); surfaceView.setOnTouchListener(this); surfaceHolder = surfaceView.getHolder(); surfaceHolder.setFormat(PixelFormat.RGB_565); surfaceHolder.addCallback(this); messageView = (TextView) findViewById(R.id.message_label); messageView.bringToFront(); transparentView = findViewById(R.id.transparent_view); numPlayersSelector = (Spinner) findViewById(R.id.num_players); ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this, R.array.playerNumber, android.R.layout.simple_spinner_item); adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); numPlayersSelector.setAdapter(adapter); button = (Button) findViewById(R.id.continue_button); button.setOnClickListener(this); statusTopleft = (TextView) findViewById(R.id.status_topleft); statusTopright = (TextView) findViewById(R.id.status_topright); statusBotleft = (TextView) findViewById(R.id.status_botleft); statusBotright = (TextView) findViewById(R.id.status_botright); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerLayout.setDrawerListener(new DrawerLayout.SimpleDrawerListener() { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); onClick(drawerView); } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (activityState == ActivityStateEnum.GAMERUNNING) showPauseScreen(); } }); statusTopright.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { statusTopright.setTextColor(0xffCCCCFF); secretHandshake += 1; } }); statusBotright.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (secretHandshake > 4) { statusBotright.setTextColor(0xffCCCCFF); final NetworkIP n = new NetworkIP((int) System.currentTimeMillis()); n.startServer(); n.clientConnect("127.0.0.1", 1234); } } }); scores = new Scores(getSharedPreferences("scores", Context.MODE_PRIVATE)); scores.loadScores(); if (savedInstanceState == null) { showIntroScreen(); } }
From source file:org.bobstuff.bobball.ActivityStateEnum.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.main);//w ww . j ava 2 s. c o m SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surface_view); surfaceView.setOnTouchListener(this); surfaceHolder = surfaceView.getHolder(); surfaceHolder.setFormat(PixelFormat.RGB_565); surfaceHolder.addCallback(this); messageView = (TextView) findViewById(R.id.message_label); percentageCleared = (TextView) findViewById(R.id.percentageCleared); totalPercentageCleared = (TextView) findViewById(R.id.totalPercentageCleared); bonusPoints = (TextView) findViewById(R.id.bonusPoints); button = (Button) findViewById(R.id.continue_button); button.setOnClickListener(this); retryButton = (Button) findViewById(R.id.retryButton); backToLevelSelectButton = (Button) findViewById(R.id.backToLevelSelectButton); statusTopleft = (TextView) findViewById(R.id.status_topleft); statusTopright = (TextView) findViewById(R.id.status_topright); statusBotleft = (TextView) findViewById(R.id.status_botleft); statusBotright = (TextView) findViewById(R.id.status_botright); drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); drawerLayout.setDrawerListener(new DrawerLayout.SimpleDrawerListener() { @Override public void onDrawerClosed(View drawerView) { super.onDrawerClosed(drawerView); if (gameManager.isPaused()) { gameManager.togglePauseGameLoop(); } changeToPauseScreen(); onClick(drawerView); } @Override public void onDrawerOpened(View drawerView) { super.onDrawerOpened(drawerView); if (activityState == ActivityStateEnum.GAMERUNNING) { if (!gameManager.isPaused()) { gameManager.togglePauseGameLoop(); } showPauseScreen(); } } }); drawerLayout.setFocusableInTouchMode(false); // if set to false, the drawer doesn't react to pressing the back key by default statusTopright.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { statusTopright.setTextColor(0xffCCCCFF); secretHandshake += 1; } }); statusBotright.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { if (secretHandshake > 4) { statusBotright.setTextColor(0xffCCCCFF); //request a hidden service Intent intent = new Intent("org.torproject.android.REQUEST_HS_PORT"); intent.setPackage("org.torproject.android"); intent.putExtra("hs_port", 8477); startActivityForResult(intent, 9999); } } }); Bundle extras = getIntent().getExtras(); level = extras.getInt("level"); numPlayers = extras.getInt("numPlayers"); scores = new Scores(numPlayers); scores.loadScores(); }
From source file:com.jasompeter.openalpr.CameraActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); setContentView(R.layout.activity_camera); SurfaceView surfaceView = (SurfaceView) findViewById(R.id.surface_view); mTorchButton = (ImageButton) findViewById(R.id.torch_button); mCapturingText = (TextView) findViewById(R.id.capturing_text); mTouchToCaptureText = (TextView) findViewById(R.id.touch_to_capture); mSurfaceHolder = surfaceView.getHolder(); mSurfaceHolder.addCallback(this); mSurfaceHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // we should not open camera on UI thread mCameraOpenTask = new AsyncTask<Void, Void, Void>() { @Override/*from w w w. j ava 2s. co m*/ protected Void doInBackground(Void[] params) { if (!mCameraIsOpen) { releaseCameraAndPreview(); try { int cameraCount = Camera.getNumberOfCameras(); Log.d(TAG, "We have " + cameraCount + " cameras."); for (int i = 0; i < cameraCount; i++) { Camera.CameraInfo cameraInfo = new Camera.CameraInfo(); Camera.getCameraInfo(i, cameraInfo); if (cameraInfo.facing == Camera.CameraInfo.CAMERA_FACING_BACK) { mCameraId = i; break; } } mCamera = Camera.open(mCameraId); mCameraIsOpen = true; } catch (Exception e) { mCameraIsOpen = false; Log.d(TAG, "Failed to open camera. Camera is probably in use."); } } return null; } @Override protected void onPostExecute(Void o) { onCameraOpened(mCamera != null); } }; // orientation manager handles orientation changes // because our activity is set to force landscape mode // and we may want rotate action buttons or do something with view mOrientationManager = new OrientationManager(this, SensorManager.SENSOR_DELAY_NORMAL, this); invalidateTorchButton(); mTorchButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { toggleTorch(); } }); initializeAlpr(); surfaceView.setOnTouchListener(new View.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { switch (event.getAction()) { case MotionEvent.ACTION_DOWN: mEnableRecognition = true; mCapturingText.setVisibility(View.VISIBLE); mTouchToCaptureText.setVisibility(View.GONE); return true; // if you want to handle the touch event case MotionEvent.ACTION_UP: mEnableRecognition = false; mCapturingText.setVisibility(View.GONE); mTouchToCaptureText.setVisibility(View.VISIBLE); return true; // if you want to handle the touch event } return false; } }); }