-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
W-16171426: [Android] Update Native Login Sample App to include QR Co…
…de Login Flow (Comment Out Log In Via UI Bridge API Generated QR Codes)
- Loading branch information
1 parent
33b5536
commit 3d60973
Showing
8 changed files
with
162 additions
and
169 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
144 changes: 72 additions & 72 deletions
144
...pp/src/main/java/com/salesforce/androidnativekotlintemplate/QrCodeEnabledLoginActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,72 +1,72 @@ | ||
package com.salesforce.androidnativekotlintemplate | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.view.View | ||
import android.view.View.VISIBLE | ||
import android.widget.Button | ||
import androidx.activity.result.ActivityResult | ||
import androidx.activity.result.ActivityResultLauncher | ||
import androidx.activity.result.contract.ActivityResultContracts | ||
import com.journeyapps.barcodescanner.ScanContract | ||
import com.journeyapps.barcodescanner.ScanIntentResult | ||
import com.journeyapps.barcodescanner.ScanOptions | ||
import com.salesforce.androidnativekotlintemplate.R.id.qr_login_button | ||
import com.salesforce.androidsdk.ui.LoginActivity | ||
|
||
/** | ||
* A subclass of Salesforce Mobile SDK's login activity that enables log in via | ||
* a Salesforce UI Bridge API generated QR code. If an app wishes not to use | ||
* this feature, this class can be removed and use the superclass directly. | ||
* | ||
*/ | ||
// Uncomment when enabling log in via Salesforce UI Bridge API generated QR codes | ||
class QrCodeEnabledLoginActivity : LoginActivity() { | ||
|
||
// region Activity Implementation | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
findViewById<Button>(qr_login_button).visibility = VISIBLE | ||
prepareQRReader() | ||
} | ||
|
||
// endregion | ||
// region User Interface Events | ||
|
||
/** | ||
* An action for the "Log In With QR" button. | ||
* @param view The button that the user tapped | ||
*/ | ||
fun onQRLoginClick(@Suppress("UNUSED_PARAMETER") view: View?) = startQrCodeReader() | ||
|
||
// endregion | ||
// region Private Implementation For QR Code Log In | ||
|
||
private var qrCodeReaderActivityResultLauncher: ActivityResultLauncher<Intent>? = null | ||
|
||
private fun prepareQRReader() { | ||
qrCodeReaderActivityResultLauncher = registerForActivityResult( | ||
ActivityResultContracts.StartActivityForResult() | ||
) { resultData: ActivityResult -> | ||
if (resultData.resultCode == RESULT_OK) { | ||
|
||
val result = ScanIntentResult.parseActivityResult( | ||
resultData.resultCode, | ||
resultData.data | ||
) | ||
|
||
result.contents?.let { qrCodeContent -> | ||
loginFromQrCode(qrCodeContent) | ||
} | ||
} | ||
} | ||
} | ||
|
||
private fun startQrCodeReader() { | ||
qrCodeReaderActivityResultLauncher?.launch(ScanContract().createIntent(this, ScanOptions())) | ||
} | ||
|
||
// endregion | ||
} | ||
//package com.salesforce.androidnativekotlintemplate | ||
// | ||
//import android.content.Intent | ||
//import android.os.Bundle | ||
//import android.view.View | ||
//import android.view.View.VISIBLE | ||
//import android.widget.Button | ||
//import androidx.activity.result.ActivityResult | ||
//import androidx.activity.result.ActivityResultLauncher | ||
//import androidx.activity.result.contract.ActivityResultContracts | ||
//import com.journeyapps.barcodescanner.ScanContract | ||
//import com.journeyapps.barcodescanner.ScanIntentResult | ||
//import com.journeyapps.barcodescanner.ScanOptions | ||
//import com.salesforce.androidnativekotlintemplate.R.id.qr_login_button | ||
//import com.salesforce.androidsdk.ui.LoginActivity | ||
// | ||
///** | ||
// * A subclass of Salesforce Mobile SDK's login activity that enables log in via | ||
// * a Salesforce UI Bridge API generated QR code. If an app wishes not to use | ||
// * this feature, this class can be removed and use the superclass directly. | ||
// * | ||
// */ | ||
// // Uncomment when enabling log in via Salesforce UI Bridge API generated QR codes | ||
//class QrCodeEnabledLoginActivity : LoginActivity() { | ||
// | ||
// // region Activity Implementation | ||
// | ||
// override fun onCreate(savedInstanceState: Bundle?) { | ||
// super.onCreate(savedInstanceState) | ||
// | ||
// findViewById<Button>(qr_login_button).visibility = VISIBLE | ||
// prepareQRReader() | ||
// } | ||
// | ||
// // endregion | ||
// // region User Interface Events | ||
// | ||
// /** | ||
// * An action for the "Log In With QR" button. | ||
// * @param view The button that the user tapped | ||
// */ | ||
// fun onQRLoginClick(@Suppress("UNUSED_PARAMETER") view: View?) = startQrCodeReader() | ||
// | ||
// // endregion | ||
// // region Private Implementation For QR Code Log In | ||
// | ||
// private var qrCodeReaderActivityResultLauncher: ActivityResultLauncher<Intent>? = null | ||
// | ||
// private fun prepareQRReader() { | ||
// qrCodeReaderActivityResultLauncher = registerForActivityResult( | ||
// ActivityResultContracts.StartActivityForResult() | ||
// ) { resultData: ActivityResult -> | ||
// if (resultData.resultCode == RESULT_OK) { | ||
// | ||
// val result = ScanIntentResult.parseActivityResult( | ||
// resultData.resultCode, | ||
// resultData.data | ||
// ) | ||
// | ||
// result.contents?.let { qrCodeContent -> | ||
// loginFromQrCode(qrCodeContent) | ||
// } | ||
// } | ||
// } | ||
// } | ||
// | ||
// private fun startQrCodeReader() { | ||
// qrCodeReaderActivityResultLauncher?.launch(ScanContract().createIntent(this, ScanOptions())) | ||
// } | ||
// | ||
// // endregion | ||
//} |
146 changes: 73 additions & 73 deletions
146
AndroidNativeKotlinTemplate/app/src/main/res/layout/sf__login.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,79 +1,79 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- This override layout adds a "Log In With QR" button to enable log in via Salesforce UI Bridge API generated QR codes --> | ||
<!-- Uncomment when enabling log in via Salesforce UI Bridge API generated QR codes --> | ||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:id="@+id/sf__auth_container_phone" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:windowDrawsSystemBarBackgrounds="true"> | ||
<!--<?xml version="1.0" encoding="utf-8"?>--> | ||
<!--<!– This override layout adds a "Log In With QR" button to enable log in via Salesforce UI Bridge API generated QR codes –>--> | ||
<!--<!– Uncomment when enabling log in via Salesforce UI Bridge API generated QR codes –>--> | ||
<!--<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"--> | ||
<!-- android:id="@+id/sf__auth_container_phone"--> | ||
<!-- android:layout_width="match_parent"--> | ||
<!-- android:layout_height="match_parent"--> | ||
<!-- android:windowDrawsSystemBarBackgrounds="true">--> | ||
|
||
<ProgressBar | ||
android:id="@+id/sf__loading_spinner" | ||
android:layout_width="wrap_content" | ||
android:layout_height="wrap_content" | ||
android:layout_centerInParent="true" /> | ||
<!-- <ProgressBar--> | ||
<!-- android:id="@+id/sf__loading_spinner"--> | ||
<!-- android:layout_width="wrap_content"--> | ||
<!-- android:layout_height="wrap_content"--> | ||
<!-- android:layout_centerInParent="true" />--> | ||
|
||
<WebView | ||
android:id="@+id/sf__oauth_webview" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:scrollbars="none" | ||
android:visibility="gone" | ||
android:windowDrawsSystemBarBackgrounds="true" /> | ||
<!-- <WebView--> | ||
<!-- android:id="@+id/sf__oauth_webview"--> | ||
<!-- android:layout_width="match_parent"--> | ||
<!-- android:layout_height="match_parent"--> | ||
<!-- android:scrollbars="none"--> | ||
<!-- android:visibility="gone"--> | ||
<!-- android:windowDrawsSystemBarBackgrounds="true" />--> | ||
|
||
<LinearLayout | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_alignParentEnd="true" | ||
android:layout_alignParentBottom="true" | ||
android:orientation="vertical"> | ||
<!-- <LinearLayout--> | ||
<!-- android:layout_width="match_parent"--> | ||
<!-- android:layout_height="wrap_content"--> | ||
<!-- android:layout_alignParentEnd="true"--> | ||
<!-- android:layout_alignParentBottom="true"--> | ||
<!-- android:orientation="vertical">--> | ||
|
||
<Button | ||
android:id="@+id/sf__idp_login_button" | ||
android:layout_width="match_parent" | ||
android:layout_height="50dp" | ||
android:layout_marginLeft="20dp" | ||
android:layout_marginRight="20dp" | ||
android:layout_marginBottom="20dp" | ||
android:background="@drawable/sf__primary_color_button" | ||
android:onClick="onIDPLoginClick" | ||
android:text="@string/sf__launch_idp" | ||
android:textAllCaps="false" | ||
android:textColor="?attr/sfColorSecondary" | ||
android:textSize="14sp" | ||
android:textStyle="bold" | ||
android:visibility="gone" /> | ||
<!-- <Button--> | ||
<!-- android:id="@+id/sf__idp_login_button"--> | ||
<!-- android:layout_width="match_parent"--> | ||
<!-- android:layout_height="50dp"--> | ||
<!-- android:layout_marginLeft="20dp"--> | ||
<!-- android:layout_marginRight="20dp"--> | ||
<!-- android:layout_marginBottom="20dp"--> | ||
<!-- android:background="@drawable/sf__primary_color_button"--> | ||
<!-- android:onClick="onIDPLoginClick"--> | ||
<!-- android:text="@string/sf__launch_idp"--> | ||
<!-- android:textAllCaps="false"--> | ||
<!-- android:textColor="?attr/sfColorSecondary"--> | ||
<!-- android:textSize="14sp"--> | ||
<!-- android:textStyle="bold"--> | ||
<!-- android:visibility="gone" />--> | ||
|
||
<Button | ||
android:id="@+id/sf__bio_login_button" | ||
android:layout_width="match_parent" | ||
android:layout_height="50dp" | ||
android:layout_marginLeft="20dp" | ||
android:layout_marginRight="20dp" | ||
android:layout_marginBottom="20dp" | ||
android:background="@drawable/sf__primary_color_button" | ||
android:onClick="onBioAuthClick" | ||
android:text="@string/sf__login_with_biometric" | ||
android:textAllCaps="false" | ||
android:textColor="?attr/sfColorSecondary" | ||
android:textSize="14sp" | ||
android:textStyle="bold" | ||
android:visibility="gone" /> | ||
<!-- <Button--> | ||
<!-- android:id="@+id/sf__bio_login_button"--> | ||
<!-- android:layout_width="match_parent"--> | ||
<!-- android:layout_height="50dp"--> | ||
<!-- android:layout_marginLeft="20dp"--> | ||
<!-- android:layout_marginRight="20dp"--> | ||
<!-- android:layout_marginBottom="20dp"--> | ||
<!-- android:background="@drawable/sf__primary_color_button"--> | ||
<!-- android:onClick="onBioAuthClick"--> | ||
<!-- android:text="@string/sf__login_with_biometric"--> | ||
<!-- android:textAllCaps="false"--> | ||
<!-- android:textColor="?attr/sfColorSecondary"--> | ||
<!-- android:textSize="14sp"--> | ||
<!-- android:textStyle="bold"--> | ||
<!-- android:visibility="gone" />--> | ||
|
||
<Button | ||
android:id="@+id/qr_login_button" | ||
android:layout_width="match_parent" | ||
android:layout_height="50dp" | ||
android:layout_marginLeft="20dp" | ||
android:layout_marginRight="20dp" | ||
android:layout_marginBottom="20dp" | ||
android:background="@drawable/sf__primary_color_button" | ||
android:onClick="onQRLoginClick" | ||
android:text="@string/login_with_qr" | ||
android:textAllCaps="false" | ||
android:textColor="?attr/sfColorSecondary" | ||
android:textSize="14sp" | ||
android:textStyle="bold" | ||
android:visibility="gone" /> | ||
</LinearLayout> | ||
</RelativeLayout> | ||
<!-- <Button--> | ||
<!-- android:id="@+id/qr_login_button"--> | ||
<!-- android:layout_width="match_parent"--> | ||
<!-- android:layout_height="50dp"--> | ||
<!-- android:layout_marginLeft="20dp"--> | ||
<!-- android:layout_marginRight="20dp"--> | ||
<!-- android:layout_marginBottom="20dp"--> | ||
<!-- android:background="@drawable/sf__primary_color_button"--> | ||
<!-- android:onClick="onQRLoginClick"--> | ||
<!-- android:text="@string/login_with_qr"--> | ||
<!-- android:textAllCaps="false"--> | ||
<!-- android:textColor="?attr/sfColorSecondary"--> | ||
<!-- android:textSize="14sp"--> | ||
<!-- android:textStyle="bold"--> | ||
<!-- android:visibility="gone" />--> | ||
<!-- </LinearLayout>--> | ||
<!--</RelativeLayout>--> |
4 changes: 2 additions & 2 deletions
4
AndroidNativeKotlinTemplate/app/src/main/res/values/bootconfig.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.