Example usage for android.os RemoteCallback RemoteCallback

List of usage examples for android.os RemoteCallback RemoteCallback

Introduction

In this page you can find the example usage for android.os RemoteCallback RemoteCallback.

Prototype

RemoteCallback(Parcel parcel) 

Source Link

Usage

From source file:uk.ac.hutton.ics.buntata.activity.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    ButterKnife.bind(this);

    /* Make sure the default preferences are set */
    PreferenceUtils.setDefaults(this);
    NodeManager.clearCaches();/*from   w w  w.  j a v  a  2  s  .c o  m*/
    DatasourceService.init(this);

    /* Initialize the internal database for track history keeping */
    new LogEntryManager(this).initializeDatabase();

    DatasourceService.getAllAdvanced(this, false, false,
            new RemoteCallback<List<BuntataDatasourceAdvanced>>(this) {
                @Override
                public void onSuccess(List<BuntataDatasourceAdvanced> result) {
                    boolean updateAvailable = false;

                    for (BuntataDatasourceAdvanced adv : result) {
                        updateAvailable = adv
                                .getState() == BuntataDatasourceAdvanced.InstallState.INSTALLED_HAS_UPDATE;

                        if (updateAvailable)
                            break;
                    }

                    long timeSince = System.currentTimeMillis() - lastUpdateCheck;

                    /* Only check for updates if it has been at least 2 hours */
                    if (updateAvailable && timeSince > 1000 * 60 * 60 * 2) {
                        /* Show a Snackbar with a button to open the datasource activity */
                        int textColor = ContextCompat.getColor(MainActivity.this,
                                android.R.color.primary_text_dark);
                        SnackbarUtils.create(getSnackbarParentView(), R.string.snackbar_updates_available,
                                textColor, ContextCompat.getColor(MainActivity.this, R.color.colorPrimaryDark),
                                5000).setAction(R.string.generic_show, new View.OnClickListener() {
                                    @Override
                                    public void onClick(View v) {
                                        startActivityForResult(
                                                new Intent(getApplicationContext(), DatasourceActivity.class),
                                                REQUEST_DATA_SOURCE);
                                    }
                                }).setActionTextColor(textColor).show();

                        lastUpdateCheck = System.currentTimeMillis();
                    }
                }
            });
}

From source file:uk.ac.hutton.ics.buntata.fragment.DatasourceFragment.java

private void requestData() {
    final boolean cancelable = getActivity() instanceof DatasourceActivity;

    final List<BuntataDatasourceAdvanced> datasources = new ArrayList<>();

    /* Set it initially */
    adapter = new DatasourceAdapter(getActivity(), recyclerView, datasources);
    recyclerView.setAdapter(adapter);//  w w w  .  j a  v  a  2 s.c o m

    DatasourceService.getAllAdvanced(getActivity(), cancelable, true,
            new RemoteCallback<List<BuntataDatasourceAdvanced>>(getActivity()) {
                @Override
                public void onSuccess(List<BuntataDatasourceAdvanced> result) {
                    if (result.size() < 1) {
                        layout.setVisibility(View.VISIBLE);
                    } else {
                        layout.setVisibility(View.GONE);

                        adapter = new DatasourceAdapter(getActivity(), recyclerView, result);
                        recyclerView.setAdapter(adapter);
                    }
                }
            });
}