diff options
Diffstat (limited to 'src_ui_overrides/com/android/launcher3/uioverrides')
5 files changed, 6 insertions, 428 deletions
diff --git a/src_ui_overrides/com/android/launcher3/uioverrides/OverviewAccessibilityDelegate.java b/src_ui_overrides/com/android/launcher3/uioverrides/OverviewAccessibilityDelegate.java index 88a1e10d8..d9ce87c7c 100644 --- a/src_ui_overrides/com/android/launcher3/uioverrides/OverviewAccessibilityDelegate.java +++ b/src_ui_overrides/com/android/launcher3/uioverrides/OverviewAccessibilityDelegate.java @@ -27,13 +27,13 @@ import com.android.launcher3.Launcher; import com.android.launcher3.LauncherState; import com.android.launcher3.R; import com.android.launcher3.Utilities; +import com.android.launcher3.views.OptionsPopupView; /** * Accessibility delegate with actions pointing to various Overview entry points. */ public class OverviewAccessibilityDelegate extends AccessibilityDelegate { - private static final int OVERVIEW = R.string.accessibility_action_overview; private static final int WALLPAPERS = R.string.wallpaper_button_text; private static final int WIDGETS = R.string.widget_button_text; private static final int SETTINGS = R.string.settings_button_text; @@ -43,7 +43,6 @@ public class OverviewAccessibilityDelegate extends AccessibilityDelegate { super.onInitializeAccessibilityNodeInfo(host, info); Context context = host.getContext(); - info.addAction(new AccessibilityAction(OVERVIEW, context.getText(OVERVIEW))); if (Utilities.isWallpaperAllowed(context)) { info.addAction(new AccessibilityAction(WALLPAPERS, context.getText(WALLPAPERS))); @@ -55,18 +54,13 @@ public class OverviewAccessibilityDelegate extends AccessibilityDelegate { @Override public boolean performAccessibilityAction(View host, int action, Bundle args) { Launcher launcher = Launcher.getLauncher(host.getContext()); - OverviewPanel overviewPanel = launcher.findViewById(R.id.overview_panel); - if (action == OVERVIEW) { - launcher.getStateManager().goToState(LauncherState.OVERVIEW); - return true; - } else if (action == WALLPAPERS) { + if (action == WALLPAPERS) { launcher.onClickWallpaperPicker(host); return true; } else if (action == WIDGETS) { - overviewPanel.onClickAddWidgetButton(); - return true; + return OptionsPopupView.onWidgetsClicked(launcher); } else if (action == SETTINGS) { - overviewPanel.onClickSettingsButton(host); + OptionsPopupView.startSettings(launcher); return true; } return super.performAccessibilityAction(host, action, args); diff --git a/src_ui_overrides/com/android/launcher3/uioverrides/OverviewPanel.java b/src_ui_overrides/com/android/launcher3/uioverrides/OverviewPanel.java deleted file mode 100644 index 616e25c2b..000000000 --- a/src_ui_overrides/com/android/launcher3/uioverrides/OverviewPanel.java +++ /dev/null @@ -1,194 +0,0 @@ -/* - * Copyright (C) 2017 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.android.launcher3.uioverrides; - -import static com.android.launcher3.LauncherState.OVERVIEW; -import static com.android.launcher3.WorkspaceStateTransitionAnimation.NO_ANIM_PROPERTY_SETTER; - -import android.content.Context; -import android.content.Intent; -import android.content.res.Resources; -import android.graphics.Rect; -import android.util.AttributeSet; -import android.view.View; -import android.widget.FrameLayout; -import android.widget.LinearLayout; -import android.widget.Toast; - -import com.android.launcher3.Insettable; -import com.android.launcher3.Launcher; -import com.android.launcher3.LauncherState; -import com.android.launcher3.LauncherStateManager; -import com.android.launcher3.LauncherStateManager.AnimationConfig; -import com.android.launcher3.R; -import com.android.launcher3.Utilities; -import com.android.launcher3.WorkspaceStateTransitionAnimation.AnimatedPropertySetter; -import com.android.launcher3.WorkspaceStateTransitionAnimation.PropertySetter; -import com.android.launcher3.anim.AnimatorSetBuilder; -import com.android.launcher3.anim.Interpolators; -import com.android.launcher3.userevent.nano.LauncherLogProto.Action; -import com.android.launcher3.userevent.nano.LauncherLogProto.ControlType; -import com.android.launcher3.widget.WidgetsFullSheet; - -public class OverviewPanel extends LinearLayout implements Insettable, View.OnClickListener, - View.OnLongClickListener, LauncherStateManager.StateHandler { - - // Out of 100, the percent of space the overview bar should try and take vertically. - private static final float OVERVIEW_ICON_ZONE_RATIO = 0.22f; - - private final Launcher mLauncher; - - public OverviewPanel(Context context) { - this(context, null); - } - - public OverviewPanel(Context context, AttributeSet attrs) { - this(context, attrs, 0); - } - - public OverviewPanel(Context context, AttributeSet attrs, int defStyleAttr) { - super(context, attrs, defStyleAttr); - mLauncher = Launcher.getLauncher(context); - setAlpha(0); - } - - @Override - protected void onFinishInflate() { - super.onFinishInflate(); - - int visibleChildCount = 3; - // Attach buttons. - attachListeners(findViewById(R.id.wallpaper_button)); - attachListeners(findViewById(R.id.widget_button)); - - View settingsButton = findViewById(R.id.settings_button); - if (mLauncher.hasSettings()) { - attachListeners(settingsButton); - } else { - settingsButton.setVisibility(GONE); - visibleChildCount--; - } - - // Init UI - Resources res = getResources(); - int itemWidthPx = - res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_bar_item_width); - int spacerWidthPx = - res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_bar_spacer_width); - - int totalItemWidth = visibleChildCount * itemWidthPx; - int maxWidth = totalItemWidth + (visibleChildCount - 1) * spacerWidthPx; - - getLayoutParams().width = Math.min(mLauncher.getDeviceProfile().availableWidthPx, maxWidth); - getLayoutParams().height = getButtonBarHeight(mLauncher); - } - - private void attachListeners(View view) { - view.setOnClickListener(this); - view.setOnLongClickListener(this); - } - - @Override - public void setInsets(Rect insets) { - ((FrameLayout.LayoutParams) getLayoutParams()).bottomMargin = insets.bottom; - } - - @Override - public void onClick(View view) { - handleViewClick(view, Action.Touch.TAP); - } - - @Override - public boolean onLongClick(View view) { - return handleViewClick(view, Action.Touch.LONGPRESS); - } - - private boolean handleViewClick(View view, int action) { - if (mLauncher.getWorkspace().isSwitchingState()) { - return false; - } - - final int controlType; - if (view.getId() == R.id.wallpaper_button) { - mLauncher.onClickWallpaperPicker(view); - controlType = ControlType.WALLPAPER_BUTTON; - } else if (view.getId() == R.id.widget_button) { - onClickAddWidgetButton(); - controlType = ControlType.WIDGETS_BUTTON; - } else if (view.getId() == R.id.settings_button) { - onClickSettingsButton(view); - controlType = ControlType.SETTINGS_BUTTON; - } else { - return false; - } - - mLauncher.getUserEventDispatcher().logActionOnControl(action, controlType); - return true; - } - - /** - * Event handler for the (Add) Widgets button that appears after a long press - * on the home screen. - */ - public void onClickAddWidgetButton() { - if (getContext().getPackageManager().isSafeMode()) { - Toast.makeText(mLauncher, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show(); - } else { - WidgetsFullSheet.show(mLauncher, true /* animated */); - } - } - - /** - * Event handler for a click on the settings button that appears after a long press - * on the home screen. - */ - public void onClickSettingsButton(View v) { - Intent intent = new Intent(Intent.ACTION_APPLICATION_PREFERENCES) - .setPackage(getContext().getPackageName()); - intent.setSourceBounds(mLauncher.getViewBounds(v)); - intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - getContext().startActivity(intent, mLauncher.getActivityLaunchOptionsAsBundle(v, false)); - } - - @Override - public void setState(LauncherState state) { - setState(state, NO_ANIM_PROPERTY_SETTER); - } - - @Override - public void setStateWithAnimation(LauncherState toState, - AnimatorSetBuilder builder, AnimationConfig config) { - setState(toState, new AnimatedPropertySetter(config.duration, builder)); - } - - private void setState(LauncherState state, PropertySetter setter) { - float myAlpha = state == OVERVIEW ? 1 : 0; - setter.setViewAlpha(this, myAlpha, Interpolators.ACCEL); - } - - public static int getButtonBarHeight(Launcher launcher) { - int zoneHeight = (int) (OVERVIEW_ICON_ZONE_RATIO * - launcher.getDeviceProfile().availableHeightPx); - Resources res = launcher.getResources(); - int overviewModeMinIconZoneHeightPx = - res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_min_icon_zone_height); - int overviewModeMaxIconZoneHeightPx = - res.getDimensionPixelSize(R.dimen.dynamic_grid_overview_max_icon_zone_height); - return Utilities.boundToRange(zoneHeight, - overviewModeMinIconZoneHeightPx, - overviewModeMaxIconZoneHeightPx); - } -} diff --git a/src_ui_overrides/com/android/launcher3/uioverrides/OverviewState.java b/src_ui_overrides/com/android/launcher3/uioverrides/OverviewState.java index 37d0aa249..3dfbc401d 100644 --- a/src_ui_overrides/com/android/launcher3/uioverrides/OverviewState.java +++ b/src_ui_overrides/com/android/launcher3/uioverrides/OverviewState.java @@ -33,56 +33,7 @@ import com.android.launcher3.userevent.nano.LauncherLogProto.ContainerType; */ public class OverviewState extends LauncherState { - // The percent to shrink the workspace during overview mode - private static final float SCALE_FACTOR = 0.7f; - - private static final int STATE_FLAGS = FLAG_SHOW_SCRIM | FLAG_MULTI_PAGE | - FLAG_DISABLE_PAGE_CLIPPING | FLAG_PAGE_BACKGROUNDS | FLAG_OVERVIEW_UI; - public OverviewState(int id) { - super(id, ContainerType.WORKSPACE, OVERVIEW_TRANSITION_MS, STATE_FLAGS); - } - - @Override - public float[] getWorkspaceScaleAndTranslation(Launcher launcher) { - DeviceProfile grid = launcher.getDeviceProfile(); - Workspace ws = launcher.getWorkspace(); - Rect insets = launcher.getDragLayer().getInsets(); - - int overviewButtonBarHeight = OverviewPanel.getButtonBarHeight(launcher); - int scaledHeight = (int) (SCALE_FACTOR * ws.getNormalChildHeight()); - int workspaceTop = insets.top + grid.workspacePadding.top; - int workspaceBottom = ws.getHeight() - insets.bottom - grid.workspacePadding.bottom; - int overviewTop = insets.top; - int overviewBottom = ws.getHeight() - insets.bottom - overviewButtonBarHeight; - int workspaceOffsetTopEdge = - workspaceTop + ((workspaceBottom - workspaceTop) - scaledHeight) / 2; - int overviewOffsetTopEdge = overviewTop + (overviewBottom - overviewTop - scaledHeight) / 2; - return new float[] {SCALE_FACTOR, 0, -workspaceOffsetTopEdge + overviewOffsetTopEdge }; - } - - @Override - public float getHoseatAlpha(Launcher launcher) { - return 0; - } - - @Override - public void onStateEnabled(Launcher launcher) { - launcher.getWorkspace().setPageRearrangeEnabled(true); - - if (isAccessibilityEnabled(launcher)) { - launcher.getOverviewPanel().getChildAt(0).performAccessibilityAction( - AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null); - } - } - - @Override - public void onStateDisabled(Launcher launcher) { - launcher.getWorkspace().setPageRearrangeEnabled(false); - } - - @Override - public View getFinalFocus(Launcher launcher) { - return launcher.getOverviewPanel(); + super(id, ContainerType.WORKSPACE, OVERVIEW_TRANSITION_MS, FLAG_DISABLE_RESTORE); } } diff --git a/src_ui_overrides/com/android/launcher3/uioverrides/PinchToOverviewListener.java b/src_ui_overrides/com/android/launcher3/uioverrides/PinchToOverviewListener.java deleted file mode 100644 index a7c8cee29..000000000 --- a/src_ui_overrides/com/android/launcher3/uioverrides/PinchToOverviewListener.java +++ /dev/null @@ -1,164 +0,0 @@ -/* - * Copyright (C) 2016 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.android.launcher3.uioverrides; - -import static com.android.launcher3.LauncherAnimUtils.OVERVIEW_TRANSITION_MS; -import static com.android.launcher3.LauncherState.NORMAL; -import static com.android.launcher3.LauncherState.OVERVIEW; -import static com.android.launcher3.compat.AccessibilityManagerCompat.isAccessibilityEnabled; - -import android.animation.Animator; -import android.animation.AnimatorListenerAdapter; -import android.view.MotionEvent; -import android.view.ScaleGestureDetector; -import android.view.ScaleGestureDetector.OnScaleGestureListener; - -import com.android.launcher3.AbstractFloatingView; -import com.android.launcher3.Launcher; -import com.android.launcher3.LauncherState; -import com.android.launcher3.Workspace; -import com.android.launcher3.anim.AnimatorPlaybackController; -import com.android.launcher3.util.TouchController; - -/** - * Detects pinches and animates the Workspace to/from overview mode. - */ -public class PinchToOverviewListener extends AnimatorListenerAdapter - implements TouchController, OnScaleGestureListener { - - private static final float ACCEPT_THRESHOLD = 0.65f; - /** - * The velocity threshold at which a pinch will be completed instead of canceled, - * even if the first threshold has not been passed. Measured in scale / millisecond - */ - private static final float FLING_VELOCITY = 0.001f; - - private final ScaleGestureDetector mPinchDetector; - private Launcher mLauncher; - private Workspace mWorkspace = null; - private boolean mPinchStarted = false; - - private AnimatorPlaybackController mCurrentAnimation; - private float mCurrentScale; - private boolean mShouldGoToFinalState; - - private LauncherState mToState; - - public PinchToOverviewListener(Launcher launcher) { - mLauncher = launcher; - mPinchDetector = new ScaleGestureDetector(mLauncher, this); - } - - public boolean onControllerInterceptTouchEvent(MotionEvent ev) { - mPinchDetector.onTouchEvent(ev); - return mPinchStarted; - } - - public boolean onControllerTouchEvent(MotionEvent ev) { - return mPinchDetector.onTouchEvent(ev); - } - - @Override - public boolean onScaleBegin(ScaleGestureDetector detector) { - if (isAccessibilityEnabled(mLauncher)) { - return false; - } - if (!mLauncher.isInState(NORMAL) && !mLauncher.isInState(OVERVIEW)) { - // Don't listen for the pinch gesture if on all apps, widget picker, -1, etc. - return false; - } - if (mCurrentAnimation != null) { - // Don't listen for the pinch gesture if we are already animating from a previous one. - return false; - } - if (mLauncher.isWorkspaceLocked()) { - // Don't listen for the pinch gesture if the workspace isn't ready. - return false; - } - if (mWorkspace == null) { - mWorkspace = mLauncher.getWorkspace(); - } - if (mWorkspace.isSwitchingState()) { - // Don't listen for the pinch gesture while switching state, as it will cause a jump - // once the state switching animation is complete. - return false; - } - if (AbstractFloatingView.getTopOpenView(mLauncher) != null) { - // Don't listen for the pinch gesture if a floating view is open. - return false; - } - - if (mLauncher.getDragController().isDragging()) { - mLauncher.getDragController().cancelDrag(); - } - - mToState = mLauncher.isInState(OVERVIEW) ? NORMAL : OVERVIEW; - mCurrentAnimation = mLauncher.getStateManager() - .createAnimationToNewWorkspace(mToState, OVERVIEW_TRANSITION_MS); - mCurrentAnimation.getTarget().addListener(this); - mPinchStarted = true; - mCurrentScale = 1; - mShouldGoToFinalState = false; - - mCurrentAnimation.dispatchOnStart(); - return true; - } - - @Override - public void onAnimationEnd(Animator animation) { - mCurrentAnimation = null; - mPinchStarted = false; - } - - @Override - public void onScaleEnd(ScaleGestureDetector detector) { - if (mShouldGoToFinalState) { - mCurrentAnimation.start(); - } else { - mCurrentAnimation.setEndAction(new Runnable() { - @Override - public void run() { - mLauncher.getStateManager().goToState( - mToState == OVERVIEW ? NORMAL : OVERVIEW, false); - } - }); - mCurrentAnimation.reverse(); - } - } - - @Override - public boolean onScale(ScaleGestureDetector detector) { - mCurrentScale = detector.getScaleFactor() * mCurrentScale; - - // If we are zooming out, inverse the mCurrentScale so that animationFraction = [0, 1] - // 0 => Animation complete - // 1=> Animation started - float animationFraction = mToState == OVERVIEW ? mCurrentScale : (1 / mCurrentScale); - - float velocity = (1 - detector.getScaleFactor()) / detector.getTimeDelta(); - if (Math.abs(velocity) >= FLING_VELOCITY) { - LauncherState toState = velocity > 0 ? OVERVIEW : NORMAL; - mShouldGoToFinalState = toState == mToState; - } else { - mShouldGoToFinalState = animationFraction <= ACCEPT_THRESHOLD; - } - - // Move the transition animation to that duration. - mCurrentAnimation.setPlayFraction(1 - animationFraction); - return true; - } -}
\ No newline at end of file diff --git a/src_ui_overrides/com/android/launcher3/uioverrides/UiFactory.java b/src_ui_overrides/com/android/launcher3/uioverrides/UiFactory.java index de75ac9ba..a9694a74c 100644 --- a/src_ui_overrides/com/android/launcher3/uioverrides/UiFactory.java +++ b/src_ui_overrides/com/android/launcher3/uioverrides/UiFactory.java @@ -16,9 +16,6 @@ package com.android.launcher3.uioverrides; -import static com.android.launcher3.LauncherState.OVERVIEW; - -import android.graphics.PointF; import android.view.View.AccessibilityDelegate; import com.android.launcher3.Launcher; @@ -28,8 +25,7 @@ import com.android.launcher3.util.TouchController; public class UiFactory { public static TouchController[] createTouchControllers(Launcher launcher) { - return new TouchController[] { - new AllAppsSwipeController(launcher), new PinchToOverviewListener(launcher)}; + return new TouchController[] {new AllAppsSwipeController(launcher)}; } public static AccessibilityDelegate newPageIndicatorAccessibilityDelegate() { @@ -38,14 +34,9 @@ public class UiFactory { public static StateHandler[] getStateHandler(Launcher launcher) { return new StateHandler[] { - (OverviewPanel) launcher.getOverviewPanel(), launcher.getAllAppsController(), launcher.getWorkspace() }; } - public static void onWorkspaceLongPress(Launcher launcher, PointF touchPoint) { - launcher.getStateManager().goToState(OVERVIEW); - } - public static void resetOverview(Launcher launcher) { } public static void onLauncherStateOrFocusChanged(Launcher launcher) { } |