-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5455 from grzesiek2010/COLLECT-5454
Support displaying snackbars above a particular view
- Loading branch information
Showing
5 changed files
with
62 additions
and
59 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
androidshared/src/main/java/org/odk/collect/androidshared/ui/SnackbarUtils.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,58 @@ | ||
/* | ||
Copyright 2018 Shobhit | ||
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 | ||
http://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 org.odk.collect.androidshared.ui | ||
|
||
import android.view.View | ||
import android.widget.TextView | ||
import com.google.android.material.R | ||
import com.google.android.material.snackbar.Snackbar | ||
|
||
/** | ||
* Convenience wrapper around Android's [Snackbar] API. | ||
*/ | ||
object SnackbarUtils { | ||
@JvmStatic | ||
@JvmOverloads | ||
fun showShortSnackbar(parentView: View, message: String, anchorView: View? = null) { | ||
showSnackbar(parentView, message, 3500, anchorView) | ||
} | ||
|
||
@JvmStatic | ||
@JvmOverloads | ||
fun showLongSnackbar(parentView: View, message: String, anchorView: View? = null) { | ||
showSnackbar(parentView, message, 5500, anchorView) | ||
} | ||
|
||
/** | ||
* Displays snackbar with {@param message} and multi-line message enabled. | ||
* | ||
* @param parentView The view to find a parent from. | ||
* @param anchorView The view this snackbar should be anchored above. | ||
* @param message The text to show. Can be formatted text. | ||
*/ | ||
private fun showSnackbar(parentView: View, message: String, duration: Int, anchorView: View?) { | ||
if (message.isBlank()) { | ||
return | ||
} | ||
|
||
Snackbar.make(parentView, message.trim(), duration).apply { | ||
val textView = this.view.findViewById<TextView>(R.id.snackbar_text) | ||
textView.isSingleLine = false | ||
|
||
if (anchorView?.visibility != View.GONE) { | ||
this.anchorView = anchorView | ||
} | ||
}.show() | ||
} | ||
} |
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
55 changes: 0 additions & 55 deletions
55
collect_app/src/main/java/org/odk/collect/android/utilities/SnackbarUtils.java
This file was deleted.
Oops, something went wrong.