All Projects → skydoves → Needs

skydoves / Needs

Licence: apache-2.0
🌂 An easy way to implement modern permission instructions popup.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Needs

Cdalertview
Highly customizable alertview and alert/notification/success/error/alarm popup written in Swift
Stars: ✭ 1,056 (+93.41%)
Mutual labels:  popup, popup-window
WechatPopupWindow
高仿微信聊天界面长按弹框样式
Stars: ✭ 71 (-87%)
Mutual labels:  popup-window, popup
Jalert
jQuery alert/modal/lightbox plugin
Stars: ✭ 73 (-86.63%)
Mutual labels:  popup, popup-window
Basepopup
Android下打造通用便捷的PopupWindow弹窗库
Stars: ✭ 4,603 (+743.04%)
Mutual labels:  popup, popup-window
Wpopup
一个简单使用并且高度定制的Popupwindow。超简单实现朋友圈点赞效果,并且只用一个WPopup!完全不用担心复用问题!点击切换动画效果等!
Stars: ✭ 269 (-50.73%)
Mutual labels:  popup, popup-window
Powermenu
🔥 The powerful and easiest way to implement modern material popup menu.
Stars: ✭ 822 (+50.55%)
Mutual labels:  popup, popup-window
Arek
AREK is a clean and easy way to request any kind of iOS permission (with some nifty features 🤖)
Stars: ✭ 947 (+73.44%)
Mutual labels:  permission, popup
Xpopup
🔥XPopup2.0版本重磅来袭,2倍以上性能提升,带来可观的动画性能优化和交互细节的提升!!!功能强大,交互优雅,动画丝滑的通用弹窗!可以替代Dialog,PopupWindow,PopupMenu,BottomSheet,DrawerLayout,Spinner等组件,自带十几种效果良好的动画, 支持完全的UI和动画自定义!(Powerful and Beautiful Popup for Android,can absolutely replace Dialog,PopupWindow,PopupMenu,BottomSheet,DrawerLayout,Spinner. With built-in animators , very easy to custom popup v…
Stars: ✭ 6,106 (+1018.32%)
Mutual labels:  popup, popup-window
BalloonPopup
Forget Android Toast! BalloonPopup displays a round or squared popup and attaches it to a View, like a callout. Uses the Builder pattern for maximum ease. The popup can automatically hide and can persist when the value is updated.
Stars: ✭ 32 (-94.14%)
Mutual labels:  popup-window, popup
CustomPermissionsDialogue
Custom Permissions Dialogue is the only permissions library that supports ALL permission request scenarios. This library handles multiple edge cases such as not enabling all permissions or permanently rejecting a permission request.
Stars: ✭ 51 (-90.66%)
Mutual labels:  popup, permission
Jbox
jBox is a jQuery plugin that makes it easy to create customizable tooltips, modal windows, image galleries and more.
Stars: ✭ 1,251 (+129.12%)
Mutual labels:  popup, popup-window
Popbox.js
A tiny and simple stackable modal plugin for web apps
Stars: ✭ 295 (-45.97%)
Mutual labels:  popup, popup-window
ToolTipPopupWordTV
ToolTipopupWordTV is an Open Source Android library that allows developers to easily open a popup with details by select a word from a textview.
Stars: ✭ 41 (-92.49%)
Mutual labels:  popup-window, popup
React New Window
🔲 Pop new windows in React, using `window.open`.
Stars: ✭ 281 (-48.53%)
Mutual labels:  popup, popup-window
Popupwindow
PopupWindow is a simple Popup using another UIWindow in Swift
Stars: ✭ 401 (-26.56%)
Mutual labels:  popup, popup-window
Permissionmanager
Admin interface for managing users, roles, permissions, using Backpack CRUD
Stars: ✭ 363 (-33.52%)
Mutual labels:  permission
Fwpopupview
弹窗控件:支持AlertView、Sheet、自定义视图的PopupView。AlertView中可以嵌套自定义视图,各组件的显示隐藏可配置;Sheet仿微信样式;同时提供自定义弹出。更多配置请参考”可设置参数“,提供OC使用Demo。
Stars: ✭ 361 (-33.88%)
Mutual labels:  popup
Shiro Action
基于 Shiro 的权限管理系统,支持 restful url 授权,体验地址 :
Stars: ✭ 357 (-34.62%)
Mutual labels:  permission
Search Dialog
An easy to use, yet very customizable search dialog
Stars: ✭ 503 (-7.88%)
Mutual labels:  popup
React Native Social Share
Use the iOS and Android native Twitter and Facebook share popup with React Native https://github.com/doefler/react-native-social-share
Stars: ✭ 405 (-25.82%)
Mutual labels:  popup

Needs

License API Build Status Android Arsenal Android Weekly Javadoc
An easy way to implement modern permission instructions popup.
Needs can be fully customized and showing with animations.

img0 img1

Download

Maven Central JitPack

Gradle

Add below codes to your root build.gradle file (not your module build.gradle file).

allprojects {
    repositories {
        mavenCentral()
    }
}

And add a dependency code to your module's build.gradle file.

dependencies {
    implementation "com.github.skydoves:needs:1.1.2"
}

Usage

Basic example

This is a basic example on a screenshot. Here is how to create Needs using Needs.Builder.

Needs needs = new Needs.Builder(context)
      .setTitle("Permission instructions for using this Android app.")
      .addNeedsItem(new NeedsItem(null, "· SD Card", "(Required)", "Access photos, media, and files on device."))
      .addNeedsItem(new NeedsItem(null, "· Location", "(Required)", "Access this device's location."))
      .addNeedsItem(new NeedsItem(null, "· Camera", "(Optional)", "Take pictures and record video."))
      .addNeedsItem(new NeedsItem(null, "· Contact", "(Optional)", "Access this device's contacts."))
      .addNeedsItem(new NeedsItem(null, "· SMS", "(Optional)", " end and view SMS messages."))
      .setDescription("The above accesses are used to better serve you.")
      .setConfirm("Confirm")
      .setBackgroundAlpha(0.6f)
      .setLifecycleOwner(lifecycleOwner)
      .build();

Create using kotlin dsl

This is how to create Needs's instance using kotlin dsl.

val needs = createNeeds(baseContext) {
      titleIcon = iconDrawable
      title = "Permission instructions \nfor using this Android app."
      titleTextForm = titleForm
      addNeedsItem(NeedsItem(drawable_sd, "SD Card", "(Required)", "Access photos, media, and files on device."))
      addNeedsItem(NeedsItem(drawable_location, "Location", "(Required)", "Access this device's location."))
      addNeedsItem(NeedsItem(drawable_camera, "Camera", "(Optional)", "Take pictures and record video."))
      addNeedsItem(NeedsItem(drawable_contact, "Contact", "(Optional)", "Access this device's contacts."))
      addNeedsItem(NeedsItem(drawable_sms, "SMS", "(Optional)", "Send and view SMS messages."))
      description = "The above accesses are used to better serve you."
      confirm = "Confirm"
      backgroundAlpha = 0.6f
      lifecycleOwner = lifecycle
      needsTheme = theme
      needsItemTheme = itemTheme
      needsAnimation = NeedsAnimation.CIRCULAR
    }

OnConfirmListener

We can listen to the confirm button is clicked using OnConfirmListener.

needs.setOnConfirmListener(new OnConfirmListener() {
  @Override
  public void onConfirm() {
      // confirmed
  }
});

Show and dismiss

Here is how to show needs popup and dismiss easily.

needs.show(layout); // shows the popup menu to the center. 
needs.dismiss(); // dismiss the popup menu.

TextForm

TextFrom is an attribute class that has some attributes about TextView for customizing popup texts.

TextForm textForm = new TextForm.Builder()
          .setTextColor(R.color.colorPrimary)
          .setTextSize(14)
          .setTextStyle(Typeface.BOLD)
          .build();

builder.setTitleTextForm(titleTextForm);
builder.setDescriptionTextForm(descriptionTextForm);
builder.setConfirmTextForm(confirmTextForm);

Here is how to create TextForm using kotlin dsl.

val titleForm = textForm {
  textSize = 18
  textStyle = Typeface.BOLD
  textColor = ContextCompat.getColor(baseContext, R.color.black)
}

NeedsTheme

NeedsTheme is an attribute class for changing Needs popup theme easily.

NeedsTheme needsTheme = new NeedsTheme.Builder(context)
           .setBackgroundColor(ContextCompat.getColor(context, R.color.background))
           .setTitleTextForm(titleTextForm)
           .setDescriptionTextForm(descriptionTextForm)
           .setConfirmTextForm(confirmTextForm)
           .build();

builder.setNeedsTheme(needsTheme);           

Here is how to create NeedsTheme using kotlin dsl.

val theme = needsTheme(baseContext) {
      backgroundColor = ContextCompat.getColor(baseContext, R.color.background)
      titleTextForm = textForm(baseContext) {
        textSize = 18
        textColor = ContextCompat.getColor(baseContext, R.color.white)
      }
      descriptionTextForm = textForm(baseContext) {
        textSize = 12
        textColor = ContextCompat.getColor(baseContext, R.color.description)
      }
    }

NeedsItemTheme

NeedsTheme is an attribute class for changing Needs popup RecyclerView's item theme easily.

NeedsItemTheme needsItemTheme = new NeedsItemTheme.Builder(context)
               .setBackgroundColor(ContextCompat.getColor(context, R.color.background))
               .setTitleTextForm(titleTextForm)
               .setRequireTextForm(requireTextForm)
               .setBulletForm(bulletForm)
               .build();

builder.setNeedsItemTheme(needsItemTheme);

Here is how to create NeedsItemTheme using kotlin dsl.

val itemTheme = needsItemTheme(baseContext) {
      backgroundColor = ContextCompat.getColor(baseContext, R.color.background)
      titleTextForm = textForm(baseContext) {
        textColor = ContextCompat.getColor(baseContext, R.color.colorPrimaryDark)
        textSize = 16
      }
      descriptionTextForm = textForm(baseContext) {
        textColor = ContextCompat.getColor(baseContext, R.color.description)
      }
    }

BulletForm

We can make bullet points in front of every title and they can be fully customized.

BulletForm bulletForm = new BulletForm.Builder(context)
                    .setBulletColorResource(R.color.colorPrimary)
                    .setBulletSize(12)
                    .setBulletPadding(9)
                    .build();

Here is how to create BulletForm using kotlin dsl.

val bulletForm = bulletForm(context) {
      setBulletColorResource(R.color.colorPrimary)
      setBulletSize(12)
}

NeedsAnimation

NeedsAnimation implements showing and dismissing popup with animations.

ELASTIC CIRCULAR
elastic circluar
NONE FADE
none fade
builder.setNeedsAnimation(NeedsAnimation.FADE)
builder.setNeedsAnimation(NeedsAnimation.NONE)
builder.setNeedsAnimation(NeedsAnimation.ELASTIC)
builder.setNeedsAnimation(NeedsAnimation.CIRCULAR)

Kotlin Extensions

We can show and initialize Needs property more polish using extensions.

showNeeds

Shows the popup menu to the center.
It observes the target view's inflating and after inflate finished, show up on the target view.

targetView.showNeeds(needs)

Lazy initialization

We can initialize the needs property lazily using needs keyword and Needs.Factory abstract class.
The needs extension keyword can be used on Activity and Fragment.

class MainActivity : AppCompatActivity() {
  private val myNeeds by needs<DarkNeedsFactory>()
  
  // ..
}

We should create a class which extends Needs.Factory.
An implementation class of the factory must have a default(non-argument) constructor.

class DarkNeedsFactory : Needs.Factory() {

  override fun create(context: Context, lifecycle: LifecycleOwner): Needs {
    return Needs.Builder(context)
      .setTitle("Permission instructions \nfor using this Android app.")
      .setDescription("The above accesses are used to better serve you. This application is available even if you do not agree to allow it.")
      .setConfirm("Confirm")
      .setBackgroundAlpha(0.6f)
      .setLifecycleOwner(lifecycle)
      .setNeedsAnimation(NeedsAnimation.FADE)
      .addNeedsItem(NeedsItem(null, "· SD Card", "(Required)", "   Access photos, media, and files on device."))
      .addNeedsItem(NeedsItem(null, "· Location", "(Required)", "   Access this device's location."))
      .addNeedsItem(NeedsItem(null, "· Camera", "(Optional)", "   Take pictures and record video."))
      .addNeedsItem(NeedsItem(null, "· Contact", "(Optional)", "   Access this device's contacts."))
      .addNeedsItem(NeedsItem(null, "· SMS", "(Optional)", "   Send and view SMS messages."))
      .build()
  }
}

Preference

If you want to show-up the Popup only once or a specific number of times, here is how to implement it simply.

.setPreferenceName("MyNeeds") // sets preference name of the Needs.
.setShowTime(3) // show-up three of times the popup. the default value is 1 If the preference name is set.

Avoid Memory leak

Dialog, PopupWindow and etc.. have memory leak issue if not dismissed before activity or fragment are destroyed.
But Lifecycles are now integrated with the Support Library since Architecture Components 1.0 Stable released.
So we can solve the memory leak issue so easily.

Just use setLifecycleOwner method. Then dismiss method will be called automatically before activity or fragment would be destroyed.

.setLifecycleOwner(lifecycleOwner)

Needs builder methods

.setTitleIcon(@DrawableRes drawable: Drawable)
.setTitle(value: String)
.setTitleTextForm(value: TextForm)
.setDescription(value: String)
.setDescriptionTextForm(value: TextForm)
.setConfirmBackgroundColor(@ColorInt value: Int)
.setConfirm(value: String)
.setConfirmTextForm(value: TextForm)
.setConfirmVisible(value: Boolean)
.setListAdapter(value: RecyclerView.Adapter<*>)
.setListHeight(value: Int)
.setPadding(value: Int)
.addNeedsItem(value: NeedsItem)
.addNeedsItemList(value: List<NeedsItem>)
.setBackground(@DrawableRes value: Drawable)
.setBackgroundColor(@ColorInt value: Int)
.setBackgroundAlpha(value: Float)
.setDividerColor(@ColorInt value: Int)
.setDividerVisible(value: Boolean)
.setDividerHeight(value: Float)
.setOnConfirmListener(value: OnConfirmListener)
.setLifecycleOwner(value: LifecycleOwner)
.setNeedsTheme(value: NeedsTheme)
.setNeedsItemTheme(value: NeedsItemTheme)
.setNeedsAnimation(value: NeedsAnimation)

Find this library useful? ❤️

Support it by joining stargazers for this repository. ⭐️

License

Copyright 2019 skydoves

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.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].