Skip to content

Commit

Permalink
add comments in code
Browse files Browse the repository at this point in the history
  • Loading branch information
naman14 committed Aug 29, 2015
1 parent c08fd77 commit 6263314
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Expand Up @@ -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) {
Expand All @@ -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);
Expand Down
Expand Up @@ -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;
Expand All @@ -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));
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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());
}
Expand Down

0 comments on commit 6263314

Please sign in to comment.