Code for the Back End or Calculators, Data Passing, Etc. in Java Mainly With Android Classes.
First Part of 3
========================================================
package biz.quantumsupport.tilecalculator;
import android.app.Activity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.os.Bundle;
public class MyMain extends Activity {
TextView textOutTilesNeeded, txtWidthError, txtHeightError, txtAreaError;
EditText getInputW, getInputH, getInputArea;
String strWidth, strHeight, strArea, strTilesNeeded;
float fltWidth, fltHeight, fltArea, fltTilesNeeded;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
txtWidthError = (EditText) findViewById(R.id.txtTileWidth);
txtHeightError = (EditText) findViewById(R.id.txtTileHeight);
txtAreaError = (EditText) findViewById(R.id.txtArea2cover);
textOutTilesNeeded = (TextView) findViewById(R.id.lblTilesNeeded);
getInputW = (EditText) findViewById(R.id.txtTileWidth);
getInputH = (EditText) findViewById(R.id.txtTileHeight);
getInputArea = (EditText) findViewById(R.id.txtArea2cover);
Button enter = (Button) findViewById(R.id.btnEnterTile);
enter.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
strWidth = getInputW.getText().toString();
strHeight = getInputH.getText().toString();
strArea = getInputArea.getText().toString();
try{
fltWidth = Float.parseFloat(strWidth);
fltHeight = Float.parseFloat(strHeight);
fltArea = Float.parseFloat(strArea);
if(fltWidth==0 || fltHeight==0 || fltArea==0)
{
throw new Exception();
}
}
catch (Exception e) {
txtWidthError.setText("Enter");
txtHeightError.setText("All");
txtAreaError.setText("Numbers");
textOutTilesNeeded.setText("No Zeros");
return;
}
fltTilesNeeded = ((fltArea)/(fltWidth*fltHeight));
strTilesNeeded = String.valueOf(fltTilesNeeded);
textOutTilesNeeded.setText(strTilesNeeded);
}
});
}
}
============================================================
Code for the Graphical User Interface - Android Uses Declarative Design in XML - 2nd Part of 3
============================================================
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="50" android:gravity="center_horizontal" android:text="Tile Width"></TextView>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="50" android:gravity="center_horizontal" android:text="Tile Height"></TextView>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText android:id="@+id/txtTileWidth" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="50" android:gravity="center_horizontal"></EditText>
<EditText android:id="@+id/txtTileHeight" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="50" android:gravity="center_horizontal"></EditText>
</LinearLayout>
<Button android:id="@+id/btnEnterTile" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Enter"></Button>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="50" android:gravity="center_horizontal" android:text="Area to Tile"></TextView>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="50" android:gravity="center_horizontal" android:text="Tiles Needed"></TextView>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<EditText android:id="@+id/txtArea2cover" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="50" android:gravity="center_horizontal"></EditText>
<TextView android:id="@+id/lblTilesNeeded" android:gravity="center_horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_weight="50" android:text=""></TextView>
</LinearLayout>
</LinearLayout>
==================================================================
Android Manifest Code - Android Development Consists of 3 Parts - Android Manifest is the 3rd of the 3 parts here. It's Unique Part to Software Development for Android - It also is in an XML format.
===================================================================
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="biz.quantumsupport.tilecalculator"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="3" />
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MyMain"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>