Skip to content

Most visited

Recently visited

navigation
WearNotifications / Wearable / src / com.example.android.wearable.wear.wearnotifications /

ScalingOffsettingHelper.java

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
package com.example.android.wearable.wear.wearnotifications;
17
 
18
import android.support.wearable.view.DefaultOffsettingHelper;
19
import android.support.wearable.view.WearableRecyclerView;
20
import android.view.View;
21
 
22
/**
23
 * Customizes all items (children) in a {@link WearableRecyclerView} to align to left side of
24
 * surface/watch and shrinks each item (child) as you scroll away from it.
25
 */
26
public class ScalingOffsettingHelper extends DefaultOffsettingHelper {
27
 
28
    // Max we scale the child View
29
    private static final float MAX_CHILD_SCALE = 0.65f;
30
 
31
    private float mProgressToCenter;
32
 
33
    public ScalingOffsettingHelper() {}
34
 
35
    // Shrinks icons/text and you scroll away
36
    @Override
37
    public void updateChild(View child, WearableRecyclerView parent) {
38
        super.updateChild(child, parent);
39
 
40
        // Figure out % progress from top to bottom
41
        float centerOffset = ((float) child.getHeight() / 2.0f) /  (float) parent.getHeight();
42
        float yRelativeToCenterOffset = (child.getY() / parent.getHeight()) + centerOffset;
43
 
44
        // Normalize for center
45
        mProgressToCenter = Math.abs(0.5f - yRelativeToCenterOffset);
46
 
47
        // Adjust to the maximum scale
48
        mProgressToCenter = Math.min(mProgressToCenter, MAX_CHILD_SCALE);
49
 
50
        child.setScaleX(1 - mProgressToCenter);
51
        child.setScaleY(1 - mProgressToCenter);
52
    }
53
}
This site uses cookies to store your preferences for site-specific language and display options.

Get the latest Android developer news and tips that will help you find success on Google Play.

* Required Fields

Hooray!

Browse this site in ?

You requested a page in , but your language preference for this site is .

Would you like to change your language preference and browse this site in ? If you want to change your language preference later, use the language menu at the bottom of each page.

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.

Take a short survey?
Help us improve the Android developer experience.
(Sep 2017 survey)