Skip to content

Programming in Android

landawn edited this page May 1, 2018 · 5 revisions

Below features are supported for Android.

The coming version Android studio is going to support Java 8 features. The Stream API provided in AbacusUtil mostly is consistent with the Stream API in JDK 8. It's very easy to replace with each other. The implementation of Stream API in AbacusUtil is pretty straight forward. In a lot of scenarios, it's even faster than the implementation in JDK 8. Besides int, long, double, other primitive types: boolean, char, byte, short, float are also supported by the Stream API in AbacusUtil. Additionally, a lot of methods(e.g. forEach, filter...) in N are also designed to support functional programming...Enjoying Note: I tested on Android Studio 2.1 RC. and found couple of issues: 1), Instant run is not supported. 2), slow, 3), unable to show the variable value in debug. So maybe it's better to stay with Retrolambda before new Java 8 features become stable.

  • Switch smoothly between UI and background threads by the fluent execute/callback APIs in CompletableFuture
TPExecutor.execute(() -> {
    return accountService.createAccount(signUpRequest);
}).thenRunOnUI((signUpResp, signUpError) -> {
    signInButton.setText("SIGN UP");
    ProgressBarTask.finish();

    if (Fu.check(signUpResp)) {
        final LoginRequest signInRequest = new LoginRequest().setAccessToken(accessToken).setLoginId(signUpRequest.getEmailAddress())
            .setLoginPassword(signUpRequest.getPassword());

        TPExecutor.execute(() -> {
            return accountService.login(signInRequest);
        }).thenRunOnUI((signInResp, signInError) -> {
            if (Fu.check(signInResp)) {
                final Account account = signInResp.getAccount();
                Settings.setUserId(account.getId());
                Settings.setUserName(account.getFullName());
                Settings.setRWSUserAccessToken(signInResp.getUserAccessToken());

                final Intent intent = new Intent();
                intent.putExtra(Fu.USER_ACCESS_TOKEN, signInResp.getUserAccessToken());
                setResult(RESULT_OK, intent);
            } else {
                startActivity(new Intent(this, SignInActivity.class));
            }

            finish();
        });
    } else {
        if (signUpResp != null) {
            if (signUpResp.getRespCode() == ResponseCode.LOGIN_ID_NOT_AVAILABLE) {
                Fu.showToast("Email address: " + email + " has been used. Please try with another one or go to sign in page to login " +
                    "directly");
            } else {
                Fu.showToast("Unable to create account due to", signUpResp);
            }
        } else {
            Fu.showToast("Unable to create account due to network or system error.");
        }
    }
});