• R/O
  • HTTP
  • SSH
  • HTTPS

コミット

タグ
未設定

よく使われているワード(クリックで追加)

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

Android Samples


コミットメタ情報

リビジョン0a86089ef6d9791303b331baac4493d67cea115e (tree)
日時2014-06-17 04:52:49
作者Masahiko, SAWAI <say@user...>
コミッターMasahiko, SAWAI

ログメッセージ

Added module activity-manager-running-app-processes-list

変更サマリ

差分

--- /dev/null
+++ b/activity-manager-running-app-processes-list/AndroidManifest.xml
@@ -0,0 +1,24 @@
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.activity_manager_running_app_processes_list"
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.GET_TASKS" />
11+ -->
12+
13+ <application android:label="@string/app_name">
14+ <activity
15+ android:name="AppProcessListActivity"
16+ android:label="@string/app_name"
17+ >
18+ <intent-filter>
19+ <action android:name="android.intent.action.MAIN" />
20+ <category android:name="android.intent.category.LAUNCHER" />
21+ </intent-filter>
22+ </activity>
23+ </application>
24+</manifest>
--- /dev/null
+++ b/activity-manager-running-app-processes-list/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/activity-manager-running-app-processes-list/README.txt
@@ -0,0 +1,9 @@
1+! activity-manager-running-app-processes-list
2+
3+動作中のアプリケーションのプロセス一覧を表示するサンプル。
4+
5+
6+以下のメソッドでタスク一覧が取得できる。
7+* ActivityManager#getRunningAppProcesses(int max) : List<ActivityManager.RunningAppProcessInfo>
8+
9+
--- /dev/null
+++ b/activity-manager-running-app-processes-list/pom.xml
@@ -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>activity-manager-running-app-processes-list</artifactId>
10+ <packaging>apk</packaging>
11+ <version>1.0.0</version>
12+ <name>ActivityManager Running App Processes List</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>
--- /dev/null
+++ b/activity-manager-running-app-processes-list/res/layout/app_process_list_activity.xml
@@ -0,0 +1,19 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<FrameLayout
3+ xmlns:android="http://schemas.android.com/apk/res/android"
4+ android:layout_width="fill_parent"
5+ android:layout_height="fill_parent"
6+>
7+ <ListView
8+ android:id="@android:id/list"
9+ android:layout_width="fill_parent"
10+ android:layout_height="fill_parent"
11+ />
12+ <TextView
13+ android:id="@android:id/empty"
14+ android:layout_width="wrap_content"
15+ android:layout_height="wrap_content"
16+ android:layout_gravity="center"
17+ android:text="@string/empty_message"
18+ />
19+</FrameLayout>
\ No newline at end of file
--- /dev/null
+++ b/activity-manager-running-app-processes-list/res/layout/app_process_list_item.xml
@@ -0,0 +1,79 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<LinearLayout
3+ xmlns:android="http://schemas.android.com/apk/res/android"
4+ android:layout_width="fill_parent"
5+ android:layout_height="wrap_content"
6+ android:paddingLeft="10sp"
7+ android:paddingRight="10sp"
8+ android:orientation="vertical"
9+>
10+ <TextView
11+ android:id="@+id/process_name_textview"
12+ android:layout_width="fill_parent"
13+ android:layout_height="wrap_content"
14+ android:textSize="16sp"
15+ android:textColor="?android:attr/textColorPrimary"
16+ />
17+ <TextView
18+ android:id="@+id/importance_textview"
19+ android:layout_width="fill_parent"
20+ android:layout_height="wrap_content"
21+ android:textSize="16sp"
22+ android:textColor="?android:attr/textColorPrimary"
23+ />
24+ <TextView
25+ android:id="@+id/importance_reason_textview"
26+ android:layout_width="fill_parent"
27+ android:layout_height="wrap_content"
28+ android:textSize="16sp"
29+ android:textColor="?android:attr/textColorPrimary"
30+ />
31+ <LinearLayout
32+ android:layout_width="fill_parent"
33+ android:layout_height="wrap_content"
34+ android:orientation="horizontal"
35+ >
36+ <LinearLayout
37+ android:layout_width="wrap_content"
38+ android:layout_height="wrap_content"
39+ android:layout_weight="1"
40+ android:orientation="horizontal"
41+ >
42+ <TextView
43+ android:layout_width="wrap_content"
44+ android:layout_height="wrap_content"
45+ android:layout_weight="0"
46+ android:text="pid : "
47+ android:textColor="?android:attr/textColorSecondary"
48+ />
49+ <TextView
50+ android:id="@+id/pid_textview"
51+ android:layout_width="wrap_content"
52+ android:layout_height="wrap_content"
53+ android:layout_weight="0"
54+ android:textColor="?android:attr/textColorPrimary"
55+ />
56+ </LinearLayout>
57+ <LinearLayout
58+ android:layout_width="wrap_content"
59+ android:layout_height="wrap_content"
60+ android:layout_weight="1"
61+ android:orientation="horizontal"
62+ >
63+ <TextView
64+ android:layout_width="wrap_content"
65+ android:layout_height="wrap_content"
66+ android:layout_weight="0"
67+ android:text="lru : "
68+ android:textColor="?android:attr/textColorSecondary"
69+ />
70+ <TextView
71+ android:id="@+id/lru_textview"
72+ android:layout_width="wrap_content"
73+ android:layout_height="wrap_content"
74+ android:layout_weight="0"
75+ android:textColor="?android:attr/textColorPrimary"
76+ />
77+ </LinearLayout>
78+ </LinearLayout>
79+</LinearLayout>
\ No newline at end of file
--- /dev/null
+++ b/activity-manager-running-app-processes-list/res/values/strings.xml
@@ -0,0 +1,5 @@
1+<?xml version="1.0" encoding="utf-8"?>
2+<resources>
3+ <string name="app_name">Running Process List</string>
4+ <string name="empty_message">No Running Processes</string>
5+</resources>
--- /dev/null
+++ b/activity-manager-running-app-processes-list/src/com/example/hello/android/activity_manager_running_app_processes_list/AppProcessListActivity.java
@@ -0,0 +1,48 @@
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.activity_manager_running_app_processes_list;
25+
26+import android.app.ActivityManager;
27+import android.app.ListActivity;
28+import android.os.Bundle;
29+import java.util.List;
30+
31+public class AppProcessListActivity extends ListActivity
32+{
33+
34+ @Override
35+ public void onCreate(Bundle savedInstanceState)
36+ {
37+ super.onCreate(savedInstanceState);
38+ setContentView(R.layout.app_process_list_activity);
39+
40+ // Init data list
41+ ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
42+ List<ActivityManager.RunningAppProcessInfo> appProcessInfoList = activityManager.getRunningAppProcesses();
43+
44+ // Init list adapter
45+ AppProcessListAdapter listAdapter = new AppProcessListAdapter(this, appProcessInfoList);
46+ setListAdapter(listAdapter);
47+ }
48+}
--- /dev/null
+++ b/activity-manager-running-app-processes-list/src/com/example/hello/android/activity_manager_running_app_processes_list/AppProcessListAdapter.java
@@ -0,0 +1,155 @@
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.activity_manager_running_app_processes_list;
25+
26+import android.app.ActivityManager;
27+import android.content.Context;
28+import android.util.Log;
29+import android.view.LayoutInflater;
30+import android.view.View;
31+import android.view.ViewGroup;
32+import android.widget.ArrayAdapter;
33+import android.widget.TextView;
34+import java.lang.reflect.Field;
35+import java.util.HashMap;
36+import java.util.List;
37+import java.util.Map;
38+
39+public class AppProcessListAdapter extends ArrayAdapter<ActivityManager.RunningAppProcessInfo>
40+{
41+
42+ private LayoutInflater inflater;
43+ private static final String LOG_TAG = "XXX";
44+ private static final Map<Integer, String> IMPORTANCE_NAME_MAP = new HashMap<Integer, String>();
45+ private static final Map<Integer, String> REASON_NAME_MAP = new HashMap<Integer, String>();
46+ private static Field IMPORTANCE_REASON_CODE_FIELD = null; // RunningAppProcessInfo.importanceReasonCode is available in API Level 5 or later
47+
48+ static
49+ {
50+ Field[] declaredFields = ActivityManager.RunningAppProcessInfo.class.getDeclaredFields();
51+
52+ for (Field field : declaredFields)
53+ {
54+ try
55+ {
56+ String name = field.getName();
57+ if (name.startsWith("IMPORTANCE_"))
58+ {
59+ int value = field.getInt(null);
60+ IMPORTANCE_NAME_MAP.put(value, name);
61+ }
62+ else if (name.startsWith("REASON_"))
63+ {
64+ int value = field.getInt(null);
65+
66+ Log.d(LOG_TAG, "reason name => " + name + ", value => " + value);
67+ REASON_NAME_MAP.put(value, name);
68+ }
69+ }
70+ catch (IllegalArgumentException ex)
71+ {
72+ Log.e(LOG_TAG, "Error", ex);
73+ }
74+ catch (IllegalAccessException ex)
75+ {
76+ Log.e(LOG_TAG, "Error", ex);
77+ }
78+ }
79+
80+ try
81+ {
82+ IMPORTANCE_REASON_CODE_FIELD = ActivityManager.RunningAppProcessInfo.class.getField("importanceReasonCode");
83+ }
84+ catch (NoSuchFieldException ex)
85+ {
86+ Log.e(LOG_TAG, "Error", ex);
87+ }
88+ catch (SecurityException ex)
89+ {
90+ Log.e(LOG_TAG, "Error", ex);
91+ }
92+ }
93+
94+ public AppProcessListAdapter(Context context, List<ActivityManager.RunningAppProcessInfo> taskList)
95+ {
96+ super(context, 0, taskList);
97+ inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
98+ }
99+
100+ @Override
101+ public View getView(int position, View convertView, ViewGroup parent)
102+ {
103+ View view;
104+
105+ if (convertView == null)
106+ {
107+ view = inflater.inflate(R.layout.app_process_list_item, null);
108+ }
109+ else
110+ {
111+ view = convertView;
112+ }
113+
114+ ActivityManager.RunningAppProcessInfo appProcessInfo = getItem(position);
115+ if (appProcessInfo != null)
116+ {
117+
118+ TextView processNameTextView = (TextView) view.findViewById(R.id.process_name_textview);
119+ processNameTextView.setText(appProcessInfo.processName);
120+
121+ TextView importanceTextView = (TextView) view.findViewById(R.id.importance_textview);
122+ String importanceText = IMPORTANCE_NAME_MAP.get(appProcessInfo.importance);
123+ importanceTextView.setText(importanceText);
124+
125+ TextView importanceReasonTextView = (TextView) view.findViewById(R.id.importance_reason_textview);
126+ if (IMPORTANCE_REASON_CODE_FIELD == null)
127+ {
128+ importanceReasonTextView.setVisibility(View.GONE);
129+ }
130+ else
131+ {
132+ importanceReasonTextView.setVisibility(View.VISIBLE);
133+ try
134+ {
135+ int importanceReasonCode = IMPORTANCE_REASON_CODE_FIELD.getInt(appProcessInfo);
136+ String importanceReasonText = REASON_NAME_MAP.get(importanceReasonCode);
137+ importanceReasonTextView.setText(importanceReasonText);
138+ }
139+ catch (IllegalArgumentException ex)
140+ {
141+ }
142+ catch (IllegalAccessException ex)
143+ {
144+ }
145+ }
146+
147+ TextView pidTextView = (TextView) view.findViewById(R.id.pid_textview);
148+ pidTextView.setText(String.valueOf(appProcessInfo.pid));
149+
150+ TextView lruTextView = (TextView) view.findViewById(R.id.lru_textview);
151+ lruTextView.setText(String.valueOf(appProcessInfo.lru));
152+ }
153+ return view;
154+ }
155+}
--- a/pom.xml
+++ b/pom.xml
@@ -35,6 +35,7 @@
3535 <module>actionmode-listview</module>
3636 <module>actionmode-listview-dynamic-layout</module>
3737 <module>actionmode-listview-in-fragment</module>
38+ <module>activity-manager-running-app-processes-list</module>
3839 <module>activity-manager-running-tasks-list</module>
3940
4041 <module>android-app-hello</module>