- Easily implement the Steady Screen feature into any application, to counteract small device movements within the user interface.
-
Add the library as a dependency, e.g. in your
build.gradle
file:implementation 'io.github.sublimis.steadyscreen:steadyscreen-lib:2.0'
Make sure that
mavenCentral()
is included in your repositories list. -
Create a SteadyScreen instance:
SteadyScreen mSteadyScreen = new SteadyScreen(android.content.Context);
-
Start/stop receiving events for a View:
// Start receiving SteadyScreen events mSteadyScreen.attachView(android.view.View); // Stop receiving SteadyScreen events mSteadyScreen.releaseView(android.view.View);
(Optional) Enable/disable the SteadyScreen instance:
// Enable the SteadyScreen feature mSteadyScreen.setEnabled(true); // Disable the SteadyScreen feature mSteadyScreen.setEnabled(false); // Check the current enabled state mSteadyScreen.isEnabled();
(Optional) Call
mSteadyScreen.destroy()
to release all views and unbind the service when you finish. -
Install the free official Steady Screen service app.
-
Done!
This works with any View, including ViewGroup and various layouts.
If no SteadyScreen.attachView(android.view.View)
gets called or all views are released, the library is completely passive and does nothing.
The same is true when the official service app is not installed.
Follow the code in SteadyScreen.java and adapt if you need something more exotic.
Below is an example implementation in an Activity.
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import androidx.annotation.Nullable;
import io.github.sublimis.steadyscreen.SteadyScreen;
public class SteadyActivity extends Activity
{
protected SteadyScreen mSteadyScreen = null;
protected View mSteadyLayout = null;
@Override
protected void onCreate(@Nullable final Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
mSteadyScreen = new SteadyScreen(this);
mSteadyLayout = findViewById(R.id.steadyLayout);
}
@Override
protected void onStart()
{
super.onStart();
mSteadyScreen.attachView(mSteadyLayout);
}
@Override
protected void onStop()
{
super.onStop();
mSteadyScreen.releaseView(mSteadyLayout);
}
@Override
protected void onDestroy()
{
super.onDestroy();
mSteadyScreen.destroy();
}
}
Custom View can receive raw SteadyScreen service events by implementing the ISteadyView interface.