Archive for April, 2012

How to program a simple andriod application that converts kilo calories to kilo joules

April 25, 2012

I decided to learn some android programming and therefore I decided to code a small android application which converts a given amount of energy from kilocalories to kilojoules and from kilocalories to kilojoules. I chose to code such an app since I’m trying to get fit for the summer and record what I eat into shapeup club. I usually think about calorie intake in terms of kilojoules but the shapeub club only accepts kilocalories. So therefore I figure out how many kilojoules I’ve taken in and use this app to find out how man kilocalories I should add in the shapeup club app. The application itself is quite simple it has to buttons which starts two functions that perform conversions. The result of a function calls is recorded on one of the programs to result fields. The result field is a simple textview control which is updated with the settext() method.

My andriod app

My andriod app

The source code is as follows:
package com.example.test5;

import android.app.Activity;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.TextView;
import android.widget.Toast;

public class Test5Activity extends Activity {
/** Called when the activity is first created. */
Button btnCalcKj=null;
Button btnCalcKcal=null;
EditText edTxtNumKcal=null;
EditText edTxtNumKj=null;
TextView tvCompKj=null;
TextView tvCompKcal=null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnCalcKj=(Button)findViewById(R.id.btnCalcKj);
btnCalcKcal=(Button)findViewById(R.id.btnCalcKcal);
edTxtNumKcal=(EditText)findViewById(R.id.edTxtNumKcal);
edTxtNumKj=(EditText)findViewById(R.id.edTxtNumKj);
tvCompKcal=(TextView)findViewById(R.id.tvCompKcal);
tvCompKj=(TextView)findViewById(R.id.tvCompKj);
tvCompKcal.setText(“”);
tvCompKj.setText(“”);
btnCalcKcal.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
try{
// Perform action on click
double numKcal=calcNumKcal(Double.parseDouble(“”+edTxtNumKj.getText()) );
tvCompKcal.setText(“”+numKcal);
tvCompKj.setText(“”);
edTxtNumKcal.setText(“”);
edTxtNumKj.setText(“”);
}
catch(Exception e){
}
}
});
btnCalcKj.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
try{
double numKj=calcNumKj(Double.parseDouble(“”+edTxtNumKcal.getText()) );
tvCompKj.setText(“”+numKj);
tvCompKcal.setText(“”);
edTxtNumKj.setText(“”);
edTxtNumKcal.setText(“”);}
catch(Exception e){
}
}
});
}
private  double calcNumKj(double Kcal){
return Kcal*4.12;
}

private double calcNumKcal(double Kj){
return Kj/4.12;
}
}

You can also download the source code by clicking the link below. Get this app running by creating a new android 2.3.3 project in Eclipse named “Test5”. Thereafter you paste all of the code above into the file called “Test5Activity”.

Source code

Advertisements

Sony W518a an interesting feature phone with a shake function

April 16, 2012

I found an interesting feature phone called Sony Ericsson W518a.
You can control certain features by shaking the phone. One is example is changing tracks. Check it out at here.

Durrocomm Andriod – a truly rugged andriod handset!

April 10, 2012

While browsing the web I found a truly rugged handset called Durrocom Andriod. It is military certified which means that it withstands shocks and vibrations better than those phones which are only waterproof such as the Motorola Defy or Sony Ericsson Xperia Active. Except the military certification it also has an IP67 certification which means it can withstand being submerged in 1 metre of water up to 30minutes.  It measures 125 x 65 x 21 mm. It weighs in at 180g. It has a talk time of 5.5hrs and a standby time of 400hrs. It has 3G, WCDMA, Quadband GSM. It runs andriod 2.3. It has a capacitive screen and 5MP camera. It also features a torch, gps and a compass. Furthermore the phone is able to handle dual sim cards so you can use it both for work and play.

You can also check out Durrocomms homepage.
You can alo check out this Youtube video

Durrocomm Andriod - a rugged andriod phone

Durrocomm Andriod – a rugged andriod phone

Read other people’s blogs about on Technorati about: , , , smartphone, , ,

Läs även andra bloggares åsikter om: , , , , ,

Technorati token: F6U8ZD2JJGDG

Test the graphing function of google!

April 7, 2012

Here’s something for you math majors and all other people interested in mathematics! Did you know that Google can make graphs?
Try to type this sin(x)/x,1/x^2 into Google and see what you get! You can also specify within what ranges of x and y Google should draw the graph.

Google Graph of sin(x)

Google Graph of sin(x)

Read other people’s blogs about on Technorati about: , , , mathematics, , ,

Läs även andra bloggares åsikter om: , , , , ,

Technorati token: F6U8ZD2JJGDG


%d bloggers like this: