Skip to content

Commit fb0f4da

Browse files
author
Rajeev kumar
committed
Android Otto eventbus library tutorial by tutorialwing.com
0 parents  commit fb0f4da

39 files changed

+907
-0
lines changed

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures

.idea/compiler.xml

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/copyright/profiles_settings.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/encodings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

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 23
5+
buildToolsVersion "23.0.3"
6+
7+
defaultConfig {
8+
applicationId "tutorialwing.com.ottolibrarytutorial"
9+
minSdkVersion 16
10+
targetSdkVersion 23
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+
testCompile 'junit:junit:4.12'
25+
26+
compile 'com.android.support:appcompat-v7:23.4.0'
27+
compile 'com.squareup:otto:1.3.8'
28+
}

app/proguard-rules.pro

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 /Users/Rajeevkumar/Library/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+
#}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package tutorialwing.com.ottolibrarytutorial;
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+
}

app/src/main/AndroidManifest.xml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest package="tutorialwing.com.ottolibrarytutorial"
3+
xmlns:android="http://schemas.android.com/apk/res/android">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:icon="@mipmap/ic_launcher"
8+
android:label="@string/app_name"
9+
android:supportsRtl="true"
10+
android:theme="@style/AppTheme">
11+
<activity android:name=".MainActivity">
12+
<intent-filter>
13+
<action android:name="android.intent.action.MAIN"/>
14+
15+
<category android:name="android.intent.category.LAUNCHER"/>
16+
</intent-filter>
17+
</activity>
18+
<activity android:name=".SecondActivity">
19+
</activity>
20+
</application>
21+
22+
</manifest>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package tutorialwing.com.ottolibrarytutorial;
2+
3+
public class Events {
4+
5+
public static class FragmentActivityMessage {
6+
7+
private String message;
8+
9+
public FragmentActivityMessage(String message) {
10+
this.message = message;
11+
}
12+
13+
public String getMessage() {
14+
return message;
15+
}
16+
}
17+
18+
public static class ActivityFragmentMessage {
19+
20+
private String message;
21+
22+
public ActivityFragmentMessage(String message) {
23+
this.message = message;
24+
}
25+
26+
public String getMessage() {
27+
return message;
28+
}
29+
}
30+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package tutorialwing.com.ottolibrarytutorial;
2+
3+
import com.squareup.otto.Bus;
4+
5+
public class GlobalBus {
6+
private static Bus sBus;
7+
8+
public static Bus getBus() {
9+
if (sBus == null)
10+
sBus = new Bus();
11+
return sBus;
12+
}
13+
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package tutorialwing.com.ottolibrarytutorial;
2+
3+
import android.os.Bundle;
4+
import android.support.v7.app.AppCompatActivity;
5+
import android.view.View;
6+
import android.widget.EditText;
7+
import android.widget.TextView;
8+
import android.widget.Toast;
9+
10+
import com.squareup.otto.Subscribe;
11+
12+
public class MainActivity extends AppCompatActivity {
13+
14+
@Override
15+
protected void onCreate(Bundle savedInstanceState) {
16+
super.onCreate(savedInstanceState);
17+
setContentView(R.layout.activity_main);
18+
19+
addFragment();
20+
}
21+
22+
@Override
23+
protected void onStart() {
24+
super.onStart();
25+
GlobalBus.getBus().register(this);
26+
}
27+
28+
private void addFragment() {
29+
getSupportFragmentManager().beginTransaction().add(R.id.fragmentContainer, new UserFragment()).commit();
30+
}
31+
32+
public void sendMessageToFragment(View view) {
33+
EditText etMessage = (EditText) findViewById(R.id.activityData);
34+
Events.ActivityFragmentMessage activityFragmentMessageEvent =
35+
new Events.ActivityFragmentMessage(String.valueOf(etMessage.getText()));
36+
GlobalBus.getBus().post(activityFragmentMessageEvent);
37+
}
38+
39+
@Subscribe
40+
public void getMessage(Events.FragmentActivityMessage fragmentActivityMessage) {
41+
TextView messageView = (TextView) findViewById(R.id.message);
42+
messageView.setText(getString(R.string.message_received) + " " + fragmentActivityMessage.getMessage());
43+
44+
Toast.makeText(getApplicationContext(),
45+
getString(R.string.message_main_activity) + " " + fragmentActivityMessage.getMessage(),
46+
Toast.LENGTH_SHORT).show();
47+
}
48+
49+
@Override
50+
protected void onStop() {
51+
super.onStop();
52+
GlobalBus.getBus().unregister(this);
53+
}
54+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package tutorialwing.com.ottolibrarytutorial;
2+
3+
import android.os.Bundle;
4+
import android.support.v7.app.AppCompatActivity;
5+
6+
import com.squareup.otto.Produce;
7+
8+
public class SecondActivity extends AppCompatActivity {
9+
10+
@Override
11+
protected void onCreate(Bundle savedInstanceState) {
12+
super.onCreate(savedInstanceState);
13+
14+
GlobalBus.getBus().register(this);
15+
setContentView(R.layout.activity_second);
16+
}
17+
18+
@Produce
19+
public Events.FragmentActivityMessage produceEvent() {
20+
// Assuming that we are tracking the last messages for this
21+
// event (i.e. FragmentActivityMessage) and the message is "Hello Tutorialwing"
22+
return new Events.FragmentActivityMessage("Hello Tutorialwing");
23+
}
24+
}

0 commit comments

Comments
 (0)