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
17package android.support.v17.leanback.widget;
18
19import android.support.v17.leanback.R;
20import android.support.v17.leanback.app.DetailsFragment;
21import android.support.v17.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 android.support.v17.leanback.app.DetailsFragmentBackgroundController}.
30 * </p>
31 * @see DetailsFragment#getParallax()
32 * @see android.support.v17.leanback.app.DetailsFragmentBackgroundController
33 * @see DetailsSupportFragment#getParallax()
34 * @see android.support.v17.leanback.app.DetailsSupportFragmentBackgroundController
35 */
36public class DetailsParallax extends RecyclerViewParallax {
37    final IntProperty mFrameTop;
38    final IntProperty mFrameBottom;
39
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     */
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     */
66    public Parallax.IntProperty getOverviewRowBottom() {
67        return mFrameBottom;
68    }
69}
70