diff --git a/android-L-preview/AndroidManifest.xml b/android-L-preview/AndroidManifest.xml new file mode 100644 index 00000000..08eafe5f --- /dev/null +++ b/android-L-preview/AndroidManifest.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + diff --git a/android-L-preview/proguard-project.txt b/android-L-preview/proguard-project.txt new file mode 100644 index 00000000..f2fe1559 --- /dev/null +++ b/android-L-preview/proguard-project.txt @@ -0,0 +1,20 @@ +# To enable ProGuard in your project, edit project.properties +# to define the proguard.config property as described in that file. +# +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in ${sdk.dir}/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the ProGuard +# include property in project.properties. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} diff --git a/android-L-preview/res/layout/activity_main.xml b/android-L-preview/res/layout/activity_main.xml new file mode 100644 index 00000000..50fe8d03 --- /dev/null +++ b/android-L-preview/res/layout/activity_main.xml @@ -0,0 +1,12 @@ + + + + + diff --git a/android-L-preview/res/values/strings.xml b/android-L-preview/res/values/strings.xml new file mode 100644 index 00000000..7d70ec05 --- /dev/null +++ b/android-L-preview/res/values/strings.xml @@ -0,0 +1,8 @@ + + + + L Preview + MainActivity + Hello world! + + diff --git a/android-L-preview/res/values/styles.xml b/android-L-preview/res/values/styles.xml new file mode 100644 index 00000000..1192db20 --- /dev/null +++ b/android-L-preview/res/values/styles.xml @@ -0,0 +1,4 @@ + + + diff --git a/android-L-preview/src/com/hmkcode/android/L/MainActivity.java b/android-L-preview/src/com/hmkcode/android/L/MainActivity.java new file mode 100644 index 00000000..95510ec1 --- /dev/null +++ b/android-L-preview/src/com/hmkcode/android/L/MainActivity.java @@ -0,0 +1,14 @@ +package com.hmkcode.android.L; + +import android.app.Activity; +import android.os.Bundle; + + +public class MainActivity extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + } +} diff --git a/android-canvas-donut-chart/AndroidManifest.xml b/android-canvas-donut-chart/AndroidManifest.xml new file mode 100644 index 00000000..d363509e --- /dev/null +++ b/android-canvas-donut-chart/AndroidManifest.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + diff --git a/android-canvas-donut-chart/res/layout/activity_main.xml b/android-canvas-donut-chart/res/layout/activity_main.xml new file mode 100644 index 00000000..8a523745 --- /dev/null +++ b/android-canvas-donut-chart/res/layout/activity_main.xml @@ -0,0 +1,21 @@ + + + + + diff --git a/android-canvas-donut-chart/res/values/attrs.xml b/android-canvas-donut-chart/res/values/attrs.xml new file mode 100644 index 00000000..485e118d --- /dev/null +++ b/android-canvas-donut-chart/res/values/attrs.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/android-post-json/res/values/dimens.xml b/android-canvas-donut-chart/res/values/dimens.xml similarity index 100% rename from android-post-json/res/values/dimens.xml rename to android-canvas-donut-chart/res/values/dimens.xml diff --git a/android-canvas-donut-chart/res/values/strings.xml b/android-canvas-donut-chart/res/values/strings.xml new file mode 100644 index 00000000..004653b7 --- /dev/null +++ b/android-canvas-donut-chart/res/values/strings.xml @@ -0,0 +1,8 @@ + + + + Donut Chart + Hello world! + Settings + + diff --git a/android-canvas-donut-chart/res/values/styles.xml b/android-canvas-donut-chart/res/values/styles.xml new file mode 100644 index 00000000..845fb572 --- /dev/null +++ b/android-canvas-donut-chart/res/values/styles.xml @@ -0,0 +1,20 @@ + + + + + + + + + diff --git a/android-canvas-donut-chart/src/com/hmkcode/views/DonutChart.java b/android-canvas-donut-chart/src/com/hmkcode/views/DonutChart.java new file mode 100644 index 00000000..42e851d0 --- /dev/null +++ b/android-canvas-donut-chart/src/com/hmkcode/views/DonutChart.java @@ -0,0 +1,168 @@ +package com.hmkcode.views; + + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.BlurMaskFilter; +import android.graphics.Canvas; + +import android.graphics.Paint; +import android.graphics.Path; +import android.graphics.RadialGradient; +import android.graphics.RectF; +import android.graphics.Shader.TileMode; +import android.util.AttributeSet; +import android.view.View; + +public class DonutChart extends View { + + + private float radius; + + Paint paint; + Paint shadowPaint; + + Path myPath; + Path shadowPath; + + RectF outterCircle; + RectF innerCircle; + RectF shadowRectF; + + public DonutChart(Context context, AttributeSet attrs) { + super(context, attrs); + + TypedArray a = context.getTheme().obtainStyledAttributes( + attrs, + R.styleable.DonutChart, + 0, 0 + ); + + try { + radius = a.getDimension(R.styleable.DonutChart_radius, 20.0f); + } finally { + a.recycle(); + } + + paint = new Paint(); + paint.setDither(true); + paint.setStyle(Paint.Style.FILL); + paint.setStrokeJoin(Paint.Join.ROUND); + paint.setStrokeCap(Paint.Cap.ROUND); + paint.setAntiAlias(true); + paint.setStrokeWidth(radius / 14.0f); + + shadowPaint = new Paint(); + shadowPaint.setColor(0xf0000000); + shadowPaint.setStyle(Paint.Style.STROKE); + shadowPaint.setAntiAlias(true); + shadowPaint.setStrokeWidth(6.0f); + shadowPaint.setMaskFilter(new BlurMaskFilter(4, BlurMaskFilter.Blur.SOLID)); + + + myPath = new Path(); + shadowPath = new Path(); + + + outterCircle = new RectF(); + innerCircle = new RectF(); + shadowRectF = new RectF(); + + float adjust = (.019f*radius); + shadowRectF.set(adjust, adjust, radius*2-adjust, radius*2-adjust); + + adjust = .038f * radius; + outterCircle.set(adjust, adjust, radius*2-adjust, radius*2-adjust); + + adjust = .276f * radius; + innerCircle.set(adjust, adjust, radius*2-adjust, radius*2-adjust); + + } + + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + + // draw shadow + paint.setShader(null); + float adjust = (.0095f*radius); + paint.setShadowLayer(8, adjust, -adjust, 0xaa000000); + drawDonut(canvas,paint, 0,359.9f); + + + // green + setGradient(0xff84BC3D,0xff5B8829); + drawDonut(canvas,paint, 0,60); + + //red + setGradient(0xffe04a2f,0xffB7161B); + drawDonut(canvas,paint, 60,60); + + // blue + setGradient(0xff4AB6C1,0xff2182AD); + drawDonut(canvas,paint, 120,60); + + // yellow + setGradient(0xffFFFF00,0xfffed325); + drawDonut(canvas,paint, 180,180); + + + + } + + public void drawDonut(Canvas canvas, Paint paint, float start,float sweep){ + + myPath.reset(); + myPath.arcTo(outterCircle, start, sweep, false); + myPath.arcTo(innerCircle, start+sweep, -sweep, false); + myPath.close(); + canvas.drawPath(myPath, paint); + } + + public void setGradient(int sColor, int eColor){ + paint.setShader(new RadialGradient(radius, radius, radius-5, + new int[]{sColor,eColor}, + new float[]{.6f,.95f},TileMode.CLAMP) ); + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + + int desiredWidth = (int) radius*2; + int desiredHeight = (int) radius*2; + + int widthMode = MeasureSpec.getMode(widthMeasureSpec); + int widthSize = MeasureSpec.getSize(widthMeasureSpec); + int heightMode = MeasureSpec.getMode(heightMeasureSpec); + int heightSize = MeasureSpec.getSize(heightMeasureSpec); + + int width; + int height; + + //70dp exact + if (widthMode == MeasureSpec.EXACTLY) { + width = widthSize; + }else if (widthMode == MeasureSpec.AT_MOST) { + //wrap content + width = Math.min(desiredWidth, widthSize); + } else { + width = desiredWidth; + } + + //Measure Height + if (heightMode == MeasureSpec.EXACTLY) { + height = heightSize; + } else if (heightMode == MeasureSpec.AT_MOST) { + height = Math.min(desiredHeight, heightSize); + } else { + height = desiredHeight; + } + + //MUST CALL THIS + setMeasuredDimension(width, height); + } + + +} diff --git a/android-canvas-donut-chart/src/com/hmkcode/views/MainActivity.java b/android-canvas-donut-chart/src/com/hmkcode/views/MainActivity.java new file mode 100644 index 00000000..58b95bbd --- /dev/null +++ b/android-canvas-donut-chart/src/com/hmkcode/views/MainActivity.java @@ -0,0 +1,14 @@ +package com.hmkcode.views; + +import android.app.Activity; +import android.os.Bundle; + + +public class MainActivity extends Activity { + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + } +} diff --git a/android-connectivity/app/build.gradle b/android-connectivity/app/build.gradle new file mode 100644 index 00000000..0afafcf6 --- /dev/null +++ b/android-connectivity/app/build.gradle @@ -0,0 +1,40 @@ +apply plugin: 'com.android.application' + +apply plugin: 'kotlin-android' + +apply plugin: 'kotlin-android-extensions' + +android { + compileSdkVersion 28 + buildToolsVersion "29.0.2" + defaultConfig { + applicationId "com.hmkcode.connectivity" + minSdkVersion 19 + targetSdkVersion 28 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: 'libs', include: ['*.jar']) + implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version" + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.core:core-ktx:1.1.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + // Coroutine + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.2" + implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.2" + implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.2.0-alpha05" + + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1' +} diff --git a/android-connectivity/app/src/main/AndroidManifest.xml b/android-connectivity/app/src/main/AndroidManifest.xml new file mode 100644 index 00000000..16ef209d --- /dev/null +++ b/android-connectivity/app/src/main/AndroidManifest.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/android-connectivity/app/src/main/java/com/hmkcode/connectivity/MainActivity.kt b/android-connectivity/app/src/main/java/com/hmkcode/connectivity/MainActivity.kt new file mode 100644 index 00000000..a58dcc66 --- /dev/null +++ b/android-connectivity/app/src/main/java/com/hmkcode/connectivity/MainActivity.kt @@ -0,0 +1,74 @@ +package com.hmkcode.connectivity + +import android.content.Context +import android.net.ConnectivityManager +import android.net.Network +import android.net.NetworkCapabilities +import android.net.NetworkRequest +import android.os.Build +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.util.Log +import android.widget.TextView +import androidx.lifecycle.lifecycleScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.launch +import kotlinx.coroutines.withContext + +class MainActivity : AppCompatActivity() { + + lateinit var tvConnectivity: TextView + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + tvConnectivity = findViewById(R.id.tvConnectivity) + + // get ConnectivityManager + val cm:ConnectivityManager = + getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + val builder: NetworkRequest.Builder = NetworkRequest.Builder() + cm.registerNetworkCallback( + + builder.build(), + object : ConnectivityManager.NetworkCallback() { + + override fun onAvailable(network: Network) { + lifecycleScope.launch { + Log.i("MainActivity", "onAvailable!") + + // check if NetworkCapabilities has TRANSPORT_WIFI + val isWifi:Boolean = cm.getNetworkCapabilities(network).hasTransport( + NetworkCapabilities.TRANSPORT_WIFI) + + doSomething(true, isWifi) + } + } + + override fun onLost(network: Network) { + lifecycleScope.launch { + Log.i("MainActivity", "onLost!") + doSomething(false) + } + } + } + ) + } + + } + + private suspend fun doSomething(isConnected:Boolean, isWifi:Boolean= false){ + withContext(Dispatchers.Main){ + if(isConnected) { + tvConnectivity.text = "Connected "+(if(isWifi)"WIFI" else "MOBILE") + tvConnectivity.setBackgroundColor(-0x8333da) + }else { + tvConnectivity.text = "Not Connected" + tvConnectivity.setBackgroundColor(-0x10000) + } + } + } +} diff --git a/android-connectivity/app/src/main/res/drawable/ic_launcher_background.xml b/android-connectivity/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 00000000..0d025f9b --- /dev/null +++ b/android-connectivity/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android-connectivity/app/src/main/res/layout/activity_main.xml b/android-connectivity/app/src/main/res/layout/activity_main.xml new file mode 100644 index 00000000..5acf0117 --- /dev/null +++ b/android-connectivity/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,23 @@ + + + + + + \ No newline at end of file diff --git a/android-connectivity/app/src/main/res/values/colors.xml b/android-connectivity/app/src/main/res/values/colors.xml new file mode 100644 index 00000000..69b22338 --- /dev/null +++ b/android-connectivity/app/src/main/res/values/colors.xml @@ -0,0 +1,6 @@ + + + #008577 + #00574B + #D81B60 + diff --git a/android-connectivity/app/src/main/res/values/strings.xml b/android-connectivity/app/src/main/res/values/strings.xml new file mode 100644 index 00000000..5bc6865a --- /dev/null +++ b/android-connectivity/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + connectivity + diff --git a/android-connectivity/app/src/main/res/values/styles.xml b/android-connectivity/app/src/main/res/values/styles.xml new file mode 100644 index 00000000..5885930d --- /dev/null +++ b/android-connectivity/app/src/main/res/values/styles.xml @@ -0,0 +1,11 @@ + + + + + + diff --git a/android-connectivity/build.gradle b/android-connectivity/build.gradle new file mode 100644 index 00000000..e3245e7f --- /dev/null +++ b/android-connectivity/build.gradle @@ -0,0 +1,28 @@ +// Top-level build file where you can add configuration options common to all sub-projects/modules. + +buildscript { + ext.kotlin_version = '1.3.50' + repositories { + google() + jcenter() + + } + dependencies { + classpath 'com.android.tools.build:gradle:3.5.1' + classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + // NOTE: Do not place your application dependencies here; they belong + // in the individual module build.gradle files + } +} + +allprojects { + repositories { + google() + jcenter() + + } +} + +task clean(type: Delete) { + delete rootProject.buildDir +} diff --git a/android-custom-view/AndroidManifest.xml b/android-custom-view/AndroidManifest.xml new file mode 100644 index 00000000..d363509e --- /dev/null +++ b/android-custom-view/AndroidManifest.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + diff --git a/android-custom-view/res/layout/activity_main.xml b/android-custom-view/res/layout/activity_main.xml new file mode 100644 index 00000000..33440667 --- /dev/null +++ b/android-custom-view/res/layout/activity_main.xml @@ -0,0 +1,38 @@ + + + + + + + + diff --git a/android-custom-view/res/values/attrs.xml b/android-custom-view/res/values/attrs.xml new file mode 100644 index 00000000..a97caa47 --- /dev/null +++ b/android-custom-view/res/values/attrs.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/android-custom-view/res/values/dimens.xml b/android-custom-view/res/values/dimens.xml new file mode 100644 index 00000000..55c1e590 --- /dev/null +++ b/android-custom-view/res/values/dimens.xml @@ -0,0 +1,7 @@ + + + + 16dp + 16dp + + diff --git a/android-custom-view/res/values/strings.xml b/android-custom-view/res/values/strings.xml new file mode 100644 index 00000000..eed0eaf9 --- /dev/null +++ b/android-custom-view/res/values/strings.xml @@ -0,0 +1,8 @@ + + + + Simple Custom View + Hello world! + Settings + + diff --git a/android-custom-view/res/values/styles.xml b/android-custom-view/res/values/styles.xml new file mode 100644 index 00000000..845fb572 --- /dev/null +++ b/android-custom-view/res/values/styles.xml @@ -0,0 +1,20 @@ + + + + + + + + + diff --git a/android-custom-view/src/com/hmkcode/views/MainActivity.java b/android-custom-view/src/com/hmkcode/views/MainActivity.java new file mode 100644 index 00000000..f0b152f6 --- /dev/null +++ b/android-custom-view/src/com/hmkcode/views/MainActivity.java @@ -0,0 +1,48 @@ +package com.hmkcode.views; + +import android.app.Activity; +import android.os.Bundle; +import android.view.View; +import android.view.View.OnClickListener; +import android.widget.TextView; + + +public class MainActivity extends Activity implements OnClickListener { + + SimpleView svCircle; + SimpleView svSquare; + TextView tv; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + svCircle = (SimpleView) findViewById(R.id.simpleViewCircle); + svSquare = (SimpleView) findViewById(R.id.simpleViewSquare); + tv = (TextView) findViewById(R.id.tv); + + svCircle.setOnClickListener(this); + svSquare.setOnClickListener(this); + + } + + + @Override + public void onClick(View view) { + + switch(view.getId()){ + case R.id.simpleViewCircle: + tv.setText("Circle"); + break; + case R.id.simpleViewSquare: + tv.setText("Square"); + break; + + } + + } + + + +} diff --git a/android-custom-view/src/com/hmkcode/views/SimpleView.java b/android-custom-view/src/com/hmkcode/views/SimpleView.java new file mode 100644 index 00000000..121f690d --- /dev/null +++ b/android-custom-view/src/com/hmkcode/views/SimpleView.java @@ -0,0 +1,57 @@ +package com.hmkcode.views; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.graphics.CornerPathEffect; +import android.graphics.Paint; +import android.util.AttributeSet; +import android.view.View; + +public class SimpleView extends View { + + float dim; + int shape; + Paint paint; + + public static final int CIRCLE = 0; + public static final int SQUARE = 1; + public SimpleView(Context context, AttributeSet attrs) { + super(context, attrs); + + TypedArray a = context.getTheme().obtainStyledAttributes( + attrs, + R.styleable.SimpleView, + 0, 0 + ); + + try { + dim = a.getDimension(R.styleable.SimpleView_dim, 20f); + shape = a.getInteger(R.styleable.SimpleView_shape, 0); + } finally { + a.recycle(); + } + + paint = new Paint(); + paint.setColor(0xfffed325); // yellow + } + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + + // draw circle + switch(shape){ + case CIRCLE: + canvas.drawCircle(dim, dim, dim, paint); + break; + case SQUARE: + canvas.drawRect(0, 0, dim, dim, paint); + break; + + } + + } + + +} diff --git a/android-draw-happy-face/AndroidManifest.xml b/android-draw-happy-face/AndroidManifest.xml new file mode 100644 index 00000000..e8106618 --- /dev/null +++ b/android-draw-happy-face/AndroidManifest.xml @@ -0,0 +1,28 @@ + + + + + + e + + + + + + + + + + diff --git a/android-post-json/res/drawable-hdpi/ic_launcher.png b/android-draw-happy-face/res/drawable-hdpi/ic_launcher.png similarity index 100% rename from android-post-json/res/drawable-hdpi/ic_launcher.png rename to android-draw-happy-face/res/drawable-hdpi/ic_launcher.png diff --git a/android-draw-happy-face/res/drawable-hdpi/woodgraybg.jpg b/android-draw-happy-face/res/drawable-hdpi/woodgraybg.jpg new file mode 100644 index 00000000..54ebe7df Binary files /dev/null and b/android-draw-happy-face/res/drawable-hdpi/woodgraybg.jpg differ diff --git a/android-draw-happy-face/res/layout/activity_main.xml b/android-draw-happy-face/res/layout/activity_main.xml new file mode 100644 index 00000000..f3ae3687 --- /dev/null +++ b/android-draw-happy-face/res/layout/activity_main.xml @@ -0,0 +1,26 @@ + + + + + diff --git a/android-draw-happy-face/res/values/attrs.xml b/android-draw-happy-face/res/values/attrs.xml new file mode 100644 index 00000000..d2383bfe --- /dev/null +++ b/android-draw-happy-face/res/values/attrs.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/android-draw-happy-face/res/values/dimens.xml b/android-draw-happy-face/res/values/dimens.xml new file mode 100644 index 00000000..55c1e590 --- /dev/null +++ b/android-draw-happy-face/res/values/dimens.xml @@ -0,0 +1,7 @@ + + + + 16dp + 16dp + + diff --git a/android-post-json/res/values/strings.xml b/android-draw-happy-face/res/values/strings.xml similarity index 78% rename from android-post-json/res/values/strings.xml rename to android-draw-happy-face/res/values/strings.xml index 2a387699..81bedf03 100644 --- a/android-post-json/res/values/strings.xml +++ b/android-draw-happy-face/res/values/strings.xml @@ -1,8 +1,8 @@ - POST JSON - Settings + DrawFace Hello world! + Settings diff --git a/android-draw-happy-face/res/values/styles.xml b/android-draw-happy-face/res/values/styles.xml new file mode 100644 index 00000000..845fb572 --- /dev/null +++ b/android-draw-happy-face/res/values/styles.xml @@ -0,0 +1,20 @@ + + + + + + + + + diff --git a/android-draw-happy-face/src/com/hmkcode/drawing/FaceView.java b/android-draw-happy-face/src/com/hmkcode/drawing/FaceView.java new file mode 100644 index 00000000..e6a71654 --- /dev/null +++ b/android-draw-happy-face/src/com/hmkcode/drawing/FaceView.java @@ -0,0 +1,97 @@ +package com.hmkcode.drawing; + + +import com.hmkcode.drawing.shapes.Face; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.util.AttributeSet; +import android.util.Log; +import android.view.View; + +public class FaceView extends View { + private float radius; + Face face; + public FaceView(Context context, AttributeSet attrs) { + super(context, attrs); + + // get radius value + TypedArray a = context.getTheme().obtainStyledAttributes( + attrs, + R.styleable.FaceView, + 0, 0 + ); + + try { + radius = a.getDimension(R.styleable.FaceView_radius, 20.0f); + } finally { + a.recycle(); + } + + // initiate Face class + face = new Face(radius); + } + + + @Override + protected void onDraw(Canvas canvas) { + super.onDraw(canvas); + face.draw(canvas); + + } + + @Override + protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { + super.onMeasure(widthMeasureSpec, heightMeasureSpec); + + int desiredWidth = (int) radius*2+(int) Math.ceil((radius/1.70)); + int desiredHeight = (int) radius*2+(int)Math.ceil((radius/1.70)); + + int widthMode = MeasureSpec.getMode(widthMeasureSpec); + int widthSize = MeasureSpec.getSize(widthMeasureSpec); + int heightMode = MeasureSpec.getMode(heightMeasureSpec); + int heightSize = MeasureSpec.getSize(heightMeasureSpec); + + int width; + int height; + + //Measure Width + if (widthMode == MeasureSpec.EXACTLY) { + //Must be this size + width = widthSize; + } else if (widthMode == MeasureSpec.AT_MOST) { + //Can't be bigger than... + width = Math.min(desiredWidth, widthSize); + Log.d("Width AT_MOST", "width: "+width); + } else { + //Be whatever you want + width = desiredWidth; + Log.d("Width ELSE", "width: "+width); + + } + + //Measure Height + if (heightMode == MeasureSpec.EXACTLY) { + //Must be this size + height = heightSize; + } else if (heightMode == MeasureSpec.AT_MOST) { + //Can't be bigger than... + height = Math.min(desiredHeight, heightSize); + } else { + //Be whatever you want + height = desiredHeight; + } + + //MUST CALL THIS + setMeasuredDimension(width, height); + } + public float getRadius() { + return radius; + } + + public void setRadius(float radius) { + this.radius = radius; + } + +} diff --git a/android-draw-happy-face/src/com/hmkcode/drawing/MainActivity.java b/android-draw-happy-face/src/com/hmkcode/drawing/MainActivity.java new file mode 100644 index 00000000..818f6bd2 --- /dev/null +++ b/android-draw-happy-face/src/com/hmkcode/drawing/MainActivity.java @@ -0,0 +1,13 @@ +package com.hmkcode.drawing; + + +import android.app.Activity; + +public class MainActivity extends Activity { + + protected void onCreate(android.os.Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + } + +} diff --git a/android-draw-happy-face/src/com/hmkcode/drawing/shapes/Face.java b/android-draw-happy-face/src/com/hmkcode/drawing/shapes/Face.java new file mode 100644 index 00000000..06ae5dd1 --- /dev/null +++ b/android-draw-happy-face/src/com/hmkcode/drawing/shapes/Face.java @@ -0,0 +1,96 @@ +package com.hmkcode.drawing.shapes; + +import android.graphics.Canvas; +import android.graphics.CornerPathEffect; +import android.graphics.Paint; +import android.graphics.Path; +import android.graphics.RectF; + +public class Face { + + Paint facePaint; + Paint mePaint; + + + float radius; + float adjust; + + float mouthLeftX, mouthRightX, mouthTopY, mouthBottomY; + RectF mouthRectF; + Path mouthPath; + + RectF eyeLeftRectF, eyeRightRectF; + float eyeLeftX, eyeRightx, eyeTopY, eyeBottomY; + + + public Face(float radius){ + this.radius= radius; + + facePaint = new Paint(); + facePaint.setColor(0xfffed325); // yellow + facePaint.setDither(true); + facePaint.setStrokeJoin(Paint.Join.ROUND); + facePaint.setStrokeCap(Paint.Cap.ROUND); + facePaint.setPathEffect(new CornerPathEffect(10) ); + facePaint.setAntiAlias(true); + facePaint.setShadowLayer(4, 2, 2, 0x80000000); + + mePaint = new Paint(); + mePaint.setColor(0xff2a2a2a); + mePaint.setDither(true); + mePaint.setStyle(Paint.Style.STROKE); + mePaint.setStrokeJoin(Paint.Join.ROUND); + mePaint.setStrokeCap(Paint.Cap.ROUND); + mePaint.setPathEffect(new CornerPathEffect(10) ); + mePaint.setAntiAlias(true); + mePaint.setStrokeWidth(radius / 14.0f); + + + + adjust = radius / 3.2f; + + + // Left Eye + eyeLeftX = radius-(radius*0.43f); + eyeRightx = eyeLeftX+ (radius*0.3f); + eyeTopY = radius-(radius*0.5f); + eyeBottomY = eyeTopY + (radius*0.4f); + + eyeLeftRectF = new RectF(eyeLeftX+adjust,eyeTopY+adjust,eyeRightx+adjust,eyeBottomY+adjust); + + // Right Eye + eyeLeftX = eyeRightx + (radius*0.3f); + eyeRightx = eyeLeftX + (radius*0.3f); + + eyeRightRectF = new RectF(eyeLeftX+adjust,eyeTopY+adjust,eyeRightx+adjust,eyeBottomY+adjust); + + + // Smiley Mouth + mouthLeftX = radius-(radius/2.0f); + mouthRightX = mouthLeftX+ radius; + mouthTopY = radius - (radius*0.2f); + mouthBottomY = mouthTopY + (radius*0.5f); + + mouthRectF = new RectF(mouthLeftX+adjust,mouthTopY+adjust,mouthRightX+adjust,mouthBottomY+adjust); + mouthPath = new Path(); + + mouthPath.arcTo(mouthRectF, 30, 120, true); + } + + public void draw(Canvas canvas) { + + // 1. draw face + canvas.drawCircle(radius+adjust, radius+adjust, radius, facePaint); + + // 2. draw mouth + mePaint.setStyle(Paint.Style.STROKE); + + canvas.drawPath(mouthPath, mePaint); + + // 3. draw eyes + mePaint.setStyle(Paint.Style.FILL); + canvas.drawArc(eyeLeftRectF, 0, 360, true, mePaint); + canvas.drawArc(eyeRightRectF, 0, 360, true, mePaint); + + } +} diff --git a/android-gcm-client/AndroidManifest.xml b/android-gcm-client/AndroidManifest.xml new file mode 100644 index 00000000..2cd7401f --- /dev/null +++ b/android-gcm-client/AndroidManifest.xml @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/android-gcm-client/res/drawable-hdpi/ic_launcher.png b/android-gcm-client/res/drawable-hdpi/ic_launcher.png new file mode 100644 index 00000000..288b6655 Binary files /dev/null and b/android-gcm-client/res/drawable-hdpi/ic_launcher.png differ diff --git a/android-gcm-client/res/layout/activity_main.xml b/android-gcm-client/res/layout/activity_main.xml new file mode 100644 index 00000000..07bda309 --- /dev/null +++ b/android-gcm-client/res/layout/activity_main.xml @@ -0,0 +1,19 @@ + + +