Skip to content

Commit

Permalink
Improve tutorial background
Browse files Browse the repository at this point in the history
Set root background instead of the window to make shared element
transition smoother.
  • Loading branch information
pranavpandey committed Aug 30, 2022
1 parent 7058b0c commit b02d0e2
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.Icon;
import android.graphics.drawable.LayerDrawable;
Expand All @@ -30,6 +31,7 @@
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
Expand Down Expand Up @@ -1665,6 +1667,25 @@ public static void setElevation(@Nullable View view, float elevation) {
}
}

/**
* Sets the background for the window or root view.
*
* @param dynamic The dynamic object to be used.
* @param color The color to be set.
* @param <T> The type of the dynamic object.
*
* @see Window#setBackgroundDrawable(Drawable)
* @see View#setBackgroundDrawable(Drawable)
* @see #withThemeOpacity(Drawable)
*/
public static <T> void setRootBackground(@Nullable T dynamic, @ColorInt int color) {
if (dynamic instanceof Window) {
((Window) dynamic).setBackgroundDrawable(withThemeOpacity(new ColorDrawable(color)));
} else if (dynamic instanceof View) {
((View) dynamic).setBackgroundDrawable(withThemeOpacity(new ColorDrawable(color)));
}
}

/**
* Set background drawable for the view.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.transition.Fade;
Expand Down Expand Up @@ -1002,10 +1001,26 @@ protected void navigationBarThemeChange() {
* Sets the window background color.
*
* @param color The window background color to be set.
*
* @see #getWindow()
* @see Dynamic#setRootBackground(Object, int)
*/
public void setWindowBackground(@ColorInt int color) {
this.mBackgroundColor = color;
getWindow().setBackgroundDrawable(new ColorDrawable(Dynamic.withThemeOpacity(color)));

Dynamic.setRootBackground(getWindow(), color);
}

/**
* Sets the root background color.
*
* @param color The root background color to be set.
*
* @see R.id#ads_activity_root
* @see Dynamic#setRootBackground(Object, int)
*/
public void setRootBackground(@ColorInt int color) {
Dynamic.setRootBackground(findViewById(R.id.ads_activity_root), color);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,7 @@ protected void onSetColor(int position, @ColorInt int color, @ColorInt int tintC
}
}

setWindowBackground(color);
setRootBackground(color);
setStatusBarColor(systemUIColor);
setNavigationBarColor(systemUIColor);
updateTaskDescription(color);
Expand Down

0 comments on commit b02d0e2

Please sign in to comment.