| /* |
| * Copyright (C) 2017 Google Inc. All Rights Reserved. |
| * |
| * Licensed under the Apache License, Version 2.0 (the "License"); |
| * you may not use this file except in compliance with the License. |
| * You may obtain a copy of the License at |
| * |
| * http://www.apache.org/licenses/LICENSE-2.0 |
| * |
| * Unless required by applicable law or agreed to in writing, software |
| * distributed under the License is distributed on an "AS IS" BASIS, |
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| * See the License for the specific language governing permissions and |
| * limitations under the License. |
| */ |
| package com.example.android.wearable.wear.wearaccessibilityapp; |
| |
| import android.view.View; |
| |
| import androidx.recyclerview.widget.RecyclerView; |
| import androidx.wear.widget.WearableLinearLayoutManager; |
| |
| public class ScalingScrollLayoutCallback extends WearableLinearLayoutManager.LayoutCallback { |
| |
| /** How much should we scale the icon at most. */ |
| private static final float MAX_ICON_PROGRESS = 0.65f; |
| |
| @Override |
| public void onLayoutFinished(View child, RecyclerView parent) { |
| |
| // Figure out % progress from top to bottom. |
| float centerOffset = (child.getHeight() / 2.0f) / parent.getHeight(); |
| float yRelativeToCenterOffset = (child.getY() / parent.getHeight()) + centerOffset; |
| |
| // Normalize for center. |
| float progressToCenter = Math.abs(0.5f - yRelativeToCenterOffset); |
| |
| // Adjust to the maximum scale. |
| progressToCenter = Math.min(progressToCenter, MAX_ICON_PROGRESS); |
| |
| child.setScaleX(1 - progressToCenter); |
| child.setScaleY(1 - progressToCenter); |
| } |
| } |