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;
import android.graphics.RectF;
import de.greenrobot.event.EventBus;
// Singleton that also behaves as an event
publicclass ArtDetailViewport {
privatevolatile RectF mViewport0 = new RectF();
privatevolatile RectF mViewport1 = new RectF();
privateboolean mFromUser;
privatestatic ArtDetailViewport sInstance = new ArtDetailViewport();
publicstatic ArtDetailViewport getInstance() {
return sInstance;
}
private ArtDetailViewport() {
}
public RectF getViewport(int id) {
return (id == 0) ? mViewport0 : mViewport1;
}
public ArtDetailViewport setViewport(int id, RectF viewport, boolean fromUser) {
return setViewport(id, viewport.left, viewport.top, viewport.right, viewport.bottom,
fromUser);
}
public ArtDetailViewport setViewport(int id, float left, float top, float right, float bottom,
boolean fromUser) {
mFromUser = fromUser;
getViewport(id).set(left, top, right, bottom);
EventBus.getDefault().post(this);
returnthis;
}
publicboolean isFromUser() {
return mFromUser;
}
public ArtDetailViewport setDefaultViewport(int id, float bitmapAspectRatio,
float screenAspectRatio) {
mFromUser = false;
if (bitmapAspectRatio > screenAspectRatio) {
getViewport(id).set(
0.5f - screenAspectRatio / bitmapAspectRatio / 2,
0,
0.5f + screenAspectRatio / bitmapAspectRatio / 2,
1);
} else {
getViewport(id).set(
0,
0.5f - bitmapAspectRatio / screenAspectRatio / 2,
1,
0.5f + bitmapAspectRatio / screenAspectRatio / 2);
}
EventBus.getDefault().post(this);
returnthis;
}
}