Bug 741693 - Make the zoom animation frames preffable. r=Cwiiis

This commit is contained in:
Kartikaya Gupta 2012-04-17 11:33:19 -04:00
Родитель b03faaa8c6
Коммит 9dbef8e3e9
3 изменённых файлов: 54 добавлений и 5 удалений

Просмотреть файл

@ -747,3 +747,6 @@ pref("ui.scrolling.overscroll_snap_limit", -1);
// The minimum amount of space that must be present for an axis to be considered scrollable,
// in 1/1000ths of pixels.
pref("ui.scrolling.min_scrollable_distance", -1);
// A comma-separated list of float values in the range [0.0, 1.0) that are used as
// interpolation frames for zoom animations.
pref("ui.zooming.animation_frames", "");

Просмотреть файл

@ -261,7 +261,13 @@ public class GeckoLayerClient implements GeckoEventResponder,
Map<String, Integer> prefValues = new HashMap<String, Integer>();
for (int i = jsonPrefs.length() - 1; i >= 0; i--) {
JSONObject pref = jsonPrefs.getJSONObject(i);
prefValues.put(pref.getString("name"), pref.getInt("value"));
String name = pref.getString("name");
try {
prefValues.put(name, pref.getInt("value"));
} catch (JSONException je) {
// the pref value couldn't be parsed as an int. drop this pref
// and continue with the rest
}
}
// check return value from setStrategy to make sure that this is the
// right batch of prefs, since other java code may also have sent requests

Просмотреть файл

@ -38,8 +38,9 @@
package org.mozilla.gecko.ui;
import org.json.JSONObject;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.mozilla.gecko.gfx.FloatSize;
import org.mozilla.gecko.gfx.LayerController;
import org.mozilla.gecko.gfx.PointUtils;
@ -55,6 +56,8 @@ import android.util.FloatMath;
import android.util.Log;
import android.view.GestureDetector;
import android.view.MotionEvent;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.util.Timer;
import java.util.TimerTask;
@ -72,6 +75,10 @@ public class PanZoomController
private static String MESSAGE_ZOOM_RECT = "Browser:ZoomToRect";
private static String MESSAGE_ZOOM_PAGE = "Browser:ZoomToPageWidth";
private static String MESSAGE_PREFS_GET = "Preferences:Get";
private static String MESSAGE_PREFS_DATA = "Preferences:Data";
private static final String PREF_ZOOM_ANIMATION_FRAMES = "ui.zooming.animation_frames";
// Animation stops if the velocity is below this value when overscrolled or panning.
private static final float STOPPED_THRESHOLD = 4.0f;
@ -90,7 +97,7 @@ public class PanZoomController
private static final float MAX_ZOOM = 4.0f;
/* 16 precomputed frames of the _ease-out_ animation from the CSS Transitions specification. */
private static final float[] EASE_OUT_ANIMATION_FRAMES = {
private static float[] ZOOM_ANIMATION_FRAMES = new float[] {
0.00000f, /* 0 */
0.10211f, /* 1 */
0.19864f, /* 2 */
@ -154,6 +161,11 @@ public class PanZoomController
GeckoAppShell.registerGeckoEventListener(MESSAGE_ZOOM_RECT, this);
GeckoAppShell.registerGeckoEventListener(MESSAGE_ZOOM_PAGE, this);
GeckoAppShell.registerGeckoEventListener(MESSAGE_PREFS_DATA, this);
JSONArray prefs = new JSONArray();
prefs.put(PREF_ZOOM_ANIMATION_FRAMES);
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent(MESSAGE_PREFS_GET, prefs.toString()));
}
// for debugging bug 713011; it can be taken out once that is resolved.
@ -195,12 +207,40 @@ public class PanZoomController
animatedZoomTo(r);
}
});
} else if (MESSAGE_PREFS_DATA.equals(event)) {
JSONArray jsonPrefs = message.getJSONArray("preferences");
for (int i = jsonPrefs.length() - 1; i >= 0; i--) {
JSONObject pref = jsonPrefs.getJSONObject(i);
String name = pref.getString("name");
if (PREF_ZOOM_ANIMATION_FRAMES.equals(name)) {
setZoomAnimationFrames(pref.getString("value"));
GeckoAppShell.unregisterGeckoEventListener(MESSAGE_PREFS_DATA, this);
break;
}
}
}
} catch (Exception e) {
Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
}
}
private void setZoomAnimationFrames(String frames) {
try {
if (frames != null && frames.length() > 0) {
StringTokenizer st = new StringTokenizer(frames, ",");
float[] values = new float[st.countTokens()];
for (int i = 0; i < values.length; i++) {
values[i] = Float.parseFloat(st.nextToken());
}
ZOOM_ANIMATION_FRAMES = values;
}
} catch (NumberFormatException e) {
Log.e(LOGTAG, "Error setting zoom animation frames", e);
} finally {
Log.i(LOGTAG, "Zoom animation frames: " + Arrays.toString(ZOOM_ANIMATION_FRAMES));
}
}
public boolean onTouchEvent(MotionEvent event) {
switch (event.getAction() & MotionEvent.ACTION_MASK) {
case MotionEvent.ACTION_DOWN: return onTouchStart(event);
@ -615,7 +655,7 @@ public class PanZoomController
}
/* Perform the next frame of the bounce-back animation. */
if (mBounceFrame < EASE_OUT_ANIMATION_FRAMES.length) {
if (mBounceFrame < ZOOM_ANIMATION_FRAMES.length) {
advanceBounce();
return;
}
@ -629,7 +669,7 @@ public class PanZoomController
/* Performs one frame of a bounce animation. */
private void advanceBounce() {
synchronized (mController) {
float t = EASE_OUT_ANIMATION_FRAMES[mBounceFrame];
float t = ZOOM_ANIMATION_FRAMES[mBounceFrame];
ViewportMetrics newMetrics = mBounceStartMetrics.interpolate(mBounceEndMetrics, t);
mController.setViewportMetrics(newMetrics);
mController.notifyLayerClientOfGeometryChange();