Skip to content

Commit 53570ac

Browse files
Scratch View
1 parent 242b19a commit 53570ac

File tree

5 files changed

+35
-565
lines changed

5 files changed

+35
-565
lines changed

app/src/main/java/com/anupkumarpanwar/scratchview/MainActivity.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,26 +8,27 @@
88

99
public class MainActivity extends AppCompatActivity {
1010

11-
ScratchImageView scratchImageView;
11+
ScratchView scratchView;
12+
boolean revealed = false;
1213

1314
@RequiresApi(api = Build.VERSION_CODES.KITKAT)
1415
@Override
1516
protected void onCreate(Bundle savedInstanceState) {
1617
super.onCreate(savedInstanceState);
1718
setContentView(R.layout.activity_main);
1819

19-
scratchImageView = findViewById(R.id.scratch_view);
20-
scratchImageView.setRevealListener(new ScratchImageView.IRevealListener() {
20+
scratchView = findViewById(R.id.scratch_view);
21+
scratchView.setRevealListener(new ScratchView.IRevealListener() {
2122
@Override
22-
public void onRevealed(ScratchImageView scratchImageView) {
23+
public void onRevealed(ScratchView scratchView) {
2324
Toast.makeText(getApplicationContext(), "Image reveled", Toast.LENGTH_LONG).show();;
2425
}
2526

2627
@Override
27-
public void onRevealPercentChangedListener(ScratchImageView scratchImageView, float percent) {
28-
if (percent>=0.5) {
29-
Toast.makeText(getApplicationContext(), "Image reveled", Toast.LENGTH_LONG).show();;
30-
scratchImageView.reveal();
28+
public void onRevealPercentChangedListener(ScratchView scratchView, float percent) {
29+
if (percent>=0.5 && ! revealed) {
30+
Toast.makeText(getApplicationContext(), "Revealed", Toast.LENGTH_LONG).show();;
31+
revealed = true;
3132
}
3233
}
3334
});

app/src/main/res/layout/activity_main.xml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,20 @@
77
android:gravity="center"
88
tools:context=".MainActivity">
99

10-
<TextView
10+
<ImageView
1111
android:gravity="center"
1212
android:layout_width="300dp"
1313
android:layout_height="300dp"
14-
android:text="Surprise"/>
14+
android:src="@drawable/anup"/>
1515

16-
<com.anupkumarpanwar.scratchview.ScratchImageView
16+
<com.anupkumarpanwar.scratchview.ScratchView
1717
android:id="@+id/scratch_view"
1818
android:layout_width="300dp"
1919
android:layout_height="300dp"
2020
app:overlay_image="@drawable/scratch_card"
2121
app:tile_mode="CLAMP"
2222
app:overlay_width="300dp"
2323
app:overlay_height="300dp"
24-
android:src="@drawable/anup"
2524
/>
2625

2726
</RelativeLayout>

0 commit comments

Comments
 (0)