Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="image/*" />
</intent-filter>
</activity>
<!-- need to use Theme.AppCompat -->
<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package com.android.developers.androidify

import android.content.Intent
import android.net.Uri
import android.os.Build
import android.os.Bundle
import android.view.WindowManager
Expand All @@ -28,6 +30,7 @@ import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.runtime.mutableStateOf
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import androidx.core.os.BundleCompat
import com.android.developers.androidify.navigation.MainNavigation
import com.android.developers.androidify.theme.AndroidifyTheme
import com.android.developers.androidify.util.LocalOcclusion
Expand All @@ -46,6 +49,8 @@ class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)

val sharedImageUri: String? = maybeRetrieveSharedImage()

setContent {
AndroidifyTheme {
enableEdgeToEdge(
Expand All @@ -59,7 +64,7 @@ class MainActivity : ComponentActivity() {
),
)
CompositionLocalProvider(LocalOcclusion provides isWindowOccluded) {
MainNavigation()
MainNavigation(sharedImageUri = sharedImageUri)
}
}
}
Expand Down Expand Up @@ -94,4 +99,18 @@ class MainActivity : ComponentActivity() {
windowManager.unregisterTrustedPresentationListener(presentationListener)
}
}

private fun maybeRetrieveSharedImage(): String? {
if (intent?.action != Intent.ACTION_SEND || intent.type?.startsWith("image/") != true) {
return null
}
val extras = intent.extras ?: return null

return BundleCompat.getParcelable(
extras,
Intent.EXTRA_STREAM,
Uri::class.java,
)?.toString()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.android.developers.androidify.navigation

import android.content.Intent
import android.net.Uri
import androidx.compose.animation.ContentTransform
import androidx.compose.animation.ExperimentalSharedTransitionApi
import androidx.compose.animation.fadeIn
Expand All @@ -26,6 +27,7 @@ import androidx.compose.animation.scaleOut
import androidx.compose.material3.ExperimentalMaterial3ExpressiveApi
import androidx.compose.material3.MaterialTheme
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
Expand All @@ -46,8 +48,15 @@ import com.google.android.gms.oss.licenses.OssLicensesMenuActivity

@ExperimentalMaterial3ExpressiveApi
@Composable
fun MainNavigation() {
fun MainNavigation(sharedImageUri: String? = null) {
val backStack = rememberMutableStateListOf<NavigationRoute>(Home)

LaunchedEffect(sharedImageUri) {
if (sharedImageUri != null) {
backStack.add(Create(sharedImageUri))
}
}

var positionReveal by remember {
mutableStateOf(IntOffset.Zero)
}
Expand Down
Loading