• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Android Samples


Commit MetaInfo

Revisión3ae013398aed159da8964bdb005a83fe9cf45ae1 (tree)
Tiempo2013-10-08 18:01:36
AutorMasahiko, SAWAI <say@user...>
CommiterMasahiko, SAWAI

Log Message

Added two projects

* view-custom-drawing-animation
* view-custom-drawing-hello

Cambiar Resumen

Diferencia incremental

--- a/android-app-hello/pom.xml
+++ b/android-app-hello/pom.xml
@@ -1,6 +1,8 @@
11 <?xml version="1.0" encoding="UTF-8" ?>
2-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
2+<project
3+ xmlns="http://maven.apache.org/POM/4.0.0"
4+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
46 >
57 <modelVersion>4.0.0</modelVersion>
68 <groupId>com.example.hello</groupId>
--- a/pom.xml
+++ b/pom.xml
@@ -73,6 +73,8 @@
7373 <module>searchview-in-actionbar-collapse</module>
7474 <module>searchview-recent-query-suggestion</module>
7575 <module>view-composite-hello</module>
76+ <module>view-custom-drawing-animation</module>
77+ <module>view-custom-drawing-hello</module>
7678 <module>wifi-state-get</module>
7779 <module>wifi-state-receiver</module>
7880 </modules>
--- /dev/null
+++ b/view-custom-drawing-animation/AndroidManifest.xml
@@ -0,0 +1,19 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<manifest
3+ xmlns:android="http://schemas.android.com/apk/res/android"
4+ package="com.example.hello.android.view_custom_drawing_animation"
5+ android:versionCode="1"
6+ android:versionName="1.0"
7+>
8+ <application android:label="@string/app_name">
9+ <activity
10+ android:name=".MainActivity"
11+ android:label="@string/app_name"
12+ >
13+ <intent-filter>
14+ <action android:name="android.intent.action.MAIN" />
15+ <category android:name="android.intent.category.LAUNCHER" />
16+ </intent-filter>
17+ </activity>
18+ </application>
19+</manifest>
--- /dev/null
+++ b/view-custom-drawing-animation/Makefile
@@ -0,0 +1,46 @@
1+
2+all : package
3+
4+#################### build
5+
6+compile :
7+ mvn $@
8+
9+gen :
10+ mvn android:generate-sources
11+
12+package :
13+ mvn $@
14+
15+release :
16+ mvn clean -Prelease package
17+
18+install :
19+ mvn $@
20+
21+deploy :
22+ mvn package android:deploy
23+
24+undeploy :
25+ mvn android:undeploy
26+
27+rebuild :
28+ mvn clean package
29+
30+redeploy :
31+ mvn clean package android:deploy
32+
33+#################### emulator
34+
35+start :
36+ mvn android:emulator-start
37+
38+stop :
39+ mvn android:emulator-stop
40+
41+####################
42+dist :
43+ mvn assembly:assembly
44+
45+clean :
46+ mvn $@
--- /dev/null
+++ b/view-custom-drawing-animation/README.txt
@@ -0,0 +1,24 @@
1+! view-custom-drawing-animation
2+
3+アニメーションをするカスタムビューのサンプル。
4+
5+View を継承して LineArt を描画するカスタムビューを作成。
6+LineArt はアニメーションするために、Activity から View#invalidate() を
7+呼び出す Task を作成して定期的に実行させることでアニメーションしている。
8+
9+
10+!! ビルドターゲット
11+
12+http://maven-android-plugin-m2site.googlecode.com/svn/plugin-info.html
13+
14+* mvn compile - アプリケーションのコンパイル
15+* mvn package - apk の作成
16+* mvn clean - ビルドファイルの削除
17+* mvn install - maven の local リポジトリにインストール
18+
19+* mvn android:deploy - エミュレータやデバイスにインストール
20+* mvn android:generate-sources
21+
22+* mvn install - アプリケーションのインストール
23+* mvn uninstall - アプリケーションのアンインストール
24+
--- /dev/null
+++ b/view-custom-drawing-animation/pom.xml
@@ -0,0 +1,143 @@
1+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
3+ <modelVersion>4.0.0</modelVersion>
4+ <groupId>com.example.hello</groupId>
5+ <artifactId>view-custom-drawing-animation</artifactId>
6+ <packaging>apk</packaging>
7+ <version>1.0.0</version>
8+ <name>View Custom Drawing Animation</name>
9+ <url>http://www.example.com/</url>
10+
11+ <parent>
12+ <groupId>com.example.hello</groupId>
13+ <artifactId>android-samples</artifactId>
14+ <version>1.0.0</version>
15+ </parent>
16+
17+ <dependencies>
18+ <dependency>
19+ <groupId>com.google.android</groupId>
20+ <artifactId>android</artifactId>
21+ <version>1.5_r4</version>
22+ <!--
23+ <version>1.5_r3</version>
24+ <version>1.5_r4</version>
25+ <version>1.6_r2</version>
26+ <version>2.1.2</version>
27+ <version>2.1_r1</version>
28+ <version>2.2.1</version>
29+ <version>2.3.1</version>
30+ -->
31+ <scope>provided</scope>
32+ </dependency>
33+
34+ <dependency>
35+ <groupId>junit</groupId>
36+ <artifactId>junit</artifactId>
37+ <version>3.8.1</version>
38+ <scope>test</scope>
39+ </dependency>
40+ </dependencies>
41+
42+ <build>
43+ <sourceDirectory>src</sourceDirectory>
44+
45+ <plugins>
46+ <plugin>
47+ <groupId>com.jayway.maven.plugins.android.generation2</groupId>
48+ <artifactId>android-maven-plugin</artifactId>
49+ <configuration>
50+ <sdk>
51+ <path>${env.ANDROID_HOME}</path>
52+ <!-- <path>C:/Java/android-sdk</path> -->
53+ <platform>8</platform>
54+ </sdk>
55+ <proguard>
56+ <skip>true</skip>
57+ <config>proguard.conf</config>
58+ </proguard>
59+ <extractDuplicates>true</extractDuplicates>
60+ </configuration>
61+ <extensions>true</extensions>
62+ </plugin>
63+
64+ <!-- mvn compile -->
65+ <plugin>
66+ <groupId>org.apache.maven.plugins</groupId>
67+ <artifactId>maven-compiler-plugin</artifactId>
68+ <configuration>
69+ <source>1.5</source>
70+ <target>1.5</target>
71+ <encoding>UTF-8</encoding>
72+ </configuration>
73+ </plugin>
74+
75+ <!-- mvn assembly:assembly -->
76+ <plugin>
77+ <groupId>org.apache.maven.plugins</groupId>
78+ <artifactId>maven-assembly-plugin</artifactId>
79+ <configuration>
80+ <descriptorRefs>
81+ <!--
82+ <descriptorRef>jar-with-dependencies</descriptorRef>
83+ <descriptorRef>bin</descriptorRef>
84+ <descriptorRef>src</descriptorRef>
85+ -->
86+ <descriptorRef>project</descriptorRef>
87+ </descriptorRefs>
88+ </configuration>
89+ </plugin>
90+
91+ <!-- mvn resources:resources -->
92+ <plugin>
93+ <groupId>org.apache.maven.plugins</groupId>
94+ <artifactId>maven-resources-plugin</artifactId>
95+ <configuration>
96+ <encoding>UTF-8</encoding>
97+ </configuration>
98+ </plugin>
99+
100+ <!-- mvn site -->
101+ <plugin>
102+ <groupId>org.apache.maven.plugins</groupId>
103+ <artifactId>maven-site-plugin</artifactId>
104+ <configuration>
105+ <locales>en</locales>
106+ <inputEncoding>UTF-8</inputEncoding>
107+ <outputEncoding>UTF-8</outputEncoding>
108+
109+ <reportPlugins>
110+ <plugin>
111+ <groupId>org.apache.maven.plugins</groupId>
112+ <artifactId>maven-project-info-reports-plugin</artifactId>
113+ </plugin>
114+
115+ <!-- mvn javadoc:javadoc -->
116+ <plugin>
117+ <groupId>org.apache.maven.plugins</groupId>
118+ <artifactId>maven-javadoc-plugin</artifactId>
119+ <configuration>
120+ <charset>utf-8</charset>
121+ </configuration>
122+ </plugin>
123+ </reportPlugins>
124+ </configuration>
125+ </plugin>
126+
127+ </plugins>
128+
129+ <!-- mvn resources:resources -->
130+ <resources>
131+ <resource>
132+ <directory>res</directory>
133+ <filtering>false</filtering>
134+ <includes>
135+ <include>**/*.properties</include>
136+ </includes>
137+ </resource>
138+ </resources>
139+ </build>
140+
141+
142+
143+</project>
--- /dev/null
+++ b/view-custom-drawing-animation/res/values/strings.xml
@@ -0,0 +1,4 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<resources>
3+ <string name="app_name">Drawing Animation</string>
4+</resources>
--- /dev/null
+++ b/view-custom-drawing-animation/src/com/example/hello/android/view_custom_drawing_animation/LineArt.java
@@ -0,0 +1,261 @@
1+/*
2+ * The MIT License
3+ *
4+ * Copyright 2013 Masahiko, SAWAI <masahiko.sawai@gmail.com>.
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ */
24+package com.example.hello.android.view_custom_drawing_animation;
25+
26+import android.graphics.Canvas;
27+import android.graphics.Color;
28+import android.graphics.Paint;
29+import java.io.Serializable;
30+import java.util.Arrays;
31+import java.util.Random;
32+
33+/**
34+ *
35+ * @author sawai
36+ */
37+public class LineArt implements Serializable
38+{
39+
40+ public static final Random RANDOM = new Random();
41+ public static final int NUMBER_OF_LINES = 20;
42+ public static final float SCREEN_WIDTH = 100.0f;
43+ public static final float SCREEN_HEGHT = 100.0f;
44+ public static final int MAX_SPEED = 2;
45+ private int numberOfLines;
46+ private Line lines[];
47+ private int colors[];
48+ private int currentIndex;
49+ private PointMover mover1, mover2;
50+ private PointColorChanger pointColor;
51+
52+ public LineArt(int numberOfLines)
53+ {
54+ this.numberOfLines = numberOfLines;
55+ this.lines = new Line[numberOfLines];
56+ for (int i = 0; i < numberOfLines; i++)
57+ {
58+ this.lines[i] = new Line(0, 0, 0, 0);
59+ }
60+ this.colors = new int[numberOfLines];
61+ Arrays.fill(colors, Color.TRANSPARENT);
62+ this.currentIndex = 0;
63+ float x, y, dx, dy;
64+ x = RANDOM.nextFloat() * SCREEN_WIDTH;
65+ y = RANDOM.nextFloat() * SCREEN_HEGHT;
66+ dx = RANDOM.nextFloat() / 2.0f + 0.5f;
67+ dx *= RANDOM.nextBoolean() ? MAX_SPEED : -MAX_SPEED;
68+ dy = RANDOM.nextFloat() / 2.0f + 0.5f;
69+ dy *= RANDOM.nextBoolean() ? MAX_SPEED : -MAX_SPEED;
70+ mover1 = new PointMover(x, y, dx, dy);
71+
72+ x = RANDOM.nextFloat() * SCREEN_WIDTH;
73+ y = RANDOM.nextFloat() * SCREEN_HEGHT;
74+ dx = RANDOM.nextFloat();
75+ dx *= RANDOM.nextBoolean() ? MAX_SPEED : -MAX_SPEED;
76+ dy = RANDOM.nextFloat();
77+ dy *= RANDOM.nextBoolean() ? MAX_SPEED : -MAX_SPEED;
78+ mover2 = new PointMover(x, y, dx, dy);
79+
80+ pointColor = new PointColorChanger();
81+ }
82+
83+ public LineArt()
84+ {
85+ this(NUMBER_OF_LINES);
86+ }
87+
88+ public void update()
89+ {
90+ mover1.update();
91+ mover2.update();
92+ pointColor.update();
93+
94+ lines[currentIndex].p1.set(mover1.p);
95+ lines[currentIndex].p2.set(mover2.p);
96+ colors[currentIndex] = pointColor.toColor();
97+ currentIndex = (currentIndex + 1) % numberOfLines;
98+ }
99+
100+ public void draw(Canvas canvas)
101+ {
102+ Paint bg = new Paint();
103+ bg.setColor(Color.BLACK);
104+ bg.setStyle(Paint.Style.FILL);
105+ Paint fg = new Paint();
106+ fg.setColor(Color.WHITE);
107+
108+ float scaleX = (float) canvas.getWidth() / SCREEN_WIDTH;
109+ float scaleY = (float) canvas.getHeight() / SCREEN_HEGHT;
110+ canvas.save();
111+ canvas.scale(scaleX, scaleY);
112+ canvas.drawRect(0, 0, SCREEN_WIDTH, SCREEN_HEGHT, bg);
113+ for (int i = 0; i < numberOfLines; i++)
114+ {
115+ Line line = lines[i];
116+ int color = colors[i];
117+ fg.setColor(color);
118+ canvas.drawLine(line.p1.x, line.p1.y, line.p2.x, line.p2.y, fg);
119+ }
120+ canvas.restore();
121+ }
122+
123+ class Point implements Serializable
124+ {
125+
126+ float x;
127+ float y;
128+
129+ public Point(float x, float y)
130+ {
131+ this.x = x;
132+ this.y = y;
133+ }
134+
135+ public void set(Point p)
136+ {
137+ x = p.x;
138+ y = p.y;
139+ }
140+ }
141+
142+ class Line implements Serializable
143+ {
144+
145+ Point p1;
146+ Point p2;
147+
148+ public Line(int x1, int y1, int x2, int y2)
149+ {
150+ this.p1 = new Point(x1, y1);
151+ this.p2 = new Point(x2, y2);
152+ }
153+ }
154+
155+ class PointMover implements Serializable
156+ {
157+
158+ Point p;
159+ float dx, dy;
160+
161+ public PointMover(float x, float y, float dx, float dy)
162+ {
163+ p = new Point(x, y);
164+ this.dx = dx;
165+ this.dy = dy;
166+ }
167+
168+ public void update()
169+ {
170+ p.x += dx;
171+ if (p.x < 0)
172+ {
173+ p.x = -p.x;
174+ dx = -dx;
175+ }
176+ else if (p.x > SCREEN_WIDTH)
177+ {
178+ p.x = SCREEN_WIDTH * 2 - p.x;
179+ dx = -dx;
180+ }
181+ p.y += dy;
182+ if (p.y < 0)
183+ {
184+ p.y = -p.y;
185+ dy = -dy;
186+ }
187+ else if (p.y > SCREEN_HEGHT)
188+ {
189+ p.y = SCREEN_HEGHT * 2 - p.y;
190+ dy = -dy;
191+ }
192+ }
193+ }
194+
195+ class PointColorChanger implements Serializable
196+ {
197+
198+ static final int MAX_SPEED = 5;
199+ static final int MAX_VALUE = 0xff;
200+ static final int MIN_VALUE = 0x7f;
201+ int r, g, b;
202+ int dr, dg, db;
203+
204+ public PointColorChanger()
205+ {
206+ this.r = RANDOM.nextInt(256);
207+ this.g = RANDOM.nextInt(256);
208+ this.b = RANDOM.nextInt(256);
209+ this.dr = RANDOM.nextInt(MAX_SPEED) + 1;
210+ this.dr *= RANDOM.nextBoolean() ? 1 : -1;
211+ this.dg = RANDOM.nextInt(MAX_SPEED) + 1;
212+ this.dg *= RANDOM.nextBoolean() ? 1 : -1;
213+ this.db = RANDOM.nextInt(MAX_SPEED) + 1;
214+ this.db *= RANDOM.nextBoolean() ? 1 : -1;
215+ }
216+
217+ public void update()
218+ {
219+ r += dr;
220+ if (r < MIN_VALUE)
221+ {
222+ r = MIN_VALUE;
223+ dr = -dr;
224+ }
225+ else if (r > MAX_VALUE)
226+ {
227+ r = MAX_VALUE;
228+ dr = -dr;
229+ }
230+
231+ g += dg;
232+ if (g <= MIN_VALUE)
233+ {
234+ g = MIN_VALUE;
235+ dg = -dg;
236+ }
237+ else if (g > MAX_VALUE)
238+ {
239+ g = MAX_VALUE;
240+ dg = -dg;
241+ }
242+
243+ b += db;
244+ if (b <= MIN_VALUE)
245+ {
246+ b = MIN_VALUE;
247+ db = -db;
248+ }
249+ else if (b > MAX_VALUE)
250+ {
251+ b = MAX_VALUE;
252+ db = -db;
253+ }
254+ }
255+
256+ public int toColor()
257+ {
258+ return Color.rgb(r, g, b);
259+ }
260+ }
261+}
--- /dev/null
+++ b/view-custom-drawing-animation/src/com/example/hello/android/view_custom_drawing_animation/LineArtView.java
@@ -0,0 +1,61 @@
1+/*
2+ * The MIT License
3+ *
4+ * Copyright 2013 Masahiko, SAWAI <masahiko.sawai@gmail.com>.
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ */
24+package com.example.hello.android.view_custom_drawing_animation;
25+
26+import android.content.Context;
27+import android.graphics.Canvas;
28+import android.util.Log;
29+import android.view.View;
30+
31+public class LineArtView extends View
32+{
33+
34+ private static final String LOG_TAG = "XXX";
35+ private LineArt lineArt;
36+
37+ public LineArtView(Context context)
38+ {
39+ super(context);
40+ Log.d(LOG_TAG, "new CanvasView()");
41+ }
42+
43+ @Override
44+ protected void onDraw(Canvas canvas)
45+ {
46+ super.onDraw(canvas);
47+// Log.d(LOG_TAG, "onDraw()");
48+ lineArt.update();
49+ lineArt.draw(canvas);
50+ }
51+
52+ public LineArt getLineArt()
53+ {
54+ return lineArt;
55+ }
56+
57+ public void setLineArt(LineArt lineArt)
58+ {
59+ this.lineArt = lineArt;
60+ }
61+}
--- /dev/null
+++ b/view-custom-drawing-animation/src/com/example/hello/android/view_custom_drawing_animation/MainActivity.java
@@ -0,0 +1,133 @@
1+/*
2+ * The MIT License
3+ *
4+ * Copyright 2013 Masahiko, SAWAI <masahiko.sawai@gmail.com>.
5+ *
6+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7+ * of this software and associated documentation files (the "Software"), to deal
8+ * in the Software without restriction, including without limitation the rights
9+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+ * copies of the Software, and to permit persons to whom the Software is
11+ * furnished to do so, subject to the following conditions:
12+ *
13+ * The above copyright notice and this permission notice shall be included in
14+ * all copies or substantial portions of the Software.
15+ *
16+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ * THE SOFTWARE.
23+ */
24+package com.example.hello.android.view_custom_drawing_animation;
25+
26+import android.app.Activity;
27+import android.os.Bundle;
28+import android.os.Handler;
29+import android.util.Log;
30+import android.view.Window;
31+import android.view.WindowManager;
32+
33+public class MainActivity extends Activity
34+{
35+
36+ private static final String LOG_TAG = "XXX";
37+ private static final int DELAY_TIME_IN_MSEC = 30; // 33 fps?
38+ private static final String SAVE_KEY_LINEART = "LineArt";
39+ private LineArt lineArt;
40+ private LineArtView lineArtView;
41+ private RepaintTask repaintTask;
42+ private Handler handler;
43+
44+ @Override
45+ protected void onCreate(Bundle savedInstanceState)
46+ {
47+ Log.d(LOG_TAG, "onCreate()");
48+ super.onCreate(savedInstanceState);
49+ requestWindowFeature(Window.FEATURE_NO_TITLE);
50+ getWindow().setFlags(
51+ WindowManager.LayoutParams.FLAG_FULLSCREEN,
52+ WindowManager.LayoutParams.FLAG_FULLSCREEN);
53+
54+ // init LineArt
55+ Log.d(LOG_TAG, "savedInstanceState : " + savedInstanceState);
56+ if (savedInstanceState != null)
57+ {
58+ lineArt = (LineArt) savedInstanceState.getSerializable(SAVE_KEY_LINEART);
59+ Log.d(LOG_TAG, "load LineArt from savedInstanceState");
60+ }
61+ if (lineArt == null)
62+ {
63+ lineArt = new LineArt();
64+ Log.d(LOG_TAG, "new LineArt");
65+ }
66+
67+ // init View
68+ lineArtView = new LineArtView(this);
69+ lineArtView.setLineArt(lineArt);
70+ setContentView(lineArtView);
71+
72+ repaintTask = new RepaintTask();
73+ handler = new Handler();
74+ }
75+
76+ @Override
77+ protected void onSaveInstanceState(Bundle outState)
78+ {
79+ Log.d(LOG_TAG, "onSaveInstanceState()");
80+ super.onSaveInstanceState(outState);
81+ outState.putSerializable(SAVE_KEY_LINEART, lineArt);
82+ }
83+
84+ @Override
85+ protected void onPause()
86+ {
87+ Log.d(LOG_TAG, "onPause()");
88+ repaintTask.setEnable(false);
89+ handler.removeCallbacks(repaintTask);
90+ super.onPause();
91+ }
92+
93+ @Override
94+ protected void onResume()
95+ {
96+ Log.d(LOG_TAG, "onResume()");
97+ super.onResume();
98+ repaintTask.setEnable(true);
99+ handler.postDelayed(repaintTask, DELAY_TIME_IN_MSEC);
100+ }
101+
102+ class RepaintTask implements Runnable
103+ {
104+
105+ private boolean enable = false;
106+
107+ public void run()
108+ {
109+// Log.d(LOG_TAG, "run()");
110+ if (enable)
111+ {
112+ lineArtView.invalidate();
113+ handler.postDelayed(this, DELAY_TIME_IN_MSEC);
114+ }
115+ }
116+
117+ /**
118+ * @return the enable
119+ */
120+ public boolean getEnable()
121+ {
122+ return enable;
123+ }
124+
125+ /**
126+ * @param value the isRunning to set
127+ */
128+ public void setEnable(boolean value)
129+ {
130+ this.enable = value;
131+ }
132+ }
133+}
--- /dev/null
+++ b/view-custom-drawing-hello/AndroidManifest.xml
@@ -0,0 +1,18 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+ package="com.example.hello.android.view_custom_drawing_hello"
4+ android:versionCode="1"
5+ android:versionName="1.0"
6+>
7+ <application android:label="@string/app_name">
8+ <activity
9+ android:name=".MainActivity"
10+ android:label="@string/app_name"
11+ >
12+ <intent-filter>
13+ <action android:name="android.intent.action.MAIN" />
14+ <category android:name="android.intent.category.LAUNCHER" />
15+ </intent-filter>
16+ </activity>
17+ </application>
18+</manifest>
--- /dev/null
+++ b/view-custom-drawing-hello/Makefile
@@ -0,0 +1,46 @@
1+
2+all : package
3+
4+#################### build
5+
6+compile :
7+ mvn $@
8+
9+gen :
10+ mvn android:generate-sources
11+
12+package :
13+ mvn $@
14+
15+release :
16+ mvn clean -Prelease package
17+
18+install :
19+ mvn $@
20+
21+deploy :
22+ mvn package android:deploy
23+
24+undeploy :
25+ mvn android:undeploy
26+
27+rebuild :
28+ mvn clean package
29+
30+redeploy :
31+ mvn clean package android:deploy
32+
33+#################### emulator
34+
35+start :
36+ mvn android:emulator-start
37+
38+stop :
39+ mvn android:emulator-stop
40+
41+####################
42+dist :
43+ mvn assembly:assembly
44+
45+clean :
46+ mvn $@
--- /dev/null
+++ b/view-custom-drawing-hello/README.txt
@@ -0,0 +1,22 @@
1+! view-custom-drawing-hello
2+
3+View を継承して独自の描画をする View を作るサンプル。
4+
5+View の以下のメソッドをオーバーライドして描画処理を記述する。
6+* View#onDraw(Canvas canvas) : void
7+
8+!! ビルドターゲット
9+
10+http://maven-android-plugin-m2site.googlecode.com/svn/plugin-info.html
11+
12+* mvn compile - アプリケーションのコンパイル
13+* mvn package - apk の作成
14+* mvn clean - ビルドファイルの削除
15+* mvn install - maven の local リポジトリにインストール
16+
17+* mvn android:deploy - エミュレータやデバイスにインストール
18+* mvn android:generate-sources
19+
20+* mvn install - アプリケーションのインストール
21+* mvn uninstall - アプリケーションのアンインストール
22+
--- /dev/null
+++ b/view-custom-drawing-hello/pom.xml
@@ -0,0 +1,146 @@
1+<?xml version="1.0" encoding="UTF-8" ?>
2+<project
3+ xmlns="http://maven.apache.org/POM/4.0.0"
4+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"
6+>
7+ <modelVersion>4.0.0</modelVersion>
8+ <groupId>com.example.hello</groupId>
9+ <artifactId>view-custom-drawing-hello</artifactId>
10+ <packaging>apk</packaging>
11+ <version>1.0.0</version>
12+ <name>View Custom Drawing Hello</name>
13+ <url>http://www.example.com/</url>
14+
15+ <parent>
16+ <groupId>com.example.hello</groupId>
17+ <artifactId>android-samples</artifactId>
18+ <version>1.0.0</version>
19+ </parent>
20+
21+ <dependencies>
22+ <dependency>
23+ <groupId>com.google.android</groupId>
24+ <artifactId>android</artifactId>
25+ <version>1.5_r4</version>
26+ <!--
27+ <version>1.5_r3</version>
28+ <version>1.5_r4</version>
29+ <version>1.6_r2</version>
30+ <version>2.1.2</version>
31+ <version>2.1_r1</version>
32+ <version>2.2.1</version>
33+ <version>2.3.1</version>
34+ -->
35+ <scope>provided</scope>
36+ </dependency>
37+
38+ <dependency>
39+ <groupId>junit</groupId>
40+ <artifactId>junit</artifactId>
41+ <version>3.8.1</version>
42+ <scope>test</scope>
43+ </dependency>
44+ </dependencies>
45+
46+ <build>
47+ <sourceDirectory>src</sourceDirectory>
48+
49+ <plugins>
50+ <plugin>
51+ <groupId>com.jayway.maven.plugins.android.generation2</groupId>
52+ <artifactId>android-maven-plugin</artifactId>
53+ <configuration>
54+ <sdk>
55+ <path>${env.ANDROID_HOME}</path>
56+ <!-- <path>C:/Java/android-sdk</path> -->
57+ <platform>8</platform>
58+ </sdk>
59+ <proguard>
60+ <skip>true</skip>
61+ <config>proguard.conf</config>
62+ </proguard>
63+ <extractDuplicates>true</extractDuplicates>
64+ </configuration>
65+ <extensions>true</extensions>
66+ </plugin>
67+
68+ <!-- mvn compile -->
69+ <plugin>
70+ <groupId>org.apache.maven.plugins</groupId>
71+ <artifactId>maven-compiler-plugin</artifactId>
72+ <configuration>
73+ <source>1.5</source>
74+ <target>1.5</target>
75+ <encoding>UTF-8</encoding>
76+ </configuration>
77+ </plugin>
78+
79+ <!-- mvn assembly:assembly -->
80+ <plugin>
81+ <groupId>org.apache.maven.plugins</groupId>
82+ <artifactId>maven-assembly-plugin</artifactId>
83+ <configuration>
84+ <descriptorRefs>
85+ <!--
86+ <descriptorRef>jar-with-dependencies</descriptorRef>
87+ <descriptorRef>bin</descriptorRef>
88+ <descriptorRef>src</descriptorRef>
89+ -->
90+ <descriptorRef>project</descriptorRef>
91+ </descriptorRefs>
92+ </configuration>
93+ </plugin>
94+
95+ <!-- mvn resources:resources -->
96+ <plugin>
97+ <groupId>org.apache.maven.plugins</groupId>
98+ <artifactId>maven-resources-plugin</artifactId>
99+ <configuration>
100+ <encoding>UTF-8</encoding>
101+ </configuration>
102+ </plugin>
103+
104+ <!-- mvn site -->
105+ <plugin>
106+ <groupId>org.apache.maven.plugins</groupId>
107+ <artifactId>maven-site-plugin</artifactId>
108+ <configuration>
109+ <locales>en</locales>
110+ <inputEncoding>UTF-8</inputEncoding>
111+ <outputEncoding>UTF-8</outputEncoding>
112+
113+ <reportPlugins>
114+ <plugin>
115+ <groupId>org.apache.maven.plugins</groupId>
116+ <artifactId>maven-project-info-reports-plugin</artifactId>
117+ </plugin>
118+
119+ <!-- mvn javadoc:javadoc -->
120+ <plugin>
121+ <groupId>org.apache.maven.plugins</groupId>
122+ <artifactId>maven-javadoc-plugin</artifactId>
123+ <configuration>
124+ <charset>utf-8</charset>
125+ </configuration>
126+ </plugin>
127+ </reportPlugins>
128+ </configuration>
129+ </plugin>
130+
131+ </plugins>
132+
133+ <!-- mvn resources:resources -->
134+ <resources>
135+ <resource>
136+ <directory>res</directory>
137+ <filtering>false</filtering>
138+ <includes>
139+ <include>**/*.properties</include>
140+ </includes>
141+ </resource>
142+ </resources>
143+ </build>
144+
145+
146+</project>
--- /dev/null
+++ b/view-custom-drawing-hello/res/values/strings.xml
@@ -0,0 +1,4 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<resources>
3+ <string name="app_name">View Custom Drawing Hello</string>
4+</resources>
--- /dev/null
+++ b/view-custom-drawing-hello/src/com/example/hello/android/view_custom_drawing_hello/LinesView.java
@@ -0,0 +1,58 @@
1+/*
2+ * To change this template, choose Tools | Templates
3+ * and open the template in the editor.
4+ */
5+package com.example.hello.android.view_custom_drawing_hello;
6+
7+import android.content.Context;
8+import android.graphics.Canvas;
9+import android.graphics.Color;
10+import android.graphics.Paint;
11+import android.util.Log;
12+import android.view.View;
13+
14+/**
15+ *
16+ * @author sawai
17+ */
18+public class LinesView extends View
19+{
20+
21+ private Paint bgPaint;
22+ private Paint fgPaint;
23+
24+ public LinesView(Context context)
25+ {
26+ super(context);
27+ Log.d("CanvasView", "new CanvasView()");
28+ bgPaint = new Paint();
29+ bgPaint.setColor(Color.WHITE);
30+ fgPaint = new Paint();
31+ fgPaint.setColor(Color.BLACK);
32+ fgPaint.setAntiAlias(true);
33+ }
34+
35+ @Override
36+ protected void onDraw(Canvas canvas)
37+ {
38+ super.onDraw(canvas);
39+ Log.d("CanvasView", "onDraw()");
40+
41+ int w = canvas.getWidth();
42+ int h = canvas.getHeight();
43+
44+ // clear canvas
45+ canvas.drawRect(0, 0, w, h, bgPaint);
46+
47+ // draw lines
48+ int x1, x2;
49+ int y1 = 0;
50+ int y2 = h - 1;
51+ for (int i = 0; i <= 20; i++)
52+ {
53+ x1 = w * i / 20;
54+ x2 = w - x1;
55+ canvas.drawLine(x1, y1, x2, y2, fgPaint);
56+ }
57+ }
58+}
--- /dev/null
+++ b/view-custom-drawing-hello/src/com/example/hello/android/view_custom_drawing_hello/MainActivity.java
@@ -0,0 +1,22 @@
1+package com.example.hello.android.view_custom_drawing_hello;
2+
3+import android.app.Activity;
4+import android.os.Bundle;
5+import android.view.Window;
6+import android.view.WindowManager;
7+
8+public class MainActivity extends Activity
9+{
10+
11+ @Override
12+ protected void onCreate(Bundle savedInstanceState)
13+ {
14+ super.onCreate(savedInstanceState);
15+ requestWindowFeature(Window.FEATURE_NO_TITLE);
16+ getWindow().setFlags(
17+ WindowManager.LayoutParams.FLAG_FULLSCREEN,
18+ WindowManager.LayoutParams.FLAG_FULLSCREEN);
19+ LinesView view = new LinesView(this);
20+ setContentView(view);
21+ }
22+}