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

Android 15 Support - Part 2 of 2 #2624

Merged
merged 3 commits into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {
}

dependencies {
classpath("com.android.tools.build:gradle:8.5.0")
classpath("com.android.tools.build:gradle:8.6.1")
classpath("io.github.gradle-nexus:publish-plugin:1.1.0")
classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.24")
classpath("org.jacoco:org.jacoco.core:0.8.12")
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ repositories {
}

dependencies {
implementation("com.android.tools.build:gradle:8.5.0")
implementation("com.android.tools.build:gradle:8.6.1")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.9.24")
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.9.24")
}
4 changes: 2 additions & 2 deletions hybrid/HybridSampleApps/AccountEditor/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ dependencies {
android {
namespace = "com.salesforce.samples.accounteditor"

compileSdk = 34
compileSdk = 35

defaultConfig {
targetSdk = 34
targetSdk = 35
minSdk = 26
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ dependencies {
android {
namespace = "com.salesforce.samples.mobilesyncexplorerhybrid"

compileSdk = 34
compileSdk = 35

defaultConfig {
targetSdk = 34
targetSdk = 35
minSdk = 26
}

Expand Down
16 changes: 16 additions & 0 deletions libs/SalesforceSDK/res/drawable/sf__fix_status_bar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/sf__status_bar_background" android:height="100dp" >
<shape android:shape="rectangle">
<size android:height="100dp" android:width="100dp"/>
<solid android:color="@color/sf__primary_color"/>
</shape>
</item>

<item android:id="@+id/sf__nav_bar_background" android:height="100dp">
<shape android:shape="rectangle">
<size android:height="100dp" android:width="100dp"/>
<solid android:color="@android:color/transparent"/>
</shape>
</item>
</layer-list>
Comment on lines +1 to +16
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is sort of a hack to fill in the status and navigation bars with the appropriate color since they are now forced transparent and completely unsettable in Edge to Edge. Note that I am changing the height of the top rectangle to match the device status bar height in code!

4 changes: 3 additions & 1 deletion libs/SalesforceSDK/res/layout/sf__dev_info.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:id="@+id/sf__dev_menu_layout"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<ListView android:id="@+id/list" android:layout_width="match_parent"
Expand Down
1 change: 1 addition & 0 deletions libs/SalesforceSDK/res/layout/sf__server_picker.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/sf__server_picker_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:colorBackground" >
Expand Down
2 changes: 2 additions & 0 deletions libs/SalesforceSDK/res/values/sf__styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@

<style name="SalesforceSDK_Dark.Login">
<item name="android:navigationBarColor">@color/sf__background</item>
<item name="android:colorBackground">@color/sf__background</item>
</style>

<style name="SalesforceSDKActionBar" parent="@android:style/Widget.Material.ActionBar">
Expand Down Expand Up @@ -189,6 +190,7 @@
<item name="android:navigationBarColor">@color/sf__background_dark</item>
<item name="sfNegativeButtonTextColor">@color/sf__secondary_color_dark</item>
<item name="sfNegativeButtonBorderColor">@color/sf__secondary_color_dark</item>
<item name="android:windowLightStatusBar">false</item>
</style>

<style name="SalesforceSDK.ScreenLock.ErrorMessage">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ internal class IDPManager(
spConfig,
codeChallenge
) { result ->
authCodeActivity.finish()
onResult(result)
}
}
Expand Down Expand Up @@ -214,6 +213,7 @@ internal class IDPManager(
addCategory(Intent.CATEGORY_DEFAULT)
}
startActivity(activeFlow.context, launchIntent)
activeFlow.authCodeActivity?.finish()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The IDP fix.

} else {
activeFlow.onStatusUpdate(Status.ERROR_RECEIVED_FROM_SP)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
*/
package com.salesforce.androidsdk.ui;

import static com.salesforce.androidsdk.ui.EdgeToEdgeUtilKt.fixEdgeToEdge;

import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
Expand Down Expand Up @@ -67,6 +69,8 @@ public void onCreate(Bundle savedInstance) {
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_USER);
}

fixEdgeToEdge(this, findViewById(R.id.sf__account_select_layout));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
*/
package com.salesforce.androidsdk.ui;

import static com.salesforce.androidsdk.ui.EdgeToEdgeUtilKt.fixEdgeToEdge;

import android.os.Bundle;
import android.widget.ListView;
import android.widget.SimpleAdapter;
Expand Down Expand Up @@ -63,6 +65,8 @@ protected void onCreate(Bundle savedInstanceState) {
String[] from = new String[] {NAME, VALUE};
int[] to = new int[] { android.R.id.text1, android.R.id.text2};
((ListView) findViewById(R.id.list)).setAdapter(new SimpleAdapter(this, listData, android.R.layout.simple_list_item_2, from, to));

fixEdgeToEdge(this, findViewById(R.id.sf__dev_menu_layout));
}

private List<Map<String, String>> prepareListData(List<String> rawData) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.salesforce.androidsdk.ui

import android.graphics.drawable.LayerDrawable
import android.os.Build.VERSION_CODES.UPSIDE_DOWN_CAKE
import android.view.View
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.res.ResourcesCompat
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updatePadding
import com.salesforce.androidsdk.R.drawable.sf__fix_status_bar
import com.salesforce.androidsdk.R.id.sf__status_bar_background

// TODO: Remove this in 13.0 after rewriting screens in compose.
internal fun AppCompatActivity.fixEdgeToEdge(view: View) {
if (application.applicationInfo.targetSdkVersion > UPSIDE_DOWN_CAKE) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I should actually check this and SDK_INT so we don't do anything special on pre-Android 15 devices.

enableEdgeToEdge()
ViewCompat.setOnApplyWindowInsetsListener(view) { listenerView, windowInsets ->
val insets = windowInsets.getInsets(
WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout()
)

// Fix screens being drawn behind status and navigation bars
listenerView.updatePadding(insets.left, insets.top, insets.right, insets.bottom)

// Fix transparent status bar not matching action bar
val background = ResourcesCompat.getDrawable(resources, sf__fix_status_bar, null)
wmathurin marked this conversation as resolved.
Show resolved Hide resolved
val statusBarFiller = (background as LayerDrawable).findDrawableByLayerId(sf__status_bar_background)
statusBarFiller.setBounds(0, 0, insets.right, insets.bottom)
view.setBackgroundResource(sf__fix_status_bar)
wmathurin marked this conversation as resolved.
Show resolved Hide resolved

WindowInsetsCompat.CONSUMED
}
}
}
Copy link
Contributor Author

@brandonpage brandonpage Sep 28, 2024

Choose a reason for hiding this comment

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

This is where all of UX magic happens 🪄 ✨

Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ import androidx.biometric.BiometricPrompt.PromptInfo
import androidx.core.content.ContextCompat
import androidx.core.content.ContextCompat.getMainExecutor
import androidx.core.content.ContextCompat.registerReceiver
import com.salesforce.androidsdk.R.id.sf__auth_container_phone
import com.salesforce.androidsdk.R.id.sf__bio_login_button
import com.salesforce.androidsdk.R.id.sf__idp_login_button
import com.salesforce.androidsdk.R.id.sf__menu_clear_cookies
Expand Down Expand Up @@ -229,6 +230,8 @@ open class LoginActivity : AppCompatActivity(), OAuthWebviewHelperEvents {
requestedOrientation = if (salesforceSDKManager.compactScreen(this))
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT else
ActivityInfo.SCREEN_ORIENTATION_FULL_USER

fixEdgeToEdge(findViewById(sf__auth_container_phone))
}

override fun onDestroy() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
*/
package com.salesforce.androidsdk.ui;

import static com.salesforce.androidsdk.ui.EdgeToEdgeUtilKt.fixEdgeToEdge;

import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
Expand Down Expand Up @@ -53,6 +55,7 @@ public void onCreate(Bundle savedState) {
manageSpaceDialog = buildManageSpaceDialog();
manageSpaceDialog.setCanceledOnTouchOutside(false);
manageSpaceDialog.show();
fixEdgeToEdge(this, findViewById(R.id.manage_space_layout));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import android.widget.TextView;
import android.window.OnBackInvokedDispatcher;

import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.biometric.BiometricManager;
import androidx.biometric.BiometricPrompt;
Expand Down Expand Up @@ -82,6 +83,8 @@ public class ScreenLockActivity extends FragmentActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);

// Protect against screenshots.
getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,
WindowManager.LayoutParams.FLAG_SECURE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
package com.salesforce.androidsdk.ui;

import static com.salesforce.androidsdk.security.BiometricAuthenticationManager.SHOW_BIOMETRIC;
import static com.salesforce.androidsdk.ui.EdgeToEdgeUtilKt.fixEdgeToEdge;

import android.app.Activity;
import android.content.Intent;
Expand Down Expand Up @@ -149,6 +150,8 @@ public void onCreate(Bundle savedInstanceState) {
} else {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_FULL_USER);
}

fixEdgeToEdge(this, findViewById(R.id.sf__server_picker_layout));
}

@Override
Expand Down
4 changes: 2 additions & 2 deletions native/NativeSampleApps/AppConfigurator/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ dependencies {
android {
namespace = "com.salesforce.samples.appconfigurator"

compileSdk = 34
compileSdk = 35

defaultConfig {
targetSdk = 34
targetSdk = 35
minSdk = 26
}

Expand Down
4 changes: 2 additions & 2 deletions native/NativeSampleApps/ConfiguredApp/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ dependencies {
android {
namespace = "com.salesforce.samples.configuredapp"

compileSdk = 34
compileSdk = 35

defaultConfig {
targetSdk = 34
targetSdk = 35
minSdk = 26
}

Expand Down
4 changes: 2 additions & 2 deletions native/NativeSampleApps/RestExplorer/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ android {
namespace = "com.salesforce.samples.restexplorer"
testNamespace = "com.salesforce.samples.restexplorer.tests"

compileSdk = 34
compileSdk = 35

defaultConfig {
targetSdk = 34
targetSdk = 35
minSdk = 26
}

Expand Down