Use Launcher.getLauncher(Context) instead of type-casting.

Bug: 32010039
Change-Id: Icb80d3e547a706740b84df2cb80f99e4a7f81c43
This commit is contained in:
Tony
2016-10-07 12:50:01 -07:00
parent 6e74e899d3
commit 2fd0208605
19 changed files with 29 additions and 25 deletions

View File

@@ -80,7 +80,7 @@ public class AppWidgetResizeFrame extends FrameLayout implements View.OnKeyListe
LauncherAppWidgetHostView widgetView, CellLayout cellLayout, DragLayer dragLayer) {
super(context);
mLauncher = (Launcher) context;
mLauncher = Launcher.getLauncher(context);
mCellLayout = cellLayout;
mWidgetView = widgetView;
LauncherAppWidgetProviderInfo info = (LauncherAppWidgetProviderInfo)

View File

@@ -83,7 +83,7 @@ public abstract class ButtonDropTarget extends TextView
public ButtonDropTarget(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mLauncher = (Launcher) context;
mLauncher = Launcher.getLauncher(context);
Resources resources = getResources();
mBottomDragPadding = resources.getDimensionPixelSize(R.dimen.drop_target_drag_padding);

View File

@@ -196,7 +196,7 @@ public class CellLayout extends ViewGroup implements BubbleTextShadowHandler {
// the user where a dragged item will land when dropped.
setWillNotDraw(false);
setClipToPadding(false);
mLauncher = (Launcher) context;
mLauncher = Launcher.getLauncher(context);
DeviceProfile grid = mLauncher.getDeviceProfile();

View File

@@ -204,7 +204,7 @@ public class FocusHelper {
return consume;
}
final Launcher launcher = (Launcher) v.getContext();
final Launcher launcher = Launcher.getLauncher(v.getContext());
final DeviceProfile profile = launcher.getDeviceProfile();
if (DEBUG) {
@@ -341,7 +341,7 @@ public class FocusHelper {
return consume;
}
Launcher launcher = (Launcher) v.getContext();
Launcher launcher = Launcher.getLauncher(v.getContext());
DeviceProfile profile = launcher.getDeviceProfile();
if (DEBUG) {

View File

@@ -67,7 +67,7 @@ public class Hotseat extends FrameLayout
public Hotseat(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mLauncher = (Launcher) context;
mLauncher = Launcher.getLauncher(context);
mHasVerticalHotseat = mLauncher.getDeviceProfile().isVerticalBarLayout();
mBackgroundColor = ColorUtils.setAlphaComponent(
ContextCompat.getColor(context, R.color.all_apps_container_color), 0);

View File

@@ -728,7 +728,8 @@ public class LauncherModel extends BroadcastReceiver
// in the hotseat
if (context instanceof Launcher && screenId < 0 &&
container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
item.screenId = ((Launcher) context).getHotseat().getOrderInHotseat(cellX, cellY);
item.screenId = Launcher.getLauncher(context).getHotseat()
.getOrderInHotseat(cellX, cellY);
} else {
item.screenId = screenId;
}
@@ -761,7 +762,7 @@ public class LauncherModel extends BroadcastReceiver
// in the hotseat
if (context instanceof Launcher && screen < 0 &&
container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
item.screenId = ((Launcher) context).getHotseat().getOrderInHotseat(item.cellX,
item.screenId = Launcher.getLauncher(context).getHotseat().getOrderInHotseat(item.cellX,
item.cellY);
} else {
item.screenId = screen;
@@ -794,7 +795,8 @@ public class LauncherModel extends BroadcastReceiver
// in the hotseat
if (context instanceof Launcher && screenId < 0 &&
container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
item.screenId = ((Launcher) context).getHotseat().getOrderInHotseat(cellX, cellY);
item.screenId = Launcher.getLauncher(context).getHotseat()
.getOrderInHotseat(cellX, cellY);
} else {
item.screenId = screenId;
}
@@ -887,7 +889,8 @@ public class LauncherModel extends BroadcastReceiver
// in the hotseat
if (context instanceof Launcher && screenId < 0 &&
container == LauncherSettings.Favorites.CONTAINER_HOTSEAT) {
item.screenId = ((Launcher) context).getHotseat().getOrderInHotseat(cellX, cellY);
item.screenId = Launcher.getLauncher(context).getHotseat()
.getOrderInHotseat(cellX, cellY);
} else {
item.screenId = screenId;
}

View File

@@ -1834,7 +1834,7 @@ public abstract class PagedView extends ViewGroup implements ViewGroup.OnHierarc
}
protected void onUnhandledTap(MotionEvent ev) {
((Launcher) getContext()).onClick(this);
Launcher.getLauncher(getContext()).onClick(this);
}
@Override

View File

@@ -104,7 +104,7 @@ public class QsbContainerView extends FrameLayout {
}
private View createQsb(LayoutInflater inflater, ViewGroup container) {
Launcher launcher = (Launcher) getActivity();
Launcher launcher = Launcher.getLauncher(getActivity());
mWidgetInfo = getSearchWidgetProvider(launcher);
if (mWidgetInfo == null) {
// There is no search provider, just show the default widget.
@@ -168,7 +168,7 @@ public class QsbContainerView extends FrameLayout {
getActivity().startSearch("", false, null, true);
} else if (view.getId() == R.id.btn_qsb_setup) {
// Allocate a new widget id for QSB
sSavedWidgetId = ((Launcher) getActivity())
sSavedWidgetId = Launcher.getLauncher(getActivity())
.getAppWidgetHost().allocateAppWidgetId();
// Start intent for bind the widget
Intent intent = new Intent(AppWidgetManager.ACTION_APPWIDGET_BIND);
@@ -194,7 +194,8 @@ public class QsbContainerView extends FrameLayout {
sSavedWidgetId = -1;
rebindFragment();
} else if (sSavedWidgetId != -1) {
((Launcher) getActivity()).getAppWidgetHost().deleteAppWidgetId(sSavedWidgetId);
Launcher.getLauncher(getActivity()).getAppWidgetHost()
.deleteAppWidgetId(sSavedWidgetId);
sSavedWidgetId = -1;
}
}

View File

@@ -48,7 +48,7 @@ public class ShortcutAndWidgetContainer extends ViewGroup {
public ShortcutAndWidgetContainer(Context context) {
super(context);
mLauncher = (Launcher) context;
mLauncher = Launcher.getLauncher(context);
mWallpaperManager = WallpaperManager.getInstance(context);
}

View File

@@ -338,7 +338,7 @@ public class Workspace extends PagedView
public Workspace(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mLauncher = (Launcher) context;
mLauncher = Launcher.getLauncher(context);
mStateTransitionAnimation = new WorkspaceStateTransitionAnimation(mLauncher, this);
final Resources res = getResources();
DeviceProfile grid = mLauncher.getDeviceProfile();

View File

@@ -50,7 +50,7 @@ public abstract class DragAndDropAccessibilityDelegate extends ExploreByTouchHel
super(forView);
mView = forView;
mContext = mView.getContext();
mDelegate = ((Launcher) mContext).getAccessibilityDelegate();
mDelegate = Launcher.getLauncher(mContext).getAccessibilityDelegate();
}
@Override

View File

@@ -53,7 +53,7 @@ public class OverviewAccessibilityDelegate extends AccessibilityDelegate {
@Override
public boolean performAccessibilityAction(View host, int action, Bundle args) {
Launcher launcher = (Launcher) host.getContext();
Launcher launcher = Launcher.getLauncher(host.getContext());
if (action == OVERVIEW) {
launcher.showOverviewMode(true);
return true;

View File

@@ -696,7 +696,7 @@ public class AllAppsContainerView extends BaseContainerView implements DragSourc
float distance = (float) Math.hypot(dx, dy);
if (distance < viewConfig.getScaledTouchSlop()) {
// The background was clicked, so just go home
Launcher launcher = (Launcher) getContext();
Launcher launcher = Launcher.getLauncher(getContext());
launcher.showWorkspace(true);
return true;
}

View File

@@ -49,7 +49,7 @@ public class AllAppsRecyclerViewContainerView extends FrameLayout
public AllAppsRecyclerViewContainerView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
Launcher launcher = (Launcher) context;
Launcher launcher = Launcher.getLauncher(context);
DeviceProfile grid = launcher.getDeviceProfile();
mTouchFeedbackView = new ClickShadowView(context);

View File

@@ -209,7 +209,7 @@ public class AlphabeticalAppsList {
private int mNumAppRowsInAdapter;
public AlphabeticalAppsList(Context context) {
mLauncher = (Launcher) context;
mLauncher = Launcher.getLauncher(context);
mIndexer = new AlphabeticIndexCompat(context);
mAppNameComparator = new AppNameComparator(context);
}

View File

@@ -212,7 +212,7 @@ public class Folder extends LinearLayout implements DragSource, View.OnClickList
if (sHintText == null) {
sHintText = res.getString(R.string.folder_hint_text);
}
mLauncher = (Launcher) context;
mLauncher = Launcher.getLauncher(context);
// We need this view to be focusable in touch mode so that when text editing of the folder
// name is complete, we have something to focus on, thus hiding the cursor and giving
// reliable behavior when clicking the text field (since it will always gain focus on click).

View File

@@ -252,7 +252,7 @@ public class FolderPagedView extends PagedView {
}
private CellLayout createAndAddNewPage() {
DeviceProfile grid = ((Launcher) getContext()).getDeviceProfile();
DeviceProfile grid = Launcher.getLauncher(getContext()).getDeviceProfile();
CellLayout page = new CellLayout(getContext());
page.setCellDimensions(grid.folderCellWidthPx, grid.folderCellHeightPx);
page.getShortcutsAndWidgets().setMotionEventSplittingEnabled(false);

View File

@@ -49,7 +49,7 @@ public class PageIndicatorCaretLandscape extends PageIndicator {
caretDrawable.setBounds(0, 0, caretSize, caretSize);
setCaretDrawable(caretDrawable);
Launcher l = (Launcher) context;
Launcher l = Launcher.getLauncher(context);
setOnTouchListener(l.getHapticFeedbackTouchListener());
setOnClickListener(l);
setOnLongClickListener(l);

View File

@@ -125,7 +125,7 @@ public class PageIndicatorLineCaret extends PageIndicator {
mLinePaint = new Paint();
mLinePaint.setAlpha(0);
mLauncher = (Launcher) context;
mLauncher = Launcher.getLauncher(context);
mLineHeight = res.getDimensionPixelSize(R.dimen.dynamic_grid_page_indicator_line_height);
setCaretDrawable(new CaretDrawable(context));
}