Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added setLockOrientation for activities #1839

Merged
merged 14 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions auth/src/main/java/com/firebase/ui/auth/AuthUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -1207,6 +1207,7 @@ private abstract class AuthIntentBuilder<T extends AuthIntentBuilder> {
String mTosUrl;
String mPrivacyPolicyUrl;
boolean mAlwaysShowProviderChoice = false;
boolean mLockOrientation = false;
boolean mEnableCredentials = true;
boolean mEnableHints = true;
AuthMethodPickerLayout mAuthMethodPickerLayout = null;
Expand Down Expand Up @@ -1391,6 +1392,20 @@ public T setAlwaysShowSignInMethodScreen(boolean alwaysShow) {
return (T) this;
}

/**
* Enable or disables the orientation for small devices to be locked in
* Portrait orientation
* <p>
* <p>This is false by default.
*
* @param lockOrientation if true, force the activities to be in Portrait orientation.
*/
@NonNull
public T setLockOrientation(boolean lockOrientation) {
mLockOrientation = lockOrientation;
return (T) this;
}

@CallSuper
@NonNull
public Intent build() {
Expand Down Expand Up @@ -1468,6 +1483,7 @@ protected FlowParameters getFlowParams() {
mEnableHints,
mEnableAnonymousUpgrade,
mAlwaysShowProviderChoice,
mLockOrientation,
mEmailLink,
mAuthMethodPickerLayout);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public FlowParameters createFromParcel(Parcel in) {
boolean enableHints = in.readInt() != 0;
boolean enableAnonymousUpgrade = in.readInt() != 0;
boolean alwaysShowProviderChoice = in.readInt() != 0;
boolean lockOrientation = in.readInt() != 0;
String emailLink = in.readString();
AuthMethodPickerLayout customLayout = in.readParcelable(AuthMethodPickerLayout.class.getClassLoader());

Expand All @@ -68,6 +69,7 @@ public FlowParameters createFromParcel(Parcel in) {
enableHints,
enableAnonymousUpgrade,
alwaysShowProviderChoice,
lockOrientation,
emailLink,
customLayout);
}
Expand Down Expand Up @@ -106,6 +108,7 @@ public FlowParameters[] newArray(int size) {
public final boolean enableHints;
public final boolean enableAnonymousUpgrade;
public final boolean alwaysShowProviderChoice;
public final boolean lockOrientation;

@Nullable
public final AuthMethodPickerLayout authMethodPickerLayout;
Expand All @@ -122,6 +125,7 @@ public FlowParameters(
boolean enableHints,
boolean enableAnonymousUpgrade,
boolean alwaysShowProviderChoice,
boolean lockOrientation,
@Nullable String emailLink,
@Nullable AuthMethodPickerLayout authMethodPickerLayout) {
this.appName = Preconditions.checkNotNull(appName, "appName cannot be null");
Expand All @@ -136,6 +140,7 @@ public FlowParameters(
this.enableHints = enableHints;
this.enableAnonymousUpgrade = enableAnonymousUpgrade;
this.alwaysShowProviderChoice = alwaysShowProviderChoice;
this.lockOrientation = lockOrientation;
this.emailLink = emailLink;
this.authMethodPickerLayout = authMethodPickerLayout;
}
Expand All @@ -160,6 +165,7 @@ public void writeToParcel(Parcel dest, int flags) {
dest.writeInt(enableHints ? 1 : 0);
dest.writeInt(enableAnonymousUpgrade ? 1 : 0);
dest.writeInt(alwaysShowProviderChoice ? 1 : 0);
dest.writeInt(lockOrientation ? 1 : 0);
dest.writeString(emailLink);
dest.writeParcelable(authMethodPickerLayout, flags);
}
Expand Down
11 changes: 11 additions & 0 deletions auth/src/main/java/com/firebase/ui/auth/ui/AppCompatBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

package com.firebase.ui.auth.ui;

import android.annotation.SuppressLint;
import android.content.pm.ActivityInfo;
import android.os.Bundle;

import com.firebase.ui.auth.R;
Expand All @@ -31,6 +33,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.FirebaseUI); // Provides default values
setTheme(getFlowParams().themeId);

if (getFlowParams().lockOrientation) {
lockOrientation();
}
}

protected void switchFragment(@NonNull Fragment fragment,
Expand All @@ -53,4 +59,9 @@ protected void switchFragment(@NonNull Fragment fragment,
protected void switchFragment(@NonNull Fragment fragment, int fragmentId, @NonNull String tag) {
switchFragment(fragment, fragmentId, tag, false, false);
}

@SuppressLint("all")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we actually need this @SuppressLint anymore? If so can we be more specific than all?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without @SuppressLint when running gradlew check it gives the following error and I don't know how suppress it.

Error: You should not lock orientation of your activities, so that you can support a good user experience for any device or orientation [SourceLockedOrientationActivity]
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So then could it be @SuppressLint("SourceLockedOrientationActivity")?

private void lockOrientation() {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.firebase.ui.auth.ui;


import android.app.Activity;
import android.content.Context;
import android.content.Intent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@

package com.firebase.ui.auth.ui.idp;

import android.annotation.SuppressLint;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no changes in this file anymore besides these two imports and some whitespace, so maybe we can revert the whole file?

import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
Expand Down Expand Up @@ -101,7 +103,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
mHandler = ViewModelProviders.of(this).get(SocialProviderResponseHandler.class);
mHandler.init(params);


mProviders = new ArrayList<>();
if (customLayout != null) {
setContentView(customLayout.getMainLayout());
Expand Down Expand Up @@ -270,6 +271,8 @@ private String providerOrEmailLinkProvider(@NonNull String providerId) {
return providerId;
}



private void handleSignInOperation(final IdpConfig idpConfig, View view) {
ViewModelProvider supplier = ViewModelProviders.of(this);
final String providerId = idpConfig.getProviderId();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public static FlowParameters getFlowParameters(Collection<String> providerIds,
true,
enableAnonymousUpgrade,
false,
true,
null,
customLayout);
}
Expand Down