If you think the Android project muzei listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
/*
* Copyright 2014 Google Inc./*www.java2s.com*/
*
* 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.google.android.apps.muzei.render;
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.os.Handler;
import com.google.android.apps.muzei.util.LogUtil;
import java.io.IOException;
importstatic com.google.android.apps.muzei.util.LogUtil.LOGE;
publicclass DemoRenderController extends RenderController {
privatestaticfinal String TAG = LogUtil.makeLogTag(DemoRenderController.class);
privatefinal Handler mHandler = new Handler();
privatestaticfinallong ANIMATION_CYCLE_TIME_MILLIS = 35000;
privatestaticfinallong FOCUS_DELAY_TIME_MILLIS = 2000;
privatestaticfinallong FOCUS_TIME_MILLIS = 6000;
private Animator mCurrentScrollAnimator;
privateboolean mReverseDirection = false;
privateboolean mAllowFocus = true;
public DemoRenderController(Context context, MuzeiBlurRenderer renderer,
Callbacks callbacks, boolean allowFocus) {
super(context, renderer, callbacks);
mAllowFocus = allowFocus;
runAnimation();
}
privatevoid runAnimation() {
if (mCurrentScrollAnimator != null) {
mCurrentScrollAnimator.cancel();
}
mCurrentScrollAnimator = ObjectAnimator
.ofFloat(mRenderer, "normalOffsetX",
mReverseDirection ? 1f : 0f, mReverseDirection ? 0f : 1f)
.setDuration(ANIMATION_CYCLE_TIME_MILLIS);
mCurrentScrollAnimator.start();
mCurrentScrollAnimator.addListener(new AnimatorListenerAdapter() {
@Override
publicvoid onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
mReverseDirection = !mReverseDirection;
runAnimation();
}
});
if (mAllowFocus) {
mHandler.postDelayed(new Runnable() {
@Override
publicvoid run() {
mRenderer.setIsBlurred(false, false);
mHandler.postDelayed(new Runnable() {
@Override
publicvoid run() {
mRenderer.setIsBlurred(true, false);
}
}, FOCUS_TIME_MILLIS);
}
}, FOCUS_DELAY_TIME_MILLIS);
}
}
@Override
publicvoid destroy() {
super.destroy();
if (mCurrentScrollAnimator != null) {
mCurrentScrollAnimator.cancel();
}
mHandler.removeCallbacksAndMessages(null);
}
@Override
protected BitmapRegionLoader openDownloadedCurrentArtwork(boolean forceReload) {
try {
return BitmapRegionLoader.newInstance(mContext.getAssets().open("starrynight.jpg"));
} catch (IOException e) {
LOGE(TAG, "Error opening demo image.", e);
return null;
}
}
}