Adding support for showing the widget preview based on the provided RemoteViews
Bug: 35811129 Change-Id: I336e48cd00cfec2e617ac73bd8a81419b0944aa7
This commit is contained in:
1 parent
efd5cbf55c
commit
c65a0085d7
13 files changed
+320
-112
No files matched your search
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user