Home | History | Annotate | Download | only in settings
      1 /*
      2  * Copyright (C) 2015 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 
     17 package com.android.packageinstaller.permission.ui.wear.settings;
     18 
     19 import android.animation.ObjectAnimator;
     20 import android.support.wearable.view.WearableListView;
     21 import android.view.View;
     22 
     23 
     24 public class ExtendedViewHolder extends WearableListView.ViewHolder {
     25     public static final long DEFAULT_ANIMATION_DURATION = 150;
     26 
     27     private ObjectAnimator mScalingUpAnimator;
     28 
     29     private ObjectAnimator mScalingDownAnimator;
     30 
     31     private float mMinValue;
     32 
     33     private float mMaxValue;
     34 
     35     public ExtendedViewHolder(View itemView) {
     36         super(itemView);
     37         if (itemView instanceof ExtendedOnCenterProximityListener) {
     38             ExtendedOnCenterProximityListener item =
     39                     (ExtendedOnCenterProximityListener) itemView;
     40             mMinValue = item.getProximityMinValue();
     41             item.setScalingAnimatorValue(mMinValue);
     42             mMaxValue = item.getProximityMaxValue();
     43             mScalingUpAnimator = ObjectAnimator.ofFloat(item, "scalingAnimatorValue", mMinValue,
     44                     mMaxValue);
     45             mScalingUpAnimator.setDuration(DEFAULT_ANIMATION_DURATION);
     46             mScalingDownAnimator = ObjectAnimator.ofFloat(item, "scalingAnimatorValue",
     47                     mMaxValue, mMinValue);
     48             mScalingDownAnimator.setDuration(DEFAULT_ANIMATION_DURATION);
     49         }
     50     }
     51 
     52     public void onCenterProximity(boolean isCentralItem, boolean animate) {
     53         if (!(itemView instanceof ExtendedOnCenterProximityListener)) {
     54             return;
     55         }
     56         ExtendedOnCenterProximityListener item = (ExtendedOnCenterProximityListener) itemView;
     57         if (isCentralItem) {
     58             if (animate) {
     59                 mScalingDownAnimator.cancel();
     60                 if (!mScalingUpAnimator.isRunning()) {
     61                     mScalingUpAnimator.setFloatValues(item.getCurrentProximityValue(),
     62                             mMaxValue);
     63                     mScalingUpAnimator.start();
     64                 }
     65             } else {
     66                 mScalingUpAnimator.cancel();
     67                 item.setScalingAnimatorValue(item.getProximityMaxValue());
     68             }
     69         } else {
     70             mScalingUpAnimator.cancel();
     71             if (animate) {
     72                 if (!mScalingDownAnimator.isRunning()) {
     73                     mScalingDownAnimator.setFloatValues(item.getCurrentProximityValue(),
     74                             mMinValue);
     75                     mScalingDownAnimator.start();
     76                 }
     77             } else {
     78                 mScalingDownAnimator.cancel();
     79                 item.setScalingAnimatorValue(item.getProximityMinValue());
     80             }
     81         }
     82         super.onCenterProximity(isCentralItem, animate);
     83     }
     84 }
     85