Skip to content

Commit

Permalink
Use activity to control splash background color
Browse files Browse the repository at this point in the history
Update splash listener to support content fragment.
  • Loading branch information
pranavpandey committed Mar 31, 2023
1 parent 3bbe4b2 commit ec9ce66
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

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

/**
* This method will be called to create the splash fragment instance.
*
* @param layoutRes The layout resource file for the fragment.
*
* @return The splash fragment instance.
*/
@Nullable Fragment getContentFragment(@LayoutRes int layoutRes);

/**
* This method will be called just after creating the splash fragment with the supplied
* layout resource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

import androidx.annotation.ColorInt;
import androidx.annotation.Nullable;
import androidx.annotation.StyleRes;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.app.ActivityCompat;
import androidx.core.app.ActivityOptionsCompat;
Expand Down Expand Up @@ -81,6 +82,7 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {

ADS_SPLASH_MAGIC = false;
setContentView(R.layout.ads_layout_container);
setRootBackground(getBackgroundColor());

mCoordinatorLayout = findViewById(R.id.ads_coordinator_layout);

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

if (mContentFragment == null) {
mContentFragment = DynamicSplashFragment.newInstance(getLayoutRes());
mContentFragment = getContentFragment(getLayoutRes());
}

if (mContentFragment instanceof DynamicSplashFragment) {
((DynamicSplashFragment) mContentFragment).setOnSplashListener(this);
setRootBackground(((DynamicSplashFragment) mContentFragment).getBackgroundColor());
}

commitFragmentTransaction(getSupportFragmentManager().beginTransaction()
.replace(R.id.ads_container, mContentFragment, ADS_STATE_SPLASH_FRAGMENT_TAG));
if (mContentFragment != null) {
commitFragmentTransaction(getSupportFragmentManager().beginTransaction()
.replace(R.id.ads_container, mContentFragment, ADS_STATE_SPLASH_FRAGMENT_TAG));
}

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

@Override
public @Nullable Fragment getContentFragment(@StyleRes int layoutRes) {
return DynamicSplashFragment.newInstance(layoutRes);
}

@Override
public @Nullable View getContentView() {
return findViewById(R.id.ads_container);
Expand Down

0 comments on commit ec9ce66

Please sign in to comment.