GithubHelp home page GithubHelp logo

aditya94a / morphing-material-dialogs Goto Github PK

View Code? Open in Web Editor NEW
893.0 20.0 67.0 7.65 MB

Material dialog :heart: morphing animation. An android kotlin UI library for building beautiful animations for converting a floating action button into a material dialog.

Home Page: https://adi.bio

License: MIT License

Kotlin 100.00%
android android-application android-app android-ui android-sdk material-design

morphing-material-dialogs's Introduction

Morphing Material Dialogs

Release Build Status GitHub license

A library for fab-to-dialog morphing (as in Nick Butcher's Plaid) with Aidan Follestad's Material Dialogs.

Table of Contents

  1. Setup Instructions
  2. Usage Instructions
  3. Customization
  4. Misc

Setup Instructions

Add the following to your root (project) level build.gradle:

	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}

Add the library to your app's build.gradle

	dependencies {
		implementation 'com.github.AdityaAnand1:Morphing-Material-Dialogs:0.0.3'
		//you should also have the design support library, since we're using the native floating action button
   		implementation "com.android.support:design:27.0.2"
	}

In your styles.xml, override the MorphDialog.Base themes (at least one, both if you wish to support light and dark themes for your app)

    <style name="MorphDialog.Custom.Light" parent="MorphDialog.Base.Light">
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorAccent">@color/accent</item>
    </style>

    <style name="MorphDialog.Custom.Dark" parent="MorphDialog.Base.Dark">
        <item name="colorPrimary">@color/primary</item>
        <item name="colorPrimaryDark">@color/primary_dark</item>
        <item name="colorAccent">@color/accent</item>
    </style>

In your app's manifest file, add the following (at least one, both if you wish to support light and dark themes for your app)

   <activity
       android:name="com.adityaanand.morphdialog.MorphDialogActivity"
       android:theme="@style/MorphDialog.Custom.Light">
   </activity>
   <activity
       android:name="com.adityaanand.morphdialog.MorphDialogActivityDark"
       android:theme="@style/MorphDialog.Custom.Dark">
   </activity>

Usage instructions

This library mirror's a subset of afollestad/material-dialogs API.

new MorphDialog.Builder(this, fabView)
               .title("Title")
               .content("This is a sentence. Here is another one.") 
               .positiveText(R.string.ok)
               .onPositive((MorphDialog dialog1, MorphDialogAction which) -> {
                   Toast.makeText(this, "onPositive", Toast.LENGTH_SHORT).show();
               })
               .useDarkTheme(true) //optional, default is false
               .show();

For example, if you have a floating action button in your activity

       <android.support.design.widget.FloatingActionButton
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:onClick="morph"/>

Then your morph() might look like:

    public void morph(View view) {
        new MorphDialog.Builder(this, (FloatingActionButton) view)
                .title("Title")
                .content("This is a sentence. Here is another one.")
                .show();
    }

Customization

Listen for action button callbacks

MorphDialog is not a dialog. It's another activity and the only way to get back the result of any interactions with it is through onActivityResult().

In order to use the .onPositive(), .onNegative(), .onNeutral or .onAny() callbacks, you must pass on the activity result to the morphDialog object. You must do this for each dialog that you are using individually.

    MorphDialog dialog1;
    MorphDialog dialog2;
    
    void buildDialog(){
     dialog1 = new MorphDialog.Builder(this, (FloatingActionButton) view)
                .title("Title")
                .content("This is a sentence. Here is another one.")
                .positiveText(R.string.ok)
                .negativeText("Cancel")
                .neutralText("More")
                .onPositive((MorphDialog dialog1, MorphDialogAction which) -> {
                    Toast.makeText(this, "onPositive", Toast.LENGTH_SHORT).show();
                })
                .onNegative((MorphDialog dialog1, MorphDialogAction which) -> {
                    Toast.makeText(this, "onNegative", Toast.LENGTH_SHORT).show();
                })
                .onNeutral((MorphDialog dialog1, MorphDialogAction which) -> {
                    Toast.makeText(this, "onNeutral", Toast.LENGTH_SHORT).show();
                })
                .build();
	}
	
    
    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        dialog1.onActivityResult(requestCode, resultCode, data);
        dialog2.onActivityResult(requestCode, resultCode, data);
    }

If you have a large number of dialogs you may prefer to use the helper function instead, which uses a varargs parameter to register the callback to multiple dialog objects:

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
	MorphDialog.registerOnActivityResult(requestCode, resultCode, data, dialog1, dialog2, dialog3);
    }

Also, note that you will receive the callbacks only after the animation has ended.

Set Canceleable

If you do not want the dialog to close when tapping outside the dialog you can use builder.cancelable(false)

Customize Colors

The following methods can be used to customize the different colors in your dialog

new MorphDialog.Builder(context, (FloatingActionButton) view)
                .contentColor(Color.BLUE)
                .backgroundColor(Color.GREEN)
                .neutralColorRes(R.color.primary)
                .positiveColor(Color.BLACK)
                .titleColor(Color.YELLOW);

Theme overrides

Override the android:windowBackground attribute to provide a custom color for the area outside of the dialog.

    <style name="MorphDialog.Custom.Light" parent="MorphDialog.Base.Light">
        <item name="android:windowBackground">@color/windowBackground</item>
    </style>

Misc

What happens below API 21 (<Lollipop)?

Nothing. Since this library uses activity transitions which are properly supported only for Lollipop and up, the dialog pops up normally without any morphing animation below Lollipop.

Why does the library not support all of Material Dialogs features?

The problem is passing the instructions to build a MaterialDialog (i.e,a MaterialDialog.Builder object) to another activity. The Builder class is not Parcelable and contains a lot of context aware fields like custom views. In the current architecture, there's no clear path to doing this without explicitly adding memory leaks. (Suggestions welcome)

I want to morph from something other than a fab/ I want to morph to something other than MorphDialog

Currently, this library does not support morphing something-other-than-a-fab to something-other-than-a-material-dialog transition. If you'd like for it to work in another setting, say a custom view, head over to the standalone module and check out the minimal implementation (without all the library plumbing) that should point you in the direction of a custom solution.


Fun fact: This library was originally built for Timbre.

morphing-material-dialogs's People

Contributors

aditya94a avatar adityaanand1 avatar dependabot-support avatar imgbotapp avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

morphing-material-dialogs's Issues

Support more customization for the dialogs

Just going to think out loud in here.

Okay, so the material dialogs library offers a great deal of customization. Ideally, I'd like the morphing animation to work well with all of it.

Duplicating the API is hardly a good solution, might work as a quick hack right now, but in the long run a better architected solution should obviously be preferred.

  • Can we somehow just transmit the MaterialDialog root view from the calling activity into the MorphDialogActivity? Well, won't that be nice. But I think not possible without leaks, I'll look into this first.
  • But I think my best bet is to somehow save the "state" of the MaterialDialog.Builder to be reconstructed in the MorphDialogActivity. Perhaps by extending and implementing Parcelable? Or something like that...

Color chooser dialog support?

I managed to rebuild your standalone morphing dialog to my liking, however I found out the creator of MaterialDialogs also has a color picker dialog which I would like to use morphingly as well. However, upon inspection of the code he appears to use a fragment and the standard android Dialog system for this. We cannot simply "getView()" and put it inside the morphing activity. Any ideas of how to manage to do this?

Update readme

Hi,

Just tried it out and it finally works, cool stuff, but some important info was missing in the readme, maybe you can update the readme with the following:

In app's build.gradle

android {
    dataBinding {
        enabled = true
    }
}
dependencies {
    implementation 'com.github.AdityaAnand1:Morphing-Material-Dialogs:0.0.4'
    implementation 'com.afollestad.material-dialogs:core:0.9.6.0'
}

I noticed that v0.9.6.0 of Material Dialogs must be used, v2.0 will not work, and throw errors. Will you support V2.0 sometime?

Current readme also references v0.0.3 instead of 0.0.4...

Thanks!

P.S. Yes, this still works :)

Just wanted to add a quick update for any curious devs:

Yes, this library still works perfectly ๐Ÿ˜ It hasn't been updated in a while but everything is still up to the latest best practices and design guidelines.

Let me know if anyone has any feature requests or suggestions.

Failed when compile project

Error:com.android.builder.dexing.DexArchiveBuilderException: Failed to process /Users/haytran/.gradle/caches/transforms-1/files-1.1/Morphing-Material-Dialogs-0.0.1-alpha2.aar/a4e8ad92db421a1a69733ac31c121cd3/jars/classes.jar
Error:com.android.builder.dexing.DexArchiveBuilderException: Error while dexing in/adityaanand/morphdialog/MorphDialogActivity.class
Error:com.android.dx.cf.code.SimException: invalid opcode ba (invokedynamic requires --min-sdk-version >= 26)
Error:Execution failed for task ':app:transformClassesWithDexBuilderForDebug'.

com.android.build.api.transform.TransformException: com.android.builder.dexing.DexArchiveBuilderException: com.android.builder.dexing.DexArchiveBuilderException: Failed to process /Users/haytran/.gradle/caches/transforms-1/files-1.1/Morphing-Material-Dialogs-0.0.1-alpha2.aar/a4e8ad92db421a1a69733ac31c121cd3/jars/classes.jar

Logo Proposal

Hello,

I came across your amazing project and i wanted to help contribute to your awesome project...
I created a logo for you... Two design styles based on similar idea concept...

i focused more on minimal style, simplicity and clean...

You are free to choose any design style you like the most and good enough for your project...
If you find any of the styles good enough and you like it, please do let me know and i will gladly send you all the files you need both the vector files all for free...

logo design_morphing dialogs_presentation

logo design_morphing dialogs_idea concept

logo design_morphing dialogs_idea concept 2

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.