NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

package com.example.xsimons1_activity;

import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.FragmentTransaction;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.pm.ActivityInfo;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;

public class ximenes1_Activity extends AppCompatActivity implements SensorEventListener {
private SensorManager mSensorManager;
private Sensor mAccelerometer;
int tut=0;
int tut2=0;
int puan=10;
private AnimatedView mAnimatedView = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
mAccelerometer = mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER);


mAnimatedView = new AnimatedView(this);
//set
setContentView(mAnimatedView);
}

@Override
protected void onResume() {
super.onResume();
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
}

@Override
protected void onPause() {
super.onPause();
mSensorManager.unregisterListener(this);
}


@Override
public void onAccuracyChanged(Sensor arg0, int arg1) {
}

@Override
public void onSensorChanged(SensorEvent event) {
// TODO Auto-generated method stub
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
mAnimatedView.onSensorEvent(event);
}
}

public class AnimatedView extends View {
Context context;
private static final int CIRCLE_RADIUS = 27; //pixels
private Paint mPaint, p2, p3,p4,p5;
private int x;
private int y;
private int viewWidth;
private int viewHeight;

public AnimatedView(Context context) {
super(context);
this.context = context;
mPaint = new Paint();
p2 = new Paint();
p2.setColor(Color.BLACK);
p4 = new Paint();
p4.setColor(Color.rgb(223,150,0));

mPaint.setColor(Color.BLUE);
p3 = new Paint();
p3.setColor(Color.RED);
p5 = new Paint();
p5.setColor(Color.GREEN);
}

@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh) {
super.onSizeChanged(w, h, oldw, oldh);
viewWidth = w;
viewHeight = h;
}

public void onSensorEvent(SensorEvent event) {
x = x - (int) event.values[0];
y = y + (int) event.values[1];
if (x <= 0 + CIRCLE_RADIUS) {
x = 0 + CIRCLE_RADIUS;
}
if (x >= viewWidth - CIRCLE_RADIUS) {
x = viewWidth - CIRCLE_RADIUS;
}
if (y <= 0 + CIRCLE_RADIUS) {
y = 0 + CIRCLE_RADIUS;
}
if (y >= viewHeight - CIRCLE_RADIUS) {
y = viewHeight - CIRCLE_RADIUS;
}
}

public class Circle{
float x;
float y;
float radius;
Circle(float x, float y, float radius){
this.x=x;
this.y=y;
this.radius=radius;
}
}

@Override
protected void onDraw(Canvas canvas) {

canvas.drawCircle(x, y, CIRCLE_RADIUS, mPaint);
Circle siyah1 = new Circle(100,300,27);
Circle siyah2 = new Circle(500,250,27);
Circle siyah3 = new Circle(230,550,27);
Circle siyah4 = new Circle(300,1300,27);
Circle siyah5 = new Circle(650,600,27);
Circle siyah6 = new Circle(550,1000,27);
Circle siyah7 = new Circle(700,1500,27);
Circle siyah8 = new Circle(800,250,27);
Circle siyah9 = new Circle(950,600,27);
Circle siyah10 = new Circle(850,1000,27);
canvas.drawCircle(siyah1.x,siyah1.y,siyah1.radius,p2);
canvas.drawCircle(siyah2.x,siyah2.y,siyah2.radius,p2);
canvas.drawCircle(siyah3.x,siyah3.y,siyah3.radius,p2);
canvas.drawCircle(siyah4.x,siyah4.y,siyah4.radius,p2);
canvas.drawCircle(siyah5.x,siyah5.y,siyah5.radius,p2);
canvas.drawCircle(siyah6.x,siyah6.y,siyah6.radius,p2);
canvas.drawCircle(siyah7.x,siyah7.y,siyah7.radius,p2);
canvas.drawCircle(siyah8.x,siyah8.y,siyah8.radius,p2);
canvas.drawCircle(siyah9.x,siyah9.y,siyah9.radius,p2);
canvas.drawCircle(siyah10.x,siyah10.y,siyah10.radius,p2);

Circle turuncu1 = new Circle(500,450,27);
canvas.drawCircle(turuncu1.x,turuncu1.y,turuncu1.radius,p4);
Circle turuncu2 = new Circle(550,800,27);
canvas.drawCircle(turuncu2.x,turuncu2.y,turuncu2.radius,p4);
Circle turuncu3 = new Circle(250,1100,27);
canvas.drawCircle(turuncu3.x,turuncu3.y,turuncu3.radius,p4);
Circle turuncu4 = new Circle(650,1200,27);
canvas.drawCircle(turuncu4.x,turuncu4.y,turuncu4.radius,p4);
Circle turuncu5 = new Circle(900,1500,27);
canvas.drawCircle(turuncu5.x,turuncu5.y,turuncu5.radius,p4);
if (checkIntersect(x,y,CIRCLE_RADIUS,siyah1)||checkIntersect(x,y,CIRCLE_RADIUS,siyah2)||checkIntersect(x,y,CIRCLE_RADIUS,siyah3)||checkIntersect(x,y,CIRCLE_RADIUS,siyah4)||checkIntersect(x,y,CIRCLE_RADIUS,siyah5)||checkIntersect(x,y,CIRCLE_RADIUS,siyah6)||checkIntersect(x,y,CIRCLE_RADIUS,siyah7)||checkIntersect(x,y,CIRCLE_RADIUS,siyah8)||checkIntersect(x,y,CIRCLE_RADIUS,siyah9)||checkIntersect(x,y,CIRCLE_RADIUS,siyah10)){
if(tut==0){
Log.v("ÇARPIŞTI", "PUAN KAYBETTİ");
puan=puan-2;
if (puan<=0){
onPause();
x=0;
y=0;
tut=0;
tut2=0;
puan=10;
canvas.drawCircle(0,0,CIRCLE_RADIUS,p3);
AlertDialog.Builder builder1 = new AlertDialog.Builder(context);
builder1.setMessage("Kaybettiniz");
builder1.setCancelable(true);

builder1.setPositiveButton(
"Tekrar Oyna",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
onResume();
dialog.cancel();
}
});

builder1.setNegativeButton(
"Çıkış",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
});

AlertDialog alert11 = builder1.create();
alert11.show();
}
tut=1;
}
canvas.drawCircle(x, y, CIRCLE_RADIUS, p3);
}
else{
tut=0;
}
if (checkIntersect(x,y,CIRCLE_RADIUS,turuncu1)||checkIntersect(x,y,CIRCLE_RADIUS,turuncu2)||checkIntersect(x,y,CIRCLE_RADIUS,turuncu3)||checkIntersect(x,y,CIRCLE_RADIUS,turuncu4)||checkIntersect(x,y,CIRCLE_RADIUS,turuncu5)){

if(tut2==0){
Log.v("ÇARPIŞTI", "PUAN KAZANDI");
puan=puan+1;
if (puan>=50){
onPause();
x=0;
y=0;
tut=0;
tut2=0;
puan=10;
AlertDialog.Builder builder1 = new AlertDialog.Builder(context);
builder1.setMessage("Tebrikler 50 puana ulaştınız!");
builder1.setCancelable(true);

builder1.setPositiveButton(
"Tekrar Oyna",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
onResume();
dialog.cancel();
}
});

builder1.setNegativeButton(
"Çıkış",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
finish();
}
});

AlertDialog alert11 = builder1.create();
alert11.show();
}
tut2=1;
}

canvas.drawCircle(x, y, CIRCLE_RADIUS, p5);
}
else{
tut2=0;
}
invalidate();
}

public boolean checkIntersect(int x, int y, int r, Circle r1){
boolean intersects=false;
if ((Math.abs(y-r1.y)<r))
{
if ((Math.abs(x-r1.x)<r))
{
intersects=true;
}
}
return intersects;
}
}
}
     
 
what is notes.io
 

Notes is a web-based application for online 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 14 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.