Code Monkey home page Code Monkey logo

scratchview's Introduction

ScratchView

This repo is build over https://github.com/sharish/ScratchView

Demo Screen

Methods

  • isRevealed() - tells whether the view has been revealed.
  • reveal() - reveals the view if not revealed yet.
  • mask() - masks the view again and removes the existing scratches.
  • setRevealListener(IRevealListener) - a callback listener interface which gets called back when user reveals the view through onReveal() method.

Usage

ScratchView acts as an overlay over other views. Scratching the view makes it transparent so that the views below it are visible. Wrap all the layers in a RelativeLayout and put ScratchView above it.

XML
<com.anupkumarpanwar.scratchview.ScratchView
  android:id="@+id/scratch_view"
  android:layout_width="300dp"
  android:layout_height="300dp"
  app:overlay_image="@drawable/scratch_card"
  app:tile_mode="CLAMP"
  app:overlay_width="300dp"
  app:overlay_height="300dp"
  />
JAVA
ScratchView scratchView = findViewById(R.id.scratch_view);
        scratchView.setRevealListener(new ScratchView.IRevealListener() {
            @Override
            public void onRevealed(ScratchView scratchView) {
                Toast.makeText(getApplicationContext(), "Reveled", Toast.LENGTH_LONG).show();;
            }

            @Override
            public void onRevealPercentChangedListener(ScratchView scratchView, float percent) {
                if (percent>=0.5) {
                    Log.d("Reveal Percentage", "onRevealPercentChangedListener: " + String.valueOf(percent));
                }
            }
        });

Example

<RelativeLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    tools:context=".MainActivity">

    <ImageView
        android:gravity="center"
        android:layout_width="300dp"
        android:layout_height="300dp"
        android:src="@drawable/anup"/>

    <com.anupkumarpanwar.scratchview.ScratchView
        android:id="@+id/scratch_view"
        android:layout_width="300dp"
        android:layout_height="300dp"
        app:overlay_image="@drawable/scratch_card"
        app:tile_mode="CLAMP"
        app:overlay_width="300dp"
        app:overlay_height="300dp"
        />

</RelativeLayout>

Attributes

Attribute Description Values
app:overlay_image The pattern or image to cover the view. @drawable/scratch_card
app:tile_mode https://developer.android.com/reference/android/graphics/Shader.TileMode CLAMP / MIRROR / REPEAT
app:overlay_width Width of the overlay pattern 300dp
app:overlay_height Height of the overlay pattern 300dp

Installation

  • Add the following configuration in your build.gradle file.
repositories {
    jcenter()
    maven { url "https://jitpack.io" }
}

dependencies {
    implementation 'com.github.AnupKumarPanwar:ScratchView:1.3'
}

Developed By

scratchview's People

Contributors

anupkumarpanwar 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.