Skip to content

Commit

Permalink
Blur the content behind the toolbar
Browse files Browse the repository at this point in the history
  • Loading branch information
AChep committed Nov 7, 2020
1 parent 97cb214 commit 233fb5a
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 42 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ dependencies {
implementation 'com.afollestad.material-dialogs:core:3.1.0'
implementation 'com.google.android.material:material:1.3.0-alpha03'
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycle_version"
implementation 'com.eightbitlab:blurview:1.6.5'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.core:core-ktx:1.3.2'
implementation 'androidx.browser:browser:1.2.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.artemchep.pocketmode.models.Proximity
import com.artemchep.pocketmode.ui.activities.base.BaseActivity
import com.artemchep.pocketmode.util.ObserverConsumer
import com.artemchep.pocketmode.viewmodels.MainViewModel
import eightbitlab.com.blurview.RenderScriptBlur

/**
* @author Artem Chepurnoy
Expand Down Expand Up @@ -65,6 +66,13 @@ class MainActivity : BaseActivity(),
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

viewBinding.toolbarBlurView
.setupWith(viewBinding.root)
.setBlurAlgorithm(RenderScriptBlur(this))
.setBlurRadius(5f)
.setBlurAutoUpdate(true)
.setHasFixedTransformationMatrix(true)

ViewCompat.setOnApplyWindowInsetsListener(window.decorView) { _, insets ->
viewBinding.statusBar.layoutParams.height = insets.systemWindowInsetTop
viewBinding.scrollView.updatePadding(
Expand Down
98 changes: 56 additions & 42 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -80,51 +80,65 @@
android:layout_height="wrap_content"
android:orientation="vertical">

<View
android:id="@+id/statusBar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:alpha="0.8"
android:background="@drawable/bg_toolbar" />

<FrameLayout
android:id="@+id/toolbar"
<eightbitlab.com.blurview.BlurView
android:id="@+id/toolbarBlurView"
android:layout_width="match_parent"
android:layout_height="@dimen/actionBarSize"
android:foreground="?selectableItemBackground">
android:layout_height="wrap_content">

<View
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.8"
android:background="@drawable/bg_toolbar" />

<FrameLayout
android:id="@+id/toolbarContent"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="@font/manrope_semibold"
android:text="@string/app_name"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="?android:textColorPrimary"
android:textSize="20sp" />

<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/masterSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp" />

</FrameLayout>

</FrameLayout>
android:layout_height="wrap_content"
android:orientation="vertical">

<View
android:id="@+id/statusBar"
android:layout_width="match_parent"
android:layout_height="0dp"
android:alpha="0.8"
android:background="@drawable/bg_toolbar" />

<FrameLayout
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="@dimen/actionBarSize"
android:foreground="?selectableItemBackground">

<View
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.8"
android:background="@drawable/bg_toolbar" />

<FrameLayout
android:id="@+id/toolbarContent"
android:layout_width="match_parent"
android:layout_height="match_parent">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:fontFamily="@font/manrope_semibold"
android:text="@string/app_name"
android:textAppearance="?android:textAppearanceMedium"
android:textColor="?android:textColorPrimary"
android:textSize="20sp" />

<com.google.android.material.switchmaterial.SwitchMaterial
android:id="@+id/masterSwitch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp" />

</FrameLayout>

</FrameLayout>

</LinearLayout>

</eightbitlab.com.blurview.BlurView>

<View
android:layout_width="match_parent"
Expand Down

0 comments on commit 233fb5a

Please sign in to comment.