Skip to content

Commit db50398

Browse files
Update fullscreen and status bar
1 parent 7fc0f1b commit db50398

File tree

7 files changed

+129
-11
lines changed

7 files changed

+129
-11
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,88 @@
11
package com.smarttoolfactory.tutorial3_1transitions.chapter2_fragment_transitions
22

33
import android.os.Bundle
4+
import android.view.View
5+
import android.widget.Toast
46
import androidx.appcompat.app.AppCompatActivity
7+
import androidx.coordinatorlayout.widget.CoordinatorLayout
8+
import androidx.core.view.updatePadding
9+
import androidx.navigation.findNavController
10+
import com.google.android.material.bottomnavigation.BottomNavigationView
11+
import com.google.android.material.floatingactionbutton.FloatingActionButton
512
import com.smarttoolfactory.tutorial3_1transitions.R
613

714

15+
@Suppress("DEPRECATION")
816
class Activity2_6FragmentExpandCollapseTransitions : AppCompatActivity() {
917

18+
private lateinit var fab: FloatingActionButton
19+
1020
override fun onCreate(savedInstanceState: Bundle?) {
1121

1222
super.onCreate(savedInstanceState)
1323
setContentView(R.layout.activity2_6_rv_transitions_expand)
1424
title = getString(R.string.activity2_6)
1525

16-
// window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
17-
// View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or
18-
// View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
26+
val rootView = findViewById<CoordinatorLayout>(R.id.coordinatorLayout)
27+
28+
29+
hideSystemUI(rootView, true)
30+
31+
val bottomNavigationView = findViewById<BottomNavigationView>(R.id.bottom_navigation)
32+
33+
bottomNavigationView.setOnApplyWindowInsetsListener { view, insets ->
34+
view.updatePadding(bottom = 0)
35+
insets
36+
}
37+
38+
fab = findViewById<FloatingActionButton>(R.id.fab)
39+
40+
val navController = findNavController(R.id.nav_host_fragment)
41+
42+
43+
navController.addOnDestinationChangedListener { controller, destination, arguments ->
44+
45+
when (destination.id) {
46+
R.id.fragment2_6ExpandCollapseList -> {
47+
fab.setImageState(intArrayOf(-android.R.attr.state_activated), true)
48+
}
49+
50+
R.id.fragment2_6ExpandCollapseDetails -> {
51+
fab.setImageState(intArrayOf(android.R.attr.state_activated), true)
52+
}
53+
}
54+
}
55+
56+
fab.setOnClickListener {
57+
58+
if (navController.currentDestination?.id == R.id.fragment2_6ExpandCollapseList) {
59+
Toast.makeText(applicationContext, "Compose", Toast.LENGTH_SHORT).show()
60+
} else if (navController.currentDestination?.id == R.id.fragment2_6ExpandCollapseDetails) {
61+
onBackPressed()
62+
}
63+
64+
}
65+
}
66+
67+
private fun hideSystemUI(view: View = window.decorView, isFullScreen: Boolean) {
68+
69+
var uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
70+
71+
if (isFullScreen) {
72+
// hide status bar
73+
uiOptions = (
74+
uiOptions
75+
// or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
76+
// Views can use nav bar space if set
77+
or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
78+
or View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
79+
// // Removes Status bar
80+
// or View.SYSTEM_UI_FLAG_FULLSCREEN
81+
// // hide nav bar
82+
// or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
83+
)
84+
}
1985

86+
view.systemUiVisibility = uiOptions
2087
}
2188
}

Tutorial3-1Transitions/src/main/java/com/smarttoolfactory/tutorial3_1transitions/chapter2_fragment_transitions/Fragment2_6ExpandCollapseList.kt

+12-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import android.view.View
66
import android.view.ViewGroup
77
import androidx.core.view.doOnNextLayout
88
import androidx.core.view.doOnPreDraw
9+
import androidx.core.view.updatePadding
910
import androidx.fragment.app.Fragment
1011
import androidx.navigation.NavDirections
1112
import androidx.navigation.fragment.FragmentNavigatorExtras
@@ -18,7 +19,7 @@ import com.smarttoolfactory.tutorial3_1transitions.adapter.TravelAdapter
1819
import com.smarttoolfactory.tutorial3_1transitions.adapter.model.TravelModel
1920
import com.smarttoolfactory.tutorial3_1transitions.databinding.ItemTravelBinding
2021

21-
@Suppress("UNCHECKED_CAST")
22+
@Suppress("UNCHECKED_CAST", "DEPRECATION")
2223
class Fragment2_6ExpandCollapseList : Fragment() {
2324

2425
private val recycledViewPool by lazy {
@@ -65,6 +66,16 @@ class Fragment2_6ExpandCollapseList : Fragment() {
6566

6667
recyclerView.adapter = listAdapter
6768

69+
recyclerView.setOnApplyWindowInsetsListener { view, insets ->
70+
71+
view.updatePadding(
72+
top = insets.systemWindowInsetTop,
73+
bottom = insets.systemWindowInsetBottom
74+
)
75+
insets
76+
}
77+
78+
6879
listAdapter.submitList(
6980
MockDataCreator.generateMockTravelData(requireContext()).toMutableList()
7081
)

Tutorial3-1Transitions/src/main/res/layout/activity2_6_rv_transitions_expand.xml

+2-3
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,9 @@
33
xmlns:tools="http://schemas.android.com/tools">
44

55
<androidx.coordinatorlayout.widget.CoordinatorLayout
6-
android:id="@+id/coordinator_layout"
6+
android:id="@+id/coordinatorLayout"
77
android:layout_width="match_parent"
88
android:layout_height="match_parent"
9-
android:theme="@style/Theme.App.Expandable"
109
tools:context="com.materialstudies.reply.ui.MainActivity">
1110

1211
<fragment
@@ -47,7 +46,7 @@
4746
app:layout_constraintStart_toStartOf="parent"
4847
app:layout_constraintTop_toTopOf="parent"
4948
app:layout_constraintWidth_default="percent"
50-
app:layout_constraintWidth_percent=".68"
49+
app:layout_constraintWidth_percent=".72"
5150
app:menu="@menu/menu_bottom_navigation" />
5251
</androidx.constraintlayout.widget.ConstraintLayout>
5352

Tutorial3-1Transitions/src/main/res/layout/fragment2_6expand_collapse_list.xml

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
android:layout_height="match_parent"
88
android:clipToPadding="false"
99
android:orientation="vertical"
10+
android:paddingBottom="56dp"
1011
android:transitionGroup="true"
1112
app:layoutManager="androidx.recyclerview.widget.LinearLayoutManager"
1213
app:layout_behavior="@string/appbar_scrolling_view_behavior"

Tutorial3-1Transitions/src/main/res/values-night/themes.xml

+27
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,31 @@
3333
<item name="android:windowContentTransitions">true</item>
3434
<item name="android:windowSharedElementsUseOverlay">false</item>
3535
</style>
36+
37+
38+
<style name="Theme.App.Expandable" parent="Theme.MaterialComponents.DayNight.NoActionBar">
39+
40+
<item name="colorPrimary">@color/reply_blue_200</item>
41+
<item name="colorPrimaryVariant">@color/reply_blue_300</item>
42+
<item name="colorSecondary">@color/reply_orange_300</item>
43+
<item name="colorSecondaryVariant">@color/reply_orange_300</item>
44+
45+
<item name="android:colorBackground">@color/reply_black_900</item>
46+
<item name="colorSurface">@color/reply_black_800</item>
47+
<item name="colorError">@color/reply_red_200</item>
48+
49+
<item name="colorOnPrimary">@color/reply_black_900</item>
50+
<item name="colorOnSecondary">@color/reply_black_900</item>
51+
<item name="colorOnBackground">@color/reply_white_50</item>
52+
<item name="colorOnSurface">@color/reply_white_50</item>
53+
<item name="colorOnError">@color/reply_black_900</item>
54+
55+
<item name="scrimBackground">@color/reply_black_900_alpha_087</item>
56+
<item name="android:statusBarColor">@color/reply_black_900_alpha_060</item>
57+
58+
<item name="elevationOverlayEnabled">true</item>
59+
60+
<!--System/Platform attributes-->
61+
<item name="android:windowLightStatusBar" tools:ignore="NewApi">true</item>
62+
</style>
3663
</resources>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<!--
3+
Copyright (c) 2019 Google Inc.
4+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
in compliance with the License. You may obtain a copy of the License at
6+
http://www.apache.org/licenses/LICENSE-2.0
7+
Unless required by applicable law or agreed to in writing, software distributed under the License
8+
is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
9+
or implied. See the License for the specific language governing permissions and limitations under
10+
the License.
11+
-->
12+
<resources>
13+
<!--Set the navigation bar to transparent on Q+ and allow the system to guard against-->
14+
<!--low contrast scenarios.-->
15+
<color name="nav_bar">@android:color/transparent</color>
16+
</resources>

Tutorial3-1Transitions/src/main/res/values/themes.xml

+1-4
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<!-- </item>-->
4848
</style>
4949

50-
<style name="Theme.App.Expandable" parent="Theme.MaterialComponents.DayNight.NoActionBar">
50+
<style name="Theme.App.Expandable" parent="Theme.App.NoActionBar">
5151

5252
<!--Color-->
5353
<item name="colorPrimary">@color/reply_blue_700</item>
@@ -64,16 +64,13 @@
6464
<item name="colorOnBackground">@color/reply_black_900</item>
6565
<item name="colorOnSurface">@color/reply_black_900</item>
6666
<item name="colorOnError">@color/reply_black_900</item>
67-
68-
<item name="scrimBackground">@color/reply_white_50_alpha_060</item>
6967
<item name="android:statusBarColor">@color/reply_blue_50_alpha_060</item>
7068
<item name="android:navigationBarColor">@color/nav_bar</item>
7169

7270
<!--Styles-->
7371
<item name="bottomAppBarStyle">
7472
@style/Widget.MaterialComponents.BottomAppBar.PrimarySurface
7573
</item>
76-
<item name="bottomSheetStyle">@style/Widget.MaterialComponents.BottomSheet.Modal</item>
7774

7875
<!--System/Platform attributes-->
7976
<item name="android:windowBackground">?android:colorBackground</item>

0 commit comments

Comments
 (0)