10228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek/* 20228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek * Copyright (C) 2017 The Android Open Source Project 30228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek * 40228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek * Licensed under the Apache License, Version 2.0 (the "License"); 50228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek * you may not use this file except in compliance with the License. 60228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek * You may obtain a copy of the License at 70228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek * 80228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek * http://www.apache.org/licenses/LICENSE-2.0 90228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek * 100228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek * Unless required by applicable law or agreed to in writing, software 110228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek * distributed under the License is distributed on an "AS IS" BASIS, 120228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek * See the License for the specific language governing permissions and 140228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek * limitations under the License 150228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek */ 160228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek 170228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinekpackage com.android.systemui.statusbar.notification; 180228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek 190228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinekimport android.util.FloatProperty; 200228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinekimport android.util.Property; 210228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinekimport android.view.View; 220228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek 2360661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupinimport com.android.systemui.R; 240228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek 250228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinekimport java.util.function.BiConsumer; 260228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinekimport java.util.function.Function; 270228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek 280228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek/** 290228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek * An animatable property of a view. Used with {@link PropertyAnimator} 300228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek */ 3160661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupinpublic abstract class AnimatableProperty { 320228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek 3360661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin public static final AnimatableProperty X = AnimatableProperty.from(View.X, 3460661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin R.id.x_animator_tag, R.id.x_animator_tag_start_value, R.id.x_animator_tag_end_value); 3560661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin public static final AnimatableProperty Y = AnimatableProperty.from(View.Y, 3660661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin R.id.y_animator_tag, R.id.y_animator_tag_start_value, R.id.y_animator_tag_end_value); 370228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek 3860661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin public abstract int getAnimationStartTag(); 390228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek 4060661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin public abstract int getAnimationEndTag(); 410228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek 4260661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin public abstract int getAnimatorTag(); 4360661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin 4460661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin public abstract Property getProperty(); 4560661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin 4660661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin public static <T extends View> AnimatableProperty from(String name, BiConsumer<T, Float> setter, 470228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek Function<T, Float> getter, int animatorTag, int startValueTag, int endValueTag) { 480228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek Property<T, Float> property = new FloatProperty<T>(name) { 490228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek 500228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek @Override 510228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek public Float get(T object) { 520228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek return getter.apply(object); 530228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek } 540228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek 550228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek @Override 560228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek public void setValue(T object, float value) { 570228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek setter.accept(object, value); 580228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek } 590228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek }; 600228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek return new AnimatableProperty() { 610228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek @Override 620228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek public int getAnimationStartTag() { 630228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek return startValueTag; 640228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek } 650228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek 660228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek @Override 670228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek public int getAnimationEndTag() { 680228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek return endValueTag; 690228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek } 700228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek 710228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek @Override 720228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek public int getAnimatorTag() { 730228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek return animatorTag; 740228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek } 750228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek 760228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek @Override 770228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek public Property getProperty() { 780228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek return property; 790228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek } 800228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek }; 810228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek } 8260661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin 8360661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin public static <T extends View> AnimatableProperty from(Property<T, Float> property, 8460661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin int animatorTag, int startValueTag, int endValueTag) { 8560661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin return new AnimatableProperty() { 8660661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin @Override 8760661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin public int getAnimationStartTag() { 8860661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin return startValueTag; 8960661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin } 9060661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin 9160661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin @Override 9260661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin public int getAnimationEndTag() { 9360661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin return endValueTag; 9460661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin } 9560661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin 9660661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin @Override 9760661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin public int getAnimatorTag() { 9860661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin return animatorTag; 9960661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin } 10060661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin 10160661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin @Override 10260661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin public Property getProperty() { 10360661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin return property; 10460661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin } 10560661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin }; 10660661a6dd8ad7728b87a36da005acaec0272dd5aLucas Dupin } 1070228a255d6713a255dc3d68c0858be7d75fb0f97Selim Cinek} 108