) {
29 | EspressoIdlingResource.decrement() // Set app as idle.
30 | notesView.setProgressIndicator(false)
31 | notesView.showNotes(notes)
32 | }
33 | })
34 | }
35 |
36 | override fun addNewNote() = notesView.showAddNote()
37 |
38 | override fun openNoteDetails(requestedNote: Note) {
39 |
40 | }
41 |
42 | }
--------------------------------------------------------------------------------
/Chapter12/chapter_12_source/app/src/main/java/com/packtpub/eunice/todolist/MyFirebaseInstanceIDService.kt:
--------------------------------------------------------------------------------
1 | package com.packtpub.eunice.todolist
2 |
3 | import android.util.Log
4 | import com.google.firebase.iid.FirebaseInstanceId
5 | import com.google.firebase.iid.FirebaseInstanceIdService
6 |
7 | class MyFirebaseInstanceIDService : FirebaseInstanceIdService(){
8 | override fun onTokenRefresh() {
9 | // Get updated InstanceID token.
10 | val refreshedToken = FirebaseInstanceId.getInstance().token
11 | Log.d(TAG, "Refreshed token: " + refreshedToken!!)
12 | //dHDDfhzDESA:APA91bEDEmX8MKxUXX_G5EZ1Q9xCbyoVUGqwCoV68f6cwZNN9SLURGq1m4TBS3n-au4sNn0Oj_Km3FOjDDYYwAX7KfTGr1EO0TIBIJa_Pkf2GGgJzGrivpn57lc8PNCZhxRERjpnPI-H
13 |
14 | // If you want to send messages to this application instance or
15 | // manage this apps subscriptions on the server side, send the
16 | // Instance ID token to your app server.
17 | // sendRegistrationToServer(refreshedToken)
18 | }
19 |
20 | companion object {
21 | val TAG = "MyFirebaseInstanceID"
22 | }
23 | // 
Realm Platform 2.0: Overview and Demo
24 | }
25 |
--------------------------------------------------------------------------------
/Chapter06/chapter_6_source/app/src/main/java/com/packtpub/eunice/tictactoe/Snippets.kt:
--------------------------------------------------------------------------------
1 | package com.packtpub.eunice.tictactoe
2 |
3 | import android.util.Log
4 |
5 |
6 | data class Student(var name: String, var classRoomNo: Int, var studentId: Int, var age: Int)
7 |
8 |
9 |
10 |
11 | fun addStudent(name: String, age:Int, classRoomNo: Int = 1, studentId: Int) = Student(name, classRoomNo, studentId, age)
12 |
13 |
14 | var anna = addStudent("Anna", 18, 2, 1)
15 | var joseph = addStudent(name = "Joseph", age = 19, studentId = 2)
16 |
17 |
18 | fun logStudent(name: String, age:Int, createStudent:(String, Int) -> Student) {
19 | Log.d("student creation", "About to create student with name $name")
20 | val student = createStudent(name, age)
21 | Log.d("student creation", "Student created with name ${student.name} and age ${student.age}")
22 | }
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 | fun main(args: Array) {
31 |
32 | logStudent("Anna", 20, { name: String, age: Int -> Student(name, 1, 3, age)})
33 |
34 | var name: String = "Anna" // non-nullable String
35 | var gender: String? = "Female" //nullable String
36 |
37 | print("Length of name is ${name.length}") // will compile
38 |
39 |
40 | if (gender != null) {
41 | print("Length of gender is ${gender.length}")
42 | }
43 |
44 |
45 | val len = gender!!.length
46 | print("Length of gender is $len")
47 |
48 | if (gender is String) {
49 | println("Length of gender is ${gender.length}") // gender is automatically cast to a String
50 | }
51 |
52 | var fullname: String = name as String
53 |
54 | var gen: String? = gender as? String
55 |
56 | println("Anna is in classroom no. ${anna.classRoomNo}")
57 | println("Joseph is in classroom no. ${joseph.classRoomNo}")
58 |
59 |
60 | }
--------------------------------------------------------------------------------
/Chapter13/chapter_13_source/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/Chapter15/chapter_15_source/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/Chapter03/chapter_3_source/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
22 |
31 |
32 |
33 |
34 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/Chapter04/chapter_4_source/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
22 |
31 |
32 |
33 |
34 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/Chapter05/chapter_5_source/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
22 |
31 |
32 |
33 |
34 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/Chapter06/chapter_6_source/app/src/main/res/layout/activity_main.xml:
--------------------------------------------------------------------------------
1 |
2 |
8 |
9 |
13 |
14 |
20 |
21 |
22 |
31 |
32 |
33 |
34 |
42 |
43 |
44 |
--------------------------------------------------------------------------------
/Chapter10/chapter_10_source/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/Chapter11/chapter_11_source/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/Chapter12/chapter_12_source/app/src/main/res/drawable-v24/ic_launcher_foreground.xml:
--------------------------------------------------------------------------------
1 |
7 |
12 |
13 |
19 |
22 |
25 |
26 |
27 |
28 |
34 |
35 |
--------------------------------------------------------------------------------
/Chapter01/chapter_1_source/app/src/main/java/com/packtpub/eunice/tictactoe/MainActivity.java:
--------------------------------------------------------------------------------
1 | package com.packtpub.eunice.tictactoe;
2 |
3 | import android.os.Bundle;
4 | import android.support.design.widget.FloatingActionButton;
5 | import android.support.design.widget.Snackbar;
6 | import android.support.v7.app.AppCompatActivity;
7 | import android.support.v7.widget.Toolbar;
8 | import android.view.Menu;
9 | import android.view.MenuItem;
10 | import android.view.View;
11 |
12 |
13 | public class MainActivity extends AppCompatActivity {
14 |
15 | @Override
16 | protected void onCreate(Bundle savedInstanceState) {
17 | super.onCreate(savedInstanceState);
18 | setContentView(R.layout.activity_main);
19 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
20 | setSupportActionBar(toolbar);
21 |
22 | FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
23 | fab.setOnClickListener(new View.OnClickListener() {
24 | @Override
25 | public void onClick(View view) {
26 | Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
27 | .setAction("Action", null).show();
28 | }
29 | });
30 | }
31 |
32 | @Override
33 | public boolean onCreateOptionsMenu(Menu menu) {
34 | // Inflate the menu; this adds items to the action bar if it is present.
35 | getMenuInflater().inflate(R.menu.menu_main, menu);
36 | return true;
37 | }
38 |
39 | @Override
40 | public boolean onOptionsItemSelected(MenuItem item) {
41 | // Handle action bar item clicks here. The action bar will
42 | // automatically handle clicks on the Home/Up button, so long
43 | // as you specify a parent activity in AndroidManifest.xml.
44 | int id = item.getItemId();
45 |
46 | //noinspection SimplifiableIfStatement
47 | if (id == R.id.action_settings) {
48 | return true;
49 | }
50 |
51 | return super.onOptionsItemSelected(item);
52 | }
53 | }
--------------------------------------------------------------------------------
/Chapter13/chapter_13_source/app/build.gradle:
--------------------------------------------------------------------------------
1 | apply plugin: 'com.android.application'
2 | apply plugin: 'kotlin-android'
3 | apply plugin: 'kotlin-android-extensions'
4 | apply plugin: 'io.fabric'
5 |
6 | android {
7 | compileSdkVersion 27
8 | defaultConfig {
9 | applicationId "com.packtpub.eunice.notesapp"
10 | minSdkVersion 22
11 | targetSdkVersion 27
12 | versionCode 1
13 | versionName "1.0"
14 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
15 | }
16 | buildTypes {
17 | release {
18 | minifyEnabled false
19 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
20 | }
21 | }
22 | }
23 |
24 | dependencies {
25 | implementation fileTree(dir: 'libs', include: ['*.jar'])
26 | implementation "org.jetbrains.kotlin:kotlin-stdlib-jre7:$kotlin_version"
27 | implementation 'com.android.support:appcompat-v7:27.1.0'
28 | implementation 'com.android.support.constraint:constraint-layout:1.0.2'
29 | implementation "com.android.support.test.espresso:espresso-idling-resource:3.0.1"
30 | implementation 'com.google.firebase:firebase-core:12.0.1'
31 | implementation 'com.google.firebase:firebase-crash:12.0.1'
32 | implementation 'com.crashlytics.sdk.android:crashlytics:2.9.1'
33 | testImplementation 'junit:junit:4.12'
34 | testImplementation "org.mockito:mockito-all:1.10.19"
35 | testImplementation "org.hamcrest:hamcrest-all:1.3"
36 | testImplementation "org.powermock:powermock-module-junit4:1.6.2"
37 | testImplementation "org.powermock:powermock-api-mockito:1.6.2"
38 | androidTestImplementation 'com.android.support.test:runner:1.0.1'
39 | androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
40 | // Android Testing Support Library's runner and rules
41 | androidTestImplementation "com.android.support.test:runner:0.5"
42 | androidTestImplementation "com.android.support.test:rules:0.5"
43 |
44 | // Espresso UI Testing dependencies.
45 | androidTestImplementation "com.android.support.test.espresso:espresso-core:3.0.1"
46 | androidTestImplementation "com.android.support.test.espresso:espresso-contrib:3.0.1"
47 | }
48 |
49 | apply plugin: 'com.google.gms.google-services'
--------------------------------------------------------------------------------