Skip to content

Commit ec9ce66

Browse files
committed
Use activity to control splash background color
Update splash listener to support content fragment.
1 parent 3bbe4b2 commit ec9ce66

File tree

2 files changed

+23
-6
lines changed

2 files changed

+23
-6
lines changed

dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/listener/DynamicSplashListener.java

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

2121
import androidx.annotation.LayoutRes;
2222
import androidx.annotation.NonNull;
23+
import androidx.annotation.Nullable;
24+
import androidx.fragment.app.Fragment;
2325

2426
/**
2527
* An interface to implement the splash screen and to get various callbacks while showing the splash.
@@ -33,6 +35,15 @@ public interface DynamicSplashListener {
3335
*/
3436
@LayoutRes int getLayoutRes();
3537

38+
/**
39+
* This method will be called to create the splash fragment instance.
40+
*
41+
* @param layoutRes The layout resource file for the fragment.
42+
*
43+
* @return The splash fragment instance.
44+
*/
45+
@Nullable Fragment getContentFragment(@LayoutRes int layoutRes);
46+
3647
/**
3748
* This method will be called just after creating the splash fragment with the supplied
3849
* layout resource.

dynamic-support/src/main/java/com/pranavpandey/android/dynamic/support/splash/activity/DynamicSplashActivity.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
import androidx.annotation.ColorInt;
2525
import androidx.annotation.Nullable;
26+
import androidx.annotation.StyleRes;
2627
import androidx.coordinatorlayout.widget.CoordinatorLayout;
2728
import androidx.core.app.ActivityCompat;
2829
import androidx.core.app.ActivityOptionsCompat;
@@ -81,6 +82,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
8182

8283
ADS_SPLASH_MAGIC = false;
8384
setContentView(R.layout.ads_layout_container);
85+
setRootBackground(getBackgroundColor());
8486

8587
mCoordinatorLayout = findViewById(R.id.ads_coordinator_layout);
8688

@@ -90,16 +92,15 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
9092
}
9193

9294
if (mContentFragment == null) {
93-
mContentFragment = DynamicSplashFragment.newInstance(getLayoutRes());
95+
mContentFragment = getContentFragment(getLayoutRes());
9496
}
95-
9697
if (mContentFragment instanceof DynamicSplashFragment) {
9798
((DynamicSplashFragment) mContentFragment).setOnSplashListener(this);
98-
setRootBackground(((DynamicSplashFragment) mContentFragment).getBackgroundColor());
9999
}
100-
101-
commitFragmentTransaction(getSupportFragmentManager().beginTransaction()
102-
.replace(R.id.ads_container, mContentFragment, ADS_STATE_SPLASH_FRAGMENT_TAG));
100+
if (mContentFragment != null) {
101+
commitFragmentTransaction(getSupportFragmentManager().beginTransaction()
102+
.replace(R.id.ads_container, mContentFragment, ADS_STATE_SPLASH_FRAGMENT_TAG));
103+
}
103104

104105
if (DynamicTheme.getInstance().get().getPrimaryColorDark(
105106
false, false) == Theme.AUTO) {
@@ -125,6 +126,11 @@ protected void onNewIntent(@Nullable Intent intent, boolean newIntent) {
125126
((DynamicSplashFragment) mContentFragment).show(getSavedInstanceState() != null);
126127
}
127128

129+
@Override
130+
public @Nullable Fragment getContentFragment(@StyleRes int layoutRes) {
131+
return DynamicSplashFragment.newInstance(layoutRes);
132+
}
133+
128134
@Override
129135
public @Nullable View getContentView() {
130136
return findViewById(R.id.ads_container);

0 commit comments

Comments
 (0)