diff options
author | Adam Cohen <adamcohen@google.com> | 2016-01-15 16:47:43 -0800 |
---|---|---|
committer | Adam Cohen <adamcohen@google.com> | 2016-02-12 17:28:31 -0800 |
commit | f9c184a619e4e4b82cf9e0bf318ca6d8deaaaee7 (patch) | |
tree | 086983d60ee5f540e1ce391976c95427d065ea04 /src/com/android/launcher3/folder/StackFolderIconLayoutRule.java | |
parent | c338ea74c2c909927246fc604b049d5dcc773f81 (diff) | |
download | android_packages_apps_Trebuchet-f9c184a619e4e4b82cf9e0bf318ca6d8deaaaee7.tar.gz android_packages_apps_Trebuchet-f9c184a619e4e4b82cf9e0bf318ca6d8deaaaee7.tar.bz2 android_packages_apps_Trebuchet-f9c184a619e4e4b82cf9e0bf318ca6d8deaaaee7.zip |
Refactor FolderIcon to separate the preview effect into it's own class
-> Created com.android.launcher3.folder package to house most folder-related files
(aside from the FolderInfo) which is more related to the model than the UI.
Change-Id: I767063e1e4c775c01a799a3bede30cd94ac48ade
Diffstat (limited to 'src/com/android/launcher3/folder/StackFolderIconLayoutRule.java')
-rw-r--r-- | src/com/android/launcher3/folder/StackFolderIconLayoutRule.java | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/src/com/android/launcher3/folder/StackFolderIconLayoutRule.java b/src/com/android/launcher3/folder/StackFolderIconLayoutRule.java new file mode 100644 index 000000000..1405b40c5 --- /dev/null +++ b/src/com/android/launcher3/folder/StackFolderIconLayoutRule.java @@ -0,0 +1,86 @@ +/** + * Copyright (C) 2015 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.folder; + +import com.android.launcher3.folder.FolderIcon.PreviewItemDrawingParams; + +public class StackFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule { + + public static final int NUM_ITEMS_IN_PREVIEW = 3; + + // The degree to which the item in the back of the stack is scaled [0...1] + // (0 means it's not scaled at all, 1 means it's scaled to nothing) + private static final float PERSPECTIVE_SCALE_FACTOR = 0.35f; + + // The amount of vertical spread between items in the stack [0...1] + private static final float PERSPECTIVE_SHIFT_FACTOR = 0.18f; + + //private int mIntrinsicIconSize; + private float mBaselineIconScale; + private int mBaselineIconSize; + private int mAvailableSpaceInPreview; + private float mMaxPerspectiveShift; + + public void init(int availableSpace, int intrinsicIconSize) { + mAvailableSpaceInPreview = availableSpace; + + // cos(45) = 0.707 + ~= 0.1) = 0.8f + int adjustedAvailableSpace = (int) ((mAvailableSpaceInPreview / 2) * (1 + 0.8f)); + + int unscaledHeight = (int) (intrinsicIconSize * (1 + PERSPECTIVE_SHIFT_FACTOR)); + + mBaselineIconScale = (1.0f * adjustedAvailableSpace / unscaledHeight); + + mBaselineIconSize = (int) (intrinsicIconSize * mBaselineIconScale); + mMaxPerspectiveShift = mBaselineIconSize * PERSPECTIVE_SHIFT_FACTOR; + } + + @Override + public PreviewItemDrawingParams computePreviewItemDrawingParams(int index, + PreviewItemDrawingParams params) { + + index = NUM_ITEMS_IN_PREVIEW - index - 1; + float r = (index * 1.0f) / (NUM_ITEMS_IN_PREVIEW - 1); + float scale = (1 - PERSPECTIVE_SCALE_FACTOR * (1 - r)); + + float offset = (1 - r) * mMaxPerspectiveShift; + float scaledSize = scale * mBaselineIconSize; + float scaleOffsetCorrection = (1 - scale) * mBaselineIconSize; + + // We want to imagine our coordinates from the bottom left, growing up and to the + // right. This is natural for the x-axis, but for the y-axis, we have to invert things. + float transY = mAvailableSpaceInPreview - (offset + scaledSize + scaleOffsetCorrection); + float transX = (mAvailableSpaceInPreview - scaledSize) / 2; + float totalScale = mBaselineIconScale * scale; + final float overlayAlpha = (80 * (1 - r)) / 255f; + + if (params == null) { + params = new PreviewItemDrawingParams(transX, transY, totalScale, overlayAlpha); + } else { + params.transX = transX; + params.transY = transY; + params.scale = totalScale; + params.overlayAlpha = overlayAlpha; + } + return params; + } + + @Override + public int numItems() { + return NUM_ITEMS_IN_PREVIEW; + } +} |