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

feat(android15) : Support Android 15 SDK-3997 #664

Open
wants to merge 29 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
46cc156
feat(android15) : update android sdk versions SDK-3960
piyush-kukadiya Aug 6, 2024
acf4242
chore(lint) : fix build error related to test_shared package SDK-4011
piyush-kukadiya Aug 20, 2024
37c96fa
chore(lint) : fix build error related to instant-app package SDK-4011
piyush-kukadiya Aug 20, 2024
91dff4a
chore(lint) : fix build error related to instant-app compileSdk versi…
piyush-kukadiya Aug 20, 2024
401c96d
chore(lint) : update Project versions in toml file SDK-4011
piyush-kukadiya Aug 20, 2024
e62758a
chore(lint) : update AndroidX versions in toml file SDK-4011
piyush-kukadiya Aug 20, 2024
129cb17
chore(lint) : change ExistingPeriodicWorkPolicy REPLACE to UPDATE as …
piyush-kukadiya Aug 20, 2024
1180e18
feat(Android15) : fix tests failures due to OPENJDK API changes in An…
piyush-kukadiya Aug 21, 2024
1b72b0a
feat(Android15) : bump material, media3 and all unit test dependencie…
piyush-kukadiya Aug 21, 2024
23e364e
feat(Android15) : bump google and huawei dependencies SDK-4011
piyush-kukadiya Aug 22, 2024
107b3a3
feat(Android15) : add unit tests for String format() due to OpenJDK c…
piyush-kukadiya Aug 22, 2024
a8f6313
feat(Android15) : replace Dialog with ComponentDialog and remove depr…
piyush-kukadiya Aug 23, 2024
f192f80
feat(Android15) : remove optionsBundle while creating activity pendin…
piyush-kukadiya Aug 23, 2024
2d1e833
feat(Android15) : add edge-to-edge and display cutout support for inb…
piyush-kukadiya Aug 26, 2024
11b14c6
feat(Android15) : add edge-to-edge and display cutout support for htm…
piyush-kukadiya Aug 26, 2024
93c2d95
feat(Android15) : add edge-to-edge and display cutout support below O…
piyush-kukadiya Aug 27, 2024
0ad807c
feat(Android15) : add edge-to-edge and display cutout support for nat…
piyush-kukadiya Aug 27, 2024
51013d8
feat(Android15) : add edge-to-edge and display cutout support for nat…
piyush-kukadiya Aug 28, 2024
670b0be
chore(Android15) : remove unused imports SDK-4004
piyush-kukadiya Sep 3, 2024
274a1d8
Merge branch 'refs/heads/develop' into feat/android_15/SDK-3960
piyush-kukadiya Sep 3, 2024
4589097
chore(Android15) : update sample app to support Android 15 SDK-4041
piyush-kukadiya Sep 4, 2024
18a8d02
feat(Android15) : update AGP to 8.6.0 SDK-4041
piyush-kukadiya Sep 5, 2024
acf5044
feat(Android15) : update gradle to 8.10 SDK-4041
piyush-kukadiya Sep 5, 2024
dc0283a
chore(Android15) : remove redundant logging SDK-4041
piyush-kukadiya Sep 10, 2024
5b7c660
chore(Android15) : remove redundant tests SDK-4041
piyush-kukadiya Sep 10, 2024
c301c4c
chore(Android15) : add comments for setupStrictMode() SDK-4041
piyush-kukadiya Sep 10, 2024
c98e97d
chore(Android15) : rename method name of applySystemBarsInsetsWithMar…
piyush-kukadiya Sep 10, 2024
7431190
chore(Android15) : bump versions in instant-app SDK-4041
piyush-kukadiya Sep 11, 2024
051d25c
Merge branch 'develop' into feat/android_15/SDK-3960
CTLalit Oct 1, 2024
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 build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ buildscript {

plugins {
alias(libs.plugins.sonarqube)
alias(libs.plugins.compose.compiler) apply false
}
allprojects {
repositories {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ import android.content.SharedPreferences
import android.location.Location
import android.os.Build.VERSION
import android.os.Build.VERSION_CODES
import android.view.View
import android.view.ViewGroup.MarginLayoutParams
import androidx.annotation.MainThread
import androidx.annotation.RequiresApi
import androidx.annotation.WorkerThread
import androidx.core.app.NotificationManagerCompat
import androidx.core.graphics.Insets
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.updateLayoutParams
import com.clevertap.android.sdk.events.EventGroup.PUSH_NOTIFICATION_VIEWED
import com.clevertap.android.sdk.task.CTExecutorFactory
import org.json.JSONArray
Expand Down Expand Up @@ -299,3 +305,40 @@ fun String?.toJsonOrNull(): JSONObject? {
}
}
}

/**
* Adjusts the margins of the view based on the system bar insets (such as the status bar, navigation bar,
* or display cutout) using the provided margin adjustment logic.
*
* This function sets a listener on the view to handle window insets and invokes the provided `marginAdjuster`
* block to allow custom margin adjustments. The `marginAdjuster` lambda receives the system bar insets and
* the view's margin layout parameters, allowing the caller to modify the margins as needed.
*
* @param marginAdjuster A lambda function that takes two parameters:
* - `bars`: The insets for system bars and display cutouts, representing the space occupied by UI elements
* such as the status bar or navigation bar.
* - `mlp`: The `MarginLayoutParams` of the view, which can be modified to adjust the margins based on the insets.
*
* Example usage:
* ```
* view.applyInsetsWithMarginAdjustment { insets, layoutParams ->
* layoutParams.leftMargin = insets.left
* layoutParams.rightMargin = insets.right
* layoutParams.topMargin = insets.top
* layoutParams.bottomMargin = insets.bottom
* }
* ```
*/
fun View.applyInsetsWithMarginAdjustment(marginAdjuster : (insets:Insets, mlp:MarginLayoutParams) -> Unit) {
ViewCompat.setOnApplyWindowInsetsListener(this
) { v, insets ->
val bars: Insets = insets.getInsets(
Anush-Shand marked this conversation as resolved.
Show resolved Hide resolved
WindowInsetsCompat.Type.systemBars() or WindowInsetsCompat.Type.displayCutout()
piyush-kukadiya marked this conversation as resolved.
Show resolved Hide resolved
)
v.updateLayoutParams<MarginLayoutParams> {
marginAdjuster(bars,this)
}
WindowInsetsCompat.CONSUMED
piyush-kukadiya marked this conversation as resolved.
Show resolved Hide resolved
}
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
package com.clevertap.android.sdk.inapp;

import static com.clevertap.android.sdk.CTXtensions.applyInsetsWithMarginAdjustment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.clevertap.android.sdk.Constants;

public class CTInAppHtmlCoverFragment extends CTInAppBaseFullHtmlFragment {
Expand All @@ -19,4 +29,20 @@ protected RelativeLayout.LayoutParams getLayoutParamsForCloseButton() {
closeIvLp.setMargins(0, sub, sub, 0);
return closeIvLp;
}

@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View inAppView = super.onCreateView(inflater, container, savedInstanceState);
if (inAppView != null) {
applyInsetsWithMarginAdjustment(inAppView, (insets, mlp) -> {
mlp.leftMargin = insets.left;
mlp.rightMargin = insets.right;
mlp.topMargin = insets.top;
mlp.bottomMargin = insets.bottom;
return null;
});
}
return inAppView;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.clevertap.android.sdk.inapp;

import static com.clevertap.android.sdk.CTXtensions.applyInsetsWithMarginAdjustment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.clevertap.android.sdk.R;

public class CTInAppHtmlFooterFragment extends CTInAppBasePartialHtmlFragment {
Expand All @@ -14,6 +17,13 @@ ViewGroup getLayout(View view) {

@Override
View getView(LayoutInflater inflater, ViewGroup container) {
return inflater.inflate(R.layout.inapp_html_footer, container, false);
View inAppView = inflater.inflate(R.layout.inapp_html_footer, container, false);
applyInsetsWithMarginAdjustment(inAppView, (insets, mlp) -> {
mlp.leftMargin = insets.left;
mlp.rightMargin = insets.right;
mlp.bottomMargin = insets.bottom;
Anush-Shand marked this conversation as resolved.
Show resolved Hide resolved
return null;
});
return inAppView;
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package com.clevertap.android.sdk.inapp;

import static com.clevertap.android.sdk.CTXtensions.applyInsetsWithMarginAdjustment;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.clevertap.android.sdk.R;

public class CTInAppHtmlHeaderFragment extends CTInAppBasePartialHtmlFragment {
Expand All @@ -14,7 +17,13 @@ ViewGroup getLayout(View view) {

@Override
View getView(LayoutInflater inflater, ViewGroup container) {
return inflater.inflate(R.layout.inapp_html_header, container, false);
View inAppView = inflater.inflate(R.layout.inapp_html_header, container, false);
applyInsetsWithMarginAdjustment(inAppView, (insets, mlp) -> {
mlp.leftMargin = insets.left;
mlp.rightMargin = insets.right;
mlp.topMargin = insets.top;
Anush-Shand marked this conversation as resolved.
Show resolved Hide resolved
return null;
});
return inAppView;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.clevertap.android.sdk.inapp;

import static com.clevertap.android.sdk.CTXtensions.applyInsetsWithMarginAdjustment;

import android.annotation.SuppressLint;
import android.content.res.Configuration;
import android.graphics.Bitmap;
Expand All @@ -14,9 +16,12 @@
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;

import com.clevertap.android.sdk.R;
import com.clevertap.android.sdk.customviews.CloseImageView;

import java.util.ArrayList;

public class CTInAppNativeCoverFragment extends CTInAppBaseFullNativeFragment {
Expand All @@ -27,6 +32,13 @@ public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,

ArrayList<Button> inAppButtons = new ArrayList<>();
View inAppView = inflater.inflate(R.layout.inapp_cover, container, false);
applyInsetsWithMarginAdjustment(inAppView, (insets, mlp) -> {
mlp.leftMargin = insets.left;
mlp.rightMargin = insets.right;
mlp.topMargin = insets.top;
mlp.bottomMargin = insets.bottom;
return null;
});

FrameLayout fl = inAppView.findViewById(R.id.inapp_cover_frame_layout);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.clevertap.android.sdk.inapp;

import static com.clevertap.android.sdk.CTXtensions.applyInsetsWithMarginAdjustment;

import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.Color;
Expand All @@ -20,7 +22,13 @@ public class CTInAppNativeCoverImageFragment extends CTInAppBaseFullFragment {
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, Bundle savedInstanceState) {
View inAppView = inflater.inflate(R.layout.inapp_cover_image, container, false);

applyInsetsWithMarginAdjustment(inAppView, (insets, mlp) -> {
mlp.leftMargin = insets.left;
mlp.rightMargin = insets.right;
mlp.topMargin = insets.top;
mlp.bottomMargin = insets.bottom;
return null;
});
FrameLayout fl = inAppView.findViewById(R.id.inapp_cover_image_frame_layout);
fl.setBackgroundColor(Color.parseColor(inAppNotification.getBackgroundColor()));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.clevertap.android.sdk.inapp;

import static com.clevertap.android.sdk.CTXtensions.applyInsetsWithMarginAdjustment;

import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.Color;
Expand All @@ -17,6 +19,7 @@
import android.widget.TextView;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import com.clevertap.android.sdk.R;
import java.util.ArrayList;

Expand Down Expand Up @@ -90,7 +93,13 @@ public boolean onTouch(View v, MotionEvent event) {
return true;
}
});

applyInsetsWithMarginAdjustment(inAppView, (insets, mlp) -> {
mlp.leftMargin = insets.left;
mlp.rightMargin = insets.right;
mlp.bottomMargin = insets.bottom;
return null;
});
return inAppView;
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.clevertap.android.sdk.inapp;

import static com.clevertap.android.sdk.CTXtensions.applyInsetsWithMarginAdjustment;

import android.annotation.SuppressLint;
import android.graphics.Bitmap;
import android.graphics.Color;
Expand All @@ -15,9 +17,12 @@
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;

import com.clevertap.android.sdk.R;

import java.util.ArrayList;

public class CTInAppNativeHeaderFragment extends CTInAppBasePartialNativeFragment {
Expand Down Expand Up @@ -87,7 +92,12 @@ public boolean onTouch(View v, MotionEvent event) {
return true;
}
});

applyInsetsWithMarginAdjustment(inAppView, (insets, mlp) -> {
mlp.leftMargin = insets.left;
mlp.rightMargin = insets.right;
mlp.topMargin = insets.top;
return null;
});
return inAppView;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.res.Configuration;
import android.graphics.Bitmap;
import android.graphics.Color;
Expand All @@ -23,10 +22,13 @@
import android.widget.RelativeLayout;
import android.widget.TextView;

import androidx.activity.ComponentDialog;
import androidx.activity.OnBackPressedCallback;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.content.ContextCompat;
import androidx.core.content.res.ResourcesCompat;
import androidx.fragment.app.FragmentActivity;
import androidx.media3.common.util.UnstableApi;

import com.clevertap.android.sdk.Logger;
Expand All @@ -45,7 +47,7 @@

private boolean exoPlayerFullscreen = false;

private Dialog fullScreenDialog;
private ComponentDialog fullScreenDialog;

private ImageView fullScreenIcon;

Expand All @@ -61,6 +63,15 @@
private FrameLayout videoFrameInDialog;

private ViewGroup.LayoutParams imageViewLayoutParams;
private final OnBackPressedCallback onBackPressedCallback = new OnBackPressedCallback(false) {
@Override
public void handleOnBackPressed() {
if (exoPlayerFullscreen) {
closeFullscreenDialog();
onBackPressedCallback.setEnabled(false);
}
}
};

@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
Expand Down Expand Up @@ -199,9 +210,11 @@ private void initFullScreenIconForStream() {
fullScreenIcon.setImageDrawable(ResourcesCompat.getDrawable(this.context.getResources(), R.drawable.ct_ic_fullscreen_expand, null));
fullScreenIcon.setOnClickListener(v -> {
if (!exoPlayerFullscreen) {
onBackPressedCallback.setEnabled(true);
openFullscreenDialog();
} else {
closeFullscreenDialog();
onBackPressedCallback.setEnabled(false);
}
});

Expand Down Expand Up @@ -311,6 +324,7 @@ public void onPause() {
}
if (exoPlayerFullscreen) {
closeFullscreenDialog();
onBackPressedCallback.setEnabled(false);
}
handle.savePosition();
handle.pause();
Expand Down Expand Up @@ -365,21 +379,20 @@ private void openFullscreenDialog() {
if (fullScreenDialog == null) {
// create only once
// create full screen dialog and show
fullScreenDialog = new Dialog(this.context, android.R.style.Theme_Black_NoTitleBar_Fullscreen) {
public void onBackPressed() {
if (exoPlayerFullscreen) {
closeFullscreenDialog();
}
super.onBackPressed();
}
};
fullScreenDialog = new ComponentDialog(this.context, android.R.style.Theme_Black_NoTitleBar_Fullscreen);
ViewGroup.LayoutParams fullScreenParams = new FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
);
videoFrameInDialog = new FrameLayout(context);
fullScreenDialog.addContentView(videoFrameInDialog, fullScreenParams);

FragmentActivity activity = getActivity();
if (activity != null) {
fullScreenDialog.getOnBackPressedDispatcher().addCallback(activity,onBackPressedCallback);
}
}

videoFrameInDialog.addView(playerView);
exoPlayerFullscreen = true;
fullScreenDialog.show();
Expand Down
Loading
Loading