Customize loading view
Loading is a common interaction in Griver AppContainer. In Griver, the following situations may trigger the loading interaction.
showLoading
startup parameter is set to betrue
.showLoading
API is called from a web app or mini program.
The default loading in Griver is shown in the following picture.
Customization guide
The loading view can be customized by GriverLoadingViewExtension
that Griver provides.
copy
public interface GriverLoadingViewExtension extends GriverExtension {
/**
* Show the loading view
*
* @param context The context of the loading view
* @param text The loading text
* @param cancelable Whether the loading view can be canceled,
* true means the loading view can be canceled by clicking back button or blank area,
* false means the loading view cna not be canceled by user behaviors
*/
void show(Context context, String text, boolean cancelable);
/**
* Dismiss the loading view
*/
void dismiss();
/**
* Whether intercept the back press event,
* when this happens, if the loading view is showing, should dismiss the loading view and return true
*
* otherwise, return false directly
* @return true will intercept the back press event to avoid to exit page, false will not intercept the exit flow
*/
boolean onBackPressed();
}
Implement the interface and register it to Griver, then Griver will use the customized loading view.
Sample code
A customized extension is shown in the following code.
copy
public class CustomLoadingExtension implements GriverLoadingViewExtension {
Dialog loading;
@Override
public void show(Context context, String text, boolean cancelable) {
if (loading == null) {
loading = new AlertDialog.Builder(context).setTitle("loading").setMessage(text)
.setCancelable(cancelable).create();
}
loading.show();
}
@Override
public void dismiss() {
if (loading != null) {
loading.dismiss();
loading = null;
}
}
@Override
public boolean onBackPressed() {
if (loading != null && loading.isShowing()) {
dismiss();
return true;
}
return false;
}
}
Then register the extension to Griver.
copy
Griver.registerExtension(new GriverExtensionManifest(GriverLoadingViewExtension.class, new CustomLoadingExtension()));