Skip to content

Commit 28a6f36

Browse files
committed
virtual-device-app: Add LoadingFragment for commissioning establish started event
Signed-off-by: Jaehoon You <jaehoon.you@samsung.com>
1 parent e059202 commit 28a6f36

File tree

5 files changed

+246
-0
lines changed

5 files changed

+246
-0
lines changed

examples/virtual-device-app/android/App/core/common/src/main/java/com/matter/virtual/device/app/core/common/DeepLink.kt

+8
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,12 @@ object DeepLink {
1818
)
1919
.build()
2020
}
21+
22+
fun getDeepLinkRequestForLoadingFragment(setting: String): NavDeepLinkRequest {
23+
return NavDeepLinkRequest.Builder.fromUri(
24+
"android-app://com.matter.virtual.device.app.feature.main/loadingFragment/${setting}"
25+
.toUri()
26+
)
27+
.build()
28+
}
2129
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package com.matter.virtual.device.app.feature.main
2+
3+
import android.content.Context
4+
import android.os.Bundle
5+
import android.view.LayoutInflater
6+
import android.view.View
7+
import android.view.ViewGroup
8+
import androidx.activity.OnBackPressedCallback
9+
import androidx.appcompat.app.AppCompatActivity
10+
import androidx.databinding.DataBindingUtil
11+
import androidx.fragment.app.Fragment
12+
import androidx.navigation.fragment.findNavController
13+
import androidx.navigation.fragment.navArgs
14+
import com.matter.virtual.device.app.core.common.MatterSettings
15+
import com.matter.virtual.device.app.feature.main.databinding.FragmentLoadingBinding
16+
import dagger.hilt.android.AndroidEntryPoint
17+
import kotlin.math.abs
18+
import kotlinx.serialization.ExperimentalSerializationApi
19+
import kotlinx.serialization.decodeFromString
20+
import kotlinx.serialization.json.Json
21+
import timber.log.Timber
22+
23+
@AndroidEntryPoint
24+
class LoadingFragment : Fragment() {
25+
26+
private lateinit var binding: FragmentLoadingBinding
27+
28+
private lateinit var matterSettings: MatterSettings
29+
private lateinit var onBackPressedCallback: OnBackPressedCallback
30+
31+
override fun onCreateView(
32+
inflater: LayoutInflater,
33+
container: ViewGroup?,
34+
savedInstanceState: Bundle?
35+
): View {
36+
Timber.d("Hit")
37+
binding = DataBindingUtil.inflate(inflater, R.layout.fragment_loading, container, false)
38+
binding.lifecycleOwner = viewLifecycleOwner
39+
40+
return binding.root
41+
}
42+
43+
@OptIn(ExperimentalSerializationApi::class)
44+
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
45+
Timber.d("Hit")
46+
super.onViewCreated(view, savedInstanceState)
47+
48+
(activity as AppCompatActivity).setSupportActionBar(binding.toolbar)
49+
(activity as AppCompatActivity).supportActionBar?.setDisplayHomeAsUpEnabled(true)
50+
51+
binding.appBarLayout.addOnOffsetChangedListener { appBarLayout, verticalOffset ->
52+
var ratio = 0F
53+
if (abs(verticalOffset) != 0) {
54+
ratio = abs(verticalOffset).toFloat() / appBarLayout.totalScrollRange.toFloat()
55+
}
56+
57+
binding.collapseTitle.alpha = 1f - ratio * 2f + 0.1f
58+
binding.toolbarTitle.alpha = (ratio - 0.5f) * 2f + 0.1f
59+
}
60+
61+
val args: LoadingFragmentArgs by navArgs()
62+
this.matterSettings = Json.decodeFromString(args.setting)
63+
}
64+
65+
override fun onResume() {
66+
Timber.d("Hit")
67+
super.onResume()
68+
}
69+
70+
override fun onAttach(context: Context) {
71+
Timber.d("Hit")
72+
super.onAttach(context)
73+
74+
onBackPressedCallback =
75+
object : OnBackPressedCallback(true) {
76+
override fun handleOnBackPressed() {
77+
Timber.d("handleOnBackPressed()")
78+
findNavController().popBackStack()
79+
}
80+
}
81+
82+
requireActivity().onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
83+
}
84+
85+
override fun onDetach() {
86+
Timber.d("Hit")
87+
super.onDetach()
88+
onBackPressedCallback.remove()
89+
}
90+
91+
override fun onDestroy() {
92+
Timber.d("Hit")
93+
super.onDestroy()
94+
}
95+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<layout xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto">
4+
5+
<androidx.coordinatorlayout.widget.CoordinatorLayout
6+
android:layout_width="match_parent"
7+
android:layout_height="match_parent"
8+
android:fitsSystemWindows="true">
9+
10+
<com.google.android.material.appbar.AppBarLayout
11+
android:id="@+id/app_bar_layout"
12+
android:layout_width="match_parent"
13+
android:layout_height="@dimen/appbar_layout_height"
14+
android:background="@android:color/transparent"
15+
android:fitsSystemWindows="true"
16+
app:elevation="0dp"
17+
app:expanded="false"
18+
app:layout_behavior="com.matter.virtual.device.app.core.common.ui.DisableAppBarLayoutBehavior">
19+
20+
<com.google.android.material.appbar.CollapsingToolbarLayout
21+
android:id="@+id/toolbar_layout"
22+
android:layout_width="match_parent"
23+
android:layout_height="match_parent"
24+
android:fitsSystemWindows="true"
25+
android:theme="@style/Theme.CollapsingToolbar"
26+
app:layout_scrollFlags="scroll|exitUntilCollapsed">
27+
28+
<TextView
29+
android:id="@+id/collapse_title"
30+
android:layout_width="match_parent"
31+
android:layout_height="match_parent"
32+
android:gravity="center"
33+
android:text="@string/title_loading"
34+
android:textAlignment="center"
35+
android:textSize="@dimen/collapse_title_text_size" />
36+
37+
<androidx.appcompat.widget.Toolbar
38+
android:id="@+id/toolbar"
39+
android:layout_width="match_parent"
40+
android:layout_height="?attr/actionBarSize"
41+
android:layout_gravity="bottom"
42+
android:background="@android:color/transparent"
43+
android:contentInsetStart="0dp"
44+
android:contentInsetLeft="0dp"
45+
android:contentInsetEnd="0dp"
46+
android:contentInsetRight="0dp"
47+
android:theme="@style/Theme.CollapsingToolbar"
48+
app:contentInsetEnd="0dp"
49+
app:contentInsetLeft="0dp"
50+
app:contentInsetRight="0dp"
51+
app:contentInsetStart="0dp"
52+
app:contentInsetStartWithNavigation="0dp"
53+
app:elevation="0dp"
54+
app:layout_collapseMode="pin">
55+
56+
<androidx.constraintlayout.widget.ConstraintLayout
57+
android:layout_width="match_parent"
58+
android:layout_height="match_parent">
59+
60+
<TextView
61+
android:id="@+id/toolbar_title"
62+
android:layout_width="match_parent"
63+
android:layout_height="wrap_content"
64+
android:text="@string/title_loading"
65+
android:textAlignment="viewStart"
66+
android:textSize="@dimen/toolbar_title_text_size"
67+
app:layout_constraintBottom_toBottomOf="parent"
68+
app:layout_constraintStart_toStartOf="parent"
69+
app:layout_constraintTop_toTopOf="parent" />
70+
</androidx.constraintlayout.widget.ConstraintLayout>
71+
</androidx.appcompat.widget.Toolbar>
72+
</com.google.android.material.appbar.CollapsingToolbarLayout>
73+
</com.google.android.material.appbar.AppBarLayout>
74+
75+
<androidx.core.widget.NestedScrollView
76+
android:id="@+id/nested_scroll_view"
77+
android:layout_width="match_parent"
78+
android:layout_height="match_parent"
79+
android:fillViewport="true"
80+
app:layout_behavior="@string/appbar_scrolling_view_behavior">
81+
82+
<FrameLayout
83+
android:layout_width="match_parent"
84+
android:layout_height="wrap_content"
85+
android:animateLayoutChanges="true">
86+
87+
<androidx.constraintlayout.widget.ConstraintLayout
88+
android:layout_width="match_parent"
89+
android:layout_height="wrap_content"
90+
android:layout_marginStart="@dimen/menu_item_side_space"
91+
android:layout_marginTop="20dp"
92+
android:layout_marginEnd="@dimen/menu_item_side_space"
93+
android:background="@drawable/menu_item_bg">
94+
95+
<com.google.android.material.progressindicator.CircularProgressIndicator
96+
android:id="@+id/loading_progress"
97+
android:layout_width="wrap_content"
98+
android:layout_height="wrap_content"
99+
android:layout_marginStart="20dp"
100+
android:layout_marginTop="20dp"
101+
android:layout_marginEnd="20dp"
102+
android:layout_marginBottom="20dp"
103+
app:indicatorColor="@color/colorControlActivated"
104+
android:indeterminate="true"
105+
app:layout_constraintBottom_toTopOf="@+id/loading_description"
106+
app:layout_constraintEnd_toEndOf="parent"
107+
app:layout_constraintStart_toStartOf="parent"
108+
app:layout_constraintTop_toTopOf="parent" />
109+
110+
<androidx.appcompat.widget.AppCompatTextView
111+
android:id="@+id/loading_description"
112+
android:layout_width="match_parent"
113+
android:layout_height="wrap_content"
114+
android:layout_marginStart="20dp"
115+
android:layout_marginTop="20dp"
116+
android:layout_marginEnd="20dp"
117+
android:layout_marginBottom="20dp"
118+
android:gravity="center"
119+
android:text="@string/description_loading"
120+
android:textAlignment="center"
121+
android:textSize="17sp"
122+
app:layout_constraintBottom_toBottomOf="parent"
123+
app:layout_constraintEnd_toEndOf="parent"
124+
app:layout_constraintStart_toStartOf="parent"
125+
app:layout_constraintTop_toBottomOf="@+id/loading_progress" />
126+
</androidx.constraintlayout.widget.ConstraintLayout>
127+
</FrameLayout>
128+
</androidx.core.widget.NestedScrollView>
129+
</androidx.coordinatorlayout.widget.CoordinatorLayout>
130+
</layout>

examples/virtual-device-app/android/App/feature/main/src/main/res/navigation/main_nav_graph.xml

+11
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,15 @@
1010
android:name="com.matter.virtual.device.app.feature.main.MainFragment"
1111
android:label="MainFragment"
1212
tools:layout="@layout/fragment_main" />
13+
14+
<fragment
15+
android:id="@+id/loadingFragment"
16+
android:name="com.matter.virtual.device.app.feature.main.LoadingFragment"
17+
android:label="LoadingFragment"
18+
tools:layout="@layout/fragment_loading">
19+
<argument
20+
android:name="setting"
21+
app:argType="string" />
22+
<deepLink app:uri="android-app://com.matter.virtual.device.app.feature.main/loadingFragment/{setting}" />
23+
</fragment>
1324
</navigation>
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<resources>
33
<string name="title_main" translatable="false">Matter Virtual Device</string>
4+
<string name="title_loading" translatable="false">Loading</string>
5+
<string name="description_loading">Commissioning in process.</string>
46
</resources>

0 commit comments

Comments
 (0)