Skip to content
This repository has been archived by the owner on Feb 20, 2023. It is now read-only.

Commit

Permalink
For #3086: Adds settings animations
Browse files Browse the repository at this point in the history
  • Loading branch information
sblatz committed Mar 16, 2020
1 parent e861200 commit 2d7b7a7
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 3 deletions.
21 changes: 21 additions & 0 deletions app/src/main/java/org/mozilla/fenix/settings/SettingsFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ import androidx.preference.Preference
import androidx.preference.Preference.OnPreferenceClickListener
import androidx.preference.PreferenceCategory
import androidx.preference.PreferenceFragmentCompat
import androidx.recyclerview.widget.RecyclerView
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.Dispatchers.Main
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import mozilla.components.concept.sync.AccountObserver
Expand Down Expand Up @@ -114,6 +117,8 @@ class SettingsFragment : PreferenceFragmentCompat() {
showToolbar(getString(R.string.settings_title))

update()

view!!.findViewById<RecyclerView>(R.id.recycler_view)?.hideInitialScrollBar(lifecycleScope)
}

private fun update() {
Expand Down Expand Up @@ -165,6 +170,10 @@ class SettingsFragment : PreferenceFragmentCompat() {

@Suppress("ComplexMethod", "LongMethod")
override fun onPreferenceTreeClick(preference: Preference): Boolean {
// Hide the scrollbar so the animation looks smoother
val recyclerView = view!!.findViewById<RecyclerView>(R.id.recycler_view)
recyclerView.isVerticalScrollBarEnabled = false

val directions: NavDirections? = when (preference.key) {
resources.getString(R.string.pref_key_search_settings) -> {
SettingsFragmentDirections.actionSettingsFragmentToSearchEngineFragment()
Expand Down Expand Up @@ -301,6 +310,18 @@ class SettingsFragment : PreferenceFragmentCompat() {
}
}

// Extension function for hiding the scroll bar on initial loading. We must do this so the
// animation to the next screen doesn't animate the initial scroll bar (it ignores
// isVerticalScrollBarEnabled being set to false).
private fun RecyclerView.hideInitialScrollBar(scope: CoroutineScope) {
scope.launch {
val originalSize = scrollBarSize
scrollBarSize = 0
delay(10)
scrollBarSize = originalSize
}
}

/**
* Updates the UI to reflect current account state.
* Possible conditions are logged-in without problems, logged-out, and logged-in but needs to re-authenticate.
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/res/anim/slide_in_left.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="-50%" android:toXDelta="0%"
android:interpolator="@android:interpolator/decelerate_quad"
android:duration="275"/>
<alpha android:fromAlpha="0" android:toAlpha="1.0"
android:duration="275" />
</set>
11 changes: 11 additions & 0 deletions app/src/main/res/anim/slide_in_right.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="50%" android:toXDelta="0%"
android:interpolator="@android:interpolator/decelerate_quad"
android:duration="275"/>
<alpha android:fromAlpha="0" android:toAlpha="1.0"
android:duration="275" />
</set>
11 changes: 11 additions & 0 deletions app/src/main/res/anim/slide_out_left.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0%" android:toXDelta="-50%"
android:interpolator="@android:interpolator/decelerate_quad"
android:duration="275"/>
<alpha android:fromAlpha="1.0" android:toAlpha="0"
android:duration="275" />
</set>
11 changes: 11 additions & 0 deletions app/src/main/res/anim/slide_out_right.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<!-- This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate android:fromXDelta="0%" android:toXDelta="50%"
android:interpolator="@android:interpolator/decelerate_quad"
android:duration="275"/>
<alpha android:fromAlpha="1.0" android:toAlpha="0"
android:duration="275" />
</set>g
53 changes: 52 additions & 1 deletion app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
<fragment
android:id="@+id/homeFragment"
android:name="org.mozilla.fenix.home.HomeFragment"
app:enterAnim="@anim/zoom_out_fade"
tools:layout="@layout/fragment_home">
<action
android:id="@+id/action_homeFragment_to_turnOnSyncFragment"
Expand Down Expand Up @@ -87,6 +86,10 @@
app:destination="@id/historyFragment" />
<action
android:id="@+id/action_homeFragment_to_settingsFragment"
app:enterAnim="@anim/fade_in_up"
app:exitAnim="@anim/fade_out"
app:popExitAnim="@anim/fade_out_down"
app:popEnterAnim="@anim/fade_in"
app:destination="@id/settingsFragment" />
<action
android:id="@+id/action_homeFragment_to_createCollectionFragment"
Expand Down Expand Up @@ -381,40 +384,88 @@
app:popUpTo="@+id/settingsFragment" />
<action
android:id="@+id/action_settingsFragment_to_dataChoicesFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/dataChoicesFragment"
app:popUpTo="@+id/settingsFragment" />
<action
android:id="@+id/action_settingsFragment_to_sitePermissionsFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/sitePermissionsFragment" />
<action
android:id="@+id/action_settingsFragment_to_loginsFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/loginsFragment" />
<action
android:id="@+id/action_settingsFragment_to_accessibilityFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/accessibilityFragment" />
<action
android:id="@+id/action_settingsFragment_to_accountSettingsFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/accountSettingsFragment" />
<action
android:id="@+id/action_settingsFragment_to_searchEngineFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/searchEngineFragment" />
<action
android:id="@+id/action_settingsFragment_to_turnOnSyncFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/turnOnSyncFragment" />
<action
android:id="@+id/action_settingsFragment_to_aboutFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/aboutFragment" />
<action
android:id="@+id/action_settingsFragment_to_customizationFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/customizationFragment" />
<action
android:id="@+id/action_settingsFragment_to_privateBrowsingFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/privateBrowsingFragment" />
<action
android:id="@+id/action_settingsFragment_to_trackingProtectionFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/trackingProtectionFragment" />
<action
android:id="@+id/action_settingsFragment_to_deleteBrowsingDataFragment"
app:enterAnim="@anim/slide_in_right"
app:exitAnim="@anim/slide_out_left"
app:popEnterAnim="@anim/slide_in_left"
app:popExitAnim="@anim/slide_out_right"
app:destination="@id/deleteBrowsingDataFragment" />
<action
android:id="@+id/action_settingsFragment_to_accountProblemFragment"
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
- License, v. 2.0. If a copy of the MPL was not distributed with this
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->

<androidx.preference.PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.preference.PreferenceScreen
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:scrollbars="none">

<androidx.preference.Preference
app:allowDividerBelow="false"
Expand Down

0 comments on commit 2d7b7a7

Please sign in to comment.