From 62633143df47d80a1c1142aa82757478f41649ef Mon Sep 17 00:00:00 2001 From: naman14 Date: Sat, 29 Aug 2015 11:04:44 +0530 Subject: [PATCH] add comments in code --- .../com/naman14/washingmachineview/OverlayView.java | 9 +++++++++ .../washingmachineview/WashingMachineView.java | 11 ++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/com/naman14/washingmachineview/OverlayView.java b/app/src/main/java/com/naman14/washingmachineview/OverlayView.java index f8fda72..5b8ac98 100644 --- a/app/src/main/java/com/naman14/washingmachineview/OverlayView.java +++ b/app/src/main/java/com/naman14/washingmachineview/OverlayView.java @@ -24,7 +24,9 @@ public class OverlayView extends View { private Paint p = new Paint(); private Paint transparentPaint; + //the radius of the hole from where water waves are visible private int holeradius; + private int mMachineColor; public OverlayView(Context context, AttributeSet attrs) { @@ -46,17 +48,24 @@ protected void onDraw(Canvas canvas) { temp = new Canvas(bitmapx); paint = new Paint(); paint.setColor(mMachineColor); + + //paint for creating a hole in view transparentPaint = new Paint(); transparentPaint.setColor(getResources().getColor(android.R.color.transparent)); transparentPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); + //draw machine color background temp.drawRect(0, 0, getWidth(), getHeight(), paint); + + //draw trasparent hole temp.drawCircle(getWidth() / 2, getHeight() / 2, holeradius, transparentPaint); canvas.drawBitmap(bitmapx, 0, 0, p); + //draw single dot in the view at top/left paint.setColor(Color.WHITE); canvas.drawCircle(getDimensionInPixel(25), getDimensionInPixel(25), getDimensionInPixel(5), paint); + //draw the ring around the hole Paint ringPaint = new Paint(Paint.ANTI_ALIAS_FLAG); ringPaint.setStyle(Paint.Style.STROKE); ringPaint.setColor(Color.WHITE); diff --git a/app/src/main/java/com/naman14/washingmachineview/WashingMachineView.java b/app/src/main/java/com/naman14/washingmachineview/WashingMachineView.java index c8f9c0d..c4d56ce 100644 --- a/app/src/main/java/com/naman14/washingmachineview/WashingMachineView.java +++ b/app/src/main/java/com/naman14/washingmachineview/WashingMachineView.java @@ -19,6 +19,8 @@ */ public class WashingMachineView extends LinearLayout { + //linear layout consisting of three views-topview,machineview and bottomview + private int mTopviewHeight; private int mMiddleviewHeight; private int mBottomviewHeight; @@ -36,6 +38,7 @@ public WashingMachineView(Context context, AttributeSet attrs) { setOrientation(VERTICAL); + //add the views addView(new TopView(context, attrs)); addView(new MachineView(context, attrs)); addView(new BottomView(context, attrs)); @@ -59,18 +62,21 @@ public TopView(Context context, AttributeSet attrs) { protected void onDraw(Canvas canvas) { super.onDraw(canvas); + //background of topview Rect rectBackground = new Rect(0, 0, getWidth(), getHeight()); paint.setColor(mMachineColor); paint.setStyle(Paint.Style.FILL); paint.setAntiAlias(true); canvas.drawRect(rectBackground, paint); + //the rectangular strip on topview Rect rectWhite = new Rect(getDimensionInPixel(20), getHeight() / 2 - getDimensionInPixel(4), getDimensionInPixel(60), getHeight() / 2 + getDimensionInPixel(4)); paint.setColor(Color.WHITE); paint.setStyle(Paint.Style.FILL); paint.setAntiAlias(true); canvas.drawRect(rectWhite, paint); + //three dots at the end of topview canvas.drawCircle(getWidth() - getDimensionInPixel(80), getHeight() / 2, getDimensionInPixel(6), paint); canvas.drawCircle(getWidth() - getDimensionInPixel(55), getHeight() / 2, getDimensionInPixel(6), paint); canvas.drawCircle(getWidth() - getDimensionInPixel(30), getHeight() / 2, getDimensionInPixel(4), paint); @@ -103,8 +109,10 @@ protected void onDraw(Canvas canvas) { } } - public class MachineView extends FrameLayout { + //machineview(middle view) extends FrameLayout and has two views-WaterWave and Overlay. + //Overlay consists of a transparent hole from which water waves are visible + public class MachineView extends FrameLayout { public MachineView(Context context, AttributeSet attrs) { super(context, attrs); @@ -118,6 +126,7 @@ public MachineView(Context context, AttributeSet attrs) { } + //get all dimensions in dp so that views behaves properly on different screen resolutions private int getDimensionInPixel(int dp){ return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, getResources().getDisplayMetrics()); }