2018-05-10 16:31:00 -07:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2018 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* 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.android.launcher3.util;
|
|
|
|
|
|
2022-09-13 14:40:48 -07:00
|
|
|
import static com.android.launcher3.LauncherAnimUtils.VIEW_ALPHA;
|
|
|
|
|
|
2018-05-10 16:31:00 -07:00
|
|
|
import android.view.View;
|
|
|
|
|
|
2020-07-17 13:06:57 -07:00
|
|
|
import com.android.launcher3.anim.AlphaUpdateListener;
|
|
|
|
|
|
2018-05-10 16:31:00 -07:00
|
|
|
/**
|
|
|
|
|
* Utility class to handle separating a single value as a factor of multiple values
|
|
|
|
|
*/
|
2022-09-13 14:40:48 -07:00
|
|
|
public class MultiValueAlpha extends MultiPropertyFactory<View> {
|
2018-05-10 16:31:00 -07:00
|
|
|
|
2022-09-13 14:40:48 -07:00
|
|
|
private static final FloatBiFunction ALPHA_AGGREGATOR = (a, b) -> a * b;
|
2018-05-10 16:31:00 -07:00
|
|
|
|
2020-07-17 13:06:57 -07:00
|
|
|
// Whether we should change from INVISIBLE to VISIBLE and vice versa at low alpha values.
|
|
|
|
|
private boolean mUpdateVisibility;
|
2018-05-10 16:31:00 -07:00
|
|
|
|
2023-08-04 17:16:11 +00:00
|
|
|
private final int mHiddenVisibility;
|
|
|
|
|
|
2018-05-10 16:31:00 -07:00
|
|
|
public MultiValueAlpha(View view, int size) {
|
2023-08-04 17:16:11 +00:00
|
|
|
this(view, size, View.INVISIBLE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public MultiValueAlpha(View view, int size, int hiddenVisibility) {
|
2022-09-13 14:40:48 -07:00
|
|
|
super(view, VIEW_ALPHA, size, ALPHA_AGGREGATOR, 1f);
|
2023-08-04 17:16:11 +00:00
|
|
|
this.mHiddenVisibility = hiddenVisibility;
|
2018-05-10 16:31:00 -07:00
|
|
|
}
|
|
|
|
|
|
2020-07-17 13:06:57 -07:00
|
|
|
/** Sets whether we should update between INVISIBLE and VISIBLE based on alpha. */
|
|
|
|
|
public void setUpdateVisibility(boolean updateVisibility) {
|
|
|
|
|
mUpdateVisibility = updateVisibility;
|
|
|
|
|
}
|
|
|
|
|
|
2022-09-13 14:40:48 -07:00
|
|
|
@Override
|
|
|
|
|
protected void apply(float value) {
|
|
|
|
|
super.apply(value);
|
|
|
|
|
if (mUpdateVisibility) {
|
2023-08-04 17:16:11 +00:00
|
|
|
AlphaUpdateListener.updateVisibility(mTarget, mHiddenVisibility);
|
2021-06-01 16:54:07 -07:00
|
|
|
}
|
2018-05-10 16:31:00 -07:00
|
|
|
}
|
|
|
|
|
}
|