|
| 1 | +# ScratchView |
| 2 | + |
| 3 | +[](https://jitpack.io/#AnupKumarPanwar/ScratchView) |
| 4 | + |
| 5 | + |
| 6 | +This repo is build over https://github.com/sharish/ScratchView |
| 7 | + |
| 8 | + |
| 9 | +Demo Screen |
| 10 | +------ |
| 11 | + |
| 12 | + |
| 13 | + |
| 14 | + |
| 15 | +### Methods |
| 16 | + |
| 17 | +* ```isRevealed()``` - tells whether the view has been revealed. |
| 18 | +* ```reveal()``` - reveals the view if not revealed yet. |
| 19 | +* ```mask()``` - masks the view again and removes the existing scratches. |
| 20 | +* ```setRevealListener(IRevealListener)``` - a callback listener interface which gets called back when user reveals the view |
| 21 | +through onReveal() method. |
| 22 | + |
| 23 | + |
| 24 | +Usage |
| 25 | +-------- |
| 26 | + |
| 27 | +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. |
| 28 | + |
| 29 | + |
| 30 | +##### XML |
| 31 | + |
| 32 | +```xml |
| 33 | +<com.anupkumarpanwar.scratchview.ScratchView |
| 34 | + android:id="@+id/scratch_view" |
| 35 | + android:layout_width="300dp" |
| 36 | + android:layout_height="300dp" |
| 37 | + app:overlay_image="@drawable/scratch_card" |
| 38 | + app:tile_mode="CLAMP" |
| 39 | + app:overlay_width="300dp" |
| 40 | + app:overlay_height="300dp" |
| 41 | + /> |
| 42 | + |
| 43 | +``` |
| 44 | + |
| 45 | +##### JAVA |
| 46 | + |
| 47 | +```java |
| 48 | +ScratchView scratchView = findViewById(R.id.scratch_view); |
| 49 | + scratchView.setRevealListener(new ScratchView.IRevealListener() { |
| 50 | + @Override |
| 51 | + public void onRevealed(ScratchView scratchView) { |
| 52 | + Toast.makeText(getApplicationContext(), "Reveled", Toast.LENGTH_LONG).show();; |
| 53 | + } |
| 54 | + |
| 55 | + @Override |
| 56 | + public void onRevealPercentChangedListener(ScratchView scratchView, float percent) { |
| 57 | + if (percent>=0.5) { |
| 58 | + Log.d("Reveal Percentage", "onRevealPercentChangedListener: " + String.valueOf(percent)); |
| 59 | + } |
| 60 | + } |
| 61 | + }); |
| 62 | +``` |
| 63 | + |
| 64 | + |
| 65 | +Example |
| 66 | +-------- |
| 67 | + |
| 68 | +```xml |
| 69 | +<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" |
| 70 | + xmlns:app="http://schemas.android.com/apk/res-auto" |
| 71 | + xmlns:tools="http://schemas.android.com/tools" |
| 72 | + android:layout_width="match_parent" |
| 73 | + android:layout_height="match_parent" |
| 74 | + android:gravity="center" |
| 75 | + tools:context=".MainActivity"> |
| 76 | + |
| 77 | + <ImageView |
| 78 | + android:gravity="center" |
| 79 | + android:layout_width="300dp" |
| 80 | + android:layout_height="300dp" |
| 81 | + android:src="@drawable/anup"/> |
| 82 | + |
| 83 | + <com.anupkumarpanwar.scratchview.ScratchView |
| 84 | + android:id="@+id/scratch_view" |
| 85 | + android:layout_width="300dp" |
| 86 | + android:layout_height="300dp" |
| 87 | + app:overlay_image="@drawable/scratch_card" |
| 88 | + app:tile_mode="CLAMP" |
| 89 | + app:overlay_width="300dp" |
| 90 | + app:overlay_height="300dp" |
| 91 | + /> |
| 92 | + |
| 93 | +</RelativeLayout> |
| 94 | + |
| 95 | +``` |
| 96 | + |
| 97 | +Attributes |
| 98 | +-------- |
| 99 | +| Attribute | Description | Values | |
| 100 | +| ---------------------------- | ----------------------------- | ----------------------------- | |
| 101 | +| `app:overlay_image` | The pattern or image to cover the view. | @drawable/scratch_card | |
| 102 | +| `app:tile_mode` | https://developer.android.com/reference/android/graphics/Shader.TileMode | CLAMP / MIRROR / REPEAT| |
| 103 | +| `app:overlay_width` | Width of the overlay pattern | 300dp | |
| 104 | +| `app:overlay_height` | Height of the overlay pattern | 300dp | |
| 105 | + |
| 106 | + |
| 107 | +Installation |
| 108 | +------------------------ |
| 109 | + |
| 110 | +- Add the following configuration in your build.gradle file. |
| 111 | + |
| 112 | +```gradle |
| 113 | +repositories { |
| 114 | + jcenter() |
| 115 | + maven { url "https://jitpack.io" } |
| 116 | +} |
| 117 | +
|
| 118 | +dependencies { |
| 119 | + implementation 'com.github.AnupKumarPanwar:ScratchView:1.3' |
| 120 | +} |
| 121 | +``` |
| 122 | + |
| 123 | +Developed By |
| 124 | +------------ |
| 125 | + |
| 126 | +* Anup Kumar Panwar - <[email protected]> |
0 commit comments