Add file picker support to glass proto
Test: manual Change-Id: If728296285b26e77b07a451e5ac5b9645fec0fe9
This commit is contained in:
@@ -219,6 +219,19 @@
|
||||
app:layout_constraintStart_toEndOf="@+id/background2"
|
||||
android:src="@drawable/background3" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/pickImage"
|
||||
android:layout_width="64dp"
|
||||
android:layout_height="64dp"
|
||||
android:layout_marginStart="8dp"
|
||||
android:scaleType="centerCrop"
|
||||
android:foreground="?android:attr/selectableItemBackgroundBorderless"
|
||||
android:clickable="true"
|
||||
android:onClick="onPickImageClick"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/background1"
|
||||
app:layout_constraintStart_toEndOf="@+id/background3"
|
||||
android:text="Pick file" />
|
||||
|
||||
<Switch
|
||||
android:id="@+id/lightMaterialSwitch"
|
||||
android:layout_width="wrap_content"
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.android.test.silkfx.materials
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.graphics.Bitmap
|
||||
import android.graphics.BitmapFactory
|
||||
import android.graphics.Color
|
||||
@@ -47,7 +48,12 @@ class GlassActivity : Activity(), SeekBar.OnSeekBarChangeListener {
|
||||
lateinit var blurRadiusValue: TextView
|
||||
lateinit var zoomValue: TextView
|
||||
|
||||
lateinit var background: Bitmap
|
||||
var background: Bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888)
|
||||
set(value) {
|
||||
field = value
|
||||
backgroundView.setImageBitmap(background)
|
||||
materialView.backgroundBitmap = background
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@@ -70,8 +76,6 @@ class GlassActivity : Activity(), SeekBar.OnSeekBarChangeListener {
|
||||
zoomValue = requireViewById(R.id.zoomValue)
|
||||
|
||||
background = BitmapFactory.decodeResource(resources, R.drawable.background1)
|
||||
backgroundView.setImageBitmap(background)
|
||||
materialView.backgroundBitmap = background
|
||||
|
||||
blurRadiusSeekBar.setOnSeekBarChangeListener(this)
|
||||
materialOpacitySeekBar.setOnSeekBarChangeListener(this)
|
||||
@@ -128,7 +132,23 @@ class GlassActivity : Activity(), SeekBar.OnSeekBarChangeListener {
|
||||
}
|
||||
|
||||
background = BitmapFactory.decodeResource(resources, resource)
|
||||
backgroundView.setImageBitmap(background)
|
||||
materialView.backgroundBitmap = background
|
||||
}
|
||||
|
||||
fun onPickImageClick(view: View) {
|
||||
val intent = Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
|
||||
addCategory(Intent.CATEGORY_OPENABLE)
|
||||
type = "image/*"
|
||||
}
|
||||
startActivityForResult(intent, 0)
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (resultCode === RESULT_OK) {
|
||||
data?.data?.also {
|
||||
contentResolver.openFileDescriptor(it, "r").let {
|
||||
background = BitmapFactory.decodeFileDescriptor(it?.fileDescriptor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user