1 /* 2 * Copyright (C) 2017 Google Inc. All Rights Reserved. 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.wearaccessibilityapp; 17 18 import android.support.v7.widget.RecyclerView; 19 import android.support.wear.widget.WearableLinearLayoutManager; 20 import android.view.View; 21 22 public class ScalingScrollLayoutCallback extends WearableLinearLayoutManager.LayoutCallback { 23 24 /** How much should we scale the icon at most. */ 25 private static final float MAX_ICON_PROGRESS = 0.65f; 26 27 @Override 28 public void onLayoutFinished(View child, RecyclerView parent) { 29 30 // Figure out % progress from top to bottom. 31 float centerOffset = (child.getHeight() / 2.0f) / parent.getHeight(); 32 float yRelativeToCenterOffset = (child.getY() / parent.getHeight()) + centerOffset; 33 34 // Normalize for center. 35 float progressToCenter = Math.abs(0.5f - yRelativeToCenterOffset); 36 37 // Adjust to the maximum scale. 38 progressToCenter = Math.min(progressToCenter, MAX_ICON_PROGRESS); 39 40 child.setScaleX(1 - progressToCenter); 41 child.setScaleY(1 - progressToCenter); 42 } 43 } 44