add logo animation in search bar on app start

This commit is contained in:
johan12345
2021-10-10 19:38:25 +02:00
committed by Johan von Forstner
parent a9f735d783
commit 63eddde837
5 changed files with 145 additions and 67 deletions

View File

@@ -1,5 +1,6 @@
package net.vonforst.evmap
import android.app.PendingIntent
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
@@ -111,56 +112,58 @@ class MapsActivity : AppCompatActivity(),
navController.graph = navGraph
return
} else {
var deepLink: PendingIntent? = null
if (intent?.scheme == "geo") {
val query = intent.data?.query?.split("=")?.get(1)
val coords = getLocationFromIntent(intent)
if (coords != null) {
val lat = coords[0]
val lon = coords[1]
deepLink = navController.createDeepLink()
.setGraph(R.navigation.nav_graph)
.setDestination(R.id.map)
.setArguments(MapFragmentArgs(latLng = LatLng(lat, lon)).toBundle())
.createPendingIntent()
} else if (query != null && query.isNotEmpty()) {
deepLink = navController.createDeepLink()
.setGraph(R.navigation.nav_graph)
.setDestination(R.id.map)
.setArguments(MapFragmentArgs(locationName = query).toBundle())
.createPendingIntent()
}
} else if (intent?.scheme == "https" && intent?.data?.host == "www.goingelectric.de") {
val id = intent.data?.pathSegments?.last()?.toLongOrNull()
if (id != null) {
deepLink = navController.createDeepLink()
.setGraph(R.navigation.nav_graph)
.setDestination(R.id.map)
.setArguments(MapFragmentArgs(chargerId = id).toBundle())
.createPendingIntent()
}
} else if (intent.hasExtra(EXTRA_CHARGER_ID)) {
deepLink = navController.createDeepLink()
.setDestination(R.id.map)
.setArguments(
MapFragmentArgs(
chargerId = intent.getLongExtra(EXTRA_CHARGER_ID, 0),
latLng = LatLng(
intent.getDoubleExtra(EXTRA_LAT, 0.0),
intent.getDoubleExtra(EXTRA_LON, 0.0)
)
).toBundle()
)
.createPendingIntent()
}
navGraph.setStartDestination(R.id.map)
navController.graph = navGraph
}
if (intent?.scheme == "geo") {
val query = intent.data?.query?.split("=")?.get(1)
val coords = getLocationFromIntent(intent)
if (coords != null) {
val lat = coords[0]
val lon = coords[1]
val deepLink = navController.createDeepLink()
.setGraph(R.navigation.nav_graph)
.setDestination(R.id.map)
.setArguments(MapFragmentArgs(latLng = LatLng(lat, lon)).toBundle())
.createPendingIntent()
deepLink.send()
} else if (query != null && query.isNotEmpty()) {
val deepLink = navController.createDeepLink()
.setGraph(R.navigation.nav_graph)
.setDestination(R.id.map)
.setArguments(MapFragmentArgs(locationName = query).toBundle())
.createPendingIntent()
if (deepLink != null) {
navController.graph = navGraph
deepLink.send()
} else {
navController.setGraph(navGraph, MapFragmentArgs(appStart = true).toBundle())
}
} else if (intent?.scheme == "https" && intent?.data?.host == "www.goingelectric.de") {
val id = intent.data?.pathSegments?.last()?.toLongOrNull()
if (id != null) {
val deepLink = navController.createDeepLink()
.setGraph(R.navigation.nav_graph)
.setDestination(R.id.map)
.setArguments(MapFragmentArgs(chargerId = id).toBundle())
.createPendingIntent()
deepLink.send()
}
} else if (intent.hasExtra(EXTRA_CHARGER_ID)) {
navController.createDeepLink()
.setDestination(R.id.map)
.setArguments(
MapFragmentArgs(
chargerId = intent.getLongExtra(EXTRA_CHARGER_ID, 0),
latLng = LatLng(
intent.getDoubleExtra(EXTRA_LAT, 0.0),
intent.getDoubleExtra(EXTRA_LON, 0.0)
)
).toBundle()
)
.createPendingIntent()
.send()
}
}

View File

@@ -250,6 +250,32 @@ class MapFragment : Fragment(), OnMapReadyCallback, MapsActivity.FragmentCallbac
// when there is already another navigation going on
}
}*/
val fragmentArgs: MapFragmentArgs by navArgs()
if (savedInstanceState == null && fragmentArgs.appStart) {
// logo animation after starting the app
binding.appLogo.root.visibility = View.VISIBLE
binding.appLogo.root.alpha = 0f
binding.search.visibility = View.GONE
binding.appLogo.root.animate().alpha(1f)
.withEndAction {
binding.appLogo.root.animate().alpha(0f).apply {
startDelay = 1000
}.withEndAction {
binding.appLogo.root.visibility = View.GONE
binding.search.visibility = View.VISIBLE
binding.search.alpha = 0f
binding.search.animate().alpha(1f).start()
}.start()
}.apply {
startDelay = 100
}.start()
arguments = fragmentArgs.copy(appStart = false).toBundle()
} else {
binding.appLogo.root.visibility = View.GONE
binding.search.visibility = View.VISIBLE
}
}
override fun onResume() {

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:visibility="gone"
tools:visibility="visible">
<ImageView
android:id="@+id/imageView2"
android:layout_width="48dp"
android:layout_height="48dp"
android:padding="-4dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/textView14"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_launcher_foreground" />
<TextView
android:id="@+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
android:text="@string/app_name"
android:textAppearance="@style/TextAppearance.Material3.TitleLarge"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@id/imageView2"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -69,13 +69,17 @@
android:layout_height="48dp"
app:contentInsetStartWithNavigation="70dp">
<LinearLayout
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center_vertical"
android:focusable="true"
android:focusableInTouchMode="true">
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:gravity="center_vertical"
android:focusable="true"
android:focusableInTouchMode="true">
<net.vonforst.evmap.ui.AutocompleteTextViewWithSuggestions
android:id="@+id/search"
@@ -95,20 +99,27 @@
android:popupElevation="2dp"
android:popupBackground="@drawable/rounded_rect_24dp" />
<ImageButton
android:id="@+id/clearSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:background="?attr/selectableItemBackgroundBorderless"
app:invisibleUnless="@{search.text.length() > 0}"
app:tint="?colorControlNormal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/handle"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_close"
android:contentDescription="@string/delete" />
</LinearLayout>
<ImageButton
android:id="@+id/clearSearch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:background="?attr/selectableItemBackgroundBorderless"
app:invisibleUnless="@{search.text.length() > 0}"
app:tint="?colorControlNormal"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/handle"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/ic_close"
android:contentDescription="@string/delete" />
</LinearLayout>
<include
layout="@layout/app_logo_small"
android:id="@+id/app_logo"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
</com.google.android.material.appbar.MaterialToolbar>

View File

@@ -47,6 +47,10 @@
android:defaultValue="@null"
app:argType="com.car2go.maps.model.LatLng"
app:nullable="true" />
<argument
android:name="appStart"
android:defaultValue="false"
app:argType="boolean" />
</fragment>
<fragment
android:id="@+id/about"