Android Samples
Revision | 2f50b4466e4f54c0c35c2add6ab84211c1b98e91 (tree) |
---|---|
Zeit | 2014-06-06 03:02:43 |
Autor | Masahiko, SAWAI <say@user...> |
Commiter | Masahiko, SAWAI |
Added layer-system-overlay module
@@ -0,0 +1,32 @@ | ||
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.layer_system_overlay" | |
5 | + android:versionCode="1" | |
6 | + android:versionName="1.0" | |
7 | +> | |
8 | + <uses-sdk android:minSdkVersion="3" android:targetSdkVersion="19" /> | |
9 | + | |
10 | + <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> | |
11 | + | |
12 | + <application android:label="@string/app_name"> | |
13 | + | |
14 | + <!-- Activity Manifest --> | |
15 | + <activity | |
16 | + android:name="MainActivity" | |
17 | + android:label="@string/app_name" | |
18 | + > | |
19 | + <intent-filter> | |
20 | + <action android:name="android.intent.action.MAIN" /> | |
21 | + <category android:name="android.intent.category.LAUNCHER" /> | |
22 | + </intent-filter> | |
23 | + </activity> | |
24 | + | |
25 | + <!-- Service Manifest --> | |
26 | + <service | |
27 | + android:name="LayerViewService" | |
28 | + android:label="Layer View Service" | |
29 | + /> | |
30 | + | |
31 | + </application> | |
32 | +</manifest> |
@@ -0,0 +1,47 @@ | ||
1 | +RELEASE_PROFILE=android-hello | |
2 | + | |
3 | +all : package | |
4 | + | |
5 | +#################### build | |
6 | + | |
7 | +compile : | |
8 | + mvn $@ | |
9 | + | |
10 | +gen : | |
11 | + mvn android:generate-sources | |
12 | + | |
13 | +package : | |
14 | + mvn $@ | |
15 | + | |
16 | +release : | |
17 | + mvn clean && mvn -P$(RELEASE_PROFILE) package | |
18 | + | |
19 | +install : | |
20 | + mvn $@ | |
21 | + | |
22 | +deploy : | |
23 | + mvn package android:deploy | |
24 | + | |
25 | +undeploy : | |
26 | + mvn android:undeploy | |
27 | + | |
28 | +rebuild : | |
29 | + mvn clean package | |
30 | + | |
31 | +redeploy : | |
32 | + mvn clean package android:deploy | |
33 | + | |
34 | + | |
35 | +#################### emulator | |
36 | +start : | |
37 | + mvn android:emulator-start | |
38 | + | |
39 | +stop : | |
40 | + mvn android:emulator-stop | |
41 | + | |
42 | +#################### project | |
43 | +dist : | |
44 | + mvn assembly:assembly | |
45 | + | |
46 | +clean : | |
47 | + mvn $@ |
@@ -0,0 +1,42 @@ | ||
1 | +! layer-system-overlay | |
2 | + | |
3 | +SYSTEM_OVERLAY レイヤーに View を配置するサンプル。 | |
4 | + | |
5 | +Android では通常のアプリケーションの表示される | |
6 | +レイヤー以外にも描画用レイヤーがある。 | |
7 | + | |
8 | +主な表示レイヤーは以下の通り。他にもある。 | |
9 | +* WindowManager.TYPE_SYSTEM_ERROR システムエラー用の表示レイヤー | |
10 | +* WindowManager.TYPE_SYSTEM_OVERLAY システム用の表示レイヤー | |
11 | +* WindowManager.TYPE_TOAST Toast用の表示レイヤー | |
12 | +* WindowManager.TYPE_PHONE 電話インタフェース用の表示レイヤー | |
13 | + | |
14 | +このサンプルでは TYPE_SYSTEM_OVERLAY に TextView を描画する。 | |
15 | + | |
16 | +※ TYPE_SYSTEM_OVERLAY に置いた View ではイベントが取得できません。 | |
17 | + | |
18 | +!! 手順 | |
19 | + | |
20 | +* SYSTEM_ALERT_WINDOW パーミッションの設定、 | |
21 | +* Activity からではなく Service から View を追加 | |
22 | + | |
23 | +アプリケーションレイヤー以外に描画する場合、 AndroidManifest.xml に | |
24 | +以下のパーミッションが必要である。 | |
25 | + | |
26 | + <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> | |
27 | + | |
28 | +!! ビルドターゲット | |
29 | + | |
30 | +http://maven-android-plugin-m2site.googlecode.com/svn/plugin-info.html | |
31 | + | |
32 | +* mvn compile - アプリケーションのコンパイル | |
33 | +* mvn package - apk の作成 | |
34 | +* mvn clean - ビルドファイルの削除 | |
35 | +* mvn install - maven の local リポジトリにインストール | |
36 | + | |
37 | +* mvn android:deploy - エミュレータやデバイスにインストール | |
38 | +* mvn android:generate-sources | |
39 | + | |
40 | +* mvn install - アプリケーションのインストール | |
41 | +* mvn uninstall - アプリケーションのアンインストール | |
42 | + |
@@ -0,0 +1,142 @@ | ||
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>layer-system-overlay</artifactId> | |
10 | + <packaging>apk</packaging> | |
11 | + <version>1.0.0</version> | |
12 | + <name>Layer SYSTEM_OVERLAY</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 | + | |
23 | + <dependency> | |
24 | + <groupId>android</groupId> | |
25 | + <artifactId>android</artifactId> | |
26 | + <version>1.5_r4</version> | |
27 | + <!-- | |
28 | + <version>1.5_r3</version> | |
29 | + <version>1.5_r4</version> | |
30 | + <version>1.6_r2</version> | |
31 | + <version>2.1.2</version> | |
32 | + <version>2.1_r1</version> | |
33 | + <version>2.2.1</version> | |
34 | + <version>2.3.1</version> | |
35 | + <version>2.3.3</version> | |
36 | + <version>4.0.1.2</version> | |
37 | + --> | |
38 | + <scope>provided</scope> | |
39 | + </dependency> | |
40 | + | |
41 | + <dependency> | |
42 | + <groupId>junit</groupId> | |
43 | + <artifactId>junit</artifactId> | |
44 | + <scope>test</scope> | |
45 | + </dependency> | |
46 | + </dependencies> | |
47 | + | |
48 | + <build> | |
49 | + <sourceDirectory>src</sourceDirectory> | |
50 | + | |
51 | + <plugins> | |
52 | + <plugin> | |
53 | + <groupId>com.jayway.maven.plugins.android.generation2</groupId> | |
54 | + <artifactId>android-maven-plugin</artifactId> | |
55 | + <configuration> | |
56 | + <sdk> | |
57 | + <!--<path>${env.ANDROID_HOME}</path>--> | |
58 | + <platform>4</platform> | |
59 | + </sdk> | |
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 | +</project> |
@@ -0,0 +1,14 @@ | ||
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<LinearLayout | |
3 | + xmlns:android="http://schemas.android.com/apk/res/android" | |
4 | + android:orientation="vertical" | |
5 | + android:layout_width="wrap_content" | |
6 | + android:layout_height="wrap_content" | |
7 | +> | |
8 | + <TextView | |
9 | + android:id="@+id/start_service_button" | |
10 | + android:layout_width="fill_parent" | |
11 | + android:layout_height="wrap_content" | |
12 | + android:text="@string/hello" | |
13 | + /> | |
14 | +</LinearLayout> |
@@ -0,0 +1,21 @@ | ||
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<LinearLayout | |
3 | + xmlns:android="http://schemas.android.com/apk/res/android" | |
4 | + android:orientation="vertical" | |
5 | + android:layout_width="fill_parent" | |
6 | + android:layout_height="fill_parent" | |
7 | +> | |
8 | + <Button | |
9 | + android:id="@+id/start_service_button" | |
10 | + android:layout_width="fill_parent" | |
11 | + android:layout_height="wrap_content" | |
12 | + android:text="@string/start_service" | |
13 | + /> | |
14 | + <Button | |
15 | + android:id="@+id/stop_service_button" | |
16 | + android:layout_width="fill_parent" | |
17 | + android:layout_height="wrap_content" | |
18 | + android:text="@string/stop_service" | |
19 | + /> | |
20 | +</LinearLayout> | |
21 | + |
@@ -0,0 +1,7 @@ | ||
1 | +<?xml version="1.0" encoding="utf-8"?> | |
2 | +<resources> | |
3 | + <string name="app_name">Layer SYSTEM_OVERLAY</string> | |
4 | + <string name="start_service">Start Service</string> | |
5 | + <string name="stop_service">Stop Service</string> | |
6 | + <string name="hello">Hello, SYSTEM_OVERLAY</string> | |
7 | +</resources> |
@@ -0,0 +1,103 @@ | ||
1 | +/* | |
2 | + * The MIT License | |
3 | + * | |
4 | + * Copyright 2014 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.layer_system_overlay; | |
25 | + | |
26 | +import android.app.Service; | |
27 | +import android.content.Context; | |
28 | +import android.content.Intent; | |
29 | +import android.graphics.PixelFormat; | |
30 | +import android.os.IBinder; | |
31 | +import android.util.Log; | |
32 | +import android.view.LayoutInflater; | |
33 | +import android.view.View; | |
34 | +import android.view.WindowManager; | |
35 | + | |
36 | +/** | |
37 | + * | |
38 | + * @author sawai | |
39 | + */ | |
40 | +public class LayerViewService extends Service | |
41 | +{ | |
42 | + | |
43 | + private static final String LOG_TAG = "XXX"; | |
44 | + private boolean running; | |
45 | + private WindowManager windowManager; | |
46 | + private View overlayView; | |
47 | + | |
48 | + @Override | |
49 | + public void onCreate() | |
50 | + { | |
51 | + Log.v(LOG_TAG, "onCreate() : Hello"); | |
52 | + super.onCreate(); | |
53 | + windowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE); | |
54 | + running = false; | |
55 | + Log.v(LOG_TAG, "onCreate() : Bye"); | |
56 | + } | |
57 | + | |
58 | + @Override | |
59 | + public void onStart(Intent intent, int startId) | |
60 | + { | |
61 | + Log.v(LOG_TAG, "onStart() : Hello"); | |
62 | + super.onStart(intent, startId); | |
63 | + if (!running) | |
64 | + { | |
65 | + running = true; | |
66 | + | |
67 | + LayoutInflater inflater = LayoutInflater.from(this); | |
68 | + overlayView = inflater.inflate(R.layout.hello_system_overlay, null); | |
69 | + | |
70 | + WindowManager.LayoutParams params = new WindowManager.LayoutParams( | |
71 | + WindowManager.LayoutParams.WRAP_CONTENT, | |
72 | + WindowManager.LayoutParams.WRAP_CONTENT, | |
73 | + WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY, | |
74 | + WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH, | |
75 | + PixelFormat.TRANSLUCENT); | |
76 | + | |
77 | + windowManager.addView(overlayView, params); | |
78 | + } | |
79 | + Log.v(LOG_TAG, "onStart() : Bye"); | |
80 | + } | |
81 | + | |
82 | + @Override | |
83 | + public void onDestroy() | |
84 | + { | |
85 | + Log.v(LOG_TAG, "onDestroy() : Hello"); | |
86 | + if (running) | |
87 | + { | |
88 | + running = false; | |
89 | + | |
90 | + windowManager.removeView(overlayView); | |
91 | + } | |
92 | + super.onDestroy(); | |
93 | + Log.v(LOG_TAG, "onDestroy() : Bye"); | |
94 | + } | |
95 | + | |
96 | + @Override | |
97 | + public IBinder onBind(Intent intent) | |
98 | + { | |
99 | + Log.v(LOG_TAG, "onBind() : Hello"); | |
100 | + Log.v(LOG_TAG, "onBind() : Bye"); | |
101 | + return null; | |
102 | + } | |
103 | +} |
@@ -0,0 +1,89 @@ | ||
1 | +/* | |
2 | + * The MIT License | |
3 | + * | |
4 | + * Copyright 2014 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.layer_system_overlay; | |
25 | + | |
26 | +import android.app.Activity; | |
27 | +import android.content.ComponentName; | |
28 | +import android.content.Intent; | |
29 | +import android.os.Bundle; | |
30 | +import android.view.View; | |
31 | +import android.view.View.OnClickListener; | |
32 | +import android.widget.Button; | |
33 | +import android.widget.Toast; | |
34 | + | |
35 | +public class MainActivity extends Activity implements OnClickListener | |
36 | +{ | |
37 | + | |
38 | + private Button startServiceButton; | |
39 | + private Button stopServiceButton; | |
40 | + private ComponentName serviceComponentName; | |
41 | + | |
42 | + @Override | |
43 | + protected void onCreate(Bundle savedInstanceState) | |
44 | + { | |
45 | + super.onCreate(savedInstanceState); | |
46 | + setContentView(R.layout.main_activity); | |
47 | + | |
48 | + startServiceButton = (Button) findViewById(R.id.start_service_button); | |
49 | + startServiceButton.setOnClickListener(this); | |
50 | + stopServiceButton = (Button) findViewById(R.id.stop_service_button); | |
51 | + stopServiceButton.setOnClickListener(this); | |
52 | + | |
53 | + startServiceButton.setEnabled(true); | |
54 | + stopServiceButton.setEnabled(false); | |
55 | + } | |
56 | + | |
57 | + public void onClick(View view) | |
58 | + { | |
59 | + switch (view.getId()) | |
60 | + { | |
61 | + case R.id.start_service_button: | |
62 | + Toast.makeText(getApplicationContext(), "Start Service!", Toast.LENGTH_SHORT).show(); | |
63 | + if (serviceComponentName == null) | |
64 | + { | |
65 | + startServiceButton.setEnabled(false); | |
66 | + stopServiceButton.setEnabled(true); | |
67 | + | |
68 | + Intent intent = new Intent(MainActivity.this, LayerViewService.class); | |
69 | + serviceComponentName = startService(intent); | |
70 | + } | |
71 | + | |
72 | + break; | |
73 | + case R.id.stop_service_button: | |
74 | + Toast.makeText(getApplicationContext(), "Stop Service!", Toast.LENGTH_SHORT).show(); | |
75 | + if (serviceComponentName != null) | |
76 | + { | |
77 | + startServiceButton.setEnabled(true); | |
78 | + stopServiceButton.setEnabled(false); | |
79 | + | |
80 | + Intent intent = new Intent(); | |
81 | + intent.setComponent(serviceComponentName); | |
82 | + stopService(intent); | |
83 | + serviceComponentName = null; | |
84 | + } | |
85 | + | |
86 | + break; | |
87 | + } | |
88 | + } | |
89 | +} |
@@ -74,6 +74,7 @@ | ||
74 | 74 | <module>imageview-zoom</module> |
75 | 75 | <module>intent-service-hello</module> |
76 | 76 | |
77 | + <module>layer-system-overlay</module> | |
77 | 78 | <module>layout-framelayout-hello</module> |
78 | 79 | <module>layout-tablelayout-hello</module> |
79 | 80 | <module>layout-tablelayout-stripe-style</module> |