Skip to content

Added setLockOrientation for activities #1839

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

Merged
merged 14 commits into from
Sep 29, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
- Add ability to always skip provider choice (#1825) (contributed by @ubragg)
- Fix a bug with `isNewUser` for some providers (#1737) (contributed by @laurentiu-git)
- Add ability to lock the Orientation (#1834) (contributed by @laurentiu-git)
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("SourceLockedOrientationActivity")
private void lockOrientation() {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}
}
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