aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKeun young Park <keunyoung@google.com>2012-08-07 14:33:37 -0700
committerKeun young Park <keunyoung@google.com>2012-08-07 14:46:33 -0700
commita5e0a5c53719f8501c814c4673d28964dee15c9c (patch)
tree1a5ab3e5b710e1c31338c8026a9b528f2bbe5256
parentb28605e5d09a08c915183772819cb1c7c53cdb34 (diff)
downloadpdk-a5e0a5c53719f8501c814c4673d28964dee15c9c.tar.gz
add dialer activity for telephony testing
- also refactor structure to have multiple activities under top list view Bug: 6910607 Change-Id: I009cfcc5bc3bde7220415742483384dc58cb3fa8
-rw-r--r--.gitignore1
-rw-r--r--apps/HelloPDK/.classpath8
-rw-r--r--apps/HelloPDK/Android.mk2
-rw-r--r--apps/HelloPDK/AndroidManifest.xml22
-rw-r--r--apps/HelloPDK/jni/Android.mk4
-rw-r--r--apps/HelloPDK/jni/HelloJniNative.cpp (renamed from apps/HelloPDK/jni/HelloPDKNative.cpp)2
-rw-r--r--apps/HelloPDK/res/layout/dialer.xml39
-rw-r--r--apps/HelloPDK/res/layout/hellojni.xml (renamed from apps/HelloPDK/res/layout/hello_pdk.xml)18
-rw-r--r--apps/HelloPDK/res/values/strings.xml7
-rw-r--r--apps/HelloPDK/src/com/example/android/helloPDK/HelloPDK.java57
-rw-r--r--apps/HelloPDK/src/com/example/android/helloPDK/MainActivity.java152
-rw-r--r--apps/HelloPDK/src/com/example/android/helloPDK/jni/HelloJni.java52
-rw-r--r--apps/HelloPDK/src/com/example/android/helloPDK/jni/HelloJniNative.java (renamed from apps/HelloPDK/src/com/example/android/helloPDK/HelloPDKNative.java)6
-rw-r--r--apps/HelloPDK/src/com/example/android/helloPDK/telephony/DialerActivity.java51
14 files changed, 347 insertions, 74 deletions
diff --git a/.gitignore b/.gitignore
index 2f836aa..b61ea46 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,3 @@
*~
*.pyc
+.project
diff --git a/apps/HelloPDK/.classpath b/apps/HelloPDK/.classpath
new file mode 100644
index 0000000..a4763d1
--- /dev/null
+++ b/apps/HelloPDK/.classpath
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="src" path="gen"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.ANDROID_FRAMEWORK"/>
+ <classpathentry kind="con" path="com.android.ide.eclipse.adt.LIBRARIES"/>
+ <classpathentry kind="output" path="bin/classes"/>
+</classpath>
diff --git a/apps/HelloPDK/Android.mk b/apps/HelloPDK/Android.mk
index 4e0cfb0..fc3b139 100644
--- a/apps/HelloPDK/Android.mk
+++ b/apps/HelloPDK/Android.mk
@@ -26,7 +26,7 @@ LOCAL_SRC_FILES := $(call all-java-files-under, src)
LOCAL_PACKAGE_NAME := HelloPDK
-LOCAL_JNI_SHARED_LIBRARIES := libhellopdk_jni
+LOCAL_JNI_SHARED_LIBRARIES := libhellojni_jni
include $(BUILD_PACKAGE)
diff --git a/apps/HelloPDK/AndroidManifest.xml b/apps/HelloPDK/AndroidManifest.xml
index 0506da9..5658e17 100644
--- a/apps/HelloPDK/AndroidManifest.xml
+++ b/apps/HelloPDK/AndroidManifest.xml
@@ -21,11 +21,29 @@
to come from a domain that you own or have control over. -->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.android.helloPDK">
+
+ <uses-permission android:name="android.permission.CALL_PHONE" />
+
<application android:label="Hello, PDK!">
- <activity android:name="HelloPDK">
+ <activity android:name="MainActivity">
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN" />
+ <category android:name="android.intent.category.DEFAULT" />
+ <category android:name="android.intent.category.LAUNCHER" />
+ </intent-filter>
+ </activity>
+ <activity android:name=".jni.HelloJni"
+ android:label="@string/activity_jni" >
+ <intent-filter>
+ <action android:name="android.intent.action.MAIN"/>
+ <category android:name="android.intent.category.SAMPLE_CODE" />
+ </intent-filter>
+ </activity>
+ <activity android:name=".telephony.DialerActivity"
+ android:label="@string/activity_dialer" >
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
- <category android:name="android.intent.category.LAUNCHER"/>
+ <category android:name="android.intent.category.SAMPLE_CODE" />
</intent-filter>
</activity>
</application>
diff --git a/apps/HelloPDK/jni/Android.mk b/apps/HelloPDK/jni/Android.mk
index d543b3c..3c2e963 100644
--- a/apps/HelloPDK/jni/Android.mk
+++ b/apps/HelloPDK/jni/Android.mk
@@ -20,12 +20,12 @@ ifneq ($(TARGET_BUILD_JAVA_SUPPORT_LEVEL),)
LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)
-LOCAL_MODULE := libhellopdk_jni
+LOCAL_MODULE := libhellojni_jni
LOCAL_MODULE_TAGS := optional
LOCAL_SRC_FILES := \
- HelloPDKNative.cpp
+ HelloJniNative.cpp
LOCAL_C_INCLUDES := $(JNI_H_INCLUDE)
diff --git a/apps/HelloPDK/jni/HelloPDKNative.cpp b/apps/HelloPDK/jni/HelloJniNative.cpp
index 53d1c98..51bf417 100644
--- a/apps/HelloPDK/jni/HelloPDKNative.cpp
+++ b/apps/HelloPDK/jni/HelloJniNative.cpp
@@ -17,7 +17,7 @@
#include <jni.h>
extern "C" JNIEXPORT jboolean JNICALL
- Java_com_example_android_helloPDK_HelloPDKNative_isPDK(
+ Java_com_example_android_helloPDK_jni_HelloJniNative_isPDK(
JNIEnv *, jobject) {
return JNI_TRUE;
}
diff --git a/apps/HelloPDK/res/layout/dialer.xml b/apps/HelloPDK/res/layout/dialer.xml
new file mode 100644
index 0000000..8e55e6f
--- /dev/null
+++ b/apps/HelloPDK/res/layout/dialer.xml
@@ -0,0 +1,39 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2012 The Android Open Source Project
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:orientation="vertical" >
+
+ <EditText
+ android:id="@+id/editText_dialer"
+ android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:ems="10"
+ android:hint="@string/dialer_call_default_number"
+ android:inputType="phone" >
+
+ <requestFocus />
+ </EditText>
+
+ <Button
+ android:id="@+id/button_dialer"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:text="@string/dialer_call_button" />
+
+</LinearLayout> \ No newline at end of file
diff --git a/apps/HelloPDK/res/layout/hello_pdk.xml b/apps/HelloPDK/res/layout/hellojni.xml
index 437b9a1..a4159a0 100644
--- a/apps/HelloPDK/res/layout/hello_pdk.xml
+++ b/apps/HelloPDK/res/layout/hellojni.xml
@@ -13,12 +13,18 @@
See the License for the specific language governing permissions and
limitations under the License.
-->
-
-<EditText xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/text"
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:textSize="18sp"
- android:autoText="true"
- android:capitalize="sentences"
- android:text="@string/hello_pdk_text_text" />
+ android:orientation="vertical" >
+
+ <Button
+ android:id="@+id/button_hellojni"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center"
+ android:text="@string/button_hellojni" />
+
+</LinearLayout>
+
diff --git a/apps/HelloPDK/res/values/strings.xml b/apps/HelloPDK/res/values/strings.xml
index 72aca7f..dc45d17 100644
--- a/apps/HelloPDK/res/values/strings.xml
+++ b/apps/HelloPDK/res/values/strings.xml
@@ -15,7 +15,10 @@
-->
<resources>
-
+ <string name="activity_jni">JNI</string>
+ <string name="activity_dialer">Dialer</string>
<string name="hello_pdk_text_text">Hello, PDK!</string>
-
+ <string name="button_hellojni">Jni Call</string>
+ <string name="dialer_call_button">Call</string>
+ <string name="dialer_call_default_number">123456789</string>
</resources>
diff --git a/apps/HelloPDK/src/com/example/android/helloPDK/HelloPDK.java b/apps/HelloPDK/src/com/example/android/helloPDK/HelloPDK.java
deleted file mode 100644
index 189fe86..0000000
--- a/apps/HelloPDK/src/com/example/android/helloPDK/HelloPDK.java
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * Copyright (C) 2012 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package com.example.android.helloPDK;
-
-import android.app.Activity;
-import android.os.Bundle;
-import android.util.Log;
-import android.view.View;
-import android.view.WindowManager;
-
-
-/**
- * A minimal "Hello, PDK!" application.
- */
-public class HelloPDK extends Activity {
- static final String TAG="HelloPDK";
- /**
- * Called with the activity is first created.
- */
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
-
- // Set the layout for this activity. You can find it
- // in res/layout/hello_pdk.xml
- View view = getLayoutInflater().inflate(R.layout.hello_pdk, null);
- setContentView(view);
-
- WindowManager.LayoutParams params = getWindow().getAttributes();
- params.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
- getWindow().setAttributes(params);
- view.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
- @Override public void onSystemUiVisibilityChange(int visibility) {
- WindowManager.LayoutParams params = getWindow().getAttributes();
- params.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
- getWindow().setAttributes(params);
- }
- });
- HelloPDKNative helloNative = new HelloPDKNative();
- Log.i(TAG, "is PDK? " + helloNative.isPDK());
- }
-}
-
diff --git a/apps/HelloPDK/src/com/example/android/helloPDK/MainActivity.java b/apps/HelloPDK/src/com/example/android/helloPDK/MainActivity.java
new file mode 100644
index 0000000..9231e28
--- /dev/null
+++ b/apps/HelloPDK/src/com/example/android/helloPDK/MainActivity.java
@@ -0,0 +1,152 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+// code originally from development samples ApiDemos
+// list all HelloPDK activities
+
+package com.example.android.helloPDK;
+
+import android.app.ListActivity;
+import android.content.Intent;
+import android.content.pm.PackageManager;
+import android.content.pm.ResolveInfo;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.ListView;
+import android.widget.SimpleAdapter;
+
+import java.text.Collator;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+public class MainActivity extends ListActivity {
+
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+
+ Intent intent = getIntent();
+ String path = intent.getStringExtra("com.example.android.helloPDK.Path");
+
+ if (path == null) {
+ path = "";
+ }
+
+ setListAdapter(new SimpleAdapter(this, getData(path),
+ android.R.layout.simple_list_item_1, new String[] { "title" },
+ new int[] { android.R.id.text1 }));
+ getListView().setTextFilterEnabled(true);
+ }
+
+ protected List<Map<String, Object>> getData(String prefix) {
+ List<Map<String, Object>> myData = new ArrayList<Map<String, Object>>();
+
+ Intent mainIntent = new Intent(Intent.ACTION_MAIN, null);
+ mainIntent.addCategory(Intent.CATEGORY_SAMPLE_CODE);
+
+ PackageManager pm = getPackageManager();
+ List<ResolveInfo> list = pm.queryIntentActivities(mainIntent, 0);
+
+ if (null == list)
+ return myData;
+
+ String[] prefixPath;
+ String prefixWithSlash = prefix;
+
+ if (prefix.equals("")) {
+ prefixPath = null;
+ } else {
+ prefixPath = prefix.split("/");
+ prefixWithSlash = prefix + "/";
+ }
+
+ int len = list.size();
+
+ Map<String, Boolean> entries = new HashMap<String, Boolean>();
+
+ for (int i = 0; i < len; i++) {
+ ResolveInfo info = list.get(i);
+ CharSequence labelSeq = info.loadLabel(pm);
+ String label = labelSeq != null ? labelSeq.toString() : info.activityInfo.name;
+
+ if (prefixWithSlash.length() == 0 || label.startsWith(prefixWithSlash)) {
+
+ String[] labelPath = label.split("/");
+
+ String nextLabel = prefixPath ==
+ null ? labelPath[0] : labelPath[prefixPath.length];
+
+ if ((prefixPath != null ? prefixPath.length : 0) == labelPath.length - 1) {
+ addItem(myData, nextLabel, activityIntent(
+ info.activityInfo.applicationInfo.packageName,
+ info.activityInfo.name));
+ } else {
+ if (entries.get(nextLabel) == null) {
+ addItem(myData, nextLabel, browseIntent(prefix.equals("") ?
+ nextLabel : prefix + "/" + nextLabel));
+ entries.put(nextLabel, true);
+ }
+ }
+ }
+ }
+
+ Collections.sort(myData, sDisplayNameComparator);
+
+ return myData;
+ }
+
+ private final static Comparator<Map<String, Object>> sDisplayNameComparator =
+ new Comparator<Map<String, Object>>() {
+ private final Collator collator = Collator.getInstance();
+
+ public int compare(Map<String, Object> map1, Map<String, Object> map2) {
+ return collator.compare(map1.get("title"), map2.get("title"));
+ }
+ };
+
+ protected Intent activityIntent(String pkg, String componentName) {
+ Intent result = new Intent();
+ result.setClassName(pkg, componentName);
+ return result;
+ }
+
+ protected Intent browseIntent(String path) {
+ Intent result = new Intent();
+ result.setClass(this, MainActivity.class);
+ result.putExtra("com.example.android.helloPDK.Path", path);
+ return result;
+ }
+
+ protected void addItem(List<Map<String, Object>> data, String name, Intent intent) {
+ Map<String, Object> temp = new HashMap<String, Object>();
+ temp.put("title", name);
+ temp.put("intent", intent);
+ data.add(temp);
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
+ protected void onListItemClick(ListView l, View v, int position, long id) {
+ Map<String, Object> map = (Map<String, Object>)l.getItemAtPosition(position);
+
+ Intent intent = (Intent) map.get("intent");
+ startActivity(intent);
+ }
+}
diff --git a/apps/HelloPDK/src/com/example/android/helloPDK/jni/HelloJni.java b/apps/HelloPDK/src/com/example/android/helloPDK/jni/HelloJni.java
new file mode 100644
index 0000000..8c33f26
--- /dev/null
+++ b/apps/HelloPDK/src/com/example/android/helloPDK/jni/HelloJni.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.helloPDK.jni;
+
+import com.example.android.helloPDK.R;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.view.WindowManager;
+import android.widget.Button;
+import android.widget.EditText;
+
+
+public class HelloJni extends Activity {
+ private Button mButton;
+ /**
+ * Called with the activity is first created.
+ */
+ @Override
+ public void onCreate(Bundle savedInstanceState) {
+ super.onCreate(savedInstanceState);
+ setContentView(R.layout.hellojni);
+ mButton = (Button)findViewById(R.id.button_hellojni);
+ mButton.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View arg0) {
+ HelloJniNative helloNative = new HelloJniNative();
+ helloNative.isPDK();
+ }
+ });
+ }
+}
+
diff --git a/apps/HelloPDK/src/com/example/android/helloPDK/HelloPDKNative.java b/apps/HelloPDK/src/com/example/android/helloPDK/jni/HelloJniNative.java
index 81d1aa2..bd15fa9 100644
--- a/apps/HelloPDK/src/com/example/android/helloPDK/HelloPDKNative.java
+++ b/apps/HelloPDK/src/com/example/android/helloPDK/jni/HelloJniNative.java
@@ -14,11 +14,11 @@
* limitations under the License.
*/
-package com.example.android.helloPDK;
+package com.example.android.helloPDK.jni;
-public class HelloPDKNative {
+public class HelloJniNative {
static {
- System.loadLibrary("hellopdk_jni");
+ System.loadLibrary("hellojni_jni");
}
native boolean isPDK();
}
diff --git a/apps/HelloPDK/src/com/example/android/helloPDK/telephony/DialerActivity.java b/apps/HelloPDK/src/com/example/android/helloPDK/telephony/DialerActivity.java
new file mode 100644
index 0000000..3173120
--- /dev/null
+++ b/apps/HelloPDK/src/com/example/android/helloPDK/telephony/DialerActivity.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2012 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.example.android.helloPDK.telephony;
+
+import com.example.android.helloPDK.R;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.net.Uri;
+import android.os.Bundle;
+import android.view.View;
+import android.widget.Button;
+import android.widget.EditText;
+
+public class DialerActivity extends Activity {
+ private EditText mText;
+ private Button mButton;
+
+ @Override
+ protected void onCreate(Bundle savedInstanceState) {
+ setContentView(R.layout.dialer);
+ mText = (EditText)findViewById(R.id.editText_dialer);
+ mButton = (Button)findViewById(R.id.button_dialer);
+ mButton.setOnClickListener(new View.OnClickListener() {
+
+ @Override
+ public void onClick(View arg0) {
+ Uri uri = Uri.parse("tel:" + mText.getText().toString());
+ Intent intent = new Intent(Intent.ACTION_CALL, uri);
+ startActivity(intent);
+
+ }
+ });
+ super.onCreate(savedInstanceState);
+ }
+
+}