Skip to content

Commit

Permalink
Simple Calculator
Browse files Browse the repository at this point in the history
  • Loading branch information
Roeun committed Oct 9, 2012
1 parent acd8864 commit 4e4dcf9
Show file tree
Hide file tree
Showing 19 changed files with 294 additions and 0 deletions.
25 changes: 25 additions & 0 deletions AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.calculatevariable"
android:versionCode="1"
android:versionName="1.0" >

<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />

<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".CalculateVariable"
android:label="@string/title_activity_calculate_variable" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
Binary file added ic_launcher-web.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added libs/android-support-v4.jar
Binary file not shown.
20 changes: 20 additions & 0 deletions proguard-project.txt
Original file line number Diff line number Diff line change
@@ -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 *;
#}
14 changes: 14 additions & 0 deletions project.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# This file is automatically generated by Android Tools.
# Do not modify this file -- YOUR CHANGES WILL BE ERASED!
#
# This file must be checked in Version Control Systems.
#
# To customize properties used by the Ant build system edit
# "ant.properties", and override values to adapt the script to your
# project structure.
#
# To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home):
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt

# Project target.
target=android-16
Binary file added res/drawable-hdpi/ic_action_search.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-ldpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/ic_action_search.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xhdpi/ic_action_search.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added res/drawable-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
111 changes: 111 additions & 0 deletions res/layout/activity_calculate_variable.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<TextView
android:id="@+id/lblTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="22dp"
android:text="@string/lblTitle"
android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="@+id/lblTitle"
android:layout_marginRight="17dp"
android:layout_marginTop="33dp"
android:ems="10"
android:inputType="numberDecimal" />

<TextView
android:id="@+id/lblValue1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/editText3"
android:layout_toLeftOf="@+id/editText3"
android:text="@string/lblValue1"
android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
android:id="@+id/txtValue2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText3"
android:layout_marginTop="16dp"
android:layout_toRightOf="@+id/lblValue1"
android:ems="10"
android:inputType="numberDecimal" />

<TextView
android:id="@+id/lblValue2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/txtValue2"
android:layout_toLeftOf="@+id/txtValue2"
android:text="@string/lblValue2"
android:textAppearance="?android:attr/textAppearanceMedium" />

<Button
android:id="@+id/btnMinus"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/lblValue2"
android:layout_below="@+id/lblValue2"
android:layout_marginTop="15dp"
android:text="@string/btnMinus" />

<Button
android:id="@+id/btnMultiple"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnMinus"
android:layout_alignBottom="@+id/btnMinus"
android:layout_toRightOf="@+id/btnMinus"
android:text="@string/btnMultiple" />

<Button
android:id="@+id/btnSum"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnMultiple"
android:layout_alignBottom="@+id/btnMultiple"
android:layout_toRightOf="@+id/btnMultiple"
android:text="@string/btnSum" />

<Button
android:id="@+id/btnDivide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/btnSum"
android:layout_alignBottom="@+id/btnSum"
android:layout_toRightOf="@+id/btnSum"
android:text="@string/btnDivide" />

<TextView
android:id="@+id/lblResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/btnMinus"
android:layout_below="@+id/btnMinus"
android:layout_marginTop="29dp"
android:text="@string/lblResult"
android:textAppearance="?android:attr/textAppearanceMedium" />

<EditText
android:id="@+id/txtResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/lblResult"
android:layout_alignBottom="@+id/lblResult"
android:layout_alignLeft="@+id/txtValue2"
android:ems="10"
android:inputType="numberDecimal" />

</RelativeLayout>
6 changes: 6 additions & 0 deletions res/menu/activity_calculate_variable.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/menu_settings"
android:title="@string/menu_settings"
android:orderInCategory="100"
android:showAsAction="never" />
</menu>
5 changes: 5 additions & 0 deletions res/values-v11/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<resources>

<style name="AppTheme" parent="android:Theme.Holo.Light" />

</resources>
5 changes: 5 additions & 0 deletions res/values-v14/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<resources>

<style name="AppTheme" parent="android:Theme.Holo.Light.DarkActionBar" />

</resources>
16 changes: 16 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<resources>

<string name="app_name">CalculateVariable</string>
<string name="hello_world">Hello world!</string>
<string name="menu_settings">Settings</string>
<string name="title_activity_calculate_variable">Calculate Variable</string>
<string name="lblTitle">My Simple Calculateor</string>
<string name="lblValue1">Value 1:</string>
<string name="lblValue2">Value 2:</string>
<string name="lblResult">Result:</string>
<string name="btnSum">+</string>
<string name="btnMinus">-</string>
<string name="btnMultiple">*</string>
<string name="btnDivide">/</string>

</resources>
5 changes: 5 additions & 0 deletions res/values/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<resources>

<style name="AppTheme" parent="android:Theme.Light" />

</resources>
87 changes: 87 additions & 0 deletions src/com/example/calculatevariable/CalculateVariable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.example.calculatevariable;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

public class CalculateVariable extends Activity {

Button btnSum;
Button btnMinus;
Button btnMultiple;
Button btnDivide;
EditText txtValue1;
EditText txtValue2;
EditText txtResult;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calculate_variable);

btnSum = (Button) this.findViewById(R.id.btnSum);
btnMinus = (Button) this.findViewById(R.id.btnMinus);
btnMultiple = (Button) this.findViewById(R.id.btnMultiple);
btnDivide = (Button) this.findViewById(R.id.btnDivide);
txtValue1 = (EditText) this.findViewById(R.id.editText3);
txtValue2 = (EditText) this.findViewById(R.id.txtValue2);
txtResult = (EditText) this.findViewById(R.id.txtResult);

btnSum.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
double value1 = Double.parseDouble(txtValue1.getText().toString());
double value2 = Double.parseDouble(txtValue2.getText().toString());
double result = value1 + value2;
txtResult.setText(Double.toString(result));
}
});


btnMinus.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
double value1 = Double.parseDouble(txtValue1.getText().toString());
double value2 = Double.parseDouble(txtValue2.getText().toString());
double result = value1 - value2;
txtResult.setText(Double.toString(result));
}
});


btnMultiple.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
double value1 = Double.parseDouble(txtValue1.getText().toString());
double value2 = Double.parseDouble(txtValue2.getText().toString());
double result = value1 * value2;
txtResult.setText(Double.toString(result));
}
});


btnDivide.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
double value1 = Double.parseDouble(txtValue1.getText().toString());
double value2 = Double.parseDouble(txtValue2.getText().toString());
double result = value1 / value2;
txtResult.setText(Double.toString(result));
}
});

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_calculate_variable, menu);
return true;
}
}

0 comments on commit 4e4dcf9

Please sign in to comment.