use of android.appwidget.AppWidgetProviderInfo in project Launcher3 by chislon.
the class LauncherBackupHelper method packWidget.
/** Serialize a widget for persistence, including a checksum wrapper. */
private byte[] packWidget(int dpi, WidgetPreviewLoader previewLoader, IconCache iconCache, ComponentName provider) {
final AppWidgetProviderInfo info = findAppWidgetProviderInfo(provider);
Widget widget = new Widget();
widget.provider = provider.flattenToShortString();
widget.label = info.label;
widget.configure = info.configure != null;
if (info.icon != 0) {
widget.icon = new Resource();
Drawable fullResIcon = iconCache.getFullResIcon(provider.getPackageName(), info.icon);
Bitmap icon = Utilities.createIconBitmap(fullResIcon, mContext);
ByteArrayOutputStream os = new ByteArrayOutputStream();
if (icon.compress(IMAGE_FORMAT, IMAGE_COMPRESSION_QUALITY, os)) {
widget.icon.data = os.toByteArray();
widget.icon.dpi = dpi;
}
}
if (info.previewImage != 0) {
widget.preview = new Resource();
Bitmap preview = previewLoader.generateWidgetPreview(info, null);
ByteArrayOutputStream os = new ByteArrayOutputStream();
if (preview.compress(IMAGE_FORMAT, IMAGE_COMPRESSION_QUALITY, os)) {
widget.preview.data = os.toByteArray();
widget.preview.dpi = dpi;
}
}
return writeCheckedBytes(widget);
}
use of android.appwidget.AppWidgetProviderInfo in project ADWLauncher2 by boombuler.
the class WidgetCellLayout method onViewportOut.
/**
* Called when this cell layout get into the viewport
*/
public void onViewportOut() {
View child;
AppWidgetHostView widgetView;
AppWidgetProviderInfo widgetInfo;
Intent intent;
for (int i = this.getChildCount() - 1; i >= 0; i--) {
try {
child = this.getChildAt(i);
if (child instanceof AppWidgetHostView) {
widgetView = ((AppWidgetHostView) child);
// Stop all animations in the view
stopAllAnimationDrawables(widgetView);
// Notify the widget provider
widgetInfo = widgetView.getAppWidgetInfo();
int appWidgetId = widgetView.getAppWidgetId();
intent = new Intent(LauncherIntent.Notification.NOTIFICATION_OUT_VIEWPORT).setComponent(widgetInfo.provider);
intent.putExtra(LauncherIntent.Extra.EXTRA_APPWIDGET_ID, appWidgetId);
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);
getContext().sendBroadcast(intent);
}
} catch (Exception e) {
// LauncherApplication.reportExceptionStack(e);
}
}
}
use of android.appwidget.AppWidgetProviderInfo in project ADWLauncher2 by boombuler.
the class WidgetSpace method unbindWidgetScrollableId.
public synchronized boolean unbindWidgetScrollableId(int widgetId) {
Log.d(TAG, "trying to completely unallocate widget ID=" + widgetId);
CharSequence keyToDelete = null;
for (ScrollViewInfos item : mScrollViewCursorInfos.values()) {
Log.d(TAG, "Comparing widget ID=" + item.widgetId);
if (item.widgetId == widgetId) {
Log.d(TAG, "trying to completely unallocate widget stuff...");
AppWidgetHostView widgetView = findWidget(widgetId);
Log.d(TAG, "Widget view to KILL:" + widgetView);
Context remoteContext = null;
if (widgetView != null) {
AppWidgetProviderInfo info = widgetView.getAppWidgetInfo();
if (info != null && info.provider != null) {
final String packageName = info.provider.getPackageName();
try {
remoteContext = getContext().createPackageContext(packageName, Context.CONTEXT_IGNORE_SECURITY);
} catch (NameNotFoundException e) {
Log.e(TAG, "couldn't find widget id:" + widgetId);
}
} else
remoteContext = null;
}
if (remoteContext == null)
remoteContext = getContext();
if (item.lv != null) {
Log.d(TAG, "Trying to KILL the ListView...");
if (item.lvAdapter != null) {
item.lvAdapter.dropCache(remoteContext);
}
item.lv.setAdapter(null);
item.lv = null;
}
remoteContext.getContentResolver().unregisterContentObserver(item.obs);
item.obsHandler = null;
item.obs = null;
keyToDelete = item.key;
item = null;
ListViewImageManager.getInstance().clearCacheForWidget(getContext(), widgetId);
}
}
if (keyToDelete != null)
mScrollViewCursorInfos.remove(keyToDelete);
ListViewImageManager.getInstance().unbindDrawables();
if (FORCE_FREE_MEMORY) {
System.gc();
}
Log.d(TAG, "AFTER REMOVING, Our Scrollable widgets array contains:" + mScrollViewCursorInfos.size());
return false;
}
use of android.appwidget.AppWidgetProviderInfo in project android_frameworks_base by ParanoidAndroid.
the class KeyguardHostView method addWidget.
private boolean addWidget(int appId, int pageIndex, boolean updateDbIfFailed) {
AppWidgetProviderInfo appWidgetInfo = mAppWidgetManager.getAppWidgetInfo(appId);
if (appWidgetInfo != null) {
AppWidgetHostView view = mAppWidgetHost.createView(mContext, appId, appWidgetInfo);
addWidget(view, pageIndex);
return true;
} else {
if (updateDbIfFailed) {
Log.w(TAG, "*** AppWidgetInfo for app widget id " + appId + " was null for user" + mUserId + ", deleting");
mAppWidgetHost.deleteAppWidgetId(appId);
mLockPatternUtils.removeAppWidget(appId);
}
return false;
}
}
use of android.appwidget.AppWidgetProviderInfo in project android_frameworks_base by ParanoidAndroid.
the class AppWidgetServiceImpl method readStateFromFileLocked.
@SuppressWarnings("unused")
void readStateFromFileLocked(FileInputStream stream) {
boolean success = false;
try {
XmlPullParser parser = Xml.newPullParser();
parser.setInput(stream, null);
int type;
int providerIndex = 0;
HashMap<Integer, Provider> loadedProviders = new HashMap<Integer, Provider>();
do {
type = parser.next();
if (type == XmlPullParser.START_TAG) {
String tag = parser.getName();
if ("p".equals(tag)) {
// TODO: do we need to check that this package has the same signature
// as before?
String pkg = parser.getAttributeValue(null, "pkg");
String cl = parser.getAttributeValue(null, "cl");
final IPackageManager packageManager = AppGlobals.getPackageManager();
try {
packageManager.getReceiverInfo(new ComponentName(pkg, cl), 0, mUserId);
} catch (RemoteException e) {
String[] pkgs = mContext.getPackageManager().currentToCanonicalPackageNames(new String[] { pkg });
pkg = pkgs[0];
}
Provider p = lookupProviderLocked(new ComponentName(pkg, cl));
if (p == null && mSafeMode) {
// if we're in safe mode, make a temporary one
p = new Provider();
p.info = new AppWidgetProviderInfo();
p.info.provider = new ComponentName(pkg, cl);
p.zombie = true;
mInstalledProviders.add(p);
}
if (p != null) {
// if it wasn't uninstalled or something
loadedProviders.put(providerIndex, p);
}
providerIndex++;
} else if ("h".equals(tag)) {
Host host = new Host();
// TODO: do we need to check that this package has the same signature
// as before?
host.packageName = parser.getAttributeValue(null, "pkg");
try {
host.uid = getUidForPackage(host.packageName);
} catch (PackageManager.NameNotFoundException ex) {
host.zombie = true;
}
if (!host.zombie || mSafeMode) {
// In safe mode, we don't discard the hosts we don't recognize
// so that they're not pruned from our list. Otherwise, we do.
host.hostId = Integer.parseInt(parser.getAttributeValue(null, "id"), 16);
mHosts.add(host);
}
} else if ("b".equals(tag)) {
String packageName = parser.getAttributeValue(null, "packageName");
if (packageName != null) {
mPackagesWithBindWidgetPermission.add(packageName);
}
} else if ("g".equals(tag)) {
AppWidgetId id = new AppWidgetId();
id.appWidgetId = Integer.parseInt(parser.getAttributeValue(null, "id"), 16);
if (id.appWidgetId >= mNextAppWidgetId) {
mNextAppWidgetId = id.appWidgetId + 1;
}
Bundle options = new Bundle();
String minWidthString = parser.getAttributeValue(null, "min_width");
if (minWidthString != null) {
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_WIDTH, Integer.parseInt(minWidthString, 16));
}
String minHeightString = parser.getAttributeValue(null, "min_height");
if (minHeightString != null) {
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MIN_HEIGHT, Integer.parseInt(minHeightString, 16));
}
String maxWidthString = parser.getAttributeValue(null, "max_width");
if (maxWidthString != null) {
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_WIDTH, Integer.parseInt(maxWidthString, 16));
}
String maxHeightString = parser.getAttributeValue(null, "max_height");
if (maxHeightString != null) {
options.putInt(AppWidgetManager.OPTION_APPWIDGET_MAX_HEIGHT, Integer.parseInt(maxHeightString, 16));
}
String categoryString = parser.getAttributeValue(null, "host_category");
if (categoryString != null) {
options.putInt(AppWidgetManager.OPTION_APPWIDGET_HOST_CATEGORY, Integer.parseInt(categoryString, 16));
}
id.options = options;
String providerString = parser.getAttributeValue(null, "p");
if (providerString != null) {
// there's no provider if it hasn't been bound yet.
// maybe we don't have to save this, but it brings the system
// to the state it was in.
int pIndex = Integer.parseInt(providerString, 16);
id.provider = loadedProviders.get(pIndex);
if (false) {
Slog.d(TAG, "bound appWidgetId=" + id.appWidgetId + " to provider " + pIndex + " which is " + id.provider);
}
if (id.provider == null) {
// that this happened when it fails to load it.
continue;
}
}
int hIndex = Integer.parseInt(parser.getAttributeValue(null, "h"), 16);
id.host = mHosts.get(hIndex);
if (id.host == null) {
// This host is gone.
continue;
}
if (id.provider != null) {
id.provider.instances.add(id);
}
id.host.instances.add(id);
mAppWidgetIds.add(id);
}
}
} while (type != XmlPullParser.END_DOCUMENT);
success = true;
} catch (NullPointerException e) {
Slog.w(TAG, "failed parsing " + e);
} catch (NumberFormatException e) {
Slog.w(TAG, "failed parsing " + e);
} catch (XmlPullParserException e) {
Slog.w(TAG, "failed parsing " + e);
} catch (IOException e) {
Slog.w(TAG, "failed parsing " + e);
} catch (IndexOutOfBoundsException e) {
Slog.w(TAG, "failed parsing " + e);
}
if (success) {
// if it matters, they'll be reconnected.
for (int i = mHosts.size() - 1; i >= 0; i--) {
pruneHostLocked(mHosts.get(i));
}
} else {
// failed reading, clean up
Slog.w(TAG, "Failed to read state, clearing widgets and hosts.");
mAppWidgetIds.clear();
mHosts.clear();
final int N = mInstalledProviders.size();
for (int i = 0; i < N; i++) {
mInstalledProviders.get(i).instances.clear();
}
}
}
Aggregations