{"id":13640768,"url":"https://github.com/tingyik90/snackprogressbar","last_synced_at":"2025-04-20T07:30:54.383Z","repository":{"id":217102143,"uuid":"92313864","full_name":"tingyik90/snackprogressbar","owner":"tingyik90","description":"Enhanced Snackbar with ProgressBar for Android.","archived":false,"fork":false,"pushed_at":"2020-06-12T19:33:18.000Z","size":488,"stargazers_count":403,"open_issues_count":0,"forks_count":34,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-08-03T01:17:40.681Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tingyik90.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2017-05-24T16:32:44.000Z","updated_at":"2024-03-31T03:25:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"f1916bd2-9dc5-428d-8dd2-fc06b2103c51","html_url":"https://github.com/tingyik90/snackprogressbar","commit_stats":null,"previous_names":["tingyik90/snackprogressbar"],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tingyik90%2Fsnackprogressbar","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tingyik90%2Fsnackprogressbar/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tingyik90%2Fsnackprogressbar/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tingyik90%2Fsnackprogressbar/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tingyik90","download_url":"https://codeload.github.com/tingyik90/snackprogressbar/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223821909,"owners_count":17208758,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-02T01:01:14.243Z","updated_at":"2024-11-09T11:30:22.533Z","avatar_url":"https://github.com/tingyik90.png","language":"Kotlin","funding_links":[],"categories":["进度条"],"sub_categories":[],"readme":"[![](https://jitpack.io/v/tingyik90/snackprogressbar.svg)](https://jitpack.io/#tingyik90/snackprogressbar)\n\n# SnackProgressBar\nEnhanced Snackbar with ProgressBar for Android.\n\n## Important\nPlease do not use **v6.0** and **v6.1** due to issue [#20](https://github.com/tingyik90/snackprogressbar/issues/20) and [#23](https://github.com/tingyik90/snackprogressbar/issues/23).\n\n## Versions\n- **v6.4.0** added 'Rounded Corner Background' as per latest Material Design! To use it, call `SnackProgressBarManager.useRoundedCornerBackground(true)`. It is `false` by default.\n- **v6.1.1+** does not break migration from **v5.0**. Added the following features:\n  - SnackProgressBarLayout is now public, so you can directly edit the layout in `OnDisplayListener.onLayoutInflated`.\n  - WeakReference is now used for views to prevent memory leak.\n  - LifeCycle Architecture is used to call `SnackProgressBarManager.disable()` automatically in `OnDestroy` to prevent memory leak.\n- **v5.0** is a migration to androidx from **v4.1**. There is no change in all methods. Only use this if you have migrated.\n- **v4.1** is a huge leap from **v3.4** and offers much better flexibility. Snackbar types changed to `TYPE_NORMAL`, `TYPE_HORIZONTAL`, `TYPE_CIRCULAR`.\n- **v3.4** is using Snackbar types of `TYPE_ACTION`, `TYPE_MESSAGE`, `TYPE_DETERMINATE`, `TYPE_INDETERMINATE`.\n\n## Features\n1. Two types of ProgressBar (TYPE_HORIZONTAL and TYPE_CIRULAR) are available (see image below). It can also be used as a normal SnackBar.\n2. Supports multi-lines of message.\n3. Supports long action text by moving it to next line as per Material Design.\n4. Supports swipe to dimiss behaviour even without providing CoordinatorLayout. (Or you can remove this behaviour for CoordinatorLayout)\n5. Additional views can be added to animate with the SnackProgressBar.\n6. Provides OverlayLayout to prevent user input.\n7. Provides a queue system.\n8. Icon can be added.\n9. Supports bundle in SnackProgressBar to carry information.\n10. Supports changing element color and text size.\n\n\u003cimg src=\"https://i.imgur.com/9C3A4UZl.png\" width=\"500\"\u003e\n\n**NOTE:** This library is still following the old Material Design Specifications.\n\n\u003cimg src=\"https://i.imgur.com/AriEeV2.png\" width=\"500\"\u003e\n\nWatch the demo video at https://youtu.be/dbawFbr6iPk.\n\n## Getting Started\nYou must have `colorAccent` declared in `colors.xml` file in your `res` folder. This library needs this value to apply proper styling to SnackProgressBar. Example:\n\n```xml\nres/values/colors.xml\n\n\u003c?xml version=\"1.0\" encoding=\"utf-8\"?\u003e\n\u003cresources\u003e\n    \u003ccolor name=\"colorAccent\"\u003e@android:color/holo_red_dark\u003c/color\u003e\n\u003c/resources\u003e\n```\n\n### SnackProgressBarManager\nStart by creating an instance of SnackProgressBarManager in your activity.\nIf possible, the root view of the activity should be provided and can be any type of layout.\nStarting v6.0, you can provide a LifecycleOwner of an activity / fragment.\nThis will call `SnackProgressBarManager.disable()` in `OnDestroy` to prevent memory leak.\n\n```kotlin\nprivate val snackProgressBarManager by lazy { SnackProgressBarManager(mainLayout, lifecycleOwner = this) }\n\noverride fun onCreate(savedInstanceState: Bundle?) {\n    super.onCreate(savedInstanceState)\n    setContentView(R.layout.activity_demo)\n    val floatingActionButton = findViewById\u003cView\u003e(R.id.fab)\n    snackProgressBarManager\n        // (Optional) Set the view which will animate with SnackProgressBar e.g. FAB when CoordinatorLayout is not used\n        .setViewToMove(floatingActionButton)\n        // (Optional) Change progressBar color, default = R.color.colorAccent\n        .setProgressBarColor(R.color.colorAccent)\n        // (Optional) Change background color, default = BACKGROUND_COLOR_DEFAULT (#FF323232)\n        .setBackgroundColor(SnackProgressBarManager.BACKGROUND_COLOR_DEFAULT)\n        // (Optional) Change text size, default = 14sp\n        .setTextSize(14f)\n        // (Optional) Set max lines, default = 2\n        .setMessageMaxLines(2)\n        // (Optional) Register onDisplayListener\n        .setOnDisplayListener(object : SnackProgressBarManager.OnDisplayListener {\n            override fun onLayoutInflated(\n                snackProgressBarLayout: SnackProgressBarLayout,\n                overlayLayout: FrameLayout,\n                snackProgressBar: SnackProgressBar,\n                onDisplayId: Int\n            ) {\n                // In v6.0, both snackProgressBarLayout and overlayLayout are exposed.\n                // You can edit them directly without reflection.\n            }\n\n            override fun onShown(snackProgressBar: SnackProgressBar, onDisplayId: Int) {\n                // We have assigned onDisplayId = 5000 for normalType SnackProgressBar\n                if (onDisplayId == 5000) {\n                    // You can retrieve the attached information here\n                    val bundle = snackProgressBar.getBundle()\n                    if (bundle != null) {\n                        val queueNo = bundle.getInt(\"queue\")\n                        val toast = \"Showing queue $queueNo!\"\n                        Toast.makeText(applicationContext, toast, Toast.LENGTH_SHORT).show()\n                    }\n                }\n            }\n\n            override fun onDismissed(snackProgressBar: SnackProgressBar, onDisplayId: Int) {\n                // Do something\n            }\n        })\n}  \n```\n\n### SnackProgressBar\nCreate a SnackProgressBar by calling the following examples.\n```kotlin\n// TYPE_NORMAL\nval normalType =\n    SnackProgressBar(SnackProgressBar.TYPE_NORMAL, \"TYPE_NORMAL - $queue\")\n        // (Optional) allow user input, default = FALSE\n        .setAllowUserInput(true)\n        // (Optional) allow user swipe to dismiss, default = FALSE\n        .setSwipeToDismiss(true)\n        // (Optional) set icon\n        .setIconResource(R.mipmap.ic_launcher)\n// Create a bundle and attach to snackProgressBar which can be retrieved via OnDisplayListener\nval bundle = Bundle()\nbundle.putInt(\"queue\", queue)\nnormalType.putBundle(bundle)\n\n// TYPE_NORMAL with action\nval normalTypeWithAction =\n    SnackProgressBar(\n        SnackProgressBar.TYPE_NORMAL,\n        \"TYPE_NORMAL - If the message and action are too long, a higher layout is used.\"\n    ).setAction(\"LONG ACTION TEXT\", object : SnackProgressBar.OnActionClickListener {\n        // (Required) Set action button\n        override fun onActionClick() {\n            Toast.makeText(applicationContext, \"Action Clicked!\", Toast.LENGTH_SHORT).show()\n        }\n    })\n\n// TYPE_HORIZONTAL\nval horizontalType =\n    SnackProgressBar(SnackProgressBar.TYPE_HORIZONTAL, \"TYPE_HORIZONTAL - Loading...\")\n        // (Optional) Set the type of progressBar, default = FALSE\n        .setIsIndeterminate(false)\n        // (Optional) Set max progress, default = 100\n        .setProgressMax(100)\n        // (Optional) Show percentage, default = FALSE\n        .setShowProgressPercentage(true)\n\n// TYPE_CIRCULAR with action\n// This type of layout is not recommended, simply because it is ugly.\nval circularTypeWithAction =\n    SnackProgressBar(SnackProgressBar.TYPE_CIRCULAR, \"TYPE_CIRCULAR - Loading...\")\n        .setIsIndeterminate(true)\n        .setAction(\"DISMISS\", object : SnackProgressBar.OnActionClickListener {\n            override fun onActionClick() {\n                Toast.makeText(applicationContext, \"Action Clicked!\", Toast.LENGTH_SHORT).show()\n            }\n        })\n```\nNote that `action` can be inserted in every type of SnackProgressBar.\n\n### Show\nShow the SnackProgressBar by calling:\n```kotlin\n// LENGTH_SHORT, LENGTH_LONG, LENGTH_INDEFINITE or other positive millis can be used\nsnackProgressBarManager.show(snackProgressBar, SnackProgressBarManager.LENGTH_LONG)\n```\n\nYou can include an `onDisplayId` when calling `show()`.\n```kotlin\nval onDisplayId = 100\nsnackProgressBarManager.show(snackProgressBar, SnackProgressBarManager.LENGTH_LONG, onDisplayId)\n```\n\nOr you can add the SnackProgressBar into memory and call it later.\n```kotlin\n// It is stored in HashMap, so storeId must be unique for each SnackProgressBar, else it will be overwritten\nval storeId = 100\nsnackProgressBarManager.put(snackProgressBar, storeId)\nsnackProgressBarManager.show(storeId, SnackProgressBarManager.LENGTH_LONG)\n```\n\nCalling show() will put the SnackProgressBar into a queue. It will be shown after other queued SnackProgressBars.\n\nNote: Starting v6.2.0, if LENGTH_INDEFINITE is specified for the queued SnackProgressBar, adding a new SnackProgressBar into the queue will cause the previous SnackProgressBar to be dismissed after showing completely. Prior to that, the SnackProgressBar will be dismissed after LENGTH_SHORT and then show the new SnackProgressBar, but this is counter-intuitive and causes issue [#26](https://github.com/tingyik90/snackprogressbar/issues/26) and [#28](https://github.com/tingyik90/snackprogressbar/issues/28).\n\n### Update\nCalling `show()` will always animate the hiding and showing of SnackProgressBar between queue. Use `updateTo()` instead to modify the\ndisplayed SnackProgressBar without animation. To modify the currently showing SnackProgressBar:\n```kotlin\n// Get the currently showing indeterminateType and change the message\nval snackProgressBar = snackProgressBarManager.getLastShown()\nsnackProgressBar.setMessage(\"new message\")\n// Calling updateTo() will not hide and show again the SnackProgressBar\nsnackProgressBarManager.updateTo(snackProgressBar)\n```\n\n### Dismiss\nCall `snackProgressBarManager.dismiss()` to dismiss the currently showing SnackProgressBar. The next SnackProgressBar in queue will be shown.\nCall `snackProgressBarManager.dismissAll()` to dismiss the currently showing SnackProgressBar and clear all other SnackProgressBars in queue.\n\n### Set Progress\nCall `snackProgressBarManager.setProgress()` to set the progress of ProgressBar.\n\n### Disable\n**IMPORTANT:** To avoid memory leak, call `SnackProgressBarManager.disable()` in onDestroy manually.\nElse, provide a `LifecycleOwner` in the constructor of `SnackProgressBarManager` to automatically call this method.\n\n## JavaDoc\nFor further information, see https://tingyik90.github.io/snackprogressbar/lib/.\n\nSee demo at https://github.com/tingyik90/snackprogressbar/blob/master/app/src/main/java/com/tingyik90/demo/DemoActivity.java\n\n## Download\nIn the project Gradle:\n```Gradle\nallprojects {\n    repositories {\n        maven { url \"https://jitpack.io\" }\n    }\n}\n```\n\nIn the app Gradle:\n```Gradle\ndependencies {\n    implementation 'com.github.tingyik90:snackprogressbar:version'\n}\n```\n\n## License\nCopyright 2017-2019 Saw Ting Yik\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n    http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftingyik90%2Fsnackprogressbar","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftingyik90%2Fsnackprogressbar","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftingyik90%2Fsnackprogressbar/lists"}