:closed_umbrella: An easy way to implement modern permission instructions popup.

Overview

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.
Comments
  • The background of the dialog can not be changed

    The background of the dialog can not be changed

    I'm trying to change the background of the dialog with the setBackgroundColor() method but it does not do anything , try several methods to get the color but the dialog continues to show the default color , the white background color .

    I'm using:

    • Android Studio 3.4.2
    • Java Language
    • Gradle 3.4.2

    Help me please.

    opened by Okami-x-Senpai 4
  • The `divider_top` and `divider_bottom` look too thick in dark theme

    The `divider_top` and `divider_bottom` look too thick in dark theme

    Is your feature request related to a problem?

    The divider_top and divider_bottom are too thick in dark theme although it's just 1 dp (but in light theme it seems fine).

    Describe the solution you'd like:

    Could we set its default height to 1 pixel instead?

    opened by anticafe 2
  • About the popup window color

    About the popup window color

    Thank you Jaewoong, I love your popup view very much.

    But I want to know how can I change the popup window color??

    When I use setBackgroundColor, it just changes the color that shows behind. ( I haven't use the DarkNeedsFactory because I don't how to use it )

    opened by LaNYGG 1
  • In landscape mode, popup does not show button to grant permissions

    In landscape mode, popup does not show button to grant permissions

    Please complete the following information:

    • Library Version: 1.0.1
    • Affected Device(s): Samsung Galaxy s8 with Android 9.0

    Describe the Bug:

    When changing orientation to landscape (or starting in landscape mode), the list of permissions is displayed but the button not. Probably it goes behind the viewport or something.

    Expected Behavior:

    The button and the complete list of permissions should be shown properly on landscape mode, too. Perhaps a ScrollView would be needed, and a layout for the landscape orientation. I would try to do one, if PR are allowed

    bug 
    opened by ghost 1
  • I think in `NeedsItem`, the word `Optional` has more meaningful than `Selection`

    I think in `NeedsItem`, the word `Optional` has more meaningful than `Selection`

    Is your feature request related to a problem?

    The word Selection makes user confused.

    Describe the solution you'd like:

    I think we should replace it with Optional

    opened by anticafe 1
  • Fixing small Typos in Read me

    Fixing small Typos in Read me

    Guidelines

    I was reading README.md file for this library , and just found a typo , so i fixed it .

    Types of changes

    What types of changes does your code introduce?

    • I fixed a small typo in README.md file.
    opened by soufianekremcht 0
  • I can't show the Dialogue

    I can't show the Dialogue

    I recently updated to the new version using previously version 1.0.3 but now I can't show the dialog, the code does nothing, do I have something to change that the new version requires?

    Code I use to display the dialog (This code used in version 1.0.3):

    mView = View.inflate(this, R.layout.main_log_in, null);
    
    mNeeds = new Needs.Builder(LogIn.this)
                                .setTitle("Title")
                                .setDescription(getString("Desc")
                                .setTitleIcon(ContextCompat.getDrawable(LogIn.this, R.drawable.ic_logo))
                                .setDividerColor(ContextCompat.getColor(LogIn.this, R.color.colorGrey2))
                                .setConfirmBackgroundColor(ContextCompat.getColor(LogIn.this, R.color.colorAccent))
                                .setNeedsTheme(mNeedsTheme)
                                .setNeedsItemTheme(mNeedsItemTheme)
                                .setTitleTextForm(mTextFormTitle)
                                .setDescriptionTextForm(mTextFormDesc)
                                .addNeedsItem(new NeedsItem(ContextCompat.getDrawable(LogIn.this, R.drawable.ic_file), ". SD Card", getString(R.string.akatsuki_title_required), getString(R.string.akatsuki_message_permission_storage)))
                                .addNeedsItem(new NeedsItem(ContextCompat.getDrawable(LogIn.this, R.drawable.ic_phone), ". Phone", getString(R.string.akatsuki_title_required), getString(R.string.akatsuki_message_permission_phone)))
                                .addNeedsItem(new NeedsItem(ContextCompat.getDrawable(LogIn.this, R.drawable.ic_wifi), ". Internet", getString(R.string.akatsuki_title_required), getString(R.string.akatsuki_message_permission_internet)))
                                .setConfirm(getString(R.string.akatsuki_btn_title_ok))
                                .setBackgroundAlpha(0.6F)
                                .setOnConfirmListener(new OnConfirmListener() {
                                    @Override
                                    public void onConfirm() {
                                        //code
                                }).setNeedsAnimation(NeedsAnimation.FADE).build();
                        mNeeds.show(mView);
    

    I await prompt response, thanks in advance.

    opened by kaname-png 0
  • Feqture request : Optional negative button

    Feqture request : Optional negative button

    I didn't try this yet. But it'd be nice if we have a optional additional button like "Later" to the left to confirm. So that users can relax :)

    opened by kamal-lab 1
Releases(1.1.2)
Owner
Jaewoong Eum
Android software engineer. Digital Nomad. Open Source Contributor. ❤️ Love coffee, music, magic tricks and writing poems. Coffee Driven Development.
Jaewoong Eum
:performing_arts: An easy, flexible way to implement veil skeletons and shimmering effect for Android.

AndroidVeil An easy, flexible way to implement veil skeletons and shimmering effect for Android. Download Gradle Add below codes to your root build.gr

Jaewoong Eum 1.2k Dec 28, 2022
AdsManager - Easy way to implement Google Ads

AdsManager Easy way to implement Google Ads Implementaion: https://jitpack.io/#R

null 3 Jul 25, 2022
:balloon: A lightweight popup like tooltips, fully customizable with an arrow and animations.

Balloon ?? A lightweight popup like tooltips, fully customizable with arrow and animations. Including in your project Gradle Add below codes to your r

Jaewoong Eum 2.9k Jan 9, 2023
:balloon: A lightweight popup like tooltips, fully customizable with an arrow and animations.

Balloon ?? A lightweight popup like tooltips, fully customizable with arrow and animations. Including in your project Gradle Add below codes to your r

Jaewoong Eum 1.8k Apr 27, 2021
Permissionmanager is a small wrapper for handling permission requests.

Permissionmanager Permissionmanager is a small wrapper for handling permission requests. Installation Add jitpack to your repositories in Project buil

Thomas Cirksena 11 Nov 17, 2020
Modern Calendar View Supporting Both Hijri and Gregorian Calendars but in highly dynamic way

KCalendar-View Modern calendar view supporting both Hijri and Gregorian calendar

Ahmed Ibrahim 8 Oct 29, 2022
:bouquet: An easy way to persist and run code block only as many times as necessary on Android.

Only ?? An easy way to persist and run code block only as many times as necessary on Android. Download Gradle Add below codes to your root build.gradl

Jaewoong Eum 479 Dec 25, 2022
Simple Android Library, that provides easy way to start the Activities with arguments.

Warning: Library is not maintained anymore. If you want to take care of this library, propose it via Pull Request. It needs adjustmensts for newer ver

Marcin Moskała 429 Dec 15, 2022
:bouquet: An easy way to persist and run code block only as many times as necessary on Android.

Only ?? An easy way to persist and run code block only as many times as necessary on Android. Download Gradle Add below codes to your root build.gradl

Jaewoong Eum 468 Apr 14, 2021
kinstall is an easy way to install gradle-based command-line kotlin projects that use the application plugin.

kinstall kinstall is an easy way to install gradle-based command-line kotlin projects that use the application plugin. use First, install kinstall its

david kilmer 0 Apr 24, 2022
In this project, I tried to understand and implement the architecture suggested by Android.

Shopping App Bu projede, Android'in önerdiği modern mimariyi anlamaya ve uygulamaya çalıştım. Projede kullandığım teknolojiler, Room Retrofit Coroutin

Süveybe Sena Küçük 24 Aug 11, 2022
This repository contains the article describing my attempt to implement a simple state reducer based on Kotlin Flow and an example app that uses it.

This repository contains the article describing my attempt to implement a simple state reducer based on Kotlin Flow and an example app that uses it.

Maciej Sady 18 Dec 29, 2022
Firebase with MVVM is a series of videos in which you will learn how to implement firebase with MVVM along with UI designs, GitHub branches, merging, and resolving conflicts.

In this project we will learn about Firebase Implementation with MVVM Architecture. It is a basic level Course and will go with project based approach so can understand better that how the things are working.

Shahzad Afridi 29 Jan 1, 2023
📒 NotyKT is a complete 💎Kotlin-stack (Backend + Android) 📱 application built to demonstrate the use of Modern development tools with best practices implementation🦸.

NotyKT ??️ NotyKT is the complete Kotlin-stack note taking ??️ application ?? built to demonstrate a use of Kotlin programming language in server-side

Shreyas Patil 1.4k Jan 4, 2023
Kotlin-based modern RecyclerView rendering weapon

Read this in other languages: 中文, English, Changelog Yasha Item introduction: Kotlin-based modern RecyclerView rendering weapon Item Features: No Adap

Season 514 Dec 21, 2022
Wrapper of FusedLocationProviderClient for Android to support modern usage like LiveData and Flow

FancyLocationProvider Wrapper of FusedLocationProviderClient for Android to support modern usage like LiveData or Flow. Install Add Jitpack repository

Jintin 66 Aug 15, 2022
CleanArchitecture is a sample project that presents a modern, 2021 approach to Android application development.

CleanArchitecture is a sample project that presents a modern, 2021 approach to Android application development. The goal of the pro

Shushant tiwari 0 Nov 13, 2021
Delish, a Food Recipes App in Jetpack Compose and Hilt based on modern Android tech-stacks and MVVM clean architecture.

Delish Screens Tech stack & Open-source libraries 100% Kotlin based + Coroutines + Flow for asynchronous. Dagger Hilt 2.37 Accompanist JetPack Jetpack

Mohamed Elbehiry 305 Dec 12, 2022
Crunch-Mobile - A Food Delivery Mobile App which uses Modern App Architecture Pattern, Firebase And a Simple Restful Api

Crunch-Mobile This is a Food Delivery Mobile App which uses Modern App Architect

Bright Ugwu 1 Jan 1, 2022