mirror of
https://github.com/seven332/EhViewer
synced 2026-11-27 17:48:06 +08:00
Add RecolorStatusBar ChangeHandler
This commit is contained in:
1 parent
cddc78516c
commit
7809d11f4c
3 files changed
+278
No files matched your search
@@ -0,0 +1,99 @@
|
||||
/*
|
||||
* Copyright 2017 Hippo Seven
|
||||
*
|
||||
* 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.hippo.ehviewer.changehandler.base;
|
||||
|
||||
/*
|
||||
* Created by Hippo on 2/7/2017.
|
||||
*/
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.ArgbEvaluator;
|
||||
import android.animation.ObjectAnimator;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Property;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import com.hippo.drawerlayout.DrawerLayout;
|
||||
import com.hippo.ehviewer.R;
|
||||
import com.hippo.ehviewer.activity.EhvActivity;
|
||||
import com.hippo.ehviewer.controller.base.MvpController;
|
||||
import com.hippo.ehviewer.util.IntProperty;
|
||||
import com.hippo.ehviewer.widget.ControllerContainer;
|
||||
|
||||
/**
|
||||
* Creates recolor status bar animator for ControllerChangeHandler.
|
||||
* <p>
|
||||
* Only works for {@link MvpController}
|
||||
* in {@link EhvActivity}.
|
||||
*/
|
||||
public final class RecolorStatusBar {
|
||||
private RecolorStatusBar() {}
|
||||
|
||||
private static final boolean SUPPORT_COLOR_BAR = Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT;
|
||||
|
||||
private static final Property<DrawerLayout, Integer> STATUS_BAR_COLOR =
|
||||
new IntProperty<DrawerLayout>(null) {
|
||||
@Override
|
||||
public void setValue(DrawerLayout object, int value) {
|
||||
object.setStatusBarColor(value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Integer get(DrawerLayout object) {
|
||||
return object.getStatusBarColor();
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates recolor status bar animator for ControllerChangeHandler.
|
||||
* <p>
|
||||
* Return {@code null} if not supported.
|
||||
* <p>
|
||||
* Only works for {@link MvpController}
|
||||
* in {@link EhvActivity}.
|
||||
*/
|
||||
@Nullable
|
||||
public static Animator createRecolorStatusBarAnimator(
|
||||
@NonNull ViewGroup container, @Nullable View from, @Nullable View to) {
|
||||
if (!SUPPORT_COLOR_BAR
|
||||
|| !(container instanceof ControllerContainer)
|
||||
|| from == null || to == null) {
|
||||
return null;
|
||||
}
|
||||
ControllerContainer controllerContainer = (ControllerContainer) container;
|
||||
DrawerLayout drawerLayout = controllerContainer.getDrawLayout();
|
||||
if (drawerLayout == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Object startObj = from.getTag(R.id.controller_status_bar_color);
|
||||
Object endObj = to.getTag(R.id.controller_status_bar_color);
|
||||
if (!(startObj instanceof Integer) || !(endObj instanceof Integer)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
ObjectAnimator statusBarAnimator = ObjectAnimator.ofInt(
|
||||
drawerLayout, STATUS_BAR_COLOR,
|
||||
(Integer) startObj, (Integer) endObj
|
||||
);
|
||||
statusBarAnimator.setEvaluator(new ArgbEvaluator());
|
||||
|
||||
return statusBarAnimator;
|
||||
}
|
||||
}
|
||||
+95
@@ -0,0 +1,95 @@
|
||||
/*
|
||||
* Copyright 2017 Hippo Seven
|
||||
*
|
||||
* 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.hippo.ehviewer.changehandler.base;
|
||||
|
||||
/*
|
||||
* Created by Hippo on 2/7/2017.
|
||||
*/
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorSet;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import com.hippo.ehviewer.activity.EhvActivity;
|
||||
import com.hippo.ehviewer.controller.base.MvpController;
|
||||
|
||||
/**
|
||||
* {@code RecolorStatusBarAnimatorChangeHandler} handles status bar color animator.
|
||||
* <p>
|
||||
* Only works for {@link MvpController}
|
||||
* in {@link EhvActivity}.
|
||||
*/
|
||||
public abstract class RecolorStatusBarAnimatorChangeHandler extends AnimatorChangeHandler {
|
||||
|
||||
private static final String KEY_DURATION = "RecolorStatusBarAnimatorChangeHandler.recolorStatusBarAnimationDuration";
|
||||
|
||||
private long recolorStatusBarAnimationDuration = DEFAULT_ANIMATION_DURATION;
|
||||
|
||||
@Override
|
||||
public void saveToBundle(@NonNull Bundle bundle) {
|
||||
super.saveToBundle(bundle);
|
||||
bundle.putLong(KEY_DURATION, recolorStatusBarAnimationDuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void restoreFromBundle(@NonNull Bundle bundle) {
|
||||
super.restoreFromBundle(bundle);
|
||||
recolorStatusBarAnimationDuration = bundle.getLong(KEY_DURATION);
|
||||
}
|
||||
|
||||
public long getRecolorStatusBarAnimationDuration() {
|
||||
return recolorStatusBarAnimationDuration;
|
||||
}
|
||||
|
||||
public void setRecolorStatusBarAnimationDuration(long duration) {
|
||||
recolorStatusBarAnimationDuration = duration;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected final Animator getAnimator2(@NonNull ViewGroup container, @Nullable View from,
|
||||
@Nullable View to, boolean isPush, boolean toAddedToContainer) {
|
||||
Animator animator = getAnimator3(container, from, to, isPush, toAddedToContainer);
|
||||
Animator recolorBar = RecolorStatusBar.createRecolorStatusBarAnimator(container, from, to);
|
||||
|
||||
if (recolorBar == null) {
|
||||
return animator;
|
||||
}
|
||||
|
||||
if (recolorStatusBarAnimationDuration >= 0) {
|
||||
recolorBar.setDuration(recolorStatusBarAnimationDuration);
|
||||
}
|
||||
|
||||
if (animator == null) {
|
||||
return recolorBar;
|
||||
}
|
||||
|
||||
AnimatorSet animatorSet = new AnimatorSet();
|
||||
animatorSet.playTogether(animator, recolorBar);
|
||||
return animatorSet;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected abstract Animator getAnimator3(@NonNull ViewGroup container, @Nullable View from,
|
||||
@Nullable View to, boolean isPush, boolean toAddedToContainer);
|
||||
|
||||
@Override
|
||||
protected void resetFromView(@NonNull View from) {}
|
||||
}
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
/*
|
||||
* Copyright 2017 Hippo Seven
|
||||
*
|
||||
* 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.hippo.ehviewer.changehandler.base;
|
||||
|
||||
/*
|
||||
* Created by Hippo on 2/6/2017.
|
||||
*/
|
||||
|
||||
import android.animation.Animator;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import com.hippo.ehviewer.activity.EhvActivity;
|
||||
import com.hippo.ehviewer.controller.base.MvpController;
|
||||
import com.hippo.ehviewer.transition.RunAnimator;
|
||||
import com.transitionseverywhere.Transition;
|
||||
import com.transitionseverywhere.TransitionSet;
|
||||
|
||||
/**
|
||||
* {@code RecolorStatusBarTransitionChangeHandler} handles status bar color transition.
|
||||
* <p>
|
||||
* Only works for {@link MvpController}
|
||||
* in {@link EhvActivity}.
|
||||
*/
|
||||
public abstract class RecolorStatusBarTransitionChangeHandler extends TransitionChangeHandler {
|
||||
|
||||
@Nullable
|
||||
private Transition getRecolorBarTransition(@NonNull ViewGroup container,
|
||||
@Nullable View from, @Nullable View to) {
|
||||
Animator animator = RecolorStatusBar.createRecolorStatusBarAnimator(container, from, to);
|
||||
if (animator != null) {
|
||||
return new RunAnimator(animator);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
protected final Transition getTransition(
|
||||
@NonNull ViewGroup container, @Nullable View from,
|
||||
@Nullable View to, boolean isPush) {
|
||||
Transition transition = getTransition2(container, from, to, isPush);
|
||||
Transition recolorBar = getRecolorBarTransition(container, from, to);
|
||||
|
||||
if (recolorBar == null) {
|
||||
return transition;
|
||||
}
|
||||
|
||||
// Treat transition as TransitionSet if it is
|
||||
if (transition instanceof TransitionSet) {
|
||||
TransitionSet set = (TransitionSet) transition;
|
||||
if (set.getOrdering() == TransitionSet.ORDERING_TOGETHER) {
|
||||
set.addTransition(recolorBar);
|
||||
return transition;
|
||||
}
|
||||
}
|
||||
|
||||
return new TransitionSet()
|
||||
.setOrdering(TransitionSet.ORDERING_TOGETHER)
|
||||
.addTransition(transition)
|
||||
.addTransition(recolorBar);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
protected abstract Transition getTransition2(
|
||||
@NonNull ViewGroup container, @Nullable View from,
|
||||
@Nullable View to, boolean isPush);
|
||||
}
|
||||
Reference in new issue
Block a user