Skip to content

Commit c5ef752

Browse files
author
David Weiser
committed
adds first androd excercise
1 parent 08df79a commit c5ef752

38 files changed

+723
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 26
5+
defaultConfig {
6+
applicationId "com.vogella.android.mymathtrainer"
7+
minSdkVersion 24
8+
targetSdkVersion 26
9+
versionCode 1
10+
versionName "1.0"
11+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
12+
}
13+
buildTypes {
14+
release {
15+
minifyEnabled false
16+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
17+
}
18+
}
19+
}
20+
21+
dependencies {
22+
implementation fileTree(dir: 'libs', include: ['*.jar'])
23+
compile 'com.android.support.constraint:constraint-layout:1.1.0-beta2'
24+
testImplementation 'junit:junit:4.12'
25+
androidTestImplementation('com.android.support.test.espresso:espresso-core:3.0.1', {
26+
exclude group: 'com.android.support', module: 'support-annotations'
27+
})
28+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.vogella.android.mymathtrainer;
2+
3+
import android.content.Context;
4+
import android.support.test.InstrumentationRegistry;
5+
import android.support.test.runner.AndroidJUnit4;
6+
7+
import org.junit.Test;
8+
import org.junit.runner.RunWith;
9+
10+
import static org.junit.Assert.*;
11+
12+
/**
13+
* Instrumented test, which will execute on an Android device.
14+
*
15+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
16+
*/
17+
@RunWith(AndroidJUnit4.class)
18+
public class ExampleInstrumentedTest {
19+
@Test
20+
public void useAppContext() throws Exception {
21+
// Context of the app under test.
22+
Context appContext = InstrumentationRegistry.getTargetContext();
23+
24+
assertEquals("com.vogella.android.mymathtrainer", appContext.getPackageName());
25+
}
26+
}
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.mymathtrainer">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:roundIcon="@mipmap/ic_launcher_round"
10+
android:supportsRtl="true"
11+
android:theme="@style/AppTheme">
12+
<activity android:name=".CreateUserActivity">
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>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package com.vogella.android.mymathtrainer;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
import android.view.View;
6+
import android.widget.Button;
7+
import android.widget.EditText;
8+
import android.widget.RadioButton;
9+
import android.widget.Toast;
10+
11+
public class CreateUserActivity extends Activity {
12+
13+
RadioButton radioMale;
14+
RadioButton radioFemale;
15+
Button createUserButton;
16+
EditText edittextUserName;
17+
boolean gender = false;
18+
19+
@Override
20+
protected void onCreate(Bundle savedInstanceState) {
21+
super.onCreate(savedInstanceState);
22+
setContentView(R.layout.activity_create_user);
23+
radioMale = findViewById(R.id.radio_male);
24+
radioFemale = findViewById(R.id.radio_female);
25+
createUserButton = findViewById(R.id.createUserButton);
26+
edittextUserName = findViewById(R.id.username);
27+
createUserButton.setEnabled(false);
28+
}
29+
30+
public void onRadioButtonClicked(View view) {
31+
switch (view.getId()) {
32+
case R.id.radio_male:
33+
gender = false;
34+
radioFemale.setAlpha(0.2f);
35+
break;
36+
case R.id.radio_female:
37+
gender = true;
38+
radioMale.setAlpha(0.2f);
39+
break;
40+
}
41+
view.setAlpha(1);
42+
createUserButton.setEnabled(true);
43+
}
44+
45+
public void onClick(View view) {
46+
switch (view.getId()){
47+
case R.id.cancelButton:
48+
setResult(Activity.RESULT_CANCELED);
49+
finish();
50+
break;
51+
case R.id.createUserButton:
52+
createUser();
53+
setResult(Activity.RESULT_OK);
54+
break;
55+
}
56+
}
57+
58+
private void createUser() {
59+
User user = new User(edittextUserName.getText().toString(), gender);
60+
String genderAsString = gender ? "female" : "male";
61+
Toast.makeText(getApplicationContext(), "User created with name: " + user.name + " and gender: " + genderAsString, Toast.LENGTH_LONG).show();
62+
}
63+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package com.vogella.android.mymathtrainer;
2+
3+
public class User {
4+
public String name;
5+
public boolean gender;
6+
7+
public User(String name, boolean gender) {
8+
this.name = name;
9+
this.gender = gender;
10+
}
11+
12+
}
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
3+
android:width="24dp"
4+
android:height="24dp"
5+
android:viewportHeight="108.0"
6+
android:viewportWidth="108.0">
7+
<path
8+
android:fillColor="#26A69A"
9+
android:pathData="M0,0h108v108h-108z"
10+
android:strokeColor="#66FFFFFF"
11+
android:strokeWidth="0.8" />
12+
<path
13+
android:fillColor="#00000000"
14+
android:pathData="M19,0L19,108"
15+
android:strokeColor="#33FFFFFF"
16+
android:strokeWidth="0.8" />
17+
<path
18+
android:fillColor="#00000000"
19+
android:pathData="M9,0L9,108"
20+
android:strokeColor="#66FFFFFF"
21+
android:strokeWidth="0.8" />
22+
<path
23+
android:fillColor="#00000000"
24+
android:pathData="M39,0L39,108"
25+
android:strokeColor="#66FFFFFF"
26+
android:strokeWidth="0.8" />
27+
<path
28+
android:fillColor="#00000000"
29+
android:pathData="M29,0L29,108"
30+
android:strokeColor="#66FFFFFF"
31+
android:strokeWidth="0.8" />
32+
<path
33+
android:fillColor="#00000000"
34+
android:pathData="M59,0L59,108"
35+
android:strokeColor="#66FFFFFF"
36+
android:strokeWidth="0.8" />
37+
<path
38+
android:fillColor="#00000000"
39+
android:pathData="M49,0L49,108"
40+
android:strokeColor="#66FFFFFF"
41+
android:strokeWidth="0.8" />
42+
<path
43+
android:fillColor="#00000000"
44+
android:pathData="M79,0L79,108"
45+
android:strokeColor="#66FFFFFF"
46+
android:strokeWidth="0.8" />
47+
<path
48+
android:fillColor="#00000000"
49+
android:pathData="M69,0L69,108"
50+
android:strokeColor="#66FFFFFF"
51+
android:strokeWidth="0.8" />
52+
<path
53+
android:fillColor="#00000000"
54+
android:pathData="M89,0L89,108"
55+
android:strokeColor="#33FFFFFF"
56+
android:strokeWidth="0.8" />
57+
<path
58+
android:fillColor="#00000000"
59+
android:pathData="M99,0L99,108"
60+
android:strokeColor="#66FFFFFF"
61+
android:strokeWidth="0.8" />
62+
<path
63+
android:fillColor="#00000000"
64+
android:pathData="M0,89L108,89"
65+
android:strokeColor="#33FFFFFF"
66+
android:strokeWidth="0.8" />
67+
<path
68+
android:fillColor="#00000000"
69+
android:pathData="M0,99L108,99"
70+
android:strokeColor="#66FFFFFF"
71+
android:strokeWidth="0.8" />
72+
<path
73+
android:fillColor="#00000000"
74+
android:pathData="M0,69L108,69"
75+
android:strokeColor="#66FFFFFF"
76+
android:strokeWidth="0.8" />
77+
<path
78+
android:fillColor="#00000000"
79+
android:pathData="M0,79L108,79"
80+
android:strokeColor="#66FFFFFF"
81+
android:strokeWidth="0.8" />
82+
<path
83+
android:fillColor="#00000000"
84+
android:pathData="M0,49L108,49"
85+
android:strokeColor="#66FFFFFF"
86+
android:strokeWidth="0.8" />
87+
<path
88+
android:fillColor="#00000000"
89+
android:pathData="M0,59L108,59"
90+
android:strokeColor="#66FFFFFF"
91+
android:strokeWidth="0.8" />
92+
<path
93+
android:fillColor="#00000000"
94+
android:pathData="M0,29L108,29"
95+
android:strokeColor="#66FFFFFF"
96+
android:strokeWidth="0.8" />
97+
<path
98+
android:fillColor="#00000000"
99+
android:pathData="M0,39L108,39"
100+
android:strokeColor="#66FFFFFF"
101+
android:strokeWidth="0.8" />
102+
<path
103+
android:fillColor="#00000000"
104+
android:pathData="M0,19L108,19"
105+
android:strokeColor="#33FFFFFF"
106+
android:strokeWidth="0.8" />
107+
<path
108+
android:fillColor="#00000000"
109+
android:pathData="M0,9L108,9"
110+
android:strokeColor="#66FFFFFF"
111+
android:strokeWidth="0.8" />
112+
</vector>
113+
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:app="http://schemas.android.com/apk/res-auto"
3+
android:id="@+id/parentLayout"
4+
android:layout_width="match_parent"
5+
android:layout_height="match_parent">
6+
7+
<Button
8+
android:id="@+id/cancelButton"
9+
android:layout_width="0dp"
10+
android:layout_height="wrap_content"
11+
android:layout_marginStart="8dp"
12+
android:layout_marginTop="8dp"
13+
android:onClick="onClick"
14+
android:text="Abbrechen"
15+
app:layout_constraintEnd_toStartOf="@+id/createUserButton"
16+
app:layout_constraintHorizontal_chainStyle="spread_inside"
17+
app:layout_constraintStart_toStartOf="parent"
18+
app:layout_constraintTop_toTopOf="parent" />
19+
20+
<Button
21+
android:id="@+id/createUserButton"
22+
android:layout_width="0dp"
23+
android:layout_height="wrap_content"
24+
android:layout_marginEnd="8dp"
25+
android:layout_marginStart="8dp"
26+
android:onClick="onClick"
27+
android:text="Erstellen"
28+
app:layout_constraintBottom_toBottomOf="@+id/cancelButton"
29+
app:layout_constraintEnd_toEndOf="parent"
30+
app:layout_constraintStart_toEndOf="@+id/cancelButton"
31+
app:layout_constraintTop_toTopOf="@+id/cancelButton" />
32+
33+
<TextView
34+
android:id="@+id/userlabel"
35+
android:layout_width="wrap_content"
36+
android:layout_height="wrap_content"
37+
android:layout_marginStart="8dp"
38+
android:layout_marginTop="8dp"
39+
android:text="Dein Name"
40+
android:textSize="24sp"
41+
app:layout_constraintStart_toStartOf="parent"
42+
app:layout_constraintTop_toBottomOf="@+id/cancelButton" />
43+
44+
<EditText
45+
android:id="@+id/username"
46+
android:layout_width="0dp"
47+
android:layout_height="wrap_content"
48+
android:layout_marginEnd="8dp"
49+
android:layout_marginStart="8dp"
50+
android:layout_marginTop="8dp"
51+
android:inputType="textPersonName"
52+
android:textSize="36sp"
53+
app:layout_constraintEnd_toEndOf="parent"
54+
app:layout_constraintStart_toStartOf="parent"
55+
app:layout_constraintTop_toBottomOf="@+id/userlabel" />
56+
57+
<TextView
58+
android:id="@+id/genderlabel"
59+
android:layout_width="0dp"
60+
android:layout_height="32dp"
61+
android:layout_marginEnd="8dp"
62+
android:layout_marginStart="8dp"
63+
android:layout_marginTop="8dp"
64+
android:text="Bist Du ein Mädchen oder ein Junge?"
65+
android:textSize="24sp"
66+
app:layout_constraintEnd_toEndOf="parent"
67+
app:layout_constraintStart_toStartOf="parent"
68+
app:layout_constraintTop_toBottomOf="@+id/username" />
69+
70+
<RadioButton
71+
android:id="@+id/radio_male"
72+
android:layout_width="wrap_content"
73+
android:layout_height="wrap_content"
74+
android:layout_marginStart="8dp"
75+
android:layout_marginTop="8dp"
76+
android:button="@drawable/male"
77+
android:onClick="onRadioButtonClicked"
78+
app:layout_constraintEnd_toStartOf="@+id/radio_female"
79+
app:layout_constraintHorizontal_chainStyle="spread"
80+
app:layout_constraintStart_toStartOf="parent"
81+
app:layout_constraintTop_toBottomOf="@+id/genderlabel" />
82+
83+
<RadioButton
84+
android:id="@+id/radio_female"
85+
android:layout_width="wrap_content"
86+
android:layout_height="wrap_content"
87+
android:layout_marginEnd="8dp"
88+
android:button="@drawable/female"
89+
android:onClick="onRadioButtonClicked"
90+
app:layout_constraintBottom_toBottomOf="@+id/radio_male"
91+
app:layout_constraintEnd_toEndOf="parent"
92+
app:layout_constraintStart_toEndOf="@+id/radio_male"
93+
app:layout_constraintTop_toTopOf="@+id/radio_male" />
94+
</android.support.constraint.ConstraintLayout>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
3+
<background android:drawable="@drawable/ic_launcher_background" />
4+
<foreground android:drawable="@mipmap/ic_launcher_foreground" />
5+
</adaptive-icon>

0 commit comments

Comments
 (0)