-
Notifications
You must be signed in to change notification settings - Fork 257
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Predictive Back] Add a new Predictive Back Samples folder. #94
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# PredictiveBackSample samples | ||
|
||
Shows different types of predictive back animations, including: | ||
|
||
+ back-to-home | ||
+ cross-activity | ||
+ (coming soon) cross-fragment | ||
+ (coming soon) androidx-transitions | ||
+ (coming soon) custom cross-activity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
|
||
/* | ||
* Copyright 2023 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
|
||
plugins { | ||
id("com.example.platform.sample") | ||
alias(libs.plugins.kotlin.android) | ||
} | ||
|
||
android { | ||
namespace = "com.example.platform.ui.predictiveback" | ||
buildFeatures { | ||
viewBinding = true | ||
} | ||
} | ||
|
||
dependencies { | ||
implementation(libs.androidx.appcompat) | ||
implementation(libs.androidx.constraintlayout) | ||
implementation(libs.mdc) | ||
// Add samples specific dependencies | ||
} |
12 changes: 12 additions & 0 deletions
12
samples/user-interface/predictiveback/src/main/AndroidManifest.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"> | ||
|
||
<application> | ||
<activity | ||
android:name=".PBHostingActivity" | ||
android:exported="false" | ||
android:label="@string/title_activity_predictive_back_sample" | ||
android:theme="@style/Theme.PlatformSamples" /> | ||
</application> | ||
|
||
</manifest> |
38 changes: 38 additions & 0 deletions
38
...erface/predictiveback/src/main/java/com/example/platform/ui/predictiveback/PBAnimation.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2023 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.platform.ui.predictiveback | ||
|
||
data class PBAnimation(val title: String, val description: String) | ||
|
||
val animations = listOf( | ||
PBAnimation( | ||
"Enable System Animations", | ||
"The system animations are back-to-home and default cross-activity. To see them: (1) Enable gesture navigation. (2) In Android 14, enable the Predictive Back Developer Option." | ||
), | ||
PBAnimation( | ||
"Back-to-Home", | ||
"To see the back-to-home animation, go to the root activity and swipe back from either the left or right edge to exit the app." | ||
), | ||
PBAnimation( | ||
"Default Cross-Activity", | ||
"To see the default cross-activity animation, on this screen swipe back from either the left or right edge." | ||
), | ||
PBAnimation( | ||
"Cross-Fragment", | ||
"Animation example coming soon." | ||
) | ||
) |
29 changes: 29 additions & 0 deletions
29
...interface/predictiveback/src/main/java/com/example/platform/ui/predictiveback/PBHolder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/* | ||
* Copyright 2023 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.platform.ui.predictiveback | ||
|
||
import androidx.recyclerview.widget.RecyclerView | ||
import com.example.platform.ui.predictiveback.databinding.ListItemAnimationBinding | ||
|
||
class PBHolder( | ||
private val binding: ListItemAnimationBinding | ||
) : RecyclerView.ViewHolder(binding.root) { | ||
fun bind(animation: PBAnimation) { | ||
binding.animationTitle.text = animation.title | ||
binding.animationDescription.text = animation.description | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
.../predictiveback/src/main/java/com/example/platform/ui/predictiveback/PBHostingActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2023 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.platform.ui.predictiveback | ||
|
||
import android.os.Bundle | ||
import androidx.appcompat.app.AppCompatActivity | ||
import com.example.platform.ui.predictiveback.databinding.HostingActivityBinding | ||
import com.google.android.catalog.framework.annotations.Sample | ||
|
||
@Sample( | ||
name="Predictive Back Sample", | ||
description="Shows Predictive Back animations." | ||
) | ||
class PBHostingActivity : AppCompatActivity() { | ||
|
||
private lateinit var binding: HostingActivityBinding | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
|
||
binding = HostingActivityBinding.inflate(layoutInflater) | ||
setContentView(binding.root) | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
...face/predictiveback/src/main/java/com/example/platform/ui/predictiveback/PBListAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* Copyright 2023 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.platform.ui.predictiveback | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.recyclerview.widget.RecyclerView | ||
import com.example.platform.ui.predictiveback.databinding.ListItemAnimationBinding | ||
|
||
class PBListAdapter(private val animations: List<PBAnimation>) : RecyclerView.Adapter<PBHolder>() { | ||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): PBHolder { | ||
val inflater = LayoutInflater.from(parent.context) | ||
val binding = ListItemAnimationBinding.inflate(inflater, parent, false) | ||
return PBHolder(binding) | ||
} | ||
|
||
override fun getItemCount() = animations.size | ||
|
||
override fun onBindViewHolder(holder: PBHolder, position: Int) { | ||
val animation = animations[position] | ||
holder.bind(animation) | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...ace/predictiveback/src/main/java/com/example/platform/ui/predictiveback/PBListFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright 2023 The Android Open Source Project | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* https://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.example.platform.ui.predictiveback | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import androidx.recyclerview.widget.LinearLayoutManager | ||
import com.example.platform.ui.predictiveback.databinding.FragmentAnimationListBinding | ||
|
||
class PBListFragment : Fragment() { | ||
|
||
private var _binding: FragmentAnimationListBinding? = null | ||
private val binding | ||
get() = checkNotNull(_binding){ | ||
"Cannot access binding in PBListFragment because it is null." | ||
} | ||
override fun onCreateView( | ||
inflater: LayoutInflater, container: ViewGroup?, | ||
savedInstanceState: Bundle?, | ||
): View { | ||
_binding = FragmentAnimationListBinding.inflate(inflater, container, false) | ||
binding.pbRecyclerView.layoutManager = LinearLayoutManager(context) | ||
|
||
val adapter = PBListAdapter(animations) | ||
binding.pbRecyclerView.adapter = adapter | ||
|
||
return binding.root | ||
} | ||
|
||
override fun onDestroyView() { | ||
super.onDestroyView() | ||
_binding = null | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
samples/user-interface/predictiveback/src/main/res/layout/fragment_animation_list.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="utf-8"?><!-- | ||
~ Copyright 2023 The Android Open Source Project | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ https://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<LinearLayout | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:orientation="vertical"> | ||
|
||
<TextView | ||
android:id="@+id/textView" | ||
android:layout_width="match_parent" | ||
android:layout_height="wrap_content" | ||
android:layout_marginTop="80dp" | ||
android:layout_margin="16dp" | ||
android:gravity="center" | ||
android:text="@string/predictive_back_sample_first_activity_header" | ||
android:textSize="24sp" | ||
android:textAppearance="?attr/textAppearanceTitleMedium" /> | ||
|
||
<androidx.recyclerview.widget.RecyclerView | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
android:id="@+id/pb_recycler_view" /> | ||
|
||
</LinearLayout> |
25 changes: 25 additions & 0 deletions
25
samples/user-interface/predictiveback/src/main/res/layout/hosting_activity.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<!-- | ||
~ Copyright 2023 The Android Open Source Project | ||
~ | ||
~ Licensed under the Apache License, Version 2.0 (the "License"); | ||
~ you may not use this file except in compliance with the License. | ||
~ You may obtain a copy of the License at | ||
~ | ||
~ https://www.apache.org/licenses/LICENSE-2.0 | ||
~ | ||
~ Unless required by applicable law or agreed to in writing, software | ||
~ distributed under the License is distributed on an "AS IS" BASIS, | ||
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
~ See the License for the specific language governing permissions and | ||
~ limitations under the License. | ||
--> | ||
|
||
<androidx.fragment.app.FragmentContainerView | ||
xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools" | ||
android:id="@+id/fragment_container" | ||
android:name="com.example.platform.ui.predictiveback.PBListFragment" | ||
android:layout_width="match_parent" | ||
android:layout_height="match_parent" | ||
tools:context=".PBHostingActivity" /> |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the activity needed to demostrate the sample? If not maybe you could just use the fragment directly. This way you can skip the theme and all the boilerplate that comes with activity.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the activity is needed. From the sample page folks can swipe back to see the cross-activity animation. I'm also hoping to add a custom cross-activity animation.