Thursday, May 10, 2012

Back again...

After a long break for studies, I have decided to come back to my blog for more advanced solutions. :-)

Sunday, March 13, 2011

Draw a Circle on screen with Canvas

First step is to create an activity which will display the CircleView on screen and then to create a class CircleView which will actually draw the circle on the screen.

Main Activity:
package com.android;

import android.app.Activity;
import android.os.Bundle;

public class NewCircle extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(new CircleView(this, 25, 25, 20));
}
}

Circle View Class:

package com.android;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.view.View;

public class CircleView extends View
{
// Variables
private final float x;
private final float y;
private final int r;
private final Paint mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

// Constructor
public CircleView(Context context, float x, float y, int r) {
super(context);
mPaint.setColor(0xFFFF0000);
this.x = x;
this.y = y;
this.r = r;
}

/ canvas onDraw Method for drawing a circle
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
canvas.drawCircle(x, y, r, mPaint);
}
}

Source 

Sunday, January 30, 2011

Android Icon Generator

Want to create icons for your Android Application?
Maybe a tab icon or a menu icon?
And dont want to use complicated tools like Photoshop?

Well, then you are at the right place for that link which will help you out in creating icons with the android looks.




 It is very simple and you can make use of Paint or any other simple image editing software.

Just remember the following steps:
  1. Create a monochrome image of your choice in any software.
  2. Black areas of the image will give you the android gradient and shadow looks.
  3. White areas of the image will become transparent.
  4. Save the image as a '.png' file.
  5. Upload it on the Android Icon Generator.
  6. Download the created icons of various resolutions.
(The different resolutions are used by the Android OS for handling the different resolutions of the devices. To know more about this topic click here.)

Now that you have got an idea about this online tool, here is the link:

On your marks...get set...go... 

My First Android Application - BMI Calculator

Hi,
This is my first blog post about my first android application. Its a Body Mass Index (BMI) calculator. It took me about 3 hours to design and complete this application. Given below are a couple of  screen shots and a method to calculate BMI.





Code for BMI:

public void calculate()
    {
     try
     {
     float bmi,height,weight;
     height=new Float(text1.getText().toString());
     weight=new Float(text2.getText().toString());
    
     bmi=weight/(height*height);
    
     tv1.setText("BMI: " + Float.toString(bmi));
     if (bmi<18.5)
     {
     tv2.setText("Result: Underweight");
     tv2.setTextColor(Color.RED);
     }
     else if(bmi>18.5 && bmi<24.9)
     {
     tv2.setText("Result: Healthy");
     tv2.setTextColor(Color.GREEN);
     }
     else if(bmi>25 && bmi<29.9)
     {
     tv2.setText("Result: Overweight");
     tv2.setTextColor(Color.MAGENTA);
     }
     else if(bmi>30 && bmi<34.9)
     {
     tv2.setText("Result: Obese");
     tv2.setTextColor(Color.MAGENTA);
     }
     else if(bmi>35 && bmi<39.9)
     {
     tv2.setText("Result: Severely Obese");
     tv2.setTextColor(Color.MAGENTA);
     }
     else 
     {
     tv2.setText("Result: Morbidly Obese");
     tv2.setTextColor(Color.MAGENTA);
     }
     }
     catch(Exception e)
     {
     finish();
     //Toast.makeText(Calculator.this, "Exception: "+e, Toast.LENGTH_LONG);
     }
    
    }