NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package com.example.shaperecognitiongame;

import android.Manifest;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.Snackbar;
import android.support.v4.app.ActivityCompat;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.shaperecognitiongame.shapes.Shape;
import com.example.shaperecognitiongame.shapes.ShapeHelper;

public class MainActivity extends AppCompatActivity {
private static final int PERMISSION_REQUEST_CAMERA = 0;
public static final String VERTICES_EXTRA = "vertices_extra";
public static final int NEW_GAME_REQUEST = 100;
public static final String FOUND_REQUEST = "found_request";

private View mMainLayout;
private ImageView mImageView;
private TextView mScoreText;
private int mVertices;

private int mScore;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.activity_main);

mMainLayout = findViewById(R.id.main_layout);
mImageView = findViewById(R.id.imageView);
mScoreText = findViewById(R.id.textView2);
mScore = 0;

chooseNewShape();

final Button button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
verifyCameraPermission();
}
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == NEW_GAME_REQUEST) {
chooseNewShape();

if (resultCode == RESULT_OK) {
mScore++;
mScoreText.setText(String.valueOf(mScore));
}
}
}

private void chooseNewShape() {
Shape shape = ShapeHelper.getRandomShape();
mVertices = shape.numberOfVertices();

int imageResource = shape.imageResource();
mImageView.setImageResource(imageResource);
}

private void startCamera() {
Intent intent = new Intent(getApplicationContext(), CvCameraActivity.class);
intent.putExtra(VERTICES_EXTRA, mVertices);
startActivityForResult(intent, NEW_GAME_REQUEST);
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
if (requestCode == PERMISSION_REQUEST_CAMERA) {
// Request for camera permission.
if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
startCamera();
} else {
// Permission request was denied.
Snackbar.make(mMainLayout, R.string.camera_access_required,
Snackbar.LENGTH_SHORT)
.show();
}
}
}

private void verifyCameraPermission() {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
== PackageManager.PERMISSION_GRANTED) {
// Permission is already available, start camera preview
startCamera();
} else {
// Permission is missing and must be requested.
requestCameraPermission();
}
}

/**
* Requests the {@link android.Manifest.permission#CAMERA} permission.
* If an additional rationale should be displayed, the user has to launch the request from
* a SnackBar that includes additional information.
*/
private void requestCameraPermission() {
// Permission has not been granted and must be requested.
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.CAMERA)) {
// Provide an additional rationale to the user if the permission was not granted
// and the user would benefit from additional context for the use of the permission.
// Display a SnackBar with cda button to request the missing permission.
Snackbar.make(mMainLayout, R.string.camera_access_required,
Snackbar.LENGTH_INDEFINITE).setAction(R.string.ok, new View.OnClickListener() {
@Override
public void onClick(View view) {
// Request the permission
ActivityCompat.requestPermissions(MainActivity.this,
new String[]{Manifest.permission.CAMERA},
PERMISSION_REQUEST_CAMERA);
}
}).show();

} else {
// Request the permission. The result will be received in onRequestPermissionResult().
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.CAMERA}, PERMISSION_REQUEST_CAMERA);
}
}
}
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.