First steps with Android
authorgumartinm <gu.martinm@gmail.com>
Wed, 2 Nov 2011 01:43:13 +0000 (02:43 +0100)
committergumartinm <gu.martinm@gmail.com>
Wed, 2 Nov 2011 01:43:13 +0000 (02:43 +0100)
14 files changed:
AndroidTetris/AndroidManifest.xml [new file with mode: 0644]
AndroidTetris/default.properties [new file with mode: 0644]
AndroidTetris/gen/de/android/androidtetris/R.java [new file with mode: 0644]
AndroidTetris/proguard.cfg [new file with mode: 0644]
AndroidTetris/res/drawable-hdpi/icon.png [new file with mode: 0644]
AndroidTetris/res/drawable-ldpi/icon.png [new file with mode: 0644]
AndroidTetris/res/drawable-mdpi/icon.png [new file with mode: 0644]
AndroidTetris/res/drawable/greenstar.png [new file with mode: 0644]
AndroidTetris/res/drawable/redstar.png [new file with mode: 0644]
AndroidTetris/res/drawable/yellowstar.png [new file with mode: 0644]
AndroidTetris/res/layout/main.xml [new file with mode: 0644]
AndroidTetris/res/values/strings.xml [new file with mode: 0644]
AndroidTetris/src/de/android/androidtetris/AndroidTetrisActivity.java [new file with mode: 0644]
AndroidTetris/src/de/android/androidtetris/DrawView.java [new file with mode: 0644]

diff --git a/AndroidTetris/AndroidManifest.xml b/AndroidTetris/AndroidManifest.xml
new file mode 100644 (file)
index 0000000..217d49f
--- /dev/null
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="utf-8"?>
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+      package="de.android.androidtetris"
+      android:versionCode="1"
+      android:versionName="1.0">
+    <uses-sdk android:minSdkVersion="13" />
+
+    <application android:icon="@drawable/icon" android:label="@string/app_name">
+        <activity android:name=".AndroidTetrisActivity"
+                  android:label="@string/app_name">
+            <intent-filter>
+                <action android:name="android.intent.action.MAIN" />
+                <category android:name="android.intent.category.LAUNCHER" />
+            </intent-filter>
+        </activity>
+
+    </application>
+</manifest>
\ No newline at end of file
diff --git a/AndroidTetris/default.properties b/AndroidTetris/default.properties
new file mode 100644 (file)
index 0000000..ac9e1a0
--- /dev/null
@@ -0,0 +1,11 @@
+# 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 use,
+# "build.properties", and override values to adapt the script to your
+# project structure.
+
+# Project target.
+target=android-13
diff --git a/AndroidTetris/gen/de/android/androidtetris/R.java b/AndroidTetris/gen/de/android/androidtetris/R.java
new file mode 100644 (file)
index 0000000..17497a4
--- /dev/null
@@ -0,0 +1,26 @@
+/* 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 de.android.androidtetris;
+
+public final class R {
+    public static final class attr {
+    }
+    public static final class drawable {
+        public static final int greenstar=0x7f020000;
+        public static final int icon=0x7f020001;
+        public static final int redstar=0x7f020002;
+        public static final int yellowstar=0x7f020003;
+    }
+    public static final class layout {
+        public static final int main=0x7f030000;
+    }
+    public static final class string {
+        public static final int app_name=0x7f040001;
+        public static final int hello=0x7f040000;
+    }
+}
diff --git a/AndroidTetris/proguard.cfg b/AndroidTetris/proguard.cfg
new file mode 100644 (file)
index 0000000..b1cdf17
--- /dev/null
@@ -0,0 +1,40 @@
+-optimizationpasses 5
+-dontusemixedcaseclassnames
+-dontskipnonpubliclibraryclasses
+-dontpreverify
+-verbose
+-optimizations !code/simplification/arithmetic,!field/*,!class/merging/*
+
+-keep public class * extends android.app.Activity
+-keep public class * extends android.app.Application
+-keep public class * extends android.app.Service
+-keep public class * extends android.content.BroadcastReceiver
+-keep public class * extends android.content.ContentProvider
+-keep public class * extends android.app.backup.BackupAgentHelper
+-keep public class * extends android.preference.Preference
+-keep public class com.android.vending.licensing.ILicensingService
+
+-keepclasseswithmembernames class * {
+    native <methods>;
+}
+
+-keepclasseswithmembers class * {
+    public <init>(android.content.Context, android.util.AttributeSet);
+}
+
+-keepclasseswithmembers class * {
+    public <init>(android.content.Context, android.util.AttributeSet, int);
+}
+
+-keepclassmembers class * extends android.app.Activity {
+   public void *(android.view.View);
+}
+
+-keepclassmembers enum * {
+    public static **[] values();
+    public static ** valueOf(java.lang.String);
+}
+
+-keep class * implements android.os.Parcelable {
+  public static final android.os.Parcelable$Creator *;
+}
diff --git a/AndroidTetris/res/drawable-hdpi/icon.png b/AndroidTetris/res/drawable-hdpi/icon.png
new file mode 100644 (file)
index 0000000..8074c4c
Binary files /dev/null and b/AndroidTetris/res/drawable-hdpi/icon.png differ
diff --git a/AndroidTetris/res/drawable-ldpi/icon.png b/AndroidTetris/res/drawable-ldpi/icon.png
new file mode 100644 (file)
index 0000000..1095584
Binary files /dev/null and b/AndroidTetris/res/drawable-ldpi/icon.png differ
diff --git a/AndroidTetris/res/drawable-mdpi/icon.png b/AndroidTetris/res/drawable-mdpi/icon.png
new file mode 100644 (file)
index 0000000..a07c69f
Binary files /dev/null and b/AndroidTetris/res/drawable-mdpi/icon.png differ
diff --git a/AndroidTetris/res/drawable/greenstar.png b/AndroidTetris/res/drawable/greenstar.png
new file mode 100644 (file)
index 0000000..26be5c8
Binary files /dev/null and b/AndroidTetris/res/drawable/greenstar.png differ
diff --git a/AndroidTetris/res/drawable/redstar.png b/AndroidTetris/res/drawable/redstar.png
new file mode 100644 (file)
index 0000000..e9c0947
Binary files /dev/null and b/AndroidTetris/res/drawable/redstar.png differ
diff --git a/AndroidTetris/res/drawable/yellowstar.png b/AndroidTetris/res/drawable/yellowstar.png
new file mode 100644 (file)
index 0000000..134b234
Binary files /dev/null and b/AndroidTetris/res/drawable/yellowstar.png differ
diff --git a/AndroidTetris/res/layout/main.xml b/AndroidTetris/res/layout/main.xml
new file mode 100644 (file)
index 0000000..3a5f117
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="utf-8"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+    android:orientation="vertical"
+    android:layout_width="fill_parent"
+    android:layout_height="fill_parent"
+    >
+<TextView  
+    android:layout_width="fill_parent" 
+    android:layout_height="wrap_content" 
+    android:text="@string/hello"
+    />
+</LinearLayout>
diff --git a/AndroidTetris/res/values/strings.xml b/AndroidTetris/res/values/strings.xml
new file mode 100644 (file)
index 0000000..8c45b4c
--- /dev/null
@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="utf-8"?>
+<resources>
+    <string name="hello">Hello World, AndroidTetrisActivity!</string>
+    <string name="app_name">AndroidTetris</string>
+</resources>
diff --git a/AndroidTetris/src/de/android/androidtetris/AndroidTetrisActivity.java b/AndroidTetris/src/de/android/androidtetris/AndroidTetrisActivity.java
new file mode 100644 (file)
index 0000000..d74dbda
--- /dev/null
@@ -0,0 +1,22 @@
+package de.android.androidtetris;
+
+import android.app.Activity;
+import android.os.Bundle;
+import android.util.DisplayMetrics;
+
+public class AndroidTetrisActivity extends Activity {
+       DrawView drawView;
+    /** Called when the activity is first created. */
+    @Override
+    public void onCreate(Bundle savedInstanceState) {
+        super.onCreate(savedInstanceState);
+        DisplayMetrics displayMetrics = new DisplayMetrics();
+        this.getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
+        
+        setContentView(R.layout.main);
+        drawView = new DrawView(this);
+        drawView.setDimensions(displayMetrics.widthPixels, displayMetrics.heightPixels);
+        this.setContentView(drawView);
+        drawView.requestFocus();
+    }
+}
\ No newline at end of file
diff --git a/AndroidTetris/src/de/android/androidtetris/DrawView.java b/AndroidTetris/src/de/android/androidtetris/DrawView.java
new file mode 100644 (file)
index 0000000..84264ee
--- /dev/null
@@ -0,0 +1,67 @@
+/**
+ * 
+ */
+package de.android.androidtetris;
+
+import android.content.Context;
+import android.content.res.Resources;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.graphics.Color;
+import android.graphics.Paint;
+import android.graphics.drawable.Drawable;
+import android.view.View;
+
+/**
+ * @author gustavo
+ *
+ */
+public class DrawView extends View {
+       Paint paint = new Paint();
+       private int width;
+       private int height;
+       private static final int WIDTH = 50;
+       private static final int HEIGHT = 50;
+       private static final int STRIDE = 64;   //
+       
+       DrawView(Context context)
+       {
+               super(context);
+               paint.setColor(Color.RED);
+               paint.setAntiAlias(true);
+       }
+       
+       @Override
+       public void onDraw(Canvas canvas)
+       {
+               super.onDraw(canvas);
+                int[] colors = new int[STRIDE * HEIGHT];
+               for (int y = 0; y < HEIGHT; y++) {
+                   for (int x = 0; x < WIDTH; x++) {
+                       int r = x * 255 / (WIDTH - 1);
+                       int g = y * 255 / (HEIGHT - 1);
+                       int b = 255 - Math.min(r, g);
+                       int a = Math.max(r, g);
+                       colors[y * STRIDE + x] = (a << 24) | (r << 16) | (g << 8) | b;
+                   }
+               }
+               //Resources r = this.getContext().getResources();
+               Bitmap bitmap = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888);
+               bitmap.setPixels(colors, 0, STRIDE, 0, 0, WIDTH, HEIGHT);
+               Bitmap bitmapnew = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888);
+               bitmapnew.setPixels(colors, 0, STRIDE, 0, 0, WIDTH, HEIGHT);
+               //Canvas canvasnew = new Canvas(bitmap);
+               //Drawable tile = r.getDrawable(R.drawable.greenstar);
+               //tile.setBounds(1000, 1000, 1000, 1000);
+               //tile.draw(canvasnew);
+               canvas.drawBitmap(bitmap, 150, 150, this.paint);
+               canvas.drawBitmap(bitmapnew, 300, 300, this.paint);
+               //canvas.drawCircle(150, 150, 100, paint);
+       }
+       
+       public void setDimensions(int width, int height)
+       {
+               this.width = width;
+               this.height = height;
+       }
+}
\ No newline at end of file