summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2017-03-17 18:41:31 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-03-17 18:41:31 +0000
commitafc3f09240abf904f0250aa7d3892ff41ec1ba6d (patch)
tree16197f015dfb3bf5e639c0a954b2955441896de1 /tests
parentf71bb700aa436d0e8c8c9056627e3999e1f667d6 (diff)
parentc65a0085d77edd8e8821254f081eb94e9dcc5e75 (diff)
downloadandroid_packages_apps_Trebuchet-afc3f09240abf904f0250aa7d3892ff41ec1ba6d.tar.gz
android_packages_apps_Trebuchet-afc3f09240abf904f0250aa7d3892ff41ec1ba6d.tar.bz2
android_packages_apps_Trebuchet-afc3f09240abf904f0250aa7d3892ff41ec1ba6d.zip
Adding support for showing the widget preview based on the provided RemoteViews
am: c65a0085d7 Change-Id: Iabea96bb74294e2775a08427c17e154020d9bc40
Diffstat (limited to 'tests')
-rw-r--r--tests/res/layout/test_layout_appwidget_view.xml14
-rw-r--r--tests/src/com/android/launcher3/testcomponent/RequestPinItemActivity.java20
-rw-r--r--tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java37
3 files changed, 60 insertions, 11 deletions
diff --git a/tests/res/layout/test_layout_appwidget_view.xml b/tests/res/layout/test_layout_appwidget_view.xml
new file mode 100644
index 000000000..7c87e6019
--- /dev/null
+++ b/tests/res/layout/test_layout_appwidget_view.xml
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="utf-8"?>
+<FrameLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:background="#FFFF00">
+
+ <ImageView
+ android:layout_width="match_parent"
+ android:layout_height="match_parent"
+ android:layout_margin="20dp"
+ android:background="#FF0000"
+ android:id="@android:id/icon" />
+</FrameLayout> \ No newline at end of file
diff --git a/tests/src/com/android/launcher3/testcomponent/RequestPinItemActivity.java b/tests/src/com/android/launcher3/testcomponent/RequestPinItemActivity.java
index 2a031af69..85809922e 100644
--- a/tests/src/com/android/launcher3/testcomponent/RequestPinItemActivity.java
+++ b/tests/src/com/android/launcher3/testcomponent/RequestPinItemActivity.java
@@ -28,6 +28,7 @@ import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.Icon;
import android.os.Bundle;
+import android.widget.RemoteViews;
/**
* Sample activity to request pinning an item.
@@ -36,7 +37,8 @@ import android.os.Bundle;
public class RequestPinItemActivity extends BaseTestingActivity {
private PendingIntent mCallback = null;
- private String mShortcutId;
+ private String mShortcutId = "test-id";
+ private int mRemoteViewColor = Color.TRANSPARENT;
@Override
protected void onCreate(Bundle savedInstanceState) {
@@ -51,6 +53,10 @@ public class RequestPinItemActivity extends BaseTestingActivity {
mCallback = callback;
}
+ public void setRemoteViewColor(int color) {
+ mRemoteViewColor = color;
+ }
+
public void setShortcutId(String id) {
mShortcutId = id;
}
@@ -84,6 +90,16 @@ public class RequestPinItemActivity extends BaseTestingActivity {
}
private void requestWidget(ComponentName cn) {
- AppWidgetManager.getInstance(this).requestPinAppWidget(cn, null, mCallback);
+ Bundle extras = null;
+ if (mRemoteViewColor != Color.TRANSPARENT) {
+ int layoutId = getResources().getIdentifier(
+ "test_layout_appwidget_view", "layout", getPackageName());
+ RemoteViews views = new RemoteViews(getPackageName(), layoutId);
+ views.setInt(android.R.id.icon, "setBackgroundColor", mRemoteViewColor);
+ extras = new Bundle();
+ extras.putParcelable(AppWidgetManager.EXTRA_APPWIDGET_PREVIEW, views);
+ }
+
+ AppWidgetManager.getInstance(this).requestPinAppWidget(cn, extras, mCallback);
}
}
diff --git a/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java b/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java
index 5ef5ec1c3..b798dfa88 100644
--- a/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java
+++ b/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java
@@ -20,6 +20,7 @@ import android.app.Application;
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.content.Intent;
+import android.graphics.Color;
import android.support.test.uiautomator.By;
import android.support.test.uiautomator.UiObject2;
import android.support.test.uiautomator.Until;
@@ -95,6 +96,23 @@ public class RequestPinItemTest extends LauncherInstrumentationTestCase {
});
}
+ public void testPinWidgetNoConfig_customPreview() throws Throwable {
+ // Command to set custom preview
+ Intent command = RequestPinItemActivity.getCommandIntent(
+ RequestPinItemActivity.class, "setRemoteViewColor").putExtra(
+ RequestPinItemActivity.EXTRA_PARAM + "0", Color.RED);
+
+ runTest("pinWidgetNoConfig", true, new ItemOperator() {
+ @Override
+ public boolean evaluate(ItemInfo info, View view) {
+ return info instanceof LauncherAppWidgetInfo &&
+ ((LauncherAppWidgetInfo) info).appWidgetId == mAppWidgetId &&
+ ((LauncherAppWidgetInfo) info).providerName.getClassName()
+ .equals(AppWidgetNoConfig.class.getName());
+ }
+ }, command);
+ }
+
public void testPinWidgetWithConfig() throws Throwable {
runTest("pinWidgetWithConfig", true, new ItemOperator() {
@Override
@@ -107,8 +125,12 @@ public class RequestPinItemTest extends LauncherInstrumentationTestCase {
});
}
+ public void testPinShortcut() throws Throwable {
+ // Command to set the shortcut id
+ Intent command = RequestPinItemActivity.getCommandIntent(
+ RequestPinItemActivity.class, "setShortcutId").putExtra(
+ RequestPinItemActivity.EXTRA_PARAM + "0", mShortcutId);
- public void testPinWidgetShortcut() throws Throwable {
runTest("pinShortcut", false, new ItemOperator() {
@Override
public boolean evaluate(ItemInfo info, View view) {
@@ -116,11 +138,11 @@ public class RequestPinItemTest extends LauncherInstrumentationTestCase {
info.itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT &&
ShortcutKey.fromItemInfo(info).getId().equals(mShortcutId);
}
- });
+ }, command);
}
- private void runTest(String activityMethod, boolean isWidget, ItemOperator itemMatcher)
- throws Throwable {
+ private void runTest(String activityMethod, boolean isWidget, ItemOperator itemMatcher,
+ Intent... commandIntents) throws Throwable {
if (!Utilities.isAtLeastO()) {
return;
}
@@ -146,11 +168,8 @@ public class RequestPinItemTest extends LauncherInstrumentationTestCase {
RequestPinItemActivity.class, "setCallback").putExtra(
RequestPinItemActivity.EXTRA_PARAM + "0", callback));
- if (!isWidget) {
- // Set shortcut id
- mTargetContext.sendBroadcast(RequestPinItemActivity.getCommandIntent(
- RequestPinItemActivity.class, "setShortcutId").putExtra(
- RequestPinItemActivity.EXTRA_PARAM + "0", mShortcutId));
+ for (Intent command : commandIntents) {
+ mTargetContext.sendBroadcast(command);
}
// call the requested method to start the flow