Repository: pranavpandey/dynamic-toasts Branch: master Commit: 63df450837fa Files: 52 Total size: 193.8 KB Directory structure: gitextract_ks34k4c_/ ├── .github/ │ ├── FUNDING.yml │ ├── ISSUE_TEMPLATE/ │ │ └── issue_template.md │ ├── PULL_REQUEST_TEMPLATE.md │ └── workflows/ │ └── build.yml ├── .gitignore ├── .travis.yml ├── CNAME ├── CODE_OF_CONDUCT.md ├── LICENSE ├── README.md ├── build.gradle ├── dynamic-toasts/ │ ├── build.gradle │ ├── maven.gradle │ └── src/ │ └── main/ │ ├── AndroidManifest.xml │ ├── java/ │ │ └── com/ │ │ └── pranavpandey/ │ │ └── android/ │ │ └── dynamic/ │ │ └── toasts/ │ │ ├── DynamicHint.java │ │ ├── DynamicToast.java │ │ └── internal/ │ │ ├── ToastCompat.java │ │ └── ToastContext.java │ └── res/ │ ├── drawable/ │ │ ├── adt_hint_background.xml │ │ └── adt_toast_background.xml │ ├── layout/ │ │ ├── adt_layout_hint.xml │ │ └── adt_layout_toast.xml │ └── values/ │ └── dimens.xml ├── gradle/ │ └── wrapper/ │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradle.properties ├── gradlew ├── gradlew.bat ├── graphics/ │ ├── icon.psd │ ├── legacy/ │ │ └── icon.psd │ └── preview.psd ├── sample/ │ ├── build.gradle │ ├── proguard-rules.pro │ └── src/ │ └── main/ │ ├── AndroidManifest.xml │ ├── java/ │ │ └── com/ │ │ └── pranavpandey/ │ │ └── android/ │ │ └── dynamic/ │ │ └── toasts/ │ │ └── sample/ │ │ ├── DynamicToastsActivity.kt │ │ └── dialog/ │ │ └── AboutDialogFragment.kt │ └── res/ │ ├── drawable/ │ │ ├── app_bar_shadow.xml │ │ ├── bg_custom_toast.xml │ │ ├── ic_info.xml │ │ ├── ic_launcher_foreground.xml │ │ ├── ic_social_github.xml │ │ └── ic_toast_icon.xml │ ├── layout/ │ │ ├── activity_dynamic_toasts.xml │ │ ├── content_dynamic_toasts.xml │ │ └── dialog_about.xml │ ├── menu/ │ │ └── main.xml │ ├── mipmap-anydpi-v26/ │ │ └── ic_launcher.xml │ └── values/ │ ├── colors.xml │ ├── dimens.xml │ ├── strings.xml │ └── styles.xml └── settings.gradle ================================================ FILE CONTENTS ================================================ ================================================ FILE: .github/FUNDING.yml ================================================ # Funding links github: pranavpandey open_collective: pranavpandeydev ko_fi: pranavpandey buy_me_a_coffee: pranavpandey patreon: pranavpandey custom: ['paypal.me/pranavpandeydev'] ================================================ FILE: .github/ISSUE_TEMPLATE/issue_template.md ================================================ --- name: Issue about: Create a issue to help us improve title: "Short description of the issue" --- **Description:** Full description of the issue. **Expected behavior:** Screenshots and/or description of the expected behavior. **Source code:** [OPTIONAL] The code snippet which is causing this issue. **Sample app and/or repro:** [OPTIONAL] A sample app or steps to reproduce the issue. You may attach a `zip` or `APK` file of the sample app or a link to the GitHub repository. **Android API version:** Android API version. `API 19` **Library version:** The Library version you are using. `1.0.0` **Device:** Device on which the bug was encountered. `Emulator or Brand Model` *Please make sure that you are using the [latest version](https://github.com/pranavpandey/dynamic-toasts/releases) of the library and we also accept [pull requests](https://github.com/pranavpandey/dynamic-toasts/pulls).* ================================================ FILE: .github/PULL_REQUEST_TEMPLATE.md ================================================ ### Thanks for starting a pull request! ## Changes - - ## Testing Describe how you tested your changes. ## Issues [OPTIONAL] Link to GitHub issues it solves. `Resolve #1234` ================================================ FILE: .github/workflows/build.yml ================================================ name: Build on: push: branches: - master jobs: build: runs-on: ubuntu-latest timeout-minutes: 60 steps: - name: Checkout uses: actions/checkout@v3 - name: Setup JDK 17 uses: actions/setup-java@v3 with: distribution: 'zulu' java-version: 17 - name: Setup Gradle uses: gradle/gradle-build-action@v2 - name: Build with Gradle run: | chmod +x gradlew ./gradlew build - name: Generate Javadoc if: github.ref_type == 'tag' run: ./gradlew generateJavadoc ================================================ FILE: .gitignore ================================================ # Built application files *.apk *.ap_ # Files for the Dalvik VM *.dex # Java class files *.class # Generated files bin/ gen/ # Gradle files .gradle/ build/ release/ # IntelliJ project files **.iml .idea # Android Studio captures folder captures/ # Local configuration file (sdk path, etc) local.properties # Proguard folder generated by Eclipse proguard/ # Log Files *.log # Misc .DS_Store ================================================ FILE: .travis.yml ================================================ language: android jdk: oraclejdk17 before_install: - mkdir "$ANDROID_HOME/licenses" || true - echo -e "\n24333f8a63b6825ea9c5514f83c2829b004d1fee" > "$ANDROID_HOME/licenses/android-sdk-license" - echo -e "\n84831b9409646a918e30573bab4c9c91346d8abd" > "$ANDROID_HOME/licenses/android-sdk-preview-license" android: components: - tools - platform-tools - build-tools-35.0.0 - android-35 - extra-android-support - extra-android-m2repository - extra-google-m2repository before_script: - chmod +x gradlew script: - ./gradlew build after_success: - ./gradlew generateJavadoc deploy: provider: pages token: $GITHUB_TOKEN edge: true keep_history: true local_dir: dynamic-toasts/build/docs/javadoc/release on: branch: master tags: true ================================================ FILE: CNAME ================================================ pranavpandey.org ================================================ FILE: CODE_OF_CONDUCT.md ================================================ # Contributor Covenant Code of Conduct ## Our Pledge We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, caste, color, religion, or sexual identity and orientation. We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. ## Our Standards Examples of behavior that contributes to a positive environment for our community include: * Demonstrating empathy and kindness toward other people * Being respectful of differing opinions, viewpoints, and experiences * Giving and gracefully accepting constructive feedback * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience * Focusing on what is best not just for us as individuals, but for the overall community Examples of unacceptable behavior include: * The use of sexualized language or imagery, and sexual attention or advances of any kind * Trolling, insulting or derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or email address, without their explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Enforcement Responsibilities Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. ## Scope This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at support@pranavpandey.com. All complaints will be reviewed and investigated promptly and fairly. All community leaders are obligated to respect the privacy and security of the reporter of any incident. ## Enforcement Guidelines Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: ### 1. Correction **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. ### 2. Warning **Community Impact**: A violation through a single incident or series of actions. **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. ### 3. Temporary Ban **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. ### 4. Permanent Ban **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. **Consequence**: A permanent ban from any sort of public interaction within the community. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.1, available at [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1]. Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder][Mozilla CoC]. For answers to common questions about this code of conduct, see the FAQ at [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at [https://www.contributor-covenant.org/translations][translations]. [homepage]: https://www.contributor-covenant.org [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html [Mozilla CoC]: https://github.com/mozilla/diversity [FAQ]: https://www.contributor-covenant.org/faq [translations]: https://www.contributor-covenant.org/translations ================================================ FILE: LICENSE ================================================ Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and (b) You must cause any modified files to carry prominent notices stating that You changed the files; and (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. END OF TERMS AND CONDITIONS APPENDIX: How to apply the Apache License to your work. To apply the Apache License to your work, attach the following boilerplate notice, with the fields enclosed by brackets "[]" replaced with your own identifying information. (Don't include the brackets!) The text should be enclosed in the appropriate comment syntax for the file format. We also recommend that a file or class name and description of purpose be included on the same "printed page" as the copyright notice for easier identification within third-party archives. Copyright 2017-2024 Pranav Pandey 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. ================================================ FILE: README.md ================================================ # Dynamic Toasts [![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg?)](https://www.apache.org/licenses/LICENSE-2.0.html) [![Build Status](https://travis-ci.org/pranavpandey/dynamic-toasts.svg?branch=master)](https://travis-ci.org/pranavpandey/dynamic-toasts) [![Release](https://img.shields.io/maven-central/v/com.pranavpandey.android/dynamic-toasts)](https://search.maven.org/artifact/com.pranavpandey.android/dynamic-toasts) **A simple library to display themed toasts with icon and text on Android 2.3 (API 9) and above.** > [!IMPORTANT] > Since v0.4.0, it uses [26.x.x support libraries][android-support] so, minimum SDK will be Android 4.0 (API 14).
Since v2.0.0, it uses [AndroidX][androidx] so, first [migrate][androidx-migrate] your project to AndroidX.
Since v4.1.0, it is dependent on Java 8 due to the dependency on [Dynamic Utils][dynamic-utils].
Since v4.2.0, it is targeting Java 17 to provide maximum compatibility.
Since v4.3.0, the minimum SDK is Android 4.4 (API 19) to comply with the latest policies. --- ## Contents - [Installation](#installation) - [Usage](#usage) - [Configuration](#configuration) - [Default toast](#default-toast) - [Default toast with duration](#default-toast-with-duration) - [Default toast with icon](#default-toast-with-icon) - [Default toast with icon and duration](#default-toast-with-icon-and-duration) - [Error toast](#error-toast) - [Error toast with duration](#error-toast-with-duration) - [Success toast](#success-toast) - [Success toast with duration](#success-toast-with-duration) - [Warning toast](#warning-toast) - [Warning toast with duration](#warning-toast-with-duration) - [Custom toast](#custom-toast) - [Custom toast with duration](#custom-toast-with-duration) - [Custom toast with icon](#custom-toast-with-icon) - [Custom toast with icon and duration](#custom-toast-with-icon-and-duration) - [Cheat sheets](#cheat-sheets) - [Dependency](#dependency) - [License](#license) --- ## Installation It can be installed by adding the following dependency to your `build.gradle` file: ```groovy dependencies { // For AndroidX enabled projects. implementation 'com.pranavpandey.android:dynamic-toasts:4.3.0' // For legacy projects. implementation 'com.pranavpandey.android:dynamic-toasts:1.3.0' } ``` --- ## Usage It has several method to display toasts based on the requirement. Each method returns a `Toast` object which can be customised further. Please call `show()` method to display the toast. > For a complete reference, please read the [documentation][documentation]. ### Configuration Optional configuration to customise the toasts further like custom background color or drawable, custom text size, typeface or icon size, etc. Various methods can be called anywhere in the app to do customisations. ```java DynamicToast.Config.getInstance() // Background color for default toast. .setDefaultBackgroundColor(@ColorInt int defaultBackgroundColor) // Tint color for default toast. .setDefaultTintColor(@ColorInt int defaultTintColor) // Background color for error toast. .setErrorBackgroundColor(@ColorInt int errorBackgroundColor) // Background color for success toast. .setSuccessBackgroundColor(@ColorInt int successBackgroundColor) // Background color for warning toast. .setWarningBackgroundColor(@ColorInt int warningBackgroundColor) // Custom icon for error toast. Pass `null` to use default icon. .setErrorIcon(@Nullable Drawable errorIcon) // Custom icon for success toast. Pass `null` to use default icon. .setSuccessIcon(@Nullable Drawable successIcon) // Custom icon for warning toast. Pass `null` to use default icon. .setWarningIcon(@Nullable Drawable warningIcon) // Disable icon for all the toasts. .setDisableIcon(boolean disableIcon) // Custom icon size in `pixels` for all the toasts. .setIconSize(int iconSize) // Custom text size in `SP` for all the toasts. .setTextSize(int textSize) // Custom text typeface for all the toasts. Pass `null` to use system typeface. .setTextTypeface(@Nullable Typeface textTypeface) // Custom background drawable for all the toasts. Pass `null` to use default background. .setToastBackground(@Nullable Drawable toastBackground) // Apply customisations. .apply(); ``` Call `reset()` method to reset all the customisations. ```java // Reset customisations. DynamicToast.Config.getInstance().reset(); ``` ### Default toast Simple toast based on the vanilla Android theme for `Toast.LENGTH_SHORT` duration. ```java DynamicToast.make(context, "Default toast").show(); ``` ### Default toast with duration Simple toast based on the vanilla Android theme for supplied duration. ```java DynamicToast.make(context, "Default toast with duration", duration).show(); ``` ### Default toast with icon Simple toast based on the vanilla Android theme with a icon for `Toast.LENGTH_SHORT` duration. ```java DynamicToast.make(context, "Default toast with icon", drawable).show(); ``` ### Default toast with icon and duration Simple toast based on the vanilla Android theme with a icon for supplied duration. ```java DynamicToast.make(context, "Default toast with icon and duration", drawable, duration).show(); ``` ### Error toast Error toast with `#F44336` background for `Toast.LENGTH_SHORT` duration. ```java DynamicToast.makeError(context, "Error toast").show(); ``` ### Error toast with duration Error toast with `#F44336` background for supplied duration. ```java DynamicToast.makeError(context, "Error toast with duration", duration).show(); ``` ### Success toast Success toast with `#4CAF50` background for `Toast.LENGTH_SHORT` duration. ```java DynamicToast.makeSuccess(context, "Success toast").show(); ``` ### Success toast with duration Success toast with `#4CAF50` background for supplied duration. ```java DynamicToast.makeSuccess(context, "Success toast with duration", duration).show(); ``` ### Warning toast Warning toast with `#FFEB3B` background for `Toast.LENGTH_SHORT` duration. ```java DynamicToast.makeWarning(context, "Warning toast").show(); ``` ### Warning toast with duration Warning toast with `#FFEB3B` background for supplied duration. ```java DynamicToast.makeWarning(context, "Warning toast with duration", duration).show(); ``` ### Custom toast Custom toast based on the supplied background and tint color for `Toast.LENGTH_SHORT` duration. ```java DynamicToast.make(context, "Custom toast", tintColor, backgroundColor).show(); ``` ### Custom toast with duration Custom toast based on the supplied background and tint color for supplied duration. ```java DynamicToast.make(context, "Custom toast with duration", tintColor, backgroundColor, duration).show(); ``` ### Custom toast with icon Custom toast based on the supplied icon, background and tint color theme for `Toast.LENGTH_SHORT` duration. ```java DynamicToast.make(context, "Custom toast with icon", drawable, tintColor, backgroundColor).show(); ``` ### Custom toast with icon and duration Custom toast based on the supplied icon, background and tint color theme for supplied duration. ```java DynamicToast.make(context, "Custom toast with icon and duration", drawable, tintColor, backgroundColor, duration).show(); ``` ### Cheat sheets Use dynamic hint to display cheat sheets for any `view`. All the methods are same as explained above, just replace `DynamicToast` with `DynamicHint` to create a cheat sheet. > Use `DynamicHint.show(view, toast)` method to display it according to the anchor view position. ### Dependency It depends on the [dynamic-utils][dynamic-utils] to perform various internal operations. So, its functions can also be used to perform other useful operations. --- ## Author Pranav Pandey [![GitHub](https://img.shields.io/github/followers/pranavpandey?label=GitHub&style=social)](https://github.com/pranavpandey) [![Follow on Twitter](https://img.shields.io/twitter/follow/pranavpandeydev?label=Follow&style=social)](https://twitter.com/intent/follow?screen_name=pranavpandeydev) [![Donate via PayPal](https://img.shields.io/static/v1?label=Donate&message=PayPal&color=blue)](https://paypal.me/pranavpandeydev) --- ## License Copyright 2017-2024 Pranav Pandey 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. [android-support]: https://developer.android.com/topic/libraries/support-library/revisions.html#26-0-0 [androidx]: https://developer.android.com/jetpack/androidx [androidx core]: https://developer.android.com/jetpack/androidx/releases/core [androidx-migrate]: https://developer.android.com/jetpack/androidx/migrate [documentation]: https://pranavpandey.github.io/dynamic-toasts [dynamic-utils]: https://github.com/pranavpandey/dynamic-utils ================================================ FILE: build.gradle ================================================ /* * Copyright 2017-2025 Pranav Pandey * * 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. */ buildscript { ext.versions = [ 'compileSdk' : 35, 'minSdk' : 21, 'targetSdk' : 35, 'buildTools' : '35.0.0', 'constraintlayout': '2.1.4', 'dynamic' : '4.6.1', 'dialogs' : '4.5.0', 'flexbox' : '3.0.0', 'kotlin' : '1.9.24' ] repositories { mavenCentral() google() } dependencies { classpath 'com.android.tools.build:gradle:8.7.3' classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${versions.kotlin}" } } plugins { id("io.github.gradle-nexus.publish-plugin") version "2.0.0" } allprojects { repositories { mavenCentral() google() } } tasks.register('clean', Delete) { delete rootProject.layout.buildDirectory } ext { projectName = 'dynamic-toasts' projectDesc = 'A simple library to display themed toasts with icon and text on Android.' versionDesc = 'A simple library to display themed toasts with icon and text on Android 4.0 ' + '(API 14) and above.' referenceTitle = 'Dynamic Toasts API reference' siteUrl = 'https://github.com/pranavpandey/dynamic-toasts' gitUrl = 'https://github.com/pranavpandey/dynamic-toasts' issueUrl = 'https://github.com/pranavpandey/dynamic-toasts/issues' githubUrl = 'pranavpandey/dynamic-toasts' mavenRepo = 'android' mavenGroup = 'com.pranavpandey.android' mavenDir = 'com/pranavpandey/android' mavenArtifactId = 'dynamic-toasts' mavenInceptionYear = '2017' mavenVersion = '4.3.0' mavenVersionCode = 34 sampleVersionCode = 35 developerId = 'pranavpandey' developerName = 'Pranav Pandey' developerEmail = 'dynamic@pranavpandey.com' licenseName = 'The Apache Software License, Version 2.0' licenseUrl = 'http://www.apache.org/licenses/LICENSE-2.0.txt' licenseDistribution = 'repo' allLicenses = ["Apache-2.0"] publication = 'local.properties' ext["signing.keyId"] = '' ext["signing.password"] = '' ext["signing.secretKeyRingFile"] = '' ossrhUsername = '' ossrhPassword = '' sonatypeStagingProfileId = '' } apply plugin: 'io.github.gradle-nexus.publish-plugin' File publish = project.rootProject.file("${publication}") if (publish.exists()) { Properties properties = new Properties() new FileInputStream(publish).withCloseable { is -> properties.load(is) } properties.each { name, value -> ext[name] = value } } nexusPublishing { repositories { sonatype { username = ossrhUsername password = ossrhPassword stagingProfileId = sonatypeStagingProfileId } } } ================================================ FILE: dynamic-toasts/build.gradle ================================================ /* * Copyright 2017-2024 Pranav Pandey * * 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. */ apply plugin: 'com.android.library' android { compileSdkVersion versions.compileSdk buildToolsVersion versions.buildTools namespace 'com.pranavpandey.android.dynamic.toasts' defaultConfig { minSdkVersion versions.minSdk targetSdkVersion versions.targetSdk } sourceSets { main.res.srcDirs 'res' } compileOptions { sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 } } dependencies { implementation(platform("org.jetbrains.kotlin:kotlin-bom:${versions.kotlin}")) api "com.pranavpandey.android:dynamic-utils:${versions.dynamic}" } if (project.rootProject.file("${publication}").exists()) { apply from: 'maven.gradle' } tasks.register('generateJavadoc') { description "Generates Javadoc." } project.afterEvaluate { android.libraryVariants.configureEach { variant -> def task = project.tasks.create( "generate${variant.name.capitalize()}Javadoc", Javadoc) { title "${referenceTitle}

${versionDesc}

${mavenVersion}
" description "Generates Javadoc for $variant.name." destinationDir = new File(destinationDir, variant.baseName) source = variant.sourceSets.collect { it.java.sourceFiles }.inject { m, i -> m + i } doFirst { classpath = project.files(variant.javaCompileProvider.get().classpath.files, project.android.getBootClasspath()) } if (JavaVersion.current().isJava8Compatible()) { options.addStringOption('Xdoclint:none', '-quiet') } options.memberLevel = JavadocMemberLevel.PROTECTED exclude "**/R", "**/R.**", "**/R\$**", "**/BuildConfig*" options.windowTitle = "${referenceTitle}" options.links('http://docs.oracle.com/javase/8/docs/api', 'http://docs.oracle.com/javase/17/docs/api') options.links('https://developer.android.com/reference') options.linksOffline('https://developer.android.com/reference', 'https://developer.android.com/reference/androidx') options.links('https://pranavpandey.org/dynamic-utils') failOnError false } task.dependsOn "assemble${variant.name.capitalize()}" generateJavadoc.dependsOn task } } ================================================ FILE: dynamic-toasts/maven.gradle ================================================ /* * Copyright 2017-2024 Pranav Pandey * * 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. */ apply plugin: 'maven-publish' apply plugin: 'signing' group = mavenGroup version = mavenVersion // Android libraries if (project.hasProperty("android")) { tasks.register('sourcesJar', Jar) { archiveClassifier.set("sources") from android.sourceSets.main.java.srcDirs } tasks.register('javadoc', Javadoc) { dependsOn "generateReleaseRFile" title "${referenceTitle}

${versionDesc}

${mavenVersion}
" failOnError = false source = android.sourceSets.main.java.sourceFiles doNotTrackState("Javadoc needs to be generated every time.") if (JavaVersion.current().isJava8Compatible()) { options.addStringOption('Xdoclint:none', '-quiet') } options.memberLevel = JavadocMemberLevel.PROTECTED exclude "**/R", "**/R.**", "**/R\$**", "**/BuildConfig*" options.windowTitle = "${referenceTitle}" options.links('http://docs.oracle.com/javase/8/docs/api', 'http://docs.oracle.com/javase/17/docs/api') options.links('https://developer.android.com/reference') options.linksOffline('https://developer.android.com/reference', 'https://developer.android.com/reference/androidx') options.links('https://pranavpandey.org/dynamic-utils') } } else { // Java libraries tasks.register('sourcesJar', Jar) { dependsOn classes archiveClassifier.set("sources") from sourceSets.main.allSource } } tasks.register('javadocJar', Jar) { dependsOn javadoc archiveClassifier.set("javadoc") from javadoc.destinationDir } artifacts { archives javadocJar archives sourcesJar } // Maven publishing { publications { library(MavenPublication) { groupId mavenGroup artifactId mavenArtifactId version mavenVersion artifact "$buildDir/outputs/aar/$mavenArtifactId-release.aar" artifact javadocJar artifact sourcesJar pom.withXml { // Project asNode().appendNode('name', projectName) asNode().appendNode('description', projectDesc) asNode().appendNode('url', siteUrl) asNode().appendNode('inceptionYear', mavenInceptionYear) // Licenses def license = asNode().appendNode('licenses').appendNode('license') license.appendNode('name', licenseName) license.appendNode('url', licenseUrl) license.appendNode('distribution', licenseDistribution) // Developers def developer = asNode().appendNode('developers').appendNode('developer') developer.appendNode('id', developerId) developer.appendNode('name', developerName) developer.appendNode('email', developerEmail) // SCM def scm = asNode().appendNode('scm') scm.appendNode('connection', "scm:git:${gitUrl}.git") scm.appendNode('developerConnection', gitUrl) scm.appendNode('url', siteUrl) // Dependencies def dependenciesNode = asNode()['dependencies'][0] if (dependenciesNode == null) { dependenciesNode = asNode().appendNode('dependencies') } // Add all that are 'compile' dependencies. configurations.api.allDependencies.each { def dependencyNode = dependenciesNode.appendNode('dependency') dependencyNode.appendNode('groupId', it.group) dependencyNode.appendNode('artifactId', it.name) dependencyNode.appendNode('version', it.version) } } } } } ext["signing.keyId"] = rootProject.ext["signing.keyId"] ext["signing.password"] = rootProject.ext["signing.password"] ext["signing.secretKeyRingFile"] = rootProject.ext["signing.secretKeyRingFile"] signing { sign publishing.publications } afterEvaluate { project -> // Fix javadoc generation. javadoc.classpath += files(android.libraryVariants.collect { variant -> variant.javaCompileProvider.get().classpath.files }) def pomTask = "generatePomFileForLibraryPublication" def dependencies = [javadocJar, sourcesJar, assembleRelease, pomTask] // Convenience task to prepare everything we need for releases. tasks.register('prepareArtifacts') { dependsOn dependencies } } ================================================ FILE: dynamic-toasts/src/main/AndroidManifest.xml ================================================ ================================================ FILE: dynamic-toasts/src/main/java/com/pranavpandey/android/dynamic/toasts/DynamicHint.java ================================================ /* * Copyright 2017-2022 Pranav Pandey * * 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 com.pranavpandey.android.dynamic.toasts; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.Rect; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.util.DisplayMetrics; import android.util.TypedValue; import android.view.Gravity; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; import com.pranavpandey.android.dynamic.toasts.internal.ToastCompat; import com.pranavpandey.android.dynamic.util.DynamicColorUtils; import com.pranavpandey.android.dynamic.util.DynamicDrawableUtils; import com.pranavpandey.android.dynamic.util.DynamicUnitUtils; /** * Helper class to display themed cheat sheets with icon and text by using {@link Toast}. *

If no color is supplied, it will display default hint based on the Android support library. */ public class DynamicHint { /** * The minimum top inset to mimic status bar. */ private static final int ADT_INSET_TOP = 32; /** * The minimum height for anchor, in dips (density-independent pixels). *

It will be used to avoid overlapping for the smaller view height. */ private static final int ADT_MIN_ANCHOR_HEIGHT = 48; /** * The toast offset, in dips (density-independent pixels). *

It will be used to determine whether the toast should appear above or below the UI element. */ private static final int ADT_TOAST_OFFSET = 4; /** * Default background color for the toast. */ private static final @ColorInt int ADT_DEFAULT_BG_COLOR = Color.parseColor("#454545"); /** * Default tint color for the toast. */ private static final @ColorInt int ADT_DEFAULT_TINT_COLOR = Color.parseColor("#FFFFFF"); /** * Default background color for the error toast. */ private static final @ColorInt int ADT_DEFAULT_ERROR_BG_COLOR = Color.parseColor("#F44336"); /** * Default background color for the success toast. */ private static final @ColorInt int ADT_DEFAULT_SUCCESS_BG_COLOR = Color.parseColor("#4CAF50"); /** * Default background color for the warning toast. */ private static final @ColorInt int ADT_DEFAULT_WARNING_BG_COLOR = Color.parseColor("#FFEB3B"); /** * Default value for the {@link #disableIcon}. *

{@code false} to enable the toast icon. */ private static final boolean ADT_DEFAULT_DISABLE_ICON = false; /** * Default value for the {@link #tintIcon}. *

{@code true} to tint the toast icon. */ private static final boolean ADT_DEFAULT_TINT_ICON = true; /** * Default icon size for the toast in pixels. *

{@code -1} to use in-built icon size. */ private static final @ColorInt int ADT_DEFAULT_ICON_SIZE = -1; /** * Default text size for the toast in SP. *

{@code -1} to use system text size. * * @see TypedValue#COMPLEX_UNIT_SP; */ private static final @ColorInt int ADT_DEFAULT_TEXT_SIZE = -1; /** * Background color for the default toast. */ private static @Nullable @ColorInt Integer defaultBackgroundColor = ADT_DEFAULT_BG_COLOR; /** * Tint color for the default toast. */ private static @Nullable @ColorInt Integer defaultTintColor = ADT_DEFAULT_TINT_COLOR; /** * Background color for the error toast. */ private static @Nullable @ColorInt Integer errorBackgroundColor = ADT_DEFAULT_ERROR_BG_COLOR; /** * Background color for the success toast. */ private static @Nullable @ColorInt Integer successBackgroundColor = ADT_DEFAULT_SUCCESS_BG_COLOR; /** * Background color for the warning toast. */ private static @Nullable @ColorInt Integer warningBackgroundColor = ADT_DEFAULT_WARNING_BG_COLOR; /** * Custom icon for the error toast. *

{@code null} to use the default icon. */ private static Drawable errorIcon = null; /** * Custom icon for the success toast. *

{@code null} to use the default icon. */ private static Drawable successIcon = null; /** * Custom icon for the warning toast. *

{@code null} to use the default icon. */ private static Drawable warningIcon = null; /** * {@code true} to disable icon for all the toasts. */ private static boolean disableIcon = ADT_DEFAULT_DISABLE_ICON; /** * {@code true} to tint icon for all the toasts. */ private static boolean tintIcon = ADT_DEFAULT_TINT_ICON; /** * Icon size for the toast in pixels. */ private static int iconSize = ADT_DEFAULT_ICON_SIZE; /** * Text size for the toast in SP. * * @see TypedValue#COMPLEX_UNIT_SP; */ private static int textSize = ADT_DEFAULT_TEXT_SIZE; /** * Custom typeface used by the toast. *

{@code null} to use the system typeface. */ private static Typeface textTypeface = null; /** * Custom background used by the toast. *

{@code null} to use the default background. */ private static Drawable toastBackground = null; /** * Generate tint color according to the supplied color, otherwise return the default value. * * @param color The color to be used to generate the tint color. * @param defaultColor The default value for the tint color. * * @return The generated tint color according to the supplied color, otherwise return the * default value. */ private static @Nullable @ColorInt Integer generateTintColor( @Nullable @ColorInt Integer color, @Nullable @ColorInt Integer defaultColor) { if (color != null) { return DynamicColorUtils.getTintColor(color); } return defaultColor; } /** * Make a standard toast that just contains a text view. *

The toast duration will be {@link Toast#LENGTH_SHORT}. * * @param context The context to use. * @param text The text to show. Can be formatted text. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast make(@NonNull Context context, @Nullable CharSequence text) { return make(context, text, null, defaultTintColor, defaultBackgroundColor, Toast.LENGTH_SHORT); } /** * Make a standard toast that just contains a text view. * * @param context The context to use. * @param text The text to show. Can be formatted text. * @param duration The duration for the toast, either {@link Toast#LENGTH_SHORT} * or {@link Toast#LENGTH_LONG}. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast make(@NonNull Context context, @Nullable CharSequence text, int duration) { return make(context, text, null, defaultTintColor, defaultBackgroundColor, duration); } /** * Make a error toast with icon and the text. *

The toast duration will be {@link Toast#LENGTH_SHORT}. * * @param context The context to use. * @param text The text to show. Can be formatted text. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast makeError(@NonNull Context context, @Nullable CharSequence text) { return make(context, text, errorIcon != null ? errorIcon : ContextCompat.getDrawable(context, R.drawable.adt_ic_error), generateTintColor(errorBackgroundColor, defaultTintColor), errorBackgroundColor); } /** * Make a error toast with icon and the text. * * @param context The context to use. * @param text The text to show. Can be formatted text. * @param duration The duration for the toast, either {@link Toast#LENGTH_SHORT} * or {@link Toast#LENGTH_LONG}. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast makeError(@NonNull Context context, @Nullable CharSequence text, int duration) { return make(context, text, ContextCompat.getDrawable(context, R.drawable.adt_ic_error), generateTintColor(errorBackgroundColor, defaultTintColor), errorBackgroundColor, duration); } /** * Make a success toast with icon and the text. *

The toast duration will be {@link Toast#LENGTH_SHORT}. * * @param context The context to use. * @param text The text to show. Can be formatted text. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast makeSuccess(@NonNull Context context, @Nullable CharSequence text) { return make(context, text, successIcon != null ? successIcon : ContextCompat.getDrawable(context, R.drawable.adt_ic_success), generateTintColor(successBackgroundColor, defaultTintColor), successBackgroundColor); } /** * Make a success toast with icon and the text. * * @param context The context to use. * @param text The text to show. Can be formatted text. * @param duration The duration for the toast, either {@link Toast#LENGTH_SHORT} * or {@link Toast#LENGTH_LONG}. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast makeSuccess(@NonNull Context context, @Nullable CharSequence text, int duration) { return make(context, text, ContextCompat.getDrawable(context, R.drawable.adt_ic_success), generateTintColor(successBackgroundColor, defaultTintColor), successBackgroundColor, duration); } /** * Make a warning toast with icon and the text. *

The toast duration will be {@link Toast#LENGTH_SHORT}. * * @param context The context to use. * @param text The text to show. Can be formatted text. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast makeWarning(@NonNull Context context, @Nullable CharSequence text) { return make(context, text, warningIcon != null ? warningIcon : ContextCompat.getDrawable(context, R.drawable.adt_ic_warning), generateTintColor(warningBackgroundColor, defaultTintColor), warningBackgroundColor); } /** * Make a warning toast with icon and the text. * * @param context The context to use. * @param text The text to show. Can be formatted text. * @param duration The duration for the toast, either {@link Toast#LENGTH_SHORT} * or {@link Toast#LENGTH_LONG}. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast makeWarning(@NonNull Context context, @Nullable CharSequence text, int duration) { return make(context, text, ContextCompat.getDrawable(context, R.drawable.adt_ic_warning), generateTintColor(warningBackgroundColor, defaultTintColor), warningBackgroundColor, duration); } /** * Make a error toast with icon and the text. *

The toast duration will be {@link Toast#LENGTH_SHORT}. * * @param context The context to use. * @param text The text to show. Can be formatted text. * @param icon The toast icon to show. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast make(@NonNull Context context, @Nullable CharSequence text, @Nullable Drawable icon) { return make(context, text, icon, defaultTintColor, defaultBackgroundColor, Toast.LENGTH_SHORT); } /** * Make a themed toast with icon and the text. * * @param context The context to use. * @param text The text to show. Can be formatted text. * @param icon The toast icon to show. * @param duration The duration for the toast, either {@link Toast#LENGTH_SHORT} * or {@link Toast#LENGTH_LONG}. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast make(@NonNull Context context, @Nullable CharSequence text, @Nullable Drawable icon, int duration) { return make(context, text, icon, defaultTintColor, defaultBackgroundColor, duration); } /** * Make a themed toast with icon and the text. *

The toast duration will be {@link Toast#LENGTH_SHORT}. * * @param context The context to use. * @param text The text to show. Can be formatted text. * @param tintColor The toast tint color based on the toast background. *

It will automatically check for the contrast to provide the * best visibility. * @param backgroundColor The toast background color. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast make(@NonNull Context context, @Nullable CharSequence text, @Nullable @ColorInt Integer tintColor, @Nullable @ColorInt Integer backgroundColor) { return make(context, text, null, tintColor, backgroundColor, Toast.LENGTH_SHORT); } /** * Make a themed toast with text, background and the tint color. *

The toast duration will be {@link Toast#LENGTH_SHORT}. * * @param context The context to use. * @param text The text to show. Can be formatted text. * @param tintColor The toast tint color based on the toast background. *

It will automatically check for the contrast to provide the * best visibility. * @param backgroundColor The toast background color. * @param duration The duration for the toast, either {@link Toast#LENGTH_SHORT} * or {@link Toast#LENGTH_LONG}. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast make(@NonNull Context context, @Nullable CharSequence text, @Nullable @ColorInt Integer tintColor, @Nullable @ColorInt Integer backgroundColor, int duration) { return make(context, text, null, tintColor, backgroundColor, duration); } /** * Make a themed toast with text, icon, background and the tint color. *

The toast duration will be {@link Toast#LENGTH_SHORT}. * * @param context The context to use. * @param text The text to show. Can be formatted text. * @param icon The toast icon to show. * @param tintColor The toast tint color based on the toast background. *

It will automatically check for the contrast to provide the * best visibility. * @param backgroundColor The toast background color. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast make(@NonNull Context context, @Nullable CharSequence text, @Nullable Drawable icon, @Nullable @ColorInt Integer tintColor, @Nullable @ColorInt Integer backgroundColor) { return make(context, text, icon, tintColor, backgroundColor, Toast.LENGTH_SHORT); } /** * Make a themed toast with text, icon, background and the tint color. * * @param context The context to use. * @param text The text to show. Can be formatted text. * @param icon The toast icon to show. * @param tintColor The toast tint color based on the toast background. *

It will automatically check for the contrast to provide the * best visibility. * @param backgroundColor The toast background color. * @param duration The duration for the toast, either {@link Toast#LENGTH_SHORT} * or {@link Toast#LENGTH_LONG}. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast make(@NonNull Context context, @Nullable CharSequence text, @Nullable Drawable icon, @Nullable @ColorInt Integer tintColor, @Nullable @ColorInt Integer backgroundColor, int duration) { if (context instanceof Activity && ((Activity) context).isFinishing()) { context = context.getApplicationContext(); } @Nullable @ColorInt Integer toastTintColor = tintColor; if (tintColor != null && backgroundColor != null) { toastTintColor = DynamicColorUtils.getContrastColor(toastTintColor, backgroundColor); } ToastCompat toast = new ToastCompat(context, new Toast(context)); View toastLayout = LayoutInflater.from(context).inflate( R.layout.adt_layout_hint, new LinearLayout(context), false); ImageView toastIcon = toastLayout.findViewById(R.id.adt_hint_icon); TextView toastText = toastLayout.findViewById(R.id.adt_hint_text); if (!disableIcon && icon != null) { if (iconSize != ADT_DEFAULT_ICON_SIZE) { toastIcon.getLayoutParams().width = iconSize; toastIcon.getLayoutParams().height = iconSize; toastIcon.requestLayout(); } if (tintIcon && toastTintColor != null) { toastIcon.setColorFilter(toastTintColor); } else { toastIcon.clearColorFilter(); } toastIcon.setImageDrawable(icon); } else { toastIcon.setVisibility(View.GONE); } if (textTypeface != null) { toastText.setTypeface(textTypeface); } if (textSize != ADT_DEFAULT_TEXT_SIZE) { toastText.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize); } if (toastTintColor != null) { toastText.setTextColor(toastTintColor); } toastText.setText(text); if (toastBackground != null) { DynamicDrawableUtils.setBackground(toastLayout, backgroundColor != null ? DynamicDrawableUtils.colorizeDrawable(toastBackground, backgroundColor, PorterDuff.Mode.MULTIPLY) : toastBackground); } else { DynamicDrawableUtils.setBackground(toastLayout, backgroundColor != null ? DynamicDrawableUtils.colorizeDrawable(ContextCompat.getDrawable(context, R.drawable.adt_hint_background), backgroundColor, PorterDuff.Mode.MULTIPLY) : ContextCompat.getDrawable(context, R.drawable.adt_hint_background)); } toast.setDuration(duration); toast.setView(toastLayout); return toast; } /** * Configuration class to customise the {@link DynamicHint} attributes. */ public static class Config { /** * Singleton instance of {@link Config}. */ private static Config sInstance; /** * Background color for the default toast. */ private @ColorInt Integer defaultBackgroundColor = DynamicHint.defaultBackgroundColor; /** * Tint color for the default toast. */ private @ColorInt Integer defaultTintColor = DynamicHint.defaultTintColor; /** * Background color for the error toast. */ private @ColorInt Integer errorBackgroundColor = DynamicHint.errorBackgroundColor; /** * Background color for the success toast. */ private @ColorInt Integer successBackgroundColor = DynamicHint.successBackgroundColor; /** * Background color for the warning toast. */ private @ColorInt Integer warningBackgroundColor = DynamicHint.warningBackgroundColor; /** * Custom icon for the error toast. */ private Drawable errorIcon = DynamicHint.errorIcon; /** * Custom icon for the success toast. */ private Drawable successIcon = DynamicHint.successIcon; /** * Custom icon for the warning toast. */ private Drawable warningIcon = DynamicHint.warningIcon; /** * {@code true} to disable icon for all the toasts. */ private boolean disableIcon = DynamicHint.disableIcon; /** * {@code true} to tint icon for all the toasts. */ private boolean tintIcon = DynamicHint.tintIcon; /** * Icon size for the toast in pixels. */ private int iconSize = DynamicHint.iconSize; /** * Text size for the toast in SP. * * @see TypedValue#COMPLEX_UNIT_SP; */ private @ColorInt int textSize = DynamicHint.textSize; /** * Custom text typeface used by the toast. */ private Typeface textTypeface = null; /** * Custom background used by the toast. */ private Drawable toastBackground = null; /** * Making default constructor private to avoid instantiation. */ private Config() { } /** * Get instance to access public methods. Must be called before accessing methods. * * @return The singleton instance of this class. */ public static @NonNull Config getInstance() { if (sInstance == null) { sInstance = new Config(); } return sInstance; } /** * Set the default background color. * * @param defaultBackgroundColor The background color to be set. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setDefaultBackgroundColor( @Nullable @ColorInt Integer defaultBackgroundColor) { this.defaultBackgroundColor = defaultBackgroundColor; return this; } /** * Set the default tint color. * * @param defaultTintColor The tint color to be set. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setDefaultTintColor(@Nullable @ColorInt Integer defaultTintColor) { this.defaultTintColor = defaultTintColor; return this; } /** * Set the error background color. * * @param errorBackgroundColor The error background color to be set. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setErrorBackgroundColor( @Nullable @ColorInt Integer errorBackgroundColor) { this.errorBackgroundColor = errorBackgroundColor; return this; } /** * Set the success background color. * * @param successBackgroundColor The success background color * to be set. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setSuccessBackgroundColor( @Nullable @ColorInt Integer successBackgroundColor) { this.successBackgroundColor = successBackgroundColor; return this; } /** * Set the warning background color. * * @param warningBackgroundColor The warning background color to be set. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setWarningBackgroundColor( @Nullable @ColorInt Integer warningBackgroundColor) { this.warningBackgroundColor = warningBackgroundColor; return this; } /** * Set the error icon. *

Pass {@code null} to use the default icon. * * @param errorIcon The error icon to be set. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setErrorIcon(@Nullable Drawable errorIcon) { this.errorIcon = errorIcon; return this; } /** * Set the success icon. *

Pass {@code null} to use the default icon. * * @param successIcon The success icon to be set. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setSuccessIcon(@Nullable Drawable successIcon) { this.successIcon = successIcon; return this; } /** * Set the warning icon. *

Pass {@code null} to use the default icon. * * @param warningIcon The warning icon to be set. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setWarningIcon(@Nullable Drawable warningIcon) { this.warningIcon = warningIcon; return this; } /** * Set the icon visibility. * * @param disableIcon {@code true} to disable icon for all the toasts. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setDisableIcon(boolean disableIcon) { this.disableIcon = disableIcon; return this; } /** * Set whether to tint the icon. * * @param tintIcon {@code true} to tint icon for all the toasts. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setTintIcon(boolean tintIcon) { this.tintIcon = tintIcon; return this; } /** * Set the icon size. * * @param iconSize The icon size to be set in {@code pixels}. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setIconSize(int iconSize) { this.iconSize = iconSize; return this; } /** * Set the text size. * * @param textSize The text size to be set in {@code sp}. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setTextSize(int textSize) { this.textSize = textSize; return this; } /** * Set the text typeface. *

Pass {@code null} to use the default typeface. * * @param textTypeface The text typeface to be set. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setTextTypeface(@Nullable Typeface textTypeface) { this.textTypeface = textTypeface; return this; } /** * Set the toast background. *

Pass {@code null} to use the default background. * * @param toastBackground The toast background to be set. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setToastBackground(@Nullable Drawable toastBackground) { this.toastBackground = toastBackground; return this; } /** * Apply customisations. */ public void apply() { DynamicHint.defaultBackgroundColor = defaultBackgroundColor; DynamicHint.defaultTintColor = defaultTintColor; DynamicHint.errorBackgroundColor = errorBackgroundColor; DynamicHint.successBackgroundColor = successBackgroundColor; DynamicHint.warningBackgroundColor = warningBackgroundColor; DynamicHint.errorIcon = errorIcon; DynamicHint.successIcon = successIcon; DynamicHint.warningIcon = warningIcon; DynamicHint.disableIcon = disableIcon; DynamicHint.tintIcon = tintIcon; DynamicHint.iconSize = iconSize; DynamicHint.textSize = textSize; DynamicHint.textTypeface = textTypeface; DynamicHint.toastBackground = toastBackground; sInstance = null; } /** * Reset customisations. */ public void reset() { DynamicHint.defaultBackgroundColor = ADT_DEFAULT_BG_COLOR; DynamicHint.defaultTintColor = ADT_DEFAULT_TINT_COLOR; DynamicHint.errorBackgroundColor = ADT_DEFAULT_ERROR_BG_COLOR; DynamicHint.successBackgroundColor = ADT_DEFAULT_SUCCESS_BG_COLOR; DynamicHint.warningBackgroundColor = ADT_DEFAULT_WARNING_BG_COLOR; DynamicHint.errorIcon = null; DynamicHint.successIcon = null; DynamicHint.warningIcon = null; DynamicHint.disableIcon = ADT_DEFAULT_DISABLE_ICON; DynamicHint.tintIcon = ADT_DEFAULT_TINT_ICON; DynamicHint.iconSize = ADT_DEFAULT_ICON_SIZE; DynamicHint.textSize = ADT_DEFAULT_TEXT_SIZE; DynamicHint.textTypeface = null; DynamicHint.toastBackground = null; sInstance = null; } } /** * Show toast above or below according to the anchor view position. * * @param anchor The anchor view to show the toast. * @param toast The toast to be displayed. */ public static void show(@NonNull View anchor, @NonNull Toast toast) { show(anchor, toast, ADT_TOAST_OFFSET); } /** * Show toast above or below according to the anchor view position. * * @param anchor The anchor view to show the toast. * @param toast The toast to be displayed. * @param offset The toast vertical offset in dips. */ @SuppressWarnings("deprecation") public static void show(@NonNull View anchor, @NonNull Toast toast, int offset) { Rect displayFrame = new Rect(); int[] screenLocation = new int[2]; anchor.getWindowVisibleDisplayFrame(displayFrame); anchor.getLocationOnScreen(screenLocation); int anchorLeft = screenLocation[0]; int anchorTop = Math.max(0, screenLocation[1] - DynamicUnitUtils.convertDpToPixels(ADT_INSET_TOP)); int minAnchorHeight = DynamicUnitUtils.convertDpToPixels(ADT_MIN_ANCHOR_HEIGHT); int yOffset = DynamicUnitUtils.convertDpToPixels(offset); DisplayMetrics metrics = anchor.getResources().getDisplayMetrics(); int widthMeasureSpec = View.MeasureSpec.makeMeasureSpec( metrics.widthPixels, View.MeasureSpec.UNSPECIFIED); int heightMeasureSpec = View.MeasureSpec.makeMeasureSpec( metrics.heightPixels, View.MeasureSpec.UNSPECIFIED); int toastWidth = DynamicUnitUtils.convertDpToPixels(ADT_MIN_ANCHOR_HEIGHT); if (toast.getView() != null) { toast.getView().measure(widthMeasureSpec, heightMeasureSpec); toastWidth = toast.getView().getMeasuredWidth(); } if (anchorTop < displayFrame.top + yOffset) { toast.setGravity(Gravity.START | Gravity.TOP, anchorLeft + (anchor.getWidth() - toastWidth) / 2, anchorTop + Math.max(minAnchorHeight, anchor.getHeight()) + yOffset); } else { toast.setGravity(Gravity.START | Gravity.TOP, anchorLeft + (anchor.getWidth() - toastWidth) / 2, anchorTop - Math.max(minAnchorHeight, anchor.getHeight()) - yOffset); } toast.show(); } } ================================================ FILE: dynamic-toasts/src/main/java/com/pranavpandey/android/dynamic/toasts/DynamicToast.java ================================================ /* * Copyright 2017-2022 Pranav Pandey * * 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 com.pranavpandey.android.dynamic.toasts; import android.app.Activity; import android.content.Context; import android.graphics.Color; import android.graphics.PorterDuff; import android.graphics.Typeface; import android.graphics.drawable.Drawable; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.ColorInt; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.core.content.ContextCompat; import com.pranavpandey.android.dynamic.toasts.internal.ToastCompat; import com.pranavpandey.android.dynamic.util.DynamicColorUtils; import com.pranavpandey.android.dynamic.util.DynamicDrawableUtils; /** * Helper class to display themed {@link Toast} with icon and text. *

If no color is supplied, it will display default toast based on the vanilla Android. */ public class DynamicToast { /** * Default background color for the toast. */ private static final @ColorInt int ADT_DEFAULT_BG_COLOR = Color.parseColor("#454545"); /** * Default tint color for the toast. */ private static final @ColorInt int ADT_DEFAULT_TINT_COLOR = Color.parseColor("#FFFFFF"); /** * Default background color for the error toast. */ private static final @ColorInt int ADT_DEFAULT_ERROR_BG_COLOR = Color.parseColor("#F44336"); /** * Default background color for the success toast. */ private static final @ColorInt int ADT_DEFAULT_SUCCESS_BG_COLOR = Color.parseColor("#4CAF50"); /** * Default background color for the warning toast. */ private static final @ColorInt int ADT_DEFAULT_WARNING_BG_COLOR = Color.parseColor("#FFEB3B"); /** * Default value for the {@link #disableIcon}. *

{@code false} to enable the toast icon. */ private static final boolean ADT_DEFAULT_DISABLE_ICON = false; /** * Default value for the {@link #tintIcon}. *

{@code true} to tint the toast icon. */ private static final boolean ADT_DEFAULT_TINT_ICON = true; /** * Default icon size for the toast in pixels. *

{@code -1} to use in-built icon size. */ private static final @ColorInt int ADT_DEFAULT_ICON_SIZE = -1; /** * Default text size for the toast in SP. *

{@code -1} to use system text size. * * @see TypedValue#COMPLEX_UNIT_SP; */ private static final @ColorInt int ADT_DEFAULT_TEXT_SIZE = -1; /** * Background color for the default toast. */ private static @Nullable @ColorInt Integer defaultBackgroundColor = ADT_DEFAULT_BG_COLOR; /** * Tint color for the default toast. */ private static @Nullable @ColorInt Integer defaultTintColor = ADT_DEFAULT_TINT_COLOR; /** * Background color for the error toast. */ private static @Nullable @ColorInt Integer errorBackgroundColor = ADT_DEFAULT_ERROR_BG_COLOR; /** * Background color for the success toast. */ private static @Nullable @ColorInt Integer successBackgroundColor = ADT_DEFAULT_SUCCESS_BG_COLOR; /** * Background color for the warning toast. */ private static @Nullable @ColorInt Integer warningBackgroundColor = ADT_DEFAULT_WARNING_BG_COLOR; /** * Custom icon for the error toast. *

{@code null} to use the default icon. */ private static Drawable errorIcon = null; /** * Custom icon for the success toast. *

{@code null} to use the default icon. */ private static Drawable successIcon = null; /** * Custom icon for the warning toast. *

{@code null} to use the default icon. */ private static Drawable warningIcon = null; /** * {@code true} to disable icon for all the toasts. */ private static boolean disableIcon = ADT_DEFAULT_DISABLE_ICON; /** * {@code true} to tint icon for all the toasts. */ private static boolean tintIcon = ADT_DEFAULT_TINT_ICON; /** * Icon size for the toast in pixels. */ private static int iconSize = ADT_DEFAULT_ICON_SIZE; /** * Text size for the toast in SP. * * @see TypedValue#COMPLEX_UNIT_SP; */ private static int textSize = ADT_DEFAULT_TEXT_SIZE; /** * Custom typeface used by the toast. *

{@code null} to use the system typeface. */ private static Typeface textTypeface = null; /** * Custom background used by the toast. *

{@code null} to use the default background. */ private static Drawable toastBackground = null; /** * Generate tint color according to the supplied color, otherwise return the default value. * * @param color The color to be used to generate the tint color. * @param defaultColor The default value for the tint color. * * @return The generated tint color according to the supplied color, otherwise return the * default value. */ private static @Nullable @ColorInt Integer generateTintColor( @Nullable @ColorInt Integer color, @Nullable @ColorInt Integer defaultColor) { if (color != null) { return DynamicColorUtils.getTintColor(color); } return defaultColor; } /** * Make a standard toast that just contains a text view. *

The toast duration will be {@link Toast#LENGTH_SHORT}. * * @param context The context to use. * @param text The text to show. Can be formatted text. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast make(@NonNull Context context, @Nullable CharSequence text) { return make(context, text, null, defaultTintColor, defaultBackgroundColor, Toast.LENGTH_SHORT); } /** * Make a standard toast that just contains a text view. * * @param context The context to use. * @param text The text to show. Can be formatted text. * @param duration The duration for the toast, either {@link Toast#LENGTH_SHORT} * or {@link Toast#LENGTH_LONG}. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast make(@NonNull Context context, @Nullable CharSequence text, int duration) { return make(context, text, null, defaultTintColor, defaultBackgroundColor, duration); } /** * Make a error toast with icon and the text. *

The toast duration will be {@link Toast#LENGTH_SHORT}. * * @param context The context to use. * @param text The text to show. Can be formatted text. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast makeError(@NonNull Context context, @Nullable CharSequence text) { return make(context, text, errorIcon != null ? errorIcon : ContextCompat.getDrawable(context, R.drawable.adt_ic_error), generateTintColor(errorBackgroundColor, defaultTintColor), errorBackgroundColor); } /** * Make a error toast with icon and the text. * * @param context The context to use. * @param text The text to show. Can be formatted text. * @param duration The duration for the toast, either {@link Toast#LENGTH_SHORT} * or {@link Toast#LENGTH_LONG}. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast makeError(@NonNull Context context, @Nullable CharSequence text, int duration) { return make(context, text, ContextCompat.getDrawable(context, R.drawable.adt_ic_error), generateTintColor(errorBackgroundColor, defaultTintColor), errorBackgroundColor, duration); } /** * Make a success toast with icon and the text. *

The toast duration will be {@link Toast#LENGTH_SHORT}. * * @param context The context to use. * @param text The text to show. Can be formatted text. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast makeSuccess(@NonNull Context context, @Nullable CharSequence text) { return make(context, text, successIcon != null ? successIcon : ContextCompat.getDrawable(context, R.drawable.adt_ic_success), generateTintColor(successBackgroundColor, defaultTintColor), successBackgroundColor); } /** * Make a success toast with icon and the text. * * @param context The context to use. * @param text The text to show. Can be formatted text. * @param duration The duration for the toast, either {@link Toast#LENGTH_SHORT} * or {@link Toast#LENGTH_LONG}. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast makeSuccess(@NonNull Context context, @Nullable CharSequence text, int duration) { return make(context, text, ContextCompat.getDrawable(context, R.drawable.adt_ic_success), generateTintColor(successBackgroundColor, defaultTintColor), successBackgroundColor, duration); } /** * Make a warning toast with icon and the text. *

The toast duration will be {@link Toast#LENGTH_SHORT}. * * @param context The context to use. * @param text The text to show. Can be formatted text. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast makeWarning(@NonNull Context context, @Nullable CharSequence text) { return make(context, text, warningIcon != null ? warningIcon : ContextCompat.getDrawable(context, R.drawable.adt_ic_warning), generateTintColor(warningBackgroundColor, defaultTintColor), warningBackgroundColor); } /** * Make a warning toast with icon and the text. * * @param context The context to use. * @param text The text to show. Can be formatted text. * @param duration The duration for the toast, either {@link Toast#LENGTH_SHORT} * or {@link Toast#LENGTH_LONG}. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast makeWarning(@NonNull Context context, @Nullable CharSequence text, int duration) { return make(context, text, ContextCompat.getDrawable(context, R.drawable.adt_ic_warning), generateTintColor(warningBackgroundColor, defaultTintColor), warningBackgroundColor, duration); } /** * Make a error toast with icon and the text. *

The toast duration will be {@link Toast#LENGTH_SHORT}. * * @param context The context to use. * @param text The text to show. Can be formatted text. * @param icon The toast icon to show. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast make(@NonNull Context context, @Nullable CharSequence text, @Nullable Drawable icon) { return make(context, text, icon, defaultTintColor, defaultBackgroundColor, Toast.LENGTH_SHORT); } /** * Make a themed toast with icon and the text. * * @param context The context to use. * @param text The text to show. Can be formatted text. * @param icon The toast icon to show. * @param duration The duration for the toast, either {@link Toast#LENGTH_SHORT} * or {@link Toast#LENGTH_LONG}. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast make(@NonNull Context context, @Nullable CharSequence text, @Nullable Drawable icon, int duration) { return make(context, text, icon, defaultTintColor, defaultBackgroundColor, duration); } /** * Make a themed toast with icon and the text. *

The toast duration will be {@link Toast#LENGTH_SHORT}. * * @param context The context to use. * @param text The text to show. Can be formatted text. * @param tintColor The toast tint color based on the toast background. *

It will automatically check for the contrast to provide the * best visibility. * @param backgroundColor The toast background color. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast make(@NonNull Context context, @Nullable CharSequence text, @Nullable @ColorInt Integer tintColor, @Nullable @ColorInt Integer backgroundColor) { return make(context, text, null, tintColor, backgroundColor, Toast.LENGTH_SHORT); } /** * Make a themed toast with text, background and the tint color. *

The toast duration will be {@link Toast#LENGTH_SHORT}. * * @param context The context to use. * @param text The text to show. Can be formatted text. * @param tintColor The toast tint color based on the toast background. *

It will automatically check for the contrast to provide the * best visibility. * @param backgroundColor The toast background color. * @param duration The duration for the toast, either {@link Toast#LENGTH_SHORT} * or {@link Toast#LENGTH_LONG}. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast make(@NonNull Context context, @Nullable CharSequence text, @Nullable @ColorInt Integer tintColor, @Nullable @ColorInt Integer backgroundColor, int duration) { return make(context, text, null, tintColor, backgroundColor, duration); } /** * Make a themed toast with text, icon, background and the tint color. *

The toast duration will be {@link Toast#LENGTH_SHORT}. * * @param context The context to use. * @param text The text to show. Can be formatted text. * @param icon The toast icon to show. * @param tintColor The toast tint color based on the toast background. *

It will automatically check for the contrast to provide the * best visibility. * @param backgroundColor The toast background color. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast make(@NonNull Context context, @Nullable CharSequence text, @Nullable Drawable icon, @Nullable @ColorInt Integer tintColor, @Nullable @ColorInt Integer backgroundColor) { return make(context, text, icon, tintColor, backgroundColor, Toast.LENGTH_SHORT); } /** * Make a themed toast with text, icon, background and the tint color. * * @param context The context to use. * @param text The text to show. Can be formatted text. * @param icon The toast icon to show. * @param tintColor The toast tint color based on the toast background. *

It will automatically check for the contrast to provide the * best visibility. * @param backgroundColor The toast background color. * @param duration The duration for the toast, either {@link Toast#LENGTH_SHORT} * or {@link Toast#LENGTH_LONG}. * * @return The toast with the supplied parameters. *

Use {@link Toast#show()} to display the toast. */ public static @NonNull Toast make(@NonNull Context context, @Nullable CharSequence text, @Nullable Drawable icon, @Nullable @ColorInt Integer tintColor, @Nullable @ColorInt Integer backgroundColor, int duration) { if (context instanceof Activity && ((Activity) context).isFinishing()) { context = context.getApplicationContext(); } @Nullable @ColorInt Integer toastTintColor = tintColor; if (tintColor != null && backgroundColor != null) { toastTintColor = DynamicColorUtils.getContrastColor(toastTintColor, backgroundColor); } ToastCompat toast = new ToastCompat(context, new Toast(context)); View toastLayout = LayoutInflater.from(context).inflate( R.layout.adt_layout_toast, new LinearLayout(context), false); ImageView toastIcon = toastLayout.findViewById(R.id.adt_toast_icon); TextView toastText = toastLayout.findViewById(R.id.adt_toast_text); if (!disableIcon && icon != null) { if (iconSize != ADT_DEFAULT_ICON_SIZE) { toastIcon.getLayoutParams().width = iconSize; toastIcon.getLayoutParams().height = iconSize; toastIcon.requestLayout(); } if (tintIcon && toastTintColor != null) { toastIcon.setColorFilter(toastTintColor); } else { toastIcon.clearColorFilter(); } toastIcon.setImageDrawable(icon); } else { toastIcon.setVisibility(View.GONE); } if (textTypeface != null) { toastText.setTypeface(textTypeface); } if (textSize != ADT_DEFAULT_TEXT_SIZE) { toastText.setTextSize(TypedValue.COMPLEX_UNIT_SP, textSize); } if (toastTintColor != null) { toastText.setTextColor(toastTintColor); } toastText.setText(text); if (toastBackground != null) { DynamicDrawableUtils.setBackground(toastLayout, backgroundColor != null ? DynamicDrawableUtils.colorizeDrawable(toastBackground, backgroundColor, PorterDuff.Mode.MULTIPLY) : toastBackground); } else { DynamicDrawableUtils.setBackground(toastLayout, backgroundColor != null ? DynamicDrawableUtils.colorizeDrawable(ContextCompat.getDrawable(context, R.drawable.adt_toast_background), backgroundColor, PorterDuff.Mode.MULTIPLY) : ContextCompat.getDrawable(context, R.drawable.adt_toast_background)); } toast.setDuration(duration); toast.setView(toastLayout); return toast; } /** * Configuration class to customise the {@link DynamicToast} attributes. */ public static class Config { /** * Singleton instance of {@link Config}. */ private static Config sInstance; /** * Background color for the default toast. */ private @ColorInt Integer defaultBackgroundColor = DynamicToast.defaultBackgroundColor; /** * Tint color for the default toast. */ private @ColorInt Integer defaultTintColor = DynamicToast.defaultTintColor; /** * Background color for the error toast. */ private @ColorInt Integer errorBackgroundColor = DynamicToast.errorBackgroundColor; /** * Background color for the success toast. */ private @ColorInt Integer successBackgroundColor = DynamicToast.successBackgroundColor; /** * Background color for the warning toast. */ private @ColorInt Integer warningBackgroundColor = DynamicToast.warningBackgroundColor; /** * Custom icon for the error toast. */ private Drawable errorIcon = DynamicToast.errorIcon; /** * Custom icon for the success toast. */ private Drawable successIcon = DynamicToast.successIcon; /** * Custom icon for the warning toast. */ private Drawable warningIcon = DynamicToast.warningIcon; /** * {@code true} to disable icon for all the toasts. */ private boolean disableIcon = DynamicToast.disableIcon; /** * {@code true} to tint icon for all the toasts. */ private boolean tintIcon = DynamicToast.tintIcon; /** * Icon size for the toast in pixels. */ private int iconSize = DynamicToast.iconSize; /** * Text size for the toast in SP. * * @see TypedValue#COMPLEX_UNIT_SP; */ private @ColorInt int textSize = DynamicToast.textSize; /** * Custom text typeface used by the toast. */ private Typeface textTypeface = null; /** * Custom background used by the toast. */ private Drawable toastBackground = null; /** * Making default constructor private to avoid instantiation. */ private Config() { } /** * Get instance to access public methods. Must be called before accessing methods. * * @return The singleton instance of this class. */ public static @NonNull Config getInstance() { if (sInstance == null) { sInstance = new Config(); } return sInstance; } /** * Set the default background color. * * @param defaultBackgroundColor The background color to be set. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setDefaultBackgroundColor( @Nullable @ColorInt Integer defaultBackgroundColor) { this.defaultBackgroundColor = defaultBackgroundColor; return this; } /** * Set the default tint color. * * @param defaultTintColor The tint color to be set. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setDefaultTintColor(@Nullable @ColorInt Integer defaultTintColor) { this.defaultTintColor = defaultTintColor; return this; } /** * Set the error background color. * * @param errorBackgroundColor The error background color to be set. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setErrorBackgroundColor( @Nullable @ColorInt Integer errorBackgroundColor) { this.errorBackgroundColor = errorBackgroundColor; return this; } /** * Set the success background color. * * @param successBackgroundColor The success background color * to be set. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setSuccessBackgroundColor( @Nullable @ColorInt Integer successBackgroundColor) { this.successBackgroundColor = successBackgroundColor; return this; } /** * Set the warning background color. * * @param warningBackgroundColor The warning background color to be set. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setWarningBackgroundColor( @Nullable @ColorInt Integer warningBackgroundColor) { this.warningBackgroundColor = warningBackgroundColor; return this; } /** * Set the error icon. *

Pass {@code null} to use the default icon. * * @param errorIcon The error icon to be set. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setErrorIcon(@Nullable Drawable errorIcon) { this.errorIcon = errorIcon; return this; } /** * Set the success icon. *

Pass {@code null} to use the default icon. * * @param successIcon The success icon to be set. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setSuccessIcon(@Nullable Drawable successIcon) { this.successIcon = successIcon; return this; } /** * Set the warning icon. *

Pass {@code null} to use the default icon. * * @param warningIcon The warning icon to be set. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setWarningIcon(@Nullable Drawable warningIcon) { this.warningIcon = warningIcon; return this; } /** * Set the icon visibility. * * @param disableIcon {@code true} to disable icon for all the toasts. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setDisableIcon(boolean disableIcon) { this.disableIcon = disableIcon; return this; } /** * Set whether to tint the icon. * * @param tintIcon {@code true} to tint icon for all the toasts. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setTintIcon(boolean tintIcon) { this.tintIcon = tintIcon; return this; } /** * Set the icon size. * * @param iconSize The icon size to be set in {@code pixels}. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setIconSize(int iconSize) { this.iconSize = iconSize; return this; } /** * Set the text size. * * @param textSize The text size to be set in {@code sp}. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setTextSize(int textSize) { this.textSize = textSize; return this; } /** * Set the text typeface. *

Pass {@code null} to use the default typeface. * * @param textTypeface The text typeface to be set. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setTextTypeface(@Nullable Typeface textTypeface) { this.textTypeface = textTypeface; return this; } /** * Set the toast background. *

Pass {@code null} to use the default background. * * @param toastBackground The toast background to be set. * * @return The {@link Config} object to allow for chaining of calls to set methods. */ public @NonNull Config setToastBackground(@Nullable Drawable toastBackground) { this.toastBackground = toastBackground; return this; } /** * Apply customisations. */ public void apply() { DynamicToast.defaultBackgroundColor = defaultBackgroundColor; DynamicToast.defaultTintColor = defaultTintColor; DynamicToast.errorBackgroundColor = errorBackgroundColor; DynamicToast.successBackgroundColor = successBackgroundColor; DynamicToast.warningBackgroundColor = warningBackgroundColor; DynamicToast.errorIcon = errorIcon; DynamicToast.successIcon = successIcon; DynamicToast.warningIcon = warningIcon; DynamicToast.disableIcon = disableIcon; DynamicToast.tintIcon = tintIcon; DynamicToast.iconSize = iconSize; DynamicToast.textSize = textSize; DynamicToast.textTypeface = textTypeface; DynamicToast.toastBackground = toastBackground; sInstance = null; } /** * Reset customisations. */ public void reset() { DynamicToast.defaultBackgroundColor = ADT_DEFAULT_BG_COLOR; DynamicToast.defaultTintColor = ADT_DEFAULT_TINT_COLOR; DynamicToast.errorBackgroundColor = ADT_DEFAULT_ERROR_BG_COLOR; DynamicToast.successBackgroundColor = ADT_DEFAULT_SUCCESS_BG_COLOR; DynamicToast.warningBackgroundColor = ADT_DEFAULT_WARNING_BG_COLOR; DynamicToast.errorIcon = null; DynamicToast.successIcon = null; DynamicToast.warningIcon = null; DynamicToast.disableIcon = ADT_DEFAULT_DISABLE_ICON; DynamicToast.tintIcon = ADT_DEFAULT_TINT_ICON; DynamicToast.iconSize = ADT_DEFAULT_ICON_SIZE; DynamicToast.textSize = ADT_DEFAULT_TEXT_SIZE; DynamicToast.textTypeface = null; DynamicToast.toastBackground = null; sInstance = null; } } } ================================================ FILE: dynamic-toasts/src/main/java/com/pranavpandey/android/dynamic/toasts/internal/ToastCompat.java ================================================ /* * Copyright 2017-2022 Pranav Pandey * * 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 com.pranavpandey.android.dynamic.toasts.internal; import android.annotation.SuppressLint; import android.content.Context; import android.content.res.Resources; import android.view.View; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.StringRes; import com.pranavpandey.android.dynamic.util.DynamicSdkUtils; import java.lang.reflect.Field; /** * A Toast to fix the bad token exception on API 25. */ @SuppressWarnings("deprecation") public final class ToastCompat extends Toast { /** * Base toast used by this toast compat. */ private final @NonNull Toast mToast; public ToastCompat(Context context, @NonNull Toast base) { super(context); this.mToast = base; } /** * Make a standard toast that just contains a text view. * * @param context The context to use. * @param text The text to show. Can be formatted text. * @param duration The duration for the toast, either {@link Toast#LENGTH_SHORT} * or {@link Toast#LENGTH_LONG}. * * @return The standard toast that just contains a text view. */ @SuppressLint("ShowToast") public static ToastCompat makeText(@NonNull Context context, @Nullable CharSequence text, int duration) { Toast toast = Toast.makeText(context, text, duration); setToastContext(toast.getView(), new ToastContext(context, toast)); return new ToastCompat(context, toast); } /** * Make a standard toast that just contains a text view. * * @param context The context to use. * @param resId The resource id of the string resource to use. Can be formatted text. * @param duration The duration for the toast, either {@link Toast#LENGTH_SHORT} * or {@link Toast#LENGTH_LONG}. * * @return The standard toast that just contains a text view. */ public static Toast makeText(@NonNull Context context, @StringRes int resId, int duration) throws Resources.NotFoundException { return makeText(context, context.getResources().getText(resId), duration); } /** * Sets the toast context to fix bad token exception. * * @param view The view used by the toast * @param context The context used by the toast. */ @SuppressLint("DiscouragedPrivateApi") private static void setToastContext(@Nullable View view, @NonNull Context context) { if (view != null && DynamicSdkUtils.is25()) { try { Field field = View.class.getDeclaredField("mContext"); field.setAccessible(true); field.set(view, context); } catch (Throwable throwable) { throwable.printStackTrace(); } } } @Override public void show() { mToast.show(); } @Override public void setDuration(int duration) { mToast.setDuration(duration); } @Override public void setGravity(int gravity, int xOffset, int yOffset) { mToast.setGravity(gravity, xOffset, yOffset); } @Override public void setMargin(float horizontalMargin, float verticalMargin) { mToast.setMargin(horizontalMargin, verticalMargin); } @Override public void setText(int resId) { mToast.setText(resId); } @Override public void setText(CharSequence s) { mToast.setText(s); } @Override public void setView(View view) { mToast.setView(view); setToastContext(view, new ToastContext(view.getContext(), this)); } @Override public float getHorizontalMargin() { return mToast.getHorizontalMargin(); } @Override public float getVerticalMargin() { return mToast.getVerticalMargin(); } @Override public int getDuration() { return mToast.getDuration(); } @Override public int getGravity() { return mToast.getGravity(); } @Override public int getXOffset() { return mToast.getXOffset(); } @Override public int getYOffset() { return mToast.getYOffset(); } @Override public @Nullable View getView() { return mToast.getView(); } public @NonNull Toast getToast() { return mToast; } } ================================================ FILE: dynamic-toasts/src/main/java/com/pranavpandey/android/dynamic/toasts/internal/ToastContext.java ================================================ /* * Copyright 2017-2022 Pranav Pandey * * 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 com.pranavpandey.android.dynamic.toasts.internal; import android.content.Context; import android.content.ContextWrapper; import android.view.Display; import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.annotation.Nullable; /** * A ContextWrapper to fix bad token exception. */ public final class ToastContext extends ContextWrapper { /** * Boast used by this context wrapper. */ private @NonNull Toast toast; /** * Constructor to initialize an object of this class. * * @param base The base context for this wrapper. * @param toast The toast for this wrapper. */ public ToastContext(@NonNull Context base, @NonNull Toast toast) { super(base); this.toast = toast; } @Override public Context getApplicationContext() { return new ApplicationContextWrapper(getBaseContext().getApplicationContext()); } /** * A ContextWrapper to initialize window manager service. */ static final class ApplicationContextWrapper extends ContextWrapper { /** * Constructor to initialize an object of this class. * * @param base The base context for this wrapper. */ private ApplicationContextWrapper(@NonNull Context base) { super(base); } @Override public Object getSystemService(@NonNull String name) { @Nullable Object service = null; if (Context.WINDOW_SERVICE.equals(name)) { service = getBaseContext().getSystemService(name); } if (service != null) { return new WindowManagerWrapper((WindowManager) service); } return super.getSystemService(name); } } /** * A WindowManager to fix the bad token exception. */ @SuppressWarnings("deprecation") static final class WindowManagerWrapper implements WindowManager { /** * The base window manager used by this wrapper. */ private final @NonNull WindowManager base; /** * Constructor to initialize an object of this class. * * @param base The base window manager for this wrapper. */ private WindowManagerWrapper(@NonNull WindowManager base) { this.base = base; } @Override public Display getDefaultDisplay() { return base.getDefaultDisplay(); } @Override public void removeViewImmediate(View view) { base.removeViewImmediate(view); } @Override public void addView(View view, ViewGroup.LayoutParams params) { try { base.addView(view, params); } catch (BadTokenException e) { e.printStackTrace(); } catch (Throwable throwable) { throwable.printStackTrace(); } } @Override public void updateViewLayout(View view, ViewGroup.LayoutParams params) { base.updateViewLayout(view, params); } @Override public void removeView(View view) { base.removeView(view); } } } ================================================ FILE: dynamic-toasts/src/main/res/drawable/adt_hint_background.xml ================================================ ================================================ FILE: dynamic-toasts/src/main/res/drawable/adt_toast_background.xml ================================================ ================================================ FILE: dynamic-toasts/src/main/res/layout/adt_layout_hint.xml ================================================ ================================================ FILE: dynamic-toasts/src/main/res/layout/adt_layout_toast.xml ================================================ ================================================ FILE: dynamic-toasts/src/main/res/values/dimens.xml ================================================ 15sp 24dp 12dp 16dp 8dp 13sp 20dp 8dp 12dp 4dp ================================================ FILE: gradle/wrapper/gradle-wrapper.properties ================================================ #Thu Jan 28 10:36:42 IST 2021 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists distributionUrl=https\://services.gradle.org/distributions/gradle-8.9-bin.zip ================================================ FILE: gradle.properties ================================================ # Project-wide Gradle settings. # IDE (e.g. Android Studio) users: # Gradle settings configured through the IDE *will override* # any settings specified in this file. # For more details on how to configure your build environment visit # http://www.gradle.org/docs/current/userguide/build_environment.html # Specifies the JVM arguments used for the daemon process. # The setting is particularly useful for tweaking memory settings. org.gradle.jvmargs=-Xmx1536m # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects # org.gradle.parallel=true # AndroidX package structure to make it clearer which packages are bundled with the # Android operating system, and which are packaged with your app's APK # https://developer.android.com/topic/libraries/support-library/androidx-rn android.useAndroidX=true # Automatically convert third-party libraries to use AndroidX android.enableJetifier=true android.nonTransitiveRClass=false ================================================ FILE: gradlew ================================================ #!/usr/bin/env bash ############################################################################## ## ## Gradle start up script for UN*X ## ############################################################################## # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. DEFAULT_JVM_OPTS="" APP_NAME="Gradle" APP_BASE_NAME=`basename "$0"` # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD="maximum" warn ( ) { echo "$*" } die ( ) { echo echo "$*" echo exit 1 } # OS specific support (must be 'true' or 'false'). cygwin=false msys=false darwin=false case "`uname`" in CYGWIN* ) cygwin=true ;; Darwin* ) darwin=true ;; MINGW* ) msys=true ;; esac # Attempt to set APP_HOME # Resolve links: $0 may be a link PRG="$0" # Need this for relative symlinks. while [ -h "$PRG" ] ; do ls=`ls -ld "$PRG"` link=`expr "$ls" : '.*-> \(.*\)$'` if expr "$link" : '/.*' > /dev/null; then PRG="$link" else PRG=`dirname "$PRG"`"/$link" fi done SAVED="`pwd`" cd "`dirname \"$PRG\"`/" >/dev/null APP_HOME="`pwd -P`" cd "$SAVED" >/dev/null CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar # Determine the Java command to use to start the JVM. if [ -n "$JAVA_HOME" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then # IBM's JDK on AIX uses strange locations for the executables JAVACMD="$JAVA_HOME/jre/sh/java" else JAVACMD="$JAVA_HOME/bin/java" fi if [ ! -x "$JAVACMD" ] ; then die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi else JAVACMD="java" which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." fi # Increase the maximum file descriptors if we can. if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then MAX_FD_LIMIT=`ulimit -H -n` if [ $? -eq 0 ] ; then if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then MAX_FD="$MAX_FD_LIMIT" fi ulimit -n $MAX_FD if [ $? -ne 0 ] ; then warn "Could not set maximum file descriptor limit: $MAX_FD" fi else warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" fi fi # For Darwin, add options to specify how the application appears in the dock if $darwin; then GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" fi # For Cygwin, switch paths to Windows format before running java if $cygwin ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` SEP="" for dir in $ROOTDIRSRAW ; do ROOTDIRS="$ROOTDIRS$SEP$dir" SEP="|" done OURCYGPATTERN="(^($ROOTDIRS))" # Add a user-defined pattern to the cygpath arguments if [ "$GRADLE_CYGPATTERN" != "" ] ; then OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" fi # Now convert the arguments - kludge to limit ourselves to /bin/sh i=0 for arg in "$@" ; do CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` else eval `echo args$i`="\"$arg\"" fi i=$((i+1)) done case $i in (0) set -- ;; (1) set -- "$args0" ;; (2) set -- "$args0" "$args1" ;; (3) set -- "$args0" "$args1" "$args2" ;; (4) set -- "$args0" "$args1" "$args2" "$args3" ;; (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; esac fi # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules function splitJvmOpts() { JVM_OPTS=("$@") } eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" ================================================ FILE: gradlew.bat ================================================ @if "%DEBUG%" == "" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @rem @rem ########################################################################## @rem Set local scope for the variables with windows NT shell if "%OS%"=="Windows_NT" setlocal @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. set DEFAULT_JVM_OPTS= set DIRNAME=%~dp0 if "%DIRNAME%" == "" set DIRNAME=. set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @rem Find java.exe if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 if "%ERRORLEVEL%" == "0" goto init echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. echo. echo Please set the JAVA_HOME variable in your environment to match the echo location of your Java installation. goto fail :findJavaFromJavaHome set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto init echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% echo. echo Please set the JAVA_HOME variable in your environment to match the echo location of your Java installation. goto fail :init @rem Get command-line arguments, handling Windowz variants if not "%OS%" == "Windows_NT" goto win9xME_args if "%@eval[2+2]" == "4" goto 4NT_args :win9xME_args @rem Slurp the command line arguments. set CMD_LINE_ARGS= set _SKIP=2 :win9xME_args_slurp if "x%~1" == "x" goto execute set CMD_LINE_ARGS=%* goto execute :4NT_args @rem Get arguments from the 4NT Shell from JP Software set CMD_LINE_ARGS=%$ :execute @rem Setup the command line set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @rem Execute Gradle "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% :end @rem End local scope for the variables with windows NT shell if "%ERRORLEVEL%"=="0" goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 exit /b 1 :mainEnd if "%OS%"=="Windows_NT" endlocal :omega ================================================ FILE: sample/build.gradle ================================================ /* * Copyright 2017-2023 Pranav Pandey * * 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. */ apply plugin: 'com.android.application' apply plugin: 'kotlin-android' android { compileSdkVersion versions.compileSdk buildToolsVersion versions.buildTools namespace 'com.pranavpandey.android.dynamic.toasts.sample' defaultConfig { applicationId "com.pranavpandey.android.dynamic.toasts.sample" minSdkVersion versions.minSdk targetSdkVersion versions.targetSdk versionCode sampleVersionCode versionName mavenVersion vectorDrawables.useSupportLibrary = true } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } lintOptions { abortOnError false } compileOptions { sourceCompatibility JavaVersion.VERSION_17 targetCompatibility JavaVersion.VERSION_17 } } dependencies { implementation(platform("org.jetbrains.kotlin:kotlin-bom:${versions.kotlin}")) implementation project(':dynamic-toasts') implementation "com.pranavpandey.android:dynamic-dialogs:${versions.dialogs}" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:${versions.kotlin}" implementation "androidx.constraintlayout:constraintlayout:${versions.constraintlayout}" implementation "com.google.android.flexbox:flexbox:${versions.flexbox}" } ================================================ FILE: sample/proguard-rules.pro ================================================ # Add project specific ProGuard rules here. # By default, the flags in this file are appended to flags specified # in ANDROID_HOME/tools/proguard/proguard-android.txt # You can edit the include path and order by changing the proguardFiles # directive in build.gradle. # # For more details, see # http://developer.android.com/guide/developing/tools/proguard.html # Add any project specific keep options here: # If your project uses WebView with JS, uncomment the following # and specify the fully qualified class name to the JavaScript interface # class: #-keepclassmembers class fqcn.of.javascript.interface.for.webview { # public *; #} # Uncomment this to preserve the line number information for # debugging stack traces. #-keepattributes SourceFile,LineNumberTable # If you keep the line number information, uncomment this to # hide the original source file name. #-renamesourcefileattribute SourceFile ================================================ FILE: sample/src/main/AndroidManifest.xml ================================================ ================================================ FILE: sample/src/main/java/com/pranavpandey/android/dynamic/toasts/sample/DynamicToastsActivity.kt ================================================ /* * Copyright 2017-2022 Pranav Pandey * * 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 com.pranavpandey.android.dynamic.toasts.sample import android.content.res.Configuration import android.graphics.Color import android.graphics.Typeface import android.os.Bundle import android.view.Menu import android.view.MenuItem import android.view.View import android.widget.TextView import android.widget.Toast import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.content.res.AppCompatResources import androidx.appcompat.widget.Toolbar import androidx.core.content.ContextCompat import com.google.android.material.floatingactionbutton.FloatingActionButton import com.pranavpandey.android.dynamic.toasts.DynamicHint import com.pranavpandey.android.dynamic.toasts.DynamicToast import com.pranavpandey.android.dynamic.toasts.sample.dialog.AboutDialogFragment import com.pranavpandey.android.dynamic.util.DynamicColorUtils import com.pranavpandey.android.dynamic.util.DynamicLinkUtils import com.pranavpandey.android.dynamic.util.DynamicPackageUtils import com.pranavpandey.android.dynamic.util.DynamicUnitUtils /** * Main activity to show the implementation of [DynamicToast]. */ class DynamicToastsActivity : AppCompatActivity(), View.OnClickListener { companion object { /** * Open source repository url. */ const val URL_GITHUB = "https://github.com/pranavpandey/dynamic-toasts" } override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_dynamic_toasts) val toolbar = findViewById(R.id.toolbar) toolbar.setSubtitle(R.string.app_name_sample) setSupportActionBar(toolbar) val fab = findViewById(R.id.fab) fab.setColorFilter(DynamicColorUtils.getTintColor( ContextCompat.getColor(this, R.color.color_accent))) (findViewById(R.id.gradle) as TextView).text = String.format( getString(R.string.format_version), DynamicPackageUtils.getVersionName(this)) fab.setOnClickListener(this) findViewById(R.id.toast_default).setOnClickListener(this) findViewById(R.id.toast_default_icon).setOnClickListener(this) findViewById(R.id.toast_success).setOnClickListener(this) findViewById(R.id.toast_error).setOnClickListener(this) findViewById(R.id.toast_success).setOnClickListener(this) findViewById(R.id.toast_warning).setOnClickListener(this) findViewById(R.id.toast_custom_icon).setOnClickListener(this) findViewById(R.id.toast_custom).setOnClickListener(this) findViewById(R.id.toast_error_color).setOnClickListener(this) findViewById(R.id.toast_success_color).setOnClickListener(this) findViewById(R.id.toast_warning_color).setOnClickListener(this) findViewById(R.id.toast_default_color).setOnClickListener(this) findViewById(R.id.toast_error_icon).setOnClickListener(this) findViewById(R.id.toast_success_icon).setOnClickListener(this) findViewById(R.id.toast_warning_icon).setOnClickListener(this) findViewById(R.id.toast_error_icon_disable).setOnClickListener(this) findViewById(R.id.toast_success_icon_disable).setOnClickListener(this) findViewById(R.id.toast_warning_icon_disable).setOnClickListener(this) findViewById(R.id.toast_error_icon_disable_tint).setOnClickListener(this) findViewById(R.id.toast_success_icon_disable_tint).setOnClickListener(this) findViewById(R.id.toast_warning_icon_disable_tint).setOnClickListener(this) findViewById(R.id.toast_config_text).setOnClickListener(this) findViewById(R.id.toast_config_background).setOnClickListener(this) findViewById(R.id.toast_config_icon_size).setOnClickListener(this) findViewById(R.id.hint_default).setOnClickListener(this) findViewById(R.id.hint_custom).setOnClickListener(this) } /** * Fix for AppCompat 1.1.0. * * https://issuetracker.google.com/issues/140602653 */ override fun applyOverrideConfiguration(overrideConfiguration: Configuration?) { if (overrideConfiguration != null) { val uiMode = overrideConfiguration.uiMode overrideConfiguration.setTo(baseContext.resources.configuration) overrideConfiguration.uiMode = uiMode } super.applyOverrideConfiguration(resources.configuration) } override fun onCreateOptionsMenu(menu: Menu): Boolean { menuInflater.inflate(R.menu.main, menu) return super.onCreateOptionsMenu(menu) } override fun onOptionsItemSelected(item: MenuItem): Boolean { if (item.itemId == R.id.menu_about) { AboutDialogFragment.newInstance().showDialog(this) return true } return super.onOptionsItemSelected(item) } override fun onClick(v: View) { when (v.id) { R.id.fab -> DynamicLinkUtils.viewUrl(this@DynamicToastsActivity, URL_GITHUB) // Default toast without icon. R.id.toast_default -> DynamicToast.make( this, getString(R.string.without_icon_desc)).show() // Default toast with icon. R.id.toast_default_icon -> DynamicToast.make( this, getString(R.string.with_icon_desc), AppCompatResources.getDrawable( this, R.drawable.ic_toast_icon)).show() // Error toast. R.id.toast_error -> DynamicToast.makeError( this, getString(R.string.error_desc)).show() // Success toast. R.id.toast_success -> DynamicToast.makeSuccess( this, getString(R.string.success_desc)).show() // Warning toast. R.id.toast_warning -> DynamicToast.makeWarning( this, getString(R.string.warning_desc)).show() // Custom toast without icon. R.id.toast_custom -> DynamicToast.make( this, getString(R.string.custom_desc), Color.parseColor("#FFFFFF"), Color.parseColor("#000000"), Toast.LENGTH_LONG).show() // Custom toast with icon. R.id.toast_custom_icon -> DynamicToast.make( this, getString(R.string.custom_desc), AppCompatResources.getDrawable(this, R.drawable.ic_social_github), Color.parseColor("#FFFFFF"), Color.parseColor("#000000"), Toast.LENGTH_LONG).show() // Error toast with custom color. R.id.toast_error_color -> { // Customise toast. DynamicToast.Config.getInstance() .setErrorBackgroundColor(Color.parseColor("#673AB7")) .apply() DynamicToast.makeError(this, getString(R.string.error_color_desc)).show() // Reset customisations. DynamicToast.Config.getInstance().reset() } // Success toast with custom color. R.id.toast_success_color -> { // Customise toast. DynamicToast.Config.getInstance() .setSuccessBackgroundColor(Color.parseColor("#2196F3")) .apply() DynamicToast.makeSuccess( this, getString(R.string.success_color_desc)).show() // Reset customisations. DynamicToast.Config.getInstance().reset() } // Warning toast with custom color. R.id.toast_warning_color -> { // Customise toast. DynamicToast.Config.getInstance() .setWarningBackgroundColor(Color.parseColor("#8BC34A")) .apply() DynamicToast.makeWarning( this, getString(R.string.warning_color_desc)).show() // Reset customisations. DynamicToast.Config.getInstance().reset() } // Default toast with custom color. R.id.toast_default_color -> { // Customise toast. DynamicToast.Config.getInstance() .setDefaultBackgroundColor(Color.parseColor("#607d8b")) .setDefaultTintColor(DynamicColorUtils.getTintColor( Color.parseColor("#607d8b"))) .apply() DynamicToast.make( this, getString(R.string.default_color_desc)).show() // Reset customisations. DynamicToast.Config.getInstance().reset() } // Error toast with custom icon. R.id.toast_error_icon -> { // Customise toast. DynamicToast.Config.getInstance() .setErrorIcon(AppCompatResources.getDrawable( this, R.drawable.ic_toast_icon)) .apply() DynamicToast.makeError(this, getString(R.string.error_icon_desc)).show() // Reset customisations. DynamicToast.Config.getInstance().reset() } // Success toast with custom icon. R.id.toast_success_icon -> { // Customise toast. DynamicToast.Config.getInstance() .setSuccessIcon(AppCompatResources.getDrawable( this, R.drawable.ic_toast_icon)) .apply() DynamicToast.makeSuccess(this, getString(R.string.success_icon_desc)).show() // Reset customisations. DynamicToast.Config.getInstance().reset() } // Warning toast with custom icon. R.id.toast_warning_icon -> { // Customise toast. DynamicToast.Config.getInstance() .setWarningIcon(AppCompatResources.getDrawable( this, R.drawable.ic_toast_icon)) .apply() DynamicToast.makeWarning(this, getString(R.string.warning_icon_desc)).show() // Reset customisations. DynamicToast.Config.getInstance().reset() } // Error toast without icon. R.id.toast_error_icon_disable -> { // Customise toast. DynamicToast.Config.getInstance() .setDisableIcon(true) .apply() DynamicToast.makeError(this, getString(R.string.error_icon_disable_desc)).show() // Reset customisations. DynamicToast.Config.getInstance().reset() } // Success toast without icon. R.id.toast_success_icon_disable -> { // Customise toast. DynamicToast.Config.getInstance() .setDisableIcon(true) .apply() DynamicToast.makeSuccess(this, getString(R.string.success_icon_disable_desc)).show() // Reset customisations. DynamicToast.Config.getInstance().reset() } // Warning toast without icon. R.id.toast_warning_icon_disable -> { // Customise toast. DynamicToast.Config.getInstance() .setDisableIcon(true) .apply() DynamicToast.makeWarning(this, getString( R.string.warning_icon_disable_desc)).show() // Reset customisations. DynamicToast.Config.getInstance().reset() } // Error toast without icon tint. R.id.toast_error_icon_disable_tint -> { // Customise toast. DynamicToast.Config.getInstance() .setErrorIcon(AppCompatResources.getDrawable( this, R.mipmap.ic_launcher)) .setTintIcon(false) .apply() DynamicToast.makeError(this, getString(R.string.error_icon_disable_tint_desc)).show() // Reset customisations. DynamicToast.Config.getInstance().reset() } // Success toast without icon tint. R.id.toast_success_icon_disable_tint -> { // Customise toast. DynamicToast.Config.getInstance() .setSuccessIcon(AppCompatResources.getDrawable( this, R.mipmap.ic_launcher)) .setTintIcon(false) .apply() DynamicToast.makeSuccess(this, getString(R.string.success_icon_disable_tint_desc)).show() // Reset customisations. DynamicToast.Config.getInstance().reset() } // Warning toast without icon tint. R.id.toast_warning_icon_disable_tint -> { // Customise toast. DynamicToast.Config.getInstance() .setWarningIcon(AppCompatResources.getDrawable( this, R.mipmap.ic_launcher)) .setTintIcon(false) .apply() DynamicToast.makeWarning(this, getString( R.string.warning_icon_disable_tint_desc)).show() // Reset customisations. DynamicToast.Config.getInstance().reset() } // Toast with custom text size and typeface. R.id.toast_config_text -> { // Customise toast. DynamicToast.Config.getInstance() .setTextSize(18) .setErrorIcon(AppCompatResources.getDrawable( this, R.drawable.ic_toast_icon)) .setTextTypeface(Typeface.create( Typeface.SERIF, Typeface.BOLD_ITALIC)) .setErrorBackgroundColor(Color.parseColor("#2196F3")) .apply() DynamicToast.makeError(this, getString(R.string.text_desc)).show() // Reset customisations. DynamicToast.Config.getInstance().reset() } // Toast with custom background. R.id.toast_config_background -> { // Customise toast. DynamicToast.Config.getInstance() .setToastBackground(AppCompatResources.getDrawable( this, R.drawable.bg_custom_toast)) .apply() DynamicToast.makeSuccess(this, getString(R.string.background_desc)).show() // Reset customisations. DynamicToast.Config.getInstance().reset() } // Toast with custom icon size. R.id.toast_config_icon_size -> { // Customise toast. DynamicToast.Config.getInstance() .setIconSize(DynamicUnitUtils.convertDpToPixels(48f)) .apply() DynamicToast.makeWarning(this, getString(R.string.icon_size_desc)).show() // Reset customisations. DynamicToast.Config.getInstance().reset() } // Default hint without icon. R.id.hint_default -> DynamicHint.show(v, DynamicHint.make(this, getString(R.string.default_hint))) // Custom hint with icon. R.id.hint_custom -> { // Customise hint. DynamicHint.Config.getInstance() .setDefaultBackgroundColor(Color.parseColor("#607d8b")) .setDefaultTintColor(DynamicColorUtils.getTintColor( Color.parseColor("#607d8b"))) .apply() DynamicHint.show(v, DynamicHint.make(this, getString(R.string.custom_hint), AppCompatResources.getDrawable(this, R.drawable.adt_ic_warning))) // Reset customisations. DynamicHint.Config.getInstance().reset() } } } } ================================================ FILE: sample/src/main/java/com/pranavpandey/android/dynamic/toasts/sample/dialog/AboutDialogFragment.kt ================================================ /* * Copyright 2017-2022 Pranav Pandey * * 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 com.pranavpandey.android.dynamic.toasts.sample.dialog import android.os.Build import android.os.Bundle import android.text.Html import android.text.Spanned import android.text.method.LinkMovementMethod import android.view.LayoutInflater import android.view.View import android.widget.LinearLayout import android.widget.TextView import androidx.core.content.ContextCompat import com.pranavpandey.android.dynamic.dialogs.DynamicDialog import com.pranavpandey.android.dynamic.dialogs.fragment.DynamicDialogFragment import com.pranavpandey.android.dynamic.toasts.sample.R import com.pranavpandey.android.dynamic.util.DynamicLinkUtils /** * About dialog to show library info. */ class AboutDialogFragment : DynamicDialogFragment() { companion object { /** * Url for other apps on Google Play. */ const val URL_PLAY_STORE = "https://play.google.com/store/apps/dev?id=6608630615059087491" /** * Initialize the new instance of this fragment. * * @return An instance of [AboutDialogFragment]. */ fun newInstance(): AboutDialogFragment { return AboutDialogFragment() } /** * Method to handle [Html.fromHtml] deprecation. */ @Suppress("DEPRECATION") private fun fromHtml(html: String): Spanned { return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY) } else { Html.fromHtml(html) } } } /** * Customise [DynamicDialog.Builder] by overriding this method. */ override fun onCustomiseBuilder( alertDialogBuilder: DynamicDialog.Builder, savedInstanceState: Bundle? ): DynamicDialog.Builder { // Customise dialog builder to add neutral, positive and negative buttons. // Also, set a view root to add top and bottom scroll indicators. return alertDialogBuilder.setTitle(R.string.about) .setPositiveButton(R.string.more_apps) { _, _ -> DynamicLinkUtils.viewUrl(requireContext(), URL_PLAY_STORE) } .setNegativeButton(android.R.string.cancel, null) // Set custom view for the dialog. .setView( LayoutInflater.from(context).inflate( R.layout.dialog_about, LinearLayout(context), false ) ) // Set view root to automatically add scroll dividers. .setViewRoot(R.id.dialog_about_root) } /** * Customise [DynamicDialog] by overriding this method. */ override fun onCustomiseDialog( alertDialog: DynamicDialog, view: View?, savedInstanceState: Bundle? ) { super.onCustomiseDialog(alertDialog, view, savedInstanceState) // Customise the custom view. val message = view?.findViewById(R.id.dialog_about_text) message?.text = fromHtml(getString(R.string.about_content)) message?.setLineSpacing(0f, 1.2f) message?.movementMethod = LinkMovementMethod.getInstance() message?.setLinkTextColor(ContextCompat.getColor(requireContext(), R.color.color_primary)) } } ================================================ FILE: sample/src/main/res/drawable/app_bar_shadow.xml ================================================ ================================================ FILE: sample/src/main/res/drawable/bg_custom_toast.xml ================================================ ================================================ FILE: sample/src/main/res/drawable/ic_info.xml ================================================ ================================================ FILE: sample/src/main/res/drawable/ic_launcher_foreground.xml ================================================ ================================================ FILE: sample/src/main/res/drawable/ic_social_github.xml ================================================ ================================================ FILE: sample/src/main/res/drawable/ic_toast_icon.xml ================================================ ================================================ FILE: sample/src/main/res/layout/activity_dynamic_toasts.xml ================================================ ================================================ FILE: sample/src/main/res/layout/content_dynamic_toasts.xml ================================================ ================================================ FILE: sample/src/main/res/layout/dialog_about.xml ================================================ ================================================ FILE: sample/src/main/res/menu/main.xml ================================================

================================================ FILE: sample/src/main/res/mipmap-anydpi-v26/ic_launcher.xml ================================================ ================================================ FILE: sample/src/main/res/values/colors.xml ================================================ #F44336 #D32F2F #673AB7 ================================================ FILE: sample/src/main/res/values/dimens.xml ================================================ 16dp 64dp 16dp 24dp ================================================ FILE: sample/src/main/res/values/strings.xml ================================================ Dynamic Toasts Sample Gradle dependency com.pranavpandey.android:dynamic-toasts:%1$s Sources About dynamic-toasts
A simple library to display themed toasts with icon and text on Android.

© Pranav Pandey

Website   GitHub   LinkedIn

Please download my other apps via Google Play to support the development. ]]>
Donate Google Play Default toasts Without icon Default toast without icon With icon Default toast with icon In-built toasts Default Custom Default toast with custom color Error An error has occurred Error toast with custom color Error toast with custom icon Error toast without icon Error toast without icon tint Success Task has been completed successfully Success toast with custom color Success toast with custom icon Success toast without icon Success toast without icon tint Warning This is a warning! Warning toast with custom color Warning toast with custom icon Warning toast without icon Warning toast without icon tint Custom toasts Sources are available on GitHub Custom colors Custom icons Disable icon Disable icon tint Other customisations Cheat sheets Default hint Custom hint text Toast with custom text size and typeface background Toast with custom background Icon size Toast with custom icon size
================================================ FILE: sample/src/main/res/values/styles.xml ================================================