Code Monkey home page Code Monkey logo

sneaker's Introduction

Sneaker v2

A lightweight Android library for customizable alerts

Download

Grab via Gradle:

implementation 'com.irozon.sneaker:sneaker:2.0.0'

Usage

In Sneaker 2.0.0 it's possilbe to show sneaker on Activity, Fragment or any ViewGroup

 Sneaker.with(activity) // To show Sneaker on Activity
 Sneaker.with(fragment) // To show Sneaker on Fragment
 Sneaker.with(viewGroup) // To show Sneaker on ViewGroup

Custom:

Sneaker.with(actvitiy) // Activity, Fragment or ViewGroup
       .setTitle("Title", R.color.white) // Title and title color
       .setMessage("This is the message.", R.color.white) // Message and message color
       .setDuration(4000) // Time duration to show
       .autoHide(true) // Auto hide Sneaker view
       .setHeight(ViewGroup.LayoutParams.WRAP_CONTENT) // Height of the Sneaker layout
       .setIcon(R.drawable.ic_no_connection, R.color.white, false) // Icon, icon tint color and circular icon view
       .setTypeface(Typeface.createFromAsset(this.getAssets(), "font/" + fontName)); // Custom font for title and message
       .setOnSneakerClickListener(this) // Click listener for Sneaker
       .setOnSneakerDismissListener(this) // Dismiss listener for Sneaker. - Version 1.0.2
       .setCornerRadius(radius, margin) // Radius and margin for round corner Sneaker. - Version 1.0.2
       .sneak(R.color.colorAccent) // Sneak with background color

Error:

 Sneaker.with(actvitiy) // Activity, Fragment or ViewGroup
        .setTitle("Error!!")
        .setMessage("This is the error message")
        .sneakError()

Success:

 Sneaker.with(actvitiy) // Activity, Fragment or ViewGroup
        .setTitle("Success!!")
        .setMessage("This is the success message")
        .sneakSuccess()

Warning:

 Sneaker.with(actvitiy) // Activity, Fragment or ViewGroup
        .setTitle("Warning!!")
        .setMessage("This is the warning message")
        .sneakWarning()

Custom View:

 val sneaker = Sneaker.with(actvitiy) // Activity, Fragment or ViewGroup
 val view = LayoutInflater.from(this).inflate(R.layout.custom_view,  sneaker.getView(), false)
 // Your custom view code
 view.findViewById<TextView>(R.id.tvInstall).setOnClickListener{
       Toast.makeText(this, "Clicked", Toast.LENGTH_SHORT).show()
 }
 sneaker.sneakCustom(view)

Apps using Sneaker

If you are using Sneaker in your app and would like to be listed here, please let me know by email or opening a new issue!

Authors

Licence

Copyright 2018 Irozon, Inc.

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.

sneaker's People

Contributors

hamadakram avatar thenishchalraj avatar turing-tech 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  avatar  avatar  avatar  avatar  avatar

sneaker's Issues

Sneaker visibility on Dialog open

When I try to display Sneaker, keeping open a Android Dialog or Alert Dialog, it is seen that Sneaker stays below it [transparent background]. Is there any way to bring it on top of everything?

Getting Force close on kitkat

Hello I'm getting force on Kitkat Api 16 on genymotion while it is working fine on Android 7.1.2 API25, can you please look into it and can you bring down minimum api sdk level to atleast 16.

java.lang.NoSuchMethodError: android.widget.LinearLayout.setElevation at com.irozon.sneaker.Sneaker.sneakView(Sneaker.java:360) at com.irozon.sneaker.Sneaker.sneakError(Sneaker.java:326) at com.ingridtech.ommahajan.ui.fragment.LoginFragment.onClick(LoginFragment.java:169) at android.view.View.performClick(View.java:4438) at android.view.View$PerformClick.run(View.java:18422) at android.os.Handler.handleCallback(Handler.java:733) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:136) at android.app.ActivityThread.main(ActivityThread.java:5001) at java.lang.reflect.Method.invokeNative(Native Method) at java.lang.reflect.Method.invoke(Method.java:515) at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) at dalvik.system.NativeStart.main(Native Method)

fragment use

this view show above activity but bellow fragment,so can't show to user when activity contain fragment

Sneaker Position

Hello, is it possible to change the sneaker position? I would like to show it on center and bottom as well.

Thanks.

don't show text on api 23

i have a strange problem :
i have button in a activity and a function for onClick event

fun sendComment(view: View): Unit {

    Sneaker.with(this) // Activity, Fragment or ViewGroup
            .setTitle("Warning!!")
            .setMessage("This is the warning message")
            .sneakWarning()

    Toast.makeText(this,"show",Toast.LENGTH_LONG).show()
}

Toast show correct but Sneaker don't show!!

but i have a other Sneaker on onCreate activity function It is displayed correctly

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_contact)
        val typeface= Typeface.createFromAsset(assets,getString(R.string.font_path))
        _tv_name.typeface = typeface
        _tv_phone_number.typeface = typeface
        _tv_comment.typeface = typeface
        _tl_comment.typeface = typeface
        _tl_phone_number.typeface = typeface
        _tl_name.typeface = typeface

        Sneaker.with(this) // Activity, Fragment or ViewGroup
                .setTitle("Warning!!")
                .setMessage("This is the warning message")
                .sneakWarning()
       }

i test it on genymotion samsung S7 and Samsung S5

Show at Bottom

Hey bro,
I want to show Sneaker at the bottom of the screen same as now showing at top
And I want to give user a choice to show at top or bottom dynamically.
So how can I achieve this ?
Thanks...

OnSneakerDismissListener no response

why activity onDismiss() have not executed
Sneaker.with(this) .setTitle(getString(R.string.login_success)) .setMessage(getString(R.string.success)) .setOnSneakerDismissListener(this) .setDuration(5000) .sneakSuccess()

override fun onDismiss() { val intent = Intent(this, MainActivity::class.java) launchActivity(intent) }

Sneaker doesn't appear when statusbar is translucent

Hi, as explained in my PR, the Sneaker isn't shown when I remove the statusbar from the Activity (and I'm not talking about Toolbar/Actionbar).

This is the code I use to remove the statusbar in any activity :

protected void onCreate(Bundle savedInstanceState) {
(...)
   Window w = getWindow();
   w.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
   w.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
}

How to change the font for sneaker?

Firstly, thank you for this beautiful library.

My doubt here is how do I change the font of text inside sneaker? I know you have provided us with a snippet of code in which there's this line:
.setTypeface(Typeface.createFromAsset(this.getAssets(), "font/" + fontName)); // Custom font for title and message
When I use this as it is in my project it gives me an error atfontName. What do I have to do in order to change the font or use this snippet provided by you?
Could you please post an example providing more clarity on this subject?
Any help would be appreciated.

Null exception on getLayout()

if (mAutoHide) {
Handler handler = new Handler();
handler.removeCallbacks(null);
handler.postDelayed(new Runnable() {
@OverRide
public void run() {
getLayout().startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.popup_hide));
viewGroup.removeView(getLayout());
}
}, mDuration);
}

Runtime bug and crash app

**This is SneakerHelper class :‌ **

package com.okabbas.olympiad.helper

import android.support.v4.app.FragmentActivity
import com.irozon.sneaker.Sneaker
import com.okabbas.olympiad.R
import com.okabbas.olympiad.app.AppApp
import com.okabbas.olympiad.helper.SneakerHelper.SneakerModel.*

class SneakerHelper {
    private var sneaker: Sneaker? = null

    enum class SneakerModel {
        SUCCESSFUL, UNSUCCESSFUL,
        WARNING, ERROR, WAIT
    }

    fun showMessage(activity: FragmentActivity, message: String, model: SneakerModel) {
        Sneaker.with(activity)
                .setTypeface(AppApp.mediumFont)
                .setTitle("result -> $message", R.color.colorWhite)
                .setIcon(getIcon(model), false)
                .setDuration(5000)
                .autoHide(true)
                .setHeight(150)
                .sneak(getColor(model))
    }

    fun showLoading(activity: FragmentActivity, message: String, model: SneakerModel) {
        sneaker = null
        sneaker = Sneaker.with(activity)
                .setTypeface(AppApp.mediumFont)
                .setTitle(message, R.color.colorWhite)
                .setIcon(getIcon(model), false)
                .setDuration(5000)
                .autoHide(false)
                .setHeight(150)

        sneaker?.sneak(getColor(model))
    }

    fun hideLoading() {
        sneaker?.let {
            it.setDuration(0)
            it.autoHide(true)
            it.setHeight(0);
            it.sneak(R.color.colorBlack);
        }
    }

    private fun getIcon(model: SneakerModel): Int {
        return when (model) {
            SUCCESSFUL -> R.mipmap.ico_successful
            UNSUCCESSFUL -> R.mipmap.ico_unsuccessful
            WARNING -> R.mipmap.ico_warnings
            ERROR -> R.mipmap.ico_error
            WAIT -> R.mipmap.ico_wait
        }
    }

    private fun getColor(model: SneakerModel): Int {
        return when (model) {
            SUCCESSFUL -> R.color.colorPrimaryDark
            UNSUCCESSFUL -> R.color.colorOrange
            WARNING -> R.color.colorRed
            ERROR -> R.color.colorHepatic
            WAIT -> R.color.colorBlack
        }
    }
}

i'm call methods hideLoading and showLoading and showMessage in main activity :
In debug mode, there's no problem, but when I release the application, I get the following errors using the fabric service.

Fatal Exception: java.lang.NullPointerException
       at com.irozon.sneaker.Sneaker$1.run(Sneaker.java:614)
       at android.os.Handler.handleCallback(Handler.java:733)
       at android.os.Handler.dispatchMessage(Handler.java:95)
       at android.os.Looper.loop(Looper.java:136)
       at android.app.ActivityThread.main(ActivityThread.java:5017)
       at java.lang.reflect.Method.invokeNative(Method.java)
       at java.lang.reflect.Method.invoke(Method.java:515)
       at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
       at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
       at dalvik.system.NativeStart.main(NativeStart.java)

What do you think the problem is ? Sneaker bug ?

Message Text always has a white background (see photo)

Using the code:

Sneaker.with(this) // Activity, Fragment or ViewGroup
                    .setTitle("Warning!!")
                    .autoHide(false)
                    .setMessage("Please check your internet connection.", getResources().getColor(R.color.black, null))
                    .sneak(getResources().getColor(R.color.alert_yellow, null));

I always see a white background for the text. I've tried multiple OS versions, and all the same.
I have also tried using .sneakWarning(), which showed the same thing.

Is there any way to supply a transparent background for the text?

Screenshot_3_14_19__12_52_PM

[FEATURE REQUEST] .setHeight wrap_content

Maybe it's an error on my end but I found that setting no height on Sneaker results in long texts truncated, and while the issue can be resolved setting an height it does not provide a reliable solution, because some device I didn't tested against or some future device could have some exotic form-factor that vanifies this implementation. So a wrap-content option could be a definitive solution to this problem. However thank you for your work.

InComplete Alert Message

Hey there, i just started using this repo and it's very useful but in some devices alert message is not showing completely as given below:

kotlindemo snap

Code:
(In Activity)

Sneaker
    .with(this)
    .setTitle("Alert!!")
    .setMessage("Internet Connection Not Found")
    .sneakWarning()

is there any solution for this problem??

bug displaying sneaker multiple times

if I click on a button multiple times it shows the sneaker, the application stops, it does not solve to add try {} catch {} when creating the sneaker
the error points to this line : getLayout().startAnimation(AnimationUtils.loadAnimation(getContext(), R.anim.popup_hide));

10-02 01:46:31.620 1767-1767/com.edwin E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.edwin, PID: 1767
java.lang.NullPointerException: Attempt to invoke virtual method 'void android.view.View.startAnimation(android.view.animation.Animation)' on a null object reference
at com.irozon.sneaker.Sneaker$1.run(Sneaker.java:474)
at android.os.Handler.handleCallback(Handler.java)
at android.os.Handler.dispatchMessage(Handler.java)
at android.os.Looper.loop(Looper.java)
at android.app.ActivityThread.main(ActivityThread.java)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java)

Could not resolve Sneaker in gradle

I am trying to add Sneaker into our dependencies but it throws an error like below

Execution failed for task ':app:dataBindingMergeDependencyArtifactsBrandtestDebug'.

Could not resolve all files for configuration ':app:brandtestDebugCompileClasspath'.
Could not find com.irozon.sneaker:sneaker:2.0.0.
Required by:
project :app

Possible solution:

project level build.gradle:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.2"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.20"

    // NOTE: Do not place your application dependencies here; they belong
    // in the individual module build.gradle files
}

}

allprojects {
repositories {
google()
mavenCentral()
}

what I am missing here?
}

task clean(type: Delete) {
delete rootProject.buildDir
}

iOS fork?

This is a beautiful library for showing alerts. Will you port it to iOS anytime soon?

How to change Text color?

Hello, I'm showing custom Sneaker with my own background color. How can i change text color of Sneaker?

Sneaker appear differently in activity and fragment

Hi,

Sneaker appears differently from Activity and Fragment like below.
In Activity, it comes from the toolbar but in the fragment, it comes from the bottom of the toolbar.
The images are from different devices but it shows the same behavior with other devices as well.
I want both of them comes from the bottom of the toolbar as Fragment did.

Here is the AppTheme, its given in Android manifest and I didn't give any other theme to Activity.

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/color_light_grey</item>
    <item name="colorPrimaryDark">@color/color_black</item>
    <item name="colorAccent">@color/color_red</item>

    <item name="android:windowContentTransitions">true</item>
</style>

Here how I show the error message, same code for both

protected fun showErrorMessage(errorMessage: String?, isGreen: Boolean = false) {
    val sneaker = Sneaker.with(this)
        .setDuration(4000)
        .autoHide(true)

    val view = LayoutInflater.from(this)
        .inflate(R.layout.view_sneaker_error, sneaker.getView(), false)

    if (isGreen) {
        view.setBackgroundColor(resources.getColor(R.color.color_green, null))
    }
    view.findViewById<TextView>(R.id.error_message).text = errorMessage

    sneaker.sneakCustom(view)
}

In Activity, FrameLayout at higher hierarchy
In Activity of Fragment,

<merge
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:filterTouchesWhenObscured="true"
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <fragment
        android:id="@+id/nav_host_fragment"
        android:name="androidx.navigation.fragment.NavHostFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:defaultNavHost="true"
        app:navGraph="@navigation/navigation_rent"/>

</merge>

and in Fragment, XML has also FrameLayout at higher hierarchy

Activity Screenshot
Activity
Fragment Screenshot
Fragment

Error:Could not find com.android.tools.build:gradle:3.0.0-alpha1.

Error:Could not find com.android.tools.build:gradle:3.0.0-alpha1.
Searched in the following locations:
file:/Applications/Android Studio.app/Contents/gradle/m2repository/com/android/tools/build/gradle/3.0.0-alpha1/gradle-3.0.0-alpha1.pom
file:/Applications/Android Studio.app/Contents/gradle/m2repository/com/android/tools/build/gradle/3.0.0-alpha1/gradle-3.0.0-alpha1.jar
https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0-alpha1/gradle-3.0.0-alpha1.pom
https://jcenter.bintray.com/com/android/tools/build/gradle/3.0.0-alpha1/gradle-3.0.0-alpha1.jar
Required by:
project :

Enter Animation

While appearing the sneaker just appears without any sliding-in animation. Is there any method for it or is it not yet supported?

Updating/Refreshing Style

Would be awesome to see a updating/refreshing style for sneaker like you have done with the error and success. I'm happy to give it a go :)

Would essentially show a unhideable sneaker that allows a cancel when something has finished updating, it could then change colour to show a success (or cancel) and then hide again.

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.