mirror of
https://repo.dactyloidae.xyz/Dactyloidae/UXP.git
synced 2026-09-06 15:58:39 +09:00
import FIREFOX_52_6_0esr_RELEASE from mozilla-esr52 hg repo
This commit is contained in:
commit
dcd9973243
150858 changed files with 23884658 additions and 0 deletions
|
|
@ -0,0 +1,21 @@
|
|||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
|
||||
package org.mozilla.gecko.animation;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
public class AnimationUtils {
|
||||
private static long mShortDuration = -1;
|
||||
|
||||
public static long getShortDuration(Context context) {
|
||||
if (mShortDuration < 0) {
|
||||
mShortDuration = context.getResources().getInteger(android.R.integer.config_shortAnimTime);
|
||||
}
|
||||
return mShortDuration;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.gecko.animation;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.Transformation;
|
||||
|
||||
public class HeightChangeAnimation extends Animation {
|
||||
int mFromHeight;
|
||||
int mToHeight;
|
||||
View mView;
|
||||
|
||||
public HeightChangeAnimation(View view, int fromHeight, int toHeight) {
|
||||
mView = view;
|
||||
mFromHeight = fromHeight;
|
||||
mToHeight = toHeight;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyTransformation(float interpolatedTime, Transformation t) {
|
||||
mView.getLayoutParams().height = Math.round((mFromHeight * (1 - interpolatedTime)) + (mToHeight * interpolatedTime));
|
||||
mView.requestLayout();
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,342 @@
|
|||
/* -*- Mode: Java; c-basic-offset: 4; tab-width: 20; indent-tabs-mode: nil; -*-
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.gecko.animation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.mozilla.gecko.AppConstants.Versions;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.support.v4.view.ViewCompat;
|
||||
import android.view.Choreographer;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewTreeObserver;
|
||||
import android.view.animation.AnimationUtils;
|
||||
import android.view.animation.DecelerateInterpolator;
|
||||
import android.view.animation.Interpolator;
|
||||
|
||||
public class PropertyAnimator implements Runnable {
|
||||
private static final String LOGTAG = "GeckoPropertyAnimator";
|
||||
|
||||
public static enum Property {
|
||||
ALPHA,
|
||||
TRANSLATION_X,
|
||||
TRANSLATION_Y,
|
||||
SCROLL_X,
|
||||
SCROLL_Y,
|
||||
WIDTH,
|
||||
HEIGHT
|
||||
}
|
||||
|
||||
private class ElementHolder {
|
||||
View view;
|
||||
Property property;
|
||||
float from;
|
||||
float to;
|
||||
}
|
||||
|
||||
public static interface PropertyAnimationListener {
|
||||
public void onPropertyAnimationStart();
|
||||
public void onPropertyAnimationEnd();
|
||||
}
|
||||
|
||||
private final Interpolator mInterpolator;
|
||||
private long mStartTime;
|
||||
private final long mDuration;
|
||||
private final float mDurationReciprocal;
|
||||
private final List<ElementHolder> mElementsList;
|
||||
private List<PropertyAnimationListener> mListeners;
|
||||
FramePoster mFramePoster;
|
||||
private boolean mUseHardwareLayer;
|
||||
|
||||
public PropertyAnimator(long duration) {
|
||||
this(duration, new DecelerateInterpolator());
|
||||
}
|
||||
|
||||
public PropertyAnimator(long duration, Interpolator interpolator) {
|
||||
mDuration = duration;
|
||||
mDurationReciprocal = 1.0f / mDuration;
|
||||
mInterpolator = interpolator;
|
||||
mElementsList = new ArrayList<ElementHolder>();
|
||||
mFramePoster = FramePoster.create(this);
|
||||
mUseHardwareLayer = true;
|
||||
}
|
||||
|
||||
public void setUseHardwareLayer(boolean useHardwareLayer) {
|
||||
mUseHardwareLayer = useHardwareLayer;
|
||||
}
|
||||
|
||||
public void attach(View view, Property property, float to) {
|
||||
ElementHolder element = new ElementHolder();
|
||||
|
||||
element.view = view;
|
||||
element.property = property;
|
||||
element.to = to;
|
||||
|
||||
mElementsList.add(element);
|
||||
}
|
||||
|
||||
public void addPropertyAnimationListener(PropertyAnimationListener listener) {
|
||||
if (mListeners == null) {
|
||||
mListeners = new ArrayList<PropertyAnimationListener>();
|
||||
}
|
||||
|
||||
mListeners.add(listener);
|
||||
}
|
||||
|
||||
public long getDuration() {
|
||||
return mDuration;
|
||||
}
|
||||
|
||||
public long getRemainingTime() {
|
||||
int timePassed = (int) (AnimationUtils.currentAnimationTimeMillis() - mStartTime);
|
||||
return mDuration - timePassed;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
int timePassed = (int) (AnimationUtils.currentAnimationTimeMillis() - mStartTime);
|
||||
if (timePassed >= mDuration) {
|
||||
stop();
|
||||
return;
|
||||
}
|
||||
|
||||
float interpolation = mInterpolator.getInterpolation(timePassed * mDurationReciprocal);
|
||||
|
||||
for (ElementHolder element : mElementsList) {
|
||||
float delta = element.from + ((element.to - element.from) * interpolation);
|
||||
invalidate(element, delta);
|
||||
}
|
||||
|
||||
mFramePoster.postNextAnimationFrame();
|
||||
}
|
||||
|
||||
public void start() {
|
||||
if (mDuration == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
mStartTime = AnimationUtils.currentAnimationTimeMillis();
|
||||
|
||||
// Fix the from value based on current position and property
|
||||
for (ElementHolder element : mElementsList) {
|
||||
if (element.property == Property.ALPHA)
|
||||
element.from = ViewHelper.getAlpha(element.view);
|
||||
else if (element.property == Property.TRANSLATION_Y)
|
||||
element.from = ViewHelper.getTranslationY(element.view);
|
||||
else if (element.property == Property.TRANSLATION_X)
|
||||
element.from = ViewHelper.getTranslationX(element.view);
|
||||
else if (element.property == Property.SCROLL_Y)
|
||||
element.from = ViewHelper.getScrollY(element.view);
|
||||
else if (element.property == Property.SCROLL_X)
|
||||
element.from = ViewHelper.getScrollX(element.view);
|
||||
else if (element.property == Property.WIDTH)
|
||||
element.from = ViewHelper.getWidth(element.view);
|
||||
else if (element.property == Property.HEIGHT)
|
||||
element.from = ViewHelper.getHeight(element.view);
|
||||
|
||||
ViewCompat.setHasTransientState(element.view, true);
|
||||
|
||||
if (shouldEnableHardwareLayer(element))
|
||||
element.view.setLayerType(View.LAYER_TYPE_HARDWARE, null);
|
||||
else
|
||||
element.view.setDrawingCacheEnabled(true);
|
||||
}
|
||||
|
||||
// Get ViewTreeObserver from any of the participant views
|
||||
// in the animation.
|
||||
final ViewTreeObserver treeObserver;
|
||||
if (mElementsList.size() > 0) {
|
||||
treeObserver = mElementsList.get(0).view.getViewTreeObserver();
|
||||
} else {
|
||||
treeObserver = null;
|
||||
}
|
||||
|
||||
final ViewTreeObserver.OnPreDrawListener preDrawListener = new ViewTreeObserver.OnPreDrawListener() {
|
||||
@Override
|
||||
public boolean onPreDraw() {
|
||||
if (treeObserver.isAlive()) {
|
||||
treeObserver.removeOnPreDrawListener(this);
|
||||
}
|
||||
|
||||
mFramePoster.postFirstAnimationFrame();
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
// Try to start animation after any on-going layout round
|
||||
// in the current view tree. OnPreDrawListener seems broken
|
||||
// on pre-Honeycomb devices, start animation immediatelly
|
||||
// in this case.
|
||||
if (treeObserver != null && treeObserver.isAlive()) {
|
||||
treeObserver.addOnPreDrawListener(preDrawListener);
|
||||
} else {
|
||||
mFramePoster.postFirstAnimationFrame();
|
||||
}
|
||||
|
||||
if (mListeners != null) {
|
||||
for (PropertyAnimationListener listener : mListeners) {
|
||||
listener.onPropertyAnimationStart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stop the animation, optionally snapping to the end position.
|
||||
* onPropertyAnimationEnd is only called when snapping to the end position.
|
||||
*/
|
||||
public void stop(boolean snapToEndPosition) {
|
||||
mFramePoster.cancelAnimationFrame();
|
||||
|
||||
// Make sure to snap to the end position.
|
||||
for (ElementHolder element : mElementsList) {
|
||||
if (snapToEndPosition)
|
||||
invalidate(element, element.to);
|
||||
|
||||
ViewCompat.setHasTransientState(element.view, false);
|
||||
|
||||
if (shouldEnableHardwareLayer(element)) {
|
||||
element.view.setLayerType(View.LAYER_TYPE_NONE, null);
|
||||
} else {
|
||||
element.view.setDrawingCacheEnabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
mElementsList.clear();
|
||||
|
||||
if (mListeners != null) {
|
||||
if (snapToEndPosition) {
|
||||
for (PropertyAnimationListener listener : mListeners) {
|
||||
listener.onPropertyAnimationEnd();
|
||||
}
|
||||
}
|
||||
|
||||
mListeners.clear();
|
||||
mListeners = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
stop(true);
|
||||
}
|
||||
|
||||
private boolean shouldEnableHardwareLayer(ElementHolder element) {
|
||||
if (!mUseHardwareLayer) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!(element.view instanceof ViewGroup)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (element.property == Property.ALPHA ||
|
||||
element.property == Property.TRANSLATION_Y ||
|
||||
element.property == Property.TRANSLATION_X) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void invalidate(final ElementHolder element, final float delta) {
|
||||
final View view = element.view;
|
||||
|
||||
// check to see if the view was detached between the check above and this code
|
||||
// getting run on the UI thread.
|
||||
if (view.getHandler() == null)
|
||||
return;
|
||||
|
||||
if (element.property == Property.ALPHA)
|
||||
ViewHelper.setAlpha(element.view, delta);
|
||||
else if (element.property == Property.TRANSLATION_Y)
|
||||
ViewHelper.setTranslationY(element.view, delta);
|
||||
else if (element.property == Property.TRANSLATION_X)
|
||||
ViewHelper.setTranslationX(element.view, delta);
|
||||
else if (element.property == Property.SCROLL_Y)
|
||||
ViewHelper.scrollTo(element.view, ViewHelper.getScrollX(element.view), (int) delta);
|
||||
else if (element.property == Property.SCROLL_X)
|
||||
ViewHelper.scrollTo(element.view, (int) delta, ViewHelper.getScrollY(element.view));
|
||||
else if (element.property == Property.WIDTH)
|
||||
ViewHelper.setWidth(element.view, (int) delta);
|
||||
else if (element.property == Property.HEIGHT)
|
||||
ViewHelper.setHeight(element.view, (int) delta);
|
||||
}
|
||||
|
||||
private static abstract class FramePoster {
|
||||
public static FramePoster create(Runnable r) {
|
||||
if (Versions.feature16Plus) {
|
||||
return new FramePosterPostJB(r);
|
||||
}
|
||||
|
||||
return new FramePosterPreJB(r);
|
||||
}
|
||||
|
||||
public abstract void postFirstAnimationFrame();
|
||||
public abstract void postNextAnimationFrame();
|
||||
public abstract void cancelAnimationFrame();
|
||||
}
|
||||
|
||||
private static class FramePosterPreJB extends FramePoster {
|
||||
// Default refresh rate in ms.
|
||||
private static final int INTERVAL = 10;
|
||||
|
||||
private final Handler mHandler;
|
||||
private final Runnable mRunnable;
|
||||
|
||||
public FramePosterPreJB(Runnable r) {
|
||||
mHandler = new Handler();
|
||||
mRunnable = r;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postFirstAnimationFrame() {
|
||||
mHandler.post(mRunnable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postNextAnimationFrame() {
|
||||
mHandler.postDelayed(mRunnable, INTERVAL);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelAnimationFrame() {
|
||||
mHandler.removeCallbacks(mRunnable);
|
||||
}
|
||||
}
|
||||
|
||||
private static class FramePosterPostJB extends FramePoster {
|
||||
private final Choreographer mChoreographer;
|
||||
private final Choreographer.FrameCallback mCallback;
|
||||
|
||||
public FramePosterPostJB(final Runnable r) {
|
||||
mChoreographer = Choreographer.getInstance();
|
||||
|
||||
mCallback = new Choreographer.FrameCallback() {
|
||||
@Override
|
||||
public void doFrame(long frameTimeNanos) {
|
||||
r.run();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postFirstAnimationFrame() {
|
||||
postNextAnimationFrame();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postNextAnimationFrame() {
|
||||
mChoreographer.postFrameCallback(mCallback);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancelAnimationFrame() {
|
||||
mChoreographer.removeFrameCallback(mCallback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
/*
|
||||
* Copyright (C) 2007 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 org.mozilla.gecko.animation;
|
||||
|
||||
import android.view.animation.Animation;
|
||||
import android.view.animation.Transformation;
|
||||
|
||||
import android.graphics.Camera;
|
||||
import android.graphics.Matrix;
|
||||
|
||||
/**
|
||||
* An animation that rotates the view on the Y axis between two specified angles.
|
||||
* This animation also adds a translation on the Z axis (depth) to improve the effect.
|
||||
*/
|
||||
public class Rotate3DAnimation extends Animation {
|
||||
private final float mFromDegrees;
|
||||
private final float mToDegrees;
|
||||
|
||||
private final float mCenterX;
|
||||
private final float mCenterY;
|
||||
|
||||
private final float mDepthZ;
|
||||
private final boolean mReverse;
|
||||
private Camera mCamera;
|
||||
|
||||
private int mWidth = 1;
|
||||
private int mHeight = 1;
|
||||
|
||||
/**
|
||||
* Creates a new 3D rotation on the Y axis. The rotation is defined by its
|
||||
* start angle and its end angle. Both angles are in degrees. The rotation
|
||||
* is performed around a center point on the 2D space, defined by a pair
|
||||
* of X and Y coordinates, called centerX and centerY. When the animation
|
||||
* starts, a translation on the Z axis (depth) is performed. The length
|
||||
* of the translation can be specified, as well as whether the translation
|
||||
* should be reversed in time.
|
||||
*
|
||||
* @param fromDegrees the start angle of the 3D rotation
|
||||
* @param toDegrees the end angle of the 3D rotation
|
||||
* @param centerX the X center of the 3D rotation
|
||||
* @param centerY the Y center of the 3D rotation
|
||||
* @param reverse true if the translation should be reversed, false otherwise
|
||||
*/
|
||||
public Rotate3DAnimation(float fromDegrees, float toDegrees,
|
||||
float centerX, float centerY, float depthZ, boolean reverse) {
|
||||
mFromDegrees = fromDegrees;
|
||||
mToDegrees = toDegrees;
|
||||
mCenterX = centerX;
|
||||
mCenterY = centerY;
|
||||
mDepthZ = depthZ;
|
||||
mReverse = reverse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initialize(int width, int height, int parentWidth, int parentHeight) {
|
||||
super.initialize(width, height, parentWidth, parentHeight);
|
||||
mCamera = new Camera();
|
||||
mWidth = width;
|
||||
mHeight = height;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void applyTransformation(float interpolatedTime, Transformation t) {
|
||||
final float fromDegrees = mFromDegrees;
|
||||
float degrees = fromDegrees + ((mToDegrees - fromDegrees) * interpolatedTime);
|
||||
|
||||
final Camera camera = mCamera;
|
||||
final Matrix matrix = t.getMatrix();
|
||||
|
||||
camera.save();
|
||||
if (mReverse) {
|
||||
camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);
|
||||
} else {
|
||||
camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));
|
||||
}
|
||||
camera.rotateX(degrees);
|
||||
camera.getMatrix(matrix);
|
||||
camera.restore();
|
||||
|
||||
matrix.preTranslate(-mCenterX * mWidth, -mCenterY * mHeight);
|
||||
matrix.postTranslate(mCenterX * mWidth, mCenterY * mHeight);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,109 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
|
||||
* You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.gecko.animation;
|
||||
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
public final class ViewHelper {
|
||||
private ViewHelper() {
|
||||
}
|
||||
|
||||
public static float getTranslationX(View view) {
|
||||
if (view != null) {
|
||||
return view.getTranslationX();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void setTranslationX(View view, float translationX) {
|
||||
if (view != null) {
|
||||
view.setTranslationX(translationX);
|
||||
}
|
||||
}
|
||||
|
||||
public static float getTranslationY(View view) {
|
||||
if (view != null) {
|
||||
return view.getTranslationY();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void setTranslationY(View view, float translationY) {
|
||||
if (view != null) {
|
||||
view.setTranslationY(translationY);
|
||||
}
|
||||
}
|
||||
|
||||
public static float getAlpha(View view) {
|
||||
if (view != null) {
|
||||
return view.getAlpha();
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
public static void setAlpha(View view, float alpha) {
|
||||
if (view != null) {
|
||||
view.setAlpha(alpha);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getWidth(View view) {
|
||||
if (view != null) {
|
||||
return view.getWidth();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void setWidth(View view, int width) {
|
||||
if (view != null) {
|
||||
ViewGroup.LayoutParams lp = view.getLayoutParams();
|
||||
lp.width = width;
|
||||
view.setLayoutParams(lp);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getHeight(View view) {
|
||||
if (view != null) {
|
||||
return view.getHeight();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void setHeight(View view, int height) {
|
||||
if (view != null) {
|
||||
ViewGroup.LayoutParams lp = view.getLayoutParams();
|
||||
lp.height = height;
|
||||
view.setLayoutParams(lp);
|
||||
}
|
||||
}
|
||||
|
||||
public static int getScrollX(View view) {
|
||||
if (view != null) {
|
||||
return view.getScrollX();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static int getScrollY(View view) {
|
||||
if (view != null) {
|
||||
return view.getScrollY();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public static void scrollTo(View view, int scrollX, int scrollY) {
|
||||
if (view != null) {
|
||||
view.scrollTo(scrollX, scrollY);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue