Skip to content

Instantly share code, notes, and snippets.

View robillo's full-sized avatar
😌
Constantly evolving..

Robin Kamboj robillo

😌
Constantly evolving..
View GitHub Profile
@robillo
robillo / MyCustomView.java
Created August 6, 2017 18:06
MyCustomView class extending View class, with constructor matching super
package com.robillo.customviewstutorial;
import android.content.Context;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
import android.util.AttributeSet;
import android.view.View;
/**
@robillo
robillo / MyCustomView.java
Created August 6, 2017 18:34
Basic rect shape drawn on canvas.
package com.robillo.customviewstutorial;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Build;
import android.support.annotation.Nullable;
import android.support.annotation.RequiresApi;
@robillo
robillo / activity_main.xml
Created August 6, 2017 18:36
Rect custom view
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="com.robillo.customviewstutorial.MainActivity">
<com.robillo.customviewstutorial.MyCustomView
@robillo
robillo / attrs.xml
Created August 7, 2017 18:10
attrs.xml
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MyCustomView">
<attr name="color" format="color"/>
</declare-styleable>
</resources>
@robillo
robillo / attrs.xml
Created August 8, 2017 16:38
attrs
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="MyCustomView">
<attr name="square_color" format="color"/>
</declare-styleable>
</resources>
@robillo
robillo / MyCustomView.java
Created August 8, 2017 17:03
mcv custom attribute
package com.robillo.customviewstutorial;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Build;
import android.support.annotation.Nullable;
@robillo
robillo / activity_main.xml
Created August 8, 2017 17:08
activity_main
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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="com.robillo.customviewstutorial.MainActivity">
<com.robillo.customviewstutorial.MyCustomView
@robillo
robillo / activity_main.xml
Created August 11, 2017 18:55
activity main
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:orientation="vertical"
tools:context="com.robillo.customviewstutorial.MainActivity">
@robillo
robillo / MyCustomView.java
Created August 11, 2017 19:14
my custom view
package com.robillo.customviewstutorial;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Rect;
import android.os.Build;
import android.support.annotation.Nullable;
@robillo
robillo / MainActivity.java
Created August 11, 2017 19:15
main activity
package com.robillo.customviewstutorial;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
public class MainActivity extends AppCompatActivity {
MyCustomView myCustomView;