Bug 741693 - Move the Axis prefs from GeckoLayerClient into PanZoomController. r=Cwiiis

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

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

@ -43,7 +43,6 @@ import org.mozilla.gecko.GeckoApp;
import org.mozilla.gecko.GeckoAppShell; import org.mozilla.gecko.GeckoAppShell;
import org.mozilla.gecko.GeckoEvent; import org.mozilla.gecko.GeckoEvent;
import org.mozilla.gecko.GeckoEventResponder; import org.mozilla.gecko.GeckoEventResponder;
import org.mozilla.gecko.ui.Axis;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
@ -124,7 +123,6 @@ public class GeckoLayerClient implements GeckoEventResponder,
JSONArray prefs = new JSONArray(); JSONArray prefs = new JSONArray();
DisplayPortCalculator.addPrefNames(prefs); DisplayPortCalculator.addPrefNames(prefs);
Axis.addPrefNames(prefs);
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Preferences:Get", prefs.toString())); GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent("Preferences:Get", prefs.toString()));
} }
@ -273,7 +271,6 @@ public class GeckoLayerClient implements GeckoEventResponder,
// right batch of prefs, since other java code may also have sent requests // right batch of prefs, since other java code may also have sent requests
// for prefs. // for prefs.
if (DisplayPortCalculator.setStrategy(prefValues)) { if (DisplayPortCalculator.setStrategy(prefValues)) {
Axis.setPrefs(prefValues);
GeckoAppShell.unregisterGeckoEventListener("Preferences:Data", this); GeckoAppShell.unregisterGeckoEventListener("Preferences:Data", this);
} }
} }

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

@ -49,7 +49,7 @@ import org.mozilla.gecko.FloatUtils;
* like displacement, velocity, viewport dimensions, etc. pertaining to * like displacement, velocity, viewport dimensions, etc. pertaining to
* a particular axis. * a particular axis.
*/ */
public abstract class Axis { abstract class Axis {
private static final String LOGTAG = "GeckoAxis"; private static final String LOGTAG = "GeckoAxis";
private static final String PREF_SCROLLING_FRICTION_SLOW = "ui.scrolling.friction_slow"; private static final String PREF_SCROLLING_FRICTION_SLOW = "ui.scrolling.friction_slow";
@ -90,7 +90,7 @@ public abstract class Axis {
return (value == null || value < 0 ? defaultValue : value); return (value == null || value < 0 ? defaultValue : value);
} }
public static void addPrefNames(JSONArray prefs) { static void addPrefNames(JSONArray prefs) {
prefs.put(PREF_SCROLLING_FRICTION_FAST); prefs.put(PREF_SCROLLING_FRICTION_FAST);
prefs.put(PREF_SCROLLING_FRICTION_SLOW); prefs.put(PREF_SCROLLING_FRICTION_SLOW);
prefs.put(PREF_SCROLLING_VELOCITY_THRESHOLD); prefs.put(PREF_SCROLLING_VELOCITY_THRESHOLD);
@ -100,7 +100,7 @@ public abstract class Axis {
prefs.put(PREF_SCROLLING_MIN_SCROLLABLE_DISTANCE); prefs.put(PREF_SCROLLING_MIN_SCROLLABLE_DISTANCE);
} }
public static void setPrefs(Map<String, Integer> prefs) { static void setPrefs(Map<String, Integer> prefs) {
FRICTION_SLOW = getFloatPref(prefs, PREF_SCROLLING_FRICTION_SLOW, 850); FRICTION_SLOW = getFloatPref(prefs, PREF_SCROLLING_FRICTION_SLOW, 850);
FRICTION_FAST = getFloatPref(prefs, PREF_SCROLLING_FRICTION_FAST, 970); FRICTION_FAST = getFloatPref(prefs, PREF_SCROLLING_FRICTION_FAST, 970);
VELOCITY_THRESHOLD = getIntPref(prefs, PREF_SCROLLING_VELOCITY_THRESHOLD, 10); VELOCITY_THRESHOLD = getIntPref(prefs, PREF_SCROLLING_VELOCITY_THRESHOLD, 10);

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

@ -57,6 +57,8 @@ import android.util.Log;
import android.view.GestureDetector; import android.view.GestureDetector;
import android.view.MotionEvent; import android.view.MotionEvent;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map;
import java.util.HashMap;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.Timer; import java.util.Timer;
import java.util.TimerTask; import java.util.TimerTask;
@ -165,6 +167,7 @@ public class PanZoomController
JSONArray prefs = new JSONArray(); JSONArray prefs = new JSONArray();
prefs.put(PREF_ZOOM_ANIMATION_FRAMES); prefs.put(PREF_ZOOM_ANIMATION_FRAMES);
Axis.addPrefNames(prefs);
GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent(MESSAGE_PREFS_GET, prefs.toString())); GeckoAppShell.sendEventToGecko(GeckoEvent.createBroadcastEvent(MESSAGE_PREFS_GET, prefs.toString()));
} }
@ -209,15 +212,30 @@ public class PanZoomController
}); });
} else if (MESSAGE_PREFS_DATA.equals(event)) { } else if (MESSAGE_PREFS_DATA.equals(event)) {
JSONArray jsonPrefs = message.getJSONArray("preferences"); JSONArray jsonPrefs = message.getJSONArray("preferences");
Map<String, Integer> axisPrefs = new HashMap<String, Integer>();
String zoomAnimationFrames = null;
for (int i = jsonPrefs.length() - 1; i >= 0; i--) { for (int i = jsonPrefs.length() - 1; i >= 0; i--) {
JSONObject pref = jsonPrefs.getJSONObject(i); JSONObject pref = jsonPrefs.getJSONObject(i);
String name = pref.getString("name"); String name = pref.getString("name");
if (PREF_ZOOM_ANIMATION_FRAMES.equals(name)) { if (PREF_ZOOM_ANIMATION_FRAMES.equals(name)) {
setZoomAnimationFrames(pref.getString("value")); zoomAnimationFrames = pref.getString("value");
GeckoAppShell.unregisterGeckoEventListener(MESSAGE_PREFS_DATA, this); } else {
break; try {
axisPrefs.put(name, pref.getInt("value"));
} catch (JSONException je) {
// the value could not be parsed as an int. ignore this
// pref and continue
}
} }
} }
// check for null to make sure the batch of preferences we got notified
// of are in the fact the ones we requested and not those requested by
// other java code
if (zoomAnimationFrames != null) {
setZoomAnimationFrames(zoomAnimationFrames);
Axis.setPrefs(axisPrefs);
GeckoAppShell.unregisterGeckoEventListener(MESSAGE_PREFS_DATA, this);
}
} }
} catch (Exception e) { } catch (Exception e) {
Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e); Log.e(LOGTAG, "Exception handling message \"" + event + "\":", e);
@ -226,7 +244,7 @@ public class PanZoomController
private void setZoomAnimationFrames(String frames) { private void setZoomAnimationFrames(String frames) {
try { try {
if (frames != null && frames.length() > 0) { if (frames.length() > 0) {
StringTokenizer st = new StringTokenizer(frames, ","); StringTokenizer st = new StringTokenizer(frames, ",");
float[] values = new float[st.countTokens()]; float[] values = new float[st.countTokens()];
for (int i = 0; i < values.length; i++) { for (int i = 0; i < values.length; i++) {