Merge "Fixing issue where widgets could be inflated in wrong orientation (issue 6584646)" into jb-dev
This commit is contained in:
@@ -682,6 +682,31 @@ public final class Launcher extends Activity
|
|||||||
// Resets the previous all apps icon press state
|
// Resets the previous all apps icon press state
|
||||||
mAppsCustomizeContent.resetDrawableState();
|
mAppsCustomizeContent.resetDrawableState();
|
||||||
}
|
}
|
||||||
|
// It is possible that widgets can receive updates while launcher is not in the foreground.
|
||||||
|
// Consequently, the widgets will be inflated in the orientation of the foreground activity
|
||||||
|
// (framework issue). On resuming, we ensure that any widgets are inflated for the current
|
||||||
|
// orientation.
|
||||||
|
reinflateWidgetsIfNecessary();
|
||||||
|
}
|
||||||
|
|
||||||
|
void reinflateWidgetsIfNecessary() {
|
||||||
|
for (LauncherAppWidgetInfo info: LauncherModel.getWidgets()) {
|
||||||
|
LauncherAppWidgetHostView lahv = (LauncherAppWidgetHostView) info.hostView;
|
||||||
|
if (lahv != null && lahv.orientationChangedSincedInflation()) {
|
||||||
|
AppWidgetProviderInfo pInfo = lahv.getAppWidgetInfo();
|
||||||
|
|
||||||
|
// Remove the current widget which is inflated with the wrong orientation
|
||||||
|
getWorkspace().getParentCellLayoutForView(lahv).removeView(lahv);
|
||||||
|
// Re-inflate the widget using the correct orientation
|
||||||
|
AppWidgetHostView widget = mAppWidgetHost.createView(this, info.appWidgetId, pInfo);
|
||||||
|
|
||||||
|
// Add the new widget back
|
||||||
|
widget.setTag(info);
|
||||||
|
info.hostView = widget;
|
||||||
|
getWorkspace().addInScreen(widget, info.container, info.screen,
|
||||||
|
info.cellX, info.cellY, info.spanX, info.spanY);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -18,10 +18,14 @@ package com.android.launcher2;
|
|||||||
|
|
||||||
import android.appwidget.AppWidgetHostView;
|
import android.appwidget.AppWidgetHostView;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Configuration;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.Parcel;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.RemoteViews;
|
||||||
|
|
||||||
import com.android.launcher.R;
|
import com.android.launcher.R;
|
||||||
|
|
||||||
@@ -31,9 +35,12 @@ import com.android.launcher.R;
|
|||||||
public class LauncherAppWidgetHostView extends AppWidgetHostView {
|
public class LauncherAppWidgetHostView extends AppWidgetHostView {
|
||||||
private CheckLongPressHelper mLongPressHelper;
|
private CheckLongPressHelper mLongPressHelper;
|
||||||
private LayoutInflater mInflater;
|
private LayoutInflater mInflater;
|
||||||
|
private Context mContext;
|
||||||
|
private int mPreviousOrientation;
|
||||||
|
|
||||||
public LauncherAppWidgetHostView(Context context) {
|
public LauncherAppWidgetHostView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
mContext = context;
|
||||||
mLongPressHelper = new CheckLongPressHelper(this);
|
mLongPressHelper = new CheckLongPressHelper(this);
|
||||||
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
||||||
}
|
}
|
||||||
@@ -43,6 +50,21 @@ public class LauncherAppWidgetHostView extends AppWidgetHostView {
|
|||||||
return mInflater.inflate(R.layout.appwidget_error, this, false);
|
return mInflater.inflate(R.layout.appwidget_error, this, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateAppWidget(RemoteViews remoteViews) {
|
||||||
|
// Store the orientation in which the widget was inflated
|
||||||
|
mPreviousOrientation = mContext.getResources().getConfiguration().orientation;
|
||||||
|
super.updateAppWidget(remoteViews);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean orientationChangedSincedInflation() {
|
||||||
|
int orientation = mContext.getResources().getConfiguration().orientation;
|
||||||
|
if (mPreviousOrientation != orientation) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
public boolean onInterceptTouchEvent(MotionEvent ev) {
|
||||||
// Consume any touch events for ourselves after longpress is triggered
|
// Consume any touch events for ourselves after longpress is triggered
|
||||||
if (mLongPressHelper.hasPerformedLongPress()) {
|
if (mLongPressHelper.hasPerformedLongPress()) {
|
||||||
|
|||||||
@@ -377,6 +377,10 @@ public class LauncherModel extends BroadcastReceiver {
|
|||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static ArrayList<LauncherAppWidgetInfo> getWidgets() {
|
||||||
|
return sAppWidgets;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find a folder in the db, creating the FolderInfo if necessary, and adding it to folderList.
|
* Find a folder in the db, creating the FolderInfo if necessary, and adding it to folderList.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user