Ribbon: fetch and repaint at 1 Hz while the keyboard is visible; stops when it hides
This commit is contained in:
@@ -17,10 +17,13 @@ public final class HostGraph
|
||||
/** Payload series order. io leads: a stalled disk is the thing worth seeing. */
|
||||
public static final String[] SERIES = { "io", "cpu" };
|
||||
/** A sample older than this is not worth drawing as if it were now. */
|
||||
/** Safety net only: with the 1 Hz re-arm this never trips, but if fetches stop the ribbon
|
||||
blanks rather than freezing mid-thought. */
|
||||
public static final long MAX_AGE_MS = 15000L;
|
||||
private static final int CONNECT_TIMEOUT_MS = 2500;
|
||||
private static final int READ_TIMEOUT_MS = 2500;
|
||||
private static final long MIN_INTERVAL_MS = 2000L;
|
||||
/** Matches the server's 1 Hz sampling; only ever called while the keyboard is visible. */
|
||||
private static final long MIN_INTERVAL_MS = 900L;
|
||||
private static final int DEFAULT_N = 60;
|
||||
|
||||
private static final Object _lock = new Object();
|
||||
|
||||
@@ -35,6 +35,22 @@ import juloo.keyboard2.suggestions.Suggestions;
|
||||
public class Keyboard2 extends InputMethodService
|
||||
implements SharedPreferences.OnSharedPreferenceChangeListener
|
||||
{
|
||||
/** The ribbon follows the server's 1 Hz sampling, so it crawls instead of jumping. */
|
||||
private static final long HOST_GRAPH_REFRESH_MS = 1000L;
|
||||
|
||||
/** Re-armed only while the keyboard is on screen, so hiding it stops the polling dead. */
|
||||
private final Runnable _hostGraphRefresh = new Runnable()
|
||||
{
|
||||
public void run()
|
||||
{
|
||||
if (!_keyboard_layout_view.isShown())
|
||||
return;
|
||||
if (_config.usageGaugeEnabled)
|
||||
HostGraph.fetchIfNeeded(HostGraph.baseOf(_config.usageGaugeUrl), _config.usageGaugeToken,
|
||||
() -> _handler.post(() -> _keyboard_layout_view.invalidate()));
|
||||
_handler.postDelayed(this, HOST_GRAPH_REFRESH_MS);
|
||||
}
|
||||
};
|
||||
/** The view containing the keyboard and candidates view. */
|
||||
private ViewGroup _keyboard_container_view;
|
||||
private Keyboard2View _keyboard_layout_view;
|
||||
@@ -283,6 +299,8 @@ public class Keyboard2 extends InputMethodService
|
||||
if (_config.usageGaugeEnabled)
|
||||
HostGraph.fetchIfNeeded(HostGraph.baseOf(_config.usageGaugeUrl), _config.usageGaugeToken,
|
||||
() -> _handler.post(() -> _keyboard_layout_view.invalidate()));
|
||||
_handler.removeCallbacks(_hostGraphRefresh);
|
||||
_handler.postDelayed(_hostGraphRefresh, HOST_GRAPH_REFRESH_MS);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user