Skip to content

Commit c3badea

Browse files
Added setLockOrientation for activities (#1839)
1 parent 25dea9d commit c3badea

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
- Add ability to always skip provider choice (#1825) (contributed by @ubragg)
22
- Fix a bug with `isNewUser` for some providers (#1737) (contributed by @laurentiu-git)
3+
- Add ability to lock the Orientation (#1834) (contributed by @laurentiu-git)

auth/src/main/java/com/firebase/ui/auth/AuthUI.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,6 +1207,7 @@ private abstract class AuthIntentBuilder<T extends AuthIntentBuilder> {
12071207
String mTosUrl;
12081208
String mPrivacyPolicyUrl;
12091209
boolean mAlwaysShowProviderChoice = false;
1210+
boolean mLockOrientation = false;
12101211
boolean mEnableCredentials = true;
12111212
boolean mEnableHints = true;
12121213
AuthMethodPickerLayout mAuthMethodPickerLayout = null;
@@ -1391,6 +1392,20 @@ public T setAlwaysShowSignInMethodScreen(boolean alwaysShow) {
13911392
return (T) this;
13921393
}
13931394

1395+
/**
1396+
* Enable or disables the orientation for small devices to be locked in
1397+
* Portrait orientation
1398+
* <p>
1399+
* <p>This is false by default.
1400+
*
1401+
* @param lockOrientation if true, force the activities to be in Portrait orientation.
1402+
*/
1403+
@NonNull
1404+
public T setLockOrientation(boolean lockOrientation) {
1405+
mLockOrientation = lockOrientation;
1406+
return (T) this;
1407+
}
1408+
13941409
@CallSuper
13951410
@NonNull
13961411
public Intent build() {
@@ -1468,6 +1483,7 @@ protected FlowParameters getFlowParams() {
14681483
mEnableHints,
14691484
mEnableAnonymousUpgrade,
14701485
mAlwaysShowProviderChoice,
1486+
mLockOrientation,
14711487
mEmailLink,
14721488
mAuthMethodPickerLayout);
14731489
}

auth/src/main/java/com/firebase/ui/auth/data/model/FlowParameters.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public FlowParameters createFromParcel(Parcel in) {
5353
boolean enableHints = in.readInt() != 0;
5454
boolean enableAnonymousUpgrade = in.readInt() != 0;
5555
boolean alwaysShowProviderChoice = in.readInt() != 0;
56+
boolean lockOrientation = in.readInt() != 0;
5657
String emailLink = in.readString();
5758
AuthMethodPickerLayout customLayout = in.readParcelable(AuthMethodPickerLayout.class.getClassLoader());
5859

@@ -68,6 +69,7 @@ public FlowParameters createFromParcel(Parcel in) {
6869
enableHints,
6970
enableAnonymousUpgrade,
7071
alwaysShowProviderChoice,
72+
lockOrientation,
7173
emailLink,
7274
customLayout);
7375
}
@@ -106,6 +108,7 @@ public FlowParameters[] newArray(int size) {
106108
public final boolean enableHints;
107109
public final boolean enableAnonymousUpgrade;
108110
public final boolean alwaysShowProviderChoice;
111+
public final boolean lockOrientation;
109112

110113
@Nullable
111114
public final AuthMethodPickerLayout authMethodPickerLayout;
@@ -122,6 +125,7 @@ public FlowParameters(
122125
boolean enableHints,
123126
boolean enableAnonymousUpgrade,
124127
boolean alwaysShowProviderChoice,
128+
boolean lockOrientation,
125129
@Nullable String emailLink,
126130
@Nullable AuthMethodPickerLayout authMethodPickerLayout) {
127131
this.appName = Preconditions.checkNotNull(appName, "appName cannot be null");
@@ -136,6 +140,7 @@ public FlowParameters(
136140
this.enableHints = enableHints;
137141
this.enableAnonymousUpgrade = enableAnonymousUpgrade;
138142
this.alwaysShowProviderChoice = alwaysShowProviderChoice;
143+
this.lockOrientation = lockOrientation;
139144
this.emailLink = emailLink;
140145
this.authMethodPickerLayout = authMethodPickerLayout;
141146
}
@@ -160,6 +165,7 @@ public void writeToParcel(Parcel dest, int flags) {
160165
dest.writeInt(enableHints ? 1 : 0);
161166
dest.writeInt(enableAnonymousUpgrade ? 1 : 0);
162167
dest.writeInt(alwaysShowProviderChoice ? 1 : 0);
168+
dest.writeInt(lockOrientation ? 1 : 0);
163169
dest.writeString(emailLink);
164170
dest.writeParcelable(authMethodPickerLayout, flags);
165171
}

auth/src/main/java/com/firebase/ui/auth/ui/AppCompatBase.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package com.firebase.ui.auth.ui;
1616

17+
import android.annotation.SuppressLint;
18+
import android.content.pm.ActivityInfo;
1719
import android.os.Bundle;
1820

1921
import com.firebase.ui.auth.R;
@@ -31,6 +33,10 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
3133
super.onCreate(savedInstanceState);
3234
setTheme(R.style.FirebaseUI); // Provides default values
3335
setTheme(getFlowParams().themeId);
36+
37+
if (getFlowParams().lockOrientation) {
38+
lockOrientation();
39+
}
3440
}
3541

3642
protected void switchFragment(@NonNull Fragment fragment,
@@ -53,4 +59,9 @@ protected void switchFragment(@NonNull Fragment fragment,
5359
protected void switchFragment(@NonNull Fragment fragment, int fragmentId, @NonNull String tag) {
5460
switchFragment(fragment, fragmentId, tag, false, false);
5561
}
62+
63+
@SuppressLint("SourceLockedOrientationActivity")
64+
private void lockOrientation() {
65+
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
66+
}
5667
}

auth/src/test/java/com/firebase/ui/auth/testhelpers/TestHelper.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@ public static FlowParameters getFlowParameters(Collection<String> providerIds,
166166
true,
167167
enableAnonymousUpgrade,
168168
false,
169+
true,
169170
null,
170171
customLayout);
171172
}

0 commit comments

Comments
 (0)