diff options
Diffstat (limited to 'src/com/android/launcher3/util')
-rw-r--r-- | src/com/android/launcher3/util/CircleRevealOutlineProvider.java | 53 | ||||
-rw-r--r-- | src/com/android/launcher3/util/FocusLogic.java | 1 | ||||
-rw-r--r-- | src/com/android/launcher3/util/LooperExecutor.java (renamed from src/com/android/launcher3/util/LooperExecuter.java) | 4 | ||||
-rw-r--r-- | src/com/android/launcher3/util/LooperIdleLock.java | 71 | ||||
-rw-r--r-- | src/com/android/launcher3/util/PillRevealOutlineProvider.java | 68 | ||||
-rw-r--r-- | src/com/android/launcher3/util/Preconditions.java | 10 | ||||
-rw-r--r-- | src/com/android/launcher3/util/RevealOutlineAnimation.java | 86 | ||||
-rw-r--r-- | src/com/android/launcher3/util/SQLiteCacheHelper.java | 4 | ||||
-rw-r--r-- | src/com/android/launcher3/util/TestingUtils.java | 2 | ||||
-rw-r--r-- | src/com/android/launcher3/util/ViewOnDrawExecutor.java | 10 |
10 files changed, 84 insertions, 225 deletions
diff --git a/src/com/android/launcher3/util/CircleRevealOutlineProvider.java b/src/com/android/launcher3/util/CircleRevealOutlineProvider.java deleted file mode 100644 index 9fe51476d..000000000 --- a/src/com/android/launcher3/util/CircleRevealOutlineProvider.java +++ /dev/null @@ -1,53 +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.util; - -public class CircleRevealOutlineProvider extends RevealOutlineAnimation { - - private int mCenterX; - private int mCenterY; - private float mRadius0; - private float mRadius1; - - /** - * @param x reveal center x - * @param y reveal center y - * @param r0 initial radius - * @param r1 final radius - */ - public CircleRevealOutlineProvider(int x, int y, float r0, float r1) { - mCenterX = x; - mCenterY = y; - mRadius0 = r0; - mRadius1 = r1; - } - - @Override - public boolean shouldRemoveElevationDuringAnimation() { - return true; - } - - @Override - public void setProgress(float progress) { - mOutlineRadius = (1 - progress) * mRadius0 + progress * mRadius1; - - mOutline.left = (int) (mCenterX - mOutlineRadius); - mOutline.top = (int) (mCenterY - mOutlineRadius); - mOutline.right = (int) (mCenterX + mOutlineRadius); - mOutline.bottom = (int) (mCenterY + mOutlineRadius); - } -} diff --git a/src/com/android/launcher3/util/FocusLogic.java b/src/com/android/launcher3/util/FocusLogic.java index afc45fe35..b80e94d15 100644 --- a/src/com/android/launcher3/util/FocusLogic.java +++ b/src/com/android/launcher3/util/FocusLogic.java @@ -23,7 +23,6 @@ import android.view.ViewGroup; import com.android.launcher3.CellLayout; import com.android.launcher3.DeviceProfile; -import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.ShortcutAndWidgetContainer; import com.android.launcher3.config.FeatureFlags; diff --git a/src/com/android/launcher3/util/LooperExecuter.java b/src/com/android/launcher3/util/LooperExecutor.java index 4db999bce..5b7c20bbf 100644 --- a/src/com/android/launcher3/util/LooperExecuter.java +++ b/src/com/android/launcher3/util/LooperExecutor.java @@ -25,11 +25,11 @@ import java.util.concurrent.TimeUnit; /** * Extension of {@link AbstractExecutorService} which executed on a provided looper. */ -public class LooperExecuter extends AbstractExecutorService { +public class LooperExecutor extends AbstractExecutorService { private final Handler mHandler; - public LooperExecuter(Looper looper) { + public LooperExecutor(Looper looper) { mHandler = new Handler(looper); } diff --git a/src/com/android/launcher3/util/LooperIdleLock.java b/src/com/android/launcher3/util/LooperIdleLock.java new file mode 100644 index 000000000..35cac14e3 --- /dev/null +++ b/src/com/android/launcher3/util/LooperIdleLock.java @@ -0,0 +1,71 @@ +/* + * 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.util; + +import android.os.Looper; +import android.os.MessageQueue; + +import com.android.launcher3.Utilities; + +/** + * Utility class to block execution until the UI looper is idle. + */ +public class LooperIdleLock implements MessageQueue.IdleHandler, Runnable { + + private final Object mLock; + + private boolean mIsLocked; + + public LooperIdleLock(Object lock, Looper looper) { + mLock = lock; + mIsLocked = true; + if (Utilities.ATLEAST_MARSHMALLOW) { + looper.getQueue().addIdleHandler(this); + } else { + // Looper.myQueue() only gives the current queue. Move the execution to the UI thread + // so that the IdleHandler is attached to the correct message queue. + new LooperExecutor(looper).execute(this); + } + } + + @Override + public void run() { + Looper.myQueue().addIdleHandler(this); + } + + @Override + public boolean queueIdle() { + synchronized (mLock) { + mIsLocked = false; + mLock.notify(); + } + return false; + } + + public boolean awaitLocked(long ms) { + if (mIsLocked) { + try { + // Just in case mFlushingWorkerThread changes but we aren't woken up, + // wait no longer than 1sec at a time + mLock.wait(ms); + } catch (InterruptedException ex) { + // Ignore + } + } + return mIsLocked; + } +} diff --git a/src/com/android/launcher3/util/PillRevealOutlineProvider.java b/src/com/android/launcher3/util/PillRevealOutlineProvider.java deleted file mode 100644 index a57d69fab..000000000 --- a/src/com/android/launcher3/util/PillRevealOutlineProvider.java +++ /dev/null @@ -1,68 +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.util; - -import android.graphics.Rect; -import android.view.ViewOutlineProvider; - -/** - * A {@link ViewOutlineProvider} that animates a reveal in a "pill" shape. - * A pill is simply a round rect, but we assume the width is greater than - * the height and that the radius is equal to half the height. - */ -public class PillRevealOutlineProvider extends RevealOutlineAnimation { - - private int mCenterX; - private int mCenterY; - private float mFinalRadius; - protected Rect mPillRect; - - /** - * @param x reveal center x - * @param y reveal center y - * @param pillRect round rect that represents the final pill shape - */ - public PillRevealOutlineProvider(int x, int y, Rect pillRect) { - this(x, y, pillRect, pillRect.height() / 2f); - } - - public PillRevealOutlineProvider(int x, int y, Rect pillRect, float radius) { - mCenterX = x; - mCenterY = y; - mPillRect = pillRect; - mOutlineRadius = mFinalRadius = radius; - } - - @Override - public boolean shouldRemoveElevationDuringAnimation() { - return false; - } - - @Override - public void setProgress(float progress) { - // Assumes width is greater than height. - int centerToEdge = Math.max(mCenterX, mPillRect.width() - mCenterX); - int currentSize = (int) (progress * centerToEdge); - - // Bound the outline to the final pill shape defined by mPillRect. - mOutline.left = Math.max(mPillRect.left, mCenterX - currentSize); - mOutline.top = Math.max(mPillRect.top, mCenterY - currentSize); - mOutline.right = Math.min(mPillRect.right, mCenterX + currentSize); - mOutline.bottom = Math.min(mPillRect.bottom, mCenterY + currentSize); - mOutlineRadius = Math.min(mFinalRadius, mOutline.height() / 2); - } -} diff --git a/src/com/android/launcher3/util/Preconditions.java b/src/com/android/launcher3/util/Preconditions.java index 89353e110..7ab0d3103 100644 --- a/src/com/android/launcher3/util/Preconditions.java +++ b/src/com/android/launcher3/util/Preconditions.java @@ -19,7 +19,7 @@ package com.android.launcher3.util; import android.os.Looper; import com.android.launcher3.LauncherModel; -import com.android.launcher3.config.ProviderConfig; +import com.android.launcher3.config.FeatureFlags; /** * A set of utility methods for thread verification. @@ -27,25 +27,25 @@ import com.android.launcher3.config.ProviderConfig; public class Preconditions { public static void assertNotNull(Object o) { - if (ProviderConfig.IS_DOGFOOD_BUILD && o == null) { + if (FeatureFlags.IS_DOGFOOD_BUILD && o == null) { throw new IllegalStateException(); } } public static void assertWorkerThread() { - if (ProviderConfig.IS_DOGFOOD_BUILD && !isSameLooper(LauncherModel.getWorkerLooper())) { + if (FeatureFlags.IS_DOGFOOD_BUILD && !isSameLooper(LauncherModel.getWorkerLooper())) { throw new IllegalStateException(); } } public static void assertUIThread() { - if (ProviderConfig.IS_DOGFOOD_BUILD && !isSameLooper(Looper.getMainLooper())) { + if (FeatureFlags.IS_DOGFOOD_BUILD && !isSameLooper(Looper.getMainLooper())) { throw new IllegalStateException(); } } public static void assertNonUiThread() { - if (ProviderConfig.IS_DOGFOOD_BUILD && isSameLooper(Looper.getMainLooper())) { + if (FeatureFlags.IS_DOGFOOD_BUILD && isSameLooper(Looper.getMainLooper())) { throw new IllegalStateException(); } } diff --git a/src/com/android/launcher3/util/RevealOutlineAnimation.java b/src/com/android/launcher3/util/RevealOutlineAnimation.java deleted file mode 100644 index 456047775..000000000 --- a/src/com/android/launcher3/util/RevealOutlineAnimation.java +++ /dev/null @@ -1,86 +0,0 @@ -package com.android.launcher3.util; - -import android.animation.Animator; -import android.animation.AnimatorListenerAdapter; -import android.animation.ValueAnimator; -import android.graphics.Outline; -import android.graphics.Rect; -import android.view.View; -import android.view.ViewOutlineProvider; - -import com.android.launcher3.Utilities; - -/** - * A {@link ViewOutlineProvider} that has helper functions to create reveal animations. - * This class should be extended so that subclasses can define the reveal shape as the - * animation progresses from 0 to 1. - */ -public abstract class RevealOutlineAnimation extends ViewOutlineProvider { - protected Rect mOutline; - protected float mOutlineRadius; - - public RevealOutlineAnimation() { - mOutline = new Rect(); - } - - /** Returns whether elevation should be removed for the duration of the reveal animation. */ - abstract boolean shouldRemoveElevationDuringAnimation(); - /** Sets the progress, from 0 to 1, of the reveal animation. */ - abstract void setProgress(float progress); - - public ValueAnimator createRevealAnimator(final View revealView) { - return createRevealAnimator(revealView, false); - } - - public ValueAnimator createRevealAnimator(final View revealView, boolean isReversed) { - ValueAnimator va = - isReversed ? ValueAnimator.ofFloat(1f, 0f) : ValueAnimator.ofFloat(0f, 1f); - final float elevation = revealView.getElevation(); - - va.addListener(new AnimatorListenerAdapter() { - private boolean mWasCanceled = false; - - public void onAnimationStart(Animator animation) { - revealView.setOutlineProvider(RevealOutlineAnimation.this); - revealView.setClipToOutline(true); - if (shouldRemoveElevationDuringAnimation()) { - revealView.setTranslationZ(-elevation); - } - } - - @Override - public void onAnimationCancel(Animator animation) { - mWasCanceled = true; - } - - public void onAnimationEnd(Animator animation) { - if (!mWasCanceled) { - revealView.setOutlineProvider(ViewOutlineProvider.BACKGROUND); - revealView.setClipToOutline(false); - if (shouldRemoveElevationDuringAnimation()) { - revealView.setTranslationZ(0); - } - } - } - - }); - - va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { - @Override - public void onAnimationUpdate(ValueAnimator arg0) { - float progress = (Float) arg0.getAnimatedValue(); - setProgress(progress); - revealView.invalidateOutline(); - if (!Utilities.ATLEAST_LOLLIPOP_MR1) { - revealView.invalidate(); - } - } - }); - return va; - } - - @Override - public void getOutline(View v, Outline outline) { - outline.setRoundRect(mOutline, mOutlineRadius); - } -} diff --git a/src/com/android/launcher3/util/SQLiteCacheHelper.java b/src/com/android/launcher3/util/SQLiteCacheHelper.java index 1ff6293a0..5344416ea 100644 --- a/src/com/android/launcher3/util/SQLiteCacheHelper.java +++ b/src/com/android/launcher3/util/SQLiteCacheHelper.java @@ -10,7 +10,7 @@ import android.database.sqlite.SQLiteOpenHelper; import android.util.Log; import com.android.launcher3.Utilities; -import com.android.launcher3.config.ProviderConfig; +import com.android.launcher3.config.FeatureFlags; /** * An extension of {@link SQLiteOpenHelper} with utility methods for a single table cache DB. @@ -19,7 +19,7 @@ import com.android.launcher3.config.ProviderConfig; public abstract class SQLiteCacheHelper { private static final String TAG = "SQLiteCacheHelper"; - private static final boolean NO_ICON_CACHE = ProviderConfig.IS_DOGFOOD_BUILD && + private static final boolean NO_ICON_CACHE = FeatureFlags.IS_DOGFOOD_BUILD && Utilities.isPropertyEnabled(LogConfig.MEMORY_ONLY_ICON_CACHE); private final String mTableName; diff --git a/src/com/android/launcher3/util/TestingUtils.java b/src/com/android/launcher3/util/TestingUtils.java index 665c37175..a7cc42b5f 100644 --- a/src/com/android/launcher3/util/TestingUtils.java +++ b/src/com/android/launcher3/util/TestingUtils.java @@ -3,7 +3,6 @@ package com.android.launcher3.util; import android.content.ComponentName; import android.content.Context; import android.content.Intent; -import android.content.SharedPreferences; import android.util.Log; import android.view.Gravity; import android.view.View; @@ -11,7 +10,6 @@ import android.widget.FrameLayout; import com.android.launcher3.CustomAppWidget; import com.android.launcher3.Launcher; -import com.android.launcher3.LauncherAppState; import com.android.launcher3.R; import com.android.launcher3.Utilities; diff --git a/src/com/android/launcher3/util/ViewOnDrawExecutor.java b/src/com/android/launcher3/util/ViewOnDrawExecutor.java index 9bd288244..4cb6ca831 100644 --- a/src/com/android/launcher3/util/ViewOnDrawExecutor.java +++ b/src/com/android/launcher3/util/ViewOnDrawExecutor.java @@ -16,12 +16,10 @@ package com.android.launcher3.util; -import android.util.Log; import android.view.View; import android.view.View.OnAttachStateChangeListener; import android.view.ViewTreeObserver.OnDrawListener; -import com.android.launcher3.DeferredHandler; import com.android.launcher3.Launcher; import java.util.ArrayList; @@ -34,7 +32,7 @@ public class ViewOnDrawExecutor implements Executor, OnDrawListener, Runnable, OnAttachStateChangeListener { private final ArrayList<Runnable> mTasks = new ArrayList<>(); - private final DeferredHandler mHandler; + private final Executor mExecutor; private Launcher mLauncher; private View mAttachedView; @@ -43,8 +41,8 @@ public class ViewOnDrawExecutor implements Executor, OnDrawListener, Runnable, private boolean mLoadAnimationCompleted; private boolean mFirstDrawCompleted; - public ViewOnDrawExecutor(DeferredHandler handler) { - mHandler = handler; + public ViewOnDrawExecutor(Executor executor) { + mExecutor = executor; } public void attachTo(Launcher launcher) { @@ -92,7 +90,7 @@ public class ViewOnDrawExecutor implements Executor, OnDrawListener, Runnable, // Post the pending tasks after both onDraw and onLoadAnimationCompleted have been called. if (mLoadAnimationCompleted && mFirstDrawCompleted && !mCompleted) { for (final Runnable r : mTasks) { - mHandler.post(r); + mExecutor.execute(r); } markCompleted(); } |