1e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu/*
2e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu * Copyright (C) 2016 The Android Open Source Project
3e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu *
4e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu * Licensed under the Apache License, Version 2.0 (the "License");
5e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu * you may not use this file except in compliance with the License.
6e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu * You may obtain a copy of the License at
7e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu *
8e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu *      http://www.apache.org/licenses/LICENSE-2.0
9e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu *
10e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu * Unless required by applicable law or agreed to in writing, software
11e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu * distributed under the License is distributed on an "AS IS" BASIS,
12e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu * See the License for the specific language governing permissions and
14e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu * limitations under the License.
15e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu */
16e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu
17ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikaspackage androidx.leanback.widget;
18e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu
19ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.leanback.R;
20ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.leanback.app.DetailsFragment;
21ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport androidx.leanback.app.DetailsSupportFragment;
22e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu
23e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu/**
24e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu * Subclass of Parallax object that tracks overview row's top and bottom edge in DetailsFragment
25e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu * or DetailsSupportFragment.
26e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu * <p>
27e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu * It can be used for both creating cover image parallax effect and controlling video playing
28e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu * when transitioning to/from half/full screen.  A direct use case is
29ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas * {@link androidx.leanback.app.DetailsFragmentBackgroundController}.
30e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu * </p>
31e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu * @see DetailsFragment#getParallax()
32ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas * @see androidx.leanback.app.DetailsFragmentBackgroundController
33e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu * @see DetailsSupportFragment#getParallax()
34ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikas * @see androidx.leanback.app.DetailsSupportFragmentBackgroundController
35e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu */
36e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gupublic class DetailsParallax extends RecyclerViewParallax {
37bf4318c67254bc11307796601b9fb4a8bbfe67b2Dake Gu    final IntProperty mFrameTop;
38bf4318c67254bc11307796601b9fb4a8bbfe67b2Dake Gu    final IntProperty mFrameBottom;
39e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu
40e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu    public DetailsParallax() {
41e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu        // track the top edge of details_frame of first item of adapter
42bf4318c67254bc11307796601b9fb4a8bbfe67b2Dake Gu        mFrameTop = addProperty("overviewRowTop")
43e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu                .adapterPosition(0)
44e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu                .viewId(R.id.details_frame);
45e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu
46e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu        // track the bottom edge of details_frame of first item of adapter
47bf4318c67254bc11307796601b9fb4a8bbfe67b2Dake Gu        mFrameBottom = addProperty("overviewRowBottom")
48e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu                .adapterPosition(0)
49e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu                .viewId(R.id.details_frame)
50e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu                .fraction(1.0f);
51e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu
52e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu    }
53e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu
54e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu    /**
55e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu     * Returns the top of the details overview row. This is tracked for implementing the
56e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu     * parallax effect.
57e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu     */
58e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu    public Parallax.IntProperty getOverviewRowTop() {
59e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu        return mFrameTop;
60e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu    }
61e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu
62e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu    /**
63e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu     * Returns the bottom of the details overview row. This is tracked for implementing the
64e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu     * parallax effect.
65e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu     */
66e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu    public Parallax.IntProperty getOverviewRowBottom() {
67e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu        return mFrameBottom;
68e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu    }
69e1cde4d4ac42a6e9e16aad2b4df970c7c7d0771cDake Gu}
70