diff --git a/core-android/src/main/java/com/uber/sdk/android/core/auth/LoginActivity.java b/core-android/src/main/java/com/uber/sdk/android/core/auth/LoginActivity.java index 3c1553ce..0d6d6b20 100644 --- a/core-android/src/main/java/com/uber/sdk/android/core/auth/LoginActivity.java +++ b/core-android/src/main/java/com/uber/sdk/android/core/auth/LoginActivity.java @@ -117,6 +117,27 @@ public static Intent newIntent( return newIntent(context, new ArrayList(), sessionConfiguration, responseType, forceWebview, false, false); } + /** + * Create an {@link Intent} to pass to this activity + * + * @param context the {@link Context} for the intent + * @param sessionConfiguration to be used for gather clientId + * @param responseType that is expected + * @param forceWebview Forced to use old webview instead of chrometabs + * @return an intent that can be passed to this activity + */ + @NonNull + public static Intent newIntent( + @NonNull Context context, + @NonNull ArrayList productPriority, + @NonNull SessionConfiguration sessionConfiguration, + @NonNull ResponseType responseType, + boolean forceWebview) { + + return newIntent(context, productPriority, sessionConfiguration, responseType, forceWebview, false, false); + } + + /** * Create an {@link Intent} to pass to this activity * diff --git a/core-android/src/main/java/com/uber/sdk/android/core/auth/LoginManager.java b/core-android/src/main/java/com/uber/sdk/android/core/auth/LoginManager.java index e495928b..6aca93c1 100644 --- a/core-android/src/main/java/com/uber/sdk/android/core/auth/LoginManager.java +++ b/core-android/src/main/java/com/uber/sdk/android/core/auth/LoginManager.java @@ -207,7 +207,7 @@ public void loginForImplicitGrant(@NonNull Activity activity) { return; } - Intent intent = LoginActivity.newIntent(activity, sessionConfiguration, + Intent intent = LoginActivity.newIntent(activity, productFlowPriority, sessionConfiguration, ResponseType.TOKEN, legacyUriRedirectHandler.isLegacyMode()); activity.startActivityForResult(intent, requestCode); } @@ -222,7 +222,7 @@ public void loginForAuthorizationCode(@NonNull Activity activity) { return; } - Intent intent = LoginActivity.newIntent(activity, sessionConfiguration, + Intent intent = LoginActivity.newIntent(activity, productFlowPriority, sessionConfiguration, ResponseType.CODE, legacyUriRedirectHandler.isLegacyMode()); activity.startActivityForResult(intent, requestCode); } @@ -240,7 +240,7 @@ private void loginForImplicitGrantWithFallback(@NonNull Activity activity) { Intent intent = LoginActivity.newIntent( activity, - new ArrayList(), + productFlowPriority, sessionConfiguration, ResponseType.TOKEN, legacyUriRedirectHandler.isLegacyMode(), diff --git a/core-android/src/main/res/layout/ub__login_view.xml b/core-android/src/main/res/layout/ub__login_view.xml deleted file mode 100644 index 1d019c0e..00000000 --- a/core-android/src/main/res/layout/ub__login_view.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - diff --git a/core-android/src/main/res/values/dimens.xml b/core-android/src/main/res/values/dimens.xml index 121acb14..8498eccf 100644 --- a/core-android/src/main/res/values/dimens.xml +++ b/core-android/src/main/res/values/dimens.xml @@ -23,9 +23,7 @@ 20sp 14sp - 12sp 16dp 8dp - 48dp diff --git a/core-android/src/test/java/com/uber/sdk/android/core/UberButtonTest.java b/core-android/src/test/java/com/uber/sdk/android/core/UberButtonTest.java index 7ba06cfc..8c9f8f18 100644 --- a/core-android/src/test/java/com/uber/sdk/android/core/UberButtonTest.java +++ b/core-android/src/test/java/com/uber/sdk/android/core/UberButtonTest.java @@ -51,7 +51,6 @@ public class UberButtonTest extends RobolectricTestBase { private static final String ANDROID_COLOR_BLACK = "@android:color/black"; private static final String ANDROID_COLOR_WHITE = "@android:color/white"; - private static final String DRAWABLE_UBER_BADGE = "@drawable/uber_badge"; private static final String GRAVITY_END = "end"; private static final String STYLE_ITALIC = "italic"; private static final String ONE_SP = "1sp"; @@ -60,8 +59,6 @@ public class UberButtonTest extends RobolectricTestBase { private static final String FOUR_SP = "4sp"; private static final String TEXT = "test"; - private static final String UBER_PACKAGE_NAME = "com.uber.sdk.android.core"; - private Context context; @Before @@ -81,19 +78,10 @@ public void onCreate_whenBackgroundAttributeSet_shouldSetBackground() { @Test public void onCreate_whenCompoundDrawablesAndPaddingSet_shouldSetCompoundDrawableAttributes() { AttributeSet attributeSet = Robolectric.buildAttributeSet() - .addAttribute(android.R.attr.drawableLeft, DRAWABLE_UBER_BADGE) - .addAttribute(android.R.attr.drawableTop, DRAWABLE_UBER_BADGE) - .addAttribute(android.R.attr.drawableRight, DRAWABLE_UBER_BADGE) - .addAttribute(android.R.attr.drawableBottom, DRAWABLE_UBER_BADGE) .addAttribute(android.R.attr.drawablePadding, ONE_SP) .build(); UberButton uberButton = new UberButton(context, attributeSet, 0, 0) { }; - Drawable[] drawables = uberButton.getCompoundDrawables(); - assertNotNull(drawables[0]); - assertNotNull(drawables[1]); - assertNotNull(drawables[2]); - assertNotNull(drawables[3]); assertEquals(1, uberButton.getCompoundDrawablePadding()); } diff --git a/rides-android/src/main/AndroidManifest.xml b/rides-android/src/main/AndroidManifest.xml index 33c1f5fa..03c26b5f 100644 --- a/rides-android/src/main/AndroidManifest.xml +++ b/rides-android/src/main/AndroidManifest.xml @@ -27,8 +27,5 @@ - diff --git a/rides-android/src/main/java/com/uber/sdk/android/rides/RequestDeeplink.java b/rides-android/src/main/java/com/uber/sdk/android/rides/RequestDeeplink.java deleted file mode 100644 index 03da7bd1..00000000 --- a/rides-android/src/main/java/com/uber/sdk/android/rides/RequestDeeplink.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Copyright (c) 2016 Uber Technologies, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package com.uber.sdk.android.rides; - -import android.content.Context; -import android.net.Uri; -import android.support.annotation.NonNull; - -import com.uber.sdk.android.core.utils.AppProtocol; -import com.uber.sdk.android.core.utils.CustomTabsHelper; - -/** - * @Deprecated use {@link RideRequestDeeplink} directly - */ -@Deprecated -public class RequestDeeplink extends RideRequestDeeplink { - - RequestDeeplink( - @NonNull Context context, - @NonNull Uri uri, - @NonNull AppProtocol appProtocol, - @NonNull CustomTabsHelper customTabsHelper) { - super(context, uri, appProtocol, customTabsHelper); - } -} diff --git a/rides-android/src/main/java/com/uber/sdk/android/rides/RequestDeeplinkBehavior.java b/rides-android/src/main/java/com/uber/sdk/android/rides/RequestDeeplinkBehavior.java deleted file mode 100644 index 72a1baa4..00000000 --- a/rides-android/src/main/java/com/uber/sdk/android/rides/RequestDeeplinkBehavior.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (c) 2016 Uber Technologies, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package com.uber.sdk.android.rides; - -import android.content.Context; -import android.support.annotation.NonNull; - -import com.uber.sdk.android.core.UberSdk; -import com.uber.sdk.core.client.SessionConfiguration; - -/** - * The {@link RideRequestBehavior} to pass to the {@link RideRequestButton} to have it execute a {@link RideRequestDeeplink}. - */ -@Deprecated -public class RequestDeeplinkBehavior implements RideRequestBehavior { - - final SessionConfiguration sessionConfiguration; - - /** - * Create a {@link RequestDeeplinkBehavior} using the default {@link SessionConfiguration} from {@link UberSdk} - */ - public RequestDeeplinkBehavior() { - this.sessionConfiguration = UberSdk.getDefaultSessionConfiguration(); - } - - /** - * Create a {@link RequestDeeplinkBehavior} with required {@link SessionConfiguration} - * @param configuration to use for signing with Client Id - */ - public RequestDeeplinkBehavior(@NonNull SessionConfiguration configuration) { - this.sessionConfiguration = configuration; - } - - /** - * Requests a ride using a {@link RideRequestDeeplink} that is constructed using the provided {@link RideParameters}. - * - * @param context {@link Context} to pass to launch the {@link RideRequestDeeplink} from - * @param params the {@link RideParameters} to use for building and executing the {@link RideRequestDeeplink} - */ - @Override - public void requestRide(@NonNull Context context, @NonNull RideParameters params) { - RideRequestDeeplink deeplink = new RideRequestDeeplink.Builder(context) - .setSessionConfiguration(sessionConfiguration) - .setRideParameters(params).build(); - deeplink.execute(); - } -} diff --git a/rides-android/src/main/java/com/uber/sdk/android/rides/RideRequestActivity.java b/rides-android/src/main/java/com/uber/sdk/android/rides/RideRequestActivity.java deleted file mode 100644 index 8964c311..00000000 --- a/rides-android/src/main/java/com/uber/sdk/android/rides/RideRequestActivity.java +++ /dev/null @@ -1,338 +0,0 @@ -/* - * Copyright (c) 2016 Uber Technologies, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package com.uber.sdk.android.rides; - -import android.Manifest; -import android.app.Activity; -import android.app.AlertDialog; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.content.pm.PackageManager; -import android.os.Bundle; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.annotation.StringRes; -import android.support.annotation.VisibleForTesting; -import android.support.v4.app.ActivityCompat; -import android.support.v4.content.ContextCompat; - -import com.uber.sdk.android.core.auth.AccessTokenManager; -import com.uber.sdk.android.core.auth.AuthenticationError; -import com.uber.sdk.android.core.auth.LoginCallback; -import com.uber.sdk.android.core.auth.LoginManager; -import com.uber.sdk.core.auth.AccessToken; -import com.uber.sdk.core.auth.AccessTokenStorage; -import com.uber.sdk.core.auth.Scope; -import com.uber.sdk.core.client.AccessTokenSession; -import com.uber.sdk.core.client.SessionConfiguration; - -import java.util.Arrays; - -/** - * The {@link RideRequestActivity} provides the entire flow to have a user authorize with their Uber account - * and display the {@link RideRequestView} once authorized in one activity. - */ -public class RideRequestActivity extends Activity implements LoginCallback, RideRequestViewCallback { - - /** - * Key for a {@link AuthenticationError} to be passed back to the calling activity. - */ - public static final String AUTHENTICATION_ERROR = "authentication_error"; - - /** - * Key for a {@link RideRequestViewError} to be passed back to the calling activity. - */ - public static final String RIDE_REQUEST_ERROR = "ride_request_error"; - - @VisibleForTesting - static final int LOGIN_REQUEST_CODE = 1112; - - private static final int REQUEST_FINE_LOCATION_PERMISSION_CODE = 1002; - private static final String USER_AGENT_RIDE_WIDGET = String.format("rides-android-v%s-ride_request_widget", - BuildConfig.VERSION_NAME); - - @VisibleForTesting static final String RIDE_PARAMETERS = "ride_parameters"; - static final String EXTRA_LOGIN_CONFIGURATION = "login_configuration"; - static final String EXTRA_ACCESS_TOKEN_STORAGE_KEY = "access_token_storage_key"; - - @VisibleForTesting AccessTokenStorage accessTokenStorage; - @Nullable @VisibleForTesting AlertDialog authenticationErrorDialog; - @Nullable @VisibleForTesting AlertDialog rideRequestErrorDialog; - @VisibleForTesting RideRequestView rideRequestView; - @VisibleForTesting LoginManager loginManager; - SessionConfiguration sessionConfiguration; - - /** - * Creates a new {@link Intent} to be passed in to this activity with all the required information. - * - * @param context the {@link Context} that will be launching this activity - * @param rideParameters the optional {@link RideParameters} containing information to populate the {@link RideRequestView} - * @param loginConfiguration required when RideRequestActivity needs to start authentication flow - * @param accessTokenStorageKey optional key to lookup access token from {@link com.uber.sdk.core.auth.AccessTokenStorage} - * @return new {@link Intent} with the necessary parameters for this activity - */ - @NonNull - public static Intent newIntent(@NonNull Context context, - @Nullable RideParameters rideParameters, - @NonNull SessionConfiguration loginConfiguration, - @Nullable String accessTokenStorageKey) { - Intent data = new Intent(context, RideRequestActivity.class); - - if (rideParameters == null) { - rideParameters = new RideParameters.Builder().build(); - } - - data.putExtra(RIDE_PARAMETERS, rideParameters); - data.putExtra(EXTRA_LOGIN_CONFIGURATION, loginConfiguration); - data.putExtra(EXTRA_ACCESS_TOKEN_STORAGE_KEY, accessTokenStorageKey); - return data; - } - - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - - setContentView(R.layout.ub__ride_request_activity); - - String accessTokenStorageKey = getIntent() - .getExtras() - .getString(EXTRA_ACCESS_TOKEN_STORAGE_KEY, AccessTokenManager.ACCESS_TOKEN_DEFAULT_KEY); - - rideRequestView = (RideRequestView) findViewById(R.id.ub__ride_request_view); - accessTokenStorage = new AccessTokenManager(this, accessTokenStorageKey); - - RideParameters rideParameters = getIntent().getParcelableExtra(RIDE_PARAMETERS); - if (rideParameters == null) { - rideParameters = new RideParameters.Builder().build(); - } - - if (rideParameters.getUserAgent() == null) { - rideParameters.setUserAgent(USER_AGENT_RIDE_WIDGET); - } - - SessionConfiguration loginConfiguration = (SessionConfiguration) getIntent().getSerializableExtra(EXTRA_LOGIN_CONFIGURATION); - sessionConfiguration = loginConfiguration - .newBuilder() - .setScopes(Arrays.asList(Scope.RIDE_WIDGETS)) - .build(); - - loginManager = new LoginManager(accessTokenStorage, this, sessionConfiguration, LOGIN_REQUEST_CODE); - rideRequestView.setRideParameters(rideParameters); - rideRequestView.setRideRequestViewCallback(this); - - int permissionCheck = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION); - if (permissionCheck != PackageManager.PERMISSION_GRANTED) { - ActivityCompat.requestPermissions(this, new String[] {Manifest.permission.ACCESS_FINE_LOCATION}, - REQUEST_FINE_LOCATION_PERMISSION_CODE); - } else { - load(); - } - } - - @Override - protected void onActivityResult(int requestCode, int resultCode, Intent data) { - super.onActivityResult(requestCode, resultCode, data); - - if (requestCode == LOGIN_REQUEST_CODE) { - loginManager.onActivityResult(this, requestCode, resultCode, data); - } - } - - @Override - public void onErrorReceived(@NonNull RideRequestViewError error) { - rideRequestView.cancelLoad(); - Intent data = new Intent(); - data.putExtra(RIDE_REQUEST_ERROR, error); - switch (error) { - case CONNECTIVITY_ISSUE: - rideRequestErrorDialog = buildRetryAlert( - R.string.ub__ride_request_activity_widget_error, - R.string.ub__ride_error_try_again, - android.R.string.cancel, - data); - rideRequestErrorDialog.show(); - break; - case NO_ACCESS_TOKEN: - case UNAUTHORIZED: - accessTokenStorage.removeAccessToken(); - login(); - break; - default: - rideRequestErrorDialog = buildErrorAlert(R.string.ub__ride_request_activity_widget_error, - android.R.string.ok, - data); - rideRequestErrorDialog.show(); - } - } - - @Override - public void onLoginCancel() { - setResult(RESULT_CANCELED, null); - finish(); - } - - @Override - public void onLoginError(@NonNull AuthenticationError error) { - Intent data = new Intent(); - data.putExtra(AUTHENTICATION_ERROR, error); - if (AuthenticationError.CONNECTIVITY_ISSUE.equals(error)) { - authenticationErrorDialog = buildRetryAlert( - R.string.ub__ride_request_activity_authentication_error, - R.string.ub__ride_error_try_again, - android.R.string.cancel, - data); - } else { - authenticationErrorDialog = buildErrorAlert( - R.string.ub__ride_request_activity_authentication_error, - android.R.string.ok, - data); - } - authenticationErrorDialog.show(); - } - - @Override - public void onLoginSuccess(@NonNull AccessToken accessToken) { - accessTokenStorage.setAccessToken(accessToken); - load(); - } - - @Override - public void onAuthorizationCodeReceived(@NonNull String authorizationCode) { - //This code should be unreachable, as we request for implicit grant. - final Intent error = new Intent().putExtra(AUTHENTICATION_ERROR, AuthenticationError.INVALID_FLOW_ERROR); - authenticationErrorDialog = buildErrorAlert(R.string.ub__ride_request_activity_authentication_error, - android.R.string.ok, error); - } - - @Override - public void onRequestPermissionsResult( - int requestCode, - @NonNull String[] permissions, - @NonNull int[] grantResults) { - if (requestCode == REQUEST_FINE_LOCATION_PERMISSION_CODE) { - load(); - } - } - - /** - * Loads the appropriate view in the activity based on whether user is successfully authorized or not. - */ - private void load() { - AccessToken accessToken = accessTokenStorage.getAccessToken(); - - if (accessToken != null) { - AccessTokenSession session = new AccessTokenSession(sessionConfiguration, - accessTokenStorage); - rideRequestView.setSession(session); - - loadRideRequestView(); - } else { - login(); - } - } - - private void login() { - loginManager.login(this); - } - - /** - * Loads the {@link RideRequestView}. - */ - private void loadRideRequestView() { - rideRequestView.load(); - } - - /** - * Builds an {@link AlertDialog} to the user to indicate an error and dismisses activity. - * - * @param messageTextId the message content {@link StringRes} text ID - * @param positiveButtonTextId the positive button {@link StringRes} text ID - * @param intent the {@link Intent} to pass in the result - * @return an {@link AlertDialog} to show - */ - @NonNull - private AlertDialog buildErrorAlert( - @StringRes int messageTextId, - @StringRes int positiveButtonTextId, - final Intent intent) { - return new AlertDialog.Builder(this) - .setMessage(messageTextId) - .setPositiveButton(positiveButtonTextId, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - setResult(RESULT_CANCELED, intent); - finish(); - } - }) - .setOnCancelListener(new DialogInterface.OnCancelListener() { - @Override - public void onCancel(DialogInterface dialog) { - setResult(RESULT_CANCELED, intent); - finish(); - } - }) - .create(); - } - - /** - * Builds an {@link AlertDialog} to the user to indicate a {@link RideRequestViewError#CONNECTIVITY_ISSUE} - * and allow the retry of the button. - * - * @param messageTextId the message content {@link StringRes} text ID - * @param positiveButtonTextId the positive button {@link StringRes} text ID - * @param negativeButtonTextId the negative button {@link StringRes} text ID - * @param intent the {@link Intent} to pass in the result - * @return an {@link AlertDialog} to show - */ - @NonNull - private AlertDialog buildRetryAlert( - @StringRes int messageTextId, - @StringRes int positiveButtonTextId, - @StringRes int negativeButtonTextId, - final Intent intent) { - return new AlertDialog.Builder(this) - .setMessage(messageTextId) - .setPositiveButton(positiveButtonTextId, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - load(); - } - }) - .setNegativeButton(negativeButtonTextId, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialogInterface, int i) { - setResult(RESULT_CANCELED, intent); - finish(); - } - }) - .setOnCancelListener(new DialogInterface.OnCancelListener() { - @Override - public void onCancel(DialogInterface dialog) { - setResult(RESULT_CANCELED, intent); - finish(); - } - }) - .create(); - } -} diff --git a/rides-android/src/main/java/com/uber/sdk/android/rides/RideRequestActivityBehavior.java b/rides-android/src/main/java/com/uber/sdk/android/rides/RideRequestActivityBehavior.java deleted file mode 100644 index 471b18b2..00000000 --- a/rides-android/src/main/java/com/uber/sdk/android/rides/RideRequestActivityBehavior.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2016 Uber Technologies, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package com.uber.sdk.android.rides; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.support.annotation.NonNull; - -import com.uber.sdk.android.core.UberSdk; -import com.uber.sdk.android.core.auth.AccessTokenManager; -import com.uber.sdk.core.client.SessionConfiguration; - -/** - * The {@link RideRequestBehavior} to pass to the {@link RideRequestButton} to have it launch a {@link RideRequestActivity}. - - * @deprecated in favor of directly using mobile web directly. - * See https://developer.uber.com/docs/riders/ride-requests/tutorials/widget/migration-to-muber - */ -@Deprecated -public class RideRequestActivityBehavior implements RideRequestBehavior { - - @NonNull private final Activity activity; - private final int requestCode; - private final SessionConfiguration sessionConfiguration; - private final String accessTokenStorageKey; - - /** - * Construct a new {@link RideRequestActivityBehavior}. - * - * @param activity the {@link Activity} to launch the {@link RideRequestActivity} from - * @param requestCode the request code to use for the {@link Activity} result - */ - public RideRequestActivityBehavior(@NonNull Activity activity, int requestCode) { - this(activity, requestCode, UberSdk.getDefaultSessionConfiguration()); - } - - /** - * Construct a new {@link RideRequestActivityBehavior}. - * - * @param activity the {@link Activity} to launch the {@link RideRequestActivity} from - * @param requestCode the request code to use for the {@link Activity} result - * @param loginConfiguration used for login scenarios from ride request screen - */ - public RideRequestActivityBehavior(@NonNull Activity activity, - int requestCode, - @NonNull SessionConfiguration loginConfiguration) { - this(activity, requestCode, loginConfiguration, AccessTokenManager.ACCESS_TOKEN_DEFAULT_KEY); - } - - /** - * Construct a new {@link RideRequestActivityBehavior}. - * - * @param activity the {@link Activity} to launch the {@link RideRequestActivity} from - * @param requestCode the request code to use for the {@link Activity} result - * @param loginConfiguration used for login scenarios from ride request screen - * @param accessTokenStorageKey key to use for looking in {@link com.uber.sdk.core.auth.AccessTokenStorage} - */ - public RideRequestActivityBehavior(@NonNull Activity activity, - int requestCode, - @NonNull SessionConfiguration loginConfiguration, - @NonNull String accessTokenStorageKey) { - this.activity = activity; - this.requestCode = requestCode; - this.sessionConfiguration = loginConfiguration; - this.accessTokenStorageKey = accessTokenStorageKey; - } - - @Override - public void requestRide(Context context, RideParameters params) { - Intent data = RideRequestActivity.newIntent(context, params, sessionConfiguration, accessTokenStorageKey); - activity.startActivityForResult(data, requestCode); - } -} diff --git a/rides-android/src/main/java/com/uber/sdk/android/rides/RideRequestBehavior.java b/rides-android/src/main/java/com/uber/sdk/android/rides/RideRequestBehavior.java deleted file mode 100644 index 8c297b83..00000000 --- a/rides-android/src/main/java/com/uber/sdk/android/rides/RideRequestBehavior.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2016 Uber Technologies, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package com.uber.sdk.android.rides; - -import android.content.Context; - -/** - * Interface to implement that describes actions for the {@link RideRequestButton}. - * - * @deprecated Use RideRequestDeeplink directly. - */ -@Deprecated -public interface RideRequestBehavior { - - /** - * This function is called by the {@link RideRequestButton} when clicked. - * - * @param context {@link Context} to pass to launch a ride request - * @param params {@link RideParameters} that describes the parameters for the ride request - */ - void requestRide(Context context, RideParameters params); -} diff --git a/rides-android/src/main/java/com/uber/sdk/android/rides/RideRequestButton.java b/rides-android/src/main/java/com/uber/sdk/android/rides/RideRequestButton.java index c7e554ab..16f3a326 100644 --- a/rides-android/src/main/java/com/uber/sdk/android/rides/RideRequestButton.java +++ b/rides-android/src/main/java/com/uber/sdk/android/rides/RideRequestButton.java @@ -65,8 +65,6 @@ public class RideRequestButton extends FrameLayout implements RideRequestButtonV private static final String USER_AGENT_BUTTON = String.format("rides-android-v%s-button", BuildConfig.VERSION_NAME); - private RideRequestBehavior rideRequestBehavior; - @NonNull private RideParameters rideParameters = new RideParameters.Builder().build(); @@ -159,21 +157,6 @@ public RideRequestButton setDeeplinkFallback(@NonNull Deeplink.Fallback fallback return this; } - /** - * Sets how the request button should act for button actions. - * - * @param requestBehavior an object that implements {@link RideRequestBehavior} - * @return this instance of {@link RideRequestButton} - * - * @deprecated Button will use deeplink by default use RideRequestButton to indicate fallback - * now instead. - */ - @Deprecated - public RideRequestButton setRequestBehavior(@NonNull RideRequestBehavior requestBehavior) { - rideRequestBehavior = requestBehavior; - return this; - } - /** * Set {@link RideRequestButtonCallback}. This is optional but it is recommended to supply one * for error handling. diff --git a/rides-android/src/main/java/com/uber/sdk/android/rides/RideRequestView.java b/rides-android/src/main/java/com/uber/sdk/android/rides/RideRequestView.java deleted file mode 100644 index de742995..00000000 --- a/rides-android/src/main/java/com/uber/sdk/android/rides/RideRequestView.java +++ /dev/null @@ -1,345 +0,0 @@ -/* - * Copyright (c) 2016 Uber Technologies, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package com.uber.sdk.android.rides; - -import android.annotation.TargetApi; -import android.content.Context; -import android.content.Intent; -import android.net.Uri; -import android.os.Build; -import android.support.annotation.NonNull; -import android.support.annotation.Nullable; -import android.support.annotation.VisibleForTesting; -import android.util.AttributeSet; -import android.webkit.GeolocationPermissions; -import android.webkit.WebChromeClient; -import android.webkit.WebResourceError; -import android.webkit.WebResourceRequest; -import android.webkit.WebResourceResponse; -import android.webkit.WebSettings; -import android.webkit.WebView; -import android.webkit.WebViewClient; -import android.widget.LinearLayout; - -import com.uber.sdk.android.core.UberSdk; -import com.uber.sdk.android.core.auth.AccessTokenManager; -import com.uber.sdk.core.auth.AccessToken; -import com.uber.sdk.core.auth.AccessTokenStorage; -import com.uber.sdk.core.client.AccessTokenSession; -import com.uber.sdk.core.client.SessionConfiguration; - -import java.util.HashMap; -import java.util.Map; - -/** - * The Uber Ride Request View: an embeddable view that provides the end-to-end Uber experience. - * The primary way to interact with this view after construction is to call the load() function. - * - * @deprecated in favor of directly using mobile web directly. - * See https://developer.uber.com/docs/riders/ride-requests/tutorials/widget/migration-to-muber - */ -@Deprecated -public class RideRequestView extends LinearLayout { - - private static final String USER_AGENT_RIDE_VIEW = String.format("rides-android-v%s-ride_request_view", - BuildConfig.VERSION_NAME); - @Nullable private AccessTokenSession accessTokenSession; - @NonNull @VisibleForTesting RideParameters rideParameters = new RideParameters.Builder().build(); - @Nullable private RideRequestViewCallback rideRequestViewCallback; - private WebView webView; - - public RideRequestView(Context context) { - this(context, null); - } - - public RideRequestView(Context context, AttributeSet attrs) { - super(context, attrs, 0); - init(context); - } - - /** - * Stops all current loading and brings up a blank page. - */ - public void cancelLoad() { - webView.stopLoading(); - webView.loadUrl("about:blank"); - } - - /** - * Gets the {@link AccessToken} being used to authorize the {@link RideRequestView}. - * - * @return - */ - @Nullable - public AccessTokenSession getSession() { - return accessTokenSession; - } - - /** - * Loads the ride widget. - * Requires that the {@link AccessToken} has been retrieved. - */ - public void load() { - final SessionConfiguration config; - final AccessTokenStorage storage; - - if (accessTokenSession == null && UberSdk.isInitialized()) { - config = UberSdk.getDefaultSessionConfiguration(); - storage = new AccessTokenManager(getContext()); - accessTokenSession = new AccessTokenSession(config, storage); - - } else if (accessTokenSession != null) { - config = accessTokenSession.getAuthenticator().getSessionConfiguration(); - storage = accessTokenSession.getAuthenticator().getTokenStorage(); - } else { - config = null; - storage = null; - } - - if (config == null || storage == null || storage.getAccessToken() == null) { - if (rideRequestViewCallback != null) { - rideRequestViewCallback.onErrorReceived(RideRequestViewError.NO_ACCESS_TOKEN); - } - return; - } - - webView.loadUrl(buildUrlFromRideParameters(getContext(), rideParameters, - config), - RideRequestView.getHeaders(storage.getAccessToken())); - } - - /** - * Set a custom {@link AccessTokenSession} to use for authenticating into the Ride Widget. - * - * @param accessTokenSession the {@link AccessTokenSession} to use for authorization - */ - public void setSession(@Nullable AccessTokenSession accessTokenSession) { - this.accessTokenSession = accessTokenSession; - } - - /** - * Configure parameters for the Ride Request Control. - * - * @param rideParameters the {@link RideParameters} to use for presetting values - */ - public void setRideParameters(@NonNull RideParameters rideParameters) { - this.rideParameters = rideParameters; - } - - /** - * Sets the callback for events occurring in the Ride Request Control such as errors. - * - * @param rideRequestViewCallback the {@link RideRequestViewCallback} - */ - public void setRideRequestViewCallback(@NonNull RideRequestViewCallback rideRequestViewCallback) { - this.rideRequestViewCallback = rideRequestViewCallback; - } - - /** - * Builds a URL with necessary query parameters to load in the {@link WebView}. - * - * @param rideParameters the {@link RideParameters} to build into the query - * @return the URL {@link String} to load in the {@link WebView} - */ - @NonNull - @VisibleForTesting - static String buildUrlFromRideParameters(@NonNull Context context, - @NonNull RideParameters rideParameters, - @NonNull SessionConfiguration loginConfiguration) { - final String ENDPOINT = "components"; - final String ENVIRONMENT_KEY = "env"; - final String HTTPS = "https"; - final String PATH = "rides/"; - final String SANDBOX = "sandbox"; - - Uri.Builder builder = new Uri.Builder(); - builder.scheme(HTTPS) - .authority(ENDPOINT + "." + loginConfiguration.getEndpointRegion().getDomain()) - .appendEncodedPath(PATH); - - if (rideParameters.getUserAgent() == null) { - rideParameters.setUserAgent(USER_AGENT_RIDE_VIEW); - } - - RideRequestDeeplink deeplink = new RideRequestDeeplink.Builder(context) - .setSessionConfiguration(loginConfiguration) - .setRideParameters(rideParameters).build(); - Uri uri = deeplink.getUri(); - builder.encodedQuery(uri.getEncodedQuery()); - - if (loginConfiguration.getEnvironment() == SessionConfiguration.Environment.SANDBOX) { - builder.appendQueryParameter(ENVIRONMENT_KEY, SANDBOX); - } - - return builder.build().toString(); - } - - /** - * Creates a {@link Map} of the headers needed to pass to the {@link WebView}. - * - * @param accessToken the {@link AccessToken} to use for the Authorization header. - * @return a {@link Map} containing headers to pass to {@link WebView}. - */ - @NonNull - @VisibleForTesting static Map getHeaders(@NonNull AccessToken accessToken) { - final String AUTH_HEADER = "Authorization"; - final String BEARER = "Bearer"; - - Map headers = new HashMap(); - headers.put(AUTH_HEADER, BEARER + " " + accessToken.getToken()); - return headers; - } - - /** - * Initialize the layout, properties, and inner web view. - */ - private void init(@NonNull Context context) { - inflate(getContext(), R.layout.ub__ride_request_view, this); - webView = (WebView) findViewById(R.id.ub__ride_request_webview); - - webView.getSettings().setJavaScriptEnabled(true); - webView.getSettings().setGeolocationEnabled(true); - webView.getSettings().setAppCacheEnabled(true); - webView.getSettings().setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK); - webView.setWebChromeClient(new RideRequestWebChromeClient()); - webView.setWebViewClient(new RideRequestWebViewClient(new RideRequestWebViewClientCallback() { - @Override - public void onErrorParsed(@NonNull RideRequestViewError error) { - if (rideRequestViewCallback != null) { - rideRequestViewCallback.onErrorReceived(error); - } - } - })); - } - - /** - * Interface for {@link RideRequestWebViewClient} to communicate with this view. - */ - @VisibleForTesting - interface RideRequestWebViewClientCallback { - - /** - * Called when an error is received in the redirect URL of the {@link WebView}. - * - * @param error the {@link RideRequestViewError} that occurred. - */ - void onErrorParsed(@NonNull RideRequestViewError error); - } - - /** - * The {@link WebViewClient} that listens for errors in the URL of the {@link WebView}. - */ - @VisibleForTesting - class RideRequestWebViewClient extends WebViewClient { - - private static final String ERROR_KEY = "error"; - private static final String REDIRECT_URL = "uberconnect://oauth"; - - @NonNull private RideRequestWebViewClientCallback rideRequestWebViewClientCallback; - - /** - * Construct the web view client to listen for and report back errors through a callback. - * - * @param callback the {@link com.uber.sdk.android.rides.RideRequestView.RideRequestWebViewClientCallback} - */ - @VisibleForTesting - RideRequestWebViewClient(@NonNull RideRequestWebViewClientCallback callback) { - rideRequestWebViewClientCallback = callback; - } - - /** - * add deprecated member "onReceivedError" to solve compatibility issue when API level < 23 - * @param view - * @param errorCode - * @param description - * @param failingUrl - */ - @Override - public void onReceivedError(WebView view, int errorCode, String description, String failingUrl) { - if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M){ - receivedError(); - } - } - - @TargetApi(23) - @Override - public void onReceivedError(WebView view, - WebResourceRequest request, - WebResourceError error) { - receivedError(); - } - - private void receivedError(){ - rideRequestWebViewClientCallback.onErrorParsed(RideRequestViewError.CONNECTIVITY_ISSUE); - } - - @TargetApi(23) - @Override - public void onReceivedHttpError(WebView view, WebResourceRequest request, WebResourceResponse errorResponse) { - // This is a no-op necessary for testing as robolectric only supports up - // to API 21 and this call was added in API 23 - } - - @Override - public boolean shouldOverrideUrlLoading(WebView view, String url) { - if (url.toLowerCase().startsWith(REDIRECT_URL)) { - Uri uri = Uri.parse(url); - - Uri fragmentUri = new Uri.Builder().encodedQuery(uri.getFragment()).build(); - String errorValue = fragmentUri.getQueryParameter(ERROR_KEY); - RideRequestViewError error = RideRequestViewError.UNKNOWN; - if (errorValue != null) { - try { - error = RideRequestViewError.valueOf(errorValue.toUpperCase()); - } catch (IllegalArgumentException e) { - error = RideRequestViewError.UNKNOWN; - } - } - rideRequestWebViewClientCallback.onErrorParsed(error); - return true; - } else if (url.startsWith("http:") || url.startsWith("https:")) { - return false; - } else { - Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url)); - RideRequestView.this.getContext().startActivity(intent); - return true; - } - } - } - - /** - * The {@link WebChromeClient} used for overriding the {@link GeolocationPermissions} prompt. - */ - private class RideRequestWebChromeClient extends WebChromeClient { - - /** - * The default implementation does nothing, so permission is never obtained and passed to Javascript. - * Overriding to always gain permission as {@link RideRequestView} assumes the app has already gained - * location permissions. - */ - @Override - public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) { - callback.invoke(origin, true, false); - } - } -} diff --git a/rides-android/src/main/java/com/uber/sdk/android/rides/RideRequestViewCallback.java b/rides-android/src/main/java/com/uber/sdk/android/rides/RideRequestViewCallback.java deleted file mode 100644 index db4818a1..00000000 --- a/rides-android/src/main/java/com/uber/sdk/android/rides/RideRequestViewCallback.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (c) 2016 Uber Technologies, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package com.uber.sdk.android.rides; - -/** - * Callback for events that occur in the {@link RideRequestView} such as errors. - */ -public interface RideRequestViewCallback { - - /** - * An error has occurred in the {@link RideRequestView}. - * - * @param error the {@link RideRequestViewError} that occurred. - */ - void onErrorReceived(RideRequestViewError error); -} diff --git a/rides-android/src/main/java/com/uber/sdk/android/rides/RideRequestViewError.java b/rides-android/src/main/java/com/uber/sdk/android/rides/RideRequestViewError.java deleted file mode 100644 index 09353fb6..00000000 --- a/rides-android/src/main/java/com/uber/sdk/android/rides/RideRequestViewError.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2016 Uber Technologies, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package com.uber.sdk.android.rides; - -/** - * Possible errors that can occur in the {@link RideRequestView}. - */ -public enum RideRequestViewError { - - /** - * There was a connectivity error while trying to load the widget. - */ - CONNECTIVITY_ISSUE, - - /** - * Attempted to use current location for pickup, but location services aren't enabled. - */ - LOCATION_SERVICES_NOT_ENABLED, - - /** - * There is no access token to make the request with. - */ - NO_ACCESS_TOKEN, - - /** - * Access token has expired. - */ - UNAUTHORIZED, - - /** - * Unknown error occurred. - */ - UNKNOWN, - - /** - * Received a web resource or HTTP error. - */ - WEB_ERROR, - - /** - * Incorrect region error. - */ - WRONG_REGION; -} diff --git a/core-android/src/main/res/drawable-hdpi/uber_badge.png b/rides-android/src/main/res/drawable-hdpi/uber_badge.png similarity index 100% rename from core-android/src/main/res/drawable-hdpi/uber_badge.png rename to rides-android/src/main/res/drawable-hdpi/uber_badge.png diff --git a/core-android/src/main/res/drawable-mdpi/uber_badge.png b/rides-android/src/main/res/drawable-mdpi/uber_badge.png similarity index 100% rename from core-android/src/main/res/drawable-mdpi/uber_badge.png rename to rides-android/src/main/res/drawable-mdpi/uber_badge.png diff --git a/core-android/src/main/res/drawable-xhdpi/uber_badge.png b/rides-android/src/main/res/drawable-xhdpi/uber_badge.png similarity index 100% rename from core-android/src/main/res/drawable-xhdpi/uber_badge.png rename to rides-android/src/main/res/drawable-xhdpi/uber_badge.png diff --git a/core-android/src/main/res/drawable-xxhdpi/uber_badge.png b/rides-android/src/main/res/drawable-xxhdpi/uber_badge.png similarity index 100% rename from core-android/src/main/res/drawable-xxhdpi/uber_badge.png rename to rides-android/src/main/res/drawable-xxhdpi/uber_badge.png diff --git a/core-android/src/main/res/drawable-xxxhdpi/uber_badge.png b/rides-android/src/main/res/drawable-xxxhdpi/uber_badge.png similarity index 100% rename from core-android/src/main/res/drawable-xxxhdpi/uber_badge.png rename to rides-android/src/main/res/drawable-xxxhdpi/uber_badge.png diff --git a/rides-android/src/main/res/layout/ub__ride_request_activity.xml b/rides-android/src/main/res/layout/ub__ride_request_activity.xml deleted file mode 100644 index 71592852..00000000 --- a/rides-android/src/main/res/layout/ub__ride_request_activity.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - - - - diff --git a/rides-android/src/main/res/layout/ub__ride_request_button.xml b/rides-android/src/main/res/layout/ub__ride_request_button.xml index c7772a61..bd6793c9 100644 --- a/rides-android/src/main/res/layout/ub__ride_request_button.xml +++ b/rides-android/src/main/res/layout/ub__ride_request_button.xml @@ -29,6 +29,7 @@ android:layout_centerVertical="true" android:layout_gravity="center_vertical|start" android:drawableLeft="@drawable/uber_badge" + android:drawableStart="@drawable/uber_badge" android:drawablePadding="@dimen/ub__small_padding" android:gravity="center_vertical|start" android:minHeight="@dimen/ub__ride_request_button_height" diff --git a/rides-android/src/main/res/layout/ub__ride_request_view.xml b/rides-android/src/main/res/layout/ub__ride_request_view.xml deleted file mode 100644 index f6a03386..00000000 --- a/rides-android/src/main/res/layout/ub__ride_request_view.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - - diff --git a/rides-android/src/main/res/values-hi-rIN/strings_localized.xml b/rides-android/src/main/res/values-hi-rIN/strings_localized.xml index 5255232d..dad09b36 100644 --- a/rides-android/src/main/res/values-hi-rIN/strings_localized.xml +++ b/rides-android/src/main/res/values-hi-rIN/strings_localized.xml @@ -22,10 +22,7 @@ --> - आपका प्रमाणन करने में कोई समस्या थी. - राइड अनुरोध विजेट में कोई समस्या आई. Uber के साथ राइड करें - पुन: प्रयास करें एक राइड पाएं %d मिनट दूर %2$s के लिए %1$s diff --git a/rides-android/src/main/res/values-zh-rCN/strings_localized.xml b/rides-android/src/main/res/values-zh-rCN/strings_localized.xml index 84b1af27..2e32a885 100644 --- a/rides-android/src/main/res/values-zh-rCN/strings_localized.xml +++ b/rides-android/src/main/res/values-zh-rCN/strings_localized.xml @@ -22,10 +22,7 @@ --> - 身份验证错误。 - 优步叫车插件错误。 搭乘优步前往 - 重试 开始搭乘 %d 分钟后到达 %2$s 的 %1$s diff --git a/rides-android/src/main/res/values-zh-rHK/strings_localized.xml b/rides-android/src/main/res/values-zh-rHK/strings_localized.xml index b0a42f8a..f08ad613 100644 --- a/rides-android/src/main/res/values-zh-rHK/strings_localized.xml +++ b/rides-android/src/main/res/values-zh-rHK/strings_localized.xml @@ -22,10 +22,7 @@ --> - 身份驗證發生問題。 - 乘客預約側邊欄出現問題。 搭乘优步前往 - 再試 開始搭乘 相距 %d 分鐘 %2$s 的估價為 %1$s diff --git a/rides-android/src/main/res/values-zh-rTW/strings_localized.xml b/rides-android/src/main/res/values-zh-rTW/strings_localized.xml index b0a42f8a..f08ad613 100644 --- a/rides-android/src/main/res/values-zh-rTW/strings_localized.xml +++ b/rides-android/src/main/res/values-zh-rTW/strings_localized.xml @@ -22,10 +22,7 @@ --> - 身份驗證發生問題。 - 乘客預約側邊欄出現問題。 搭乘优步前往 - 再試 開始搭乘 相距 %d 分鐘 %2$s 的估價為 %1$s diff --git a/rides-android/src/main/res/values/strings_localized.xml b/rides-android/src/main/res/values/strings_localized.xml index 99e14c01..51e5a804 100644 --- a/rides-android/src/main/res/values/strings_localized.xml +++ b/rides-android/src/main/res/values/strings_localized.xml @@ -21,10 +21,7 @@ --> - There was a problem authenticating you. - The Ride Request Widget encountered a problem. Ride there with Uber - Try Again Get a ride %d MIN AWAY %1$s for %2$s diff --git a/rides-android/src/test/java/com/uber/sdk/android/rides/RideRequestActivityBehaviorTest.java b/rides-android/src/test/java/com/uber/sdk/android/rides/RideRequestActivityBehaviorTest.java deleted file mode 100644 index 385dd4a5..00000000 --- a/rides-android/src/test/java/com/uber/sdk/android/rides/RideRequestActivityBehaviorTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2016 Uber Technologies, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package com.uber.sdk.android.rides; - -import android.app.Activity; -import android.content.Intent; - -import com.uber.sdk.core.client.SessionConfiguration; - -import org.junit.Test; -import org.robolectric.Robolectric; -import org.robolectric.shadows.ShadowActivity; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.robolectric.Shadows.shadowOf; - -public class RideRequestActivityBehaviorTest extends RobolectricTestBase { - - @Test - public void onRequestRide_shouldLaunchActivity() { - Activity activity = Robolectric.setupActivity(Activity.class); - ShadowActivity shadowActivity = shadowOf(activity); - RideRequestActivityBehavior behavior = new RideRequestActivityBehavior(activity, 4005, - new SessionConfiguration.Builder().setClientId("clientId").build()); - behavior.requestRide(activity, new RideParameters.Builder().build()); - Intent startedIntent = shadowActivity.getNextStartedActivity(); - assertThat(startedIntent.getComponent().getClassName()).isEqualTo(RideRequestActivity.class.getName()); - } -} diff --git a/rides-android/src/test/java/com/uber/sdk/android/rides/RideRequestActivityTest.java b/rides-android/src/test/java/com/uber/sdk/android/rides/RideRequestActivityTest.java deleted file mode 100644 index 19d7a58d..00000000 --- a/rides-android/src/test/java/com/uber/sdk/android/rides/RideRequestActivityTest.java +++ /dev/null @@ -1,236 +0,0 @@ -/* - * Copyright (c) 2016 Uber Technologies, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package com.uber.sdk.android.rides; - -import android.app.Activity; -import android.app.AlertDialog; -import android.content.Intent; - -import com.google.common.collect.ImmutableList; -import com.uber.sdk.android.core.auth.AccessTokenManager; -import com.uber.sdk.android.core.auth.AuthenticationError; -import com.uber.sdk.android.core.auth.LoginManager; -import com.uber.sdk.core.auth.AccessToken; -import com.uber.sdk.core.auth.AccessTokenStorage; -import com.uber.sdk.core.auth.Scope; -import com.uber.sdk.core.client.SessionConfiguration; - -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.robolectric.Robolectric; -import org.robolectric.shadows.ShadowActivity; -import org.robolectric.shadows.ShadowAlertDialog; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Matchers.refEq; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.robolectric.Shadows.shadowOf; - -public class RideRequestActivityTest extends RobolectricTestBase { - - private RideRequestActivity activity; - - @Before - public void setup() { - Intent data = RideRequestActivity.newIntent(Robolectric.setupActivity(Activity.class), null, - new SessionConfiguration.Builder().setClientId("clientId").build(), - null); - activity = Robolectric.buildActivity(RideRequestActivity.class).withIntent(data).create() - .get(); - } - - @Test - public void onNewIntent_withNullRideParameters_shouldGetDefaultParams() { - Intent data = RideRequestActivity.newIntent(Robolectric.setupActivity(Activity.class), null, - new SessionConfiguration.Builder().setClientId("clientId").build(), - null); - assertNotNull(data); - - RideParameters rideParameters = data.getParcelableExtra(RideRequestActivity.RIDE_PARAMETERS); - assertNotNull(rideParameters); - } - - @Test - public void onNewIntent_withRideParameters_shouldGetRideParams() { - Double PICKUP_LAT = 32.1234; - Double PICKUP_LONG = -122.3456; - Double DROPOFF_LAT = 32.5678; - Double DROPOFF_LONG = -122.6789; - RideParameters rideParameters = new RideParameters.Builder() - .setPickupLocation(PICKUP_LAT, PICKUP_LONG, null, null) - .setDropoffLocation(DROPOFF_LAT, DROPOFF_LONG, null, null) - .build(); - Intent data = RideRequestActivity.newIntent(Robolectric.setupActivity(Activity.class), - rideParameters, - new SessionConfiguration.Builder().setClientId("clientId").build(), - null); - assertNotNull(data); - - RideParameters resultParameters = data.getParcelableExtra(RideRequestActivity.RIDE_PARAMETERS); - assertNotNull(resultParameters); - assertEquals(rideParameters.getPickupLatitude(), resultParameters.getPickupLatitude()); - assertEquals(rideParameters.getPickupLongitude(), resultParameters.getPickupLongitude()); - assertEquals(rideParameters.getDropoffLatitude(), resultParameters.getDropoffLatitude()); - assertEquals(rideParameters.getDropoffLongitude(), resultParameters.getDropoffLongitude()); - } - - @Test - public void onLoad_whenNullUserAgent_shouldAddRideWidgetUserAgent() { - Double PICKUP_LAT = 32.1234; - Double PICKUP_LONG = -122.3456; - Double DROPOFF_LAT = 32.5678; - Double DROPOFF_LONG = -122.6789; - RideParameters rideParameters = new RideParameters.Builder() - .setPickupLocation(PICKUP_LAT, PICKUP_LONG, null, null) - .setDropoffLocation(DROPOFF_LAT, DROPOFF_LONG, null, null) - .build(); - Intent data = RideRequestActivity.newIntent(Robolectric.setupActivity(Activity.class), - rideParameters, - new SessionConfiguration.Builder().setClientId("clientId").build(), - null); - activity = Robolectric.buildActivity(RideRequestActivity.class).withIntent(data).create().get(); - - String tokenString = "accessToken1234"; - AccessToken accessToken = new AccessToken(2592000, ImmutableList.of(Scope.RIDE_WIDGETS), tokenString, - "refreshToken", "tokenType"); - activity.onLoginSuccess(accessToken); - - assertEquals(String.format("rides-android-v%s-ride_request_widget", BuildConfig.VERSION_NAME), - activity.rideRequestView.rideParameters.getUserAgent()); - } - - @Test - public void onLoad_withUserAgentInRideParametersButton_shouldNotGetOverridden() { - String userAgent = String.format("rides-android-v%s-button", BuildConfig.VERSION_NAME); - RideParameters rideParameters = new RideParameters.Builder().build(); - rideParameters.setUserAgent(userAgent); - Intent data = RideRequestActivity.newIntent(Robolectric.setupActivity(Activity.class), - rideParameters, - new SessionConfiguration.Builder().setClientId("clientId").build(), - null); - activity = Robolectric.buildActivity(RideRequestActivity.class).withIntent(data).create().get(); - assertEquals(userAgent, activity.rideRequestView.rideParameters.getUserAgent()); - } - - @Test - public void onCreate_withNullRideParameters_shouldCreateDefaultParamsAndLoad() { - ShadowActivity shadowActivity = shadowOf(activity); - Intent intent = new Intent(); - intent.putExtra(RideRequestActivity.EXTRA_LOGIN_CONFIGURATION, new SessionConfiguration.Builder().setClientId("clientId").build()); - activity = Robolectric.buildActivity(RideRequestActivity.class).withIntent(intent).create().get(); - assertNull(shadowActivity.getResultIntent()); - assertFalse(shadowActivity.isFinishing()); - } - - @Test - public void onLoad_whenAccessTokenGeneratedFromLogin_shouldSaveAccessTokenResult() { - String tokenString = "accessToken1234"; - AccessToken accessToken = new AccessToken(2592000, ImmutableList.of(Scope.RIDE_WIDGETS), tokenString, - "refreshToken", "tokenType"); - - activity.onLoginSuccess(accessToken); - - AccessToken resultAccessToken = new AccessTokenManager(activity).getAccessToken(); - assertNotNull(resultAccessToken); - assertEquals(resultAccessToken.getExpiresIn(), 2592000); - assertEquals(resultAccessToken.getToken(), tokenString); - assertEquals(resultAccessToken.getScopes().size(), 1); - assertTrue(resultAccessToken.getScopes().contains(Scope.RIDE_WIDGETS)); - } - - @Test - public void onLoad_whenLoginErrorOccurs_shouldReturnErrorResultIntent() { - ShadowActivity shadowActivity = shadowOf(activity); - activity.onLoginError(AuthenticationError.MISMATCHING_REDIRECT_URI); - ShadowAlertDialog shadowAlertDialog = shadowOf(activity.authenticationErrorDialog); - - String message = "There was a problem authenticating you."; - assertEquals(message, shadowAlertDialog.getMessage()); - activity.authenticationErrorDialog.getButton(AlertDialog.BUTTON_POSITIVE).performClick(); - - Assert.assertNotNull(shadowActivity.getResultIntent()); - assertEquals(shadowActivity.getResultCode(), Activity.RESULT_CANCELED); - assertEquals(AuthenticationError.MISMATCHING_REDIRECT_URI, shadowActivity.getResultIntent().getSerializableExtra - (RideRequestActivity.AUTHENTICATION_ERROR)); - } - - @Test - public void onLoad_whenLoginCanceled_shouldReturnCanceledResultIntent() { - ShadowActivity shadowActivity = shadowOf(activity); - activity.onLoginCancel(); - - assertNull(shadowActivity.getResultIntent()); - assertEquals(shadowActivity.getResultCode(), Activity.RESULT_CANCELED); - } - - @Test - public void onLoad_whenRideRequestViewAuthorizationErrorOccurs_shouldAttemptLoginLoad() { - activity.loginManager = mock(LoginManager.class); - activity.accessTokenStorage = mock(AccessTokenStorage.class); - ShadowActivity shadowActivity = shadowOf(activity); - activity.onErrorReceived(RideRequestViewError.UNAUTHORIZED); - - assertNull(shadowActivity.getResultIntent()); - verify(activity.accessTokenStorage, times(1)).removeAccessToken(); - verify(activity.loginManager).login(refEq(activity)); - } - - @Test - public void onLoad_whenSomeRideRequestViewErrorOccurs_shouldReturnResultIntentError() { - ShadowActivity shadowActivity = shadowOf(activity); - activity.onErrorReceived(RideRequestViewError.UNKNOWN); - ShadowAlertDialog shadowAlertDialog = shadowOf(activity.rideRequestErrorDialog); - - String message = "The Ride Request Widget encountered a problem."; - assertEquals(message, shadowAlertDialog.getMessage()); - activity.rideRequestErrorDialog.getButton(AlertDialog.BUTTON_POSITIVE).performClick(); - - assertNotNull(shadowActivity.getResultIntent()); - assertEquals(Activity.RESULT_CANCELED, shadowActivity.getResultCode()); - assertEquals(RideRequestViewError.UNKNOWN, shadowActivity.getResultIntent().getSerializableExtra - (RideRequestActivity.RIDE_REQUEST_ERROR)); - } - - @Test - public void onLoad_whenErrorOccursAndUserHitsBackWhenAlertShows_shouldReturnResultIntentError() { - ShadowActivity shadowActivity = shadowOf(activity); - activity.onErrorReceived(RideRequestViewError.UNKNOWN); - ShadowAlertDialog shadowAlertDialog = shadowOf(activity.rideRequestErrorDialog); - - String message = "The Ride Request Widget encountered a problem."; - assertEquals(message, shadowAlertDialog.getMessage()); - activity.rideRequestErrorDialog.onBackPressed(); - - assertNotNull(shadowActivity.getResultIntent()); - assertEquals(Activity.RESULT_CANCELED, shadowActivity.getResultCode()); - assertEquals(RideRequestViewError.UNKNOWN, shadowActivity.getResultIntent().getSerializableExtra - (RideRequestActivity.RIDE_REQUEST_ERROR)); - } -} diff --git a/rides-android/src/test/java/com/uber/sdk/android/rides/RideRequestViewTest.java b/rides-android/src/test/java/com/uber/sdk/android/rides/RideRequestViewTest.java deleted file mode 100644 index b46793fa..00000000 --- a/rides-android/src/test/java/com/uber/sdk/android/rides/RideRequestViewTest.java +++ /dev/null @@ -1,254 +0,0 @@ -/* - * Copyright (c) 2016 Uber Technologies, Inc. - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), to deal - * in the Software without restriction, including without limitation the rights - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - */ - -package com.uber.sdk.android.rides; - -import android.app.Activity; -import android.content.Context; -import android.content.Intent; -import android.webkit.WebResourceError; -import android.webkit.WebResourceRequest; -import android.webkit.WebResourceResponse; -import android.webkit.WebView; - -import com.google.common.collect.ImmutableList; -import com.uber.sdk.core.auth.AccessToken; -import com.uber.sdk.core.auth.Scope; -import com.uber.sdk.core.client.AccessTokenSession; -import com.uber.sdk.core.client.SessionConfiguration; - -import org.junit.Before; -import org.junit.Test; -import org.robolectric.Robolectric; -import org.robolectric.RuntimeEnvironment; -import org.robolectric.shadows.ShadowActivity; - -import java.io.IOException; -import java.util.Map; - -import static com.uber.sdk.android.rides.TestUtils.readUriResourceWithUserAgentParam; -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertFalse; -import static junit.framework.Assert.assertNotNull; -import static junit.framework.Assert.assertTrue; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.never; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.verifyZeroInteractions; -import static org.robolectric.Shadows.shadowOf; - -/** - * Tests {@link RideRequestView} - */ -public class RideRequestViewTest extends RobolectricTestBase { - - private static final String CLIENT_ID = "clientId"; - private static final String PRODUCT_ID = "productId"; - private static final Double PICKUP_LAT = 32.1234; - private static final Double PICKUP_LONG = -122.3456; - private static final String PICKUP_NICK = "pickupNick"; - private static final String PICKUP_ADDR = "Pickup Address"; - private static final Double DROPOFF_LAT = 32.5678; - private static final Double DROPOFF_LONG = -122.6789; - private static final String DROPOFF_NICK = "pickupNick"; - private static final String DROPOFF_ADDR = "Dropoff Address"; - private static final String TOKEN_STRING = "thisIsAnAccessToken"; - private static final String USER_AGENT_RIDE_VIEW = String.format("rides-android-v%s-ride_request_view", - BuildConfig.VERSION_NAME); - - private AccessToken accessToken; - private RideRequestView rideRequestView; - private RideRequestView.RideRequestWebViewClient client; - private RideRequestView.RideRequestWebViewClientCallback callback; - private Context context; - - @Before - public void setup() { - context = RuntimeEnvironment.application; - - accessToken = new AccessToken(2592000, ImmutableList.of(Scope.RIDE_WIDGETS), TOKEN_STRING, - "refreshToken", "Bearer"); - - rideRequestView = new RideRequestView(Robolectric.setupActivity(Activity.class)); - callback = mock(RideRequestView.RideRequestWebViewClientCallback.class); - client = rideRequestView.new RideRequestWebViewClient(callback); - } - - @Test - public void onBuildUrl_inDefaultRegion_shouldHaveUrlWithDefaultDomain() throws IOException { - String path = "src/test/resources/riderequestviewuris/default_uri"; - String expectedUri = readUriResourceWithUserAgentParam(path, USER_AGENT_RIDE_VIEW); - - RideParameters rideParameters = new RideParameters.Builder().build(); - - SessionConfiguration configuration = new SessionConfiguration.Builder() - .setClientId("clientId") - .build(); - - String result = RideRequestView.buildUrlFromRideParameters(context, rideParameters, configuration); - assertEquals(expectedUri, result); - } - - - @Test - public void onBuildUrl_inSandboxMode_shouldHaveUrlWithSandboxParam() throws IOException { - RideParameters rideParameters = new RideParameters.Builder().build(); - - SessionConfiguration configuration = new SessionConfiguration.Builder() - .setClientId("clientId") - .setEnvironment(SessionConfiguration.Environment.SANDBOX) - .build(); - - - String result = RideRequestView.buildUrlFromRideParameters(context, rideParameters, configuration); - assertTrue(result.contains("&env=sandbox")); - } - - @Test - public void onBuildUrl_withRideParams_shouldHaveRideParamsQueryParams() throws IOException { - String path = "src/test/resources/riderequestviewuris/full_details_uri"; - String expectedUri = readUriResourceWithUserAgentParam(path, USER_AGENT_RIDE_VIEW); - - RideParameters rideParameters = new RideParameters.Builder() - .setPickupLocation(PICKUP_LAT, PICKUP_LONG, PICKUP_NICK, PICKUP_ADDR) - .setDropoffLocation(DROPOFF_LAT, DROPOFF_LONG, DROPOFF_NICK, DROPOFF_ADDR) - .setProductId(PRODUCT_ID) - .build(); - SessionConfiguration configuration = new SessionConfiguration.Builder() - .setClientId("clientId") - .build(); - - String result = RideRequestView.buildUrlFromRideParameters(context, rideParameters, configuration); - assertEquals(expectedUri, result); - } - - @Test - public void onBuildUrl_withUserAgentNonNull_shouldNotOverride() throws IOException { - String widgetUserAgent = String.format("rides-android-v%s-ride_request_widget", - BuildConfig.VERSION_NAME); - String path = "src/test/resources/riderequestviewuris/default_uri"; - String expectedUri = readUriResourceWithUserAgentParam(path, widgetUserAgent); - - RideParameters rideParameters = new RideParameters.Builder().build(); - rideParameters.setUserAgent(widgetUserAgent); - - SessionConfiguration configuration = new SessionConfiguration.Builder() - .setClientId("clientId") - .build(); - - String result = RideRequestView.buildUrlFromRideParameters(context, rideParameters, configuration); - assertEquals(expectedUri, result); - } - - @Test - public void onGetHeaders_withAccessToken_shouldReturnCorrectHeader() { - String token = "accessToken123"; - AccessToken accessToken = new AccessToken(2592000, ImmutableList.of(Scope.HISTORY), token, - "refreshToken", "tokenType"); - Map headers = RideRequestView.getHeaders(accessToken); - assertEquals(headers.size(), 1); - assertEquals(headers.get("Authorization"), "Bearer " + token); - } - - @Test - public void onRideRequestViewInit_withCustomSession_viewShouldAuthorize() { - AccessTokenSession session = mock(AccessTokenSession.class); - rideRequestView.setSession(session); - assertNotNull(rideRequestView.getSession()); - assertEquals(session, rideRequestView.getSession()); - } - - @Test - public void onRideRequestViewLoad_withoutSession_viewShouldHaveAuthorizationError() { - rideRequestView.setRideParameters(new RideParameters.Builder().setPickupLocation(37.2342, -122.4232, null, - null).build()); - RideRequestViewCallback callback = mock(RideRequestViewCallback.class); - rideRequestView.setRideRequestViewCallback(callback); - rideRequestView.load(); - verify(callback, times(1)).onErrorReceived(RideRequestViewError.NO_ACCESS_TOKEN); - } - - @Test - public void whileRideRequestViewRunning_whenAccessTokenExpires_shouldReceiveUnauthorizedError() { - boolean shouldOverrideUrlLoading = client.shouldOverrideUrlLoading(mock(WebView.class), - "uberconnect://oauth#error=unauthorized"); - verify(callback, times(1)).onErrorParsed(RideRequestViewError.UNAUTHORIZED); - assertTrue(shouldOverrideUrlLoading); - } - - @Test - public void whileRideRequestViewRunning_whenWebResourceErrorOccurs_shouldReceiveWebError() { - client.onReceivedError(mock(WebView.class), mock(WebResourceRequest.class), mock(WebResourceError.class)); - verify(callback, times(1)).onErrorParsed(RideRequestViewError.CONNECTIVITY_ISSUE); - } - - @Test - public void whileRideRequestViewRunning_whenWebHTTPErrorOccurs_shouldDoNothing() { - client.onReceivedHttpError(mock(WebView.class), mock(WebResourceRequest.class), mock(WebResourceResponse.class)); - verify(callback, never()).onErrorParsed(any(RideRequestViewError.class)); - } - - @Test - public void whileRideRequestViewRunning_whenUnknownErrorOccurs_shouldReceiveUnknownError() { - boolean shouldOverrideUrlLoading = client.shouldOverrideUrlLoading(mock(WebView.class), - "uberconnect://oauth#error=on_fire"); - verify(callback, times(1)).onErrorParsed(RideRequestViewError.UNKNOWN); - assertTrue(shouldOverrideUrlLoading); - } - - @Test - public void whileRideRequestViewRunning_whenRegionErrorOccurs_shouldReceiveRegionError() { - boolean shouldOverrideUrlLoading = client.shouldOverrideUrlLoading(mock(WebView.class), - "uberconnect://oauth#error=wrong_region"); - verify(callback, times(1)).onErrorParsed(RideRequestViewError.WRONG_REGION); - assertTrue(shouldOverrideUrlLoading); - } - - @Test - public void shouldOverrideUrlLoading_whenHttpUrl_shouldNotOverride() { - assertFalse(client.shouldOverrideUrlLoading(mock(WebView.class), "http://uber.com")); - verifyZeroInteractions(callback); - } - - @Test - public void shouldOverrideUrlLoading_whenHttpsUrl_shouldNotOverride() { - assertFalse(client.shouldOverrideUrlLoading(mock(WebView.class), "https://uber.com")); - verifyZeroInteractions(callback); - } - - @Test - public void shouldOverrideUrlLoading_whenNonHttpOrRedirect_shouldOverrideAndLaunchActivity() { - Activity activity = Robolectric.setupActivity(Activity.class); - ShadowActivity shadowActivity = shadowOf(activity); - RideRequestView rideRequestView = new RideRequestView(activity); - - client = rideRequestView.new RideRequestWebViewClient(callback); - - assertTrue(client.shouldOverrideUrlLoading(mock(WebView.class), "tel:+91555555555")); - verifyZeroInteractions(callback); - Intent startedIntent = shadowActivity.getNextStartedActivity(); - assertEquals(Intent.ACTION_VIEW, startedIntent.getAction()); - assertEquals("tel:+91555555555#Intent;action=android.intent.action.VIEW;end", startedIntent.toUri(0)); - } -} diff --git a/samples/login-sample/build.gradle b/samples/login-sample/build.gradle index 92ab2e3e..a7ba0d03 100644 --- a/samples/login-sample/build.gradle +++ b/samples/login-sample/build.gradle @@ -60,7 +60,7 @@ dependencies { /** * Loads property from gradle.properties and ~/.gradle/gradle.properties - * Use to look up confidential information like keys that shoudln't be stored publicly + * Use to look up confidential information like keys that shouldn't be stored publicly * @param name to lookup * @return the value of the property or "MISSING" */ diff --git a/samples/login-sample/src/main/AndroidManifest.xml b/samples/login-sample/src/main/AndroidManifest.xml index 3bb26e75..c4f47e92 100644 --- a/samples/login-sample/src/main/AndroidManifest.xml +++ b/samples/login-sample/src/main/AndroidManifest.xml @@ -22,8 +22,7 @@ --> + package="com.uber.sdk.android.samples" > @@ -40,5 +39,4 @@ - diff --git a/samples/login-sample/src/main/java/com/uber/sdk/android/samples/LoginSampleActivity.java b/samples/login-sample/src/main/java/com/uber/sdk/android/samples/LoginSampleActivity.java index 1123de90..a87127c6 100644 --- a/samples/login-sample/src/main/java/com/uber/sdk/android/samples/LoginSampleActivity.java +++ b/samples/login-sample/src/main/java/com/uber/sdk/android/samples/LoginSampleActivity.java @@ -41,8 +41,6 @@ import com.uber.sdk.android.core.auth.LoginButton; import com.uber.sdk.android.core.auth.LoginCallback; import com.uber.sdk.android.core.auth.LoginManager; -import com.uber.sdk.android.rides.samples.BuildConfig; -import com.uber.sdk.android.rides.samples.R; import com.uber.sdk.core.auth.AccessToken; import com.uber.sdk.core.auth.AccessTokenStorage; import com.uber.sdk.core.auth.Scope; @@ -84,14 +82,13 @@ public class LoginSampleActivity extends AppCompatActivity { private Button customButton; private AccessTokenStorage accessTokenStorage; private LoginManager loginManager; - private SessionConfiguration configuration; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sample); - configuration = new SessionConfiguration.Builder() + SessionConfiguration configuration = new SessionConfiguration.Builder() .setClientId(CLIENT_ID) .setRedirectUri(REDIRECT_URI) .setScopes(Arrays.asList(Scope.PROFILE, Scope.RIDE_WIDGETS)) @@ -102,26 +99,25 @@ protected void onCreate(Bundle savedInstanceState) { accessTokenStorage = new AccessTokenManager(this); //Create a button with a custom request code - whiteButton = (LoginButton) findViewById(R.id.uber_button_white); + whiteButton = findViewById(R.id.uber_button_white); whiteButton.setCallback(new SampleLoginCallback()) .setSessionConfiguration(configuration); //Create a button using a custom AccessTokenStorage //Custom Scopes are set using XML for this button as well in R.layout.activity_sample - blackButton = (LoginButton) findViewById(R.id.uber_button_black); + blackButton = findViewById(R.id.uber_button_black); blackButton.setAccessTokenStorage(accessTokenStorage) .setCallback(new SampleLoginCallback()) .setSessionConfiguration(configuration) .setRequestCode(LOGIN_BUTTON_CUSTOM_REQUEST_CODE); - //Use a custom button with an onClickListener to call the LoginManager directly loginManager = new LoginManager(accessTokenStorage, new SampleLoginCallback(), configuration, CUSTOM_BUTTON_REQUEST_CODE); - customButton = (Button) findViewById(R.id.custom_uber_button); + customButton = findViewById(R.id.custom_uber_button); customButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { diff --git a/samples/login-sample/src/main/res/layout/activity_sample.xml b/samples/login-sample/src/main/res/layout/activity_sample.xml index 3056cd52..8a58591f 100644 --- a/samples/login-sample/src/main/res/layout/activity_sample.xml +++ b/samples/login-sample/src/main/res/layout/activity_sample.xml @@ -42,7 +42,6 @@ android:layout_gravity="center" uber:ub__request_code="1111" uber:ub__style="white" /> - - Copy Access Token to Clipboard Clear Access Token User cancels login - Error occured during login: %s + Error occurred during login: %s I want to sign in using my Uber app. Received an authorization code:\n %s Hello %s! diff --git a/samples/request-button-sample/src/main/java/com/uber/sdk/android/rides/samples/SampleActivity.java b/samples/request-button-sample/src/main/java/com/uber/sdk/android/rides/samples/SampleActivity.java index bfaebc9a..be7130a8 100644 --- a/samples/request-button-sample/src/main/java/com/uber/sdk/android/rides/samples/SampleActivity.java +++ b/samples/request-button-sample/src/main/java/com/uber/sdk/android/rides/samples/SampleActivity.java @@ -22,11 +22,9 @@ package com.uber.sdk.android.rides.samples; -import android.app.Activity; import android.content.ClipData; import android.content.ClipboardManager; import android.content.Context; -import android.content.Intent; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.util.Log; @@ -36,13 +34,9 @@ import com.uber.sdk.android.core.Deeplink; import com.uber.sdk.android.core.auth.AccessTokenManager; -import com.uber.sdk.android.core.auth.AuthenticationError; import com.uber.sdk.android.rides.RideParameters; -import com.uber.sdk.android.rides.RideRequestActivity; -import com.uber.sdk.android.rides.RideRequestActivityBehavior; import com.uber.sdk.android.rides.RideRequestButton; import com.uber.sdk.android.rides.RideRequestButtonCallback; -import com.uber.sdk.android.rides.RideRequestViewError; import com.uber.sdk.core.auth.AccessToken; import com.uber.sdk.core.auth.AccessTokenStorage; import com.uber.sdk.core.client.ServerTokenSession; @@ -61,27 +55,24 @@ public class SampleActivity extends AppCompatActivity implements RideRequestButt private static final Double DROPOFF_LAT = 37.795079; private static final Double DROPOFF_LONG = -122.397805; private static final String DROPOFF_NICK = "Embarcadero"; - private static final String ERROR_LOG_TAG = "UberSDK-SampleActivity"; private static final String PICKUP_ADDR = "1455 Market Street, San Francisco"; private static final Double PICKUP_LAT = 37.775304; private static final Double PICKUP_LONG = -122.417522; private static final String PICKUP_NICK = "Uber HQ"; private static final String UBERX_PRODUCT_ID = "a1111c8c-c720-46c3-8534-2fcdd730040d"; - private static final int WIDGET_REQUEST_CODE = 1234; private static final String CLIENT_ID = BuildConfig.CLIENT_ID; private static final String REDIRECT_URI = BuildConfig.REDIRECT_URI; private static final String SERVER_TOKEN = BuildConfig.SERVER_TOKEN; private RideRequestButton blackButton; - private SessionConfiguration configuration; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_sample); - configuration = new SessionConfiguration.Builder() + SessionConfiguration configuration = new SessionConfiguration.Builder() .setRedirectUri(REDIRECT_URI) .setClientId(CLIENT_ID) .setServerToken(SERVER_TOKEN) @@ -103,11 +94,6 @@ protected void onCreate(Bundle savedInstanceState) { blackButton.setCallback(this); blackButton.loadRideInformation(); - RideParameters rideParametersCheapestProduct = new RideParameters.Builder() - .setPickupLocation(PICKUP_LAT, PICKUP_LONG, PICKUP_NICK, PICKUP_ADDR) - .setDropoffLocation(DROPOFF_LAT, DROPOFF_LONG, DROPOFF_NICK, DROPOFF_ADDR) - .build(); - RideRequestButton uberButtonWhite = (RideRequestButton) findViewById(R.id.uber_button_white); uberButtonWhite.setRideParameters(rideParametersForProduct); uberButtonWhite.setSession(session);