| /* |
| * 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.content.Context; |
| import android.support.wearable.view.CurvedChildLayoutManager; |
| import android.support.wearable.view.WearableRecyclerView; |
| import android.view.View; |
| |
| public class MyLauncherChildLayoutManager extends CurvedChildLayoutManager { |
| |
| /** How much should we scale the icon at most. */ |
| private static final float MAX_ICON_PROGRESS = 0.65f; |
| |
| public MyLauncherChildLayoutManager(Context context) { |
| super(context); |
| } |
| |
| @Override |
| public void updateChild(View child, WearableRecyclerView parent) { |
| super.updateChild(child, 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); |
| } |
| } |