commit 60e341a36389305ae393f3068294170544cf5edb Author: Administrator Date: Sat Feb 15 09:38:34 2014 +0100 First commit diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..5176974 --- /dev/null +++ b/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..56f477e --- /dev/null +++ b/.project @@ -0,0 +1,33 @@ + + + Pong + + + + + + com.android.ide.eclipse.adt.ResourceManagerBuilder + + + + + com.android.ide.eclipse.adt.PreCompilerBuilder + + + + + org.eclipse.jdt.core.javabuilder + + + + + com.android.ide.eclipse.adt.ApkBuilder + + + + + + com.android.ide.eclipse.adt.AndroidNature + org.eclipse.jdt.core.javanature + + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs new file mode 100644 index 0000000..b080d2d --- /dev/null +++ b/.settings/org.eclipse.jdt.core.prefs @@ -0,0 +1,4 @@ +eclipse.preferences.version=1 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6 +org.eclipse.jdt.core.compiler.compliance=1.6 +org.eclipse.jdt.core.compiler.source=1.6 diff --git a/AndroidManifest.xml b/AndroidManifest.xml new file mode 100644 index 0000000..dfb7a76 --- /dev/null +++ b/AndroidManifest.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + diff --git a/bin/AndroidManifest.xml b/bin/AndroidManifest.xml new file mode 100644 index 0000000..dfb7a76 --- /dev/null +++ b/bin/AndroidManifest.xml @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + diff --git a/bin/CanvasFirstTry.apk b/bin/CanvasFirstTry.apk new file mode 100644 index 0000000..b7239b0 Binary files /dev/null and b/bin/CanvasFirstTry.apk differ diff --git a/bin/classes.dex b/bin/classes.dex new file mode 100644 index 0000000..395f55e Binary files /dev/null and b/bin/classes.dex differ diff --git a/bin/classes/mangavalk/canvasfirsttry/BuildConfig.class b/bin/classes/mangavalk/canvasfirsttry/BuildConfig.class new file mode 100644 index 0000000..c463855 Binary files /dev/null and b/bin/classes/mangavalk/canvasfirsttry/BuildConfig.class differ diff --git a/bin/classes/mangavalk/canvasfirsttry/CanvasView.class b/bin/classes/mangavalk/canvasfirsttry/CanvasView.class new file mode 100644 index 0000000..324a42f Binary files /dev/null and b/bin/classes/mangavalk/canvasfirsttry/CanvasView.class differ diff --git a/bin/classes/mangavalk/canvasfirsttry/MainActivity.class b/bin/classes/mangavalk/canvasfirsttry/MainActivity.class new file mode 100644 index 0000000..dcdb7a9 Binary files /dev/null and b/bin/classes/mangavalk/canvasfirsttry/MainActivity.class differ diff --git a/bin/classes/mangavalk/canvasfirsttry/R$attr.class b/bin/classes/mangavalk/canvasfirsttry/R$attr.class new file mode 100644 index 0000000..73bfc41 Binary files /dev/null and b/bin/classes/mangavalk/canvasfirsttry/R$attr.class differ diff --git a/bin/classes/mangavalk/canvasfirsttry/R$dimen.class b/bin/classes/mangavalk/canvasfirsttry/R$dimen.class new file mode 100644 index 0000000..4917c25 Binary files /dev/null and b/bin/classes/mangavalk/canvasfirsttry/R$dimen.class differ diff --git a/bin/classes/mangavalk/canvasfirsttry/R$drawable.class b/bin/classes/mangavalk/canvasfirsttry/R$drawable.class new file mode 100644 index 0000000..a7d5ca8 Binary files /dev/null and b/bin/classes/mangavalk/canvasfirsttry/R$drawable.class differ diff --git a/bin/classes/mangavalk/canvasfirsttry/R$id.class b/bin/classes/mangavalk/canvasfirsttry/R$id.class new file mode 100644 index 0000000..bdba24e Binary files /dev/null and b/bin/classes/mangavalk/canvasfirsttry/R$id.class differ diff --git a/bin/classes/mangavalk/canvasfirsttry/R$layout.class b/bin/classes/mangavalk/canvasfirsttry/R$layout.class new file mode 100644 index 0000000..cd6a194 Binary files /dev/null and b/bin/classes/mangavalk/canvasfirsttry/R$layout.class differ diff --git a/bin/classes/mangavalk/canvasfirsttry/R$menu.class b/bin/classes/mangavalk/canvasfirsttry/R$menu.class new file mode 100644 index 0000000..8adedd1 Binary files /dev/null and b/bin/classes/mangavalk/canvasfirsttry/R$menu.class differ diff --git a/bin/classes/mangavalk/canvasfirsttry/R$raw.class b/bin/classes/mangavalk/canvasfirsttry/R$raw.class new file mode 100644 index 0000000..c4891ad Binary files /dev/null and b/bin/classes/mangavalk/canvasfirsttry/R$raw.class differ diff --git a/bin/classes/mangavalk/canvasfirsttry/R$string.class b/bin/classes/mangavalk/canvasfirsttry/R$string.class new file mode 100644 index 0000000..e9d97b4 Binary files /dev/null and b/bin/classes/mangavalk/canvasfirsttry/R$string.class differ diff --git a/bin/classes/mangavalk/canvasfirsttry/R$style.class b/bin/classes/mangavalk/canvasfirsttry/R$style.class new file mode 100644 index 0000000..1bba9ee Binary files /dev/null and b/bin/classes/mangavalk/canvasfirsttry/R$style.class differ diff --git a/bin/classes/mangavalk/canvasfirsttry/R.class b/bin/classes/mangavalk/canvasfirsttry/R.class new file mode 100644 index 0000000..b7d5ae8 Binary files /dev/null and b/bin/classes/mangavalk/canvasfirsttry/R.class differ diff --git a/bin/dexedLibs/android-support-v4-ea5ac4ade58e5231ceadbbe26368512d.jar b/bin/dexedLibs/android-support-v4-ea5ac4ade58e5231ceadbbe26368512d.jar new file mode 100644 index 0000000..5f50933 Binary files /dev/null and b/bin/dexedLibs/android-support-v4-ea5ac4ade58e5231ceadbbe26368512d.jar differ diff --git a/bin/jarlist.cache b/bin/jarlist.cache new file mode 100644 index 0000000..0565465 --- /dev/null +++ b/bin/jarlist.cache @@ -0,0 +1,3 @@ +# cache for current jar dependency. DO NOT EDIT. +# format is +# Encoding is UTF-8 diff --git a/bin/res/crunch/drawable-hdpi/ic_launcher.png b/bin/res/crunch/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000..efa7c5f Binary files /dev/null and b/bin/res/crunch/drawable-hdpi/ic_launcher.png differ diff --git a/bin/res/crunch/drawable-mdpi/gameover.png b/bin/res/crunch/drawable-mdpi/gameover.png new file mode 100644 index 0000000..6522991 Binary files /dev/null and b/bin/res/crunch/drawable-mdpi/gameover.png differ diff --git a/bin/res/crunch/drawable-mdpi/ic_launcher.png b/bin/res/crunch/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000..ec27f2e Binary files /dev/null and b/bin/res/crunch/drawable-mdpi/ic_launcher.png differ diff --git a/bin/res/crunch/drawable-mdpi/player1.png b/bin/res/crunch/drawable-mdpi/player1.png new file mode 100644 index 0000000..f29a7a4 Binary files /dev/null and b/bin/res/crunch/drawable-mdpi/player1.png differ diff --git a/bin/res/crunch/drawable-mdpi/player2.PNG b/bin/res/crunch/drawable-mdpi/player2.PNG new file mode 100644 index 0000000..01eda44 Binary files /dev/null and b/bin/res/crunch/drawable-mdpi/player2.PNG differ diff --git a/bin/res/crunch/drawable-xhdpi/ic_launcher.png b/bin/res/crunch/drawable-xhdpi/ic_launcher.png new file mode 100644 index 0000000..92fc57d Binary files /dev/null and b/bin/res/crunch/drawable-xhdpi/ic_launcher.png differ diff --git a/bin/res/crunch/drawable-xxhdpi/ic_launcher.png b/bin/res/crunch/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..b6f8f4e Binary files /dev/null and b/bin/res/crunch/drawable-xxhdpi/ic_launcher.png differ diff --git a/bin/resources.ap_ b/bin/resources.ap_ new file mode 100644 index 0000000..609b5f1 Binary files /dev/null and b/bin/resources.ap_ differ diff --git a/examples b/examples new file mode 100644 index 0000000..dc94d73 --- /dev/null +++ b/examples @@ -0,0 +1,218 @@ +package mangavalk.canvasfirsttry; + +import android.app.Activity; +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Matrix; +import android.graphics.Paint; +import android.graphics.Paint.Style; +import android.graphics.RectF; +import android.util.DisplayMetrics; +import android.util.TypedValue; +import android.view.Display; +import android.view.View; + +public class CanvasView extends View { + Resources r ; + float dpHeight; + float dpWidth; + float Height; + float Width; + float moveX1,moveX2; + float moveY1,moveY2; + + long oldTime; + + public CanvasView(Context context) { + super(context); + + super.setBackgroundColor(Color.WHITE); + oldTime = System.currentTimeMillis(); + + this.postInvalidate(); + } + + public void SetActivity(Activity activity) + { + Display display = activity.getWindowManager().getDefaultDisplay(); + DisplayMetrics outMetrics = new DisplayMetrics (); + display.getMetrics(outMetrics); + + r = getResources(); + float density = getResources().getDisplayMetrics().density; + dpHeight = outMetrics.heightPixels / density; + dpWidth = outMetrics.widthPixels / density; + Height = outMetrics.heightPixels; + Width = outMetrics.widthPixels; + + moveY1 = 50; + moveY2 = 50; + } + + int count = 0; + + @Override + protected void onDraw(Canvas canvas) { + count++; + + long newTime = System.currentTimeMillis(); + + //drawText(canvas, count); + DrawFps(canvas, newTime); + drawPeddleRight(canvas, moveY1); + drawPeddleLeft(canvas, moveY2); + + oldTime = newTime; + + //this.postInvalidateDelayed( 100 ); + this.postInvalidate(); + } + + private void drawRoundedRectangle(Canvas canvas) { + // TODO Auto-generated method stub + Paint paint = new Paint(); + paint.setAntiAlias(true); + paint.setColor(Color.MAGENTA); + paint.setStyle(Style.FILL); + int xPosition = 10; + int yPosition = 350; + int rectangleWidth = 100; + int rectangleHeight = 50; + RectF rect=new RectF(xPosition, yPosition, xPosition + rectangleWidth, + yPosition + rectangleHeight); + canvas.drawRoundRect(rect, 10,10, paint); + paint.setStyle(Style.STROKE); + xPosition = 150; + rect=new RectF(xPosition, yPosition, xPosition + rectangleWidth, + yPosition + rectangleHeight); + canvas.drawRoundRect(rect, 10,10, paint); + + } + + private void drawRotatedImage(Canvas canvas) { + // TODO Auto-generated method stub + Bitmap bitmap = BitmapFactory.decodeResource(getResources(), + R.drawable.ic_launcher); + bitmap = Bitmap.createScaledBitmap(bitmap, 100, 100, false); + Matrix matrix = new Matrix(); + matrix.postRotate(60);// angle to rotate in clockwise direction + matrix.postTranslate(200, 180); + + canvas.drawBitmap(bitmap, matrix, null); + } + + private void DrawFps(Canvas canvas, long newTime) + { + Paint paint = new Paint(); + paint.setColor(Color.BLACK); + paint.setTextSize(30); + String text = "FPS: " + (1000/(newTime-oldTime)); + canvas.drawText(text, GetRealPixelSize(dpWidth, 5), GetRealPixelSize(dpHeight, 5), paint); + } + + float map(float x, float in_min, float in_max, float out_min, float out_max) + { + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; + } + + private void drawPeddleRight(Canvas canvas, float i) { + Paint paint = new Paint(); + paint.setAntiAlias(true); + paint.setColor(Color.BLACK); + paint.setStyle(Style.FILL); + + float rectangleWidth = 2; + float rectangleHeight = 20; + + float xPosition = 97; + float yPosition = i; + yPosition = yPosition <= (100-(rectangleHeight / 2))?yPosition:(100-(rectangleHeight / 2)); + yPosition = yPosition >= (rectangleHeight / 2)?yPosition:(rectangleHeight / 2); + + canvas.drawRect( + GetRealPixelSize(dpWidth, xPosition), + GetRealPixelSize(dpHeight, yPosition - (rectangleHeight / 2)), + GetRealPixelSize(dpWidth, xPosition + (rectangleWidth)), + GetRealPixelSize(dpHeight, yPosition + (rectangleHeight / 2)), paint); + } + + private void drawPeddleLeft(Canvas canvas, float i) { + Paint paint = new Paint(); + paint.setAntiAlias(true); + paint.setColor(Color.BLACK); + paint.setStyle(Style.FILL); + + float rectangleWidth = 2; + float rectangleHeight = 20; + + float xPosition = 3; + float yPosition = i; + yPosition = yPosition <= (100-(rectangleHeight / 2))?yPosition:(100-(rectangleHeight / 2)); + yPosition = yPosition >= (rectangleHeight / 2)?yPosition:(rectangleHeight / 2); + + canvas.drawRect( + GetRealPixelSize(dpWidth, xPosition - (rectangleWidth)), + GetRealPixelSize(dpHeight, yPosition - (rectangleHeight / 2)), + GetRealPixelSize(dpWidth, xPosition), + GetRealPixelSize(dpHeight, yPosition + (rectangleHeight / 2)), paint); + } + + private float GetRealPixelSize(float dpWH, float DIP) + { + return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (dpWH * ( DIP / 100 )), r.getDisplayMetrics()); + } + + private void drawImage(Canvas canvas) { + // TODO Auto-generated method stub + Bitmap bitmap = BitmapFactory.decodeResource(getResources(), + R.drawable.ic_launcher); + bitmap = Bitmap.createScaledBitmap(bitmap, 100, 100, false); + canvas.drawBitmap(bitmap, 10, 200, null); + } + + private void drawRectangle(Canvas canvas) { + // TODO Auto-generated method stub + Paint paint = new Paint(); + paint.setAntiAlias(true); + paint.setColor(Color.RED); + paint.setStyle(Style.FILL); + int xPosition = 10; + int yPosition = 150; + int rectangleWidth = 100; + int rectangleHeight = 50; + canvas.drawRect(xPosition, yPosition, xPosition + rectangleWidth, + yPosition + rectangleHeight, paint); + paint.setStyle(Style.STROKE); + xPosition = 150; + canvas.drawRect(xPosition, yPosition, xPosition + rectangleWidth, + yPosition + rectangleHeight, paint); + } + + private void drawCircle(Canvas canvas) { + // TODO Auto-generated method stub + Paint paint = new Paint(); + paint.setAntiAlias(true); + paint.setColor(Color.BLUE); + paint.setStyle(Style.FILL); + canvas.drawCircle(50, 60, 50, paint); + paint.setStyle(Style.STROKE); + canvas.drawCircle(200, 60, 50, paint); + } + + public void sendMove(float x, float y) { + if (x / Width >= 0.6f) + { + moveX1 = (x / Width) * 100; + moveY1 = (y / Height) * 100; + } + else if (x / Width <= 0.4f) + { + moveX2 = (x / Width) * 100; + moveY2 = (y / Height) * 100; + } + } +} \ No newline at end of file diff --git a/gen/mangavalk/canvasfirsttry/BuildConfig.java b/gen/mangavalk/canvasfirsttry/BuildConfig.java new file mode 100644 index 0000000..f0d7efc --- /dev/null +++ b/gen/mangavalk/canvasfirsttry/BuildConfig.java @@ -0,0 +1,6 @@ +/** Automatically generated file. DO NOT MODIFY */ +package mangavalk.canvasfirsttry; + +public final class BuildConfig { + public final static boolean DEBUG = true; +} \ No newline at end of file diff --git a/gen/mangavalk/canvasfirsttry/R.java b/gen/mangavalk/canvasfirsttry/R.java new file mode 100644 index 0000000..c634420 --- /dev/null +++ b/gen/mangavalk/canvasfirsttry/R.java @@ -0,0 +1,76 @@ +/* AUTO-GENERATED FILE. DO NOT MODIFY. + * + * This class was automatically generated by the + * aapt tool from the resource data it found. It + * should not be modified by hand. + */ + +package mangavalk.canvasfirsttry; + +public final class R { + public static final class attr { + } + public static final class dimen { + /** Default screen margins, per the Android Design guidelines. + + Customize dimensions originally defined in res/values/dimens.xml (such as + screen margins) for sw720dp devices (e.g. 10" tablets) in landscape here. + + */ + public static final int activity_horizontal_margin=0x7f050000; + public static final int activity_vertical_margin=0x7f050001; + } + public static final class drawable { + public static final int gameover=0x7f020000; + public static final int ic_launcher=0x7f020001; + public static final int player1=0x7f020002; + public static final int player2=0x7f020003; + } + public static final class id { + public static final int action_settings=0x7f090000; + } + public static final class layout { + public static final int activity_main=0x7f030000; + } + public static final class menu { + public static final int main=0x7f080000; + } + public static final class raw { + public static final int bat_cat=0x7f040000; + public static final int gameover=0x7f040001; + public static final int pling=0x7f040002; + } + public static final class string { + public static final int action_settings=0x7f060001; + public static final int app_name=0x7f060000; + public static final int hello_world=0x7f060002; + } + public static final class style { + /** + Base application theme, dependent on API level. This theme is replaced + by AppBaseTheme from res/values-vXX/styles.xml on newer devices. + + + Theme customizations available in newer API levels can go in + res/values-vXX/styles.xml, while customizations related to + backward-compatibility can go here. + + + Base application theme for API 11+. This theme completely replaces + AppBaseTheme from res/values/styles.xml on API 11+ devices. + + API 11 theme customizations can go here. + + Base application theme for API 14+. This theme completely replaces + AppBaseTheme from BOTH res/values/styles.xml and + res/values-v11/styles.xml on API 14+ devices. + + API 14 theme customizations can go here. + */ + public static final int AppBaseTheme=0x7f070000; + /** Application theme. + All customizations that are NOT specific to a particular API-level can go here. + */ + public static final int AppTheme=0x7f070001; + } +} diff --git a/ic_launcher-web.png b/ic_launcher-web.png new file mode 100644 index 0000000..a18cbb4 Binary files /dev/null and b/ic_launcher-web.png differ diff --git a/libs/android-support-v4.jar b/libs/android-support-v4.jar new file mode 100644 index 0000000..96644ed Binary files /dev/null and b/libs/android-support-v4.jar differ diff --git a/proguard-project.txt b/proguard-project.txt new file mode 100644 index 0000000..f2fe155 --- /dev/null +++ b/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/project.properties b/project.properties new file mode 100644 index 0000000..4ab1256 --- /dev/null +++ b/project.properties @@ -0,0 +1,14 @@ +# This file is automatically generated by Android Tools. +# Do not modify this file -- YOUR CHANGES WILL BE ERASED! +# +# This file must be checked in Version Control Systems. +# +# To customize properties used by the Ant build system edit +# "ant.properties", and override values to adapt the script to your +# project structure. +# +# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): +#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt + +# Project target. +target=android-19 diff --git a/res/drawable-hdpi/ic_launcher.png b/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 0000000..288b665 Binary files /dev/null and b/res/drawable-hdpi/ic_launcher.png differ diff --git a/res/drawable-mdpi/gameover.png b/res/drawable-mdpi/gameover.png new file mode 100644 index 0000000..ac1b4b1 Binary files /dev/null and b/res/drawable-mdpi/gameover.png differ diff --git a/res/drawable-mdpi/ic_launcher.png b/res/drawable-mdpi/ic_launcher.png new file mode 100644 index 0000000..6ae570b Binary files /dev/null and b/res/drawable-mdpi/ic_launcher.png differ diff --git a/res/drawable-mdpi/player1.png b/res/drawable-mdpi/player1.png new file mode 100644 index 0000000..5b2a4d7 Binary files /dev/null and b/res/drawable-mdpi/player1.png differ diff --git a/res/drawable-mdpi/player2.PNG b/res/drawable-mdpi/player2.PNG new file mode 100644 index 0000000..336ee5b Binary files /dev/null and b/res/drawable-mdpi/player2.PNG differ diff --git a/res/drawable-xhdpi/ic_launcher.png b/res/drawable-xhdpi/ic_launcher.png new file mode 100644 index 0000000..d4fb7cd Binary files /dev/null and b/res/drawable-xhdpi/ic_launcher.png differ diff --git a/res/drawable-xxhdpi/ic_launcher.png b/res/drawable-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..85a6081 Binary files /dev/null and b/res/drawable-xxhdpi/ic_launcher.png differ diff --git a/res/layout/activity_main.xml b/res/layout/activity_main.xml new file mode 100644 index 0000000..168c9b8 --- /dev/null +++ b/res/layout/activity_main.xml @@ -0,0 +1,16 @@ + + + + + diff --git a/res/menu/main.xml b/res/menu/main.xml new file mode 100644 index 0000000..c002028 --- /dev/null +++ b/res/menu/main.xml @@ -0,0 +1,9 @@ + + + + + diff --git a/res/raw/bat_cat.mp3 b/res/raw/bat_cat.mp3 new file mode 100644 index 0000000..52ca1cd Binary files /dev/null and b/res/raw/bat_cat.mp3 differ diff --git a/res/raw/gameover.mp3 b/res/raw/gameover.mp3 new file mode 100644 index 0000000..1c0a9b8 Binary files /dev/null and b/res/raw/gameover.mp3 differ diff --git a/res/raw/pling.mp3 b/res/raw/pling.mp3 new file mode 100644 index 0000000..767c50c Binary files /dev/null and b/res/raw/pling.mp3 differ diff --git a/res/values-sw600dp/dimens.xml b/res/values-sw600dp/dimens.xml new file mode 100644 index 0000000..44f01db --- /dev/null +++ b/res/values-sw600dp/dimens.xml @@ -0,0 +1,8 @@ + + + + + diff --git a/res/values-sw720dp-land/dimens.xml b/res/values-sw720dp-land/dimens.xml new file mode 100644 index 0000000..61e3fa8 --- /dev/null +++ b/res/values-sw720dp-land/dimens.xml @@ -0,0 +1,9 @@ + + + + 128dp + + diff --git a/res/values-v11/styles.xml b/res/values-v11/styles.xml new file mode 100644 index 0000000..3c02242 --- /dev/null +++ b/res/values-v11/styles.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/res/values-v14/styles.xml b/res/values-v14/styles.xml new file mode 100644 index 0000000..a91fd03 --- /dev/null +++ b/res/values-v14/styles.xml @@ -0,0 +1,12 @@ + + + + + + diff --git a/res/values/dimens.xml b/res/values/dimens.xml new file mode 100644 index 0000000..55c1e59 --- /dev/null +++ b/res/values/dimens.xml @@ -0,0 +1,7 @@ + + + + 16dp + 16dp + + diff --git a/res/values/strings.xml b/res/values/strings.xml new file mode 100644 index 0000000..7b51bfb --- /dev/null +++ b/res/values/strings.xml @@ -0,0 +1,8 @@ + + + + CanvasFirstTry + Settings + Hello world! + + diff --git a/res/values/styles.xml b/res/values/styles.xml new file mode 100644 index 0000000..6ce89c7 --- /dev/null +++ b/res/values/styles.xml @@ -0,0 +1,20 @@ + + + + + + + + + diff --git a/src/mangavalk/canvasfirsttry/CanvasView.java b/src/mangavalk/canvasfirsttry/CanvasView.java new file mode 100644 index 0000000..38df9cc --- /dev/null +++ b/src/mangavalk/canvasfirsttry/CanvasView.java @@ -0,0 +1,675 @@ +package mangavalk.canvasfirsttry; + +import android.app.Activity; +import android.content.Context; +import android.content.res.Resources; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.graphics.Canvas; +import android.graphics.Color; +import android.graphics.Paint; +import android.graphics.Paint.Style; +import android.graphics.RectF; +import android.media.AudioManager; +import android.media.SoundPool; +import android.util.DisplayMetrics; +import android.util.TypedValue; +import android.view.Display; +import android.view.View; + +public class CanvasView extends View +{ + //region Variabelen + Resources r; + + // Sizes + float dpHeight; + float dpWidth; + + float Height; + float Width; + + // Screen Boundary's + float boundaryTop = 10; + float boundaryBottom = 95; + + // Pointers + float moveX1,moveX2; + float moveY1,moveY2; + + // Ball + boolean bounceXdirection, bounceYdirection; + float bounceX, bounceY; + float speedX, speedY; + + // Pedles + float rectangleHeight1 = 20; + float rectangleHeight2 = 20; + + // Score + int score; + int Player1Life = 3; + int Player2Life = 3; + + // Fps + long oldTime; + + // Sound + boolean musicisplaying = false; + private SoundPool soundPool,soundPool2; + private int Sound_Pling,Sound_GameOver,Sound_Music; + + // Game Status + boolean gamePlaying = false; + boolean gameover = false; + + // Difficulty + int BotDif = 0; + + // Style + int selectedStyle = 0; + boolean StyleRound = true; + + int Color_PedleLeft = Color.WHITE; + int Color_PedleRight = Color.WHITE; + int Color_Ball = Color.RED; + int Color_ScoreBar = Color.GRAY; + int Color_Footer = Color.GRAY; + int Color_Background = Color.BLACK; + int Color_Score = Color.WHITE; + + //endregion Variabelen + + public CanvasView(Context context) { + super(context); + + super.setBackgroundColor(Color_Background); + oldTime = System.currentTimeMillis(); + + this.postInvalidate(); + } + + public void SetActivity(Activity activity) + { + Display display = activity.getWindowManager().getDefaultDisplay(); + DisplayMetrics outMetrics = new DisplayMetrics (); + display.getMetrics(outMetrics); + + r = getResources(); + float density = getResources().getDisplayMetrics().density; + dpHeight = outMetrics.heightPixels / density; + dpWidth = outMetrics.widthPixels / density; + Height = outMetrics.heightPixels; + Width = outMetrics.widthPixels; + + // Set Basic Score And Pedle Position + moveY1 = 50; + moveY2 = 50; + + bounceX = bounceY = 40 + (int)(Math.random() * ((60 - 40) + 1)); + bounceY = bounceY = 0 + (int)(Math.random() * ((100 - 0) + 1)); + + speedX = 1; + speedY = 1.1f; + + // Load the sound + soundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0); + soundPool2 = new SoundPool(10, AudioManager.STREAM_MUSIC, 0); + + Sound_Pling = soundPool.load(activity, R.raw.pling, 1); + Sound_GameOver = soundPool.load(activity, R.raw.gameover, 1); + Sound_Music = soundPool2.load(activity, R.raw.bat_cat, 1); + } + + + @Override + protected void onDraw(Canvas canvas) + { + if (musicisplaying == false) + { + soundPool2.play(Sound_Music, 1, 1, 0, -1, 1); + musicisplaying = true; + } + + if (gamePlaying) + { + Bot(); + + drawPeddleRight(canvas); + drawPeddleLeft(canvas); + + Bal(); + drawCircle(canvas, bounceX, bounceY); + + // Draw Score Bar + ScoreBar(canvas, boundaryTop); + Footer(canvas, boundaryBottom); + + // Fps + long newTime = System.currentTimeMillis(); + DrawFps(canvas, newTime); + + // Score + DrawText(canvas, "Life: " + Player1Life, 15); + DrawText(canvas, "Score: " + score, 45); + DrawText(canvas, "Life: " + Player2Life, 85); + + oldTime = newTime; + + if (gameover) + { + gameover = false; + + // Sound + soundPool.play(Sound_GameOver, .5f, .5f, 0, 0, 1); + + // Show GameOver message + if ((Player1Life < 0) || (Player2Life < 0)) + { + DrawGameOver(canvas); + + gamePlaying = false; + + // New Life + Player1Life = 3; + Player2Life = 3; + } + + // New Ball + + // Position + bounceX = 40 + (int)(Math.random() * ((60 - 40) + 1)); + bounceY = 0 + (int)(Math.random() * ((100 - 0) + 1)); + + // Direction + bounceXdirection = Math.random() >= 0.5f ? true : false; + + // Speed + speedX = 1f; + speedY = 1f; + + // Respawn time + this.postInvalidateDelayed( 5000 ); + } + else + this.postInvalidate(); + } + else // Show Start Menu + { + // Uhem + SetStyle(0); + + Rect(canvas, 15, 25, 10, 25, Color.GRAY); + DrawText(canvas, "Start", 15, 20, 50); + + Rect(canvas, 15+2, 25+2, 65, 80, Color.GRAY); + DrawText(canvas, "Style:", 70, 20+2, 50); + + + Rect(canvas, 25+4, 35+4, 65, 80, selectedStyle == 0 ? Color.RED : Color.GRAY); + DrawText(canvas, "Retro", 70, 30+4, 50); + + if ((moveX1 >= 65 && moveX1 <= 80) && (moveY1 >= 25+4 && moveY1 <= 35+4)) + selectedStyle = 0; + + + Rect(canvas, 35+6, 45+6, 65, 80, selectedStyle == 1 ? Color.RED : Color.GRAY); + DrawText(canvas, "Neon", 70, 40+6, 50); + + if ((moveX1 >= 65 && moveX1 <= 80) && (moveY1 >= 35+6 && moveY1 <= 45+6)) + selectedStyle = 1; + + + Rect(canvas, 45+8, 55+8, 65, 80, selectedStyle == 2 ? Color.RED : Color.GRAY); + DrawText(canvas, "Red", 70, 50+8, 50); + + if ((moveX1 >= 65 && moveX1 <= 80) && (moveY1 >= 45+8 && moveY1 <= 55+8)) + selectedStyle = 2; + + + Rect(canvas, 15+2, 25+2, 45, 60, Color.GRAY); + DrawText(canvas, "Bot:", 50, 20+2, 50); + + Rect(canvas, 25+4, 35+4, 45, 60, BotDif == 0 ? Color.RED : Color.GRAY); + DrawText(canvas, "Hard", 50, 30+4, 50); + + if ((moveX1 >= 45 && moveX1 <= 60) && (moveY1 >= 25+4 && moveY1 <= 35+4)) + BotDif = 0; + + + Rect(canvas, 35+6, 45+6, 45, 60, BotDif == 1 ? Color.RED : Color.GRAY); + DrawText(canvas, "Normal", 50, 40+6, 50); + + if ((moveX1 >= 45 && moveX1 <= 60) && (moveY1 >= 35+6 && moveY1 <= 45+6)) + BotDif = 1; + + + Rect(canvas, 45+8, 55+8, 45, 60, BotDif == 2 ? Color.RED : Color.GRAY); + DrawText(canvas, "Easy", 50, 50+8, 50); + + if ((moveX1 >= 45 && moveX1 <= 60) && (moveY1 >= 45+8 && moveY1 <= 55+8)) + BotDif = 2; + + Rect(canvas, 55+10, 65+10, 45, 60, BotDif == 3 ? Color.RED : Color.GRAY); + DrawText(canvas, "Novice", 50, 60+10, 50); + + if ((moveX1 >= 45 && moveX1 <= 60) && (moveY1 >= 55+10 && moveY1 <= 65+10)) + BotDif = 3; + + + Rect(canvas, 65+12, 75+12, 45, 60, BotDif == 4 ? Color.RED : Color.GRAY); + DrawText(canvas, "Off", 50, 70+12, 50); + + if ((moveX1 >= 45 && moveX1 <= 60) && (moveY1 >= 65+12 && moveY1 <= 75+12)) + BotDif = 4; + + + if ((moveX1 >= 15 && moveX1 <= 25) && (moveY1 >= 10 && moveY1 <= 25))// Start Pressed + { + // Set Style + SetStyle(selectedStyle); + + // Set Basic Score And Padle Position + moveY1 = 50; + moveY2 = 50; + + bounceX = bounceY = 40 + (int)(Math.random() * ((60 - 40) + 1)); + bounceY = bounceY = 0 + (int)(Math.random() * ((100 - 0) + 1)); + + speedX = 1; + speedY = 1.1f; + + Player1Life = 3; + Player2Life = 3; + + gamePlaying = true; + } + + this.postInvalidate(); + } + } + + private void SetStyle(int i) + { + // Set Style + switch (i) + { + case 0: + Color_PedleLeft = Color.WHITE; + Color_PedleRight = Color.WHITE; + Color_Ball = Color.RED; + Color_ScoreBar = Color.GRAY; + Color_Footer = Color.GRAY; + Color_Background = Color.BLACK; + Color_Score = Color.WHITE; + break; + case 1: + Color_PedleLeft = Color.MAGENTA; + Color_PedleRight = Color.MAGENTA; + Color_Ball = Color.BLUE; + Color_ScoreBar = Color.YELLOW; + Color_Footer = Color.YELLOW; + Color_Background = Color.CYAN; + Color_Score = Color.RED; + break; + case 2: + Color_PedleLeft = Color.RED; + Color_PedleRight = Color.RED; + Color_Ball = Color.RED; + Color_ScoreBar = Color.RED; + Color_Footer = Color.RED; + Color_Background = Color.LTGRAY; + Color_Score = Color.BLACK; + break; + } + + super.setBackgroundColor(Color_Background); + } + + + private void Bal() + { + if (bounceXdirection) + if (bounceX >= 96 & bounceY >= (moveY1 - (rectangleHeight1/2)) & bounceY <= (moveY1 + (rectangleHeight1/2))) + { + bounceXdirection = !bounceXdirection; + score++; + + // check angle; + //change speed y; + speedY = map( (bounceY - moveY1), -(rectangleHeight2/2), (rectangleHeight2/2), -2f, 2f); + if (speedY <= 0) + { + bounceYdirection = false; + speedY = Math.abs(speedY); + } + else + bounceYdirection = true; + speedX = 3f - speedY; + soundPool.play(Sound_Pling, .5f, .5f, 0, 0, 1); + } + else if (bounceX <= 96) + bounceX += speedX; + else + { + //dead + Player2Life--; + + gameover = true; + } + else if (!bounceXdirection) + if (bounceX <= 4 & bounceY >= (moveY2 - (rectangleHeight2/2)) & bounceY <= (moveY2 + (rectangleHeight2/2))) + { + bounceXdirection = !bounceXdirection; + score++; + // check angle; + //change speed y; + speedY = map( (bounceY - moveY2), -(rectangleHeight2/2), (rectangleHeight2/2), -2f, 2f); + if (speedY <= 0) + { + bounceYdirection = false; + speedY = Math.abs(speedY); + } + else + bounceYdirection = true; + speedX = 3f - speedY; + soundPool.play(Sound_Pling, .5f, .5f, 0, 0, 1); + } + else if (bounceX >= 4) + bounceX -= speedX; + else + { + //dead + Player1Life--; + + gameover = true; + } + + // Y movement + if (bounceYdirection) + if (bounceY < boundaryBottom - 1.5f) + bounceY += speedY; + else + bounceYdirection = !bounceYdirection; + else if (!bounceYdirection) + { + if (bounceY > boundaryTop + 1.5f) + bounceY -= speedY; + else + bounceYdirection = !bounceYdirection; + } + } + + private void Bot() + { + // Bot - hard + + switch (BotDif) + { + case 0: + if (bounceX <= 40) // Left + if (bounceY > moveY2 + .1f + (int)(Math.random() * ((7 - .1f) + 1))) + moveY2 += 1f + (int)(Math.random() * ((5 - 1f) + 1)); + else if (bounceY < moveY2 - .1f + (int)(Math.random() * ((7 - .1f) + 1))) + moveY2 -= 1f + (int)(Math.random() * ((5 - 1f) + 1)); + + if (bounceX >= 60) // Right + if (bounceY > moveY1 + .1f + (int)(Math.random() * ((7 - .1f) + 1))) + moveY1 += 1f + (int)(Math.random() * ((5 - 1f) + 1)); + else if (bounceY < moveY1 - .1f + (int)(Math.random() * ((7 - .1f) + 1))) + moveY1 -= 1f + (int)(Math.random() * ((5 - 1f) + 1)); + break; + + + // Bot - normal + case 1: + if (bounceX <= 40) // Left + if (bounceY > moveY2 + .1f + (int)(Math.random() * ((10 - .1f) + 1))) + moveY2 += 1f + (int)(Math.random() * ((3 - 1f) + 1)); + else if (bounceY < moveY2 - .1f + (int)(Math.random() * ((10 - .1f) + 1))) + moveY2 -= 1f + (int)(Math.random() * ((3 - 1f) + 1)); + + if (bounceX >= 60) // Right + if (bounceY > moveY1 + .1f + (int)(Math.random() * ((10 - .1f) + 1))) + moveY1 += 1f + (int)(Math.random() * ((3 - 1f) + 1)); + else if (bounceY < moveY1 - .1f + (int)(Math.random() * ((10 - .1f) + 1))) + moveY1 -= 1f + (int)(Math.random() * ((3 - 1f) + 1)); + break; + // Bot - easy + + case 2: + if (bounceX <= 40) // Left + if (bounceY > moveY2 + .1f + (int)(Math.random() * ((10 - .1f) + 1))) + moveY2 += .1f + (int)(Math.random() * ((3 - .1f) + 1)); + else if (bounceY < moveY2 - .1f + (int)(Math.random() * ((10 - .1f) + 1))) + moveY2 -= .1f + (int)(Math.random() * ((3 - .1f) + 1)); + + if (bounceX >= 60) // Right + if (bounceY > moveY1 + .1f + (int)(Math.random() * ((10 - .1f) + 1))) + moveY1 += .1f + (int)(Math.random() * ((3 - .1f) + 1)); + else if (bounceY < moveY1 - .1f + (int)(Math.random() * ((10 - .1f) + 1))) + moveY1 -= .1f + (int)(Math.random() * ((3 - .1f) + 1)); + break; + + // Bot - novice + + case 3: + if (bounceX <= 40) // Left + if (bounceY > moveY2 + .1f + (int)(Math.random() * ((10 - .1f) + 1))) + moveY2++; + else if (bounceY < moveY2 - .1f + (int)(Math.random() * ((10 - .1f) + 1))) + moveY2--; + + if (bounceX >= 60) // Right + if (bounceY > moveY1 + .1f + (int)(Math.random() * ((10 - .1f) + 1))) + moveY1++; + else if (bounceY < moveY1 - .1f + (int)(Math.random() * ((10 - .1f) + 1))) + moveY1--; + break; + } + } + + private void DrawFps(Canvas canvas, long newTime) + { + Paint paint = new Paint(); + paint.setColor(Color_Score); + paint.setTextSize(30); + String text = "FPS: " + (1000/(newTime-oldTime)); + canvas.drawText(text, GetRealPixelSize(dpWidth, 5), GetRealPixelSize(dpHeight, 5), paint); + } + + private void DrawText(Canvas canvas, String text, int x) + { + Paint paint = new Paint(); + paint.setColor(Color_Score); + paint.setTextSize(30); + canvas.drawText(text, GetRealPixelSize(dpWidth, x), GetRealPixelSize(dpHeight, 5), paint); + } + + private void DrawText(Canvas canvas, String text, int x, int y, int size) + { + Paint paint = new Paint(); + paint.setColor(Color_Score); + paint.setTextSize(size); + canvas.drawText(text, GetRealPixelSize(dpWidth, x), GetRealPixelSize(dpHeight, y), paint); + } + + private void DrawGameOver(Canvas canvas) + { + Bitmap bitmap = BitmapFactory.decodeResource(getResources(), + R.drawable.gameover); + bitmap = Bitmap.createScaledBitmap(bitmap, (int)GetRealPixelSize(dpWidth, 40), (int)GetRealPixelSize(dpHeight, 20), false); + canvas.drawBitmap(bitmap, (int)GetRealPixelSize(dpWidth, 30), (int)GetRealPixelSize(dpHeight, 40), null); + + // Which Player Won? Player1Life + if (Player1Life < 0) + { + bitmap = BitmapFactory.decodeResource(getResources(), + R.drawable.player2); + bitmap = Bitmap.createScaledBitmap(bitmap, (int)GetRealPixelSize(dpWidth, 40), (int)GetRealPixelSize(dpHeight, 20), false); + canvas.drawBitmap(bitmap, (int)GetRealPixelSize(dpWidth, 30), (int)GetRealPixelSize(dpHeight, 55), null); + } + else + { + bitmap = BitmapFactory.decodeResource(getResources(), + R.drawable.player1); + bitmap = Bitmap.createScaledBitmap(bitmap, (int)GetRealPixelSize(dpWidth, 40), (int)GetRealPixelSize(dpHeight, 20), false); + canvas.drawBitmap(bitmap, (int)GetRealPixelSize(dpWidth, 30), (int)GetRealPixelSize(dpHeight, 55), null); + } + } + + float map(float x, float in_min, float in_max, float out_min, float out_max) + { + return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; + } + + private void ScoreBar(Canvas canvas, float Bottom) + { + Paint paint = new Paint(); + paint.setAntiAlias(true); + paint.setColor(Color_ScoreBar); + paint.setStyle(Style.FILL); + + // Style Square + canvas.drawRect( + GetRealPixelSize(dpWidth, 0), + GetRealPixelSize(dpHeight, 0), + GetRealPixelSize(dpWidth, 100), + GetRealPixelSize(dpHeight, Bottom), paint); + } + + private void Footer(Canvas canvas, float Top) + { + Paint paint = new Paint(); + paint.setAntiAlias(true); + paint.setColor(Color_Footer); + paint.setStyle(Style.FILL); + + // Style Square + canvas.drawRect( + GetRealPixelSize(dpWidth, 0), + GetRealPixelSize(dpHeight, Top), + GetRealPixelSize(dpWidth, 100), + GetRealPixelSize(dpHeight, 100), paint); + } + + private void drawPeddleRight(Canvas canvas) { + Paint paint = new Paint(); + paint.setAntiAlias(true); + paint.setColor(Color_PedleRight); + paint.setStyle(Style.FILL); + + float rectangleWidth = 2; + rectangleHeight1 = 20; + + moveY1 = moveY1 <= (boundaryBottom - (rectangleHeight1 / 2)) ? moveY1 : (boundaryBottom - (rectangleHeight1 / 2)); + moveY1 = moveY1 >= (rectangleHeight1 / 2) + boundaryTop ? moveY1 : (rectangleHeight1 / 2) + boundaryTop; + + float xPosition = 97; + float yPosition = moveY1; + + // Style Square/Round + if (!StyleRound) + canvas.drawRect( + GetRealPixelSize(dpWidth, xPosition), + GetRealPixelSize(dpHeight, yPosition - (rectangleHeight1 / 2)), + GetRealPixelSize(dpWidth, xPosition + (rectangleWidth)), + GetRealPixelSize(dpHeight, yPosition + (rectangleHeight1 / 2)), paint); + else + { + RectF rect=new RectF( + GetRealPixelSize(dpWidth, xPosition), + GetRealPixelSize(dpHeight, yPosition - (rectangleHeight1 / 2)), + GetRealPixelSize(dpWidth, xPosition + (rectangleWidth)), + GetRealPixelSize(dpHeight, yPosition + (rectangleHeight1 / 2))); + + canvas.drawRoundRect(rect, 20,20, paint); + } + } + + private void Rect(Canvas canvas, float Top, float Bottom, float Left, float Right, int Color) + { + Paint paint = new Paint(); + paint.setAntiAlias(true); + paint.setColor(Color); + paint.setStyle(Style.FILL); + + // Style Square + canvas.drawRect( + GetRealPixelSize(dpWidth, Left), + GetRealPixelSize(dpHeight, Top), + GetRealPixelSize(dpWidth, Right), + GetRealPixelSize(dpHeight, Bottom), paint); + } + + private void drawPeddleLeft(Canvas canvas) { + Paint paint = new Paint(); + paint.setAntiAlias(true); + paint.setColor(Color_PedleLeft); + paint.setStyle(Style.FILL); + + float rectangleWidth = 2; + rectangleHeight2 = 20; + + moveY2 = moveY2 <= (boundaryBottom - (rectangleHeight2 / 2)) ? moveY2 : (boundaryBottom - (rectangleHeight2 / 2)); + moveY2 = moveY2 >= (rectangleHeight2 / 2) + boundaryTop ? moveY2 : (rectangleHeight2 / 2) + boundaryTop; + + float xPosition = 3; + float yPosition = moveY2; + + // Style Square/Round + if (!StyleRound) + canvas.drawRect( + GetRealPixelSize(dpWidth, xPosition - (rectangleWidth)), + GetRealPixelSize(dpHeight, yPosition - (rectangleHeight2 / 2)), + GetRealPixelSize(dpWidth, xPosition), + GetRealPixelSize(dpHeight, yPosition + (rectangleHeight2 / 2)), paint); + else + { + RectF rect=new RectF( + GetRealPixelSize(dpWidth, xPosition - (rectangleWidth)), + GetRealPixelSize(dpHeight, yPosition - (rectangleHeight2 / 2)), + GetRealPixelSize(dpWidth, xPosition), + GetRealPixelSize(dpHeight, yPosition + (rectangleHeight2 / 2))); + + canvas.drawRoundRect(rect, 20,20, paint); + } + } + + private void drawCircle(Canvas canvas, float xPosition, float yPosition) { + Paint paint = new Paint(); + paint.setAntiAlias(true); + paint.setColor(Color_Ball); + paint.setStyle(Style.FILL); + canvas.drawCircle(GetRealPixelSize(dpWidth, xPosition), GetRealPixelSize(dpHeight, yPosition), GetRealPixelSize(dpWidth, 1), paint); + } + + private float GetRealPixelSize(float dpWH, float DIP) + { + return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, (dpWH * ( DIP / 100 )), r.getDisplayMetrics()); + } + + public void sendMove(float x, float y) + { + if (!gamePlaying) + { + moveX1 = (x / Width) * 100; + moveY1 = (y / Height) * 100; + } + else if (x / Width >= 0.6f) + { + moveX1 = (x / Width) * 100; + moveY1 = (y / Height) * 100; + } + else if (x / Width <= 0.4f) + { + moveX2 = (x / Width) * 100; + moveY2 = (y / Height) * 100; + } + } + + public void SetGameState(boolean b) + { + gamePlaying = false; + } +} \ No newline at end of file diff --git a/src/mangavalk/canvasfirsttry/MainActivity.java b/src/mangavalk/canvasfirsttry/MainActivity.java new file mode 100644 index 0000000..d7c9134 --- /dev/null +++ b/src/mangavalk/canvasfirsttry/MainActivity.java @@ -0,0 +1,92 @@ + +package mangavalk.canvasfirsttry; + +import android.app.Activity; +import android.graphics.PointF; +import android.os.Bundle; +import android.util.SparseArray; +import android.view.MotionEvent; + +public class MainActivity extends Activity +{ + CanvasView canvasClass; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + canvasClass = new CanvasView(this); + setContentView(canvasClass); + mActivePointers = new SparseArray(); + canvasClass.SetActivity(this); + } + + private SparseArray mActivePointers; + + @Override + public boolean onTouchEvent(MotionEvent e) { + // MotionEvent reports input details from the touch screen + // and other input controls. In this case, you are only + // interested in events where the touch position changed. + + // get pointer index from the event object + int pointerIndex = e.getActionIndex(); + + // get pointer ID + int pointerId = e.getPointerId(pointerIndex); + + // get masked (not specific to a pointer) action + int maskedAction = e.getActionMasked(); + + switch (maskedAction) { + + case MotionEvent.ACTION_DOWN: + case MotionEvent.ACTION_POINTER_DOWN: { + // We have a new pointer. Lets add it to the list of pointers + + PointF f = new PointF(); + f.x = e.getX(pointerIndex); + f.y = e.getY(pointerIndex); + mActivePointers.put(pointerId, f); + + for (int size = e.getPointerCount(), i = 0; i < size; i++) { + PointF point = mActivePointers.get(e.getPointerId(i)); + if (point != null) { + point.x = e.getX(i); + point.y = e.getY(i); + canvasClass.sendMove(point.x, point.y); + } + } + + break; + } + case MotionEvent.ACTION_MOVE: { // a pointer was moved + for (int size = e.getPointerCount(), i = 0; i < size; i++) { + PointF point = mActivePointers.get(e.getPointerId(i)); + if (point != null) { + point.x = e.getX(i); + point.y = e.getY(i); + canvasClass.sendMove(point.x, point.y); + } + } + break; + } + case MotionEvent.ACTION_UP: + break; + case MotionEvent.ACTION_POINTER_UP: + break; + case MotionEvent.ACTION_CANCEL: { + // TODO use data + break; + } + } + + + return true; + } + + @Override + public void onBackPressed() + { + canvasClass.SetGameState(false); + } +}