Add background blur activity to silkfx
Bug: 213292227 Test: m SilkFX && adb install $OUT/testcases/SilkFX/arm/SilkFX.apk Test: adb shell am start -n com.android.test.silkfx/.materials.BackgroundBlurActivity Change-Id: I1692a53460b64b5a49d14736b2b680069217fa1d
This commit is contained in:
parent
853b6f6ede
commit
fe59c4de42
@ -20,17 +20,20 @@
|
||||
<uses-sdk android:minSdkVersion="30"/>
|
||||
|
||||
<uses-permission android:name="android.permission.CONTROL_DISPLAY_BRIGHTNESS" />
|
||||
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS" />
|
||||
|
||||
<application android:label="SilkFX"
|
||||
android:theme="@android:style/Theme.Material">
|
||||
|
||||
<activity android:name=".Main"
|
||||
android:label="SilkFX Demos"
|
||||
android:banner="@drawable/background1"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.DEFAULT"/>
|
||||
<category android:name="android.intent.category.LAUNCHER"/>
|
||||
<category android:name="android.intent.category.LEANBACK_LAUNCHER"/>
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
@ -41,13 +44,16 @@
|
||||
|
||||
<activity android:name=".materials.GlassActivity"
|
||||
android:label="Glass Examples"
|
||||
android:banner="@drawable/background1"
|
||||
android:exported="true">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN"/>
|
||||
<category android:name="android.intent.category.LEANBACK_LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<activity android:name=".materials.BackgroundBlurActivity"
|
||||
android:theme="@style/Theme.BackgroundBlurTheme"
|
||||
android:exported="true">
|
||||
</activity>
|
||||
|
||||
</application>
|
||||
</manifest>
|
||||
|
20
tests/SilkFX/res/drawable/background_blur_drawable.xml
Normal file
20
tests/SilkFX/res/drawable/background_blur_drawable.xml
Normal file
@ -0,0 +1,20 @@
|
||||
<!--
|
||||
~ Copyright (C) 2022 The Android Open Source Project
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<solid android:color="#20FFFFFF"/>
|
||||
<corners android:radius="10dp"/>
|
||||
</shape>
|
@ -0,0 +1,20 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2022 The Android Open Source Project
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:shape="rectangle">
|
||||
<corners android:radius="10dp"/>
|
||||
</shape>
|
173
tests/SilkFX/res/layout/activity_background_blur.xml
Normal file
173
tests/SilkFX/res/layout/activity_background_blur.xml
Normal file
@ -0,0 +1,173 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2022 The Android Open Source Project
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/background"
|
||||
android:layout_width="390dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:padding="15dp"
|
||||
android:orientation="vertical"
|
||||
tools:context=".materials.BackgroundBlurActivity">
|
||||
|
||||
<TextView
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center_horizontal"
|
||||
android:padding="10dp"
|
||||
android:textColor="#ffffffff"
|
||||
android:text="Hello blurry world!"/>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textColor="#ffffffff"
|
||||
android:text="Background blur"/>
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/set_background_blur"
|
||||
android:min="0"
|
||||
android:max="300"
|
||||
android:layout_width="160dp"
|
||||
android:layout_height="wrap_content"/>
|
||||
<TextView
|
||||
android:id="@+id/background_blur_radius"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="#ffffffff"
|
||||
android:ems="3"
|
||||
android:gravity="center"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp"
|
||||
android:text="TODO"/>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textColor="#ffffffff"
|
||||
android:text="Background alpha"/>
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/set_background_alpha"
|
||||
android:min="0"
|
||||
android:max="100"
|
||||
android:layout_width="160dp"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:id="@+id/background_alpha"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="#ffffffff"
|
||||
android:ems="3"
|
||||
android:gravity="center"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp"
|
||||
android:text="TODO"/>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textColor="#ffffffff"
|
||||
android:text="Blur behind"/>
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/set_blur_behind"
|
||||
android:min="0"
|
||||
android:max="300"
|
||||
android:layout_width="160dp"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:id="@+id/blur_behind_radius"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:textColor="#ffffffff"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp"
|
||||
android:ems="3"
|
||||
android:text="TODO"/>
|
||||
</LinearLayout>
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:textColor="#ffffffff"
|
||||
android:text="Dim amount"/>
|
||||
|
||||
<SeekBar
|
||||
android:id="@+id/set_dim_amount"
|
||||
android:min="0"
|
||||
android:max="100"
|
||||
android:layout_width="160dp"
|
||||
android:layout_height="wrap_content" />
|
||||
<TextView
|
||||
android:id="@+id/dim_amount"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="center"
|
||||
android:textColor="#ffffffff"
|
||||
android:paddingLeft="10dp"
|
||||
android:paddingRight="10dp"
|
||||
android:ems="3"
|
||||
android:text="TODO"/>
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginTop="5dp"
|
||||
android:orientation="vertical"
|
||||
android:gravity="center">
|
||||
|
||||
<Button
|
||||
android:id="@+id/toggle_blur_enabled"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Disable blur"
|
||||
android:onClick="toggleForceBlurDisabled"/>
|
||||
|
||||
<Button
|
||||
android:id="@+id/toggle_battery_saving_mode"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="TODO"
|
||||
android:onClick="toggleBatterySavingMode"/>
|
||||
</LinearLayout>
|
||||
<requestFocus/>
|
||||
|
||||
</LinearLayout>
|
31
tests/SilkFX/res/values/style.xml
Normal file
31
tests/SilkFX/res/values/style.xml
Normal file
@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
~ Copyright (C) 2022 The Android Open Source Project
|
||||
~
|
||||
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||
~ you may not use this file except in compliance with the License.
|
||||
~ You may obtain a copy of the License at
|
||||
~
|
||||
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||
~
|
||||
~ Unless required by applicable law or agreed to in writing, software
|
||||
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
~ See the License for the specific language governing permissions and
|
||||
~ limitations under the License.
|
||||
-->
|
||||
<!-- Styles for immersive actions UI. -->
|
||||
<resources xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<style name="Theme.BackgroundBlurTheme" parent= "Theme.AppCompat.Dialog">
|
||||
<item name="android:windowIsTranslucent">true</item>
|
||||
<item name="android:windowBlurBehindEnabled">true</item>
|
||||
<item name="android:backgroundDimEnabled">false</item>
|
||||
<item name="android:windowElevation">0dp</item>
|
||||
<item name="buttonStyle">@style/AppTheme.Button</item>
|
||||
<item name="colorAccent">#bbffffff</item>
|
||||
</style>
|
||||
<style name="AppTheme.Button" parent="Widget.AppCompat.Button">
|
||||
<item name="android:textColor">#ffffffff</item>
|
||||
</style>
|
||||
|
||||
</resources>
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (C) 2020 The Android Open Source Project
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@ -30,6 +30,7 @@ import com.android.test.silkfx.app.EXTRA_LAYOUT
|
||||
import com.android.test.silkfx.app.EXTRA_TITLE
|
||||
import com.android.test.silkfx.hdr.GlowActivity
|
||||
import com.android.test.silkfx.materials.GlassActivity
|
||||
import com.android.test.silkfx.materials.BackgroundBlurActivity
|
||||
import kotlin.reflect.KClass
|
||||
|
||||
class Demo(val name: String, val makeIntent: (Context) -> Intent) {
|
||||
@ -51,7 +52,8 @@ private val AllDemos = listOf(
|
||||
Demo("Blingy Notifications", R.layout.bling_notifications)
|
||||
)),
|
||||
DemoGroup("Materials", listOf(
|
||||
Demo("Glass", GlassActivity::class)
|
||||
Demo("Glass", GlassActivity::class),
|
||||
Demo("Background Blur", BackgroundBlurActivity::class)
|
||||
))
|
||||
)
|
||||
|
||||
@ -126,4 +128,4 @@ class Main : Activity() {
|
||||
|
||||
AllDemos.forEachIndexed { index, _ -> list.expandGroup(index) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,189 @@
|
||||
/*
|
||||
* Copyright (C) 2022 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.android.test.silkfx.materials
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.content.Context
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Color
|
||||
import android.graphics.drawable.ColorDrawable
|
||||
import android.graphics.drawable.PaintDrawable
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.os.Bundle
|
||||
import android.provider.Settings
|
||||
import android.util.TypedValue
|
||||
import android.view.View
|
||||
import android.view.WindowManager
|
||||
import android.widget.ImageView
|
||||
import android.widget.SeekBar
|
||||
import android.widget.Switch
|
||||
import android.widget.TextView
|
||||
import com.android.test.silkfx.R
|
||||
import com.android.internal.graphics.drawable.BackgroundBlurDrawable
|
||||
import android.widget.LinearLayout
|
||||
import android.widget.Button
|
||||
|
||||
import android.view.ViewRootImpl
|
||||
|
||||
class BackgroundBlurActivity : Activity(), SeekBar.OnSeekBarChangeListener {
|
||||
var mBackgroundDrawable = PaintDrawable(Color.WHITE)
|
||||
var mBackgroundBlurRadius = 50
|
||||
var mAlphaWithBlur = 0.2f
|
||||
var mAlphaNoBlur = 0.5f
|
||||
|
||||
var mBlurBehindRadius = 10
|
||||
var mDimAmountWithBlur = 0.2f
|
||||
var mDimAmountNoBlur = 0.2f
|
||||
|
||||
var mBlurForceDisabled = false
|
||||
var mBatterySavingModeOn = false
|
||||
|
||||
lateinit var blurBackgroundSeekBar: SeekBar
|
||||
lateinit var backgroundAlphaSeekBar : SeekBar
|
||||
lateinit var blurBehindSeekBar : SeekBar
|
||||
lateinit var dimAmountSeekBar : SeekBar
|
||||
|
||||
val blurEnabledListener = { enabled : Boolean ->
|
||||
blurBackgroundSeekBar.setProgress(mBackgroundBlurRadius)
|
||||
blurBehindSeekBar.setProgress(mBlurBehindRadius)
|
||||
|
||||
if (enabled) {
|
||||
setBackgroundBlur(mBackgroundBlurRadius)
|
||||
setBackgroundColorAlpha(mAlphaWithBlur)
|
||||
|
||||
setBlurBehind(mBlurBehindRadius)
|
||||
setDimAmount(mDimAmountWithBlur)
|
||||
|
||||
backgroundAlphaSeekBar.setProgress((mAlphaWithBlur * 100).toInt())
|
||||
dimAmountSeekBar.setProgress((mDimAmountWithBlur * 100).toInt())
|
||||
} else {
|
||||
setBackgroundColorAlpha(mAlphaNoBlur)
|
||||
setDimAmount(mDimAmountNoBlur)
|
||||
|
||||
backgroundAlphaSeekBar.setProgress((mAlphaNoBlur * 100).toInt())
|
||||
dimAmountSeekBar.setProgress((mDimAmountNoBlur * 100).toInt())
|
||||
}
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
setContentView(R.layout.activity_background_blur)
|
||||
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_BLUR_BEHIND)
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND)
|
||||
|
||||
mBackgroundDrawable.setCornerRadius(30f)
|
||||
window.setBackgroundDrawable(mBackgroundDrawable)
|
||||
|
||||
mBatterySavingModeOn =
|
||||
Settings.Global.getInt(getContentResolver(), Settings.Global.LOW_POWER_MODE, 0) == 1
|
||||
setBatterySavingModeOn(mBatterySavingModeOn)
|
||||
|
||||
blurBackgroundSeekBar = requireViewById(R.id.set_background_blur)
|
||||
backgroundAlphaSeekBar = requireViewById(R.id.set_background_alpha)
|
||||
blurBehindSeekBar = requireViewById(R.id.set_blur_behind)
|
||||
dimAmountSeekBar = requireViewById(R.id.set_dim_amount)
|
||||
|
||||
arrayOf(blurBackgroundSeekBar, backgroundAlphaSeekBar, blurBehindSeekBar, dimAmountSeekBar)
|
||||
.forEach {
|
||||
it.setOnSeekBarChangeListener(this)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAttachedToWindow() {
|
||||
super.onAttachedToWindow()
|
||||
getWindowManager().addCrossWindowBlurEnabledListener(blurEnabledListener)
|
||||
}
|
||||
|
||||
override fun onDetachedFromWindow() {
|
||||
super.onDetachedFromWindow()
|
||||
getWindowManager().removeCrossWindowBlurEnabledListener(blurEnabledListener)
|
||||
}
|
||||
|
||||
override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
|
||||
when (seekBar) {
|
||||
blurBackgroundSeekBar -> setBackgroundBlur(progress)
|
||||
backgroundAlphaSeekBar -> setBackgroundColorAlpha(progress / 100.0f)
|
||||
blurBehindSeekBar -> setBlurBehind(progress)
|
||||
dimAmountSeekBar -> setDimAmount(progress / 100.0f)
|
||||
else -> throw IllegalArgumentException("Unknown seek bar")
|
||||
}
|
||||
}
|
||||
|
||||
override fun onStartTrackingTouch(seekBar: SeekBar?) {}
|
||||
override fun onStopTrackingTouch(seekBar: SeekBar?) {}
|
||||
|
||||
fun setBlurDisabled(disabled: Boolean) {
|
||||
mBlurForceDisabled = disabled
|
||||
Settings.Global.putInt(getContentResolver(), Settings.Global.DISABLE_WINDOW_BLURS,
|
||||
if (mBlurForceDisabled) 1 else 0)
|
||||
(findViewById(R.id.toggle_blur_enabled) as Button)
|
||||
.setText(if (mBlurForceDisabled) "Enable blurs" else "Disable blurs")
|
||||
}
|
||||
|
||||
fun toggleForceBlurDisabled(v: View) {
|
||||
setBlurDisabled(!mBlurForceDisabled)
|
||||
}
|
||||
|
||||
fun setBackgroundBlur(radius: Int) {
|
||||
mBackgroundBlurRadius = radius
|
||||
(findViewById(R.id.background_blur_radius) as TextView).setText(radius.toString())
|
||||
window.setBackgroundBlurRadius(mBackgroundBlurRadius)
|
||||
}
|
||||
|
||||
fun setBlurBehind(radius: Int) {
|
||||
mBlurBehindRadius = radius
|
||||
(findViewById(R.id.blur_behind_radius) as TextView).setText(radius.toString())
|
||||
window.getAttributes().setBlurBehindRadius(mBlurBehindRadius)
|
||||
window.setAttributes(window.getAttributes())
|
||||
}
|
||||
|
||||
fun setDimAmount(amount: Float) {
|
||||
if (getWindowManager().isCrossWindowBlurEnabled()) {
|
||||
mDimAmountWithBlur = amount
|
||||
} else {
|
||||
mDimAmountNoBlur = amount
|
||||
}
|
||||
(findViewById(R.id.dim_amount) as TextView).setText("%.2f".format(amount))
|
||||
window.getAttributes().dimAmount = amount
|
||||
window.setAttributes(window.getAttributes())
|
||||
}
|
||||
|
||||
fun setBatterySavingModeOn(on: Boolean) {
|
||||
mBatterySavingModeOn = on
|
||||
Settings.Global.putInt(getContentResolver(),
|
||||
Settings.Global.LOW_POWER_MODE, if (on) 1 else 0)
|
||||
(findViewById(R.id.toggle_battery_saving_mode) as Button).setText(
|
||||
if (on) "Exit low power mode" else "Enter low power mode")
|
||||
}
|
||||
|
||||
fun toggleBatterySavingMode(v: View) {
|
||||
setBatterySavingModeOn(!mBatterySavingModeOn)
|
||||
}
|
||||
|
||||
fun setBackgroundColorAlpha(alpha: Float) {
|
||||
if (getWindowManager().isCrossWindowBlurEnabled()) {
|
||||
mAlphaWithBlur = alpha
|
||||
} else {
|
||||
mAlphaNoBlur = alpha
|
||||
}
|
||||
(findViewById(R.id.background_alpha) as TextView).setText("%.2f".format(alpha))
|
||||
mBackgroundDrawable.setAlpha((alpha * 255f).toInt())
|
||||
getWindowManager().updateViewLayout(window.getDecorView(), window.getAttributes())
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user