Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2918657

Browse files
committed
Adding temparature converter generated with Android studio
1 parent 81d0a54 commit 2918657

File tree

26 files changed

+534
-0
lines changed

26 files changed

+534
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.gradle
2+
/local.properties
3+
/.idea/workspace.xml
4+
/.idea/libraries
5+
.DS_Store
6+
/build
7+
/captures
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 22
5+
buildToolsVersion "23.0.0 rc2"
6+
7+
defaultConfig {
8+
applicationId "com.vogella.android.temperatureconverter"
9+
minSdkVersion 22
10+
targetSdkVersion 22
11+
versionCode 1
12+
versionName "1.0"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# Add project specific ProGuard rules here.
2+
# By default, the flags in this file are appended to flags specified
3+
# in /home/vogella/Android/Sdk/tools/proguard/proguard-android.txt
4+
# You can edit the include path and order by changing the proguardFiles
5+
# directive in build.gradle.
6+
#
7+
# For more details, see
8+
# http://developer.android.com/guide/developing/tools/proguard.html
9+
10+
# Add any project specific keep options here:
11+
12+
# If your project uses WebView with JS, uncomment the following
13+
# and specify the fully qualified class name to the JavaScript interface
14+
# class:
15+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
16+
# public *;
17+
#}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.vogella.android.temperatureconverter;
2+
3+
import android.app.Application;
4+
import android.test.ApplicationTestCase;
5+
6+
/**
7+
* <a href="http://d.android.com/tools/testing/testing_android.html">Testing Fundamentals</a>
8+
*/
9+
public class ApplicationTest extends ApplicationTestCase<Application> {
10+
public ApplicationTest() {
11+
super(Application.class);
12+
}
13+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.vogella.android.temperatureconverter" >
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:theme="@style/AppTheme" >
10+
<activity
11+
android:name=".MainActivity"
12+
android:label="@string/app_name" >
13+
<intent-filter>
14+
<action android:name="android.intent.action.MAIN" />
15+
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
19+
</application>
20+
21+
</manifest>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package com.vogella.android.temperatureconverter;
2+
3+
public class ConverterUtil {
4+
// converts to celsius
5+
public static float convertFahrenheitToCelsius(float fahrenheit) {
6+
return ((fahrenheit - 32) * 5 / 9);
7+
}
8+
9+
// converts to fahrenheit
10+
public static float convertCelsiusToFahrenheit(float celsius) {
11+
return ((celsius * 9) / 5) + 32;
12+
}
13+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.vogella.android.temperatureconverter;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
import android.view.View;
6+
import android.widget.EditText;
7+
import android.widget.RadioButton;
8+
import android.widget.Toast;
9+
10+
public class MainActivity extends Activity {
11+
private EditText text;
12+
13+
@Override
14+
public void onCreate(Bundle savedInstanceState) {
15+
super.onCreate(savedInstanceState);
16+
setContentView(R.layout.activity_main);
17+
text = (EditText) findViewById(R.id.editText1);
18+
19+
}
20+
21+
// this method is called at button click because we assigned the name to the
22+
// "OnClick" property of the button
23+
public void onClick(View view) {
24+
switch (view.getId()) {
25+
case R.id.button1:
26+
RadioButton celsiusButton = (RadioButton) findViewById(R.id.radio0);
27+
RadioButton fahrenheitButton = (RadioButton) findViewById(R.id.radio1);
28+
if (text.getText().length() == 0) {
29+
Toast.makeText(this, "Please enter a valid number",
30+
Toast.LENGTH_LONG).show();
31+
return;
32+
}
33+
34+
float inputValue = Float.parseFloat(text.getText().toString());
35+
if (celsiusButton.isChecked()) {
36+
text.setText(String
37+
.valueOf(ConverterUtil.convertFahrenheitToCelsius(inputValue)));
38+
celsiusButton.setChecked(false);
39+
fahrenheitButton.setChecked(true);
40+
} else {
41+
text.setText(String
42+
.valueOf(ConverterUtil.convertCelsiusToFahrenheit(inputValue)));
43+
fahrenheitButton.setChecked(false);
44+
celsiusButton.setChecked(true);
45+
}
46+
break;
47+
}
48+
}
49+
50+
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools"
3+
android:layout_width="match_parent"
4+
android:layout_height="match_parent"
5+
android:orientation="vertical"
6+
android:paddingBottom="@dimen/activity_vertical_margin"
7+
android:paddingLeft="@dimen/activity_horizontal_margin"
8+
android:paddingRight="@dimen/activity_horizontal_margin"
9+
android:paddingTop="@dimen/activity_vertical_margin"
10+
tools:context=".MainActivity"
11+
android:background="@color/myColor">
12+
13+
14+
<EditText
15+
android:layout_width="match_parent"
16+
android:layout_height="wrap_content"
17+
android:id="@+id/editText1" />
18+
19+
<RadioGroup
20+
android:id="@+id/radioGroup1"
21+
android:layout_width="wrap_content"
22+
android:layout_height="wrap_content"
23+
android:layout_alignStart="@+id/editText1"
24+
android:layout_below="@+id/editText1">
25+
26+
<RadioButton
27+
android:id="@+id/radio0"
28+
android:layout_width="wrap_content"
29+
android:layout_height="wrap_content"
30+
android:checked="true"
31+
android:text="RadioButton" />
32+
33+
<RadioButton
34+
android:id="@+id/radio1"
35+
android:layout_width="wrap_content"
36+
android:layout_height="wrap_content"
37+
android:text="RadioButton" />
38+
</RadioGroup>
39+
40+
<Button
41+
android:id="@+id/button1"
42+
android:layout_width="wrap_content"
43+
android:layout_height="wrap_content"
44+
android:layout_alignStart="@+id/radioGroup1"
45+
android:layout_below="@+id/radioGroup1"
46+
android:layout_marginTop="22dp"
47+
android:text="Button" />
48+
49+
</LinearLayout>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<menu xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools" tools:context=".MainActivity">
3+
<item android:id="@+id/action_settings" android:title="@string/action_settings"
4+
android:orderInCategory="100" android:showAsAction="never" />
5+
</menu>

0 commit comments

Comments
 (0)