KeyguardWidgetCarousel.java revision 9ec871def38079691085a16862c234b98de99362
1/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package com.android.internal.policy.impl.keyguard;
17
18import android.content.Context;
19import android.util.AttributeSet;
20
21import com.android.internal.R;
22
23public class KeyguardWidgetCarousel extends KeyguardWidgetPager {
24
25    private float mAdjacentPagesAngle;
26    private static float CAMERA_DISTANCE = 10000;
27
28    public KeyguardWidgetCarousel(Context context, AttributeSet attrs) {
29        this(context, attrs, 0);
30    }
31
32    public KeyguardWidgetCarousel(Context context) {
33        this(context, null, 0);
34    }
35
36    public KeyguardWidgetCarousel(Context context, AttributeSet attrs, int defStyle) {
37        super(context, attrs, defStyle);
38        mAdjacentPagesAngle = context.getResources().getInteger(R.integer.kg_carousel_angle);
39    }
40
41    protected float getMaxScrollProgress() {
42        return 1.5f;
43    }
44
45    private void updatePageAlphaValues(int screenCenter) {
46        boolean isInOverscroll = mOverScrollX < 0 || mOverScrollX > mMaxScrollX;
47        if (!isInOverscroll) {
48            for (int i = 0; i < getChildCount(); i++) {
49                KeyguardWidgetFrame child = getWidgetPageAt(i);
50                if (child != null) {
51                    float scrollProgress = getScrollProgress(screenCenter, child, i);
52                    if (!isReordering(false)) {
53                        child.setBackgroundAlphaMultiplier(
54                                backgroundAlphaInterpolator(Math.abs(scrollProgress)));
55                    } else {
56                        child.setBackgroundAlphaMultiplier(1f);
57                    }
58                }
59            }
60        }
61    }
62
63    @Override
64    protected void screenScrolled(int screenCenter) {
65        updatePageAlphaValues(screenCenter);
66        for (int i = 0; i < getChildCount(); i++) {
67            KeyguardWidgetFrame v = getWidgetPageAt(i);
68            if (v == mDragView) continue;
69            if (v != null) {
70                float scrollProgress = getScrollProgress(screenCenter, v, i);
71                int width = v.getMeasuredWidth();
72                float pivotX = (width / 2f) + scrollProgress * (width / 2f);
73                float pivotY = v.getMeasuredHeight() / 2;
74                float rotationY = - mAdjacentPagesAngle * scrollProgress;
75                v.setCameraDistance(CAMERA_DISTANCE);
76                v.setPivotX(pivotX);
77                v.setPivotY(pivotY);
78                v.setRotationY(rotationY);
79            }
80        }
81    }
82}
83