Code Monkey home page Code Monkey logo

scratchcardlayout's Introduction

ScratchCardLayout

License MinSDK Android Arsenal Download

A simple Android library for scratch card reveal kind of effect

Features:

  • Scratch card effect to ANY view.
  • Just wrap your existing complex Layout with ScratchCardLayout.
  • CardView based library. So All styling of CardView is available.
  • Set scratch brush width.
  • Enable/Disable scratching effect
  • Set Drawable to be scratched (color / image).
  • Set the percentage of scratch when you should be revealing full layout.
  • Get callbacks when scratching starts, progresses (with a percentage) and when stops..

Demonstration

Demo scratchCardLayout

Usage

Dependency:

dependencies {
     implementation 'in.codeshuffle.scratchcardlayout:ScratchCardLayout:1.0.8'
}

XML Usage

 <in.codeshuffle.scratchcardview.ui.ScratchCardLayout
        android:id="@+id/scratchCard"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:layout_centerInParent="true"
        app:scratchWidth="40dp"
        app:scratchEnabled="true"
        app:scratchDrawable="@drawable/your_drawable"
        app:scratchRevealFullAtPercent="100">

        <!--Your complex view here-->
 </in.codeshuffle.scratchcardview.ui.ScratchCardLayout>     

Java Usage

       //Get view reference
       ScratchCardLayout scratchCardLayout = findViewById(R.id.scratchCard);
       
       //Set the drawable (programmatically)
       scratchCardLayout.setScratchDrawable(getResources().getDrawable(R.drawable.car));
       
       //Set scratch brush width
       scratchCardLayout.setScratchWidth(30f);
       
       //Reveal full layout when some percent of the view is scratched
       scratchCardLayout.setRevealFullAtPercent(40);
       
       //Scratching enable/disable
       scratchCardLayout.setScratchEnabled(true);
       
       //Remove all scratch made till now
       scratchCardLayout.resetScratch();

       //Reveal scratch card (Shows the layout underneath the scratch)
       scratchCardLayout.revealScratch();

Listeners available

Implement the given interface and override these stuff:

          //Implement this to your class
          yourClass extends someBaseClass implements ScratchListener
          
          //Set the listener
          scratchCardLayout.setScratchListener(this);
            
          //You'll have three main callback methods as scratch listeners
          //Scratch started
          void onScratchStarted();
            
          //Scracth progress (NOTE: not guaranteed to be exact percent. consider it like atleast this much percent has been scratched)
          void onScratchProgress(ScratchCardLayout scratchCardLayout, int atLeastScratchedPercent);
            
          //Scratch completed
          void onScratchComplete();

PlayStore app

https://play.google.com/store/apps/details?id=in.codeshuffle.scratchcardlayoutexample

Note

- The progress is the value guaranteeing that the mentioned percent is atleast scratched. NOT THE EXACT PERCENTAGE (for performance reasaons)

License

 Copyright 2019 SkyManSandy

 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.

scratchcardlayout's People

Contributors

skymansandy avatar

Watchers

James Cloos avatar

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.