Merge "Removing reference of hostView from LauncherAppWidgetInfo" into ub-launcher3-calgary
This commit is contained in:
@@ -1567,31 +1567,28 @@ public class Launcher extends Activity
|
||||
if (!mRestoring) {
|
||||
if (hostView == null) {
|
||||
// Perform actual inflation because we're live
|
||||
launcherInfo.hostView = mAppWidgetHost.createView(this, appWidgetId,
|
||||
appWidgetInfo);
|
||||
} else {
|
||||
// The AppWidgetHostView has already been inflated and instantiated
|
||||
launcherInfo.hostView = hostView;
|
||||
hostView = mAppWidgetHost.createView(this, appWidgetId, appWidgetInfo);
|
||||
}
|
||||
launcherInfo.hostView.setVisibility(View.VISIBLE);
|
||||
addAppWidgetToWorkspace(launcherInfo, appWidgetInfo, isWorkspaceLocked());
|
||||
hostView.setVisibility(View.VISIBLE);
|
||||
addAppWidgetToWorkspace(hostView, launcherInfo, appWidgetInfo, isWorkspaceLocked());
|
||||
}
|
||||
resetAddInfo();
|
||||
}
|
||||
|
||||
private void addAppWidgetToWorkspace(LauncherAppWidgetInfo item,
|
||||
private void addAppWidgetToWorkspace(
|
||||
AppWidgetHostView hostView, LauncherAppWidgetInfo item,
|
||||
LauncherAppWidgetProviderInfo appWidgetInfo, boolean insert) {
|
||||
item.hostView.setTag(item);
|
||||
item.onBindAppWidget(this);
|
||||
hostView.setTag(item);
|
||||
item.onBindAppWidget(this, hostView);
|
||||
|
||||
item.hostView.setFocusable(true);
|
||||
item.hostView.setOnFocusChangeListener(mFocusHandler);
|
||||
hostView.setFocusable(true);
|
||||
hostView.setOnFocusChangeListener(mFocusHandler);
|
||||
|
||||
mWorkspace.addInScreen(item.hostView, item.container, item.screenId,
|
||||
mWorkspace.addInScreen(hostView, item.container, item.screenId,
|
||||
item.cellX, item.cellY, item.spanX, item.spanY, insert);
|
||||
|
||||
if (!item.isCustomWidget()) {
|
||||
addWidgetToAutoAdvanceIfNeeded(item.hostView, appWidgetInfo);
|
||||
addWidgetToAutoAdvanceIfNeeded(hostView, appWidgetInfo);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2374,8 +2371,7 @@ public class Launcher extends Activity
|
||||
} else if (itemInfo instanceof LauncherAppWidgetInfo) {
|
||||
final LauncherAppWidgetInfo widgetInfo = (LauncherAppWidgetInfo) itemInfo;
|
||||
mWorkspace.removeWorkspaceItem(v);
|
||||
removeWidgetToAutoAdvance(widgetInfo.hostView);
|
||||
widgetInfo.hostView = null;
|
||||
removeWidgetToAutoAdvance(v);
|
||||
if (deleteFromDb) {
|
||||
deleteWidgetInfo(widgetInfo);
|
||||
}
|
||||
@@ -3860,10 +3856,9 @@ public class Launcher extends Activity
|
||||
private void bindSafeModeWidget(LauncherAppWidgetInfo item) {
|
||||
PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, true);
|
||||
view.updateIcon(mIconCache);
|
||||
item.hostView = view;
|
||||
item.hostView.updateAppWidget(null);
|
||||
item.hostView.setOnClickListener(this);
|
||||
addAppWidgetToWorkspace(item, null, false);
|
||||
view.updateAppWidget(null);
|
||||
view.setOnClickListener(this);
|
||||
addAppWidgetToWorkspace(view, item, null, false);
|
||||
mWorkspace.requestLayout();
|
||||
}
|
||||
|
||||
@@ -3976,18 +3971,17 @@ public class Launcher extends Activity
|
||||
return;
|
||||
}
|
||||
|
||||
item.hostView = mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo);
|
||||
item.minSpanX = appWidgetInfo.minSpanX;
|
||||
item.minSpanY = appWidgetInfo.minSpanY;
|
||||
addAppWidgetToWorkspace(item, appWidgetInfo, false);
|
||||
addAppWidgetToWorkspace(
|
||||
mAppWidgetHost.createView(this, item.appWidgetId, appWidgetInfo),
|
||||
item, appWidgetInfo, false);
|
||||
} else {
|
||||
PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item,
|
||||
mIsSafeModeEnabled);
|
||||
PendingAppWidgetHostView view = new PendingAppWidgetHostView(this, item, false);
|
||||
view.updateIcon(mIconCache);
|
||||
item.hostView = view;
|
||||
item.hostView.updateAppWidget(null);
|
||||
item.hostView.setOnClickListener(this);
|
||||
addAppWidgetToWorkspace(item, null, false);
|
||||
view.updateAppWidget(null);
|
||||
view.setOnClickListener(this);
|
||||
addAppWidgetToWorkspace(view, item, null, false);
|
||||
}
|
||||
mWorkspace.requestLayout();
|
||||
|
||||
|
||||
@@ -80,12 +80,6 @@ public class LauncherAppWidgetInfo extends ItemInfo {
|
||||
|
||||
private boolean mHasNotifiedInitialWidgetSizeChanged;
|
||||
|
||||
/**
|
||||
* View that holds this widget after it's been created. This view isn't created
|
||||
* until Launcher knows it's needed.
|
||||
*/
|
||||
AppWidgetHostView hostView = null;
|
||||
|
||||
LauncherAppWidgetInfo(int appWidgetId, ComponentName providerName) {
|
||||
if (appWidgetId == CUSTOM_WIDGET_ID) {
|
||||
itemType = LauncherSettings.Favorites.ITEM_TYPE_CUSTOM_APPWIDGET;
|
||||
@@ -121,25 +115,18 @@ public class LauncherAppWidgetInfo extends ItemInfo {
|
||||
* When we bind the widget, we should notify the widget that the size has changed if we have not
|
||||
* done so already (only really for default workspace widgets).
|
||||
*/
|
||||
void onBindAppWidget(Launcher launcher) {
|
||||
void onBindAppWidget(Launcher launcher, AppWidgetHostView hostView) {
|
||||
if (!mHasNotifiedInitialWidgetSizeChanged) {
|
||||
AppWidgetResizeFrame.updateWidgetSizeRanges(hostView, launcher, spanX, spanY);
|
||||
mHasNotifiedInitialWidgetSizeChanged = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "AppWidget(id=" + Integer.toString(appWidgetId) + ")";
|
||||
}
|
||||
|
||||
@Override
|
||||
void unbind() {
|
||||
super.unbind();
|
||||
hostView = null;
|
||||
}
|
||||
|
||||
public final boolean isWidgetIdValid() {
|
||||
return (restoreStatus & FLAG_ID_NOT_VALID) == 0;
|
||||
}
|
||||
|
||||
@@ -1096,10 +1096,11 @@ public class Workspace extends PagedView
|
||||
for (int j = 0; j < itemCount; j++) {
|
||||
View v = swc.getChildAt(j);
|
||||
|
||||
if (v != null && v.getTag() instanceof LauncherAppWidgetInfo) {
|
||||
if (v instanceof LauncherAppWidgetHostView
|
||||
&& v.getTag() instanceof LauncherAppWidgetInfo) {
|
||||
LauncherAppWidgetInfo info = (LauncherAppWidgetInfo) v.getTag();
|
||||
LauncherAppWidgetHostView lahv = (LauncherAppWidgetHostView) info.hostView;
|
||||
if (lahv != null && lahv.isReinflateRequired()) {
|
||||
LauncherAppWidgetHostView lahv = (LauncherAppWidgetHostView) v;
|
||||
if (lahv.isReinflateRequired()) {
|
||||
// Remove and rebind the current widget (which was inflated in the wrong
|
||||
// orientation), but don't delete it from the database
|
||||
mLauncher.removeItem(lahv, info, false /* deleteFromDb */);
|
||||
@@ -4156,7 +4157,7 @@ public class Workspace extends PagedView
|
||||
});
|
||||
}
|
||||
|
||||
public void widgetsRestored(ArrayList<LauncherAppWidgetInfo> changedInfo) {
|
||||
public void widgetsRestored(final ArrayList<LauncherAppWidgetInfo> changedInfo) {
|
||||
if (!changedInfo.isEmpty()) {
|
||||
DeferredWidgetRefresh widgetRefresh = new DeferredWidgetRefresh(changedInfo,
|
||||
mLauncher.getAppWidgetHost());
|
||||
@@ -4177,12 +4178,18 @@ public class Workspace extends PagedView
|
||||
} else {
|
||||
// widgetRefresh will automatically run when the packages are updated.
|
||||
// For now just update the progress bars
|
||||
for (LauncherAppWidgetInfo info : changedInfo) {
|
||||
if (info.hostView instanceof PendingAppWidgetHostView) {
|
||||
info.installProgress = 100;
|
||||
((PendingAppWidgetHostView) info.hostView).applyState();
|
||||
mapOverItems(MAP_NO_RECURSE, new ItemOperator() {
|
||||
@Override
|
||||
public boolean evaluate(ItemInfo info, View view) {
|
||||
if (view instanceof PendingAppWidgetHostView
|
||||
&& changedInfo.contains(info)) {
|
||||
((LauncherAppWidgetInfo) info).installProgress = 100;
|
||||
((PendingAppWidgetHostView) view).applyState();
|
||||
}
|
||||
// process all the shortcuts
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4310,14 +4317,18 @@ public class Workspace extends PagedView
|
||||
|
||||
mRefreshPending = false;
|
||||
|
||||
for (LauncherAppWidgetInfo info : mInfos) {
|
||||
if (info.hostView instanceof PendingAppWidgetHostView) {
|
||||
// Remove and rebind the current widget, but don't delete it from the database
|
||||
PendingAppWidgetHostView view = (PendingAppWidgetHostView) info.hostView;
|
||||
mLauncher.removeItem(view, info, false /* deleteFromDb */);
|
||||
mLauncher.bindAppWidget(info);
|
||||
mapOverItems(MAP_NO_RECURSE, new ItemOperator() {
|
||||
@Override
|
||||
public boolean evaluate(ItemInfo info, View view) {
|
||||
if (view instanceof PendingAppWidgetHostView && mInfos.contains(info)) {
|
||||
PendingAppWidgetHostView hostView = (PendingAppWidgetHostView) view;
|
||||
mLauncher.removeItem(view, info, false /* deleteFromDb */);
|
||||
mLauncher.bindAppWidget((LauncherAppWidgetInfo) info);
|
||||
}
|
||||
// process all the shortcuts
|
||||
return false;
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user