summaryrefslogtreecommitdiffstats
path: root/tests/appwidgets
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-11 12:11:56 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-11 12:11:56 -0700
commitc39a6e0c51e182338deb8b63d07933b585134929 (patch)
treee55fc5bd38b1eb8fb4851a0fe1cc264a7fe2f245 /tests/appwidgets
parentb2a3dd88a53cc8c6d19f6dc8ec4f3d6c4abd9b54 (diff)
downloadframeworks_base-c39a6e0c51e182338deb8b63d07933b585134929.zip
frameworks_base-c39a6e0c51e182338deb8b63d07933b585134929.tar.gz
frameworks_base-c39a6e0c51e182338deb8b63d07933b585134929.tar.bz2
auto import from //branches/cupcake/...@137873
Diffstat (limited to 'tests/appwidgets')
-rw-r--r--tests/appwidgets/AppWidgetHostTest/Android.mk11
-rw-r--r--tests/appwidgets/AppWidgetHostTest/AndroidManifest.xml36
-rw-r--r--tests/appwidgets/AppWidgetHostTest/res/drawable/oh_hai_icon.pngbin0 -> 2988 bytes
-rw-r--r--tests/appwidgets/AppWidgetHostTest/res/layout/appwidget_host.xml51
-rw-r--r--tests/appwidgets/AppWidgetHostTest/res/layout/test_appwidget.xml23
-rw-r--r--tests/appwidgets/AppWidgetHostTest/res/layout/test_appwidget_configure.xml44
-rw-r--r--tests/appwidgets/AppWidgetHostTest/res/values/strings.xml24
-rw-r--r--tests/appwidgets/AppWidgetHostTest/res/xml/appwidget_info.xml10
-rw-r--r--tests/appwidgets/AppWidgetHostTest/src/com/android/tests/appwidgethost/AppWidgetContainerView.java32
-rw-r--r--tests/appwidgets/AppWidgetHostTest/src/com/android/tests/appwidgethost/AppWidgetHostActivity.java198
-rw-r--r--tests/appwidgets/AppWidgetHostTest/src/com/android/tests/appwidgethost/TestAppWidgetConfigure.java57
-rw-r--r--tests/appwidgets/AppWidgetHostTest/src/com/android/tests/appwidgethost/TestAppWidgetProvider.java69
-rw-r--r--tests/appwidgets/AppWidgetProviderTest/Android.mk11
-rw-r--r--tests/appwidgets/AppWidgetProviderTest/AndroidManifest.xml13
-rw-r--r--tests/appwidgets/AppWidgetProviderTest/res/layout/test_appwidget.xml26
-rw-r--r--tests/appwidgets/AppWidgetProviderTest/res/values/strings.xml23
-rw-r--r--tests/appwidgets/AppWidgetProviderTest/res/xml/appwidget_info.xml7
-rw-r--r--tests/appwidgets/AppWidgetProviderTest/src/com/android/tests/appwidgetprovider/TestAppWidgetProvider.java60
18 files changed, 695 insertions, 0 deletions
diff --git a/tests/appwidgets/AppWidgetHostTest/Android.mk b/tests/appwidgets/AppWidgetHostTest/Android.mk
new file mode 100644
index 0000000..1bb1e54
--- /dev/null
+++ b/tests/appwidgets/AppWidgetHostTest/Android.mk
@@ -0,0 +1,11 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := user
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+
+LOCAL_PACKAGE_NAME := AppWidgetHostTest
+LOCAL_CERTIFICATE := platform
+
+include $(BUILD_PACKAGE)
diff --git a/tests/appwidgets/AppWidgetHostTest/AndroidManifest.xml b/tests/appwidgets/AppWidgetHostTest/AndroidManifest.xml
new file mode 100644
index 0000000..bf6a7cb
--- /dev/null
+++ b/tests/appwidgets/AppWidgetHostTest/AndroidManifest.xml
@@ -0,0 +1,36 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.tests.appwidgethost">
+ <uses-permission android:name="android.permission.VIBRATE" />
+
+ <application>
+ <activity android:name="AppWidgetHostActivity" android:label="_AppWidgetHost">
+ <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="TestAppWidgetConfigure" android:label="Configure TestAppWidgetProvider">
+ <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>
+
+ <!-- BEGIN_INCLUDE(AppWidgetProvider) -->
+ <receiver android:name="TestAppWidgetProvider"
+ android:label="@string/oh_hai"
+ android:icon="@drawable/oh_hai_icon"
+ >
+ <intent-filter>
+ <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
+ </intent-filter>
+ <meta-data android:name="android.appwidget.provider"
+ android:resource="@xml/appwidget_info"
+ />
+ </receiver>
+ <!-- END_INCLUDE(AppWidgetProvider) -->
+
+ </application>
+</manifest>
diff --git a/tests/appwidgets/AppWidgetHostTest/res/drawable/oh_hai_icon.png b/tests/appwidgets/AppWidgetHostTest/res/drawable/oh_hai_icon.png
new file mode 100644
index 0000000..30ff267
--- /dev/null
+++ b/tests/appwidgets/AppWidgetHostTest/res/drawable/oh_hai_icon.png
Binary files differ
diff --git a/tests/appwidgets/AppWidgetHostTest/res/layout/appwidget_host.xml b/tests/appwidgets/AppWidgetHostTest/res/layout/appwidget_host.xml
new file mode 100644
index 0000000..e5c3b28
--- /dev/null
+++ b/tests/appwidgets/AppWidgetHostTest/res/layout/appwidget_host.xml
@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2006 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:orientation="vertical"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent" >
+
+ <TextView
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/appwidget_view_title"
+ />
+
+ <ScrollView
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:layout_weight="1"
+ >
+
+ <com.android.tests.appwidgethost.AppWidgetContainerView
+ android:id="@+id/appwidget_container"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ />
+
+ </ScrollView>
+
+ <Button
+ android:id="@+id/add_appwidget"
+ android:text="@string/add_appwidget"
+ android:layout_height="wrap_content"
+ android:layout_width="wrap_content"
+ />
+
+</LinearLayout>
+
diff --git a/tests/appwidgets/AppWidgetHostTest/res/layout/test_appwidget.xml b/tests/appwidgets/AppWidgetHostTest/res/layout/test_appwidget.xml
new file mode 100644
index 0000000..4d483c7
--- /dev/null
+++ b/tests/appwidgets/AppWidgetHostTest/res/layout/test_appwidget.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2006 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.
+-->
+
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/oh_hai_text"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/oh_hai"
+/>
+
diff --git a/tests/appwidgets/AppWidgetHostTest/res/layout/test_appwidget_configure.xml b/tests/appwidgets/AppWidgetHostTest/res/layout/test_appwidget_configure.xml
new file mode 100644
index 0000000..0d9b983
--- /dev/null
+++ b/tests/appwidgets/AppWidgetHostTest/res/layout/test_appwidget_configure.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2006 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="fill_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical"
+ >
+
+ <TextView
+ android:id="@+id/oh_hai_text"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:text="@string/oh_hai"
+ />
+
+ <EditText
+ android:id="@+id/edit_text"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ />
+
+ <Button
+ android:id="@+id/save_button"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:text="@string/save"
+ />
+
+
+</LinearLayout>
diff --git a/tests/appwidgets/AppWidgetHostTest/res/values/strings.xml b/tests/appwidgets/AppWidgetHostTest/res/values/strings.xml
new file mode 100644
index 0000000..8a617e7
--- /dev/null
+++ b/tests/appwidgets/AppWidgetHostTest/res/values/strings.xml
@@ -0,0 +1,24 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 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.
+-->
+
+<resources>
+ <string name="appwidget_view_title">Widget Test</string>
+ <string name="add_appwidget">Add Widget</string>
+ <string name="oh_hai">Oh hai.</string>
+ <string name="delete_appwidget">Delete</string>
+ <string name="save">Save</string>
+</resources>
+
diff --git a/tests/appwidgets/AppWidgetHostTest/res/xml/appwidget_info.xml b/tests/appwidgets/AppWidgetHostTest/res/xml/appwidget_info.xml
new file mode 100644
index 0000000..f12ba16
--- /dev/null
+++ b/tests/appwidgets/AppWidgetHostTest/res/xml/appwidget_info.xml
@@ -0,0 +1,10 @@
+<!-- BEGIN_INCLUDE(AppWidgetProviderInfo) -->
+<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
+ android:minWidth="40dp"
+ android:minHeight="30dp"
+ android:updatePeriodMillis="86400000"
+ android:initialLayout="@layout/test_appwidget"
+ android:configure="com.android.tests.appwidgethost.TestAppWidgetConfigure"
+ >
+</appwidget-provider>
+<!-- END_INCLUDE(AppWidgetProviderInfo) -->
diff --git a/tests/appwidgets/AppWidgetHostTest/src/com/android/tests/appwidgethost/AppWidgetContainerView.java b/tests/appwidgets/AppWidgetHostTest/src/com/android/tests/appwidgethost/AppWidgetContainerView.java
new file mode 100644
index 0000000..b08ba52
--- /dev/null
+++ b/tests/appwidgets/AppWidgetHostTest/src/com/android/tests/appwidgethost/AppWidgetContainerView.java
@@ -0,0 +1,32 @@
+/*
+ * Copyright (C) 2008 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.android.tests.appwidgethost;
+
+import android.content.Context;
+import android.util.AttributeSet;
+import android.widget.LinearLayout;
+
+public class AppWidgetContainerView extends LinearLayout
+{
+ public AppWidgetContainerView(Context context) {
+ super(context);
+ }
+
+ public AppWidgetContainerView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ }
+}
diff --git a/tests/appwidgets/AppWidgetHostTest/src/com/android/tests/appwidgethost/AppWidgetHostActivity.java b/tests/appwidgets/AppWidgetHostTest/src/com/android/tests/appwidgethost/AppWidgetHostActivity.java
new file mode 100644
index 0000000..2fb2d1d
--- /dev/null
+++ b/tests/appwidgets/AppWidgetHostTest/src/com/android/tests/appwidgethost/AppWidgetHostActivity.java
@@ -0,0 +1,198 @@
+/*
+ * Copyright (C) 2008 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.android.tests.appwidgethost;
+
+import android.app.Activity;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.appwidget.AppWidgetHost;
+import android.appwidget.AppWidgetHostView;
+import android.appwidget.AppWidgetProviderInfo;
+import android.appwidget.AppWidgetManager;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.ContextMenu;
+import android.view.MenuItem;
+import android.view.View;
+import android.widget.LinearLayout;
+
+public class AppWidgetHostActivity extends Activity
+{
+ static final String TAG = "AppWidgetHostActivity";
+
+ static final int DISCOVER_APPWIDGET_REQUEST = 1;
+ static final int CONFIGURE_APPWIDGET_REQUEST = 2;
+ static final int HOST_ID = 1234;
+
+ static final String PENDING_APPWIDGET_ID = "pending_appwidget";
+
+ AppWidgetManager mAppWidgetManager;
+ AppWidgetContainerView mAppWidgetContainer;
+
+ public AppWidgetHostActivity() {
+ mAppWidgetManager = AppWidgetManager.getInstance(this);
+ }
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ setContentView(R.layout.appwidget_host);
+
+ findViewById(R.id.add_appwidget).setOnClickListener(mOnClickListener);
+ mAppWidgetContainer = (AppWidgetContainerView)findViewById(R.id.appwidget_container);
+
+ if (false) {
+ if (false) {
+ mHost.deleteHost();
+ } else {
+ AppWidgetHost.deleteAllHosts();
+ }
+ }
+ }
+
+ View.OnClickListener mOnClickListener = new View.OnClickListener() {
+ public void onClick(View v) {
+ discoverAppWidget(DISCOVER_APPWIDGET_REQUEST);
+ }
+ };
+
+ void discoverAppWidget(int requestCode) {
+ Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_PICK);
+ intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mHost.allocateAppWidgetId());
+ startActivityForResult(intent, requestCode);
+ }
+
+ void configureAppWidget(int requestCode, int appWidgetId, ComponentName configure) {
+ Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_CONFIGURE);
+ intent.setComponent(configure);
+ intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
+ SharedPreferences.Editor prefs = getPreferences(0).edit();
+ prefs.putInt(PENDING_APPWIDGET_ID, appWidgetId);
+ prefs.commit();
+ startActivityForResult(intent, requestCode);
+ }
+
+ void handleAppWidgetPickResult(int resultCode, Intent intent) {
+ // BEGIN_INCLUDE(getExtra_EXTRA_APPWIDGET_ID)
+ Bundle extras = intent.getExtras();
+ int appWidgetId = extras.getInt(AppWidgetManager.EXTRA_APPWIDGET_ID);
+ // END_INCLUDE(getExtra_EXTRA_APPWIDGET_ID)
+ if (resultCode == RESULT_OK) {
+ AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
+
+ if (appWidget.configure != null) {
+ // configure the AppWidget if we should
+ configureAppWidget(CONFIGURE_APPWIDGET_REQUEST, appWidgetId, appWidget.configure);
+ } else {
+ // just add it as is
+ addAppWidgetView(appWidgetId, appWidget);
+ }
+ } else {
+ mHost.deleteAppWidgetId(appWidgetId);
+ }
+ }
+
+ void handleAppWidgetConfigureResult(int resultCode, Intent data) {
+ int appWidgetId = getPreferences(0).getInt(PENDING_APPWIDGET_ID, -1);
+ Log.d(TAG, "resultCode=" + resultCode + " appWidgetId=" + appWidgetId);
+ if (appWidgetId < 0) {
+ Log.w(TAG, "was no preference for PENDING_APPWIDGET_ID");
+ return;
+ }
+ if (resultCode == RESULT_OK) {
+ AppWidgetProviderInfo appWidget = mAppWidgetManager.getAppWidgetInfo(appWidgetId);
+ addAppWidgetView(appWidgetId, appWidget);
+ } else {
+ mHost.deleteAppWidgetId(appWidgetId);
+ }
+ }
+
+ void addAppWidgetView(int appWidgetId, AppWidgetProviderInfo appWidget) {
+ // Inflate the AppWidget's RemoteViews
+ AppWidgetHostView view = mHost.createView(this, appWidgetId, appWidget);
+
+ // Add it to the list
+ LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
+ LinearLayout.LayoutParams.FILL_PARENT,
+ LinearLayout.LayoutParams.WRAP_CONTENT);
+ mAppWidgetContainer.addView(view, layoutParams);
+
+ registerForContextMenu(view);
+ }
+
+ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
+ switch (requestCode) {
+ case DISCOVER_APPWIDGET_REQUEST:
+ handleAppWidgetPickResult(resultCode, data);
+ break;
+ case CONFIGURE_APPWIDGET_REQUEST:
+ handleAppWidgetConfigureResult(resultCode, data);
+ }
+ }
+
+ protected void onStart() {
+ super.onStart();
+ mHost.startListening();
+ }
+
+ protected void onStop() {
+ super.onStop();
+ mHost.stopListening();
+ }
+
+ public void onCreateContextMenu(ContextMenu menu, View v,
+ ContextMenu.ContextMenuInfo menuInfo) {
+ menu.add(ContextMenu.NONE, R.string.delete_appwidget, ContextMenu.NONE,
+ R.string.delete_appwidget);
+ }
+
+ public boolean onContextItemSelected(MenuItem item) {
+ MyAppWidgetView view = (MyAppWidgetView)item.getMenuInfo();
+ switch (item.getItemId()) {
+ case R.string.delete_appwidget:
+ Log.d(TAG, "delete! " + view.appWidgetId);
+ mAppWidgetContainer.removeView(view);
+ mHost.deleteAppWidgetId(view.appWidgetId);
+ break;
+ }
+
+ return true;
+ }
+
+ class MyAppWidgetView extends AppWidgetHostView implements ContextMenu.ContextMenuInfo {
+ int appWidgetId;
+
+ MyAppWidgetView(int appWidgetId) {
+ super(AppWidgetHostActivity.this);
+ this.appWidgetId = appWidgetId;
+ }
+
+ public ContextMenu.ContextMenuInfo getContextMenuInfo() {
+ return this;
+ }
+ }
+
+ AppWidgetHost mHost = new AppWidgetHost(this, HOST_ID) {
+ protected AppWidgetHostView onCreateView(Context context, int appWidgetId, AppWidgetProviderInfo appWidget) {
+ return new MyAppWidgetView(appWidgetId);
+ }
+ };
+}
+
+
diff --git a/tests/appwidgets/AppWidgetHostTest/src/com/android/tests/appwidgethost/TestAppWidgetConfigure.java b/tests/appwidgets/AppWidgetHostTest/src/com/android/tests/appwidgethost/TestAppWidgetConfigure.java
new file mode 100644
index 0000000..9a6099a
--- /dev/null
+++ b/tests/appwidgets/AppWidgetHostTest/src/com/android/tests/appwidgethost/TestAppWidgetConfigure.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright (C) 2008 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.android.tests.appwidgethost;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.os.Bundle;
+import android.util.Log;
+import android.view.View;
+import android.widget.EditText;
+
+public class TestAppWidgetConfigure extends Activity {
+ static final String TAG = "TestAppWidgetConfigure";
+
+ public TestAppWidgetConfigure() {
+ super();
+ }
+
+ @Override
+ public void onCreate(Bundle icicle) {
+ super.onCreate(icicle);
+ setContentView(R.layout.test_appwidget_configure);
+
+ findViewById(R.id.save_button).setOnClickListener(mOnClickListener);
+ }
+
+ View.OnClickListener mOnClickListener = new View.OnClickListener() {
+ public void onClick(View v) {
+ String text = ((EditText)findViewById(R.id.edit_text)).getText().toString();
+ Log.d(TAG, "text is '" + text + '\'');
+ SharedPreferences.Editor prefs = getSharedPreferences(TestAppWidgetProvider.PREFS_NAME, 0)
+ .edit();
+ prefs.putString(TestAppWidgetProvider.PREF_PREFIX_KEY, text);
+ prefs.commit();
+ setResult(RESULT_OK);
+ finish();
+ }
+ };
+
+}
+
+
diff --git a/tests/appwidgets/AppWidgetHostTest/src/com/android/tests/appwidgethost/TestAppWidgetProvider.java b/tests/appwidgets/AppWidgetHostTest/src/com/android/tests/appwidgethost/TestAppWidgetProvider.java
new file mode 100644
index 0000000..b5d91d4
--- /dev/null
+++ b/tests/appwidgets/AppWidgetHostTest/src/com/android/tests/appwidgethost/TestAppWidgetProvider.java
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2008 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.android.tests.appwidgethost;
+
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.content.SharedPreferences;
+import android.appwidget.AppWidgetManager;
+import android.os.Bundle;
+import android.os.SystemClock;
+import android.util.Log;
+import android.widget.RemoteViews;
+
+public class TestAppWidgetProvider extends BroadcastReceiver {
+ static final String TAG = "TestAppWidgetProvider";
+
+ static final String PREFS_NAME = "com.android.tests.appwidgethost.TestAppWidgetProvider";
+ static final String PREF_PREFIX_KEY = "prefix";
+
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ Log.d(TAG, "intent=" + intent);
+
+ if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)) {
+ Log.d(TAG, "ENABLED");
+ }
+ else if (AppWidgetManager.ACTION_APPWIDGET_DISABLED.equals(action)) {
+ Log.d(TAG, "DISABLED");
+ }
+ else if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) {
+ Log.d(TAG, "UPDATE");
+ // BEGIN_INCLUDE(getExtra_EXTRA_APPWIDGET_IDS)
+ Bundle extras = intent.getExtras();
+ int[] appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
+ // END_INCLUDE(getExtra_EXTRA_APPWIDGET_IDS)
+
+ SharedPreferences prefs = context.getSharedPreferences(
+ TestAppWidgetProvider.PREFS_NAME, 0);
+ String prefix = prefs.getString(PREF_PREFIX_KEY, "hai");
+
+ AppWidgetManager gm = AppWidgetManager.getInstance(context);
+ RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.test_appwidget);
+ views.setTextViewText(R.id.oh_hai_text, prefix + ": " + SystemClock.elapsedRealtime());
+ if (false) {
+ gm.updateAppWidget(appWidgetIds, views);
+ } else {
+ gm.updateAppWidget(new ComponentName("com.android.tests.appwidgethost",
+ "com.android.tests.appwidgethost.TestAppWidgetProvider"), views);
+ }
+ }
+ }
+}
+
diff --git a/tests/appwidgets/AppWidgetProviderTest/Android.mk b/tests/appwidgets/AppWidgetProviderTest/Android.mk
new file mode 100644
index 0000000..c87a0f2
--- /dev/null
+++ b/tests/appwidgets/AppWidgetProviderTest/Android.mk
@@ -0,0 +1,11 @@
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+LOCAL_MODULE_TAGS := user
+
+LOCAL_SRC_FILES := $(call all-subdir-java-files)
+
+LOCAL_PACKAGE_NAME := AppWidgetProvider
+LOCAL_CERTIFICATE := platform
+
+include $(BUILD_PACKAGE)
diff --git a/tests/appwidgets/AppWidgetProviderTest/AndroidManifest.xml b/tests/appwidgets/AppWidgetProviderTest/AndroidManifest.xml
new file mode 100644
index 0000000..ec4d583
--- /dev/null
+++ b/tests/appwidgets/AppWidgetProviderTest/AndroidManifest.xml
@@ -0,0 +1,13 @@
+<manifest xmlns:android="http://schemas.android.com/apk/res/android"
+ package="com.android.tests.appwidgetprovider">
+ <uses-permission android:name="android.permission.VIBRATE" />
+
+ <application>
+ <receiver android:name="TestAppWidgetProvider">
+ <intent-filter>
+ <action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
+ </intent-filter>
+ <meta-data android:name="android.appwidget.provider" android:resource="@xml/appwidget_info" />
+ </receiver>
+ </application>
+</manifest>
diff --git a/tests/appwidgets/AppWidgetProviderTest/res/layout/test_appwidget.xml b/tests/appwidgets/AppWidgetProviderTest/res/layout/test_appwidget.xml
new file mode 100644
index 0000000..e0a416e
--- /dev/null
+++ b/tests/appwidgets/AppWidgetProviderTest/res/layout/test_appwidget.xml
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2006 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.
+-->
+
+<TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/oh_hai_text"
+ android:layout_width="150dp"
+ android:layout_height="150dp"
+ android:text="@string/oh_hai"
+ android:background="#8fff"
+ android:textColor="#000"
+ android:textStyle="bold"
+/>
+
diff --git a/tests/appwidgets/AppWidgetProviderTest/res/values/strings.xml b/tests/appwidgets/AppWidgetProviderTest/res/values/strings.xml
new file mode 100644
index 0000000..e51299b
--- /dev/null
+++ b/tests/appwidgets/AppWidgetProviderTest/res/values/strings.xml
@@ -0,0 +1,23 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!-- Copyright (C) 2007 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.
+-->
+
+<resources>
+ <string name="appwidget_view_title">Widget Test</string>
+ <string name="add_appwidget">Add Widget</string>
+ <string name="oh_hai">Oh hai.</string>
+ <string name="delete_appwidget">Delete</string>
+</resources>
+
diff --git a/tests/appwidgets/AppWidgetProviderTest/res/xml/appwidget_info.xml b/tests/appwidgets/AppWidgetProviderTest/res/xml/appwidget_info.xml
new file mode 100644
index 0000000..c133743
--- /dev/null
+++ b/tests/appwidgets/AppWidgetProviderTest/res/xml/appwidget_info.xml
@@ -0,0 +1,7 @@
+<appwidget-provider xmlns:android="http://schemas.android.com/apk/res/android"
+ android:minWidth="150dp"
+ android:minHeight="150dp"
+ android:updatePeriodMillis="2000"
+ android:initialLayout="@layout/test_appwidget"
+ >
+</appwidget-provider>
diff --git a/tests/appwidgets/AppWidgetProviderTest/src/com/android/tests/appwidgetprovider/TestAppWidgetProvider.java b/tests/appwidgets/AppWidgetProviderTest/src/com/android/tests/appwidgetprovider/TestAppWidgetProvider.java
new file mode 100644
index 0000000..418be65
--- /dev/null
+++ b/tests/appwidgets/AppWidgetProviderTest/src/com/android/tests/appwidgetprovider/TestAppWidgetProvider.java
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2008 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.android.tests.appwidgetprovider;
+
+import android.content.BroadcastReceiver;
+import android.content.ComponentName;
+import android.content.Context;
+import android.content.Intent;
+import android.appwidget.AppWidgetManager;
+import android.os.Bundle;
+import android.os.SystemClock;
+import android.util.Log;
+import android.widget.RemoteViews;
+
+public class TestAppWidgetProvider extends BroadcastReceiver {
+
+ static final String TAG = "TestAppWidgetProvider";
+
+ public void onReceive(Context context, Intent intent) {
+ String action = intent.getAction();
+ Log.d(TAG, "intent=" + intent);
+
+ if (AppWidgetManager.ACTION_APPWIDGET_ENABLED.equals(action)) {
+ Log.d(TAG, "ENABLED");
+ }
+ else if (AppWidgetManager.ACTION_APPWIDGET_DISABLED.equals(action)) {
+ Log.d(TAG, "DISABLED");
+ }
+ else if (AppWidgetManager.ACTION_APPWIDGET_UPDATE.equals(action)) {
+ Log.d(TAG, "UPDATE");
+ Bundle extras = intent.getExtras();
+ int[] appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
+
+ AppWidgetManager gm = AppWidgetManager.getInstance(context);
+ RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.test_appwidget);
+ views.setTextViewText(R.id.oh_hai_text, "hai: " + SystemClock.elapsedRealtime());
+ if (false) {
+ gm.updateAppWidget(appWidgetIds, views);
+ } else {
+ gm.updateAppWidget(new ComponentName("com.android.tests.appwidgetprovider",
+ "com.android.tests.appwidgetprovider.TestAppWidgetProvider"), views);
+ }
+ }
+ }
+}
+