Skip to content

Commit 029ca94

Browse files
committed
Refactor: Update Storage Access Framework sample and icons
- Renamed `GetDocument` to `GetContentSample` for clarity. - Removed the `@Sample` annotation from `GetContentSample` as it is managed in `SampleDemo` now. - Added new icons in the `drawable` folder to replace `Material Icons`. - Updated `FileCard` to use `DrawableRes` instead of `ImageVector`. - Replaced the filter icon with a new one. - Updated `SampleDemo` to use the renamed `GetContentSample`. - Clean up deleted `StorageSampleActivity`.
1 parent 9830732 commit 029ca94

File tree

11 files changed

+59
-68
lines changed

11 files changed

+59
-68
lines changed

app/src/main/java/com/example/platform/app/SampleDemo.kt

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ import com.example.platform.shared.MinSdkBox
6363
import com.example.platform.storage.mediastore.MediaStoreQuerySample
6464
import com.example.platform.storage.mediastore.SelectedPhotosAccessSample
6565
import com.example.platform.storage.photopicker.PhotoPickerSample
66+
import com.example.platform.storage.storageaccessframework.GetContentSample
6667
import com.example.platform.ui.appwidgets.AppWidgets
6768
import com.example.platform.ui.constraintlayout.AdvancedArrangementFragment
6869
import com.example.platform.ui.constraintlayout.AdvancedChainsFragment
@@ -566,6 +567,14 @@ val SAMPLE_DEMOS by lazy {
566567
apiSurface = StorageApiSurface,
567568
content = { MediaStoreQuerySample() },
568569
),
570+
ComposableSampleDemo(
571+
id = "storageaccessframework-getcontent",
572+
name = "Storage Access Framework - GET_CONTENT",
573+
description = "Open a document using the Storage Access Framework",
574+
documentation = "https://developer.android.com/training/data-storage/shared/documents-files#open-file",
575+
apiSurface = StorageApiSurface,
576+
content = { GetContentSample() },
577+
),
569578
ComposableSampleDemo(
570579
id = "selected-photos-access",
571580
name = "Selected Photos Access",

samples/storage/src/main/java/com/example/platform/storage/StorageSampleActivity.kt

Lines changed: 0 additions & 43 deletions
This file was deleted.

samples/storage/src/main/java/com/example/platform/storage/storageaccessframework/GetDocument.kt renamed to samples/storage/src/main/java/com/example/platform/storage/storageaccessframework/GetContentSample.kt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import androidx.compose.foundation.lazy.items
2828
import androidx.compose.foundation.rememberScrollState
2929
import androidx.compose.material.icons.Icons
3030
import androidx.compose.material.icons.filled.Check
31-
import androidx.compose.material.icons.filled.FilterAlt
3231
import androidx.compose.material.icons.outlined.Check
3332
import androidx.compose.material3.DropdownMenu
3433
import androidx.compose.material3.DropdownMenuItem
@@ -51,8 +50,10 @@ import androidx.compose.runtime.setValue
5150
import androidx.compose.ui.Alignment
5251
import androidx.compose.ui.Modifier
5352
import androidx.compose.ui.platform.LocalContext
53+
import androidx.compose.ui.res.painterResource
5454
import androidx.compose.ui.semantics.contentDescription
5555
import androidx.compose.ui.semantics.semantics
56+
import com.example.platform.storage.R
5657
import com.example.platform.storage.storageaccessframework.shared.AudioFileCard
5758
import com.example.platform.storage.storageaccessframework.shared.BinaryFileCard
5859
import com.example.platform.storage.storageaccessframework.shared.FileRecord
@@ -61,16 +62,10 @@ import com.example.platform.storage.storageaccessframework.shared.ImageFileCard
6162
import com.example.platform.storage.storageaccessframework.shared.PdfFileCard
6263
import com.example.platform.storage.storageaccessframework.shared.TextFileCard
6364
import com.example.platform.storage.storageaccessframework.shared.VideoFileCard
64-
import com.google.android.catalog.framework.annotations.Sample
6565
import kotlinx.coroutines.launch
6666

67-
@Sample(
68-
name = "GetDocument",
69-
description = "Open a document using the Storage Access Framework",
70-
documentation = "https://developer.android.com/training/data-storage/shared/documents-files#open-file",
71-
)
7267
@Composable
73-
fun GetDocument() {
68+
fun GetContentSample() {
7469
val coroutineScope = rememberCoroutineScope()
7570
val context = LocalContext.current
7671
var selectedFilter by remember { mutableStateOf(FileType.Any) }
@@ -127,7 +122,7 @@ fun GetDocument() {
127122
) {
128123
IconButton(onClick = { expanded = true }) {
129124
Icon(
130-
Icons.Default.FilterAlt,
125+
painter = painterResource(R.drawable.ic_filter_alt_24),
131126
contentDescription = "Localized description",
132127
)
133128
}

samples/storage/src/main/java/com/example/platform/storage/storageaccessframework/shared/FileCard.kt

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ package com.example.platform.storage.storageaccessframework.shared
1919
import android.content.Context
2020
import android.net.Uri
2121
import android.text.format.Formatter
22+
import androidx.annotation.DrawableRes
2223
import androidx.compose.foundation.layout.Column
2324
import androidx.compose.foundation.layout.Row
2425
import androidx.compose.foundation.layout.Spacer
@@ -28,13 +29,6 @@ import androidx.compose.foundation.layout.height
2829
import androidx.compose.foundation.layout.padding
2930
import androidx.compose.foundation.layout.size
3031
import androidx.compose.foundation.layout.width
31-
import androidx.compose.material.icons.Icons
32-
import androidx.compose.material.icons.automirrored.filled.InsertDriveFile
33-
import androidx.compose.material.icons.filled.AudioFile
34-
import androidx.compose.material.icons.filled.Description
35-
import androidx.compose.material.icons.filled.Image
36-
import androidx.compose.material.icons.filled.PictureAsPdf
37-
import androidx.compose.material.icons.filled.VideoFile
3832
import androidx.compose.material3.Button
3933
import androidx.compose.material3.ElevatedCard
4034
import androidx.compose.material3.Icon
@@ -49,13 +43,14 @@ import androidx.compose.runtime.remember
4943
import androidx.compose.runtime.setValue
5044
import androidx.compose.ui.Alignment
5145
import androidx.compose.ui.Modifier
52-
import androidx.compose.ui.graphics.vector.ImageVector
5346
import androidx.compose.ui.layout.ContentScale
5447
import androidx.compose.ui.platform.LocalContext
48+
import androidx.compose.ui.res.painterResource
5549
import androidx.compose.ui.text.style.TextOverflow
5650
import androidx.compose.ui.tooling.preview.Preview
5751
import androidx.compose.ui.unit.dp
5852
import coil.compose.AsyncImage
53+
import com.example.platform.storage.R
5954
import kotlinx.coroutines.Dispatchers
6055
import kotlinx.coroutines.withContext
6156
import java.io.BufferedReader
@@ -64,7 +59,7 @@ import java.io.InputStreamReader
6459
@Composable
6560
fun FileCard(
6661
file: FileRecord,
67-
icon: ImageVector,
62+
@DrawableRes iconResourceId: Int,
6863
contentPreview: @Composable (() -> Unit)? = null,
6964
) {
7065
val sizeLabel = Formatter.formatShortFileSize(LocalContext.current, file.size)
@@ -81,7 +76,7 @@ fun FileCard(
8176
verticalAlignment = Alignment.Top,
8277
) {
8378
Icon(
84-
imageVector = icon,
79+
painter = painterResource(iconResourceId),
8580
contentDescription = null,
8681
modifier = Modifier.size(42.dp),
8782
)
@@ -106,7 +101,7 @@ fun FileCard(
106101

107102
@Composable
108103
fun ImageFileCard(file: FileRecord, contentPreview: @Composable (() -> Unit)? = null) {
109-
FileCard(file, Icons.Default.Image) {
104+
FileCard(file, R.drawable.ic_image_24) {
110105
if (contentPreview != null) {
111106
Spacer(modifier = Modifier.height(16.dp))
112107
contentPreview()
@@ -132,7 +127,7 @@ fun ImageFileCard(file: FileRecord, contentPreview: @Composable (() -> Unit)? =
132127

133128
@Composable
134129
fun VideoFileCard(file: FileRecord, contentPreview: @Composable (() -> Unit)? = null) {
135-
FileCard(file, Icons.Default.VideoFile) {
130+
FileCard(file, R.drawable.ic_video_file_24) {
136131
if (contentPreview != null) {
137132
Spacer(modifier = Modifier.height(16.dp))
138133
contentPreview()
@@ -158,7 +153,7 @@ fun VideoFileCard(file: FileRecord, contentPreview: @Composable (() -> Unit)? =
158153

159154
@Composable
160155
fun AudioFileCard(file: FileRecord, contentPreview: @Composable (() -> Unit)? = null) {
161-
FileCard(file, Icons.Default.AudioFile) {
156+
FileCard(file, R.drawable.ic_audio_file_24) {
162157
if (contentPreview != null) {
163158
Spacer(modifier = Modifier.height(16.dp))
164159
contentPreview()
@@ -194,7 +189,7 @@ fun AudioFileCard(file: FileRecord, contentPreview: @Composable (() -> Unit)? =
194189

195190
@Composable
196191
fun TextFileCard(file: FileRecord, contentPreview: @Composable (() -> Unit)? = null) {
197-
FileCard(file, Icons.Default.Description) {
192+
FileCard(file, R.drawable.ic_description_24) {
198193
if (contentPreview != null) {
199194
Spacer(modifier = Modifier.height(16.dp))
200195
contentPreview()
@@ -230,7 +225,7 @@ fun TextFileCard(file: FileRecord, contentPreview: @Composable (() -> Unit)? = n
230225

231226
@Composable
232227
fun PdfFileCard(file: FileRecord, contentPreview: @Composable (() -> Unit)? = null) {
233-
FileCard(file, Icons.Default.PictureAsPdf) {
228+
FileCard(file, R.drawable.ic_picture_as_pdf_24) {
234229
if (contentPreview != null) {
235230
Spacer(modifier = Modifier.height(16.dp))
236231
contentPreview()
@@ -266,7 +261,7 @@ fun PdfFileCard(file: FileRecord, contentPreview: @Composable (() -> Unit)? = nu
266261

267262
@Composable
268263
fun BinaryFileCard(file: FileRecord, contentPreview: @Composable (() -> Unit)? = null) {
269-
FileCard(file, Icons.AutoMirrored.Filled.InsertDriveFile) {
264+
FileCard(file, R.drawable.ic_insert_drive_file_24) {
270265
if (contentPreview != null) {
271266
Spacer(modifier = Modifier.height(16.dp))
272267
contentPreview()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
2+
3+
<path android:fillColor="@android:color/white" android:pathData="M14,2H6C4.9,2 4.01,2.9 4.01,4L4,20c0,1.1 0.89,2 1.99,2H18c1.1,0 2,-0.9 2,-2V8L14,2zM16,13h-3v3.75c0,1.24 -1.01,2.25 -2.25,2.25S8.5,17.99 8.5,16.75c0,-1.24 1.01,-2.25 2.25,-2.25c0.46,0 0.89,0.14 1.25,0.38V11h4V13zM13,9V3.5L18.5,9H13z"/>
4+
5+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
2+
3+
<path android:fillColor="@android:color/white" android:pathData="M14,2L6,2c-1.1,0 -1.99,0.9 -1.99,2L4,20c0,1.1 0.89,2 1.99,2L18,22c1.1,0 2,-0.9 2,-2L20,8l-6,-6zM16,18L8,18v-2h8v2zM16,14L8,14v-2h8v2zM13,9L13,3.5L18.5,9L13,9z"/>
4+
5+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
2+
3+
<path android:fillColor="@android:color/white" android:pathData="M4.25,5.61C6.27,8.2 10,13 10,13v6c0,0.55 0.45,1 1,1h2c0.55,0 1,-0.45 1,-1v-6c0,0 3.72,-4.8 5.74,-7.39C20.25,4.95 19.78,4 18.95,4H5.04C4.21,4 3.74,4.95 4.25,5.61z"/>
4+
5+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
2+
3+
<path android:fillColor="@android:color/white" android:pathData="M21,19V5c0,-1.1 -0.9,-2 -2,-2H5c-1.1,0 -2,0.9 -2,2v14c0,1.1 0.9,2 2,2h14c1.1,0 2,-0.9 2,-2zM8.5,13.5l2.5,3.01L14.5,12l4.5,6H5l3.5,-4.5z"/>
4+
5+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:autoMirrored="true" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
2+
3+
<path android:fillColor="@android:color/white" android:pathData="M6,2c-1.1,0 -1.99,0.9 -1.99,2L4,20c0,1.1 0.89,2 1.99,2L18,22c1.1,0 2,-0.9 2,-2L20,8l-6,-6L6,2zM13,9L13,3.5L18.5,9L13,9z"/>
4+
5+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
2+
3+
<path android:fillColor="@android:color/white" android:pathData="M20,2L8,2c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2L22,4c0,-1.1 -0.9,-2 -2,-2zM11.5,9.5c0,0.83 -0.67,1.5 -1.5,1.5L9,11v2L7.5,13L7.5,7L10,7c0.83,0 1.5,0.67 1.5,1.5v1zM16.5,11.5c0,0.83 -0.67,1.5 -1.5,1.5h-2.5L12.5,7L15,7c0.83,0 1.5,0.67 1.5,1.5v3zM20.5,8.5L19,8.5v1h1.5L20.5,11L19,11v2h-1.5L17.5,7h3v1.5zM9,9.5h1v-1L9,8.5v1zM4,6L2,6v14c0,1.1 0.9,2 2,2h14v-2L4,20L4,6zM14,11.5h1v-3h-1v3z"/>
4+
5+
</vector>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android" android:height="24dp" android:tint="#000000" android:viewportHeight="24" android:viewportWidth="24" android:width="24dp">
2+
3+
<path android:fillColor="@android:color/white" android:pathData="M14,2H6.01c-1.1,0 -2,0.89 -2,2L4,20c0,1.1 0.9,2 2,2h12c1.1,0 2,-0.9 2,-2V8L14,2zM13,9V3.5L18.5,9H13zM14,14l2,-1.06v4.12L14,16v1c0,0.55 -0.45,1 -1,1H9c-0.55,0 -1,-0.45 -1,-1v-4c0,-0.55 0.45,-1 1,-1h4c0.55,0 1,0.45 1,1V14z"/>
4+
5+
</vector>

0 commit comments

Comments
 (0)