-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5f640e5
commit fe4ade4
Showing
2 changed files
with
147 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2021 Anup Kumar Panwar | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
# ScratchView | ||
|
||
[](https://jitpack.io/#AnupKumarPanwar/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 | ||
|
||
```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 | ||
|
||
```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 | ||
-------- | ||
|
||
```xml | ||
<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. | ||
|
||
```gradle | ||
repositories { | ||
jcenter() | ||
maven { url "https://jitpack.io" } | ||
} | ||
dependencies { | ||
implementation 'com.github.AnupKumarPanwar:ScratchView:1.3' | ||
} | ||
``` | ||
|
||
Developed By | ||
------------ | ||
|
||
* Anup Kumar Panwar - <[email protected]> |