com.amazonaws.mobile.client.AWSMobileClient Java Examples

The following examples show how to use com.amazonaws.mobile.client.AWSMobileClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HTMobileClient.java    From live-app-android with MIT License 6 votes vote down vote up
public static TripsManager getTripsManager(Context context) {
    return TripsManager.getInstance(context, new AsyncTokenProvider() {
        @Override
        public void getAuthenticationToken(@NonNull final ResultHandler<String> resultHandler) {
            AWSMobileClient.getInstance().getTokens(new com.amazonaws.mobile.client.Callback<Tokens>() {
                @Override
                public void onResult(Tokens result) {
                    resultHandler.onResult(result.getIdToken().getTokenString());
                }

                @Override
                public void onError(Exception e) {
                    resultHandler.onError(e);
                }
            });
        }
    });
}
 
Example #2
Source File: MainActivity.java    From aws-mobile-simple-video-transcoding with Apache License 2.0 6 votes vote down vote up
/**
 * Called when Activity is created.
 *
 * @param savedInstanceState bundle for state if resuming
 */
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    final Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    final FloatingActionButton uploadButton = (FloatingActionButton) findViewById(R.id.uploadButton);
    uploadButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(final View view) {

            if (videoView != null) {
                videoView.pause();
            }

            recordVideo();
        }
    });

    AWSMobileClient.getInstance().initialize(this).execute();
    final IdentityManager identityManager = IdentityManager.getDefaultIdentityManager();
    identityManager.getUserID(this);
}
 
Example #3
Source File: HTMobileClient.java    From live-app-android with MIT License 6 votes vote down vote up
public void signIn(final String email, final String password, @NonNull final Callback callback) {
    AWSMobileClient.getInstance().signIn(email, password, null, new InnerCallback<SignInResult>(callback) {

        @Override
        public void onResult(SignInResult result) {
            updatePublishableKey(callback);
        }

        @Override
        public void onError(Exception e) {
            super.onError(e);
            signUpEmail = email;
            signUpPassword = password;
        }
    });
}
 
Example #4
Source File: MainActivity.java    From VyAPI with MIT License 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    Toolbar toolbar = findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    DrawerLayout drawer = findViewById(R.id.drawer_layout);
    NavigationView navigationView = findViewById(R.id.nav_view);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
            this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
    drawer.addDrawerListener(toggle);
    toggle.syncState();
    navigationView.setNavigationItemSelectedListener(this);

    // Set Default Fragment
    getSupportFragmentManager().beginTransaction().replace(R.id.fragment_container, new HomeFragment()).commit();

    // Get an instance of ContactViewModel
    contactViewModel = new ViewModelProvider(this).get(ContactViewModel.class);

    // Reference to Adapter
    final ContactAdapter adapter = new ContactAdapter();

    Toast.makeText(this, "Welcome " + AWSMobileClient.getInstance().getUsername() + "!", Toast.LENGTH_LONG).show();

    //Allowing Strict mode policy for Nougat support
    StrictMode.VmPolicy.Builder builder = new StrictMode.VmPolicy.Builder();
    StrictMode.setVmPolicy(builder.build());
}
 
Example #5
Source File: Authentication.java    From VyAPI with MIT License 5 votes vote down vote up
private void showSignIn() {

        ListSupportedAlgorithms();

        try {
            AWSMobileClient.getInstance().showSignIn(this, SignInUIOptions.builder()
                    .nextActivity(MainActivity.class)
                    .logo(R.drawable.vyapi_elevated_black_fg_round_bg_transparent)
                    .backgroundColor(Color.rgb(0, 138, 198))
                    .build());
        } catch (Exception e) {
            Log.e(TAG, e.toString());
        }
    }
 
Example #6
Source File: AuthenticatorActivity.java    From amazon-freertos-ble-android-sdk with Apache License 2.0 5 votes vote down vote up
private void signinsuccessful() {
    try {
        AWSCredentialsProvider credentialsProvider = AWSMobileClient.getInstance();
        AWSIotClient awsIotClient = new AWSIotClient(credentialsProvider);
        awsIotClient.setRegion(Region.getRegion(DemoConstants.AWS_IOT_REGION));

        AttachPolicyRequest attachPolicyRequest = new AttachPolicyRequest()
                .withPolicyName(DemoConstants.AWS_IOT_POLICY_NAME)
                .withTarget(AWSMobileClient.getInstance().getIdentityId());
        awsIotClient.attachPolicy(attachPolicyRequest);
        Log.i(TAG, "Iot policy attached successfully.");
    } catch (Exception e) {
        Log.e(TAG, "Exception caught: ", e);
    }
}
 
Example #7
Source File: DeviceScanFragment.java    From amazon-freertos-ble-android-sdk with Apache License 2.0 5 votes vote down vote up
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
        case R.id.logout:
            AWSMobileClient.getInstance().signOut();
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}
 
Example #8
Source File: HTMobileClient.java    From live-app-android with MIT License 5 votes vote down vote up
public void initialize(@NonNull final Callback callback) {
    AWSMobileClient.getInstance().initialize(mContext, new InnerCallback<UserStateDetails>(callback) {
        @Override
        public void onResult(UserStateDetails userStateDetails) {
            onSuccessHidden(HTMobileClient.this);
        }
    });
}
 
Example #9
Source File: HTMobileClient.java    From live-app-android with MIT License 5 votes vote down vote up
public void signUp(final String email, final String password, Map<String, String> attributes, @NonNull final Callback callback) {
    AWSMobileClient.getInstance().signUp(email, password, attributes, null, new InnerCallback<SignUpResult>(callback) {
        @Override
        public void onResult(SignUpResult result) {
            signUpEmail = email;
            signUpPassword = password;
            onSuccessHidden(HTMobileClient.this);
        }
    });
}
 
Example #10
Source File: HTMobileClient.java    From live-app-android with MIT License 5 votes vote down vote up
public void resendSignUp(@NonNull final Callback callback) {
    if (!TextUtils.isEmpty(signUpEmail)) {
        AWSMobileClient.getInstance().resendSignUp(signUpEmail, new InnerCallback<SignUpResult>(callback) {
            @Override
            public void onResult(SignUpResult result) {
                onSuccessHidden(HTMobileClient.this);
            }
        });
    }
}
 
Example #11
Source File: HTMobileClient.java    From live-app-android with MIT License 5 votes vote down vote up
public void confirmSignIn(@NonNull final Callback callback) {
    AWSMobileClient.getInstance().signIn(signUpEmail, signUpPassword, null, new InnerCallback<SignInResult>(callback) {

        @Override
        public void onResult(SignInResult result) {
            updatePublishableKey(callback);
        }
    });

}
 
Example #12
Source File: AuthenticatorActivity.java    From aws-mobile-simple-video-transcoding with Apache License 2.0 5 votes vote down vote up
@Override
protected void onCreate(final Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_authenticator);

    AWSMobileClient.getInstance().initialize(this, new AWSStartupHandler() {
        @Override
        public void onComplete(final AWSStartupResult awsStartupResult) {
            SignInUI signin = (SignInUI) AWSMobileClient.getInstance().getClient(AuthenticatorActivity.this, SignInUI.class);
            signin.login(AuthenticatorActivity.this, MainActivity.class).execute();
        }
    }).execute();
}
 
Example #13
Source File: AWSService.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
void signIn() {
    LOGGER.log(Level.INFO, "Sign in or resume");
    SignInUI signin = (SignInUI) AWSMobileClient.getInstance().getClient(SignInUI.class);
    signin.login(HOME_VIEW, AwsMobileHub.SIGNED_VIEW).execute();
}
 
Example #14
Source File: AWSService.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
AWSService() {
    LOGGER.log(Level.INFO, "[GLUONAWS] Reading AWSConfiguration");
    try {
        awsConfiguration = new AWSConfiguration();
    } catch (Exception e) {
        LOGGER.log(Level.SEVERE, "Missing awsconfiguration.json file under /src/main/resources");
    }
    
    signedIn = false;
    AWSMobileClient.getInstance().initialize(awsStartupResult -> {
        LOGGER.log(Level.INFO, "[GLUONAWS] AWSMobileClient is instantiated and you are connected to AWS!");
        
        // Obtain the reference to the AWSCredentialsProvider and AWSConfiguration objects
        AWSCredentialsProvider credentialsProvider = AWSMobileClient.getInstance().getCredentialsProvider();
        AWSConfiguration configuration = AWSMobileClient.getInstance().getConfiguration();

        LOGGER.log(Level.INFO, "[GLUONAWS] credentials:");
        // Use IdentityManager#getUserID to fetch the identity id.
        IdentityManager.getDefaultIdentityManager().getUserID(new IdentityHandler() {
            @Override
            public void onIdentityId(String identityId) {
                LOGGER.log(Level.INFO, "[GLUONAWS] Identity ID = " + identityId);

                // Use IdentityManager#getCachedUserID to
                //  fetch the locally cached identity id.
                final String cachedIdentityId = IdentityManager.getDefaultIdentityManager().getCachedUserID();
                LOGGER.log(Level.INFO, "[GLUONAWS] cachedIdentityId " + cachedIdentityId);
            }

            @Override
            public void handleError(Exception exception) {
                LOGGER.log(Level.INFO, "[GLUONAWS] Error in retrieving the identity" + exception);
                MobileApplication.getInstance().switchView(AwsMobileHub.SIGNED_OUT_VIEW, ViewStackPolicy.SKIP);
            }
        });
        IdentityManager.getDefaultIdentityManager().addSignInStateChangeListener(new SignInStateChangeListener() {
            @Override
            public void onUserSignedIn() {
                LOGGER.log(Level.INFO, "[GLUONAWS] User signed in");
                signedIn = true;
            }

            @Override
            public void onUserSignedOut() {
                LOGGER.log(Level.INFO, "[GLUONAWS] User signed out");
                signedIn = false;
                Platform.runLater(() -> MobileApplication.getInstance().switchView(AwsMobileHub.SIGNED_OUT_VIEW, ViewStackPolicy.SKIP));
            }
        });
        signIn();
    }).execute();
}
 
Example #15
Source File: HTMobileClient.java    From live-app-android with MIT License 4 votes vote down vote up
public boolean isAuthorized() {
    return AWSMobileClient.getInstance().isSignedIn();
}
 
Example #16
Source File: DeviceScanFragment.java    From amazon-freertos-ble-android-sdk with Apache License 2.0 4 votes vote down vote up
public void bind(BleDevice bleDevice) {
    mBleDevice = bleDevice;
    mBleDeviceNameTextView.setText(mBleDevice.getName());
    mBleDeviceMacTextView.setText(mBleDevice.getMacAddr());
    mBleDeviceSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener(){
        AmazonFreeRTOSDevice aDevice = null;
        boolean autoReconnect = true;
        @Override
        public void onCheckedChanged(CompoundButton v, boolean isChecked) {
            Log.i(TAG, "Connect switch isChecked: " + (isChecked ? "ON":"OFF"));
            if (isChecked) {
                if (aDevice == null) {
                    AWSCredentialsProvider credentialsProvider = AWSMobileClient.getInstance();

                    aDevice = mAmazonFreeRTOSManager.connectToDevice(mBleDevice.getBluetoothDevice(),
                            connectionStatusCallback, credentialsProvider, autoReconnect);
                }
            } else {
                if (userDisconnect || !autoReconnect) {
                    if (aDevice != null) {
                        mAmazonFreeRTOSManager.disconnectFromDevice(aDevice);
                        aDevice = null;
                    }
                } else {
                    userDisconnect = true;
                }
                resetUI();
            }
        }
    });

    mMenuTextView.setOnClickListener(new View.OnClickListener(){
        @Override
        public void onClick(View view) {
            Log.i(TAG, "Click menu.");
            PopupMenu popup = new PopupMenu(getContext(), mMenuTextView);
            popup.inflate(R.menu.options_menu);
            popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
                @Override
                public boolean onMenuItemClick(MenuItem item) {
                    switch (item.getItemId()) {
                        case R.id.wifi_provisioning_menu_id:
                            Intent intentToStartWifiProvision
                                    = WifiProvisionActivity.newIntent(getActivity(), mBleDevice.getMacAddr());
                            startActivity(intentToStartWifiProvision);
                            return true;
                        case R.id.mqtt_proxy_menu_id:
                            Toast.makeText(getContext(),"Already signed in",Toast.LENGTH_SHORT).show();
                            return true;
                    }
                    return false;
                }
            });
            popup.show();
        }
    });

    resetUI();
}
 
Example #17
Source File: MainActivity.java    From VyAPI with MIT License 4 votes vote down vote up
public void signOut(){
    AWSMobileClient.getInstance().signOut();
    Intent intent = new Intent(this, Authentication.class);
    startActivity(intent);
}