summaryrefslogtreecommitdiff
path: root/android
diff options
context:
space:
mode:
authoraleksandar-stefanovic <theonewithideas@gmail.com>2017-01-31 19:35:52 +0100
committerChristian Lohmaier <lohmaier+LibreOffice@googlemail.com>2017-02-07 11:27:55 +0000
commit7d6269ecc9945bff9dc00f5eeb62e47e2cf284bb (patch)
treea78cb3b2cb24bd638ee02403cbd5cbd209a07cb7 /android
parent94a870fd21229364c1e3723917bae723ce00a01b (diff)
Removed static context from DisplayPortCalculator
Refactored many fields of DisplayPortCalculator to not be static, so that they could use the Context object from the constructor. Once refactored, the static context object could be removed from LibreOfficeMainActivity. Change-Id: Ic23030b74a24c753a4a2d2086fc6301eeb9d8728 Reviewed-on: https://gerrit.libreoffice.org/33765 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Christian Lohmaier <lohmaier+LibreOffice@googlemail.com>
Diffstat (limited to 'android')
-rwxr-xr-xandroid/source/src/java/org/libreoffice/LibreOfficeMainActivity.java3
-rw-r--r--android/source/src/java/org/mozilla/gecko/gfx/DisplayPortCalculator.java57
-rw-r--r--android/source/src/java/org/mozilla/gecko/gfx/GeckoLayerClient.java8
3 files changed, 37 insertions, 31 deletions
diff --git a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
index 4f0beb9767bd..d88e7eabe270 100755
--- a/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
+++ b/android/source/src/java/org/libreoffice/LibreOfficeMainActivity.java
@@ -54,8 +54,6 @@ public class LibreOfficeMainActivity extends AppCompatActivity {
private static final String ENABLE_EXPERIMENTAL_PREFS_KEY = "ENABLE_EXPERIMENTAL";
private static final String ASSETS_EXTRACTED_PREFS_KEY = "ASSETS_EXTRACTED";
- //TODO WIP: removing this static Context (in the following commits)
- public static LibreOfficeMainActivity mAppContext;
//TODO "public static" is a temporary workaround
public static LOKitThread loKitThread;
@@ -100,7 +98,6 @@ public class LibreOfficeMainActivity extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
Log.w(LOGTAG, "onCreate..");
- mAppContext = this;
super.onCreate(savedInstanceState);
SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
diff --git a/android/source/src/java/org/mozilla/gecko/gfx/DisplayPortCalculator.java b/android/source/src/java/org/mozilla/gecko/gfx/DisplayPortCalculator.java
index 838286b669a8..717aaec5d0c1 100644
--- a/android/source/src/java/org/mozilla/gecko/gfx/DisplayPortCalculator.java
+++ b/android/source/src/java/org/mozilla/gecko/gfx/DisplayPortCalculator.java
@@ -36,24 +36,30 @@ final class DisplayPortCalculator {
private static final String PREF_DISPLAYPORT_VB_DANGER_Y_INCR = "gfx.displayport.strategy_vb.danger_y_incr";
private static final String PREF_DISPLAYPORT_PB_VELOCITY_THRESHOLD = "gfx.displayport.strategy_pb.threshold";
- private static DisplayPortStrategy sStrategy = new VelocityBiasStrategy(null);
+ private DisplayPortStrategy sStrategy;
+ private final LibreOfficeMainActivity mMainActivity;
- static DisplayPortMetrics calculate(ImmutableViewportMetrics metrics, PointF velocity) {
+ DisplayPortCalculator(LibreOfficeMainActivity context) {
+ this.mMainActivity = context;
+ sStrategy = new VelocityBiasStrategy(mMainActivity, null);
+ }
+
+ DisplayPortMetrics calculate(ImmutableViewportMetrics metrics, PointF velocity) {
return sStrategy.calculate(metrics, (velocity == null ? ZERO_VELOCITY : velocity));
}
- static boolean aboutToCheckerboard(ImmutableViewportMetrics metrics, PointF velocity, DisplayPortMetrics displayPort) {
+ boolean aboutToCheckerboard(ImmutableViewportMetrics metrics, PointF velocity, DisplayPortMetrics displayPort) {
if (displayPort == null) {
return true;
}
return sStrategy.aboutToCheckerboard(metrics, (velocity == null ? ZERO_VELOCITY : velocity), displayPort);
}
- static boolean drawTimeUpdate(long millis, int pixels) {
+ boolean drawTimeUpdate(long millis, int pixels) {
return sStrategy.drawTimeUpdate(millis, pixels);
}
- static void resetPageState() {
+ void resetPageState() {
sStrategy.resetPageState();
}
@@ -77,7 +83,7 @@ final class DisplayPortCalculator {
* See the gfx.displayport.strategy pref in mobile/android/app/mobile.js to see the
* mapping between ints and strategies.
*/
- static boolean setStrategy(Map<String, Integer> prefs) {
+ boolean setStrategy(Map<String, Integer> prefs) {
Integer strategy = prefs.get(PREF_DISPLAYPORT_STRATEGY);
if (strategy == null) {
return false;
@@ -88,16 +94,16 @@ final class DisplayPortCalculator {
sStrategy = new FixedMarginStrategy(prefs);
break;
case 1:
- sStrategy = new VelocityBiasStrategy(prefs);
+ sStrategy = new VelocityBiasStrategy(mMainActivity, prefs);
break;
case 2:
- sStrategy = new DynamicResolutionStrategy(prefs);
+ sStrategy = new DynamicResolutionStrategy(mMainActivity, prefs);
break;
case 3:
sStrategy = new NoMarginStrategy(prefs);
break;
case 4:
- sStrategy = new PredictionBiasStrategy(prefs);
+ sStrategy = new PredictionBiasStrategy(mMainActivity, prefs);
break;
default:
Log.e(LOGTAG, "Invalid strategy index specified");
@@ -337,10 +343,9 @@ final class DisplayPortCalculator {
private final float DANGER_ZONE_INCR_X_MULTIPLIER;
private final float DANGER_ZONE_INCR_Y_MULTIPLIER;
- VelocityBiasStrategy(Map<String, Integer> prefs) {
+ VelocityBiasStrategy(LibreOfficeMainActivity context, Map<String, Integer> prefs) {
SIZE_MULTIPLIER = getFloatPref(prefs, PREF_DISPLAYPORT_VB_MULTIPLIER, 2000);
- //TODO remove static reference to context
- VELOCITY_THRESHOLD = LOKitShell.getDpi(LibreOfficeMainActivity.mAppContext) * getFloatPref(prefs, PREF_DISPLAYPORT_VB_VELOCITY_THRESHOLD, 32);
+ VELOCITY_THRESHOLD = LOKitShell.getDpi(context) * getFloatPref(prefs, PREF_DISPLAYPORT_VB_VELOCITY_THRESHOLD, 32);
REVERSE_BUFFER = getFloatPref(prefs, PREF_DISPLAYPORT_VB_REVERSE_BUFFER, 200);
DANGER_ZONE_BASE_X_MULTIPLIER = getFloatPref(prefs, PREF_DISPLAYPORT_VB_DANGER_X_BASE, 1000);
DANGER_ZONE_BASE_Y_MULTIPLIER = getFloatPref(prefs, PREF_DISPLAYPORT_VB_DANGER_Y_BASE, 1000);
@@ -448,14 +453,21 @@ final class DisplayPortCalculator {
* where we draw less but never even show it on the screen.
*/
private static class DynamicResolutionStrategy extends DisplayPortStrategy {
- // The length of each axis of the display port will be the corresponding view length
- // multiplied by this factor.
- private static final float SIZE_MULTIPLIER = 1.5f;
// The velocity above which we start zooming out the display port to keep up
// with the panning.
- //TODO remove static reference to context
- private static final float VELOCITY_EXPANSION_THRESHOLD = LOKitShell.getDpi(LibreOfficeMainActivity.mAppContext) / 16f;
+ private final float VELOCITY_EXPANSION_THRESHOLD;
+
+
+ DynamicResolutionStrategy(LibreOfficeMainActivity context, Map<String, Integer> prefs) {
+ // ignore prefs for now
+ VELOCITY_EXPANSION_THRESHOLD = LOKitShell.getDpi(context) / 16f;
+ VELOCITY_FAST_THRESHOLD = VELOCITY_EXPANSION_THRESHOLD * 2.0f;
+ }
+
+ // The length of each axis of the display port will be the corresponding view length
+ // multiplied by this factor.
+ private static final float SIZE_MULTIPLIER = 1.5f;
// How much we increase the display port based on velocity. Assuming no friction and
// splitting (see below), this should be the number of frames (@60fps) between us
@@ -481,7 +493,7 @@ final class DisplayPortCalculator {
// assumption that if the user is panning fast, they are less likely to reverse directions
// and go backwards, so we should spend more of our display port buffer in the direction of
// panning.
- private static final float VELOCITY_FAST_THRESHOLD = VELOCITY_EXPANSION_THRESHOLD * 2.0f;
+ private final float VELOCITY_FAST_THRESHOLD;
private static final float FAST_SPLIT_FACTOR = 0.95f;
private static final float SLOW_SPLIT_FACTOR = 0.8f;
@@ -500,10 +512,6 @@ final class DisplayPortCalculator {
private static final float PREDICTION_VELOCITY_MULTIPLIER = 30.0f;
private static final float DANGER_ZONE_MULTIPLIER = 0.20f; // must be less than (SIZE_MULTIPLIER - 1.0f)
- DynamicResolutionStrategy(Map<String, Integer> prefs) {
- // ignore prefs for now
- }
-
public DisplayPortMetrics calculate(ImmutableViewportMetrics metrics, PointF velocity) {
float displayPortWidth = metrics.getWidth() * SIZE_MULTIPLIER;
float displayPortHeight = metrics.getHeight() * SIZE_MULTIPLIER;
@@ -655,9 +663,8 @@ final class DisplayPortCalculator {
private int mMinFramesToDraw; // minimum number of frames we take to draw
private int mMaxFramesToDraw; // maximum number of frames we take to draw
- PredictionBiasStrategy(Map<String, Integer> prefs) {
- //TODO remove static reference to context
- VELOCITY_THRESHOLD = LOKitShell.getDpi(LibreOfficeMainActivity.mAppContext) * getFloatPref(prefs, PREF_DISPLAYPORT_PB_VELOCITY_THRESHOLD, 16);
+ PredictionBiasStrategy(LibreOfficeMainActivity context, Map<String, Integer> prefs) {
+ VELOCITY_THRESHOLD = LOKitShell.getDpi(context) * getFloatPref(prefs, PREF_DISPLAYPORT_PB_VELOCITY_THRESHOLD, 16);
resetPageState();
}
diff --git a/android/source/src/java/org/mozilla/gecko/gfx/GeckoLayerClient.java b/android/source/src/java/org/mozilla/gecko/gfx/GeckoLayerClient.java
index 12c939690200..ad73d50f4c36 100644
--- a/android/source/src/java/org/mozilla/gecko/gfx/GeckoLayerClient.java
+++ b/android/source/src/java/org/mozilla/gecko/gfx/GeckoLayerClient.java
@@ -49,6 +49,7 @@ public class GeckoLayerClient implements PanZoomTarget {
private PanZoomController mPanZoomController;
private LayerView mView;
+ private final DisplayPortCalculator mDisplayPortCalculator;
public GeckoLayerClient(LibreOfficeMainActivity context) {
// we can fill these in with dummy values because they are always written
@@ -56,6 +57,7 @@ public class GeckoLayerClient implements PanZoomTarget {
mContext = context;
mScreenSize = new IntSize(0, 0);
mDisplayPort = new DisplayPortMetrics();
+ mDisplayPortCalculator = new DisplayPortCalculator(mContext);
mForceRedraw = true;
DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics();
@@ -112,7 +114,7 @@ public class GeckoLayerClient implements PanZoomTarget {
if (!mPanZoomController.getRedrawHint()) {
return false;
}
- return DisplayPortCalculator.aboutToCheckerboard(mViewportMetrics, mPanZoomController.getVelocityVector(), getDisplayPort());
+ return mDisplayPortCalculator.aboutToCheckerboard(mViewportMetrics, mPanZoomController.getVelocityVector(), getDisplayPort());
}
/**
@@ -175,7 +177,7 @@ public class GeckoLayerClient implements PanZoomTarget {
ImmutableViewportMetrics clampedMetrics = metrics.clamp();
if (displayPort == null) {
- displayPort = DisplayPortCalculator.calculate(metrics, mPanZoomController.getVelocityVector());
+ displayPort = mDisplayPortCalculator.calculate(metrics, mPanZoomController.getVelocityVector());
}
mDisplayPort = displayPort;
@@ -258,7 +260,7 @@ public class GeckoLayerClient implements PanZoomTarget {
// immediately request a draw of that area by setting the display port
// accordingly. This way we should have the content pre-rendered by the
// time the animation is done.
- DisplayPortMetrics displayPort = DisplayPortCalculator.calculate(viewport, null);
+ DisplayPortMetrics displayPort = mDisplayPortCalculator.calculate(viewport, null);
adjustViewport(displayPort);
}
}