1 /*
2  * Copyright (C) 2016 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  */
16 
17 package androidx.leanback.widget;
18 
19 import androidx.leanback.R;
20 import androidx.leanback.app.DetailsFragment;
21 import androidx.leanback.app.DetailsSupportFragment;
22 
23 /**
24  * Subclass of Parallax object that tracks overview row's top and bottom edge in DetailsFragment
25  * or DetailsSupportFragment.
26  * <p>
27  * It can be used for both creating cover image parallax effect and controlling video playing
28  * when transitioning to/from half/full screen.  A direct use case is
29  * {@link androidx.leanback.app.DetailsFragmentBackgroundController}.
30  * </p>
31  * @see DetailsFragment#getParallax()
32  * @see androidx.leanback.app.DetailsFragmentBackgroundController
33  * @see DetailsSupportFragment#getParallax()
34  * @see androidx.leanback.app.DetailsSupportFragmentBackgroundController
35  */
36 public class DetailsParallax extends RecyclerViewParallax {
37     final IntProperty mFrameTop;
38     final IntProperty mFrameBottom;
39 
DetailsParallax()40     public DetailsParallax() {
41         // track the top edge of details_frame of first item of adapter
42         mFrameTop = addProperty("overviewRowTop")
43                 .adapterPosition(0)
44                 .viewId(R.id.details_frame);
45 
46         // track the bottom edge of details_frame of first item of adapter
47         mFrameBottom = addProperty("overviewRowBottom")
48                 .adapterPosition(0)
49                 .viewId(R.id.details_frame)
50                 .fraction(1.0f);
51 
52     }
53 
54     /**
55      * Returns the top of the details overview row. This is tracked for implementing the
56      * parallax effect.
57      */
getOverviewRowTop()58     public Parallax.IntProperty getOverviewRowTop() {
59         return mFrameTop;
60     }
61 
62     /**
63      * Returns the bottom of the details overview row. This is tracked for implementing the
64      * parallax effect.
65      */
getOverviewRowBottom()66     public Parallax.IntProperty getOverviewRowBottom() {
67         return mFrameBottom;
68     }
69 }
70